diff --git a/CMakeLists.txt b/CMakeLists.txt index 278bfa531..4795fe073 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,7 @@ MACRO (CMAKE_BUILD_UTILITIES) SET(CMAKE_ZLIB_INCLUDES ${ZLIB_INCLUDE_DIR}) SET(CMAKE_ZLIB_LIBRARIES ${ZLIB_LIBRARIES}) ELSE(CMAKE_USE_SYSTEM_ZLIB) - SET(CMAKE_ZLIB_INCLUDES) + SET(CMAKE_ZLIB_INCLUDES ${CMake_SOURCE_DIR}/Utilities) SET(CMAKE_ZLIB_LIBRARIES cmzlib) ADD_SUBDIRECTORY(Utilities/cmzlib) CMAKE_SET_TARGET_FOLDER(cmzlib "Utilities/3rdParty") @@ -336,13 +336,14 @@ MACRO (CMAKE_BUILD_UTILITIES) SET(CMAKE_TAR_INCLUDES ${LibArchive_INCLUDE_DIRS}) SET(CMAKE_TAR_LIBRARIES ${LibArchive_LIBRARIES}) ELSE(CMAKE_USE_SYSTEM_LIBARCHIVE) - SET(HAVE_LIBZ 1) - SET(HAVE_ZLIB_H 1) SET(ZLIB_INCLUDE_DIR ${CMAKE_ZLIB_INCLUDES}) - SET(ZLIB_LIBRARIES ${CMAKE_ZLIB_LIBRARIES}) SET(ZLIB_LIBRARY ${CMAKE_ZLIB_LIBRARIES}) - SET(BUILD_ARCHIVE_WITHIN_CMAKE TRUE) ADD_DEFINITIONS(-DLIBARCHIVE_STATIC) + SET(ENABLE_NETTLE OFF CACHE INTERNAL "Enable use of Nettle") + SET(ENABLE_OPENSSL ${CMAKE_USE_OPENSSL} CACHE INTERNAL "Enable use of OpenSSL") + SET(ENABLE_XATTR OFF CACHE INTERNAL "Enable extended attribute support") + SET(ENABLE_ACL OFF CACHE INTERNAL "Enable ACL support") + SET(ENABLE_ICONV OFF CACHE INTERNAL "Enable iconv support") ADD_SUBDIRECTORY(Utilities/cmlibarchive) CMAKE_SET_TARGET_FOLDER(cmlibarchive "Utilities/3rdParty") SET(CMAKE_TAR_LIBRARIES cmlibarchive ${BZIP2_LIBRARIES}) @@ -424,7 +425,7 @@ ENDIF() # The CMake version number. SET(CMake_VERSION_MAJOR 2) SET(CMake_VERSION_MINOR 8) -SET(CMake_VERSION_PATCH 7) +SET(CMake_VERSION_PATCH 8) SET(CMake_VERSION_TWEAK 0) #SET(CMake_VERSION_RC 2) @@ -630,7 +631,6 @@ INSTALL( PATTERN "*.sh*" PERMISSIONS OWNER_READ OWNER_EXECUTE OWNER_WRITE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE - PATTERN "CVS" EXCLUDE ) #----------------------------------------------------------------------- diff --git a/CTestCustom.cmake.in b/CTestCustom.cmake.in index 1a466889b..982919198 100644 --- a/CTestCustom.cmake.in +++ b/CTestCustom.cmake.in @@ -1,3 +1,7 @@ +SET(CTEST_CUSTOM_ERROR_MATCH + ${CTEST_CUSTOM_ERROR_MATCH} + "ERROR:") + SET(CTEST_CUSTOM_WARNING_EXCEPTION ${CTEST_CUSTOM_WARNING_EXCEPTION} "xtree.[0-9]+. : warning C4702: unreachable code" @@ -36,14 +40,16 @@ SET(CTEST_CUSTOM_WARNING_EXCEPTION "warning.*directory name.*CMake-Xcode.*/bin/.*does not exist.*" "stl_deque.h:1051" "(Lexer|Parser).*warning.*conversion.*may (alter its value|change the sign)" + "(Lexer|Parser).*warning.*statement is unreachable" + "PGC-W-0095-Type cast required for this conversion.*ProcessUNIX.c" "[Qq]t([Cc]ore|[Gg]ui).*warning.*conversion.*may alter its value" - "Parser.cxx.*warning.*2111-D.*statement is unreachable" "warning:.*is.*very unsafe.*consider using.*" "warning:.*is.*misused, please use.*" "CMakeSetupManifest.xml.*manifest authoring warning.*Unrecognized Element" "cc-3968 CC: WARNING File.*" # "implicit" truncation by static_cast "ld: warning: directory not found for option .-(F|L)" "warning.*This version of Mac OS X is unsupported" + "clang.*: warning: argument unused during compilation: .-g" # Ignore clang's summary warning, assuming prior text has matched some # other warning expression: diff --git a/ChangeLog.manual b/ChangeLog.manual index f672b80ed..691ff9459 100644 --- a/ChangeLog.manual +++ b/ChangeLog.manual @@ -1,3 +1,595 @@ +Changes in CMake 2.8.8 (since 2.8.8-rc2) +---------------------------------------- +Brad King (1): + CheckIncludeFiles: Shorten check description message + +David Cole (3): + CPackNSIS: Rewrite variable documentation to make it more readable. + OS X: Use correct extra path when searching for applicaton bundles (#13066) + OS X: Mark find_program results as advanced + +Eric NOULARD (1): + Fix some doc typo and add an undocumented var. + +Kashif Rasul (1): + OS X: Use OSX_DEVELOPER_ROOT for app search path (#13066) + +Rolf Eike Beer (1): + FindBoost: add support for 1.49 and 1.50 + +Changes in CMake 2.8.8-rc2 (since 2.8.8-rc1) +-------------------------------------------- +Alex Neundorf (4): + make cmLocalGenerator::EscapeForCMake() static + automoc: fix #13018, proper cmake escaping to avoid false rebuilds + automoc: add define to test which caused bug #13018 + fix #13054: support OBJECT libraries in Eclipse + +Ben Boeckel (1): + Create granular targets for Ninja generators too + +Brad King (6): + CTest.UpdateHG: Fix repo URL for leading slash + Always compile sources with known language + Classify known header file extensions as headers + VS: Add CMakeLists.txt re-run rules at start of generation + Test generated module .def files + Ninja: Fix module .def file path conversion + +David Cole (2): + CMake: Clarify SUFFIX target property documentation. + Xcode: Pay attention to custom configuration types (#13082) + +Peter Collingbourne (1): + Ninja: Substitute and in depfile flags + +Rolf Eike Beer (2): + FILE: mention that TO_CMAKE_PATH also handles list delimiters + FIND_LIBRARY: document FIND_LIBRARY_USE_LIB64_PATHS + +Sean McBride (1): + automoc: include on Apple to get pathconf + +Tom Hughes (1): + Override topdir from rpm command line seems necessary on Amazon linux. + +Changes in CMake 2.8.8-rc1 (since 2.8.7) +---------------------------------------- +Aaron C. Meadows (1): + Visual Studio: Allow setting Single Byte Character Set (#12189) + +Alex Neundorf (34): + GNUInstallDirs: add support for Debian multiarch + FindRuby: fix usage of RUBY_VERSION_MAJOR (#12172) + FindRuby: add more possible library names (for ubuntu, #12172) + FindRuby.cmake: add more debug output + fix FeatureSummary for REQUIRED packages, they were reported as OPTIONAL + FindGetText: fix multiple targets with the same name problem (CMP0002) + fix #6976: FindX11 also searches for X11_Xxf86vm_LIB + GenerateExportHeader: use double quotes around _gcc_version + -remove trailing whitespace + -don't pull in CheckTypeSize.cmake from the cmake which is being built + bootstrap: move while() and endwhile() into the bootstrap build + Check*.cmake: Expand imported targets in CMAKE_REQUIRED_LIBRARIES + find_package: print error if an invalid CONFIGS name is used + find_package: rename NoModule to UseFindModules + find_package: improve error message when no Find module is present + find_package: add MODULE mode to use only Find-modules + find_package: add CONFIG mode keyword alias for NO_MODULE + find_package: mention requested version number in error message + add CMakePackageConfigHelpers: configure_package_config_file() + wrap write_basic_config_version_file as write_basic_package_version_file() + find_package: error out if REQUIRED Config has not been found + write_basic_package_version_file(): improve documentation + write_basic_package_version_file: add ExactVersion mode + WriteBasicConfigVersionFile: add test for ExactVersion mode + find_package: allow Config.cmake to set _FOUND to FALSE + find_package: add test for setting Foo_FOUND to FALSE in a Config file + find_package: additional test for checking the error message + find_package: add OPTIONAL_COMPONENTS keyword + FPHSA(): add missing "]" to documentation + find_package: add documentation for OPTIONAL_COMPONENTS + FPHSA(): add HANDLE_COMPONENTS option + add macro check_required_components() to configure_package_config_file() + Eclipse: fix #13036, make version detection work with symlinks + guard eCos.cmake against multiple inclusion (#12987) + +Alexandru Ciobanu (2): + CTest: Detect Xcode error "Command ... failed with exit code" + CTest: Match valgrind errors with "points to" (#12922) + +Alexey Ozeritsky (1): + FindBLAS/FindLAPACK: Work with MKL version 10.3 (#12924, #12925) + +Artur Kedzierski (1): + Add CURL_CA_BUNDLE option for SSL support (#12946) + +Bill Hoffman (12): + Add CMakeAddFortranSubdirectory to use MinGW gfortran in VS + VSGNUFortran: Add special case for SunPro Fortran runtime library + VSGNUFortran: Disable test in special cases + CMakeAddFortranSubdirectory: Make IMPORTED targets GLOBAL + Use upgraded qt on linux build machine. + Teach CTest what a ninja error looks like. + Allow two cmake_add_fortran_subdirectory calls in the same project. + Add ability to include a file in a project via a cache variable. + Fix typo in error message, and remove redundent test. + Ninja: Add a cache option CMAKE_ENABLE_NINJA to enable the ninja generator. + Ninja: Fix for PDB files with spaces in the path. + Fix FindMPI for the intel compiler on linux by looking in implict directories. + +Bjoern Ricks (1): + Fix crash if app bundle executeable couldn't be found + +Brad King (138): + CheckCCompilerFlag: Generalize "but not for C" case (#12633) + complex: Remove ancient unused ComplexRelativePaths test + complex: Sync Tests/ComplexOneConfig with Tests/Complex + complex: Remove dynamic loader tests + complex: Move GeneratedFileStream test to CMakeLibTests + complex: Simplify test for single-character exe name + complex: Move cmSystemTools::UpperCase test to CMakeLibTests + complex: Remove test dependence on cmSystemTools + complex: Remove unused option to test CMakeLib + Intel: Fix Windows per-config Fortran flags (#12642) + libarchive: Remove our copy to make room for new import + libarchive: Add .gitattributes for indentation with tab + libarchive: Add README-CMake.txt + libarchive: Do not build subdirectories not in reduced snapshot + libarchive: Remove -Wall -Werror from build with GNU + libarchive: Build one static cmlibarchive for CMake + libarchive: Include cm_zlib.h to get zlib used by CMake + Handle libarchive API change in archive_read_data_block + Configure libarchive build within CMake + libarchive: Install COPYING with CMake documentation + libarchive: Port to OSF operating system + libarchive: Fix typo in CheckFileOffsetBits + libarchive: Implement custom lseek for Borland + libarchive: Declare mbstate_t and wcrtomb for Borland + libarchive: Cast constants to int64_t instead of using LL suffix + libarchive: Workaround case-insensitive symbols on Borland + libarchive: Clean up configuration within CMake build + libarchive: Cast mode constants to mode_t in case it is signed + libarchive: Fix Windows NT API usage in VS 6 + libarchive: Suppress compiler warnings + libarchive: Fix var decl after statement in archive_string.c + libarchive: Do not use ST_NOATIME if not defined + libarchive: Check for 'struct statvfs' member 'f_iosize' + libarchive: Do not use MNT_NOATIME if not defined + libarchive: Use Apple copyfile.h API only if available + libarchive: Remove hard-coded build configuration + libarchive: Cleanup after ZLIB_WINAPI check + libarchive: Define _XOPEN_SOURCE=500 on HP-UX + libarchive: Include linux/types.h before linux/fiemap.h + libarchive: Rename isoent_rr_move_dir parameter isoent => curent + libarchive: Suppress PathScale compiler warnings + libarchive: Avoid bogus conversion warning from PGI compiler + libarchive: Set .gitattributes to allow trailing whitespace + libarchive: Update README-CMake.txt for new snapshot + libarchive: Restore CMake 2.6.3 as minimum version + bootstrap: Update copyright year in version report + bootstrap: Re-implement command line option processing + bootstrap: Forward options after '--' to cmake + VS10: Fix /pdb option vcxproj element name (#12328) + Add framework to detect compiler version with its id (#12408) + Detect GNU compiler version with its id (#6251) + Detect MSVC compiler version with its id + Detect Intel compiler version with its id (#11937) + Detect Borland compiler version with its id + Detect IBM XL compiler version with its id + Detect PGI compiler version with its id + Detect Clang compiler version with its id + Detect Watcom compiler version with its id + Detect SunPro compiler version with its id + Detect HP compiler version with its id + Document compiler version macro formats used for detection + Detect SGI MIPSpro compiler version with its id + ExternalProject: Fix git.cmd version detection + ExternalProject: Update copyright year + Include bzlib.h consistently across CMake build (#10950) + FindMPI: Append MPI C++ library correctly in non-compiler case (#12874) + Add infrastructure for CMake-only tests + Tolerate cycles in shared library link interfaces (#12647) + cmInstallCommand: Fix line length for style + cmake-mode.el: Indent after multiline argument (#12908) + Clarify IMPORTED_ target property documentation + Optionally allow IMPORTED targets to be globally visible + Add test covering imported target scope rules + VS: Simplify ;-separated attribute value parsing + Fix CXX/Fortran MODULE flags when enabled before C (#12929) + Remove unused test code + Allow directory names containing '=' and warn if necessary (#12934) + Add CheckLanguage module + CMakeAddFortranSubdirectory: Allow full paths to directories + CMakeAddFortranSubdirectory: Fix documentation format and typos + CMakeAddFortranSubdirectory: Find gfortran in PATH + CMakeAddFortranSubdirectory: Validate gfortran architecture + CMakeAddFortranSubdirectory: Always parse arguments + CMakeAddFortranSubdirectory: Add NO_EXTERNAL_INSTALL option + libarchive: Workaround mbsnrtowcs assertion failure on old glibc + Recognize OpenBSD versioned .so names (#12954) + try_compile: Use random executable file name (#12957) + Rename Modules/Platform/Windows-{Borland => Embarcadero}.cmake + Recognize Embarcadero compiler (#12604) + Factor cmInstallType out of cmTarget::TargetType + Add infrastructure for CMakeCommands tests + find_package: Reject mixed use of MODULE- and CONFIG-only options + find_package: Optionally warn when implicitly using Config mode + find_package: Test error and warning messages in failure cases + bootstrap: Convert MSYS paths to Windows format (#13001) + CTest.UpdateHG: Fix repo URL for local filesystem (#13001) + cmcurl: Do not hard-coded Windows check results for MinGW (#13001) + CheckSourceTree: Remove CVS checkout support (#13001) + Fix MSYS CVS local test repo path format (#13001) + find_package: Test that REQUIRED aborts processing correctly + Remove unused partial OBJECT_FILES property implementation + VS: Simplify object name computation + Hide Makefile local object info inside local generator + KWIML: Make test_INT robust to #define-d int#_t and INT#_C + Add stronger infrastructure for CMake-only tests + Use generalized RunCMake test infrastrucure for find_package test + Use generalized RunCMake test infrastrucure for build_command test + Document Fortran_MODULE_DIRECTORY as OUTPUT only (#13034) + Ninja: Constify use of cmCustomCommand + Ninja: Avoid using 'this' in member initializers + Write CMakeCache.txt atomically (#13040) + Add cmGeneratorTarget to represent a target during generation + Create a cmGeneratorTarget for each cmTarget during generation + Simplify cmMakefileTargetGenerator using cmGeneratorTarget + Simplify cmVisualStudio10TargetGenerator using cmGeneratorTarget + Pre-compute object file names before Makefile generation + Pre-compute object file names before VS project generation + Remove unused cmSourceGroup method + Rename/constify build-time config placeholder lookup + Pre-compute and store target object directory in cmGeneratorTarget + Add OBJECT_LIBRARY target type + Build object library targets in Makefiles + Build object library targets in VS + Add $ expression to use an object library + Test OBJECT library success cases + Test OBJECT library failure cases + Test OBJECT library language propagation + Test OBJECT library use without other sources + Document OBJECT library type in add_library command + Simplify cmNinjaTargetGenerator using cmGeneratorTarget + Pre-compute object file names before Ninja generation + Build object library targets in Ninja + Ninja: Honor $ source expressions + find_package: Test rejection of required+optional components + Simplify cmVisualStudio10TargetGenerator source classification + VS10: Fix external objects generated outside target (#13047) + Fix ObjectLibrary test on Watcom + KWIML: Avoid conflict with C++11 user-defined literals + +Christian Andersson (1): + FindPythonLibs: Search for single-user installs on Windows + +Christopher Sean Morrison (1): + cmake-mode.el: Make indentation case-insensitive (#12995) + +Clinton Stimpson (14): + GetPrerequisites: Add support for @rpath on Mac OS X. + GetPrerequisites: Add support for @rpath on Mac OS X. + GetPrerequisites: Add test for @rpath support. + Fix new BundleUtilities test failure on Mac 10.4.x + Fix BundleUtilities test failure with space in build path. + cmake-gui: Improve interrupt granularity to fix bug 12649. + FindQt4: clarify warning message about incorrect Qt installation. + FindQt4: Add include directories for lupdate. + Fix paths/hints for finding qtmain. + DragNDrop: Fix problem with relocated files in Xcode 4.3 + Add test for DeployQt4.cmake + Fix for Qt4Deploy on some test machines. + Remove QtGui dependency in Qt4Deploy test and verify QtSql existance. + DeployQt4: Add path to Qt dlls on Windows. + +Daniel Nelson (1): + CPack Add top level directory in component install for Archive Generators + +David Cole (33): + Begin post-2.8.7 development + Release: Increase timeout for slow-testing cygwin build + Update dashmacmini2 release script to use Qt 4.6.3 + Update dashmacmini2 release script to use Qt 4.8.0 + Tests: Update drop site value for the Trilinos contract test + Update version of Qt for dashmacmini5 produced release binaries + CTestCustom: Suppress clang warning on the dashboard + CMake: Eliminate cmMakefile::IncludeDirectories + Remove cmMakefile::GetIncludeDirectories + Make search paths ordered and unique + Call ExpandVariablesInString for each target's INCLUDE_DIRECTORIES + Update the documentation regarding INCLUDE_DIRECTORIES. + Fix compiler error reported on older Borland dashboard. + Fix compiler warning reported on older Borland dashboard. + Fix shadowed variable warning on dashboard results + Remove trailing white space + Use correct "requires" line in cygwin setup hint file + VS6: Avoid _MBCS define when _SBCS is defined (#12189) + VS6: Avoid SBCS test on VS6 (#12189) + Suppress warnings occurring on the dashboards using the PGI compiler. + CPack: Fix retry logic when calls to hdiutil fail + Ninja: CMake: Adapt Ninja generator for per-target include dirs + Ninja: Add friend struct so it can access the private ConvertToNinjaPath. + Xcode: Detect new default locations of Xcode 4.3 bits and pieces (#12621) + CPack: Use real path to PackageMaker to find its version file (#12621) + Xcode: Re-factor code into GetObjectsNormalDirectory method + Xcode: Re-factor some existing methods into "FromPath" variants + Add a default source group for object files. + Allow txt files as ExtraSources in object library targets + Pre-compute object file names before Xcode generation + Build object library targets in Xcode + Xcode: Honor $ source expressions + Tests: Relax restrictions on version variable contents + +Deborah Pickett (1): + CPackRPM flag direcories with %dir in the generated spec file + +Droscy (1): + FindCxxTest: Add support for CxxTest 4 (#13022) + +Eric NOULARD (41): + Document undocumented (but existing) cpack options (fix #0010134) + Enhance bash completion file for cmake and ctest + Do not add the content of a file if it's a symlink. + CPackArchive restore default behavior and provide new variable. + CPackNSIS fix #0012935 switch from LOG_WARNING to avoid final error. + CPack begin the implementation of --help-command* and --help-variables* + Implement simple CMake script comment markup language. + CPack Documentation extraction from CMake script begins to work + Update bash completion file in order to handle new CPack doc options. + Suppress unused var, beautify code, avoid 1 extra newline. + Fix potential bad memory access, thanks to Eike + Calm down compiler warning about unused var + Really avoid compiler warning about unused vars + Fix another compiler warning due to a typo + Make the load of script documentation more efficient and dynamic. + Example of builtin variable documentation (i.e. only used in C++ source code). + Add missing section markup for CPackComponent + Create getDocumentedModulesListInDir which may be used in other context. + Fix non existent std::string::clear on VS6 + Avoid discovering system infos for documentation. Adding some path is enough. + Dynamically add documentation section specified in documented script. + Add structured documentation for NSIS + Add structure documentation for CPack Bundle generator + Suppress unecessary (now empty) doc sections + Correct copy/paste section name mistake + Put CPack DMG and PackageMaker doc in separate files + More documentation concerning CPack Components + Fix typo in end markup + Try to fix compile error on Win32-vs70 + Do not build RPM if path of the build tree contains space + Fix layout of the CPack Bundle documentation + Fix CPack Drag and Drop generator documentation layout. + Review and update CPack variable documentation. + Update CPackConfig template. + Provide template for CPack Cygwin generator specific variables. + Update CPack PackageMaker variable doc layout + Typo: Add missing ##end for ##module + Fix some typos in CPACK_SET_DESTDIR doc + Add some missing CPACK_NSIS_xxx doc and move some to common CPack section. + CPack STGZ put execute permission on all packages files (component case) + Handle CPACK_MONOLITHIC_INSTALL in some rare use cases. + +Eugene Golushkov (1): + VS: Add support for WinRT project properties (#12930) + +James Bigler (1): + Added support for curand, cusparse, npp, nvcuenc and nvcuvid libraries. + +Jason Erb (1): + FindwxWidgets: Add webview library (#12636) + +LibArchive Upstream (2): + libarchive 3.0.1-r3950 (reduced) + libarchive 3.0.2-r4051 (reduced) + +Matthias Kretz (1): + Improve checks for Open64 and g++ incompatible flags (#12119) + +Mattias Helsing (1): + CPack: Fix NSIS handling of privileged users (#12923) + +Michael Wild (1): + GenerateExportHeader: Fix wrong use of IS_ABSOLUTE (#12645) + +Mike McQuaid (5): + Don't use QT_LIBRARIES_PLUGINS by default. + Fix mismatched arguments. + Fix bad plugin paths. + Ensure libs are passed to BundleUtilities. + Fix plugin installation issues. + +Modestas Vainius (3): + various typo and formatting fixes in manual pages (#12975) + KWIML: Teach ABI.h that MIPS is biendian + Tests: Escape metachars before embedding paths into the regex (#12999) + +Nicolas Despres (5): + ccmake: Factor clear line. + ccmake: Extend clear line. + java: Factor jar output path. + java: Add CMAKE_JAVA_TARGET_OUTPUT_DIR optional variable. + java: Add CMAKE_JAVA_JAR_ENTRY_POINT optional variable. + +Peter Collingbourne (19): + Add cmSystemTools::TrimWhitespace function + Add executable with exports flag support to cmLocalGenerator::GetTargetFlags + Provide dependency file flags to generator + Ninja: Add the Ninja generator + Ninja: Fix a 79-col violation + Ninja: Remove some default arguments + Ninja: Appease various compilers + Ninja: Partially revert "win fixes: escape back slash/colon, use cd. as cmd.exe nop" + Ninja: Identifier encoding rules for ' ' and ':' + Ninja: Backslash rules for Windows + Ninja: Shell encode paths used in "cd" commands + Ninja: Shell encode various CMake invocations + Ninja: Shell encode the command used in custom commands + Ninja: Import library support for Windows + Ninja: Add a missed license header + Ninja: Use cmSystemTools::ExpandListArgument to split compile/link commands + Ninja: Remove an unnecessary variable + Ninja: add support for OBJECT_OUTPUTS, fix PrecompiledHeader test case + Ninja: shell escape $(CMAKE_SOURCE_DIR) and $(CMAKE_BINARY_DIR) + +Peter Kuemmel (12): + Find VC Express during default generator selection (#12917) + Ninja: win fixes: escape back slash/colon, use cd. as cmd.exe nop + Ninja: don't define MSVC_IDE when using the ninja generator + Ninja: also build ninja support on Windows + Ninja: add some hacks for Windows + Ninja: disable unfinished Windows ninja support + Ninja: mark the Windows specific hacks with a comment only + Ninja: windows msvc: create for each target a .pdb file + Ninja: ensure the output dir exists at compile time + Ninja: add .def file support + Ninja: add /DEF: flag to linker call + Ninja: Fix substitution + +Philip Lowman (5): + FindProtobuf: Merge patch that allows extra import dirs + FindProtobuf: Update documentation comment for 2.8.8 + Findosg: New modules for osgQt and osgPresentation + FindALSA: Fix incorrect include path detection + FindALSA: Fix version detection after last commit + +Rolf Eike Beer (95): + remove reference to CVS directory when installing files + CheckSymbolExists: force the compiler to keep the referenced symbol + add a test for Check{,CXX}SymbolExists + FindOpenSSL: improve version number handling + FindOpenSSL: only try to parse opensslv.h if it exists + FindOpenSSL: also parse version number define with uppercase letters + GenerateExportHeader test: add newlines before end of file + add a test that loops through most Find* modules + AllFindModules test: keep complete output + AllFindModules test: also check Qt3 modules if Qt4 is not found + FindPythonInterp: make version selectable + FindPythonInterp: fix version parsing + LoadCommand test: cleanup + FindThreads: Try pthreads with no special option first (#11333) + fix uninitialized var in if(NOT foo bar STREQUAL "foo bar") + use pkg_check_modules() quiet in other modules + FindLibXml2: support version selection + FindGnuTLS: partly support version selection + FindGit: support version number + FindCups: major overhaul + FindEXPAT: support version number + FindCURL: support version selection + FindFLEX: fix version parsing for old flex versions + FindFLEX: fix version parsing when the executable is quoted + FindJasper: find debug libraries + FindJasper: support version number + FindBZip2: add support for version checking + FindBZip2: add support for debug libraries (#12867) + FindImageMagick: make use of more FPHSA features + FindPNG: support version selection + FindRuby: do not blindly set version to 1.8.0 + FindTclsh: support version selection + SelectLibraryConfigurations: do not output identical configurations + FindLua51: add version support + FindTIFF: support version selection + FindCURL: detect version number also for older versions + FindLibXml2: detect version when PkgConfig is not used + FindPostgreSQL: support version selection + FindOpenSSL: properly parse the hex version components + FindBISON: add a version expression for GNU Bison 1.x + FindPythonInterp: try harder to get a version number + FindJasper: fix library name + FindGnuplot: add version selection + FindALSA: support version selection + FindGettext: support version selection + CheckCXXCompilerFlag test: make it a CMakeOnly test + CMakeOnly.AllFindModules: clean up the Qt3/Qt4 code + CMakeOnly.AllFindModules: always check FindQt + CMakeOnly.AllFindModules: suppress two modules from testing + CMakeOnly.AllFindModules: require version for some modules + CheckIncludeFiles: fix status output + FindPerl{,Libs}: move version detection into FindPerl + FindLibArchive: support version selection + FindX11: also search for Xmu (#12447) + detect "pgfortran" as PGI Fortran compiler (#12425) + FindSDL*: use FPHSA (#12467) + AllFindModules test: do not enforce GNUPLOT version + FindPerlLibs: properly detect libperl on Windows (#12224) + CTest: mark all gcov covered files as covered + FindGLUT: honor REQUIRED (#12466) + FindRuby: clean up querying variables from Ruby + FindLibXslt: support version selection + Tests: document where to put tests + FindPkgConfig: support version selection of pkg-config itself + fix the same typos as found by Debian in other places, too + Find_library(): allow searching for versioned shared objects + FindFreetype: support version selection + AllFindModules test: expect more modules to have a version number available + FindOpenMP: do not fail if only C or CXX is enabled (#11910) + FindOpenMP: try the most likely flags first + FindOpenMP: simplify check for enabled languages + UseSWIG: clean up string compares + FindPython{Interp,Libs}: document Python_ADDITIONAL_VERSIONS as input + FindPythonLibs: make the version selection work as for PythonInterp + FindPythonLibs: get the exact version of the found library (#3080) + FindPythonLibs: put debug libraries into PYTHON_LIBRARIES + FindPythonLibs: stop scanning when libraries are found + Check{C,CXX}CompilerFlag: detect ICC error messages + GenerateExportHeader: remove unneeded code + GenerateExportHeader: improve compiler identification + FindOpenSceneGraph: give every message() with an explicit level + FindHSPELL: set HSPELL_VERSION_STRING + FindImageMagick: fix fail if no components were given + FindPythonInterp: rework the version detection + document when version detection will not work + AllFindModules test: once again expand version checking + improve error message on a stray "endwhile()" + add testcases for while()/endwhile() errors + reflect that the QtAutomoc depends on QtGui + FindQt3: fix warning when Qt3 is not found + FindQt3: fix version extraction for versions with letters + FindQt3: let FPHSA handle the version selection + FindQt3: fix detection of Qt3 include directory + AllFindModules test: do not require TCLSH version + add test for get_property() errors + +Stephen Kelly (13): + Fix typos arguement -> argument. + Exit the loop when we have determined the language. + Add whitespace after '.' in CMAKE_SKIP_RPATH docs. + Fix documented function signature to match reality. + Add default initializers for WIN32_EXECUTABLE and MACOSX_BUNDLE + Add an option to skip RPATH during installation. + Refactor GetIncludeFlags to take includes instead of fetching them + Make it safe to call this method without creating duplicates. + Remove include flags memoization. + Add API to get the ordered includes for a target. + Keep the INCLUDE_DIRECTORIES target property up to date. + Extract and use the INCLUDE_DIRECTORIES target properties. + Fix some typos in the docs comments. + +Yury G. Kudryashov (23): + FindDoxygen: add DOXYGEN_VERSION variable + cmInstallCommand: Fix indentation error + cmInstallCommand: Remove duplicated sentence from docs + FindPkgConfig: respect REQUIRED (#12620) + FindPackageHandleStandardArgs: fix documentation + Remove unused file cmake.1 + Fix typo in documentation + Drop if(...) check because condition is always true + CMakeFindPackageMode: fix 32/64bit detection if 'file' is a symlink + Run vim spellcheck on some files + cmPropertyDefinition::IsChained is const + Add 'const' qualifier to some cmCommand members + doxygen: cmPropertyDefinition + doxygen: Improve API docs of GetRealDependency + doxygen: Use proper syntax to document enum + doxygen: Small fixes in cmake.h apidocs + doxygen: fix some comments in cmPolicies.h + doxygen: remove a few comments + doxygen: review cmake.h + doxygen: MathCommand is not about string operators + Rename UsedCommands to FinalPassCommands + Remove UnionsAvailable member from 2 classes + Remove cmExprParserHelper::SetLineFile() + Changes in CMake 2.8.7 (since 2.8.7-rc2) -------------------------------------------- None diff --git a/Docs/cmake-completion b/Docs/cmake-completion index 011f3fa93..d70ac2445 100644 --- a/Docs/cmake-completion +++ b/Docs/cmake-completion @@ -51,13 +51,20 @@ _cmake() COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; + # FIXME: don't know how to handle multi words completion + # or more precisely word that contains space in them like "Unix Makefiles" + # -G) + # local running=$(for x in `cmake --help | grep "^ .*=\ .*" | grep -v "^ -" | cut -d"=" -f 1 | grep -v "^ "`; do echo \"${x}\" ; done ) + # COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) + # return 0 + # ;; --help-command) - local running=$(for x in `cmake --help-command-list`; do echo ${x} ; done ) + local running=$(for x in `cmake --help-command-list | grep -v "cmake version"`; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; --help-module) - local running=$(for x in `cmake --help-module-list`; do echo ${x} ; done ) + local running=$(for x in `cmake --help-module-list | grep -v "cmake version"`; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; @@ -67,12 +74,12 @@ _cmake() return 0 ;; --help-property) - local running=$(for x in `cmake --help-property-list`; do echo ${x} ; done ) + local running=$(for x in `cmake --help-property-list | grep -v "cmake version"`; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; --help-variable) - local running=$(for x in `cmake --help-variable-list`; do echo ${x} ; done ) + local running=$(for x in `cmake --help-variable-list | grep -v "cmake version"`; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; @@ -123,19 +130,29 @@ _cpack() COMPREPLY=( $(compgen -f ${cur}) ) return 0 ;; + --help-variable) + local running=$(for x in `cpack --help-variable-list | grep -v "cpack version" `; do echo ${x} ; done ) + COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) + return 0 + ;; + --help-command) + local running=$(for x in `cpack --help-command-list | grep -v "cpack version" `; do echo ${x} ; done ) + COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) + return 0 + ;; *) ;; esac # - # Complete the option (Level 0 - right after cmake) + # Complete the option (Level 0 - right after cpack) # COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) } && complete -F _cpack -o default cpack # -# cmake command +# ctest command # # have ctest && _ctest() @@ -156,11 +173,11 @@ _ctest() # case "${prev}" in --help-command) - local running=$(for x in `ctest --help-command-list`; do echo ${x} ; done ) + local running=$(for x in `ctest --help-command-list | grep -v "ctest version" `; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 ;; - -R) + -R|-E) local running=$(for x in `ctest -N 2> /dev/null | grep "^ Test" | cut -d: -f 2`; do echo ${x} ; done ) COMPREPLY=( $(compgen -W "${running}" -- ${cur}) ) return 0 @@ -187,4 +204,4 @@ complete -F _ctest -o default ctest # sh-indent-comment: t # indent-tabs-mode: nil # End: -# ex: ts=4 sw=4 et filetype=sh \ No newline at end of file +# ex: ts=4 sw=4 et filetype=sh diff --git a/Docs/cmake-mode.el b/Docs/cmake-mode.el index 2f51f830d..951745515 100644 --- a/Docs/cmake-mode.el +++ b/Docs/cmake-mode.el @@ -68,9 +68,9 @@ set the path with these commands: "\\|" "[ \t\r\n]" "\\)*")) (defconst cmake-regex-block-open - "^\\(IF\\|MACRO\\|FOREACH\\|ELSE\\|ELSEIF\\|WHILE\\|FUNCTION\\)$") + "^\\([iI][fF]\\|[mM][aA][cC][rR][oO]\\|[fF][oO][rR][eE][aA][cC][hH]\\|[eE][lL][sS][eE]\\|[eE][lL][sS][eE][iI][fF]\\|[wW][hH][iI][lL][eE]\\|[fF][uU][nN][cC][tT][iI][oO][nN]\\)$") (defconst cmake-regex-block-close - "^[ \t]*\\(ENDIF\\|ENDFOREACH\\|ENDMACRO\\|ELSE\\|ELSEIF\\|ENDWHILE\\|ENDFUNCTION\\)[ \t]*(") + "^[ \t]*\\([eE][nN][dD][iI][fF]\\|[eE][nN][dD][fF][oO][rR][eE][aA][cC][hH]\\|[eE][nN][dD][mM][aA][cC][rR][oO]\\|[eE][lL][sS][eE]\\|[eE][lL][sS][eE][iI][fF]\\|[eE][nN][dD][wW][hH][iI][lL][eE]\\|[eE][nN][dD][fF][uU][nN][cC][tT][iI][oO][nN]\\)[ \t]*(") ;------------------------------------------------------------------------------ @@ -99,6 +99,7 @@ set the path with these commands: (setq region (buffer-substring-no-properties (point) point-start)) (while (and (not (bobp)) (or (looking-at cmake-regex-blank) + (cmake-line-starts-inside-string) (not (and (string-match cmake-regex-indented region) (= (length region) (match-end 0)))))) (forward-line -1) diff --git a/Modules/AutomocInfo.cmake.in b/Modules/AutomocInfo.cmake.in index 29dab9759..13f21617b 100644 --- a/Modules/AutomocInfo.cmake.in +++ b/Modules/AutomocInfo.cmake.in @@ -1,9 +1,9 @@ -set(AM_SOURCES "@_moc_files@" ) -set(AM_HEADERS "@_moc_headers@" ) -set(AM_MOC_COMPILE_DEFINITIONS "@_moc_compile_defs@") -set(AM_MOC_DEFINITIONS "@_moc_defs@") -set(AM_MOC_INCLUDES "@_moc_incs@") -set(AM_MOC_OPTIONS "@_moc_options@") +set(AM_SOURCES @_moc_files@ ) +set(AM_HEADERS @_moc_headers@ ) +set(AM_MOC_COMPILE_DEFINITIONS @_moc_compile_defs@) +set(AM_MOC_DEFINITIONS @_moc_defs@) +set(AM_MOC_INCLUDES @_moc_incs@) +set(AM_MOC_OPTIONS @_moc_options@) set(AM_CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE "@CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE@") set(AM_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@/") set(AM_CMAKE_SOURCE_DIR "@CMAKE_SOURCE_DIR@/") @@ -12,5 +12,5 @@ set(AM_CMAKE_CURRENT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@/") set(AM_CMAKE_CURRENT_BINARY_DIR "@CMAKE_CURRENT_BINARY_DIR@/") set(AM_QT_VERSION_MAJOR "@QT_VERSION_MAJOR@" ) set(AM_Qt5Core_VERSION_MAJOR "@Qt5Core_VERSION_MAJOR@" ) -set(AM_TARGET_NAME "@_moc_target_name@") +set(AM_TARGET_NAME @_moc_target_name@) set(AM_RELAXED_MODE "@_moc_relaxed_mode@") diff --git a/Modules/BasicConfigVersion-ExactVersion.cmake.in b/Modules/BasicConfigVersion-ExactVersion.cmake.in new file mode 100644 index 000000000..c610baa28 --- /dev/null +++ b/Modules/BasicConfigVersion-ExactVersion.cmake.in @@ -0,0 +1,42 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is equal to the requested version. +# The tweak version component is ignored. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "@CVF_VERSION@") + +if("@CVF_VERSION@" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\..*") # strip the tweak version + set(CVF_VERSION_NO_TWEAK "${CMAKE_MATCH_1}") +else() + set(CVF_VERSION_NO_TWEAK "@CVF_VERSION@") +endif() + +if("${PACKAGE_FIND_VERSION}" MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)\\..*") # strip the tweak version + set(REQUESTED_VERSION_NO_TWEAK "${CMAKE_MATCH_1}") +else() + set(REQUESTED_VERSION_NO_TWEAK "${PACKAGE_FIND_VERSION}") +endif() + +if("${REQUESTED_VERSION_NO_TWEAK}" STREQUAL "${CVF_VERSION_NO_TWEAK}") + set(PACKAGE_VERSION_COMPATIBLE TRUE) +else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) +endif() + +if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) +endif() + + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "@CMAKE_SIZEOF_VOID_P@") + math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/Modules/CMakeAddFortranSubdirectory.cmake b/Modules/CMakeAddFortranSubdirectory.cmake new file mode 100644 index 000000000..abd910055 --- /dev/null +++ b/Modules/CMakeAddFortranSubdirectory.cmake @@ -0,0 +1,206 @@ +# - Use MinGW gfortran from VS if a fortran compiler is not found. +# The 'add_fortran_subdirectory' function adds a subdirectory +# to a project that contains a fortran only sub-project. The module +# will check the current compiler and see if it can support fortran. +# If no fortran compiler is found and the compiler is MSVC, then +# this module will find the MinGW gfortran. It will then use +# an external project to build with the MinGW tools. It will also +# create imported targets for the libraries created. This will only +# work if the fortran code is built into a dll, so BUILD_SHARED_LIBS +# is turned on in the project. In addition the CMAKE_GNUtoMS option +# is set to on, so that the MS .lib files are created. +# Usage is as follows: +# cmake_add_fortran_subdirectory( +# # name of subdirectory +# PROJECT # project name in subdir top CMakeLists.txt +# ARCHIVE_DIR # dir where project places .lib files +# RUNTIME_DIR # dir where project places .dll files +# LIBRARIES ... # names of library targets to import +# LINK_LIBRARIES # link interface libraries for LIBRARIES +# [LINK_LIBS ...]... +# CMAKE_COMMAND_LINE ... # extra command line flags to pass to cmake +# NO_EXTERNAL_INSTALL # skip installation of external project +# ) +# Relative paths in ARCHIVE_DIR and RUNTIME_DIR are interpreted with respect +# to the build directory corresponding to the source directory in which the +# function is invoked. +# +# Limitations: +# +# NO_EXTERNAL_INSTALL is required for forward compatibility with a +# future version that supports installation of the external project +# binaries during "make install". + +#============================================================================= +# Copyright 2011-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + + +set(_MS_MINGW_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) +include(CheckLanguage) +include(ExternalProject) +include(CMakeParseArguments) + +function(_setup_mingw_config_and_build source_dir build_dir) + # Look for a MinGW gfortran. + find_program(MINGW_GFORTRAN + NAMES gfortran + PATHS + c:/MinGW/bin + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MinGW;InstallLocation]/bin" + ) + if(NOT MINGW_GFORTRAN) + message(FATAL_ERROR + "gfortran not found, please install MinGW with the gfortran option." + "Or set the cache variable MINGW_GFORTRAN to the full path. " + " This is required to build") + endif() + + # Validate the MinGW gfortran we found. + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_mingw_target "Target:.*64.*mingw") + else() + set(_mingw_target "Target:.*mingw32") + endif() + execute_process(COMMAND "${MINGW_GFORTRAN}" -v + ERROR_VARIABLE out ERROR_STRIP_TRAILING_WHITESPACE) + if(NOT "${out}" MATCHES "${_mingw_target}") + string(REPLACE "\n" "\n " out " ${out}") + message(FATAL_ERROR + "MINGW_GFORTRAN is set to\n" + " ${MINGW_GFORTRAN}\n" + "which is not a MinGW gfortran for this architecture. " + "The output from -v does not match \"${_mingw_target}\":\n" + "${out}\n" + "Set MINGW_GFORTRAN to a proper MinGW gfortran for this architecture." + ) + endif() + + # Configure scripts to run MinGW tools with the proper PATH. + get_filename_component(MINGW_PATH ${MINGW_GFORTRAN} PATH) + file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH) + string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}") + configure_file( + ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/config_mingw.cmake.in + ${build_dir}/config_mingw.cmake + @ONLY) + configure_file( + ${_MS_MINGW_SOURCE_DIR}/CMakeAddFortranSubdirectory/build_mingw.cmake.in + ${build_dir}/build_mingw.cmake + @ONLY) +endfunction() + +function(_add_fortran_library_link_interface library depend_library) + set_target_properties(${library} PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "${depend_library}") +endfunction() + + +function(cmake_add_fortran_subdirectory subdir) + # Parse arguments to function + set(options NO_EXTERNAL_INSTALL) + set(oneValueArgs PROJECT ARCHIVE_DIR RUNTIME_DIR) + set(multiValueArgs LIBRARIES LINK_LIBRARIES CMAKE_COMMAND_LINE) + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + if(NOT ARGS_NO_EXTERNAL_INSTALL) + message(FATAL_ERROR + "Option NO_EXTERNAL_INSTALL is required (for forward compatibility) " + "but was not given." + ) + endif() + + # if we are not using MSVC without fortran support + # then just use the usual add_subdirectory to build + # the fortran library + check_language(Fortran) + if(NOT (MSVC AND (NOT CMAKE_Fortran_COMPILER))) + add_subdirectory(${subdir}) + return() + endif() + + # if we have MSVC without Intel fortran then setup + # external projects to build with mingw fortran + + set(source_dir "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}") + set(project_name "${ARGS_PROJECT}") + set(library_dir "${ARGS_ARCHIVE_DIR}") + set(binary_dir "${ARGS_RUNTIME_DIR}") + set(libraries ${ARGS_LIBRARIES}) + # use the same directory that add_subdirectory would have used + set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}") + foreach(dir_var library_dir binary_dir) + if(NOT IS_ABSOLUTE "${${dir_var}}") + get_filename_component(${dir_var} + "${CMAKE_CURRENT_BINARY_DIR}/${${dir_var}}" ABSOLUTE) + endif() + endforeach() + # create build and configure wrapper scripts + _setup_mingw_config_and_build("${source_dir}" "${build_dir}") + # create the external project + externalproject_add(${project_name}_build + SOURCE_DIR ${source_dir} + BINARY_DIR ${build_dir} + CONFIGURE_COMMAND ${CMAKE_COMMAND} + -P ${build_dir}/config_mingw.cmake + BUILD_COMMAND ${CMAKE_COMMAND} + -P ${build_dir}/build_mingw.cmake + INSTALL_COMMAND "" + ) + # make the external project always run make with each build + externalproject_add_step(${project_name}_build forcebuild + COMMAND ${CMAKE_COMMAND} + -E remove + ${CMAKE_CURRENT_BUILD_DIR}/${project_name}-prefix/src/${project_name}-stamp/${project_name}-build + DEPENDEES configure + DEPENDERS build + ALWAYS 1 + ) + # create imported targets for all libraries + foreach(lib ${libraries}) + add_library(${lib} SHARED IMPORTED GLOBAL) + set_property(TARGET ${lib} APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG) + set_target_properties(${lib} PROPERTIES + IMPORTED_IMPLIB_NOCONFIG "${library_dir}/lib${lib}.lib" + IMPORTED_LOCATION_NOCONFIG "${binary_dir}/lib${lib}.dll" + ) + add_dependencies(${lib} ${project_name}_build) + endforeach() + + # now setup link libraries for targets + set(start FALSE) + set(target) + foreach(lib ${ARGS_LINK_LIBRARIES}) + if("${lib}" STREQUAL "LINK_LIBS") + set(start TRUE) + else() + if(start) + if(DEFINED target) + # process current target and target_libs + _add_fortran_library_link_interface(${target} "${target_libs}") + # zero out target and target_libs + set(target) + set(target_libs) + endif() + # save the current target and set start to FALSE + set(target ${lib}) + set(start FALSE) + else() + # append the lib to target_libs + list(APPEND target_libs "${lib}") + endif() + endif() + endforeach() + # process anything that is left in target and target_libs + if(DEFINED target) + _add_fortran_library_link_interface(${target} "${target_libs}") + endif() +endfunction() diff --git a/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in b/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in new file mode 100644 index 000000000..55b271a2d --- /dev/null +++ b/Modules/CMakeAddFortranSubdirectory/build_mingw.cmake.in @@ -0,0 +1,2 @@ +set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}") +execute_process(COMMAND "@CMAKE_COMMAND@" --build . ) diff --git a/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in b/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in new file mode 100644 index 000000000..97f67693a --- /dev/null +++ b/Modules/CMakeAddFortranSubdirectory/config_mingw.cmake.in @@ -0,0 +1,9 @@ +set(ENV{PATH} "@MINGW_PATH@\;$ENV{PATH}") +set(CMAKE_COMMAND_LINE "@ARGS_CMAKE_COMMAND_LINE@") +execute_process( + COMMAND "@CMAKE_COMMAND@" "-GMinGW Makefiles" + -DCMAKE_Fortran_COMPILER:PATH=@MINGW_GFORTRAN@ + -DBUILD_SHARED_LIBS=ON + -DCMAKE_GNUtoMS=ON + ${CMAKE_COMMAND_LINE} + "@source_dir@") diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 04a5cec6d..b14cf3427 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -1,6 +1,7 @@ SET(CMAKE_C_COMPILER "@CMAKE_C_COMPILER@") SET(CMAKE_C_COMPILER_ARG1 "@CMAKE_C_COMPILER_ARG1@") SET(CMAKE_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@") +SET(CMAKE_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@") SET(CMAKE_C_PLATFORM_ID "@CMAKE_C_PLATFORM_ID@") @SET_MSVC_C_ARCHITECTURE_ID@ SET(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 4cc690a26..06aa9bf06 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -2,27 +2,68 @@ # error "A C++ compiler has been selected for C." #endif +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + #if defined(__18CXX) # define ID_VOID_MAIN #endif #if defined(__INTEL_COMPILER) || defined(__ICC) # define COMPILER_ID "Intel" + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif #elif defined(__clang__) # define COMPILER_ID "Clang" +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) #elif defined(__BORLANDC__) # define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) #elif defined(__WATCOMC__) # define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC(__WATCOMC__ % 100) #elif defined(__SUNPRO_C) # define COMPILER_ID "SunPro" +# if __SUNPRO_C >= 0x5100 + /* __SUNPRO_C = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# else + /* __SUNPRO_C = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# endif #elif defined(__HP_cc) # define COMPILER_ID "HP" + /* __HP_cc = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) #elif defined(__DECC) # define COMPILER_ID "Compaq" @@ -30,14 +71,25 @@ #elif defined(__IBMC__) # if defined(__COMPILER_VER__) # define COMPILER_ID "zOS" -# elif __IBMC__ >= 800 -# define COMPILER_ID "XL" # else -# define COMPILER_ID "VisualAge" +# if __IBMC__ >= 800 +# define COMPILER_ID "XL" +# else +# define COMPILER_ID "VisualAge" +# endif + /* __IBMC__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) # endif #elif defined(__PGI) # define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif #elif defined(__PATHSCALE__) # define COMPILER_ID "PathScale" @@ -56,9 +108,29 @@ #elif defined(__GNUC__) # define COMPILER_ID "GNU" +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif #elif defined(_MSC_VER) # define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) /* Analog Devices C++ compiler for Blackfin, TigerSHARC and @@ -78,6 +150,17 @@ #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) # define COMPILER_ID "MIPSpro" +# if defined(_SGI_COMPILER_VERSION) + /* _SGI_COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) +# else + /* _COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) +# endif /* This compiler is either not known or is too old to define an identification macro. Try to identify the platform and guess that @@ -112,6 +195,9 @@ int main(int argc, char* argv[]) require += info_compiler[argc]; require += info_platform[argc]; require += info_arch[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif (void)argv; return require; } diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index ea06526cc..bc3bc2efb 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -1,6 +1,7 @@ SET(CMAKE_CXX_COMPILER "@CMAKE_CXX_COMPILER@") SET(CMAKE_CXX_COMPILER_ARG1 "@CMAKE_CXX_COMPILER_ARG1@") SET(CMAKE_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@") +SET(CMAKE_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@") SET(CMAKE_CXX_PLATFORM_ID "@CMAKE_CXX_PLATFORM_ID@") @SET_MSVC_CXX_ARCHITECTURE_ID@ SET(CMAKE_AR "@CMAKE_AR@") diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index 4c8f4972c..95fc852d6 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -5,26 +5,67 @@ # error "A C compiler has been selected for C++." #endif +/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */ + #if defined(__COMO__) # define COMPILER_ID "Comeau" #elif defined(__INTEL_COMPILER) || defined(__ICC) # define COMPILER_ID "Intel" + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif #elif defined(__clang__) # define COMPILER_ID "Clang" +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) + +#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) +# define COMPILER_ID "Embarcadero" +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) #elif defined(__BORLANDC__) # define COMPILER_ID "Borland" + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) #elif defined(__WATCOMC__) # define COMPILER_ID "Watcom" + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC(__WATCOMC__ % 100) #elif defined(__SUNPRO_CC) # define COMPILER_ID "SunPro" +# if __SUNPRO_CC >= 0x5100 + /* __SUNPRO_CC = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# endif #elif defined(__HP_aCC) # define COMPILER_ID "HP" + /* __HP_aCC = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) #elif defined(__DECCXX) # define COMPILER_ID "Compaq" @@ -32,14 +73,25 @@ #elif defined(__IBMCPP__) # if defined(__COMPILER_VER__) # define COMPILER_ID "zOS" -# elif __IBMCPP__ >= 800 -# define COMPILER_ID "XL" # else -# define COMPILER_ID "VisualAge" +# if __IBMCPP__ >= 800 +# define COMPILER_ID "XL" +# else +# define COMPILER_ID "VisualAge" +# endif + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) # endif #elif defined(__PGI) # define COMPILER_ID "PGI" +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif #elif defined(__PATHSCALE__) # define COMPILER_ID "PathScale" @@ -55,9 +107,29 @@ #elif defined(__GNUC__) # define COMPILER_ID "GNU" +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif #elif defined(_MSC_VER) # define COMPILER_ID "MSVC" + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif #elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) /* Analog Devices C++ compiler for Blackfin, TigerSHARC and @@ -66,6 +138,17 @@ #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) # define COMPILER_ID "MIPSpro" +# if defined(_SGI_COMPILER_VERSION) + /* _SGI_COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) +# else + /* _COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) +# endif /* This compiler is either not known or is too old to define an identification macro. Try to identify the platform and guess that @@ -96,6 +179,9 @@ int main(int argc, char* argv[]) int require = 0; require += info_compiler[argc]; require += info_platform[argc]; +#ifdef COMPILER_VERSION_MAJOR + require += info_version[argc]; +#endif (void)argv; return require; } diff --git a/Modules/CMakeCXXInformation.cmake b/Modules/CMakeCXXInformation.cmake index b97a69c3b..25abb8c39 100644 --- a/Modules/CMakeCXXInformation.cmake +++ b/Modules/CMakeCXXInformation.cmake @@ -93,12 +93,6 @@ IF(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX) ENDIF() -# for most systems a module is the same as a shared library -# so unless the variable CMAKE_MODULE_EXISTS is set just -# copy the values from the LIBRARY variables -IF(NOT CMAKE_MODULE_EXISTS) - SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -ENDIF(NOT CMAKE_MODULE_EXISTS) # Create a set of shared library variable specific to C++ # For 90% of the systems, these are the same flags as the C versions # so if these are not set just copy the flags from the c version @@ -158,6 +152,14 @@ IF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX) SET(CMAKE_INCLUDE_FLAG_SEP_CXX ${CMAKE_INCLUDE_FLAG_SEP_C}) ENDIF(NOT CMAKE_INCLUDE_FLAG_SEP_CXX) +# for most systems a module is the same as a shared library +# so unless the variable CMAKE_MODULE_EXISTS is set just +# copy the values from the LIBRARY variables +IF(NOT CMAKE_MODULE_EXISTS) + SET(CMAKE_SHARED_MODULE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS}) +ENDIF(NOT CMAKE_MODULE_EXISTS) + # repeat for modules IF(NOT CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS) SET(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index b160dee62..686cc9b6a 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -55,8 +55,13 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) # Display the final identification result. IF(CMAKE_${lang}_COMPILER_ID) + IF(CMAKE_${lang}_COMPILER_VERSION) + SET(_version " ${CMAKE_${lang}_COMPILER_VERSION}") + ELSE() + SET(_version "") + ENDIF() MESSAGE(STATUS "The ${lang} compiler identification is " - "${CMAKE_${lang}_COMPILER_ID}") + "${CMAKE_${lang}_COMPILER_ID}${_version}") ELSE(CMAKE_${lang}_COMPILER_ID) MESSAGE(STATUS "The ${lang} compiler identification is unknown") ENDIF(CMAKE_${lang}_COMPILER_ID) @@ -65,6 +70,7 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) SET(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) SET(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" PARENT_SCOPE) + SET(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID) #----------------------------------------------------------------------------- @@ -177,9 +183,10 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) IF(NOT CMAKE_${lang}_COMPILER_ID) # Read the compiler identification string from the executable file. SET(COMPILER_ID) + SET(COMPILER_VERSION) SET(PLATFORM_ID) FILE(STRINGS ${file} - CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 3 REGEX "INFO:") + CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 4 REGEX "INFO:") SET(HAVE_COMPILER_TWICE 0) FOREACH(info ${CMAKE_${lang}_COMPILER_ID_STRINGS}) IF("${info}" MATCHES ".*INFO:compiler\\[([^]\"]*)\\].*") @@ -197,6 +204,11 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) STRING(REGEX REPLACE ".*INFO:arch\\[([^]]*)\\].*" "\\1" ARCHITECTURE_ID "${info}") ENDIF("${info}" MATCHES ".*INFO:arch\\[([^]\"]*)\\].*") + IF("${info}" MATCHES ".*INFO:compiler_version\\[([^]\"]*)\\].*") + STRING(REGEX REPLACE ".*INFO:compiler_version\\[([^]]*)\\].*" "\\1" COMPILER_VERSION "${info}") + STRING(REGEX REPLACE "^0+([0-9])" "\\1" COMPILER_VERSION "${COMPILER_VERSION}") + STRING(REGEX REPLACE "\\.0+([0-9])" ".\\1" COMPILER_VERSION "${COMPILER_VERSION}") + ENDIF("${info}" MATCHES ".*INFO:compiler_version\\[([^]\"]*)\\].*") ENDFOREACH(info) # Check if a valid compiler and platform were found. @@ -204,6 +216,7 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) SET(CMAKE_${lang}_COMPILER_ID "${COMPILER_ID}") SET(CMAKE_${lang}_PLATFORM_ID "${PLATFORM_ID}") SET(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}") + SET(CMAKE_${lang}_COMPILER_VERSION "${COMPILER_VERSION}") ENDIF(COMPILER_ID AND NOT COMPILER_ID_TWICE) # Check the compiler identification string. @@ -251,6 +264,7 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang file) SET(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) SET(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" PARENT_SCOPE) + SET(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_${lang}_COMPILER_VERSION}" PARENT_SCOPE) SET(CMAKE_EXECUTABLE_FORMAT "${CMAKE_EXECUTABLE_FORMAT}" PARENT_SCOPE) ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID_CHECK lang) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index efcba29cf..ade6d586c 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -50,7 +50,7 @@ IF(NOT CMAKE_Fortran_COMPILER) # fort77: native F77 compiler under HP-UX (and some older Crays) # frt: Fujitsu F77 compiler # pathf90/pathf95/pathf2003: PathScale Fortran compiler - # pgf77/pgf90/pgf95: Portland Group F77/F90/F95 compilers + # pgf77/pgf90/pgf95/pgfortran: Portland Group F77/F90/F95 compilers # xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers # lf95: Lahey-Fujitsu F95 compiler # fl32: Microsoft Fortran 77 "PowerStation" compiler @@ -64,8 +64,8 @@ IF(NOT CMAKE_Fortran_COMPILER) # then 77 or older compilers, gnu is always last in the group, # so if you paid for a compiler it is picked by default. SET(CMAKE_Fortran_COMPILER_LIST - ifort ifc af95 af90 efc f95 pathf2003 pathf95 pgf95 lf95 xlf95 fort - gfortran gfortran-4 g95 f90 pathf90 pgf90 xlf90 epcf90 fort77 + ifort ifc af95 af90 efc f95 pathf2003 pathf95 pgf95 pgfortran lf95 xlf95 + fort gfortran gfortran-4 g95 f90 pathf90 pgf90 xlf90 epcf90 fort77 frt pgf77 xlf fl32 af77 g77 f77 ) @@ -73,7 +73,7 @@ IF(NOT CMAKE_Fortran_COMPILER) SET(_Fortran_COMPILER_NAMES_GNU gfortran gfortran-4 g95 g77) SET(_Fortran_COMPILER_NAMES_Intel ifort ifc efc) SET(_Fortran_COMPILER_NAMES_Absoft af95 af90 af77) - SET(_Fortran_COMPILER_NAMES_PGI pgf95 pgf90 pgf77) + SET(_Fortran_COMPILER_NAMES_PGI pgf95 pgfortran pgf90 pgf77) SET(_Fortran_COMPILER_NAMES_PathScale pathf2003 pathf95 pathf90) SET(_Fortran_COMPILER_NAMES_XL xlf) SET(_Fortran_COMPILER_NAMES_VisualAge xlf95 xlf90 xlf) diff --git a/Modules/CMakeExpandImportedTargets.cmake b/Modules/CMakeExpandImportedTargets.cmake new file mode 100644 index 000000000..fba071a06 --- /dev/null +++ b/Modules/CMakeExpandImportedTargets.cmake @@ -0,0 +1,129 @@ +# CMAKE_EXPAND_IMPORTED_TARGETS( LIBRARIES lib1 lib2...libN +# [CONFIGURATION ] ) +# +# CMAKE_EXPAND_IMPORTED_TARGETS() takes a list of libraries and replaces +# all imported targets contained in this list with their actual file paths +# of the referenced libraries on disk, including the libraries from their +# link interfaces. +# If a CONFIGURATION is given, it uses the respective configuration of the +# imported targets if it exists. If no CONFIGURATION is given, it uses +# the first configuration from ${CMAKE_CONFIGURATION_TYPES} if set, otherwise +# ${CMAKE_BUILD_TYPE}. +# This macro is used by all Check*.cmake files which use +# TRY_COMPILE() or TRY_RUN() and support CMAKE_REQUIRED_LIBRARIES , so that +# these checks support imported targets in CMAKE_REQUIRED_LIBRARIES: +# cmake_expand_imported_targets(expandedLibs LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} +# CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}" ) + + +#============================================================================= +# Copyright 2012 Kitware, Inc. +# Copyright 2009-2012 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +include(CMakeParseArguments) + +function(CMAKE_EXPAND_IMPORTED_TARGETS _RESULT ) + + set(options ) + set(oneValueArgs CONFIGURATION ) + set(multiValueArgs LIBRARIES ) + + cmake_parse_arguments(CEIT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(CEIT_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to CMAKE_EXPAND_IMPORTED_TARGETS(): \"${CEIT_UNPARSED_ARGUMENTS}\"") + endif() + + if(NOT CEIT_CONFIGURATION) + if(CMAKE_CONFIGURATION_TYPES) + list(GET CMAKE_CONFIGURATION_TYPES 0 CEIT_CONFIGURATION) + else() + set(CEIT_CONFIGURATION ${CMAKE_BUILD_TYPE}) + endif() + endif() + + # handle imported library targets + + set(_CCSR_REQ_LIBS ${CEIT_LIBRARIES}) + + set(_CHECK_FOR_IMPORTED_TARGETS TRUE) + set(_CCSR_LOOP_COUNTER 0) + while(_CHECK_FOR_IMPORTED_TARGETS) + math(EXPR _CCSR_LOOP_COUNTER "${_CCSR_LOOP_COUNTER} + 1 ") + set(_CCSR_NEW_REQ_LIBS ) + set(_CHECK_FOR_IMPORTED_TARGETS FALSE) + foreach(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + get_target_property(_importedConfigs "${_CURRENT_LIB}" IMPORTED_CONFIGURATIONS) + if (_importedConfigs) +# message(STATUS "Detected imported target ${_CURRENT_LIB}") + # Ok, so this is an imported target. + # First we get the imported configurations. + # Then we get the location of the actual library on disk of the first configuration. + # then we'll get its link interface libraries property, + # iterate through it and replace all imported targets we find there + # with there actual location. + + # guard against infinite loop: abort after 100 iterations ( 100 is arbitrary chosen) + if ("${_CCSR_LOOP_COUNTER}" LESS 100) + set(_CHECK_FOR_IMPORTED_TARGETS TRUE) +# else ("${_CCSR_LOOP_COUNTER}" LESS 1) +# message(STATUS "********* aborting loop, counter : ${_CCSR_LOOP_COUNTER}") + endif ("${_CCSR_LOOP_COUNTER}" LESS 100) + + # if one of the imported configurations equals ${CMAKE_TRY_COMPILE_CONFIGURATION}, + # use it, otherwise simply use the first one: + list(FIND _importedConfigs "${CEIT_CONFIGURATION}" _configIndexToUse) + if("${_configIndexToUse}" EQUAL -1) + set(_configIndexToUse 0) + endif("${_configIndexToUse}" EQUAL -1) + list(GET _importedConfigs ${_configIndexToUse} _importedConfigToUse) + + get_target_property(_importedLocation "${_CURRENT_LIB}" IMPORTED_LOCATION_${_importedConfigToUse}) + get_target_property(_linkInterfaceLibs "${_CURRENT_LIB}" IMPORTED_LINK_INTERFACE_LIBRARIES_${_importedConfigToUse} ) + + list(APPEND _CCSR_NEW_REQ_LIBS "${_importedLocation}") +# message(STATUS "Appending lib ${_CURRENT_LIB} as ${_importedLocation}") + if(_linkInterfaceLibs) + foreach(_currentLinkInterfaceLib ${_linkInterfaceLibs}) +# message(STATUS "Appending link interface lib ${_currentLinkInterfaceLib}") + if(_currentLinkInterfaceLib) + list(APPEND _CCSR_NEW_REQ_LIBS "${_currentLinkInterfaceLib}" ) + endif(_currentLinkInterfaceLib) + endforeach(_currentLinkInterfaceLib "${_linkInterfaceLibs}") + endif(_linkInterfaceLibs) + else(_importedConfigs) + # "Normal" libraries are just used as they are. + list(APPEND _CCSR_NEW_REQ_LIBS "${_CURRENT_LIB}" ) +# message(STATUS "Appending lib directly: ${_CURRENT_LIB}") + endif(_importedConfigs) + endforeach(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + + set(_CCSR_REQ_LIBS ${_CCSR_NEW_REQ_LIBS} ) + endwhile(_CHECK_FOR_IMPORTED_TARGETS) + + # Finally we iterate once more over all libraries. This loop only removes + # all remaining imported target names (there shouldn't be any left anyway). + set(_CCSR_NEW_REQ_LIBS ) + foreach(_CURRENT_LIB ${_CCSR_REQ_LIBS}) + get_target_property(_importedConfigs "${_CURRENT_LIB}" IMPORTED_CONFIGURATIONS) + if (NOT _importedConfigs) + list(APPEND _CCSR_NEW_REQ_LIBS "${_CURRENT_LIB}" ) +# message(STATUS "final: appending ${_CURRENT_LIB}") + else (NOT _importedConfigs) +# message(STATUS "final: skipping ${_CURRENT_LIB}") + endif (NOT _importedConfigs) + endforeach(_CURRENT_LIB ${_CCSR_REQ_LIBS}) +# message(STATUS "setting -${_RESULT}- to -${_CCSR_NEW_REQ_LIBS}-") + set(${_RESULT} "${_CCSR_NEW_REQ_LIBS}" PARENT_SCOPE) + +endfunction() diff --git a/Modules/CMakeFindEclipseCDT4.cmake b/Modules/CMakeFindEclipseCDT4.cmake index dd061280f..a4264e78e 100644 --- a/Modules/CMakeFindEclipseCDT4.cmake +++ b/Modules/CMakeFindEclipseCDT4.cmake @@ -20,7 +20,9 @@ FIND_PROGRAM(CMAKE_ECLIPSE_EXECUTABLE NAMES eclipse DOC "The Eclipse executable" FUNCTION(_FIND_ECLIPSE_VERSION) # This code is in a function so the variables used here have only local scope IF(CMAKE_ECLIPSE_EXECUTABLE) - GET_FILENAME_COMPONENT(_ECLIPSE_DIR "${CMAKE_ECLIPSE_EXECUTABLE}" PATH) + # use REALPATH to resolve symlinks (http://public.kitware.com/Bug/view.php?id=13036) + GET_FILENAME_COMPONENT(_REALPATH_CMAKE_ECLIPSE_EXECUTABLE "${CMAKE_ECLIPSE_EXECUTABLE}" REALPATH) + GET_FILENAME_COMPONENT(_ECLIPSE_DIR "${_REALPATH_CMAKE_ECLIPSE_EXECUTABLE}" PATH) FILE(GLOB _ECLIPSE_FEATURE_DIR "${_ECLIPSE_DIR}/features/org.eclipse.platform*") IF("${_ECLIPSE_FEATURE_DIR}" MATCHES ".+org.eclipse.platform_([0-9]+\\.[0-9]+).+") SET(_ECLIPSE_VERSION ${CMAKE_MATCH_1}) diff --git a/Modules/CMakeFindPackageMode.cmake b/Modules/CMakeFindPackageMode.cmake index 42965773a..59c7ba5ee 100644 --- a/Modules/CMakeFindPackageMode.cmake +++ b/Modules/CMakeFindPackageMode.cmake @@ -71,7 +71,8 @@ if(UNIX) # use the file utility to check whether itself is 64 bit: find_program(FILE_EXECUTABLE file) if(FILE_EXECUTABLE) - execute_process(COMMAND "${FILE_EXECUTABLE}" "${FILE_EXECUTABLE}" OUTPUT_VARIABLE fileOutput ERROR_QUIET) + get_filename_component(FILE_ABSPATH "${FILE_EXECUTABLE}" ABSOLUTE) + execute_process(COMMAND "${FILE_ABSPATH}" "${FILE_ABSPATH}" OUTPUT_VARIABLE fileOutput ERROR_QUIET) if("${fileOutput}" MATCHES "64-bit") set(CMAKE_SIZEOF_VOID_P 8) endif() diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index aed1fd2df..76cf34e9f 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -109,6 +109,14 @@ IF(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG) SET(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_C_FLAG}) ENDIF() +# for most systems a module is the same as a shared library +# so unless the variable CMAKE_MODULE_EXISTS is set just +# copy the values from the LIBRARY variables +IF(NOT CMAKE_MODULE_EXISTS) + SET(CMAKE_SHARED_MODULE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_Fortran_FLAGS}) + SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS}) +ENDIF(NOT CMAKE_MODULE_EXISTS) + # repeat for modules IF(NOT DEFINED CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS) SET(CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS ${CMAKE_SHARED_MODULE_CREATE_C_FLAGS}) diff --git a/Modules/CMakeGenericSystem.cmake b/Modules/CMakeGenericSystem.cmake index 6cd8fe6a4..ee8040e3b 100644 --- a/Modules/CMakeGenericSystem.cmake +++ b/Modules/CMakeGenericSystem.cmake @@ -39,6 +39,8 @@ SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) SET (CMAKE_SKIP_RPATH "NO" CACHE BOOL "If set, runtime paths are not added when using shared libraries.") +SET (CMAKE_SKIP_INSTALL_RPATH "NO" CACHE BOOL + "If set, runtime paths are not added when installing shared libraries, but are added when building.") SET(CMAKE_VERBOSE_MAKEFILE FALSE CACHE BOOL "If this value is on, makefiles will be generated without the .SILENT directive, and all commands will be echoed to the console during the make. This is useful for debugging only. With Visual Studio IDE projects all commands are done without /nologo.") @@ -168,5 +170,6 @@ ENDIF(CMAKE_HOST_UNIX) MARK_AS_ADVANCED( CMAKE_SKIP_RPATH + CMAKE_SKIP_INSTALL_RPATH CMAKE_VERBOSE_MAKEFILE ) diff --git a/Modules/CMakeNinjaFindMake.cmake b/Modules/CMakeNinjaFindMake.cmake new file mode 100644 index 000000000..f15c3e0d4 --- /dev/null +++ b/Modules/CMakeNinjaFindMake.cmake @@ -0,0 +1,17 @@ + +#============================================================================= +# Copyright 2011 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +FIND_PROGRAM(CMAKE_MAKE_PROGRAM ninja + DOC "Program used to build from build.ninja files.") +MARK_AS_ADVANCED(CMAKE_MAKE_PROGRAM) diff --git a/Modules/CMakePackageConfigHelpers.cmake b/Modules/CMakePackageConfigHelpers.cmake new file mode 100644 index 000000000..48039e522 --- /dev/null +++ b/Modules/CMakePackageConfigHelpers.cmake @@ -0,0 +1,227 @@ +# - CONFIGURE_PACKAGE_CONFIG_FILE(), WRITE_BASIC_PACKAGE_VERSION_FILE() +# +# CONFIGURE_PACKAGE_CONFIG_FILE( INSTALL_DESTINATION +# [PATH_VARS ... ] +# [NO_SET_AND_CHECK_MACRO] +# [NO_CHECK_REQUIRED_COMPONENTS_MACRO]) +# +# CONFIGURE_PACKAGE_CONFIG_FILE() should be used instead of the plain +# CONFIGURE_FILE() command when creating the Config.cmake or -config.cmake +# file for installing a project or library. It helps making the resulting package +# relocatable by avoiding hardcoded paths in the installed Config.cmake file. +# +# In a FooConfig.cmake file there may be code like this to make the +# install destinations know to the using project: +# set(FOO_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" ) +# set(FOO_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" ) +# set(FOO_ICONS_DIR "@CMAKE_INSTALL_PREFIX@/share/icons" ) +# ...logic to determine installedPrefix from the own location... +# set(FOO_CONFIG_DIR "${installedPrefix}/@CONFIG_INSTALL_DIR@" ) +# All 4 options shown above are not sufficient, since the first 3 hardcode +# the absolute directory locations, and the 4th case works only if the logic +# to determine the installedPrefix is correct, and if CONFIG_INSTALL_DIR contains +# a relative path, which in general cannot be guaranteed. +# This has the effect that the resulting FooConfig.cmake file would work poorly +# under Windows and OSX, where users are used to choose the install location +# of a binary package at install time, independent from how CMAKE_INSTALL_PREFIX +# was set at build/cmake time. +# +# Using CONFIGURE_PACKAGE_CONFIG_FILE() helps. If used correctly, it makes the +# resulting FooConfig.cmake file relocatable. +# Usage: +# 1. write a FooConfig.cmake.in file as you are used to +# 2. insert a line containing only the string "@PACKAGE_INIT@" +# 3. instead of SET(FOO_DIR "@SOME_INSTALL_DIR@"), use SET(FOO_DIR "@PACKAGE_SOME_INSTALL_DIR@") +# (this must be after the @PACKAGE_INIT@ line) +# 4. instead of using the normal CONFIGURE_FILE(), use CONFIGURE_PACKAGE_CONFIG_FILE() +# +# The and arguments are the input and output file, the same way +# as in CONFIGURE_FILE(). +# +# The given to INSTALL_DESTINATION must be the destination where the FooConfig.cmake +# file will be installed to. This can either be a relative or absolute path, both work. +# +# The variables to given as PATH_VARS are the variables which contain +# install destinations. For each of them the macro will create a helper variable +# PACKAGE_. These helper variables must be used +# in the FooConfig.cmake.in file for setting the installed location. They are calculated +# by CONFIGURE_PACKAGE_CONFIG_FILE() so that they are always relative to the +# installed location of the package. This works both for relative and also for absolute locations. +# For absolute locations it works only if the absolute location is a subdirectory +# of CMAKE_INSTALL_PREFIX. +# +# By default configure_package_config_file() also generates two helper macros, +# set_and_check() and check_required_components() into the FooConfig.cmake file. +# +# set_and_check() should be used instead of the normal set() +# command for setting directories and file locations. Additionally to setting the +# variable it also checks that the referenced file or directory actually exists +# and fails with a FATAL_ERROR otherwise. This makes sure that the created +# FooConfig.cmake file does not contain wrong references. +# When using the NO_SET_AND_CHECK_MACRO, this macro is not generated into the +# FooConfig.cmake file. +# +# check_required_components() should be called at the end of the +# FooConfig.cmake file if the package supports components. +# This macro checks whether all requested, non-optional components have been found, +# and if this is not the case, sets the Foo_FOUND variable to FALSE, so that the package +# is considered to be not found. +# It does that by testing the Foo__FOUND variables for all requested +# required components. +# When using the NO_CHECK_REQUIRED_COMPONENTS option, this macro is not generated +# into the FooConfig.cmake file. +# +# For an example see below the documentation for WRITE_BASIC_PACKAGE_VERSION_FILE(). +# +# +# WRITE_BASIC_PACKAGE_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion|ExactVersion) ) +# +# Writes a file for use as ConfigVersion.cmake file to . +# See the documentation of FIND_PACKAGE() for details on this. +# filename is the output filename, it should be in the build tree. +# major.minor.patch is the version number of the project to be installed +# The COMPATIBILITY mode AnyNewerVersion means that the installed package version +# will be considered compatible if it is newer or exactly the same as the requested version. +# This mode should be used for packages which are fully backward compatible, +# also across major versions. +# If SameMajorVersion is used instead, then the behaviour differs from AnyNewerVersion +# in that the major version number must be the same as requested, e.g. version 2.0 will +# not be considered compatible if 1.0 is requested. +# This mode should be used for packages which guarantee backward compatibility within the +# same major version. +# If ExactVersion is used, then the package is only considered compatible if the requested +# version matches exactly its own version number (not considering the tweak version). +# For example, version 1.2.3 of a package is only considered compatible to requested version 1.2.3. +# This mode is for packages without compatibility guarantees. +# If your project has more elaborated version matching rules, you will need to write your +# own custom ConfigVersion.cmake file instead of using this macro. +# +# Internally, this macro executes configure_file() to create the resulting +# version file. Depending on the COMPATIBLITY, either the file +# BasicConfigVersion-SameMajorVersion.cmake.in or BasicConfigVersion-AnyNewerVersion.cmake.in +# is used. Please note that these two files are internal to CMake and you should +# not call configure_file() on them yourself, but they can be used as starting +# point to create more sophisticted custom ConfigVersion.cmake files. +# +# +# Example using both configure_package_config_file() and write_basic_package_version_file(): +# CMakeLists.txt: +# set(INCLUDE_INSTALL_DIR include/ ... CACHE ) +# set(LIB_INSTALL_DIR lib/ ... CACHE ) +# set(SYSCONFIG_INSTALL_DIR etc/foo/ ... CACHE ) +# ... +# include(CMakePackageConfigHelpers) +# configure_package_config_file(FooConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake +# INSTALL_DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake +# PATH_VARS INCLUDE_INSTALL_DIR SYSCONFIG_INSTALL_DIR) +# write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake +# VERSION 1.2.3 +# COMPATIBILITY SameMajorVersion ) +# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake +# DESTINATION ${LIB_INSTALL_DIR}/Foo/cmake ) +# +# With a FooConfig.cmake.in: +# set(FOO_VERSION x.y.z) +# ... +# @PACKAGE_INIT@ +# ... +# set_and_check(FOO_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +# set_and_check(FOO_SYSCONFIG_DIR "@PACKAGE_SYSCONFIG_INSTALL_DIR@") +# +# check_required_components(Foo) + + +#============================================================================= +# Copyright 2012 Alexander Neundorf +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +include(CMakeParseArguments) + +include(WriteBasicConfigVersionFile) + +macro(WRITE_BASIC_PACKAGE_VERSION_FILE) + write_basic_config_version_file(${ARGN}) +endmacro() + + +function(CONFIGURE_PACKAGE_CONFIG_FILE _inputFile _outputFile) + set(options NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) + set(oneValueArgs INSTALL_DESTINATION ) + set(multiValueArgs PATH_VARS ) + + cmake_parse_arguments(CCF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if(CCF_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown keywords given to CONFIGURE_PACKAGE_CONFIG_FILE(): \"${CCF_UNPARSED_ARGUMENTS}\"") + endif() + + if(NOT CCF_INSTALL_DESTINATION) + message(FATAL_ERROR "No INSTALL_DESTINATION given to CONFIGURE_PACKAGE_CONFIG_FILE()") + endif() + + if(IS_ABSOLUTE "${CCF_INSTALL_DESTINATION}") + set(absInstallDir "${CCF_INSTALL_DESTINATION}") + else() + set(absInstallDir "${CMAKE_INSTALL_PREFIX}/${CCF_INSTALL_DESTINATION}") + endif() + file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${absInstallDir}" "${CMAKE_INSTALL_PREFIX}" ) + + foreach(var ${CCF_PATH_VARS}) + if(NOT DEFINED ${var}) + message(FATAL_ERROR "Variable ${var} does not exist") + else() + if(IS_ABSOLUTE "${${var}}") + string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${PACKAGE_PREFIX_DIR}" + PACKAGE_${var} "${${var}}") + else() + set(PACKAGE_${var} "\${PACKAGE_PREFIX_DIR}/${${var}}") + endif() + endif() + endforeach() + + set(PACKAGE_INIT " +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +get_filename_component(PACKAGE_PREFIX_DIR \"\${CMAKE_CURRENT_LIST_DIR}/${PACKAGE_RELATIVE_PATH}\" ABSOLUTE) +") + + if(NOT CCF_NO_SET_AND_CHECK_MACRO) + set(PACKAGE_INIT "${PACKAGE_INIT} +macro(set_and_check _var _file) + set(\${_var} \"\${_file}\") + if(NOT EXISTS \"\${_file}\") + message(FATAL_ERROR \"File or directory \${_file} referenced by variable \${_var} does not exist !\") + endif() +endmacro() +") + endif() + + + if(NOT CCF_NO_CHECK_REQUIRED_COMPONENTS_MACRO) + set(PACKAGE_INIT "${PACKAGE_INIT} +macro(check_required_components _NAME) + foreach(comp \${\${_NAME}_FIND_COMPONENTS}) + if(NOT \${_NAME}_\${comp}_FOUND) + if(\${_NAME}_FIND_REQUIRED_\${comp}) + set(\${_NAME}_FOUND FALSE) + endif() + endif() + endforeach(comp) +endmacro() +") + endif() + + set(PACKAGE_INIT "${PACKAGE_INIT} +####################################################################################") + + configure_file("${_inputFile}" "${_outputFile}" @ONLY) + +endfunction() diff --git a/Modules/CMakePlatformId.h.in b/Modules/CMakePlatformId.h.in index cb3f40a1f..b69bf6310 100644 --- a/Modules/CMakePlatformId.h.in +++ b/Modules/CMakePlatformId.h.in @@ -105,6 +105,46 @@ # define ARCHITECTURE_ID "" #endif +/* Convert integer to decimal digit literals. */ +#define DEC(n) \ + ('0' + (((n) / 10000000)%10)), \ + ('0' + (((n) / 1000000)%10)), \ + ('0' + (((n) / 100000)%10)), \ + ('0' + (((n) / 10000)%10)), \ + ('0' + (((n) / 1000)%10)), \ + ('0' + (((n) / 100)%10)), \ + ('0' + (((n) / 10)%10)), \ + ('0' + ((n) % 10)) + +/* Convert integer to hex digit literals. */ +#define HEX(n) \ + ('0' + ((n)>>28 & 0xF)), \ + ('0' + ((n)>>24 & 0xF)), \ + ('0' + ((n)>>20 & 0xF)), \ + ('0' + ((n)>>16 & 0xF)), \ + ('0' + ((n)>>12 & 0xF)), \ + ('0' + ((n)>>8 & 0xF)), \ + ('0' + ((n)>>4 & 0xF)), \ + ('0' + ((n) & 0xF)) + +/* Construct a string literal encoding the version number components. */ +#ifdef COMPILER_VERSION_MAJOR +char const info_version[] = { + 'I', 'N', 'F', 'O', ':', + 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', + COMPILER_VERSION_MAJOR, +# ifdef COMPILER_VERSION_MINOR + '.', COMPILER_VERSION_MINOR, +# ifdef COMPILER_VERSION_PATCH + '.', COMPILER_VERSION_PATCH, +# ifdef COMPILER_VERSION_TWEAK + '.', COMPILER_VERSION_TWEAK, +# endif +# endif +# endif + ']','\0'}; +#endif + /* Construct the string literal in pieces to prevent the source from getting matched. Store it in a pointer rather than an array because some compilers will just produce instructions to fill the diff --git a/Modules/CPack.cmake b/Modules/CPack.cmake index 2cc27cf11..571770e98 100644 --- a/Modules/CPack.cmake +++ b/Modules/CPack.cmake @@ -1,5 +1,7 @@ -# - Build binary and source package installers -# +##section Variables common to all CPack generators +##end +##module +# - Build binary and source package installers. # The CPack module generates binary and source installers in a variety # of formats using the cpack program. Inclusion of the CPack module # adds two new targets to the resulting makefiles, package and @@ -29,16 +31,16 @@ # on a per-generator basis. It only need contain overrides. # # Here's how it works: -# - cpack runs -# - it includes CPackConfig.cmake -# - it iterates over the generators listed in that file's -# CPACK_GENERATOR list variable (unless told to use just a -# specific one via -G on the command line...) +# - cpack runs +# - it includes CPackConfig.cmake +# - it iterates over the generators listed in that file's +# CPACK_GENERATOR list variable (unless told to use just a +# specific one via -G on the command line...) # -# - foreach generator, it then -# - sets CPACK_GENERATOR to the one currently being iterated -# - includes the CPACK_PROJECT_CONFIG_FILE -# - produces the package for that generator +# - foreach generator, it then +# - sets CPACK_GENERATOR to the one currently being iterated +# - includes the CPACK_PROJECT_CONFIG_FILE +# - produces the package for that generator # # This is the key: For each generator listed in CPACK_GENERATOR # in CPackConfig.cmake, cpack will *reset* CPACK_GENERATOR @@ -48,174 +50,216 @@ # Before including this CPack module in your CMakeLists.txt file, # there are a variety of variables that can be set to customize # the resulting installers. The most commonly-used variables are: -# -# CPACK_PACKAGE_NAME - The name of the package (or application). If -# not specified, defaults to the project name. -# -# CPACK_PACKAGE_VENDOR - The name of the package vendor (e.g., -# "Kitware"). -# -# CPACK_PACKAGE_VERSION_MAJOR - Package major Version -# -# CPACK_PACKAGE_VERSION_MINOR - Package minor Version -# -# CPACK_PACKAGE_VERSION_PATCH - Package patch Version -# -# CPACK_PACKAGE_DESCRIPTION_FILE - A text file used to describe the -# project. Used, for example, the introduction screen of a -# CPack-generated Windows installer to describe the project. -# -# CPACK_PACKAGE_DESCRIPTION_SUMMARY - Short description of the -# project (only a few words). -# -# CPACK_PACKAGE_FILE_NAME - The name of the package file to generate, -# not including the extension. For example, cmake-2.6.1-Linux-i686. -# -# CPACK_PACKAGE_INSTALL_DIRECTORY - Installation directory on the -# target system, e.g., "CMake 2.5". -# -# CPACK_PROJECT_CONFIG_FILE - File included at cpack time, once per -# generator after setting CPACK_GENERATOR to the actual generator -# being used. Allows per-generator setting of CPACK_* variables at -# cpack time. -# -# CPACK_RESOURCE_FILE_LICENSE - License file for the project, which -# will typically be displayed to the user (often with an explicit -# "Accept" button, for graphical installers) prior to installation. -# -# CPACK_RESOURCE_FILE_README - ReadMe file for the project, which -# typically describes in some detail -# -# CPACK_RESOURCE_FILE_WELCOME - Welcome file for the project, which -# welcomes users to this installer. Typically used in the graphical -# installers on Windows and Mac OS X. -# -# CPACK_MONOLITHIC_INSTALL - Disables the component-based -# installation mechanism, so that all components are always installed. -# -# CPACK_GENERATOR - List of CPack generators to use. If not -# specified, CPack will create a set of options (e.g., -# CPACK_BINARY_NSIS) allowing the user to enable/disable individual -# generators. -# -# CPACK_OUTPUT_CONFIG_FILE - The name of the CPack configuration file -# for binary installers that will be generated by the CPack -# module. Defaults to CPackConfig.cmake. -# -# CPACK_PACKAGE_EXECUTABLES - Lists each of the executables along -# with a text label, to be used to create Start Menu shortcuts on -# Windows. For example, setting this to the list ccmake;CMake will -# create a shortcut named "CMake" that will execute the installed -# executable ccmake. -# -# CPACK_STRIP_FILES - List of files to be stripped. Starting with -# CMake 2.6.0 CPACK_STRIP_FILES will be a boolean variable which -# enables stripping of all files (a list of files evaluates to TRUE -# in CMake, so this change is compatible). +##end +# +##variable +# CPACK_PACKAGE_NAME - The name of the package (or application). If +# not specified, defaults to the project name. +##end +# +##variable +# CPACK_PACKAGE_VENDOR - The name of the package vendor. (e.g., +# "Kitware"). +##end +# +##variable +# CPACK_PACKAGE_VERSION_MAJOR - Package major Version +##end +# +##variable +# CPACK_PACKAGE_VERSION_MINOR - Package minor Version +##end +# +##variable +# CPACK_PACKAGE_VERSION_PATCH - Package patch Version +##end +# +##variable +# CPACK_PACKAGE_DESCRIPTION_FILE - A text file used to describe the +# project. Used, for example, the introduction screen of a +# CPack-generated Windows installer to describe the project. +##end +# +##variable +# CPACK_PACKAGE_DESCRIPTION_SUMMARY - Short description of the +# project (only a few words). +##end +# +##variable +# CPACK_PACKAGE_FILE_NAME - The name of the package file to generate, +# not including the extension. For example, cmake-2.6.1-Linux-i686. +# The default value is +# ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}. +##end +# +##variable +# CPACK_PACKAGE_INSTALL_DIRECTORY - Installation directory on the +# target system. This may be used by some CPack generators +# like NSIS to create an installation directory e.g., "CMake 2.5" +# below the installation prefix. All installed element will be +# put inside this directory. +##end +# +##variable +# CPACK_PACKAGE_ICON - A branding image that will be displayed inside +# the installer (used by GUI installers). +##end +# +##variable +# CPACK_PROJECT_CONFIG_FILE - CPack-time project CPack configuration +# file. This file included at cpack time, once per +# generator after CPack has set CPACK_GENERATOR to the actual generator +# being used. It allows per-generator setting of CPACK_* variables at +# cpack time. +##end +# +##variable +# CPACK_RESOURCE_FILE_LICENSE - License to be embedded in the installer. It +# will typically be displayed to the user by the produced installer +# (often with an explicit "Accept" button, for graphical installers) +# prior to installation. This license file is NOT added to installed +# file but is used by some CPack generators like NSIS. If you want +# to install a license file (may be the same as this one) +# along with your project you must add an appropriate CMake INSTALL +# command in your CMakeLists.txt. +##end +# +##variable +# CPACK_RESOURCE_FILE_README - ReadMe file to be embedded in the installer. It +# typically describes in some detail the purpose of the project +# during the installation. Not all CPack generators uses +# this file. +##end +# +##variable +# CPACK_RESOURCE_FILE_WELCOME - Welcome file to be embedded in the +# installer. It welcomes users to this installer. +# Typically used in the graphical installers on Windows and Mac OS X. +##end +# +##variable +# CPACK_MONOLITHIC_INSTALL - Disables the component-based +# installation mechanism. When set the component specification is ignored +# and all installed items are put in a single "MONOLITHIC" package. +# Some CPack generators do monolithic packaging by default and +# may be asked to do component packaging by setting +# CPACK__COMPONENT_INSTALL to 1/TRUE. +##end +# +##variable +# CPACK_GENERATOR - List of CPack generators to use. If not +# specified, CPack will create a set of options CPACK_BINARY_ (e.g., +# CPACK_BINARY_NSIS) allowing the user to enable/disable individual +# generators. This variable may be used on the command line +# as well as in: +# +# cpack -D CPACK_GENERATOR="ZIP;TGZ" /path/to/build/tree +##end +# +##variable +# CPACK_OUTPUT_CONFIG_FILE - The name of the CPack binary configuration +# file. This file is the CPack configuration generated by the CPack module +# for binary installers. Defaults to CPackConfig.cmake. +##end +# +##variable +# CPACK_PACKAGE_EXECUTABLES - Lists each of the executables and associated +# text label to be used to create Start Menu shortcuts. For example, +# setting this to the list ccmake;CMake will +# create a shortcut named "CMake" that will execute the installed +# executable ccmake. Not all CPack generators use it (at least NSIS and +# OSXX11 do). +##end +# +##variable +# CPACK_STRIP_FILES - List of files to be stripped. Starting with +# CMake 2.6.0 CPACK_STRIP_FILES will be a boolean variable which +# enables stripping of all files (a list of files evaluates to TRUE +# in CMake, so this change is compatible). +##end # # The following CPack variables are specific to source packages, and # will not affect binary packages: # -# CPACK_SOURCE_PACKAGE_FILE_NAME - The name of the source package, -# e.g., cmake-2.6.1 -# -# CPACK_SOURCE_STRIP_FILES - List of files in the source tree that -# will be stripped. Starting with CMake 2.6.0 -# CPACK_SOURCE_STRIP_FILES will be a boolean variable which enables -# stripping of all files (a list of files evaluates to TRUE in CMake, -# so this change is compatible). -# -# CPACK_SOURCE_GENERATOR - List of generators used for the source -# packages. As with CPACK_GENERATOR, if this is not specified then -# CPack will create a set of options (e.g., CPACK_SOURCE_ZIP) -# allowing users to select which packages will be generated. -# -# CPACK_SOURCE_OUTPUT_CONFIG_FILE - The name of the CPack -# configuration file for source installers that will be generated by -# the CPack module. Defaults to CPackSourceConfig.cmake. -# -# CPACK_SOURCE_IGNORE_FILES - Pattern of files in the source tree -# that won't be packaged when building a source package. This is a -# list of patterns, e.g., /CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.* -# -# The following variables are specific to the DragNDrop installers -# built on Mac OS X: -# -# CPACK_DMG_VOLUME_NAME - The volume name of the generated disk -# image. Defaults to CPACK_PACKAGE_FILE_NAME. -# -# CPACK_DMG_FORMAT - The disk image format. Common values are UDRO -# (UDIF read-only), UDZO (UDIF zlib-compressed) or UDBZ (UDIF -# bzip2-compressed). Refer to hdiutil(1) for more information on -# other available formats. -# -# CPACK_DMG_DS_STORE - Path to a custom .DS_Store file which e.g. -# can be used to specify the Finder window position/geometry and -# layout (such as hidden toolbars, placement of the icons etc.). -# This file has to be generated by the Finder (either manually or -# through OSA-script) using a normal folder from which the .DS_Store -# file can then be extracted. -# -# CPACK_DMG_BACKGROUND_IMAGE - Path to an image file which is to be -# used as the background for the Finder Window when the disk image -# is opened. By default no background image is set. The background -# image is applied after applying the custom .DS_Store file. -# -# CPACK_COMMAND_HDIUTIL - Path to the hdiutil(1) command used to -# operate on disk image files on Mac OS X. This variable can be used -# to override the automatically detected command (or specify its -# location if the auto-detection fails to find it.) -# -# CPACK_COMMAND_SETFILE - Path to the SetFile(1) command used to set -# extended attributes on files and directories on Mac OS X. This -# variable can be used to override the automatically detected -# command (or specify its location if the auto-detection fails to -# find it.) -# -# CPACK_COMMAND_REZ - Path to the Rez(1) command used to compile -# resources on Mac OS X. This variable can be used to override the -# automatically detected command (or specify its location if the -# auto-detection fails to find it.) -# -# The following variable is specific to installers build on Mac OS X -# using PackageMaker: -# -# CPACK_OSX_PACKAGE_VERSION - The version of Mac OS X that the -# resulting PackageMaker archive should be compatible -# with. Different versions of Mac OS X support different -# features. For example, CPack can only build component-based -# installers for Mac OS X 10.4 or newer, and can only build -# installers that download component son-the-fly for Mac OS X 10.5 -# or newer. If left blank, this value will be set to the minimum -# version of Mac OS X that supports the requested features. Set this -# variable to some value (e.g., 10.4) only if you want to guarantee -# that your installer will work on that version of Mac OS X, and -# don't mind missing extra features available in the installer -# shipping with later versions of Mac OS X. +##variable +# CPACK_SOURCE_PACKAGE_FILE_NAME - The name of the source package. For +# example cmake-2.6.1. +##end +# +##variable +# CPACK_SOURCE_STRIP_FILES - List of files in the source tree that +# will be stripped. Starting with CMake 2.6.0 +# CPACK_SOURCE_STRIP_FILES will be a boolean variable which enables +# stripping of all files (a list of files evaluates to TRUE in CMake, +# so this change is compatible). +##end +# +##variable +# CPACK_SOURCE_GENERATOR - List of generators used for the source +# packages. As with CPACK_GENERATOR, if this is not specified then +# CPack will create a set of options (e.g., CPACK_SOURCE_ZIP) +# allowing users to select which packages will be generated. +##end +# +##variable +# CPACK_SOURCE_OUTPUT_CONFIG_FILE - The name of the CPack source +# configuration file. This file is the CPack configuration generated by the +# CPack module for source installers. Defaults to CPackSourceConfig.cmake. +##end +# +##variable +# CPACK_SOURCE_IGNORE_FILES - Pattern of files in the source tree +# that won't be packaged when building a source package. This is a +# list of regular expression patterns (that must be properly escaped), +# e.g., /CVS/;/\\.svn/;\\.swp$;\\.#;/#;.*~;cscope.* +##end # # The following variables are for advanced uses of CPack: # -# CPACK_CMAKE_GENERATOR - What CMake generator should be used if the -# project is CMake project. Defaults to the value of CMAKE_GENERATOR; -# few users will want to change this setting. -# -# CPACK_INSTALL_CMAKE_PROJECTS - List of four values that specify -# what project to install. The four values are: Build directory, -# Project Name, Project Component, Directory. If omitted, CPack will -# build an installer that installers everything. -# -# CPACK_SYSTEM_NAME - System name, defaults to the value of -# ${CMAKE_SYSTEM_NAME}. -# -# CPACK_PACKAGE_VERSION - Package full version, used internally. By -# default, this is built from CPACK_PACKAGE_VERSION_MAJOR, -# CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH. -# -# CPACK_TOPLEVEL_TAG - Directory for the installed files. -# -# CPACK_INSTALL_COMMANDS - Extra commands to install components. -# -# CPACK_INSTALLED_DIRECTORIES - Extra directories to install. +##variable +# CPACK_CMAKE_GENERATOR - What CMake generator should be used if the +# project is CMake project. Defaults to the value of CMAKE_GENERATOR +# few users will want to change this setting. +##end +# +##variable +# CPACK_INSTALL_CMAKE_PROJECTS - List of four values that specify +# what project to install. The four values are: Build directory, +# Project Name, Project Component, Directory. If omitted, CPack will +# build an installer that installers everything. +##end +# +##variable +# CPACK_SYSTEM_NAME - System name, defaults to the value of +# ${CMAKE_SYSTEM_NAME}. +##end +# +##variable +# CPACK_PACKAGE_VERSION - Package full version, used internally. By +# default, this is built from CPACK_PACKAGE_VERSION_MAJOR, +# CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH. +##end +# +##variable +# CPACK_TOPLEVEL_TAG - Directory for the installed files. +##end +# +##variable +# CPACK_INSTALL_COMMANDS - Extra commands to install components. +##end +# +##variable +# CPACK_INSTALLED_DIRECTORIES - Extra directories to install. +##end +# +##variable +# CPACK_PACKAGE_INSTALL_REGISTRY_KEY - Registry key used when +# installing this project. This is only used +# by installer for Windows. +##end +##variable +# CPACK_CREATE_DESKTOP_LINKS - List of desktop links to create. +##end # #============================================================================= @@ -259,7 +303,7 @@ MACRO(cpack_set_if_not_set name value) ENDIF(NOT DEFINED "${name}") ENDMACRO(cpack_set_if_not_set) -# Macro to encode variables for the configuration file +# cpack_encode_variables - Macro to encode variables for the configuration file # find any variable that starts with CPACK and create a variable # _CPACK_OTHER_VARIABLES_ that contains SET commands for # each cpack variable. _CPACK_OTHER_VARIABLES_ is then @@ -350,6 +394,12 @@ macro(cpack_optional_append _list _cond _item) endif(${_cond}) endmacro(cpack_optional_append _list _cond _item) +##variable +# CPACK_BINARY_ - CPack generated options for binary generators. The +# CPack.cmake module generates (when CPACK_GENERATOR is not set) +# a set of CMake options (see CMake option command) which may then be used to +# select the CPack generator(s) to be used when launching the package target. +##end # Provide options to choose generators # we might check here if the required tools for the generates exist # and set the defaults according to the results diff --git a/Modules/CPackBundle.cmake b/Modules/CPackBundle.cmake index 3ac4ea8ff..0da51e30b 100644 --- a/Modules/CPackBundle.cmake +++ b/Modules/CPackBundle.cmake @@ -1,25 +1,36 @@ +##section Variables specific to CPack Bundle generator +##end +##module # - CPack Bundle generator (Mac OS X) specific options # # Installers built on Mac OS X using the Bundle generator use the -# aforementioned DragNDrop variables, plus the following Bundle-specific -# parameters: +# aforementioned DragNDrop (CPACK_DMG_xxx) variables, plus +# the following Bundle-specific parameters (CPACK_BUNDLE_xxx). +##end # -# CPACK_BUNDLE_NAME - The name of the generated bundle. This -# appears in the OSX finder as the bundle name. Required. +##variable +# CPACK_BUNDLE_NAME - The name of the generated bundle. This +# appears in the OSX finder as the bundle name. Required. +##end # -# CPACK_BUNDLE_PLIST - Path to an OSX plist file that will be used -# as the Info.plist for the generated bundle. This assumes that -# the caller has generated or specified their own Info.plist file. -# Required. +##variable +# CPACK_BUNDLE_PLIST - Path to an OSX plist file that will be used +# for the generated bundle. This assumes that the caller has generated +# or specified their own Info.plist file. Required. +##end # -# CPACK_BUNDLE_ICON - Path to an OSX icns file that will be used as -# the icon for the generated bundle. This is the icon that appears -# in the OSX finder for the bundle, and in the OSX dock when the -# bundle is opened. Required. +##variable +# CPACK_BUNDLE_ICON - Path to an OSX icon file that will be used as +# the icon for the generated bundle. This is the icon that appears in the +# OSX finder for the bundle, and in the OSX dock when the bundle is opened. +# Required. +##end # -# CPACK_BUNDLE_STARTUP_SCRIPT - Path to an executable or script that -# will be run whenever an end-user double-clicks the generated bundle -# in the OSX Finder. Optional. +##variable +# CPACK_BUNDLE_STARTUP_COMMAND - Path to a startup script. This is a path to +# an executable or script that will be run whenever an end-user double-clicks +# the generated bundle in the OSX Finder. Optional. +##end #============================================================================= # Copyright 2006-2009 Kitware, Inc. diff --git a/Modules/CPackComponent.cmake b/Modules/CPackComponent.cmake index 1c10372ff..15987030e 100644 --- a/Modules/CPackComponent.cmake +++ b/Modules/CPackComponent.cmake @@ -1,3 +1,6 @@ +##section Variables concerning CPack Components +##end +##module # - Build binary and source package installers # # The CPackComponent module is the module which handles @@ -20,7 +23,54 @@ # components are identified by the COMPONENT argument of CMake's # INSTALL commands, and should be further described by the following # CPack commands: -# +##end +# +##variable +# CPACK_COMPONENTS_ALL - The list of component to install. +# +# The default value of this variable is computed by CPack +# and contains all components defined by the project. The +# user may set it to only include the specified components. +##end +# +##variable +# CPACK__COMPONENT_INSTALL - Enable/Disable component install for +# CPack generator . +# +# Each CPack Generator (RPM, DEB, ARCHIVE, NSIS, DMG, etc...) has a legacy +# default behavior. e.g. RPM builds monolithic whereas NSIS builds component. +# One can change the default behavior by setting this variable to 0/1 or OFF/ON. +##end +##variable +# CPACK_COMPONENTS_GROUPING - Specify how components are grouped for multi-package +# component-aware CPack generators. +# +# Some generators like RPM or ARCHIVE family (TGZ, ZIP, ...) generates several +# packages files when asked for component packaging. They group the component +# differently depending on the value of this variable: +# - ONE_PER_GROUP (default): creates one package file per component group +# - ALL_COMPONENTS_IN_ONE : creates a single package with all (requested) component +# - IGNORE : creates one package per component, i.e. IGNORE component group +# One can specify different grouping for different CPack generator by using +# a CPACK_PROJECT_CONFIG_FILE. +##end +##variable +# CPACK_COMPONENT__DISPLAY_NAME - The name to be displayed for a component. +##end +##variable +# CPACK_COMPONENT__DESCRIPTION - The description of a component. +##end +##variable +# CPACK_COMPONENT__GROUP - The group of a component. +##end +##variable +# CPACK_COMPONENT__DEPENDS - The dependencies (list of components) +# on which this component depends. +##end +##variable +# CPACK_COMPONENT__REQUIRED - True is this component is required. +##end +##macro # cpack_add_component - Describes a CPack installation component # named by the COMPONENT argument to a CMake INSTALL command. # @@ -90,7 +140,9 @@ # create a file with some name based on CPACK_PACKAGE_FILE_NAME and # the name of the component. See cpack_configure_downloads for more # information. +##end # +##macro # cpack_add_component_group - Describes a group of related CPack # installation components. # @@ -134,7 +186,9 @@ # # BOLD_TITLE indicates that the group title should appear in bold, # to call the user's attention to the group. +##end # +##macro # cpack_add_install_type - Add a new installation type containing a # set of predefined component selections to the graphical installer. # @@ -153,7 +207,9 @@ # DISPLAY_NAME is the displayed name of the install type, which will # typically show up in a drop-down box within a graphical # installer. This value can be any string. +##end # +##macro # cpack_configure_downloads - Configure CPack to download selected # components on-the-fly as part of the installation process. # @@ -203,6 +259,7 @@ # that can be called from Windows' Add/Remove Programs dialog (via the # "Modify" button) to change the set of installed components. NO_ADD_REMOVE # turns off this behavior. This option is ignored on Mac OS X. +##endmacro #============================================================================= # Copyright 2006-2009 Kitware, Inc. diff --git a/Modules/CPackCygwin.cmake b/Modules/CPackCygwin.cmake new file mode 100644 index 000000000..7ed7f678b --- /dev/null +++ b/Modules/CPackCygwin.cmake @@ -0,0 +1,33 @@ +##section Variables specific to CPack Cygwin generator +##end +##module +# - Cygwin CPack generator (Cygwin). +# The following variable is specific to installers build on +# and/or for Cygwin: +##end +# +##variable +# CPACK_CYGWIN_PATCH_NUMBER - The Cygwin patch number. +# FIXME: This documentation is incomplete. +##end +##variable +# CPACK_CYGWIN_PATCH_FILE - The Cygwin patch file. +# FIXME: This documentation is incomplete. +##end +##variable +# CPACK_CYGWIN_BUILD_SCRIPT - The Cygwin build script. +# FIXME: This documentation is incomplete. +##end + +#============================================================================= +# Copyright 2006-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) diff --git a/Modules/CPackDMG.cmake b/Modules/CPackDMG.cmake new file mode 100644 index 000000000..e866bab80 --- /dev/null +++ b/Modules/CPackDMG.cmake @@ -0,0 +1,70 @@ +##section Variables specific to CPack DragNDrop generator +##end +##module +# - DragNDrop CPack generator (Mac OS X). +# The following variables are specific to the DragNDrop installers +# built on Mac OS X: +##end +# +##variable +# CPACK_DMG_VOLUME_NAME - The volume name of the generated disk +# image. Defaults to CPACK_PACKAGE_FILE_NAME. +##end +# +##variable +# CPACK_DMG_FORMAT - The disk image format. Common values are UDRO +# (UDIF read-only), UDZO (UDIF zlib-compressed) or UDBZ (UDIF +# bzip2-compressed). Refer to hdiutil(1) for more information on +# other available formats. +##end +# +##variable +# CPACK_DMG_DS_STORE - Path to a custom DS_Store file. This .DS_Store +# file e.g. can be used to specify the Finder window +# position/geometry and layout (such as hidden toolbars, placement of the +# icons etc.). This file has to be generated by the Finder (either manually or +# through OSA-script) using a normal folder from which the .DS_Store +# file can then be extracted. +##end +# +##variable +# CPACK_DMG_BACKGROUND_IMAGE - Path to a background image file. This +# file will be used as the background for the Finder Window when the disk +# image is opened. By default no background image is set. The background +# image is applied after applying the custom .DS_Store file. +##end +# +##variable +# CPACK_COMMAND_HDIUTIL - Path to the hdiutil(1) command used to +# operate on disk image files on Mac OS X. This variable can be used +# to override the automatically detected command (or specify its +# location if the auto-detection fails to find it.) +##end +# +##variable +# CPACK_COMMAND_SETFILE - Path to the SetFile(1) command used to set +# extended attributes on files and directories on Mac OS X. This +# variable can be used to override the automatically detected +# command (or specify its location if the auto-detection fails to +# find it.) +##end +# +##variable +# CPACK_COMMAND_REZ - Path to the Rez(1) command used to compile +# resources on Mac OS X. This variable can be used to override the +# automatically detected command (or specify its location if the +# auto-detection fails to find it.) +##end + +#============================================================================= +# Copyright 2006-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) diff --git a/Modules/CPackDeb.cmake b/Modules/CPackDeb.cmake index 26433bb97..fe81dc92c 100644 --- a/Modules/CPackDeb.cmake +++ b/Modules/CPackDeb.cmake @@ -1,3 +1,6 @@ +##section Variables specific to CPack Debian (DEB) generator +##end +##module # - The builtin (binary) CPack Deb generator (Unix only) # CPackDeb may be used to create Deb package using CPack. # CPackDeb is a CPack generator thus it uses the CPACK_XXX variables @@ -11,43 +14,63 @@ # the wiki: # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29 # However as a handy reminder here comes the list of specific variables: +##end # +##variable # CPACK_DEBIAN_PACKAGE_NAME # Mandatory : YES # Default : CPACK_PACKAGE_NAME (lower case) # The debian package summary +##end +##variable # CPACK_DEBIAN_PACKAGE_VERSION # Mandatory : YES # Default : CPACK_PACKAGE_VERSION # The debian package version +##end +##variable # CPACK_DEBIAN_PACKAGE_ARCHITECTURE # Mandatory : YES # Default : Output of dpkg --print-architecture (or i386 if dpkg is not found) # The debian package architecture +##end +##variable # CPACK_DEBIAN_PACKAGE_DEPENDS # Mandatory : NO # Default : - # May be used to set deb dependencies. +##end +##variable # CPACK_DEBIAN_PACKAGE_MAINTAINER # Mandatory : YES # Default : CPACK_PACKAGE_CONTACT # The debian package maintainer +##end +##variable # CPACK_DEBIAN_PACKAGE_DESCRIPTION # Mandatory : YES # Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY # The debian package description +##end +##variable # CPACK_DEBIAN_PACKAGE_SECTION # Mandatory : YES # Default : 'devel' # The debian package section +##end +##variable # CPACK_DEBIAN_PACKAGE_PRIORITY # Mandatory : YES # Default : 'optional' # The debian package priority +##end +##variable # CPACK_DEBIAN_PACKAGE_HOMEPAGE # Mandatory : NO # Default : - # The URL of the web site for this package +##end +##variable # CPACK_DEBIAN_PACKAGE_SHLIBDEPS # Mandatory : NO # Default : OFF @@ -57,11 +80,15 @@ # if you use this feature, because if you don't dpkg-shlibdeps # may fail to find your own shared libs. # See http://www.cmake.org/Wiki/CMake_RPATH_handling. +##end +##variable # CPACK_DEBIAN_PACKAGE_DEBUG # Mandatory : NO # Default : - # May be set when invoking cpack in order to trace debug information # during CPackDeb run. +##end +##variable # CPACK_DEBIAN_PACKAGE_PREDEPENDS # Mandatory : NO # Default : - @@ -69,12 +96,16 @@ # This field is like Depends, except that it also forces dpkg to complete installation of # the packages named before even starting the installation of the package which declares # the pre-dependency. +##end +##variable # CPACK_DEBIAN_PACKAGE_ENHANCES # Mandatory : NO # Default : - # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps # This field is similar to Suggests but works in the opposite direction. # It is used to declare that a package can enhance the functionality of another package. +##end +##variable # CPACK_DEBIAN_PACKAGE_BREAKS # Mandatory : NO # Default : - @@ -82,23 +113,30 @@ # When one binary package declares that it breaks another, dpkg will refuse to allow the # package which declares Breaks be installed unless the broken package is deconfigured first, # and it will refuse to allow the broken package to be reconfigured. +##end +##variable # CPACK_DEBIAN_PACKAGE_CONFLICTS # Mandatory : NO # Default : - # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps # When one binary package declares a conflict with another using a Conflicts field, # dpkg will refuse to allow them to be installed on the system at the same time. +##end +##variable # CPACK_DEBIAN_PACKAGE_PROVIDES # Mandatory : NO # Default : - # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps # A virtual package is one which appears in the Provides control field of another package. +##end +##variable # CPACK_DEBIAN_PACKAGE_REPLACES # Mandatory : NO # Default : - # see http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps # Packages can declare in their control file that they should overwrite # files in certain other packages, or completely replace other packages. +##end #============================================================================= # Copyright 2007-2009 Kitware, Inc. diff --git a/Modules/CPackNSIS.cmake b/Modules/CPackNSIS.cmake index d9dab5328..5e2ba17f8 100644 --- a/Modules/CPackNSIS.cmake +++ b/Modules/CPackNSIS.cmake @@ -1,70 +1,118 @@ +##section Variables specific to CPack NSIS generator +##end +##module # - CPack NSIS generator specific options # # The following variables are specific to the graphical installers built # on Windows using the Nullsoft Installation System. +##end # -# CPACK_PACKAGE_INSTALL_REGISTRY_KEY - Registry key used when -# installing this project. -# +##variable # CPACK_NSIS_INSTALL_ROOT - The default installation directory presented # to the end user by the NSIS installer is under this root dir. The full # directory presented to the end user is: # ${CPACK_NSIS_INSTALL_ROOT}/${CPACK_PACKAGE_INSTALL_DIRECTORY} +##end # -# CPACK_NSIS_MUI_ICON - The icon file (.ico) for the generated +##variable +# CPACK_NSIS_MUI_ICON - An icon filename. +# The name of a *.ico file used as the main icon for the generated # install program. +##end # -# CPACK_NSIS_MUI_UNIICON - The icon file (.ico) for the generated +##variable +# CPACK_NSIS_MUI_UNIICON - An icon filename. +# The name of a *.ico file used as the main icon for the generated # uninstall program. +##end # -# CPACK_PACKAGE_ICON - A branding image that will be displayed inside -# the installer. +##variable +# CPACK_NSIS_INSTALLER_MUI_ICON_CODE - undocumented. +##end # +##variable # CPACK_NSIS_EXTRA_INSTALL_COMMANDS - Extra NSIS commands that will # be added to the install Section. +##end # +##variable # CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS - Extra NSIS commands that will # be added to the uninstall Section. +##end # +##variable # CPACK_NSIS_COMPRESSOR - The arguments that will be passed to the # NSIS SetCompressor command. +##end # -# CPACK_NSIS_MODIFY_PATH - If this is set to "ON", then an extra page +##variable +# CPACK_NSIS_MODIFY_PATH - Modify PATH toggle. +# If this is set to "ON", then an extra page # will appear in the installer that will allow the user to choose # whether the program directory should be added to the system PATH # variable. +##end # +##variable # CPACK_NSIS_DISPLAY_NAME - The display name string that appears in # the Windows Add/Remove Program control panel +##end # +##variable # CPACK_NSIS_PACKAGE_NAME - The title displayed at the top of the # installer. +##end # +##variable # CPACK_NSIS_INSTALLED_ICON_NAME - A path to the executable that # contains the installer icon. +##end # +##variable # CPACK_NSIS_HELP_LINK - URL to a web site providing assistance in # installing your application. +##end # +##variable # CPACK_NSIS_URL_INFO_ABOUT - URL to a web site providing more # information about your application. +##end # +##variable # CPACK_NSIS_CONTACT - Contact information for questions and comments # about the installation process. +##end # +##variable # CPACK_NSIS_CREATE_ICONS_EXTRA - Additional NSIS commands for # creating start menu shortcuts. +##end # +##variable # CPACK_NSIS_DELETE_ICONS_EXTRA -Additional NSIS commands to # uninstall start menu shortcuts. +##end # +##variable # CPACK_NSIS_EXECUTABLES_DIRECTORY - Creating NSIS start menu links # assumes that they are in 'bin' unless this variable is set. # For example, you would set this to 'exec' if your executables are # in an exec directory. +##end # +##variable # CPACK_NSIS_MUI_FINISHPAGE_RUN - Specify an executable to add an option # to run on the finish page of the NSIS installer. +##end +##variable +# CPACK_NSIS_MENU_LINKS - Specify links in [application] menu. +# This should contain a list of pair "link" "link name". The link +# may be an URL or a path relative to installation prefix. +# Like: +# set(CPACK_NSIS_MENU_LINKS +# "doc/cmake-@CMake_VERSION_MAJOR@.@CMake_VERSION_MINOR@/cmake.html" "CMake Help" +# "http://www.cmake.org" "CMake Web Site") +##end #============================================================================= # Copyright 2006-2009 Kitware, Inc. diff --git a/Modules/CPackPackageMaker.cmake b/Modules/CPackPackageMaker.cmake new file mode 100644 index 000000000..45ba465cc --- /dev/null +++ b/Modules/CPackPackageMaker.cmake @@ -0,0 +1,35 @@ +##section Variables specific to CPack PackageMaker generator +##end +##module +# - PackageMaker CPack generator (Mac OS X). +# The following variable is specific to installers build on Mac OS X +# using PackageMaker: +##end +# +##variable +# CPACK_OSX_PACKAGE_VERSION - The version of Mac OS X that the +# resulting PackageMaker archive should be compatible with. Different +# versions of Mac OS X support different +# features. For example, CPack can only build component-based +# installers for Mac OS X 10.4 or newer, and can only build +# installers that download component son-the-fly for Mac OS X 10.5 +# or newer. If left blank, this value will be set to the minimum +# version of Mac OS X that supports the requested features. Set this +# variable to some value (e.g., 10.4) only if you want to guarantee +# that your installer will work on that version of Mac OS X, and +# don't mind missing extra features available in the installer +# shipping with later versions of Mac OS X. +##end + +#============================================================================= +# Copyright 2006-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake index bf476ad89..cba746fc5 100644 --- a/Modules/CPackRPM.cmake +++ b/Modules/CPackRPM.cmake @@ -1,3 +1,6 @@ +##section Variables specific to CPack RPM generator +##end +##module # - The builtin (binary) CPack RPM generator (Unix only) # CPackRPM may be used to create RPM package using CPack. # CPackRPM is a CPack generator thus it uses the CPACK_XXX variables @@ -15,52 +18,67 @@ # You'll find a detailed usage of CPackRPM on the wiki: # http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#RPM_.28Unix_Only.29 # However as a handy reminder here comes the list of specific variables: +##end # -# CPACK_RPM_PACKAGE_SUMMARY +##variable +# CPACK_RPM_PACKAGE_SUMMARY - The RPM package summary. # Mandatory : YES # Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY -# The RPM package summary -# CPACK_RPM_PACKAGE_NAME +##end +##variable +# CPACK_RPM_PACKAGE_NAME - The RPM package name. # Mandatory : YES # Default : CPACK_PACKAGE_NAME -# The RPM package name -# CPACK_RPM_PACKAGE_VERSION +##end +##variable +# CPACK_RPM_PACKAGE_VERSION - The RPM package version. # Mandatory : YES # Default : CPACK_PACKAGE_VERSION -# The RPM package version -# CPACK_RPM_PACKAGE_ARCHITECTURE +##end +##variable +# CPACK_RPM_PACKAGE_ARCHITECTURE - The RPM package architecture. # Mandatory : NO # Default : - -# The RPM package architecture. This may be set to "noarch" if you +# This may be set to "noarch" if you # know you are building a noarch package. -# CPACK_RPM_PACKAGE_RELEASE +##end +##variable +# CPACK_RPM_PACKAGE_RELEASE - The RPM package release. # Mandatory : YES # Default : 1 -# The RPM package release. This is the numbering of the RPM package +# This is the numbering of the RPM package # itself, i.e. the version of the packaging and not the version of the # content (see CPACK_RPM_PACKAGE_VERSION). One may change the default # value if the previous packaging was buggy and/or you want to put here # a fancy Linux distro specific numbering. -# CPACK_RPM_PACKAGE_LICENSE +##end +##variable +# CPACK_RPM_PACKAGE_LICENSE - The RPM package license policy. # Mandatory : YES # Default : "unknown" -# The RPM package license policy. -# CPACK_RPM_PACKAGE_GROUP +##end +##variable +# CPACK_RPM_PACKAGE_GROUP - The RPM package group. # Mandatory : YES # Default : "unknown" -# The RPM package group. -# CPACK_RPM_PACKAGE_VENDOR +##end +##variable +# CPACK_RPM_PACKAGE_VENDOR - The RPM package vendor. # Mandatory : YES # Default : CPACK_PACKAGE_VENDOR if set or "unknown" -# The RPM package vendor. -# CPACK_RPM_PACKAGE_URL +##end +##variable +# CPACK_RPM_PACKAGE_URL - The projects URL. # Mandatory : NO # Default : - -# The projects URL. -# CPACK_RPM_PACKAGE_DESCRIPTION +##end +##variable +# CPACK_RPM_PACKAGE_DESCRIPTION - RPM package description. # Mandatory : YES # Default : CPACK_PACKAGE_DESCRIPTION_FILE if set or "no package description available" -# CPACK_RPM_COMPRESSION_TYPE +##end +##variable +# CPACK_RPM_COMPRESSION_TYPE - RPM compression type. # Mandatory : NO # Default : - # May be used to override RPM compression type to be used @@ -68,7 +86,9 @@ # to lzma or xz compression whereas older cannot use such RPM. # Using this one can enforce compression type to be used. # Possible value are: lzma, xz, bzip2 and gzip. -# CPACK_RPM_PACKAGE_REQUIRES +##end +##variable +# CPACK_RPM_PACKAGE_REQUIRES - RPM spec requires field. # Mandatory : NO # Default : - # May be used to set RPM dependencies (requires). @@ -77,22 +97,30 @@ # set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8") # The required package list of an RPM file could be printed with # rpm -qp --requires file.rpm -# CPACK_RPM_PACKAGE_SUGGESTS +##end +##variable +# CPACK_RPM_PACKAGE_SUGGESTS - RPM spec suggest field. # Mandatory : NO # Default : - # May be used to set weak RPM dependencies (suggests). # Note that you must enclose the complete requires string between quotes. -# CPACK_RPM_PACKAGE_PROVIDES +##end +##variable +# CPACK_RPM_PACKAGE_PROVIDES - RPM spec provides field. # Mandatory : NO # Default : - # May be used to set RPM dependencies (provides). # The provided package list of an RPM file could be printed with # rpm -qp --provides file.rpm -# CPACK_RPM_PACKAGE_OBSOLETES +##end +##variable +# CPACK_RPM_PACKAGE_OBSOLETES - RPM spec obsoletes field. # Mandatory : NO # Default : - # May be used to set RPM packages that are obsoleted by this one. -# CPACK_RPM_PACKAGE_RELOCATABLE +##end +##variable +# CPACK_RPM_PACKAGE_RELOCATABLE - build a relocatable RPM. # Mandatory : NO # Default : CPACK_PACKAGE_RELOCATABLE # If this variable is set to TRUE or ON CPackRPM will try @@ -103,7 +131,9 @@ # If CPACK_SET_DESTDIR is set then you will get a warning message # but if there is file installed with absolute path you'll get # unexpected behavior. -# CPACK_RPM_SPEC_INSTALL_POST [deprecated] +##end +##variable +# CPACK_RPM_SPEC_INSTALL_POST - [deprecated]. # Mandatory : NO # Default : - # This way of specifying post-install script is deprecated use @@ -111,23 +141,31 @@ # May be used to set an RPM post-install command inside the spec file. # For example setting it to "/bin/true" may be used to prevent # rpmbuild to strip binaries. -# CPACK_RPM_SPEC_MORE_DEFINE +##end +##variable +# CPACK_RPM_SPEC_MORE_DEFINE - RPM extended spec definitions lines. # Mandatory : NO # Default : - # May be used to add any %define lines to the generated spec file. -# CPACK_RPM_PACKAGE_DEBUG +##end +##variable +# CPACK_RPM_PACKAGE_DEBUG - Toggle CPackRPM debug output. # Mandatory : NO # Default : - # May be set when invoking cpack in order to trace debug information # during CPack RPM run. For example you may launch CPack like this # cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM -# CPACK_RPM_USER_BINARY_SPECFILE +##end +##variable +# CPACK_RPM_USER_BINARY_SPECFILE - A user provided spec file. # Mandatory : NO # Default : - # May be set by the user in order to specify a USER binary spec file # to be used by CPackRPM instead of generating the file. # The specified file will be processed by CONFIGURE_FILE( @ONLY). -# CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE +##end +##variable +# CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE - Spec file template. # Mandatory : NO # Default : - # If set CPack will generate a template for USER specified binary @@ -135,6 +173,8 @@ # cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM # The user may then use this file in order to hand-craft is own # binary spec file which may be used with CPACK_RPM_USER_BINARY_SPECFILE. +##end +##variable # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE # Mandatory : NO @@ -143,11 +183,13 @@ # The refered script file(s) will be read and directly # put after the %pre or %preun section # If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for -# each component can be overriden with +# each component can be overridden with # CPACK_RPM__PRE_INSTALL_SCRIPT_FILE and # CPACK_RPM__PRE_UNINSTALL_SCRIPT_FILE # One may verify which scriptlet has been included with # rpm -qp --scripts package.rpm +##end +##variable # CPACK_RPM_POST_INSTALL_SCRIPT_FILE # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE # Mandatory : NO @@ -156,26 +198,31 @@ # The refered script file(s) will be read and directly # put after the %post or %postun section # If CPACK_RPM_COMPONENT_INSTALL is set to ON the (un)install script for -# each component can be overriden with +# each component can be overridden with # CPACK_RPM__POST_INSTALL_SCRIPT_FILE and # CPACK_RPM__POST_UNINSTALL_SCRIPT_FILE # One may verify which scriptlet has been included with # rpm -qp --scripts package.rpm +##end +##variable # CPACK_RPM_USER_FILELIST # CPACK_RPM__USER_FILELIST # Mandatory : NO # Default : - -# May be used to explicitely specify %() file line +# May be used to explicitly specify %() file line # in the spec file. Like %config(noreplace) or any other directive # that be found in the %files section. Since CPackRPM is generating # the list of files (and directories) the user specified files of # the CPACK_RPM__USER_FILELIST list will be removed from the generated list. -# CPACK_RPM_CHANGELOG_FILE +##end +##variable +# CPACK_RPM_CHANGELOG_FILE - RPM changelog file. # Mandatory : NO # Default : - # May be used to embed a changelog in the spec file. # The refered file will be read and directly put after the %changelog # section. +##end #============================================================================= # Copyright 2007-2009 Kitware, Inc. @@ -714,6 +761,25 @@ else() set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") endif(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) +# Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir +# This is necessary to avoid duplicate files since rpmbuild do +# recursion on its own when encountering a pathname which is a directory +# which is not flagged as %dir +string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) +string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST + "${CPACK_RPM_INSTALL_FILES_LIST}") +string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST + "${CPACK_RPM_INSTALL_FILES_LIST}") +set(CPACK_RPM_INSTALL_FILES "") +foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) + if(IS_DIRECTORY "${WDIR}/${F}") + set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}%dir \"${F}\"\n") + else() + set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}\"${F}\"\n") + endif() +endforeach(F) +set(CPACK_RPM_INSTALL_FILES_LIST "") + # The name of the final spec file to be used by rpmbuild SET(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_NAME}.spec") @@ -833,6 +899,7 @@ IF(RPMBUILD_EXECUTABLE) # Now call rpmbuild using the SPECFILE EXECUTE_PROCESS( COMMAND "${RPMBUILD_EXECUTABLE}" -bb + --define "_topdir ${CPACK_RPM_DIRECTORY}" --buildroot "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" "${CPACK_RPM_BINARY_SPECFILE}" WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" diff --git a/Modules/CTestTargets.cmake b/Modules/CTestTargets.cmake index d66874d8f..bc4d9646a 100644 --- a/Modules/CTestTargets.cmake +++ b/Modules/CTestTargets.cmake @@ -69,7 +69,7 @@ IF(NOT _CTEST_TARGETS_ADDED) ENDFOREACH(mode) # For Makefile generators add more granular targets. - IF("${CMAKE_GENERATOR}" MATCHES Make) + IF("${CMAKE_GENERATOR}" MATCHES "(Ninja|Make)") # Make targets for Experimental builds FOREACH(mode Nightly Experimental Continuous) FOREACH(testtype @@ -83,7 +83,7 @@ IF(NOT _CTEST_TARGETS_ADDED) SET_PROPERTY(TARGET ${mode}${testtype} PROPERTY FOLDER "CTestDashboardTargets") ENDFOREACH(testtype) ENDFOREACH(mode) - ENDIF("${CMAKE_GENERATOR}" MATCHES Make) + ENDIF("${CMAKE_GENERATOR}" MATCHES "(Ninja|Make)") # If requested, add an alias that is the equivalent of the built-in "test" # or "RUN_TESTS" target: diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index ec0a773e3..1c08c5959 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -7,8 +7,9 @@ # that can modify the build. #============================================================================= -# Copyright 2006-2010 Kitware, Inc. +# Copyright 2006-2011 Kitware, Inc. # Copyright 2006 Alexander Neundorf +# Copyright 2011 Matthias Kretz # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -27,15 +28,16 @@ MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT) SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT} # Some compilers do not fail with a bad flag - FAIL_REGEX "warning: command line option .* is valid for .* but not for C" - # Apple gcc + FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU FAIL_REGEX "unrecognized .*option" # GNU FAIL_REGEX "unknown .*option" # Clang FAIL_REGEX "ignoring unknown option" # MSVC FAIL_REGEX "warning D9002" # MSVC, any lang + FAIL_REGEX "option .*not supported" # Intel FAIL_REGEX "[Uu]nknown option" # HP FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro FAIL_REGEX "command option .* is not recognized" # XL + FAIL_REGEX "WARNING: unknown flag:" # Open64 ) SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") ENDMACRO (CHECK_C_COMPILER_FLAG) diff --git a/Modules/CheckCSourceCompiles.cmake b/Modules/CheckCSourceCompiles.cmake index d59fe5519..266933634 100644 --- a/Modules/CheckCSourceCompiles.cmake +++ b/Modules/CheckCSourceCompiles.cmake @@ -24,6 +24,9 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR) IF("${VAR}" MATCHES "^${VAR}$") SET(_FAIL_REGEX) @@ -40,8 +43,10 @@ MACRO(CHECK_C_SOURCE_COMPILES SOURCE VAR) SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) diff --git a/Modules/CheckCSourceRuns.cmake b/Modules/CheckCSourceRuns.cmake index 764c756d4..feee93a71 100644 --- a/Modules/CheckCSourceRuns.cmake +++ b/Modules/CheckCSourceRuns.cmake @@ -24,13 +24,18 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_C_SOURCE_RUNS SOURCE VAR) IF("${VAR}" MATCHES "^${VAR}$") - SET(MACRO_CHECK_FUNCTION_DEFINITIONS + SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_C_SOURCE_COMPILES_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) @@ -61,7 +66,7 @@ MACRO(CHECK_C_SOURCE_RUNS SOURCE VAR) IF("${${VAR}_EXITCODE}" EQUAL 0) SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}") MESSAGE(STATUS "Performing Test ${VAR} - Success") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C SOURCE FILE Test ${VAR} succeded with the following output:\n" "${OUTPUT}\n" "Return value: ${${VAR}}\n" @@ -74,7 +79,7 @@ MACRO(CHECK_C_SOURCE_RUNS SOURCE VAR) ENDIF(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") MESSAGE(STATUS "Performing Test ${VAR} - Failed") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C SOURCE FILE Test ${VAR} failed with the following output:\n" "${OUTPUT}\n" "Return value: ${${VAR}_EXITCODE}\n" diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake index 3da04b478..6fa69b12d 100644 --- a/Modules/CheckCXXCompilerFlag.cmake +++ b/Modules/CheckCXXCompilerFlag.cmake @@ -9,6 +9,7 @@ #============================================================================= # Copyright 2006-2010 Kitware, Inc. # Copyright 2006 Alexander Neundorf +# Copyright 2011 Matthias Kretz # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -27,15 +28,18 @@ MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT) SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT} # Some compilers do not fail with a bad flag + FAIL_REGEX "command line option .* is valid for .* but not for C\\\\+\\\\+" # GNU FAIL_REGEX "unrecognized .*option" # GNU FAIL_REGEX "unknown .*option" # Clang FAIL_REGEX "ignoring unknown option" # MSVC FAIL_REGEX "warning D9002" # MSVC, any lang + FAIL_REGEX "option .*not supported" # Intel FAIL_REGEX "[Uu]nknown option" # HP FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro FAIL_REGEX "command option .* is not recognized" # XL FAIL_REGEX "not supported in this configuration; ignored" # AIX FAIL_REGEX "File with unknown suffix passed to linker" # PGI + FAIL_REGEX "WARNING: unknown flag:" # Open64 ) SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") ENDMACRO (CHECK_CXX_COMPILER_FLAG) diff --git a/Modules/CheckCXXSourceCompiles.cmake b/Modules/CheckCXXSourceCompiles.cmake index 0491b3780..7f7336e5b 100644 --- a/Modules/CheckCXXSourceCompiles.cmake +++ b/Modules/CheckCXXSourceCompiles.cmake @@ -24,6 +24,9 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) IF("${VAR}" MATCHES "^${VAR}$") SET(_FAIL_REGEX) @@ -41,8 +44,10 @@ MACRO(CHECK_CXX_SOURCE_COMPILES SOURCE VAR) SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) diff --git a/Modules/CheckCXXSourceRuns.cmake b/Modules/CheckCXXSourceRuns.cmake index ace60d1a7..cd68d5706 100644 --- a/Modules/CheckCXXSourceRuns.cmake +++ b/Modules/CheckCXXSourceRuns.cmake @@ -24,13 +24,18 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_CXX_SOURCE_RUNS SOURCE VAR) IF("${VAR}" MATCHES "^${VAR}$") - SET(MACRO_CHECK_FUNCTION_DEFINITIONS + SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${VAR} ${CMAKE_REQUIRED_FLAGS}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_CXX_SOURCE_COMPILES_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) @@ -62,9 +67,9 @@ MACRO(CHECK_CXX_SOURCE_RUNS SOURCE VAR) IF("${${VAR}_EXITCODE}" EQUAL 0) SET(${VAR} 1 CACHE INTERNAL "Test ${VAR}") MESSAGE(STATUS "Performing Test ${VAR} - Success") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing C++ SOURCE FILE Test ${VAR} succeded with the following output:\n" - "${OUTPUT}\n" + "${OUTPUT}\n" "Return value: ${${VAR}}\n" "Source file was:\n${SOURCE}\n") ELSE("${${VAR}_EXITCODE}" EQUAL 0) @@ -75,9 +80,9 @@ MACRO(CHECK_CXX_SOURCE_RUNS SOURCE VAR) ENDIF(CMAKE_CROSSCOMPILING AND "${${VAR}_EXITCODE}" MATCHES "FAILED_TO_RUN") MESSAGE(STATUS "Performing Test ${VAR} - Failed") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing C++ SOURCE FILE Test ${VAR} failed with the following output:\n" - "${OUTPUT}\n" + "${OUTPUT}\n" "Return value: ${${VAR}_EXITCODE}\n" "Source file was:\n${SOURCE}\n") ENDIF("${${VAR}_EXITCODE}" EQUAL 0) diff --git a/Modules/CheckFortranFunctionExists.cmake b/Modules/CheckFortranFunctionExists.cmake index 6e932d09d..abec9f738 100644 --- a/Modules/CheckFortranFunctionExists.cmake +++ b/Modules/CheckFortranFunctionExists.cmake @@ -22,12 +22,17 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE) if(NOT DEFINED ${VARIABLE}) message(STATUS "Looking for Fortran ${FUNCTION}") if(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + cmake_expand_imported_targets(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") else(CMAKE_REQUIRED_LIBRARIES) set(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) endif(CMAKE_REQUIRED_LIBRARIES) @@ -50,13 +55,13 @@ macro(CHECK_FORTRAN_FUNCTION_EXISTS FUNCTION VARIABLE) if(${VARIABLE}) set(${VARIABLE} 1 CACHE INTERNAL "Have Fortran function ${FUNCTION}") message(STATUS "Looking for Fortran ${FUNCTION} - found") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining if the Fortran ${FUNCTION} exists passed with the following output:\n" "${OUTPUT}\n\n") else(${VARIABLE}) message(STATUS "Looking for Fortran ${FUNCTION} - not found") set(${VARIABLE} "" CACHE INTERNAL "Have Fortran function ${FUNCTION}") - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if the Fortran ${FUNCTION} exists failed with the following output:\n" "${OUTPUT}\n\n") endif(${VARIABLE}) diff --git a/Modules/CheckFunctionExists.cmake b/Modules/CheckFunctionExists.cmake index 0ba36d9aa..8c469f012 100644 --- a/Modules/CheckFunctionExists.cmake +++ b/Modules/CheckFunctionExists.cmake @@ -27,14 +27,19 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE) IF("${VARIABLE}" MATCHES "^${VARIABLE}$") - SET(MACRO_CHECK_FUNCTION_DEFINITIONS + SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") MESSAGE(STATUS "Looking for ${FUNCTION}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_FUNCTION_EXISTS_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) @@ -55,13 +60,13 @@ MACRO(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE) IF(${VARIABLE}) SET(${VARIABLE} 1 CACHE INTERNAL "Have function ${FUNCTION}") MESSAGE(STATUS "Looking for ${FUNCTION} - found") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining if the function ${FUNCTION} exists passed with the following output:\n" "${OUTPUT}\n\n") ELSE(${VARIABLE}) MESSAGE(STATUS "Looking for ${FUNCTION} - not found") SET(${VARIABLE} "" CACHE INTERNAL "Have function ${FUNCTION}") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if the function ${FUNCTION} exists failed with the following output:\n" "${OUTPUT}\n\n") ENDIF(${VARIABLE}) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index 75b5ca168..a94644e6a 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -13,7 +13,7 @@ # CMAKE_REQUIRED_INCLUDES = list of include directories #============================================================================= -# Copyright 2003-2009 Kitware, Inc. +# Copyright 2003-2012 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -44,7 +44,17 @@ MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE) CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY IMMEDIATE) - MESSAGE(STATUS "Looking for include files ${VARIABLE}") + SET(_INCLUDE ${INCLUDE}) # remove empty elements + IF("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$") + LIST(LENGTH _INCLUDE _INCLUDE_LEN) + SET(_description "${_INCLUDE_LEN} include files ${CMAKE_MATCH_1}, ..., ${CMAKE_MATCH_2}") + ELSEIF("${_INCLUDE}" MATCHES "^([^;]+);([^;]+)$") + SET(_description "include files ${CMAKE_MATCH_1}, ${CMAKE_MATCH_2}") + ELSE() + SET(_description "include file ${_INCLUDE}") + ENDIF() + + MESSAGE(STATUS "Looking for ${_description}") TRY_COMPILE(${VARIABLE} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c @@ -54,15 +64,15 @@ MACRO(CHECK_INCLUDE_FILES INCLUDE VARIABLE) "${CHECK_INCLUDE_FILES_INCLUDE_DIRS}" OUTPUT_VARIABLE OUTPUT) IF(${VARIABLE}) - MESSAGE(STATUS "Looking for include files ${VARIABLE} - found") - SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${VARIABLE}") + MESSAGE(STATUS "Looking for ${_description} - found") + SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${INCLUDE}") FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining if files ${INCLUDE} " "exist passed with the following output:\n" "${OUTPUT}\n\n") ELSE(${VARIABLE}) - MESSAGE(STATUS "Looking for include files ${VARIABLE} - not found.") - SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${VARIABLE}") + MESSAGE(STATUS "Looking for ${_description} - not found.") + SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${INCLUDE}") FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if files ${INCLUDE} " "exist failed with the following output:\n" diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake new file mode 100644 index 000000000..87a401813 --- /dev/null +++ b/Modules/CheckLanguage.cmake @@ -0,0 +1,65 @@ +# - Check if a language can be enabled +# Usage: +# check_language() +# where is a language that may be passed to enable_language() +# such as "Fortran". If CMAKE__COMPILER is already defined the +# check does nothing. Otherwise it tries enabling the language in a +# test project. The result is cached in CMAKE__COMPILER as the +# compiler that was found, or NOTFOUND if the language cannot be enabled. +# +# Example: +# check_language(Fortran) +# if(CMAKE_Fortran_COMPILER) +# enable_language(Fortran) +# else() +# message(STATUS "No Fortran support") +# endif() + +#============================================================================= +# Copyright 2009-2012 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +macro(check_language lang) + if(NOT DEFINED CMAKE_${lang}_COMPILER) + set(_desc "Looking for a ${lang} compiler") + message(STATUS ${_desc}) + file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt" + "cmake_minimum_required(VERSION 2.8) +project(Check${lang} ${lang}) +file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" + \"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\" + ) +") + execute_process( + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang} + COMMAND ${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE result + ) + include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/result.cmake OPTIONAL) + if(CMAKE_${lang}_COMPILER AND "${result}" STREQUAL "0") + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "${_desc} passed with the following output:\n" + "${output}\n") + else() + set(CMAKE_${lang}_COMPILER NOTFOUND) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "${_desc} failed with the following output:\n" + "${output}\n") + endif() + message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}") + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler") + mark_as_advanced(CMAKE_${lang}_COMPILER) + endif() +endmacro() diff --git a/Modules/CheckLibraryExists.cmake b/Modules/CheckLibraryExists.cmake index caf4f4c93..59fca0a32 100644 --- a/Modules/CheckLibraryExists.cmake +++ b/Modules/CheckLibraryExists.cmake @@ -26,21 +26,26 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) IF("${VARIABLE}" MATCHES "^${VARIABLE}$") - SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION + SET(MACRO_CHECK_LIBRARY_EXISTS_DEFINITION "-DCHECK_FUNCTION_EXISTS=${FUNCTION} ${CMAKE_REQUIRED_FLAGS}") MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY}") SET(CHECK_LIBRARY_EXISTS_LIBRARIES ${LIBRARY}) IF(CMAKE_REQUIRED_LIBRARIES) - SET(CHECK_LIBRARY_EXISTS_LIBRARIES - ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") + SET(CHECK_LIBRARY_EXISTS_LIBRARIES + ${CHECK_LIBRARY_EXISTS_LIBRARIES} ${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}) ENDIF(CMAKE_REQUIRED_LIBRARIES) TRY_COMPILE(${VARIABLE} ${CMAKE_BINARY_DIR} ${CMAKE_ROOT}/Modules/CheckFunctionExists.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - CMAKE_FLAGS + CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_LIBRARY_EXISTS_DEFINITION} -DLINK_DIRECTORIES:STRING=${LOCATION} "-DLINK_LIBRARIES:STRING=${CHECK_LIBRARY_EXISTS_LIBRARIES}" @@ -49,14 +54,14 @@ MACRO(CHECK_LIBRARY_EXISTS LIBRARY FUNCTION LOCATION VARIABLE) IF(${VARIABLE}) MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - found") SET(${VARIABLE} 1 CACHE INTERNAL "Have library ${LIBRARY}") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " "passed with the following output:\n" "${OUTPUT}\n\n") ELSE(${VARIABLE}) MESSAGE(STATUS "Looking for ${FUNCTION} in ${LIBRARY} - not found") SET(${VARIABLE} "" CACHE INTERNAL "Have library ${LIBRARY}") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if the function ${FUNCTION} exists in the ${LIBRARY} " "failed with the following output:\n" "${OUTPUT}\n\n") diff --git a/Modules/CheckPrototypeDefinition.cmake b/Modules/CheckPrototypeDefinition.cmake index 244b9b53b..63d424237 100644 --- a/Modules/CheckPrototypeDefinition.cmake +++ b/Modules/CheckPrototypeDefinition.cmake @@ -34,8 +34,11 @@ # License text for the above reference.) # +include("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + get_filename_component(__check_proto_def_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) + function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE) if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$") @@ -43,8 +46,10 @@ function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIAB set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS}) if (CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + cmake_expand_imported_targets(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") set(CHECK_PROTOTYPE_DEFINITION_LIBS - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") else(CMAKE_REQUIRED_LIBRARIES) set(CHECK_PROTOTYPE_DEFINITION_LIBS) endif(CMAKE_REQUIRED_LIBRARIES) diff --git a/Modules/CheckSymbolExists.cmake b/Modules/CheckSymbolExists.cmake index 183b2bbe6..e6e677d4f 100644 --- a/Modules/CheckSymbolExists.cmake +++ b/Modules/CheckSymbolExists.cmake @@ -35,6 +35,9 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_SYMBOL_EXISTS SYMBOL FILES VARIABLE) _CHECK_SYMBOL_EXISTS("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSymbolExists.c" "${SYMBOL}" "${FILES}" "${VARIABLE}" ) ENDMACRO(CHECK_SYMBOL_EXISTS) @@ -44,8 +47,10 @@ MACRO(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE) SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") SET(MACRO_CHECK_SYMBOL_EXISTS_FLAGS ${CMAKE_REQUIRED_FLAGS}) IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_SYMBOL_EXISTS_LIBS - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_SYMBOL_EXISTS_LIBS) ENDIF(CMAKE_REQUIRED_LIBRARIES) @@ -60,7 +65,7 @@ MACRO(_CHECK_SYMBOL_EXISTS SOURCEFILE SYMBOL FILES VARIABLE) "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n") ENDFOREACH(FILE) SET(CMAKE_CONFIGURABLE_FILE_CONTENT - "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nvoid cmakeRequireSymbol(int dummy,...){(void)dummy;}\nint main()\n{\n#ifndef ${SYMBOL}\n cmakeRequireSymbol(0,&${SYMBOL});\n#endif\n return 0;\n}\n") + "${CMAKE_CONFIGURABLE_FILE_CONTENT}\nint main(int argc, char** argv)\n{\n (void)argv;\n#ifndef ${SYMBOL}\n return ((int*)(&${SYMBOL}))[argc];\n#else\n (void)argc;\n return 0;\n#endif\n}\n") CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" "${SOURCEFILE}" @ONLY IMMEDIATE) diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake index 5d5c931b9..1717718c9 100644 --- a/Modules/CheckTypeSize.cmake +++ b/Modules/CheckTypeSize.cmake @@ -47,6 +47,7 @@ # License text for the above reference.) include(CheckIncludeFile) +include("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") cmake_policy(PUSH) cmake_minimum_required(VERSION 2.6 FATAL_ERROR) @@ -76,6 +77,10 @@ function(__check_type_size_impl type var map builtin) endforeach() # Perform the check. + + # this one translates potentially used imported library targets to their files on disk + cmake_expand_imported_targets(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c) set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin) configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY) @@ -84,7 +89,7 @@ function(__check_type_size_impl type var map builtin) CMAKE_FLAGS "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}" "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}" - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}" + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}" OUTPUT_VARIABLE output COPY_FILE ${bin} ) diff --git a/Modules/CheckVariableExists.cmake b/Modules/CheckVariableExists.cmake index 98328912c..7d6c7945d 100644 --- a/Modules/CheckVariableExists.cmake +++ b/Modules/CheckVariableExists.cmake @@ -1,6 +1,6 @@ # - Check if the variable exists. # CHECK_VARIABLE_EXISTS(VAR VARIABLE) -# +# # VAR - the name of the variable # VARIABLE - variable to store the result # @@ -26,14 +26,19 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +INCLUDE("${CMAKE_CURRENT_LIST_DIR}/CMakeExpandImportedTargets.cmake") + + MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE) IF("${VARIABLE}" MATCHES "^${VARIABLE}$") - SET(MACRO_CHECK_VARIABLE_DEFINITIONS + SET(MACRO_CHECK_VARIABLE_DEFINITIONS "-DCHECK_VARIABLE_EXISTS=${VAR} ${CMAKE_REQUIRED_FLAGS}") MESSAGE(STATUS "Looking for ${VAR}") IF(CMAKE_REQUIRED_LIBRARIES) + # this one translates potentially used imported library targets to their files on disk + CMAKE_EXPAND_IMPORTED_TARGETS(_ADJUSTED_CMAKE_REQUIRED_LIBRARIES LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CONFIGURATION "${CMAKE_TRY_COMPILE_CONFIGURATION}") SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES - "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}") + "-DLINK_LIBRARIES:STRING=${_ADJUSTED_CMAKE_REQUIRED_LIBRARIES}") ELSE(CMAKE_REQUIRED_LIBRARIES) SET(CHECK_VARIABLE_EXISTS_ADD_LIBRARIES) ENDIF(CMAKE_REQUIRED_LIBRARIES) @@ -47,13 +52,13 @@ MACRO(CHECK_VARIABLE_EXISTS VAR VARIABLE) IF(${VARIABLE}) SET(${VARIABLE} 1 CACHE INTERNAL "Have variable ${VAR}") MESSAGE(STATUS "Looking for ${VAR} - found") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Determining if the variable ${VAR} exists passed with the following output:\n" "${OUTPUT}\n\n") ELSE(${VARIABLE}) SET(${VARIABLE} "" CACHE INTERNAL "Have variable ${VAR}") MESSAGE(STATUS "Looking for ${VAR} - not found") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Determining if the variable ${VAR} exists failed with the following output:\n" "${OUTPUT}\n\n") ENDIF(${VARIABLE}) diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 8d6f5dfb8..c74c17919 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -24,6 +24,18 @@ macro(__compiler_gnu lang) set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC") set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared") + # Older versions of gcc (< 4.5) contain a bug causing them to report a missing + # header file as a warning if depfiles are enabled, causing check_header_file + # tests to always succeed. Work around this by disabling dependency tracking + # in try_compile mode. + GET_PROPERTY(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE) + if(NOT _IN_TC OR CMAKE_FORCE_DEPFILES) + # distcc does not transform -o to -MT when invoking the preprocessor + # internally, as it ought to. Work around this bug by setting -MT here + # even though it isn't strictly necessary. + set(CMAKE_DEPFILE_FLAGS_${lang} "-MMD -MT -MF ") + endif() + # Initial configuration flags. set(CMAKE_${lang}_FLAGS_INIT "") set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g") diff --git a/Modules/DeployQt4.cmake b/Modules/DeployQt4.cmake index 83f322c2d..b37695d4b 100644 --- a/Modules/DeployQt4.cmake +++ b/Modules/DeployQt4.cmake @@ -82,6 +82,7 @@ include(BundleUtilities) set(DeployQt4_cmake_dir "${CMAKE_CURRENT_LIST_DIR}") +set(DeployQt4_apple_plugins_dir "PlugIns") function(write_qt4_conf qt_conf_dir qt_conf_contents) set(qt_conf_path "${qt_conf_dir}/qt.conf") @@ -125,11 +126,17 @@ function(fixup_qt4_executable executable) if(QT_LIBRARY_DIR) list(APPEND dirs "${QT_LIBRARY_DIR}") endif() + if(QT_BINARY_DIR) + list(APPEND dirs "${QT_BINARY_DIR}") + endif() if(APPLE) set(qt_conf_dir "${executable}/Contents/Resources") set(executable_path "${executable}") set(write_qt_conf TRUE) + if(NOT plugins_dir) + set(plugins_dir "${DeployQt4_apple_plugins_dir}") + endif() else() get_filename_component(executable_path "${executable}" PATH) if(NOT executable_path) @@ -141,7 +148,7 @@ function(fixup_qt4_executable executable) foreach(plugin ${qtplugins}) set(installed_plugin_path "") - install_qt4_plugin("${plugin}" "${plugins_dir}" "${executable}" 1 installed_plugin_path) + install_qt4_plugin("${plugin}" "${executable}" 1 installed_plugin_path) list(APPEND libs ${installed_plugin_path}) endforeach() @@ -166,23 +173,19 @@ function(install_qt4_plugin_path plugin executable copy installed_plugin_path_va set(component ${ARGV5}) set(configurations ${ARGV6}) if(EXISTS "${plugin}") - if(plugins_dir) - set(plugins_dir "${plugins_dir}") - else() - if(APPLE) - set(plugins_dir "PlugIns") - else() - set(plugins_dir "plugins") - endif() - endif() if(APPLE) + if(NOT plugins_dir) + set(plugins_dir "${DeployQt4_apple_plugins_dir}") + endif() set(plugins_path "${executable}/Contents/${plugins_dir}") else() - get_filename_component(executable_path "${executable}" PATH) - if(NOT executable_path) - set(executable_path ".") + get_filename_component(plugins_path "${executable}" PATH) + if(NOT plugins_path) + set(plugins_path ".") + endif() + if(plugins_dir) + set(plugins_path "${plugins_path}/${plugins_dir}") endif() - set(plugins_path "${executable_path}/${plugins_dir}") endif() set(plugin_group "") @@ -210,7 +213,7 @@ function(install_qt4_plugin_path plugin executable copy installed_plugin_path_va endif() install(FILES "${plugin}" DESTINATION "${plugins_path}" ${configurations} ${component}) endif() - set(${installed_plugin_path_var} ${${installed_path_var}} "${plugins_path}/${plugin_name}" PARENT_SCOPE) + set(${installed_plugin_path_var} "${plugins_path}/${plugin_name}" PARENT_SCOPE) endif() endfunction() @@ -220,11 +223,7 @@ function(install_qt4_plugin plugin executable copy installed_plugin_path_var) if(EXISTS "${plugin}") install_qt4_plugin_path("${plugin}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}") else() - if(QT_IS_STATIC) - string(TOUPPER "QT_${plugin}_LIBRARY" plugin_var) - else() - string(TOUPPER "QT_${plugin}_PLUGIN" plugin_var) - endif() + string(TOUPPER "QT_${plugin}_PLUGIN" plugin_var) set(plugin_release_var "${plugin_var}_RELEASE") set(plugin_debug_var "${plugin_var}_DEBUG") set(plugin_release "${${plugin_release_var}}") @@ -232,10 +231,24 @@ function(install_qt4_plugin plugin executable copy installed_plugin_path_var) if(DEFINED "${plugin_release_var}" AND DEFINED "${plugin_debug_var}" AND NOT EXISTS "${plugin_release}" AND NOT EXISTS "${plugin_debug}") message(WARNING "Qt plugin \"${plugin}\" not recognized or found.") endif() - install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}" "Release|RelWithDebInfo|MinSizeRel") - install_qt4_plugin_path("${plugin_debug}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}" "Debug") + if(NOT EXISTS "${${plugin_debug_var}}") + set(plugin_debug "${plugin_release}") + endif() + + if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) + install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}_release" "${plugins_dir}" "${component}" "Release|RelWithDebInfo|MinSizeRel") + install_qt4_plugin_path("${plugin_debug}" "${executable}" "${copy}" "${installed_plugin_path_var}_debug" "${plugins_dir}" "${component}" "Debug") + + if(CMAKE_BUILD_TYPE MATCHES "^Debug$") + set(${installed_plugin_path_var} ${${installed_plugin_path_var}_debug}) + else() + set(${installed_plugin_path_var} ${${installed_plugin_path_var}_release}) + endif() + else() + install_qt4_plugin_path("${plugin_release}" "${executable}" "${copy}" "${installed_plugin_path_var}" "${plugins_dir}" "${component}") + endif() endif() - set(installed_plugin_path_var "${installed_plugin_path_var}" PARENT_SCOPE) + set(${installed_plugin_path_var} ${${installed_plugin_path_var}} PARENT_SCOPE) endfunction() function(install_qt4_executable executable) @@ -248,6 +261,9 @@ function(install_qt4_executable executable) if(QT_LIBRARY_DIR) list(APPEND dirs "${QT_LIBRARY_DIR}") endif() + if(QT_BINARY_DIR) + list(APPEND dirs "${QT_BINARY_DIR}") + endif() if(component) set(component COMPONENT ${component}) else() @@ -264,16 +280,16 @@ function(install_qt4_executable executable) set(qt_plugins_dir "") endif() - if(NOT qtplugins AND QT_LIBRARIES_PLUGINS) - set(qtplugins "${QT_LIBRARIES_PLUGINS}") + if(QT_IS_STATIC) + message(WARNING "Qt built statically: not installing plugins.") + else() + foreach(plugin ${qtplugins}) + set(installed_plugin_paths "") + install_qt4_plugin("${plugin}" "${executable}" 0 installed_plugin_paths "${plugins_dir}" "${component}") + list(APPEND libs ${installed_plugin_paths}) + endforeach() endif() - foreach(plugin ${qtplugins}) - set(installed_plugin_paths "") - install_qt4_plugin("${plugin}" "${executable}" 0 installed_plugin_paths "${plugins_dir}" "${component}") - list(APPEND libs ${installed_plugin_paths}) - endforeach() - resolve_qt4_paths(libs) install(CODE diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index a37771b92..b6fe19004 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -144,7 +144,7 @@ # set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test) #============================================================================= -# Copyright 2008-2009 Kitware, Inc. +# Copyright 2008-2012 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -833,6 +833,12 @@ function(ExternalProject_Add_StepTargets name) foreach(step ${steps}) add_custom_target(${name}-${step} DEPENDS ${stamp_dir}${cfgdir}/${name}-${step}) + + # Depend on other external projects (target-level). + get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS) + foreach(arg IN LISTS deps) + add_dependencies(${name}-${step} ${arg}) + endforeach() endforeach() endfunction(ExternalProject_Add_StepTargets) @@ -954,6 +960,7 @@ function(_ep_get_git_version git_EXECUTABLE git_version_var) execute_process( COMMAND "${git_EXECUTABLE}" --version OUTPUT_VARIABLE ov + ERROR_VARIABLE ev OUTPUT_STRIP_TRAILING_WHITESPACE ) string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}") @@ -1450,9 +1457,18 @@ function(ExternalProject_Add name) # depends on the 'done' mark so that it rebuilds when this project # rebuilds. It is important that 'done' is not the output of any # custom command so that CMake does not propagate build rules to - # other external project targets. + # other external project targets, which may cause problems during + # parallel builds. However, the Ninja generator needs to see the entire + # dependency graph, and can cope with custom commands belonging to + # multiple targets, so we add the 'done' mark as an output for Ninja only. + set(complete_outputs ${cmf_dir}${cfgdir}/${name}-complete) + if(${CMAKE_GENERATOR} MATCHES "Ninja") + set(complete_outputs + ${complete_outputs} ${stamp_dir}${cfgdir}/${name}-done) + endif() + add_custom_command( - OUTPUT ${cmf_dir}${cfgdir}/${name}-complete + OUTPUT ${complete_outputs} COMMENT "Completed '${name}'" COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir} COMMAND ${CMAKE_COMMAND} -E touch ${cmf_dir}${cfgdir}/${name}-complete diff --git a/Modules/FeatureSummary.cmake b/Modules/FeatureSummary.cmake index eb10cbc94..cef647eb5 100644 --- a/Modules/FeatureSummary.cmake +++ b/Modules/FeatureSummary.cmake @@ -125,7 +125,7 @@ # # set_package_properties(LibXml2 PROPERTIES TYPE RECOMMENDED # PURPOSE "Enables HTML-import in MyWordProcessor") -# ... +# ... # set_package_properties(LibXml2 PROPERTIES TYPE OPTIONAL # PURPOSE "Enables odt-export in MyWordProcessor") # diff --git a/Modules/FindALSA.cmake b/Modules/FindALSA.cmake index af84f8cd6..4a0b69303 100644 --- a/Modules/FindALSA.cmake +++ b/Modules/FindALSA.cmake @@ -8,11 +8,12 @@ # # ALSA_INCLUDE_DIR - where to find asoundlib.h, etc. # ALSA_LIBRARY - the asound library +# ALSA_VERSION_STRING - the version of alsa found (since CMake 2.8.8) # #============================================================================= -# Copyright 2009 Kitware, Inc. -# Copyright 2009 Philip Lowman +# Copyright 2009-2011 Kitware, Inc. +# Copyright 2009-2011 Philip Lowman # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -24,8 +25,7 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -find_path(ALSA_INCLUDE_DIR NAMES asoundlib.h - PATH_SUFFIXES alsa +find_path(ALSA_INCLUDE_DIR NAMES alsa/asoundlib.h DOC "The ALSA (asound) include directory" ) @@ -33,10 +33,19 @@ find_library(ALSA_LIBRARY NAMES asound DOC "The ALSA (asound) library" ) +if(ALSA_INCLUDE_DIR AND EXISTS "${ALSA_INCLUDE_DIR}/alsa/version.h") + file(STRINGS "${ALSA_INCLUDE_DIR}/alsa/version.h" alsa_version_str REGEX "^#define[\t ]+SND_LIB_VERSION_STR[\t ]+\".*\"") + + string(REGEX REPLACE "^.*SND_LIB_VERSION_STR[\t ]+\"([^\"]*)\".*$" "\\1" ALSA_VERSION_STRING "${alsa_version_str}") + unset(alsa_version_str) +endif() + # handle the QUIETLY and REQUIRED arguments and set ALSA_FOUND to TRUE if # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA DEFAULT_MSG ALSA_LIBRARY ALSA_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALSA + REQUIRED_VARS ALSA_LIBRARY ALSA_INCLUDE_DIR + VERSION_VAR ALSA_VERSION_STRING) if(ALSA_FOUND) set( ALSA_LIBRARIES ${ALSA_LIBRARY} ) diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake index edde9eb96..7af336788 100644 --- a/Modules/FindBISON.cmake +++ b/Modules/FindBISON.cmake @@ -75,8 +75,9 @@ IF(BISON_EXECUTABLE) ELSEIF("${BISON_version_output}" MATCHES "^bison[^+]") STRING(REGEX REPLACE "^bison \\(GNU Bison\\) ([^\n]+)\n.*" "\\1" BISON_VERSION "${BISON_version_output}") - ELSE() - SET(BISON_VERSION "unknown") + ELSEIF("${BISON_version_output}" MATCHES "^GNU Bison ") + STRING(REGEX REPLACE "^GNU Bison (version )?([^\n]+).*" "\\2" + BISON_VERSION "${BISON_version_output}") ENDIF() ENDIF() diff --git a/Modules/FindBLAS.cmake b/Modules/FindBLAS.cmake index 9b76d909c..9eadfd125 100644 --- a/Modules/FindBLAS.cmake +++ b/Modules/FindBLAS.cmake @@ -23,6 +23,7 @@ ########## ### List of vendors (BLA_VENDOR) valid in this module ## Goto,ATLAS PhiPACK,CXML,DXML,SunPerf,SCSL,SGIMATH,IBMESSL,Intel10_32 (intel mkl v10 32 bit),Intel10_64lp (intel mkl v10 64 bit,lp thread model, lp64 model), +## Intel10_64lp_seq (intel mkl v10 64 bit,sequential code, lp64 model), ## Intel( older versions of mkl 32 and 64 bit), ACML,ACML_MP,ACML_GPU,Apple, NAS, Generic # C/CXX should be enabled to use Intel mkl @@ -85,6 +86,7 @@ if (NOT _libdir) set(_libdir /usr/local/lib /usr/lib /usr/local/lib64 /usr/lib64 ENV LD_LIBRARY_PATH) endif () endif () + foreach(_library ${_list}) set(_combined_name ${_combined_name}_${_library}) @@ -115,7 +117,7 @@ foreach(_library ${_list}) endforeach(_library ${_list}) if(_libraries_work) # Test this combination of libraries. - set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threads}) + set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread}) # message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") if (_CHECK_FORTRAN) check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS) @@ -460,117 +462,99 @@ if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") else(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) find_package(Threads REQUIRED) endif(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) - if (WIN32) + + set(BLAS_SEARCH_LIBS "") + if(BLA_F95) - if(NOT BLAS95_LIBRARIES) - check_fortran_libraries( - BLAS95_LIBRARIES - BLAS - sgemm - "" - "mkl_blas95;mkl_intel_c;mkl_intel_thread;mkl_core;libguide40" - "" - ) - endif(NOT BLAS95_LIBRARIES) - else(BLA_F95) - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - SGEMM - "" - "mkl_c_dll;mkl_intel_thread_dll;mkl_core_dll;libguide40" - "" - ) - endif(NOT BLAS_LIBRARIES) - endif(BLA_F95) - else(WIN32) - if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - if(BLA_F95) - if(NOT BLAS95_LIBRARIES) - check_fortran_libraries( - BLAS95_LIBRARIES - BLAS - sgemm - "" - "mkl_blas95;mkl_intel;mkl_intel_thread;mkl_core;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS95_LIBRARIES) - else(BLA_F95) - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "mkl_intel;mkl_intel_thread;mkl_core;guide" - "${CMAKE_THREAD_LIBS_INIT}" - "${LM}" - ) - endif(NOT BLAS_LIBRARIES) - endif(BLA_F95) - endif (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - if(BLA_F95) - if(NOT BLAS95_LIBRARIES) - check_fortran_libraries( - BLAS95_LIBRARIES - BLAS - sgemm - "" - "mkl_blas95;mkl_intel_lp64;mkl_intel_thread;mkl_core;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS95_LIBRARIES) - else(BLA_F95) - if(NOT BLAS_LIBRARIES) + set(BLAS_mkl_SEARCH_SYMBOL SGEMM) + set(_LIBRARIES BLAS95_LIBRARIES) + if (WIN32) + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95 mkl_intel_c mkl_intel_thread mkl_core libguide40") + else (WIN32) + if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide") + endif () + if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") + # old version + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide") + + # mkl >= 10.3 + if (CMAKE_C_COMPILER MATCHES ".+gcc.*") + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core") + set(LM "${LM};-lgomp") + else () + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core iomp5") + endif () + endif () + endif (WIN32) + if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS + "mkl_blas95_lp64 mkl_intel_lp64 mkl_sequential mkl_core") + endif () + else (BLA_F95) + set(BLAS_mkl_SEARCH_SYMBOL sgemm) + set(_LIBRARIES BLAS_LIBRARIES) + if (WIN32) + list(APPEND BLAS_SEARCH_LIBS + "mkl_c_dll mkl_intel_thread_dll mkl_core_dll libguide40") + else (WIN32) + if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS + "mkl_intel mkl_intel_thread mkl_core guide") + endif () + if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") + + # old version + list(APPEND BLAS_SEARCH_LIBS + "mkl_intel_lp64 mkl_intel_thread mkl_core guide") + + # mkl >= 10.3 + if (CMAKE_C_COMPILER MATCHES ".+gcc.*") + list(APPEND BLAS_SEARCH_LIBS + "mkl_intel_lp64 mkl_gnu_thread mkl_core") + set(LM "${LM};-lgomp") + else () + list(APPEND BLAS_SEARCH_LIBS + "mkl_intel_lp64 mkl_intel_thread mkl_core iomp5") + endif () + endif () + + #older vesions of intel mkl libs + if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS + "mkl") + list(APPEND BLAS_SEARCH_LIBS + "mkl_ia32") + list(APPEND BLAS_SEARCH_LIBS + "mkl_em64t") + endif () + endif (WIN32) + if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All") + list(APPEND BLAS_SEARCH_LIBS + "mkl_intel_lp64 mkl_sequential mkl_core") + endif () + endif (BLA_F95) + + foreach (IT ${BLAS_SEARCH_LIBS}) + string(REPLACE " " ";" SEARCH_LIBS ${IT}) + if (${_LIBRARIES}) + else () check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "mkl_intel_lp64;mkl_intel_thread;mkl_core;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS_LIBRARIES) - endif(BLA_F95) - endif (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - endif (WIN32) - #older vesions of intel mkl libs - # BLAS in intel mkl library? (shared) - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "mkl;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS_LIBRARIES) - #BLAS in intel mkl library? (static, 32bit) - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "mkl_ia32;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS_LIBRARIES) - #BLAS in intel mkl library? (static, em64t 64bit) - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "mkl_em64t;guide" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif(NOT BLAS_LIBRARIES) + ${_LIBRARIES} + BLAS + ${BLAS_mkl_SEARCH_SYMBOL} + "" + "${SEARCH_LIBS}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + endif () + endforeach () + endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) endif (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") diff --git a/Modules/FindBZip2.cmake b/Modules/FindBZip2.cmake index 679c1298e..713019259 100644 --- a/Modules/FindBZip2.cmake +++ b/Modules/FindBZip2.cmake @@ -5,10 +5,12 @@ # BZIP2_INCLUDE_DIR - the BZip2 include directory # BZIP2_LIBRARIES - Link these to use BZip2 # BZIP2_NEED_PREFIX - this is set if the functions are prefixed with BZ2_ +# BZIP2_VERSION_STRING - the version of BZip2 found (since CMake 2.8.8) #============================================================================= -# Copyright 2006-2009 Kitware, Inc. +# Copyright 2006-2012 Kitware, Inc. # Copyright 2006 Alexander Neundorf +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -22,17 +24,29 @@ FIND_PATH(BZIP2_INCLUDE_DIR bzlib.h ) -FIND_LIBRARY(BZIP2_LIBRARIES NAMES bz2 bzip2 ) +IF (NOT BZIP2_LIBRARIES) + FIND_LIBRARY(BZIP2_LIBRARY_RELEASE NAMES bz2 bzip2 ) + FIND_LIBRARY(BZIP2_LIBRARY_DEBUG NAMES bzip2d ) + + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + SELECT_LIBRARY_CONFIGURATIONS(BZIP2) +ENDIF (NOT BZIP2_LIBRARIES) + +IF (BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h") + FILE(STRINGS "${BZIP2_INCLUDE_DIR}/bzlib.h" BZLIB_H REGEX "bzip2/libbzip2 version [0-9]+\\.[^ ]+ of [0-9]+ ") + STRING(REGEX REPLACE ".* bzip2/libbzip2 version ([0-9]+\\.[^ ]+) of [0-9]+ .*" "\\1" BZIP2_VERSION_STRING "${BZLIB_H}") +ENDIF (BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h") # handle the QUIETLY and REQUIRED arguments and set BZip2_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2 DEFAULT_MSG BZIP2_LIBRARIES BZIP2_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(BZip2 + REQUIRED_VARS BZIP2_LIBRARIES BZIP2_INCLUDE_DIR + VERSION_VAR BZIP2_VERSION_STRING) IF (BZIP2_FOUND) INCLUDE(CheckLibraryExists) - CHECK_LIBRARY_EXISTS(${BZIP2_LIBRARIES} BZ2_bzCompressInit "" BZIP2_NEED_PREFIX) + CHECK_LIBRARY_EXISTS("${BZIP2_LIBRARIES}" BZ2_bzCompressInit "" BZIP2_NEED_PREFIX) ENDIF (BZIP2_FOUND) -MARK_AS_ADVANCED(BZIP2_INCLUDE_DIR BZIP2_LIBRARIES) - +MARK_AS_ADVANCED(BZIP2_INCLUDE_DIR) diff --git a/Modules/FindBoost.cmake b/Modules/FindBoost.cmake index 9c03b3d1d..7504ea44c 100644 --- a/Modules/FindBoost.cmake +++ b/Modules/FindBoost.cmake @@ -65,7 +65,8 @@ # 1.33, 1.33.0, 1.33.1, 1.34, 1.34.0, 1.34.1, 1.35, 1.35.0, 1.35.1, # 1.36, 1.36.0, 1.36.1, 1.37, 1.37.0, 1.38, 1.38.0, 1.39, 1.39.0, # 1.40, 1.40.0, 1.41, 1.41.0, 1.42, 1.42.0, 1.43, 1.43.0, 1.44, 1.44.0, -# 1.45, 1.45.0, 1.46, 1.46.0, 1.46.1, 1.47, 1.47.0, 1.48, 1.48.0 +# 1.45, 1.45.0, 1.46, 1.46.0, 1.46.1, 1.47, 1.47.0, 1.48, 1.48.0, +# 1.49, 1.49.0, 1.50, 1.50.0 # # NOTE: If you add a new major 1.x version in Boost_ADDITIONAL_VERSIONS you should # add both 1.x and 1.x.0 as shown above. Official Boost include directories @@ -449,7 +450,7 @@ else(Boost_FIND_VERSION_EXACT) # The user has not requested an exact version. Among known # versions, find those that are acceptable to the user request. set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" + "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0" diff --git a/Modules/FindCUDA.cmake b/Modules/FindCUDA.cmake index 18f7442cc..9f8d5755f 100644 --- a/Modules/FindCUDA.cmake +++ b/Modules/FindCUDA.cmake @@ -216,6 +216,18 @@ # CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS # implementation (alterative to: # CUDA_ADD_CUBLAS_TO_TARGET macro). +# CUDA_curand_LIBRARY -- CUDA Random Number Generation library. +# Only available for CUDA version 3.2+. +# CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library. +# Only available for CUDA version 3.2+. +# CUDA_npp_LIBRARY -- NVIDIA Performance Primitives library. +# Only available for CUDA version 4.0+. +# CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library. +# Only available for CUDA version 3.2+. +# Windows only. +# CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library. +# Only available for CUDA version 3.2+. +# Windows only. # # # James Bigler, NVIDIA Corp (nvidia.com - jbigler) @@ -430,6 +442,11 @@ if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") unset(CUDA_cublasemu_LIBRARY CACHE) unset(CUDA_cufft_LIBRARY CACHE) unset(CUDA_cufftemu_LIBRARY CACHE) + unset(CUDA_curand_LIBRARY CACHE) + unset(CUDA_cusparse_LIBRARY CACHE) + unset(CUDA_npp_LIBRARY CACHE) + unset(CUDA_nvcuvenc_LIBRARY CACHE) + unset(CUDA_nvcuvid_LIBRARY CACHE) endif() if(NOT "${CUDA_SDK_ROOT_DIR}" STREQUAL "${CUDA_SDK_ROOT_DIR_INTERNAL}") @@ -600,7 +617,7 @@ if(CUDA_VERSION VERSION_GREATER "3.0") endif() endif() -# Search for cufft and cublas libraries. +# Search for additional CUDA toolkit libraries. if(CUDA_VERSION VERSION_LESS "3.1") # Emulation libraries aren't available in version 3.1 onward. find_cuda_helper_libs(cufftemu) @@ -608,6 +625,18 @@ if(CUDA_VERSION VERSION_LESS "3.1") endif() find_cuda_helper_libs(cufft) find_cuda_helper_libs(cublas) +if(NOT CUDA_VERSION VERSION_LESS "3.2") + # cusparse showed up in version 3.2 + find_cuda_helper_libs(cusparse) + find_cuda_helper_libs(curand) + if (WIN32) + find_cuda_helper_libs(nvcuvenc) + find_cuda_helper_libs(nvcuvid) + endif() +endif() +if(NOT CUDA_VERSION VERSION_LESS "4.0") + find_cuda_helper_libs(npp) +endif() if (CUDA_BUILD_EMULATION) set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY}) @@ -877,7 +906,7 @@ macro(CUDA_WRAP_SRCS cuda_target format generated_files) message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS: '${format}'. Use OBJ or PTX.") endif() - # Set up all the command line flags here, so that they can be overriden on a per target basis. + # Set up all the command line flags here, so that they can be overridden on a per target basis. set(nvcc_flags "") diff --git a/Modules/FindCURL.cmake b/Modules/FindCURL.cmake index 36f384130..cc00d53f4 100644 --- a/Modules/FindCURL.cmake +++ b/Modules/FindCURL.cmake @@ -1,12 +1,14 @@ # - Find curl # Find the native CURL headers and libraries. # -# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc. -# CURL_LIBRARIES - List of libraries when using curl. -# CURL_FOUND - True if curl found. +# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc. +# CURL_LIBRARIES - List of libraries when using curl. +# CURL_FOUND - True if curl found. +# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8) #============================================================================= # Copyright 2006-2009 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -32,10 +34,24 @@ FIND_LIBRARY(CURL_LIBRARY NAMES ) MARK_AS_ADVANCED(CURL_LIBRARY) +IF(CURL_INCLUDE_DIR) + FOREACH(_curl_version_header curlver.h curl.h) + IF(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") + FILE(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") + + STRING(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") + UNSET(curl_version_str) + BREAK() + ENDIF() + ENDFOREACH(_curl_version_header) +ENDIF() + # handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL DEFAULT_MSG CURL_LIBRARY CURL_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL + REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR + VERSION_VAR CURL_VERSION_STRING) IF(CURL_FOUND) SET(CURL_LIBRARIES ${CURL_LIBRARY}) diff --git a/Modules/FindCups.cmake b/Modules/FindCups.cmake index 7e3e10ab1..3862f7ddf 100644 --- a/Modules/FindCups.cmake +++ b/Modules/FindCups.cmake @@ -4,12 +4,14 @@ # CUPS_FOUND - system has Cups # CUPS_INCLUDE_DIR - the Cups include directory # CUPS_LIBRARIES - Libraries needed to use Cups +# CUPS_VERSION_STRING - version of Cups found (since CMake 2.8.8) # Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which # features this function (i.e. at least 1.1.19) #============================================================================= # Copyright 2006-2009 Kitware, Inc. # Copyright 2006 Alexander Neundorf +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -21,36 +23,47 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -INCLUDE(CheckLibraryExists) +find_path(CUPS_INCLUDE_DIR cups/cups.h ) -FIND_PATH(CUPS_INCLUDE_DIR cups/cups.h ) +find_library(CUPS_LIBRARIES NAMES cups ) -FIND_LIBRARY(CUPS_LIBRARIES NAMES cups ) +if (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES AND CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE) + include(CheckLibraryExists) -IF (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES) - SET(CUPS_FOUND TRUE) + # ippDeleteAttribute is new in cups-1.1.19 (and used by kdeprint) + CHECK_LIBRARY_EXISTS(cups ippDeleteAttribute "" CUPS_HAS_IPP_DELETE_ATTRIBUTE) +endif (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES AND CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE) - # ippDeleteAttribute is new in cups-1.1.19 (and used by kdeprint) - CHECK_LIBRARY_EXISTS(cups ippDeleteAttribute "" CUPS_HAS_IPP_DELETE_ATTRIBUTE) - IF (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE AND NOT CUPS_HAS_IPP_DELETE_ATTRIBUTE) - SET(CUPS_FOUND FALSE) - ENDIF (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE AND NOT CUPS_HAS_IPP_DELETE_ATTRIBUTE) +if (CUPS_INCLUDE_DIR AND EXISTS "${CUPS_INCLUDE_DIR}/cups/cups.h") + file(STRINGS "${CUPS_INCLUDE_DIR}/cups/cups.h" cups_version_str + REGEX "^#[\t ]*define[\t ]+CUPS_VERSION_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$") -ELSE (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES) - SET(CUPS_FOUND FALSE) -ENDIF (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES) + unset(CUPS_VERSION_STRING) + foreach(VPART MAJOR MINOR PATCH) + foreach(VLINE ${cups_version_str}) + if(VLINE MATCHES "^#[\t ]*define[\t ]+CUPS_VERSION_${VPART}") + string(REGEX REPLACE "^#[\t ]*define[\t ]+CUPS_VERSION_${VPART}[\t ]+([0-9]+)$" "\\1" + CUPS_VERSION_PART "${VLINE}") + if(CUPS_VERSION_STRING) + set(CUPS_VERSION_STRING "${CUPS_VERSION_STRING}.${CUPS_VERSION_PART}") + else(CUPS_VERSION_STRING) + set(CUPS_VERSION_STRING "${CUPS_VERSION_PART}") + endif(CUPS_VERSION_STRING) + endif() + endforeach(VLINE) + endforeach(VPART) +endif (CUPS_INCLUDE_DIR AND EXISTS "${CUPS_INCLUDE_DIR}/cups/cups.h") -IF (CUPS_FOUND) - IF (NOT Cups_FIND_QUIETLY) - MESSAGE(STATUS "Found Cups: ${CUPS_LIBRARIES}") - ENDIF (NOT Cups_FIND_QUIETLY) -ELSE (CUPS_FOUND) - SET(CUPS_LIBRARIES ) - IF (Cups_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could NOT find Cups") - ENDIF (Cups_FIND_REQUIRED) -ENDIF (CUPS_FOUND) - - -MARK_AS_ADVANCED(CUPS_INCLUDE_DIR CUPS_LIBRARIES) +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + +if (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups + REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR CUPS_HAS_IPP_DELETE_ATTRIBUTE + VERSION_VAR CUPS_VERSION_STRING) +else (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups + REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR + VERSION_VAR CUPS_VERSION_STRING) +endif (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE) +mark_as_advanced(CUPS_INCLUDE_DIR CUPS_LIBRARIES) diff --git a/Modules/FindCxxTest.cmake b/Modules/FindCxxTest.cmake index 4ff310cc3..a4d150493 100644 --- a/Modules/FindCxxTest.cmake +++ b/Modules/FindCxxTest.cmake @@ -9,6 +9,7 @@ # Only used in the case both Python & Perl # are detected on the system to control # which CxxTest code generator is used. +# Valid only for CxxTest version 3. # # NOTE: In older versions of this Find Module, # this variable controlled if the Python test @@ -159,7 +160,8 @@ find_package(PythonInterp QUIET) find_package(Perl QUIET) find_path(CXXTEST_INCLUDE_DIR cxxtest/TestSuite.h) -find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE cxxtestgen.py +find_program(CXXTEST_PYTHON_TESTGEN_EXECUTABLE + NAMES cxxtestgen cxxtestgen.py PATHS ${CXXTEST_INCLUDE_DIR}) find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl PATHS ${CXXTEST_INCLUDE_DIR}) @@ -167,7 +169,7 @@ find_program(CXXTEST_PERL_TESTGEN_EXECUTABLE cxxtestgen.pl if(PYTHONINTERP_FOUND OR PERL_FOUND) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) - if(PYTHONINTERP_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND)) + if(PYTHONINTERP_FOUND AND (CXXTEST_USE_PYTHON OR NOT PERL_FOUND OR NOT DEFINED CXXTEST_USE_PYTHON)) set(CXXTEST_TESTGEN_EXECUTABLE ${CXXTEST_PYTHON_TESTGEN_EXECUTABLE}) set(CXXTEST_TESTGEN_INTERPRETER ${PYTHON_EXECUTABLE}) FIND_PACKAGE_HANDLE_STANDARD_ARGS(CxxTest DEFAULT_MSG diff --git a/Modules/FindDoxygen.cmake b/Modules/FindDoxygen.cmake index e5428aecb..6cc9efb18 100644 --- a/Modules/FindDoxygen.cmake +++ b/Modules/FindDoxygen.cmake @@ -11,6 +11,7 @@ # # DOXYGEN_EXECUTABLE = The path to the doxygen command. # DOXYGEN_FOUND = Was Doxygen found or not? +# DOXYGEN_VERSION = The version reported by doxygen --version # # DOXYGEN_DOT_EXECUTABLE = The path to the dot program used by doxygen. # DOXYGEN_DOT_FOUND = Was Dot found or not? @@ -76,8 +77,12 @@ FIND_PROGRAM(DOXYGEN_EXECUTABLE DOC "Doxygen documentation generation tool (http://www.doxygen.org)" ) +IF(DOXYGEN_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${DOXYGEN_EXECUTABLE} "--version" OUTPUT_VARIABLE DOXYGEN_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) +ENDIF() + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Doxygen DEFAULT_MSG DOXYGEN_EXECUTABLE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Doxygen REQUIRED_VARS DOXYGEN_EXECUTABLE VERSION_VAR DOXYGEN_VERSION) # # Find Dot... diff --git a/Modules/FindEXPAT.cmake b/Modules/FindEXPAT.cmake index 8551fd636..1bf074357 100644 --- a/Modules/FindEXPAT.cmake +++ b/Modules/FindEXPAT.cmake @@ -24,10 +24,32 @@ FIND_PATH(EXPAT_INCLUDE_DIR NAMES expat.h) # Look for the library. FIND_LIBRARY(EXPAT_LIBRARY NAMES expat libexpat) +if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h") + file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str + REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$") + + unset(EXPAT_VERSION_STRING) + foreach(VPART MAJOR MINOR MICRO) + foreach(VLINE ${expat_version_str}) + if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION") + string(REGEX REPLACE "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$" "\\1" + EXPAT_VERSION_PART "${VLINE}") + if(EXPAT_VERSION_STRING) + set(EXPAT_VERSION_STRING "${EXPAT_VERSION_STRING}.${EXPAT_VERSION_PART}") + else(EXPAT_VERSION_STRING) + set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}") + endif(EXPAT_VERSION_STRING) + endif() + endforeach(VLINE) + endforeach(VPART) +endif (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h") + # handle the QUIETLY and REQUIRED arguments and set EXPAT_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT DEFAULT_MSG EXPAT_LIBRARY EXPAT_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT + REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR + VERSION_VAR EXPAT_VERSION_STRING) # Copy the results to the output variables. IF(EXPAT_FOUND) diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index 6a70b4030..586f77a6e 100644 --- a/Modules/FindFLEX.cmake +++ b/Modules/FindFLEX.cmake @@ -91,8 +91,12 @@ IF(FLEX_EXECUTABLE) MESSAGE("Command \"${FLEX_EXECUTABLE} --version\" failed with output:\n${FLEX_version_output}\n${FLEX_version_error}\nFLEX_VERSION will not be available") ENDIF() ELSE() - STRING(REGEX REPLACE "^flex (.*)$" "\\1" + # older versions of flex printed "/full/path/to/executable version X.Y" + # newer versions use "basename(executable) X.Y" + GET_FILENAME_COMPONENT(FLEX_EXE_NAME "${FLEX_EXECUTABLE}" NAME) + STRING(REGEX REPLACE "^.*${FLEX_EXE_NAME}\"? (version )?([0-9]+[^ ]*)$" "\\2" FLEX_VERSION "${FLEX_version_output}") + UNSET(FLEX_EXE_NAME) ENDIF() #============================================================ diff --git a/Modules/FindFreetype.cmake b/Modules/FindFreetype.cmake index 6251805df..e6f670256 100644 --- a/Modules/FindFreetype.cmake +++ b/Modules/FindFreetype.cmake @@ -3,6 +3,7 @@ # FREETYPE_LIBRARIES, the library to link against # FREETYPE_FOUND, if false, do not try to link to FREETYPE # FREETYPE_INCLUDE_DIRS, where to find headers. +# FREETYPE_VERSION_STRING, the version of freetype found (since CMake 2.8.8) # This is the concatenation of the paths: # FREETYPE_INCLUDE_DIR_ft2build # FREETYPE_INCLUDE_DIR_freetype2 @@ -77,10 +78,33 @@ IF(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) ENDIF(FREETYPE_INCLUDE_DIR_ft2build AND FREETYPE_INCLUDE_DIR_freetype2) SET(FREETYPE_LIBRARIES "${FREETYPE_LIBRARY}") +IF(FREETYPE_INCLUDE_DIR_freetype2 AND EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") + FILE(STRINGS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h" freetype_version_str + REGEX "^#[\t ]*define[\t ]+FREETYPE_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$") + + UNSET(FREETYPE_VERSION_STRING) + FOREACH(VPART MAJOR MINOR PATCH) + FOREACH(VLINE ${freetype_version_str}) + IF(VLINE MATCHES "^#[\t ]*define[\t ]+FREETYPE_${VPART}") + STRING(REGEX REPLACE "^#[\t ]*define[\t ]+FREETYPE_${VPART}[\t ]+([0-9]+)$" "\\1" + FREETYPE_VERSION_PART "${VLINE}") + IF(FREETYPE_VERSION_STRING) + SET(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_STRING}.${FREETYPE_VERSION_PART}") + ELSE(FREETYPE_VERSION_STRING) + SET(FREETYPE_VERSION_STRING "${FREETYPE_VERSION_PART}") + ENDIF(FREETYPE_VERSION_STRING) + UNSET(FREETYPE_VERSION_PART) + ENDIF() + ENDFOREACH(VLINE) + ENDFOREACH(VPART) +ENDIF(FREETYPE_INCLUDE_DIR_freetype2 AND EXISTS "${FREETYPE_INCLUDE_DIR_freetype2}/freetype/freetype.h") + + # handle the QUIETLY and REQUIRED arguments and set FREETYPE_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype DEFAULT_MSG FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS) - +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Freetype + REQUIRED_VARS FREETYPE_LIBRARY FREETYPE_INCLUDE_DIRS + VERSION_VAR FREETYPE_VERSION_STRING) MARK_AS_ADVANCED(FREETYPE_LIBRARY FREETYPE_INCLUDE_DIR_freetype2 FREETYPE_INCLUDE_DIR_ft2build) diff --git a/Modules/FindGLUT.cmake b/Modules/FindGLUT.cmake index af889972e..82057792d 100644 --- a/Modules/FindGLUT.cmake +++ b/Modules/FindGLUT.cmake @@ -64,25 +64,23 @@ ELSE (WIN32) ENDIF (WIN32) -SET( GLUT_FOUND "NO" ) -IF(GLUT_INCLUDE_DIR) - IF(GLUT_glut_LIBRARY) - # Is -lXi and -lXmu required on all platforms that have it? - # If not, we need some way to figure out what platform we are on. - SET( GLUT_LIBRARIES - ${GLUT_glut_LIBRARY} - ${GLUT_Xmu_LIBRARY} - ${GLUT_Xi_LIBRARY} - ${GLUT_cocoa_LIBRARY} - ) - SET( GLUT_FOUND "YES" ) - - #The following deprecated settings are for backwards compatibility with CMake1.4 - SET (GLUT_LIBRARY ${GLUT_LIBRARIES}) - SET (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) + +IF (GLUT_FOUND) + # Is -lXi and -lXmu required on all platforms that have it? + # If not, we need some way to figure out what platform we are on. + SET( GLUT_LIBRARIES + ${GLUT_glut_LIBRARY} + ${GLUT_Xmu_LIBRARY} + ${GLUT_Xi_LIBRARY} + ${GLUT_cocoa_LIBRARY} + ) - ENDIF(GLUT_glut_LIBRARY) -ENDIF(GLUT_INCLUDE_DIR) + #The following deprecated settings are for backwards compatibility with CMake1.4 + SET (GLUT_LIBRARY ${GLUT_LIBRARIES}) + SET (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) +ENDIF(GLUT_FOUND) MARK_AS_ADVANCED( GLUT_INCLUDE_DIR diff --git a/Modules/FindGettext.cmake b/Modules/FindGettext.cmake index c44adb46c..6dbc02618 100644 --- a/Modules/FindGettext.cmake +++ b/Modules/FindGettext.cmake @@ -4,6 +4,7 @@ # GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool. # GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool. # GETTEXT_FOUND: True if gettext has been found. +# GETTEXT_VERSION_STRING: the version of gettext found (since CMake 2.8.8) # # Additionally it provides the following macros: # GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN ) @@ -42,11 +43,35 @@ FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge) FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt) +IF(GETTEXT_MSGMERGE_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --version + OUTPUT_VARIABLE gettext_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF (gettext_version MATCHES "^msgmerge \\(.*\\) [0-9]") + STRING(REGEX REPLACE "^msgmerge \\([^\\)]*\\) ([0-9\\.]+[^ \n]*).*" "\\1" GETTEXT_VERSION_STRING "${gettext_version}") + ENDIF() + UNSET(gettext_version) +ENDIF(GETTEXT_MSGMERGE_EXECUTABLE) + INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext + REQUIRED_VARS GETTEXT_MSGMERGE_EXECUTABLE GETTEXT_MSGFMT_EXECUTABLE + VERSION_VAR GETTEXT_VERSION_STRING) INCLUDE(CMakeParseArguments) +FUNCTION(_GETTEXT_GET_UNIQUE_TARGET_NAME _name _unique_name) + SET(propertyName "_GETTEXT_UNIQUE_COUNTER_${_name}") + GET_PROPERTY(currentCounter GLOBAL PROPERTY "${propertyName}") + IF(NOT currentCounter) + SET(currentCounter 1) + ENDIF() + SET(${_unique_name} "${_name}_${currentCounter}" PARENT_SCOPE) + MATH(EXPR currentCounter "${currentCounter} + 1") + SET_PROPERTY(GLOBAL PROPERTY ${propertyName} ${currentCounter} ) +ENDFUNCTION() + MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) # make it a real variable, so we can modify it here SET(_firstPoFile "${_firstPoFileArg}") @@ -80,7 +105,15 @@ MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFileArg) ENDFOREACH (_currentPoFile ) - ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_gmoFiles}) + IF(NOT TARGET translations) + ADD_CUSTOM_TARGET(translations) + ENDIF() + + _GETTEXT_GET_UNIQUE_TARGET_NAME(translations uniqueTargetName) + + ADD_CUSTOM_TARGET(${uniqueTargetName} ${_addToAll} DEPENDS ${_gmoFiles}) + + ADD_DEPENDENCIES(translations ${uniqueTargetName}) ENDMACRO(GETTEXT_CREATE_TRANSLATIONS ) @@ -119,11 +152,20 @@ FUNCTION(GETTEXT_PROCESS_POT_FILE _potFile) LIST(APPEND _gmoFiles ${_gmoFile}) ENDFOREACH (_lang ) + IF(NOT TARGET potfiles) + ADD_CUSTOM_TARGET(potfiles) + ENDIF() + + _GETTEXT_GET_UNIQUE_TARGET_NAME( potfiles uniqueTargetName) + IF(_parsedArguments_ALL) - ADD_CUSTOM_TARGET(potfiles ALL DEPENDS ${_gmoFiles}) + ADD_CUSTOM_TARGET(${uniqueTargetName} ALL DEPENDS ${_gmoFiles}) ELSE(_parsedArguments_ALL) - ADD_CUSTOM_TARGET(potfiles DEPENDS ${_gmoFiles}) + ADD_CUSTOM_TARGET(${uniqueTargetName} DEPENDS ${_gmoFiles}) ENDIF(_parsedArguments_ALL) + + ADD_DEPENDENCIES(potfiles ${uniqueTargetName}) + ENDFUNCTION(GETTEXT_PROCESS_POT_FILE) @@ -151,11 +193,21 @@ FUNCTION(GETTEXT_PROCESS_PO_FILES _lang) LIST(APPEND _gmoFiles ${_gmoFile}) ENDFOREACH(_current_PO_FILE) + + IF(NOT TARGET pofiles) + ADD_CUSTOM_TARGET(pofiles) + ENDIF() + + _GETTEXT_GET_UNIQUE_TARGET_NAME( pofiles uniqueTargetName) + IF(_parsedArguments_ALL) - ADD_CUSTOM_TARGET(pofiles ALL DEPENDS ${_gmoFiles}) + ADD_CUSTOM_TARGET(${uniqueTargetName} ALL DEPENDS ${_gmoFiles}) ELSE(_parsedArguments_ALL) - ADD_CUSTOM_TARGET(pofiles DEPENDS ${_gmoFiles}) + ADD_CUSTOM_TARGET(${uniqueTargetName} DEPENDS ${_gmoFiles}) ENDIF(_parsedArguments_ALL) + + ADD_DEPENDENCIES(pofiles ${uniqueTargetName}) + ENDFUNCTION(GETTEXT_PROCESS_PO_FILES) IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE ) diff --git a/Modules/FindGit.cmake b/Modules/FindGit.cmake index 503b640ed..f89d1afa3 100644 --- a/Modules/FindGit.cmake +++ b/Modules/FindGit.cmake @@ -1,6 +1,7 @@ # The module defines the following variables: # GIT_EXECUTABLE - path to git command line client # GIT_FOUND - true if the command line client was found +# GIT_VERSION_STRING - the version of git found (since CMake 2.8.8) # Example usage: # find_package(Git) # if(GIT_FOUND) @@ -9,6 +10,7 @@ #============================================================================= # Copyright 2010 Kitware, Inc. +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -40,8 +42,21 @@ find_program(GIT_EXECUTABLE ) mark_as_advanced(GIT_EXECUTABLE) +if(GIT_EXECUTABLE) + execute_process(COMMAND ${GIT_EXECUTABLE} --version + OUTPUT_VARIABLE git_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if (git_version MATCHES "^git version [0-9]") + string(REPLACE "git version " "" GIT_VERSION_STRING "${git_version}") + endif() + unset(git_version) +endif(GIT_EXECUTABLE) + # Handle the QUIETLY and REQUIRED arguments and set GIT_FOUND to TRUE if # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -find_package_handle_standard_args(Git DEFAULT_MSG GIT_EXECUTABLE) +find_package_handle_standard_args(Git + REQUIRED_VARS GIT_EXECUTABLE + VERSION_VAR GIT_VERSION_STRING) diff --git a/Modules/FindGnuTLS.cmake b/Modules/FindGnuTLS.cmake index a437a1f41..02f29648a 100644 --- a/Modules/FindGnuTLS.cmake +++ b/Modules/FindGnuTLS.cmake @@ -35,9 +35,10 @@ IF (NOT WIN32) # try using pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls # also fills in GNUTLS_DEFINITIONS, although that isn't normally useful - FIND_PACKAGE(PkgConfig) - PKG_CHECK_MODULES(PC_GNUTLS gnutls) + FIND_PACKAGE(PkgConfig QUIET) + PKG_CHECK_MODULES(PC_GNUTLS QUIET gnutls) SET(GNUTLS_DEFINITIONS ${PC_GNUTLS_CFLAGS_OTHER}) + SET(GNUTLS_VERSION_STRING ${PC_GNUTLS_VERSION}) ENDIF (NOT WIN32) FIND_PATH(GNUTLS_INCLUDE_DIR gnutls/gnutls.h @@ -57,7 +58,9 @@ MARK_AS_ADVANCED(GNUTLS_INCLUDE_DIR GNUTLS_LIBRARY) # handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS DEFAULT_MSG GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GnuTLS + REQUIRED_VARS GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR + VERSION_VAR GNUTLS_VERSION_STRING) IF(GNUTLS_FOUND) SET(GNUTLS_LIBRARIES ${GNUTLS_LIBRARY}) diff --git a/Modules/FindGnuplot.cmake b/Modules/FindGnuplot.cmake index 7c59f0375..b8dc3f49a 100644 --- a/Modules/FindGnuplot.cmake +++ b/Modules/FindGnuplot.cmake @@ -4,6 +4,9 @@ # # GNUPLOT_FOUND - system has Gnuplot # GNUPLOT_EXECUTABLE - the Gnuplot executable +# GNUPLOT_VERSION_STRING - the version of Gnuplot found (since CMake 2.8.8) +# +# GNUPLOT_VERSION_STRING will not work for old versions like 3.7.1. #============================================================================= # Copyright 2002-2009 Kitware, Inc. @@ -29,13 +32,26 @@ FIND_PROGRAM(GNUPLOT_EXECUTABLE ${CYGWIN_INSTALL_PATH}/bin ) +IF (GNUPLOT_EXECUTABLE) + EXECUTE_PROCESS(COMMAND "${GNUPLOT_EXECUTABLE}" --version + OUTPUT_VARIABLE GNUPLOT_OUTPUT_VARIABLE + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + STRING(REGEX REPLACE "^gnuplot ([0-9\\.]+)( patchlevel )?" "\\1." GNUPLOT_VERSION_STRING "${GNUPLOT_OUTPUT_VARIABLE}") + STRING(REGEX REPLACE "\\.$" "" GNUPLOT_VERSION_STRING "${GNUPLOT_VERSION_STRING}") + UNSET(GNUPLOT_OUTPUT_VARIABLE) +ENDIF() + # for compatibility SET(GNUPLOT ${GNUPLOT_EXECUTABLE}) # handle the QUIETLY and REQUIRED arguments and set GNUPLOT_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gnuplot DEFAULT_MSG GNUPLOT_EXECUTABLE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gnuplot + REQUIRED_VARS GNUPLOT_EXECUTABLE + VERSION_VAR GNUPLOT_VERSION_STRING) MARK_AS_ADVANCED( GNUPLOT_EXECUTABLE ) diff --git a/Modules/FindHSPELL.cmake b/Modules/FindHSPELL.cmake index 054f565a5..ca5709b62 100644 --- a/Modules/FindHSPELL.cmake +++ b/Modules/FindHSPELL.cmake @@ -32,12 +32,15 @@ IF (HSPELL_INCLUDE_DIR) FILE(READ "${HSPELL_INCLUDE_DIR}/hspell.h" HSPELL_H) STRING(REGEX REPLACE ".*#define HSPELL_VERSION_MAJOR ([0-9]+).*" "\\1" HSPELL_VERSION_MAJOR "${HSPELL_H}") STRING(REGEX REPLACE ".*#define HSPELL_VERSION_MINOR ([0-9]+).*" "\\1" HSPELL_VERSION_MINOR "${HSPELL_H}") + SET(HSPELL_VERSION_STRING "${HSPELL_VERSION_MAJOR}.${HSPELL_VERSION_MINOR}") ENDIF() # handle the QUIETLY and REQUIRED arguments and set HSPELL_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(HSPELL DEFAULT_MSG HSPELL_LIBRARIES HSPELL_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(HSPELL + REQUIRED_VARS HSPELL_LIBRARIES HSPELL_INCLUDE_DIR + VERSION_VAR HSPELL_VERSION_STRING) MARK_AS_ADVANCED(HSPELL_INCLUDE_DIR HSPELL_LIBRARIES) diff --git a/Modules/FindImageMagick.cmake b/Modules/FindImageMagick.cmake index 5e6fa20a9..f21b63008 100644 --- a/Modules/FindImageMagick.cmake +++ b/Modules/FindImageMagick.cmake @@ -24,6 +24,10 @@ # ImageMagick_EXECUTABLE_DIR - Full path to executables directory. # ImageMagick__FOUND - TRUE if is found. # ImageMagick__EXECUTABLE - Full path to executable. +# ImageMagick_VERSION_STRING - the version of ImageMagick found +# (since CMake 2.8.8) +# +# ImageMagick_VERSION_STRING will not work for old versions like 5.2.3. # # There are also components for the following ImageMagick APIs: # @@ -53,6 +57,7 @@ #============================================================================= # Copyright 2007-2009 Kitware, Inc. # Copyright 2007-2008 Miguel A. Figueroa-Villanueva +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -134,7 +139,8 @@ FIND_PATH(ImageMagick_EXECUTABLE_DIR # Find each component. Search for all tools in same dir # ; otherwise they should be found # independently and not in a cohesive module such as this one. -SET(ImageMagick_FOUND TRUE) +UNSET(ImageMagick_REQUIRED_VARS) +UNSET(ImageMagick_DEFAULT_EXECUTABLES) FOREACH(component ${ImageMagick_FIND_COMPONENTS} # DEPRECATED: forced components for backward compatibility convert mogrify import montage composite @@ -143,37 +149,65 @@ FOREACH(component ${ImageMagick_FIND_COMPONENTS} FIND_IMAGEMAGICK_API(Magick++ Magick++.h Magick++ CORE_RL_Magick++_ ) + LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_Magick++_LIBRARY) ELSEIF(component STREQUAL "MagickWand") FIND_IMAGEMAGICK_API(MagickWand wand/MagickWand.h Wand MagickWand CORE_RL_wand_ ) + LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickWand_LIBRARY) ELSEIF(component STREQUAL "MagickCore") FIND_IMAGEMAGICK_API(MagickCore magick/MagickCore.h Magick MagickCore CORE_RL_magick_ ) + LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_MagickCore_LIBRARY) ELSE(component STREQUAL "Magick++") IF(ImageMagick_EXECUTABLE_DIR) FIND_IMAGEMAGICK_EXE(${component}) ENDIF(ImageMagick_EXECUTABLE_DIR) + + IF(ImageMagick_FIND_COMPONENTS) + LIST(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested) + IF(is_requested GREATER -1) + LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_${component}_EXECUTABLE) + ENDIF(is_requested GREATER -1) + ELSEIF(ImageMagick_${component}_EXECUTABLE) + # if no components were requested explicitly put all (default) executables + # in the list + LIST(APPEND ImageMagick_DEFAULT_EXECUTABLES ImageMagick_${component}_EXECUTABLE) + ENDIF(ImageMagick_FIND_COMPONENTS) ENDIF(component STREQUAL "Magick++") - - IF(NOT ImageMagick_${component}_FOUND) - LIST(FIND ImageMagick_FIND_COMPONENTS ${component} is_requested) - IF(is_requested GREATER -1) - SET(ImageMagick_FOUND FALSE) - ENDIF(is_requested GREATER -1) - ENDIF(NOT ImageMagick_${component}_FOUND) ENDFOREACH(component) +IF(NOT ImageMagick_FIND_COMPONENTS AND NOT ImageMagick_DEFAULT_EXECUTABLES) + # No components were requested, and none of the default components were + # found. Just insert mogrify into the list of the default components to + # find so FPHSA below has something to check + LIST(APPEND ImageMagick_REQUIRED_VARS ImageMagick_mogrify_EXECUTABLE) +ELSEIF(ImageMagick_DEFAULT_EXECUTABLES) + LIST(APPEND ImageMagick_REQUIRED_VARS ${ImageMagick_DEFAULT_EXECUTABLES}) +ENDIF() + SET(ImageMagick_INCLUDE_DIRS ${ImageMagick_INCLUDE_DIRS}) SET(ImageMagick_LIBRARIES ${ImageMagick_LIBRARIES}) +IF(ImageMagick_mogrify_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${ImageMagick_mogrify_EXECUTABLE} -version + OUTPUT_VARIABLE imagemagick_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF(imagemagick_version MATCHES "^Version: ImageMagick [0-9]") + STRING(REGEX REPLACE "^Version: ImageMagick ([-0-9\\.]+).*" "\\1" ImageMagick_VERSION_STRING "${imagemagick_version}") + ENDIF() + UNSET(imagemagick_version) +ENDIF(ImageMagick_mogrify_EXECUTABLE) + #--------------------------------------------------------------------- # Standard Package Output #--------------------------------------------------------------------- INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( - ImageMagick DEFAULT_MSG ImageMagick_FOUND +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ImageMagick + REQUIRED_VARS ${ImageMagick_REQUIRED_VARS} + VERSION_VAR ImageMagick_VERSION_STRING ) # Maintain consistency with all other variables. SET(ImageMagick_FOUND ${IMAGEMAGICK_FOUND}) diff --git a/Modules/FindJasper.cmake b/Modules/FindJasper.cmake index bae4c0549..6dc7e4db7 100644 --- a/Modules/FindJasper.cmake +++ b/Modules/FindJasper.cmake @@ -3,11 +3,13 @@ # # JASPER_FOUND - system has Jasper # JASPER_INCLUDE_DIR - the Jasper include directory -# JASPER_LIBRARIES - The libraries needed to use Jasper +# JASPER_LIBRARIES - the libraries needed to use Jasper +# JASPER_VERSION_STRING - the version of Jasper found (since CMake 2.8.8) #============================================================================= # Copyright 2006-2009 Kitware, Inc. # Copyright 2006 Alexander Neundorf +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -19,19 +21,33 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -FIND_PACKAGE(JPEG) - FIND_PATH(JASPER_INCLUDE_DIR jasper/jasper.h) -FIND_LIBRARY(JASPER_LIBRARY NAMES jasper libjasper) +IF (NOT JASPER_LIBRARIES) + FIND_PACKAGE(JPEG) + + FIND_LIBRARY(JASPER_LIBRARY_RELEASE NAMES jasper libjasper) + FIND_LIBRARY(JASPER_LIBRARY_DEBUG NAMES jasperd) + + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) + SELECT_LIBRARY_CONFIGURATIONS(JASPER) +ENDIF (NOT JASPER_LIBRARIES) + +IF (JASPER_INCLUDE_DIR AND EXISTS "${JASPER_INCLUDE_DIR}/jasper/jas_config.h") + FILE(STRINGS "${JASPER_INCLUDE_DIR}/jasper/jas_config.h" jasper_version_str REGEX "^#define[\t ]+JAS_VERSION[\t ]+\".*\".*") + + STRING(REGEX REPLACE "^#define[\t ]+JAS_VERSION[\t ]+\"([^\"]+)\".*" "\\1" JASPER_VERSION_STRING "${jasper_version_str}") +ENDIF (JASPER_INCLUDE_DIR AND EXISTS "${JASPER_INCLUDE_DIR}/jasper/jas_config.h") # handle the QUIETLY and REQUIRED arguments and set JASPER_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Jasper DEFAULT_MSG JASPER_LIBRARY JASPER_INCLUDE_DIR JPEG_LIBRARIES) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Jasper + REQUIRED_VARS JASPER_LIBRARIES JASPER_INCLUDE_DIR JPEG_LIBRARIES + VERSION_VAR JASPER_VERSION_STRING) IF (JASPER_FOUND) - SET(JASPER_LIBRARIES ${JASPER_LIBRARY} ${JPEG_LIBRARIES} ) + SET(JASPER_LIBRARIES ${JASPER_LIBRARIES} ${JPEG_LIBRARIES} ) ENDIF (JASPER_FOUND) -MARK_AS_ADVANCED(JASPER_INCLUDE_DIR JASPER_LIBRARY) +MARK_AS_ADVANCED(JASPER_INCLUDE_DIR) diff --git a/Modules/FindLAPACK.cmake b/Modules/FindLAPACK.cmake index 884266fc9..0ae98dfa7 100644 --- a/Modules/FindLAPACK.cmake +++ b/Modules/FindLAPACK.cmake @@ -219,40 +219,69 @@ if (BLA_VENDOR STREQUAL "Generic" OR endif ( NOT LAPACK_LIBRARIES ) endif () #intel lapack - if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") +if (BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") + if (NOT WIN32) + set(LM "-lm") + endif () if (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) - if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + if(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) find_PACKAGE(Threads) - else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) - find_package(Threads REQUIRED) - endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) - if (BLA_F95) - if(NOT LAPACK95_LIBRARIES) - check_lapack_libraries( - LAPACK95_LIBRARIES - LAPACK - cheev - "" - "mkl_lapack95" - "${BLAS95_LIBRARIES}" - "${CMAKE_THREAD_LIBS_INIT}" - ) - endif(NOT LAPACK95_LIBRARIES) - else(BLA_F95) - if(NOT LAPACK_LIBRARIES) - check_lapack_libraries( - LAPACK_LIBRARIES - LAPACK - cheev - "" - "mkl_lapack" - "${BLAS_LIBRARIES}" - "${CMAKE_THREAD_LIBS_INIT}" - ) - endif(NOT LAPACK_LIBRARIES) - endif(BLA_F95) + else(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + find_package(Threads REQUIRED) + endif(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED) + if (BLA_F95) + if(NOT LAPACK95_LIBRARIES) + # old + check_lapack_libraries( + LAPACK95_LIBRARIES + LAPACK + cheev + "" + "mkl_lapack95" + "${BLAS95_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + endif(NOT LAPACK95_LIBRARIES) + if(NOT LAPACK95_LIBRARIES) + # new >= 10.3 + check_lapack_libraries( + LAPACK95_LIBRARIES + LAPACK + CHEEV + "" + "mkl_intel_lp64" + "${BLAS95_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + endif(NOT LAPACK95_LIBRARIES) + else(BLA_F95) + if(NOT LAPACK_LIBRARIES) + # old + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "mkl_lapack" + "${BLAS_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + endif(NOT LAPACK_LIBRARIES) + if(NOT LAPACK_LIBRARIES) + # new >= 10.3 + check_lapack_libraries( + LAPACK_LIBRARIES + LAPACK + cheev + "" + "mkl_gf_lp64" + "${BLAS_LIBRARIES}" + "${CMAKE_THREAD_LIBS_INIT};${LM}" + ) + endif(NOT LAPACK_LIBRARIES) + endif(BLA_F95) endif (_LANGUAGES_ MATCHES C OR _LANGUAGES_ MATCHES CXX) - endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") +endif(BLA_VENDOR MATCHES "Intel*" OR BLA_VENDOR STREQUAL "All") else(BLAS_FOUND) message(STATUS "LAPACK requires BLAS") endif(BLAS_FOUND) diff --git a/Modules/FindLibArchive.cmake b/Modules/FindLibArchive.cmake index cedcd245a..be931c525 100644 --- a/Modules/FindLibArchive.cmake +++ b/Modules/FindLibArchive.cmake @@ -54,8 +54,9 @@ endif() # itself includes this FindLibArchive when built with an older CMake that does # not provide it. The older CMake also does not have CMAKE_CURRENT_LIST_DIR.) include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) -find_package_handle_standard_args(LibArchive DEFAULT_MSG - LibArchive_LIBRARY LibArchive_INCLUDE_DIR +find_package_handle_standard_args(LibArchive + REQUIRED_VARS LibArchive_LIBRARY LibArchive_INCLUDE_DIR + VERSION_VAR LibArchive_VERSION ) set(LibArchive_FOUND ${LIBARCHIVE_FOUND}) unset(LIBARCHIVE_FOUND) diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake index 95ae18041..48a549806 100644 --- a/Modules/FindLibXml2.cmake +++ b/Modules/FindLibXml2.cmake @@ -6,6 +6,7 @@ # LIBXML2_LIBRARIES - The libraries needed to use LibXml2 # LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2 # LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2 +# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8) #============================================================================= # Copyright 2006-2009 Kitware, Inc. @@ -23,8 +24,8 @@ # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls -FIND_PACKAGE(PkgConfig) -PKG_CHECK_MODULES(PC_LIBXML libxml-2.0 QUIET) +FIND_PACKAGE(PkgConfig QUIET) +PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0) SET(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER}) FIND_PATH(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h @@ -44,10 +45,22 @@ FIND_PROGRAM(LIBXML2_XMLLINT_EXECUTABLE xmllint) # for backwards compat. with KDE 4.0.x: SET(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}") +IF(PC_LIBXML_VERSION) + SET(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION}) +ELSEIF(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h") + FILE(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str + REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"") + + STRING(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + LIBXML2_VERSION_STRING "${libxml2_version_str}") + UNSET(libxml2_version_str) +ENDIF() + # handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 + REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR + VERSION_VAR LIBXML2_VERSION_STRING) MARK_AS_ADVANCED(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE) - diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake index 1f49c3bda..dd5aac461 100644 --- a/Modules/FindLibXslt.cmake +++ b/Modules/FindLibXslt.cmake @@ -5,6 +5,7 @@ # LIBXSLT_INCLUDE_DIR - the LibXslt include directory # LIBXSLT_LIBRARIES - Link these to LibXslt # LIBXSLT_DEFINITIONS - Compiler switches required for using LibXslt +# LIBXSLT_VERSION_STRING - version of LibXslt found (since CMake 2.8.8) # Additionally, the following two variables are set (but not required for using xslt): # LIBXSLT_EXSLT_LIBRARIES - Link to these if you need to link against the exslt library # LIBXSLT_XSLTPROC_EXECUTABLE - Contains the full path to the xsltproc executable if found @@ -25,7 +26,7 @@ # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls -FIND_PACKAGE(PkgConfig) +FIND_PACKAGE(PkgConfig QUIET) PKG_CHECK_MODULES(PC_LIBXSLT QUIET libxslt) SET(LIBXSLT_DEFINITIONS ${PC_LIBXSLT_CFLAGS_OTHER}) @@ -51,10 +52,21 @@ SET(LIBXSLT_EXSLT_LIBRARIES ${LIBXSLT_EXSLT_LIBRARY} ) FIND_PROGRAM(LIBXSLT_XSLTPROC_EXECUTABLE xsltproc) -# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if -# all listed variables are TRUE +IF(PC_LIBXSLT_VERSION) + SET(LIBXSLT_VERSION_STRING ${PC_LIBXSLT_VERSION}) +ELSEIF(LIBXSLT_INCLUDE_DIR AND EXISTS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h") + FILE(STRINGS "${LIBXSLT_INCLUDE_DIR}/libxslt/xsltconfig.h" libxslt_version_str + REGEX "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\".*\"") + + STRING(REGEX REPLACE "^#define[\t ]+LIBXSLT_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + LIBXSLT_VERSION_STRING "${libxslt_version_str}") + UNSET(libxslt_version_str) +ENDIF() + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXslt DEFAULT_MSG LIBXSLT_LIBRARIES LIBXSLT_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXslt + REQUIRED_VARS LIBXSLT_LIBRARIES LIBXSLT_INCLUDE_DIR + VERSION_VAR LIBXSLT_VERSION_STRING) MARK_AS_ADVANCED(LIBXSLT_INCLUDE_DIR LIBXSLT_LIBRARIES diff --git a/Modules/FindLua51.cmake b/Modules/FindLua51.cmake index 123fd5d05..b67dd4cec 100644 --- a/Modules/FindLua51.cmake +++ b/Modules/FindLua51.cmake @@ -2,7 +2,8 @@ # This module defines # LUA51_FOUND, if false, do not try to link to Lua # LUA_LIBRARIES -# LUA_INCLUDE_DIR, where to find lua.h +# LUA_INCLUDE_DIR, where to find lua.h +# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8) # # Note that the expected include convention is # #include "lua.h" @@ -66,10 +67,19 @@ IF(LUA_LIBRARY) ENDIF(UNIX AND NOT APPLE) ENDIF(LUA_LIBRARY) +IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h") + FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"") + + STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}") + UNSET(lua_version_str) +ENDIF() + INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) # handle the QUIETLY and REQUIRED arguments and set LUA_FOUND to TRUE if # all listed variables are TRUE -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51 DEFAULT_MSG LUA_LIBRARIES LUA_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51 + REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR + VERSION_VAR LUA_VERSION_STRING) MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY) diff --git a/Modules/FindMPI.cmake b/Modules/FindMPI.cmake index 250d8a6b3..ae50ca7b9 100644 --- a/Modules/FindMPI.cmake +++ b/Modules/FindMPI.cmake @@ -354,6 +354,20 @@ function (interrogate_mpi_compiler lang try_libs) # Extract the set of libraries to link against from the link command # line string(REGEX MATCHALL "(^| )-l([^\" ]+|\"[^\"]+\")" MPI_LIBNAMES "${MPI_LINK_CMDLINE}") + # add the compiler implicit directories because some compilers + # such as the intel compiler have libraries that show up + # in the showme list that can only be found in the implicit + # link directories of the compiler. Do this for C++ and C + # compilers if the implicit link directories are defined. + if (DEFINED CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES) + set(MPI_LINK_PATH + "${MPI_LINK_PATH};${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}") + endif () + + if (DEFINED CMAKE_C_IMPLICIT_LINK_DIRECTORIES) + set(MPI_LINK_PATH + "${MPI_LINK_PATH};${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}") + endif () # Determine full path names for all of the libraries that one needs # to link against in an MPI program @@ -413,7 +427,7 @@ function (interrogate_mpi_compiler lang try_libs) HINTS ${_MPI_BASE_DIR} ${_MPI_PREFIX_PATH} PATH_SUFFIXES lib) if (MPI_LIBRARIES_WORK AND MPI_LIB) - set(MPI_LIBRARIES_WORK "${MPI_LIBRARIES_WORK} ${MPI_LIB}") + list(APPEND MPI_LIBRARIES_WORK ${MPI_LIB}) endif() endif() diff --git a/Modules/FindOpenMP.cmake b/Modules/FindOpenMP.cmake index 652803c80..b96a2ecfb 100644 --- a/Modules/FindOpenMP.cmake +++ b/Modules/FindOpenMP.cmake @@ -1,7 +1,7 @@ # - Finds OpenMP support # This module can be used to detect OpenMP support in a compiler. # If the compiler supports OpenMP, the flags required to compile with -# openmp support are set. +# openmp support are set. # # The following variables are set: # OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support @@ -13,6 +13,7 @@ #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2008-2009 André Rigland Brodtkorb +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -24,31 +25,54 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -include(CheckCSourceCompiles) -include(CheckCXXSourceCompiles) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) - -set(OpenMP_C_FLAG_CANDIDATES - #Gnu - "-fopenmp" - #Microsoft Visual Studio - "/openmp" - #Intel windows - "-Qopenmp" - #Intel - "-openmp" - #Empty, if compiler automatically accepts openmp - " " - #Sun - "-xopenmp" - #HP - "+Oopenmp" - #IBM XL C/c++ - "-qsmp" - #Portland Group - "-mp" -) -set(OpenMP_CXX_FLAG_CANDIDATES ${OpenMP_C_FLAG_CANDIDATES}) +set(_OPENMP_REQUIRED_VARS) + +function(_OPENMP_FLAG_CANDIDATES LANG) + set(OpenMP_FLAG_CANDIDATES + #GNU + "-fopenmp" + #Microsoft Visual Studio + "/openmp" + #Intel windows + "-Qopenmp" + #PathScale, Intel + "-openmp" + #Empty, if compiler automatically accepts openmp + " " + #Sun + "-xopenmp" + #HP + "+Oopenmp" + #IBM XL C/c++ + "-qsmp" + #Portland Group, MIPSpro + "-mp" + ) + + set(OMP_FLAG_GNU "-fopenmp") + set(OMP_FLAG_HP "+Oopenmp") + if(WIN32) + set(OMP_FLAG_Intel "-Qopenmp") + else() + set(OMP_FLAG_Intel "-openmp") + endif() + set(OMP_FLAG_MIPSpro "-mp") + set(OMP_FLAG_MSVC "/openmp") + set(OMP_FLAG_PathScale "-openmp") + set(OMP_FLAG_PGI "-mp") + set(OMP_FLAG_SunPro "-xopenmp") + set(OMP_FLAG_XL "-qsmp") + + # Move the flag that matches the compiler to the head of the list, + # this is faster and doesn't clutter the output that much. If that + # flag doesn't work we will still try all. + if(OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}) + list(REMOVE_ITEM OpenMP_FLAG_CANDIDATES "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}") + list(INSERT OpenMP_FLAG_CANDIDATES 0 "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}") + endif() + + set(OpenMP_${LANG}_FLAG_CANDIDATES "${OpenMP_FLAG_CANDIDATES}" PARENT_SCOPE) +endfunction(_OPENMP_FLAG_CANDIDATES) # sample openmp source code to test set(OpenMP_C_TEST_SOURCE @@ -62,53 +86,82 @@ int main() { #endif } ") -# use the same source for CXX as C for now -set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE}) -# if these are set then do not try to find them again, -# by avoiding any try_compiles for the flags -if(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS) - set(OpenMP_C_FLAG_CANDIDATES) - set(OpenMP_CXX_FLAG_CANDIDATES) -endif(DEFINED OpenMP_C_FLAGS AND DEFINED OpenMP_CXX_FLAGS) # check c compiler -foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES}) - set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - set(CMAKE_REQUIRED_FLAGS "${FLAG}") - unset(OpenMP_FLAG_DETECTED CACHE) - message(STATUS "Try OpenMP C flag = [${FLAG}]") - check_c_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED) - set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") - if(OpenMP_FLAG_DETECTED) - set(OpenMP_C_FLAGS_INTERNAL "${FLAG}") - break() - endif(OpenMP_FLAG_DETECTED) -endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES}) +if(CMAKE_C_COMPILER_LOADED) + # if these are set then do not try to find them again, + # by avoiding any try_compiles for the flags + if(OpenMP_C_FLAGS) + unset(OpenMP_C_FLAG_CANDIDATES) + else() + _OPENMP_FLAG_CANDIDATES("C") + include(CheckCSourceCompiles) + endif() + + foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES}) + set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${FLAG}") + unset(OpenMP_FLAG_DETECTED CACHE) + message(STATUS "Try OpenMP C flag = [${FLAG}]") + check_c_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED) + set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") + if(OpenMP_FLAG_DETECTED) + set(OpenMP_C_FLAGS_INTERNAL "${FLAG}") + break() + endif(OpenMP_FLAG_DETECTED) + endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES}) + + set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}" + CACHE STRING "C compiler flags for OpenMP parallization") + + list(APPEND _OPENMP_REQUIRED_VARS OpenMP_C_FLAGS) + unset(OpenMP_C_FLAG_CANDIDATES) +endif() # check cxx compiler -foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES}) - set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") - set(CMAKE_REQUIRED_FLAGS "${FLAG}") - unset(OpenMP_FLAG_DETECTED CACHE) - message(STATUS "Try OpenMP CXX flag = [${FLAG}]") - check_cxx_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED) - set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") - if(OpenMP_FLAG_DETECTED) - set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}") - break() - endif(OpenMP_FLAG_DETECTED) -endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES}) - -set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}" - CACHE STRING "C compiler flags for OpenMP parallization") - -set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}" - CACHE STRING "C++ compiler flags for OpenMP parallization") -# handle the standard arguments for find_package -find_package_handle_standard_args(OpenMP DEFAULT_MSG - OpenMP_C_FLAGS OpenMP_CXX_FLAGS ) - -mark_as_advanced( - OpenMP_C_FLAGS - OpenMP_CXX_FLAGS -) +if(CMAKE_CXX_COMPILER_LOADED) + # if these are set then do not try to find them again, + # by avoiding any try_compiles for the flags + if(OpenMP_CXX_FLAGS) + unset(OpenMP_CXX_FLAG_CANDIDATES) + else() + _OPENMP_FLAG_CANDIDATES("CXX") + include(CheckCXXSourceCompiles) + + # use the same source for CXX as C for now + set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE}) + endif() + + foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES}) + set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${FLAG}") + unset(OpenMP_FLAG_DETECTED CACHE) + message(STATUS "Try OpenMP CXX flag = [${FLAG}]") + check_cxx_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED) + set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") + if(OpenMP_FLAG_DETECTED) + set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}") + break() + endif(OpenMP_FLAG_DETECTED) + endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES}) + + set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}" + CACHE STRING "C++ compiler flags for OpenMP parallization") + + list(APPEND _OPENMP_REQUIRED_VARS OpenMP_CXX_FLAGS) + unset(OpenMP_CXX_FLAG_CANDIDATES) + unset(OpenMP_CXX_TEST_SOURCE) +endif() + +if(_OPENMP_REQUIRED_VARS) + include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + + find_package_handle_standard_args(OpenMP + REQUIRED_VARS ${_OPENMP_REQUIRED_VARS}) + + mark_as_advanced(${_OPENMP_REQUIRED_VARS}) + + unset(_OPENMP_REQUIRED_VARS) +else() + message(SEND_ERROR "FindOpenMP requires C or CXX language to be enabled") +endif() diff --git a/Modules/FindOpenSSL.cmake b/Modules/FindOpenSSL.cmake index af799d6b7..d1fc2d259 100644 --- a/Modules/FindOpenSSL.cmake +++ b/Modules/FindOpenSSL.cmake @@ -7,7 +7,7 @@ # OPENSSL_FOUND - system has the OpenSSL library # OPENSSL_INCLUDE_DIR - the OpenSSL include directory # OPENSSL_LIBRARIES - The libraries needed to use OpenSSL -# OPENSSL_VERSION - This is set to $major.$minor.$revision (eg. 0.9.8) +# OPENSSL_VERSION - This is set to $major.$minor.$revision$path (eg. 0.9.8s) #============================================================================= # Copyright 2006-2009 Kitware, Inc. @@ -25,10 +25,8 @@ # License text for the above reference.) if (UNIX) - find_package(PkgConfig) - if (PKG_CONFIG_FOUND) - pkg_check_modules(_OPENSSL openssl) - endif (PKG_CONFIG_FOUND) + find_package(PkgConfig QUIET) + pkg_check_modules(_OPENSSL QUIET openssl) endif (UNIX) # http://www.slproweb.com/products/Win32OpenSSL.html @@ -215,17 +213,73 @@ ELSE(WIN32 AND NOT CYGWIN) ENDIF(WIN32 AND NOT CYGWIN) +function(from_hex HEX DEC) + string(TOUPPER "${HEX}" HEX) + set(_res 0) + string(LENGTH "${HEX}" _strlen) + + while (_strlen GREATER 0) + math(EXPR _res "${_res} * 16") + string(SUBSTRING "${HEX}" 0 1 NIBBLE) + string(SUBSTRING "${HEX}" 1 -1 HEX) + if (NIBBLE STREQUAL "A") + math(EXPR _res "${_res} + 10") + elseif (NIBBLE STREQUAL "B") + math(EXPR _res "${_res} + 11") + elseif (NIBBLE STREQUAL "C") + math(EXPR _res "${_res} + 12") + elseif (NIBBLE STREQUAL "D") + math(EXPR _res "${_res} + 13") + elseif (NIBBLE STREQUAL "E") + math(EXPR _res "${_res} + 14") + elseif (NIBBLE STREQUAL "F") + math(EXPR _res "${_res} + 15") + else() + math(EXPR _res "${_res} + ${NIBBLE}") + endif() + + string(LENGTH "${HEX}" _strlen) + endwhile() + + set(${DEC} ${_res} PARENT_SCOPE) +endfunction(from_hex) + if (OPENSSL_INCLUDE_DIR) - file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x[0-9][0-9][0-9][0-9][0-9][0-9].*") + if (_OPENSSL_VERSION) + set(OPENSSL_VERSION "${_OPENSSL_VERSION}") + elseif(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str + REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + + # The version number is encoded as 0xMNNFFPPS: major minor fix patch status + # The status gives if this is a developer or prerelease and is ignored here. + # Major, minor, and fix directly translate into the version numbers shown in + # the string. The patch field translates to the single character suffix that + # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so + # on. - string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9]).*$" "\\1" OPENSSL_VERSION_MAJOR "${openssl_version_str}") - string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x[0-9]([0-9][0-9]).*$" "\\1" OPENSSL_VERSION_MINOR "${openssl_version_str}") - string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x[0-9][0-9][0-9]([0-9][0-9]).*$" "\\1" OPENSSL_VERSION_PATCH "${openssl_version_str}") + string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$" + "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}") + list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR) + list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR) + from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR) + list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX) + from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX) + list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH) - string(REGEX REPLACE "^0" "" OPENSSL_VERSION_MINOR "${OPENSSL_VERSION_MINOR}") - string(REGEX REPLACE "^0" "" OPENSSL_VERSION_PATCH "${OPENSSL_VERSION_PATCH}") + if (NOT OPENSSL_VERSION_PATCH STREQUAL "00") + from_hex("${OPENSSL_VERSION_PATCH}" _tmp) + # 96 is the ASCII code of 'a' minus 1 + math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96") + unset(_tmp) + # Once anyone knows how OpenSSL would call the patch versions beyond 'z' + # this should be updated to handle that, too. This has not happened yet + # so it is simply ignored here for now. + string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING) + endif (NOT OPENSSL_VERSION_PATCH STREQUAL "00") - set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_PATCH}") + set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}") + endif (_OPENSSL_VERSION) endif (OPENSSL_INCLUDE_DIR) include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) diff --git a/Modules/FindOpenSceneGraph.cmake b/Modules/FindOpenSceneGraph.cmake index 460f0fd31..52f931689 100644 --- a/Modules/FindOpenSceneGraph.cmake +++ b/Modules/FindOpenSceneGraph.cmake @@ -78,7 +78,7 @@ list(APPEND _osg_modules_to_process "osg" "OpenThreads") list(REMOVE_DUPLICATES _osg_modules_to_process) if(OpenSceneGraph_DEBUG) - message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " + message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Components = ${_osg_modules_to_process}") endif() @@ -93,7 +93,7 @@ endif() # Try to ascertain the version... if(OSG_INCLUDE_DIR) if(OpenSceneGraph_DEBUG) - message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " + message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Detected OSG_INCLUDE_DIR = ${OSG_INCLUDE_DIR}") endif() @@ -127,14 +127,14 @@ if(OSG_INCLUDE_DIR) string(REGEX REPLACE ".*#define OPENSCENEGRAPH_PATCH_VERSION[ \t]+([0-9]+).*" "\\1" _osg_VERSION_PATCH ${_osg_Version_contents}) else() - message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " + message(WARNING "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Failed to parse version number, please report this as a bug") endif() set(OPENSCENEGRAPH_VERSION "${_osg_VERSION_MAJOR}.${_osg_VERSION_MINOR}.${_osg_VERSION_PATCH}" CACHE INTERNAL "The version of OSG which was detected") if(OpenSceneGraph_DEBUG) - message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " + message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Detected version ${OPENSCENEGRAPH_VERSION}") endif() endif() @@ -165,7 +165,7 @@ endif() # foreach(_osg_module ${_osg_modules_to_process}) if(OpenSceneGraph_DEBUG) - message("[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " + message(STATUS "[ FindOpenSceneGraph.cmake:${CMAKE_CURRENT_LIST_LINE} ] " "Calling find_package(${_osg_module} ${_osg_required} ${_osg_quiet})") endif() find_package(${_osg_module} ${_osg_quiet}) diff --git a/Modules/FindPNG.cmake b/Modules/FindPNG.cmake index f61697309..a6c181cb1 100644 --- a/Modules/FindPNG.cmake +++ b/Modules/FindPNG.cmake @@ -7,6 +7,7 @@ # PNG_LIBRARIES, the libraries to link against to use PNG. # PNG_DEFINITIONS - You should add_definitons(${PNG_DEFINITIONS}) before compiling code that includes png library files. # PNG_FOUND, If false, do not try to use PNG. +# PNG_VERSION_STRING - the version of the PNG library found (since CMake 2.8.8) # Also defined, but not for general use are # PNG_LIBRARY, where to find the PNG library. # For backward compatiblity the variable PNG_INCLUDE_DIR is also set. It has the same value as PNG_INCLUDE_DIRS. @@ -56,11 +57,19 @@ if(ZLIB_FOUND) endif (PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR) + if (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h") + file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"") + + string(REGEX REPLACE "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*" "\\1" PNG_VERSION_STRING "${png_version_str}") + unset(png_version_str) + endif (PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h") endif(ZLIB_FOUND) # handle the QUIETLY and REQUIRED arguments and set PNG_FOUND to TRUE if # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -find_package_handle_standard_args(PNG DEFAULT_MSG PNG_LIBRARY PNG_PNG_INCLUDE_DIR) +find_package_handle_standard_args(PNG + REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR + VERSION_VAR PNG_VERSION_STRING) mark_as_advanced(PNG_PNG_INCLUDE_DIR PNG_LIBRARY ) diff --git a/Modules/FindPackageHandleStandardArgs.cmake b/Modules/FindPackageHandleStandardArgs.cmake index 1acb021e8..cdcf9ca7c 100644 --- a/Modules/FindPackageHandleStandardArgs.cmake +++ b/Modules/FindPackageHandleStandardArgs.cmake @@ -19,7 +19,8 @@ # # The second mode is more powerful and also supports version checking: # FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME [REQUIRED_VARS ...] -# [VERSION_VAR +# [VERSION_VAR ] +# [HANDLE_COMPONENTS] # [CONFIG_MODE] # [FAIL_MESSAGE "Custom failure message"] ) # @@ -32,10 +33,15 @@ # in the find_package() call. The EXACT keyword is also handled. The default # messages include information about the required version and the version # which has been actually found, both if the version is ok or not. +# If the package supports components, use the HANDLE_COMPONENTS option to enable +# handling them. In this case, find_package_handle_standard_args() will report +# which components have been found and which are missing, and the _FOUND +# variable will be set to FALSE if any of the required components (i.e. not the +# ones listed after OPTIONAL_COMPONENTS) are missing. # Use the option CONFIG_MODE if your FindXXX.cmake module is a wrapper for -# a find_package(... NO_MODULE) call, in this case all the information -# provided by the config-mode of find_package() will be evaluated -# automatically. +# a find_package(... NO_MODULE) call. In this case VERSION_VAR will be set +# to _VERSION and the macro will automatically check whether the +# Config module was found. # Via FAIL_MESSAGE a custom failure message can be specified, if this is not # used, the default message will be displayed. # @@ -128,7 +134,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # set up the arguments for CMAKE_PARSE_ARGUMENTS and check whether we are in # new extended or in the "old" mode: - SET(options CONFIG_MODE) + SET(options CONFIG_MODE HANDLE_COMPONENTS) SET(oneValueArgs FAIL_MESSAGE VERSION_VAR) SET(multiValueArgs REQUIRED_VARS) SET(_KEYWORDS_FOR_EXTENDED_MODE ${options} ${oneValueArgs} ${multiValueArgs} ) @@ -189,6 +195,36 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) ENDIF(NOT ${_CURRENT_VAR}) ENDFOREACH(_CURRENT_VAR) + # component handling + UNSET(FOUND_COMPONENTS_MSG) + UNSET(MISSING_COMPONENTS_MSG) + + IF(FPHSA_HANDLE_COMPONENTS) + FOREACH(comp ${${_NAME}_FIND_COMPONENTS}) + IF(${_NAME}_${comp}_FOUND) + + IF(NOT DEFINED FOUND_COMPONENTS_MSG) + SET(FOUND_COMPONENTS_MSG "found components: ") + ENDIF() + SET(FOUND_COMPONENTS_MSG "${FOUND_COMPONENTS_MSG} ${comp}") + + ELSE() + + IF(NOT DEFINED MISSING_COMPONENTS_MSG) + SET(MISSING_COMPONENTS_MSG "missing components: ") + ENDIF() + SET(MISSING_COMPONENTS_MSG "${MISSING_COMPONENTS_MSG} ${comp}") + + IF(${_NAME}_FIND_REQUIRED_${comp}) + SET(${_NAME_UPPER}_FOUND FALSE) + SET(MISSING_VARS "${MISSING_VARS} ${comp}") + ENDIF() + + ENDIF() + ENDFOREACH(comp) + SET(COMPONENT_MSG "${FOUND_COMPONENTS_MSG} ${MISSING_COMPONENTS_MSG}") + SET(DETAILS "${DETAILS}[c${COMPONENT_MSG}]") + ENDIF(FPHSA_HANDLE_COMPONENTS) # version handling: SET(VERSION_MSG "") @@ -240,7 +276,7 @@ FUNCTION(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FIRST_ARG) # print the result: IF (${_NAME_UPPER}_FOUND) - FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG}" "${DETAILS}") + FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME}: ${${_FIRST_REQUIRED_VAR}} ${VERSION_MSG} ${COMPONENT_MSG}" "${DETAILS}") ELSE (${_NAME_UPPER}_FOUND) IF(FPHSA_CONFIG_MODE) diff --git a/Modules/FindPerl.cmake b/Modules/FindPerl.cmake index db393e7d4..ae686df75 100644 --- a/Modules/FindPerl.cmake +++ b/Modules/FindPerl.cmake @@ -1,8 +1,9 @@ # - Find perl # this module looks for Perl # -# PERL_EXECUTABLE - the full path to perl -# PERL_FOUND - If false, don't attempt to use perl. +# PERL_EXECUTABLE - the full path to perl +# PERL_FOUND - If false, don't attempt to use perl. +# PERL_VERSION_STRING - version of perl found (since CMake 2.8.8) #============================================================================= # Copyright 2001-2009 Kitware, Inc. @@ -39,12 +40,44 @@ FIND_PROGRAM(PERL_EXECUTABLE PATHS ${PERL_POSSIBLE_BIN_PATHS} ) +IF(PERL_EXECUTABLE) + ### PERL_VERSION + EXECUTE_PROCESS( + COMMAND + ${PERL_EXECUTABLE} -V:version + OUTPUT_VARIABLE + PERL_VERSION_OUTPUT_VARIABLE + RESULT_VARIABLE + PERL_VERSION_RESULT_VARIABLE + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + IF(NOT PERL_VERSION_RESULT_VARIABLE AND NOT PERL_VERSION_OUTPUT_VARIABLE MATCHES "^version='UNKNOWN'") + STRING(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE}) + ELSE() + EXECUTE_PROCESS( + COMMAND ${PERL_EXECUTABLE} -v + OUTPUT_VARIABLE PERL_VERSION_OUTPUT_VARIABLE + RESULT_VARIABLE PERL_VERSION_RESULT_VARIABLE + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + IF(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl.*[ \\(]v([0-9\\._]+)[ \\)]") + STRING(REGEX REPLACE ".*This is perl.*[ \\(]v([0-9\\._]+)[ \\)].*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE}) + ELSEIF(NOT PERL_VERSION_RESULT_VARIABLE AND PERL_VERSION_OUTPUT_VARIABLE MATCHES "This is perl, version ([0-9\\._]+) +") + STRING(REGEX REPLACE ".*This is perl, version ([0-9\\._]+) +.*" "\\1" PERL_VERSION_STRING ${PERL_VERSION_OUTPUT_VARIABLE}) + ENDIF() + ENDIF() +ENDIF(PERL_EXECUTABLE) + # Deprecated settings for compatibility with CMake1.4 SET(PERL ${PERL_EXECUTABLE}) # handle the QUIETLY and REQUIRED arguments and set PERL_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl DEFAULT_MSG PERL_EXECUTABLE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Perl + REQUIRED_VARS PERL_EXECUTABLE + VERSION_VAR PERL_VERSION_STRING) MARK_AS_ADVANCED(PERL_EXECUTABLE) diff --git a/Modules/FindPerlLibs.cmake b/Modules/FindPerlLibs.cmake index eea55f174..b2ffd3cf6 100644 --- a/Modules/FindPerlLibs.cmake +++ b/Modules/FindPerlLibs.cmake @@ -55,19 +55,6 @@ if (PERL_EXECUTABLE) string(REGEX REPLACE "prefix='([^']+)'.*" "\\1" PERL_PREFIX ${PERL_PREFIX_OUTPUT_VARIABLE}) endif (NOT PERL_PREFIX_RESULT_VARIABLE) - ### PERL_VERSION - execute_process( - COMMAND - ${PERL_EXECUTABLE} -V:version - OUTPUT_VARIABLE - PERL_VERSION_OUTPUT_VARIABLE - RESULT_VARIABLE - PERL_VERSION_RESULT_VARIABLE - ) - if (NOT PERL_VERSION_RESULT_VARIABLE) - string(REGEX REPLACE "version='([^']+)'.*" "\\1" PERL_VERSION ${PERL_VERSION_OUTPUT_VARIABLE}) - endif (NOT PERL_VERSION_RESULT_VARIABLE) - ### PERL_ARCHNAME execute_process( COMMAND @@ -107,6 +94,7 @@ if (PERL_EXECUTABLE) ) if (NOT PERL_SITESEARCH_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITESEARCH ${PERL_SITESEARCH_OUTPUT_VARIABLE}) + file(TO_CMAKE_PATH "${PERL_SITESEARCH}" PERL_SITESEARCH) endif (NOT PERL_SITESEARCH_RESULT_VARIABLE) ### PERL_SITELIB @@ -120,6 +108,7 @@ if (PERL_EXECUTABLE) ) if (NOT PERL_SITELIB_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_SITELIB ${PERL_SITELIB_OUTPUT_VARIABLE}) + file(TO_CMAKE_PATH "${PERL_SITELIB}" PERL_SITELIB) endif (NOT PERL_SITELIB_RESULT_VARIABLE) ### PERL_VENDORARCH @@ -133,6 +122,7 @@ if (PERL_EXECUTABLE) ) if (NOT PERL_VENDORARCH_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORARCH ${PERL_VENDORARCH_OUTPUT_VARIABLE}) + file(TO_CMAKE_PATH "${PERL_VENDORARCH}" PERL_VENDORARCH) endif (NOT PERL_VENDORARCH_RESULT_VARIABLE) ### PERL_VENDORLIB @@ -146,6 +136,7 @@ if (PERL_EXECUTABLE) ) if (NOT PERL_VENDORLIB_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_VENDORLIB ${PERL_VENDORLIB_OUTPUT_VARIABLE}) + file(TO_CMAKE_PATH "${PERL_VENDORLIB}" PERL_VENDORLIB) endif (NOT PERL_VENDORLIB_RESULT_VARIABLE) macro(perl_adjust_darwin_lib_variable varname) @@ -186,6 +177,7 @@ if (PERL_EXECUTABLE) if (NOT PERL_ARCHLIB_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_ARCHLIB ${PERL_ARCHLIB_OUTPUT_VARIABLE}) perl_adjust_darwin_lib_variable( ARCHLIB ) + file(TO_CMAKE_PATH "${PERL_ARCHLIB}" PERL_ARCHLIB) endif (NOT PERL_ARCHLIB_RESULT_VARIABLE) ### PERL_PRIVLIB @@ -200,28 +192,10 @@ if (PERL_EXECUTABLE) if (NOT PERL_PRIVLIB_RESULT_VARIABLE) string(REGEX REPLACE "install[a-z]+='([^']+)'.*" "\\1" PERL_PRIVLIB ${PERL_PRIVLIB_OUTPUT_VARIABLE}) perl_adjust_darwin_lib_variable( PRIVLIB ) + file(TO_CMAKE_PATH "${PERL_PRIVLIB}" PERL_PRIVLIB) endif (NOT PERL_PRIVLIB_RESULT_VARIABLE) - - ### PERL_POSSIBLE_INCLUDE_PATHS - set(PERL_POSSIBLE_INCLUDE_PATHS - ${PERL_ARCHLIB}/CORE - /usr/lib/perl5/${PERL_VERSION}/${PERL_ARCHNAME}/CORE - /usr/lib/perl/${PERL_VERSION}/${PERL_ARCHNAME}/CORE - /usr/lib/perl5/${PERL_VERSION}/CORE - /usr/lib/perl/${PERL_VERSION}/CORE - ) - - ### PERL_POSSIBLE_LIB_PATHS - set(PERL_POSSIBLE_LIB_PATHS - ${PERL_ARCHLIB}/CORE - /usr/lib/perl5/${PERL_VERSION}/${PERL_ARCHNAME}/CORE - /usr/lib/perl/${PERL_VERSION}/${PERL_ARCHNAME}/CORE - /usr/lib/perl5/${PERL_VERSION}/CORE - /usr/lib/perl/${PERL_VERSION}/CORE - ) - - ### PERL_POSSIBLE_LIBRARY_NAME + ### PERL_POSSIBLE_LIBRARY_NAMES execute_process( COMMAND ${PERL_EXECUTABLE} -V:libperl @@ -231,10 +205,9 @@ if (PERL_EXECUTABLE) PERL_LIBRARY_RESULT_VARIABLE ) if (NOT PERL_LIBRARY_RESULT_VARIABLE) - foreach(_perl_lib_path ${PERL_POSSIBLE_LIB_PATHS}) - string(REGEX REPLACE "libperl='([^']+)'" "\\1" PERL_LIBRARY_OUTPUT_VARIABLE ${PERL_LIBRARY_OUTPUT_VARIABLE}) - set(PERL_POSSIBLE_LIBRARY_NAME ${PERL_POSSIBLE_LIBRARY_NAME} "${_perl_lib_path}/${PERL_LIBRARY_OUTPUT_VARIABLE}") - endforeach(_perl_lib_path ${PERL_POSSIBLE_LIB_PATHS}) + string(REGEX REPLACE "libperl='([^']+)'.*" "\\1" PERL_POSSIBLE_LIBRARY_NAMES ${PERL_LIBRARY_OUTPUT_VARIABLE}) + else (NOT PERL_LIBRARY_RESULT_VARIABLE) + set(PERL_POSSIBLE_LIBRARY_NAMES perl${PERL_VERSION_STRING} perl) endif (NOT PERL_LIBRARY_RESULT_VARIABLE) ### PERL_INCLUDE_PATH @@ -242,17 +215,23 @@ if (PERL_EXECUTABLE) NAMES perl.h PATHS - ${PERL_POSSIBLE_INCLUDE_PATHS} + ${PERL_ARCHLIB}/CORE + /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE + /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE + /usr/lib/perl5/${PERL_VERSION_STRING}/CORE + /usr/lib/perl/${PERL_VERSION_STRING}/CORE ) - + ### PERL_LIBRARY find_library(PERL_LIBRARY NAMES - ${PERL_POSSIBLE_LIBRARY_NAME} - perl${PERL_VERSION} - perl + ${PERL_POSSIBLE_LIBRARY_NAMES} PATHS - ${PERL_POSSIBLE_LIB_PATHS} + ${PERL_ARCHLIB}/CORE + /usr/lib/perl5/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE + /usr/lib/perl/${PERL_VERSION_STRING}/${PERL_ARCHNAME}/CORE + /usr/lib/perl5/${PERL_VERSION_STRING}/CORE + /usr/lib/perl/${PERL_VERSION_STRING}/CORE ) endif (PERL_EXECUTABLE) @@ -261,15 +240,16 @@ endif (PERL_EXECUTABLE) # all listed variables are TRUE include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args(PerlLibs REQUIRED_VARS PERL_LIBRARY PERL_INCLUDE_PATH - VERSION_VAR PERL_VERSION) + VERSION_VAR PERL_VERSION_STRING) # Introduced after CMake 2.6.4 to bring module into compliance set(PERL_INCLUDE_DIR ${PERL_INCLUDE_PATH}) set(PERL_INCLUDE_DIRS ${PERL_INCLUDE_PATH}) set(PERL_LIBRARIES ${PERL_LIBRARY}) +# For backward compatibility with CMake before 2.8.8 +set(PERL_VERSION ${PERL_VERSION_STRING}) mark_as_advanced( PERL_INCLUDE_PATH - PERL_EXECUTABLE PERL_LIBRARY ) diff --git a/Modules/FindPkgConfig.cmake b/Modules/FindPkgConfig.cmake index c47f583cb..5d93ab151 100644 --- a/Modules/FindPkgConfig.cmake +++ b/Modules/FindPkgConfig.cmake @@ -13,14 +13,17 @@ # When the 'QUIET' argument is set, no status messages will be printed. # # It sets the following variables: -# PKG_CONFIG_FOUND ... true if pkg-config works on the system -# PKG_CONFIG_EXECUTABLE ... pathname of the pkg-config program -# _FOUND ... set to 1 if module(s) exist +# PKG_CONFIG_FOUND ... true if pkg-config works on the system +# PKG_CONFIG_EXECUTABLE ... pathname of the pkg-config program +# PKG_CONFIG_VERSION_STRING ... the version of the pkg-config program found +# (since CMake 2.8.8) +# PKG_CONFIG_FOUND ... if pkg-config executable was found # # For the following variables two sets of values exist; first one is the # common one and has the given PREFIX. The second set contains flags # which are given out when pkgconfig was called with the '--static' # option. +# _FOUND ... set to 1 if module(s) exist # _LIBRARIES ... only the libraries (w/o the '-l') # _LIBRARY_DIRS ... the paths of the libraries (w/o the '-L') # _LDFLAGS ... all required linker flags @@ -85,15 +88,21 @@ ### Common stuff #### set(PKG_CONFIG_VERSION 1) -set(PKG_CONFIG_FOUND 0) find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config DOC "pkg-config executable") mark_as_advanced(PKG_CONFIG_EXECUTABLE) -if(PKG_CONFIG_EXECUTABLE) - set(PKG_CONFIG_FOUND 1) -endif(PKG_CONFIG_EXECUTABLE) - +if (PKG_CONFIG_EXECUTABLE) + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --version + OUTPUT_VARIABLE PKG_CONFIG_VERSION_STRING + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +endif (PKG_CONFIG_EXECUTABLE) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +find_package_handle_standard_args(PkgConfig + REQUIRED_VARS PKG_CONFIG_EXECUTABLE + VERSION_VAR PKG_CONFIG_VERSION_STRING) # Unsets the given variables macro(_pkgconfig_unset var) diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index 55f95c617..94e5676fe 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -1,20 +1,11 @@ # - Find the PostgreSQL installation. -# Usage: -# In your CMakeLists.txt file do something like this: -# ... -# # PostgreSQL -# FIND_PACKAGE(PostgreSQL) -# ... -# if( PostgreSQL_FOUND ) -# include_directories(${PostgreSQL_INCLUDE_DIRS}) -# endif( PostgreSQL_FOUND ) -# ... -# Remember to include ${PostgreSQL_LIBRARIES} in the target_link_libraries() statement. -# -# # In Windows, we make the assumption that, if the PostgreSQL files are installed, the default directory # will be C:\Program Files\PostgreSQL. # +# This module defines +# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking +# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers +# PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8) #============================================================================= # Copyright 2004-2009 Kitware, Inc. @@ -150,11 +141,20 @@ find_library( PostgreSQL_LIBRARY ) get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH) +if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h") + file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str + REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") + + string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1" + PostgreSQL_VERSION_STRING "${pgsql_version_str}") + unset(pgsql_version_str) +endif() + # Did we find anything? include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(PostgreSQL DEFAULT_MSG - PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR) - +find_package_handle_standard_args(PostgreSQL + REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR + VERSION_VAR PostgreSQL_VERSION_STRING) set( PostgreSQL_FOUND ${POSTGRESQL_FOUND}) # Now try to get the include and library path. diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index 53443040d..1e1e49301 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -7,6 +7,9 @@ # (vsprojects/Debug & vsprojects/Release) will be searched # for libraries and binaries. # +# PROTOBUF_IMPORT_DIRS - List of additional directories to be searched for +# imported .proto files. (New in CMake 2.8.8) +# # Defines the following variables: # # PROTOBUF_FOUND - Found the Google Protocol Buffers library (libprotobuf & header files) @@ -91,6 +94,16 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) endif() + if(DEFINED PROTOBUF_IMPORT_DIRS) + foreach(DIR ${PROTOBUF_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + endif() + set(${SRCS}) set(${HDRS}) foreach(FIL ${ARGN}) diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake index a10ec2371..a131c5fde 100644 --- a/Modules/FindPythonInterp.cmake +++ b/Modules/FindPythonInterp.cmake @@ -10,11 +10,14 @@ # PYTHON_VERSION_MINOR - Python minor version found e.g. 5 # PYTHON_VERSION_PATCH - Python patch version found e.g. 2 # -# Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for +# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of +# version numbers that should be taken into account when searching for Python. +# You need to set this variable before calling find_package(PythonInterp). #============================================================================= # Copyright 2005-2010 Kitware, Inc. # Copyright 2011 Bjoern Ricks +# Copyright 2012 Rolf Eike Beer # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -26,14 +29,51 @@ # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) +unset(_Python_NAMES) + +set(_PYTHON1_VERSIONS 1.6 1.5) +set(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) +set(_PYTHON3_VERSIONS 3.3 3.2 3.1 3.0) + +if(PythonInterp_FIND_VERSION) + if(PythonInterp_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") + string(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _PYTHON_FIND_MAJ_MIN "${PythonInterp_FIND_VERSION}") + string(REGEX REPLACE "^([0-9]+).*" "\\1" _PYTHON_FIND_MAJ "${_PYTHON_FIND_MAJ_MIN}") + list(APPEND _Python_NAMES python${_PYTHON_FIND_MAJ_MIN} python${_PYTHON_FIND_MAJ}) + unset(_PYTHON_FIND_OTHER_VERSIONS) + if(NOT PythonInterp_FIND_VERSION_EXACT) + foreach(_PYTHON_V ${_PYTHON${_PYTHON_FIND_MAJ}_VERSIONS}) + if(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN) + list(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V}) + endif() + endforeach() + endif(NOT PythonInterp_FIND_VERSION_EXACT) + unset(_PYTHON_FIND_MAJ_MIN) + unset(_PYTHON_FIND_MAJ) + else(PythonInterp_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") + list(APPEND _Python_NAMES python${PythonInterp_FIND_VERSION}) + set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonInterp_FIND_VERSION}_VERSIONS}) + endif(PythonInterp_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") +else(PythonInterp_FIND_VERSION) + set(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS}) +endif(PythonInterp_FIND_VERSION) + +list(APPEND _Python_NAMES python) + # Search for the current active python version first -find_program(PYTHON_EXECUTABLE NAMES python) +find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES}) # Set up the versions we know about, in the order we will search. Always add # the user supplied additional versions to the front. set(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS} - 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5) + ${_PYTHON_FIND_OTHER_VERSIONS} + ) + +unset(_PYTHON_FIND_OTHER_VERSIONS) +unset(_PYTHON1_VERSIONS) +unset(_PYTHON2_VERSIONS) +unset(_PYTHON3_VERSIONS) # Search for newest python version if python executable isn't found if(NOT PYTHON_EXECUTABLE) @@ -51,12 +91,47 @@ endif() # determine python version string if(PYTHON_EXECUTABLE) - execute_process(COMMAND "${PYTHON_EXECUTABLE}" --version ERROR_VARIABLE _VERSION OUTPUT_QUIET ERROR_STRIP_TRAILING_WHITESPACE) - string(REPLACE "Python " "" PYTHON_VERSION_STRING "${_VERSION}") - string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}") - string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}") -endif() + execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c + "import sys; sys.stdout.write(';'.join([str(x) for x in sys.version_info[:3]]))" + OUTPUT_VARIABLE _VERSION + RESULT_VARIABLE _PYTHON_VERSION_RESULT + ERROR_QUIET) + if(NOT _PYTHON_VERSION_RESULT) + string(REPLACE ";" "." PYTHON_VERSION_STRING "${_VERSION}") + list(GET _VERSION 0 PYTHON_VERSION_MAJOR) + list(GET _VERSION 1 PYTHON_VERSION_MINOR) + list(GET _VERSION 2 PYTHON_VERSION_PATCH) + if(PYTHON_VERSION_PATCH EQUAL 0) + # it's called "Python 2.7", not "2.7.0" + string(REGEX REPLACE "\\.0$" "" PYTHON_VERSION_STRING "${PYTHON_VERSION_STRING}") + endif() + else() + # sys.version predates sys.version_info, so use that + execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys; sys.stdout.write(sys.version)" + OUTPUT_VARIABLE _VERSION + RESULT_VARIABLE _PYTHON_VERSION_RESULT + ERROR_QUIET) + if(NOT _PYTHON_VERSION_RESULT) + string(REGEX REPLACE " .*" "" PYTHON_VERSION_STRING "${_VERSION}") + string(REGEX REPLACE "^([0-9]+)\\.[0-9]+.*" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION_STRING}") + string(REGEX REPLACE "^[0-9]+\\.([0-9])+.*" "\\1" PYTHON_VERSION_MINOR "${PYTHON_VERSION_STRING}") + if(PYTHON_VERSION_STRING MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+.*") + string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PYTHON_VERSION_PATCH "${PYTHON_VERSION_STRING}") + else() + set(PYTHON_VERSION_PATCH "0") + endif() + else() + # sys.version was first documented for Python 1.5, so assume + # this is older. + set(PYTHON_VERSION_STRING "1.4") + set(PYTHON_VERSION_MAJOR "1") + set(PYTHON_VERSION_MAJOR "4") + set(PYTHON_VERSION_MAJOR "0") + endif() + endif() + unset(_PYTHON_VERSION_RESULT) + unset(_VERSION) +endif(PYTHON_EXECUTABLE) # handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if # all listed variables are TRUE diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index adcec4631..fcd0838f1 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -7,8 +7,12 @@ # PYTHON_LIBRARIES - path to the python library # PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated) # PYTHON_INCLUDE_DIRS - path to where Python.h is found -# PYTHON_DEBUG_LIBRARIES - path to the debug library -# Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for +# PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated) +# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8) +# +# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of +# version numbers that should be taken into account when searching for Python. +# You need to set this variable before calling find_package(PythonLibs). #============================================================================= # Copyright 2001-2009 Kitware, Inc. @@ -27,11 +31,42 @@ INCLUDE(CMakeFindFrameworks) # Search for the python framework on Apple. CMAKE_FIND_FRAMEWORKS(Python) +SET(_PYTHON1_VERSIONS 1.6 1.5) +SET(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) +SET(_PYTHON3_VERSIONS 3.3 3.2 3.1 3.0) + +IF(PythonLibs_FIND_VERSION) + IF(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") + STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION}") + STRING(REGEX REPLACE "^([0-9]+).*" "\\1" _PYTHON_FIND_MAJ "${_PYTHON_FIND_MAJ_MIN}") + UNSET(_PYTHON_FIND_OTHER_VERSIONS) + IF(NOT PythonLibs_FIND_VERSION_EXACT) + FOREACH(_PYTHON_V ${_PYTHON${_PYTHON_FIND_MAJ}_VERSIONS}) + IF(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN) + LIST(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V}) + ENDIF() + ENDFOREACH() + ENDIF(NOT PythonLibs_FIND_VERSION_EXACT) + UNSET(_PYTHON_FIND_MAJ_MIN) + UNSET(_PYTHON_FIND_MAJ) + ELSE(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") + SET(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION}_VERSIONS}) + ENDIF(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$") +ELSE(PythonLibs_FIND_VERSION) + SET(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS}) +ENDIF(PythonLibs_FIND_VERSION) + # Set up the versions we know about, in the order we will search. Always add # the user supplied additional versions to the front. -set(_Python_VERSIONS +SET(_Python_VERSIONS ${Python_ADDITIONAL_VERSIONS} - 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5) + ${_PYTHON_FIND_OTHER_VERSIONS} + ) + +UNSET(_PYTHON_FIND_OTHER_VERSIONS) +UNSET(_PYTHON1_VERSIONS) +UNSET(_PYTHON2_VERSIONS) +UNSET(_PYTHON3_VERSIONS) FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION}) @@ -40,13 +75,17 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) NAMES python${_CURRENT_VERSION_NO_DOTS}_d python PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs ) + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs + ) ENDIF(WIN32) FIND_LIBRARY(PYTHON_LIBRARY NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION} PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs # Avoid finding the .dll in the PATH. We want the .lib. NO_SYSTEM_ENVIRONMENT_PATH ) @@ -79,6 +118,7 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) PATHS ${PYTHON_FRAMEWORK_INCLUDES} [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include PATH_SUFFIXES python${_CURRENT_VERSION} ) @@ -87,6 +127,17 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL "Path to where Python.h is found (deprecated)") + IF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") + FILE(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str + REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"") + STRING(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1" + PYTHONLIBS_VERSION_STRING "${python_version_str}") + UNSET(python_version_str) + ENDIF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") + + IF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR) + BREAK() + ENDIF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR) ENDFOREACH(_CURRENT_VERSION) MARK_AS_ADVANCED( @@ -100,13 +151,23 @@ MARK_AS_ADVANCED( # library. We now set the variables listed by the documentation for this # module. SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") -SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") +# These variables have been historically named in this module different from +# what SELECT_LIBRARY_CONFIGURATIONS() expects. +SET(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}") +SET(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}") +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +SELECT_LIBRARY_CONFIGURATIONS(PYTHON) +# SELECT_LIBRARY_CONFIGURATIONS() sets ${PREFIX}_FOUND if it has a library. +# Unset this, this prefix doesn't match the module prefix, they are different +# for historical reasons. +UNSET(PYTHON_FOUND) INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs DEFAULT_MSG PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) - +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs + REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS + VERSION_VAR PYTHONLIBS_VERSION_STRING) # PYTHON_ADD_MODULE( src1 src2 ... srcN) is used to build modules for python. # PYTHON_WRITE_MODULES_HEADER() writes a header file you can include diff --git a/Modules/FindQt3.cmake b/Modules/FindQt3.cmake index bacbb070e..2d8dbde22 100644 --- a/Modules/FindQt3.cmake +++ b/Modules/FindQt3.cmake @@ -1,10 +1,11 @@ # - Locate Qt include paths and libraries # This module defines: -# QT_INCLUDE_DIR - where to find qt.h, etc. -# QT_LIBRARIES - the libraries to link against to use Qt. -# QT_DEFINITIONS - definitions to use when -# compiling code that uses Qt. -# QT_FOUND - If false, don't try to use Qt. +# QT_INCLUDE_DIR - where to find qt.h, etc. +# QT_LIBRARIES - the libraries to link against to use Qt. +# QT_DEFINITIONS - definitions to use when +# compiling code that uses Qt. +# QT_FOUND - If false, don't try to use Qt. +# QT_VERSION_STRING - the version of Qt found # # If you need the multithreaded version of Qt, set QT_MT_REQUIRED to TRUE # @@ -46,13 +47,16 @@ IF(QT4_FOUND) ENDIF(QT4_FOUND) -FILE(GLOB GLOB_PATHS_BIN /usr/lib/qt-3*/bin/) +FILE(GLOB GLOB_PATHS /usr/lib/qt-3*) +FOREACH(GLOB_PATH ${GLOB_PATHS}) + LIST(APPEND GLOB_PATHS_BIN "${GLOB_PATH}/bin") +ENDFOREACH(GLOB_PATH) FIND_PATH(QT_INCLUDE_DIR qt.h "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/include/Qt" "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/include/Qt" "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/include/Qt" $ENV{QTDIR}/include - ${GLOB_PATHS_BIN} + ${GLOB_PATHS} /usr/local/qt/include /usr/lib/qt/include /usr/lib/qt3/include @@ -71,12 +75,13 @@ ENDIF(NOT EXISTS ${QT_INCLUDE_DIR}/qglobal.h) IF(QT_INCLUDE_DIR) #extract the version string from qglobal.h FILE(READ ${QT_INCLUDE_DIR}/qglobal.h QGLOBAL_H) - STRING(REGEX MATCH "#define[\t ]+QT_VERSION_STR[\t ]+\"([0-9]+.[0-9]+.[0-9]+)\"" QGLOBAL_H "${QGLOBAL_H}") - STRING(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+)\".*" "\\1" qt_version_str "${QGLOBAL_H}") + STRING(REGEX MATCH "#define[\t ]+QT_VERSION_STR[\t ]+\"[0-9]+.[0-9]+.[0-9]+[a-z]*\"" QGLOBAL_H "${QGLOBAL_H}") + STRING(REGEX REPLACE ".*\"([0-9]+.[0-9]+.[0-9]+[a-z]*)\".*" "\\1" qt_version_str "${QGLOBAL_H}") # Under windows the qt library (MSVC) has the format qt-mtXYZ where XYZ is the # version X.Y.Z, so we need to remove the dots from version STRING(REGEX REPLACE "\\." "" qt_version_str_lib "${qt_version_str}") + SET(QT_VERSION_STRING "${qt_version_str}") ENDIF(QT_INCLUDE_DIR) FILE(GLOB GLOB_PATHS_LIB /usr/lib/qt-3*/lib/) @@ -183,67 +188,28 @@ ENDIF(QT_UIC_EXECUTABLE) IF (WIN32) FIND_LIBRARY(QT_QTMAIN_LIBRARY qtmain + HINTS + $ENV{QTDIR}/lib "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.1;InstallDir]/lib" "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.2.0;InstallDir]/lib" "[HKEY_CURRENT_USER\\Software\\Trolltech\\Qt3Versions\\3.1.0;InstallDir]/lib" + PATHS "$ENV{ProgramFiles}/qt/lib" - $ENV{QTDIR}/lib "C:/Program Files/qt/lib" + "C:/Program Files/qt/lib" DOC "This Library is only needed by and included with Qt3 on MSWindows. It should be NOTFOUND, undefined or IGNORE otherwise." ) ENDIF (WIN32) - -IF (QT_MIN_VERSION) - - STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" qt_major_vers "${qt_version_str}") - STRING(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" qt_minor_vers "${qt_version_str}") - STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" qt_patch_vers "${qt_version_str}") - - #now parse the parts of the user given version string into variables - STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+$" req_qt_major_vers "${QT_MIN_VERSION}") - IF (NOT req_qt_major_vers) - error_message( "Invalid Qt version string given: \"${QT_MIN_VERSION}\", expected e.g. \"3.1.5\"") - ENDIF (NOT req_qt_major_vers) - - STRING(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" req_qt_major_vers "${QT_MIN_VERSION}") - STRING(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" req_qt_minor_vers "${QT_MIN_VERSION}") - STRING(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" req_qt_patch_vers "${QT_MIN_VERSION}") - - # req = "6.5.4", qt = "3.2.1" - MACRO(error_message msg) - IF(QT3_REQUIRED) - MESSAGE( FATAL_ERROR ${msg}) - ELSE(QT3_REQUIRED) - MESSAGE( STATUS ${msg}) - ENDIF(QT3_REQUIRED) - ENDMACRO(error_message) - - IF (req_qt_major_vers GREATER qt_major_vers) # (6 > 3) ? - ERROR_MESSAGE( "Qt major version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes - ELSE (req_qt_major_vers GREATER qt_major_vers) # no - IF (req_qt_major_vers LESS qt_major_vers) # (6 < 3) ? - SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes - ELSE (req_qt_major_vers LESS qt_major_vers) # ( 6==3) ? - IF (req_qt_minor_vers GREATER qt_minor_vers) # (5>2) ? - ERROR_MESSAGE( "Qt minor version not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes - ELSE (req_qt_minor_vers GREATER qt_minor_vers) # no - IF (req_qt_minor_vers LESS qt_minor_vers) # (5<2) ? - SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes - ELSE (req_qt_minor_vers LESS qt_minor_vers) # (5==2) - IF (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ? - ERROR_MESSAGE( "Qt patch level not matched (required: ${QT_MIN_VERSION}, found: ${qt_version_str})") # yes - ELSE (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ? - SET( QT_VERSION_BIG_ENOUGH "YES" ) # yes - ENDIF (req_qt_patch_vers GREATER qt_patch_vers) # (4>1) ? - ENDIF (req_qt_minor_vers LESS qt_minor_vers) - ENDIF (req_qt_minor_vers GREATER qt_minor_vers) - ENDIF (req_qt_major_vers LESS qt_major_vers) - ENDIF (req_qt_major_vers GREATER qt_major_vers) -ENDIF (QT_MIN_VERSION) +#support old QT_MIN_VERSION if set, but not if version is supplied by find_package() +IF(NOT Qt3_FIND_VERSION AND QT_MIN_VERSION) + SET(Qt3_FIND_VERSION ${QT_MIN_VERSION}) +ENDIF(NOT Qt3_FIND_VERSION AND QT_MIN_VERSION) # if the include a library are found then we have it INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3 DEFAULT_MSG QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Qt3 + REQUIRED_VARS QT_QT_LIBRARY QT_INCLUDE_DIR QT_MOC_EXECUTABLE + VERSION_VAR QT_VERSION_STRING) SET(QT_FOUND ${QT3_FOUND} ) IF(QT_FOUND) @@ -293,8 +259,16 @@ IF(QT_FOUND) ENDIF(QT_QT_LIBRARY MATCHES "qt-mt") ENDIF(QT_FOUND) -EXEC_PROGRAM(${QT_MOC_EXECUTABLE} ARGS "-v" OUTPUT_VARIABLE QTVERSION_MOC) -EXEC_PROGRAM(${QT_UIC_EXECUTABLE} ARGS "-version" OUTPUT_VARIABLE QTVERSION_UIC) +IF(QT_MOC_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${QT_MOC_EXECUTABLE} "-v" + OUTPUT_VARIABLE QTVERSION_MOC + ERROR_QUIET) +ENDIF(QT_MOC_EXECUTABLE) +IF(QT_UIC_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${QT_UIC_EXECUTABLE} "-version" + OUTPUT_VARIABLE QTVERSION_UIC + ERROR_QUIET) +ENDIF(QT_UIC_EXECUTABLE) SET(_QT_UIC_VERSION_3 FALSE) IF("${QTVERSION_UIC}" MATCHES ".* 3..*") diff --git a/Modules/FindQt4.cmake b/Modules/FindQt4.cmake index c56827eaa..9b646b443 100644 --- a/Modules/FindQt4.cmake +++ b/Modules/FindQt4.cmake @@ -588,8 +588,9 @@ IF (QT_QMAKE_EXECUTABLE AND QTVERSION) SET(QT_LIBRARY_DIR ${QT_LIBRARY_DIR_TMP} CACHE INTERNAL "Qt library dir" FORCE) SET(QT_QTCORE_FOUND 1) ELSE() - MESSAGE("Warning: QT_QMAKE_EXECUTABLE reported QT_INSTALL_LIBS as ${QT_LIBRARY_DIR_TMP}") - MESSAGE("Warning: But QtCore couldn't be found. Qt must NOT be installed correctly, or it wasn't found for cross compiling.") + MESSAGE(WARNING "${QT_QMAKE_EXECUTABLE} reported QT_INSTALL_LIBS as \"${QT_LIBRARY_DIR_TMP}\" " + "but QtCore could not be found there. " + "Qt is NOT installed correctly for the target build environment.") IF(Qt4_FIND_REQUIRED) MESSAGE( FATAL_ERROR "Could NOT find QtCore. Check ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log for more details.") ENDIF(Qt4_FIND_REQUIRED) diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index ae2ea2e33..5e973e485 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -60,50 +60,45 @@ ENDIF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19") FIND_PROGRAM(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}) -IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION) - # query the ruby version - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MAJOR']" - OUTPUT_VARIABLE RUBY_VERSION_MAJOR) +IF(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) + FUNCTION(_RUBY_CONFIG_VAR RBVAR OUTVAR) + EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" + RESULT_VARIABLE _RUBY_SUCCESS + OUTPUT_VARIABLE _RUBY_OUTPUT + ERROR_QUIET) + IF(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT) + EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']" + RESULT_VARIABLE _RUBY_SUCCESS + OUTPUT_VARIABLE _RUBY_OUTPUT + ERROR_QUIET) + ENDIF(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT) + SET(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE) + ENDFUNCTION(_RUBY_CONFIG_VAR) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MINOR']" - OUTPUT_VARIABLE RUBY_VERSION_MINOR) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['TEENY']" - OUTPUT_VARIABLE RUBY_VERSION_PATCH) + # query the ruby version + _RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR) + _RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR) + _RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH) # query the different directories - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']" - OUTPUT_VARIABLE RUBY_ARCH_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['arch']" - OUTPUT_VARIABLE RUBY_ARCH) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubyhdrdir']" - OUTPUT_VARIABLE RUBY_HDR_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']" - OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']" - OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR) + _RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR) + _RUBY_CONFIG_VAR("arch" RUBY_ARCH) + _RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR) + _RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR) + _RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR) # site_ruby - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']" - OUTPUT_VARIABLE RUBY_SITEARCH_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']" - OUTPUT_VARIABLE RUBY_SITELIB_DIR) + _RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR) + _RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR) # vendor_ruby available ? EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'" OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET) IF(RUBY_HAS_VENDOR_RUBY) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']" - OUTPUT_VARIABLE RUBY_VENDORLIB_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" - OUTPUT_VARIABLE RUBY_VENDORARCH_DIR) + _RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR) + _RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR) ENDIF(RUBY_HAS_VENDOR_RUBY) # save the results in the cache so we don't have to run ruby the next time again @@ -135,11 +130,11 @@ IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION) RUBY_VERSION_MINOR RUBY_VERSION_PATCH ) -ENDIF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION) +ENDIF(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) # In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling) # try to detect which version we found. This is not too good. -IF(NOT RUBY_VERSION_MAJOR) +IF(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) # by default assume 1.8.0 SET(RUBY_VERSION_MAJOR 1) SET(RUBY_VERSION_MINOR 8) @@ -149,13 +144,14 @@ IF(NOT RUBY_VERSION_MAJOR) SET(RUBY_VERSION_MAJOR 1) SET(RUBY_VERSION_MINOR 9) ENDIF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR) -ENDIF(NOT RUBY_VERSION_MAJOR) - +ENDIF(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) -SET(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}") -SET(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}") -SET(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}") -SET(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}") +IF(RUBY_VERSION_MAJOR) + SET(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}") + SET(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}") + SET(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}") + SET(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}") +ENDIF(RUBY_VERSION_MAJOR) FIND_PATH(RUBY_INCLUDE_DIR NAMES ruby.h @@ -167,7 +163,7 @@ FIND_PATH(RUBY_INCLUDE_DIR SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} ) # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir -IF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR) +IF( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR) FIND_PATH(RUBY_CONFIG_INCLUDE_DIR NAMES ruby/config.h config.h HINTS @@ -176,11 +172,11 @@ IF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT ) SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} ) -ENDIF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR) +ENDIF( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR) # Determine the list of possible names for the ruby library -SET(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ruby${_RUBY_VERSION_SHORT_NODOT}) +SET(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ruby${_RUBY_VERSION_SHORT_NODOT} ruby-${_RUBY_VERSION_SHORT} ruby-${RUBY_VERSION}) IF(WIN32) SET( _RUBY_MSVC_RUNTIME "" ) @@ -224,6 +220,10 @@ IF(_RUBY_DEBUG_OUTPUT) MESSAGE(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}") MESSAGE(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"") MESSAGE(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}") + MESSAGE(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}") + MESSAGE(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}") + MESSAGE(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}") + MESSAGE(STATUS "RUBY_CONFIG_INCLUDE_DIR: ${RUBY_CONFIG_INCLUDE_DIR}") MESSAGE(STATUS "--------------------") ENDIF(_RUBY_DEBUG_OUTPUT) diff --git a/Modules/FindSDL.cmake b/Modules/FindSDL.cmake index 0dc02f5b6..1c04726ea 100644 --- a/Modules/FindSDL.cmake +++ b/Modules/FindSDL.cmake @@ -81,7 +81,6 @@ FIND_PATH(SDL_INCLUDE_DIR SDL.h /opt/csw # Blastwave /opt ) -#MESSAGE("SDL_INCLUDE_DIR is ${SDL_INCLUDE_DIR}") # SDL-1.1 is the name used by FreeBSD ports... # don't confuse it for the version number. @@ -97,8 +96,6 @@ FIND_LIBRARY(SDL_LIBRARY_TEMP /opt ) -#MESSAGE("SDL_LIBRARY_TEMP is ${SDL_LIBRARY_TEMP}") - IF(NOT SDL_BUILDING_LIBRARY) IF(NOT ${SDL_INCLUDE_DIR} MATCHES ".framework") # Non-OS X framework versions expect you to also dynamically link to @@ -134,7 +131,6 @@ IF(MINGW) SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") ENDIF(MINGW) -SET(SDL_FOUND "NO") IF(SDL_LIBRARY_TEMP) # For SDLmain IF(NOT SDL_BUILDING_LIBRARY) @@ -169,9 +165,9 @@ IF(SDL_LIBRARY_TEMP) SET(SDL_LIBRARY ${SDL_LIBRARY_TEMP} CACHE STRING "Where the SDL Library can be found") # Set the temp variable to INTERNAL so it is not seen in the CMake GUI SET(SDL_LIBRARY_TEMP "${SDL_LIBRARY_TEMP}" CACHE INTERNAL "") - - SET(SDL_FOUND "YES") ENDIF(SDL_LIBRARY_TEMP) -#MESSAGE("SDL_LIBRARY is ${SDL_LIBRARY}") +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL + REQUIRED_VARS SDL_LIBRARY SDL_INCLUDE_DIR) diff --git a/Modules/FindSDL_image.cmake b/Modules/FindSDL_image.cmake index 5a5f59ba8..9a130fa22 100644 --- a/Modules/FindSDL_image.cmake +++ b/Modules/FindSDL_image.cmake @@ -68,8 +68,7 @@ FIND_LIBRARY(SDLIMAGE_LIBRARY /opt ) -SET(SDLIMAGE_FOUND "NO") -IF(SDLIMAGE_LIBRARY AND SDLIMAGE_INCLUDE_DIR) - SET(SDLIMAGE_FOUND "YES") -ENDIF(SDLIMAGE_LIBRARY AND SDLIMAGE_INCLUDE_DIR) +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLIMAGE + REQUIRED_VARS SDLIMAGE_LIBRARY SDLIMAGE_INCLUDE_DIR) diff --git a/Modules/FindSDL_mixer.cmake b/Modules/FindSDL_mixer.cmake index e2b2294c4..ce1ae9e2c 100644 --- a/Modules/FindSDL_mixer.cmake +++ b/Modules/FindSDL_mixer.cmake @@ -68,8 +68,7 @@ FIND_LIBRARY(SDLMIXER_LIBRARY /opt ) -SET(SDLMIXER_FOUND "NO") -IF(SDLMIXER_LIBRARY AND SDLMIXER_INCLUDE_DIR) - SET(SDLMIXER_FOUND "YES") -ENDIF(SDLMIXER_LIBRARY AND SDLMIXER_INCLUDE_DIR) +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLMIXER + REQUIRED_VARS SDLMIXER_LIBRARY SDLMIXER_INCLUDE_DIR) diff --git a/Modules/FindSDL_net.cmake b/Modules/FindSDL_net.cmake index 730b129f0..b5ada54b9 100644 --- a/Modules/FindSDL_net.cmake +++ b/Modules/FindSDL_net.cmake @@ -67,8 +67,7 @@ FIND_LIBRARY(SDLNET_LIBRARY /opt ) -SET(SDLNET_FOUND "NO") -IF(SDLNET_LIBRARY AND SDLNET_INCLUDE_DIR) - SET(SDLNET_FOUND "YES") -ENDIF(SDLNET_LIBRARY AND SDLNET_INCLUDE_DIR) +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLNET + REQUIRED_VARS SDLNET_LIBRARY SDLNET_INCLUDE_DIR) diff --git a/Modules/FindSDL_sound.cmake b/Modules/FindSDL_sound.cmake index 959f3ebe5..8edf6ca05 100644 --- a/Modules/FindSDL_sound.cmake +++ b/Modules/FindSDL_sound.cmake @@ -114,7 +114,6 @@ FIND_LIBRARY(SDL_SOUND_LIBRARY /opt/lib ) -SET(SDL_SOUND_FOUND "NO") IF(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY) # CMake is giving me problems using TRY_COMPILE with the CMAKE_FLAGS @@ -414,8 +413,9 @@ IF(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY) ENDIF(NOT MY_RESULT) SET(SDL_SOUND_LIBRARIES "${SDL_SOUND_EXTRAS} ${SDL_SOUND_LIBRARIES_TMP}" CACHE INTERNAL "SDL_sound and dependent libraries") - SET(SDL_SOUND_FOUND "YES") ENDIF(SDL_FOUND AND SDL_SOUND_INCLUDE_DIR AND SDL_SOUND_LIBRARY) - # MESSAGE("SDL_SOUND_LIBRARIES is ${SDL_SOUND_LIBRARIES}") +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL_SOUND + REQUIRED_VARS SDL_SOUND_LIBRARIES SDL_SOUND_INCLUDE_DIR) diff --git a/Modules/FindSDL_ttf.cmake b/Modules/FindSDL_ttf.cmake index b36ddd3b9..3d07ab7a8 100644 --- a/Modules/FindSDL_ttf.cmake +++ b/Modules/FindSDL_ttf.cmake @@ -68,8 +68,7 @@ FIND_LIBRARY(SDLTTF_LIBRARY PATH_SUFFIXES lib64 lib ) -SET(SDLTTF_FOUND "NO") -IF(SDLTTF_LIBRARY AND SDLTTF_INCLUDE_DIR) - SET(SDLTTF_FOUND "YES") -ENDIF(SDLTTF_LIBRARY AND SDLTTF_INCLUDE_DIR) +INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDLTTF + REQUIRED_VARS SDLTTF_LIBRARY SDLTTF_INCLUDE_DIR) diff --git a/Modules/FindTCL.cmake b/Modules/FindTCL.cmake index 13f32f81e..f2c776f97 100644 --- a/Modules/FindTCL.cmake +++ b/Modules/FindTCL.cmake @@ -48,10 +48,14 @@ INCLUDE(CMakeFindFrameworks) INCLUDE(FindTclsh) INCLUDE(FindWish) -GET_FILENAME_COMPONENT(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH) -GET_FILENAME_COMPONENT(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH) -STRING(REGEX REPLACE - "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}") +IF(TCLSH_VERSION_STRING) + SET(TCL_TCLSH_VERSION "${TCLSH_VERSION_STRING}") +ELSE(TCLSH_VERSION_STRING) + GET_FILENAME_COMPONENT(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH) + GET_FILENAME_COMPONENT(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH) + STRING(REGEX REPLACE + "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}") +ENDIF(TCLSH_VERSION_STRING) GET_FILENAME_COMPONENT(TK_WISH_PATH "${TK_WISH}" PATH) GET_FILENAME_COMPONENT(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH) diff --git a/Modules/FindTIFF.cmake b/Modules/FindTIFF.cmake index 714f65f67..16f9e238a 100644 --- a/Modules/FindTIFF.cmake +++ b/Modules/FindTIFF.cmake @@ -25,10 +25,21 @@ FIND_PATH(TIFF_INCLUDE_DIR tiff.h) SET(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3) FIND_LIBRARY(TIFF_LIBRARY NAMES ${TIFF_NAMES} ) +IF(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") + FILE(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str + REGEX "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version .*") + + STRING(REGEX REPLACE "^#define[\t ]+TIFFLIB_VERSION_STR[\t ]+\"LIBTIFF, Version +([^ \\n]*).*" + "\\1" TIFF_VERSION_STRING "${tiff_version_str}") + UNSET(tiff_version_str) +ENDIF() + # handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF DEFAULT_MSG TIFF_LIBRARY TIFF_INCLUDE_DIR) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF + REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR + VERSION_VAR TIFF_VERSION_STRING) IF(TIFF_FOUND) SET( TIFF_LIBRARIES ${TIFF_LIBRARY} ) diff --git a/Modules/FindTclsh.cmake b/Modules/FindTclsh.cmake index 8fde59e8e..a45f28528 100644 --- a/Modules/FindTclsh.cmake +++ b/Modules/FindTclsh.cmake @@ -82,9 +82,19 @@ FIND_PROGRAM(TCL_TCLSH HINTS ${TCLTK_POSSIBLE_BIN_PATHS} ) +IF(TCL_TCLSH) + EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -E echo puts "\$tcl_version" + COMMAND "${TCL_TCLSH}" + OUTPUT_VARIABLE TCLSH_VERSION_STRING + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) +ENDIF(TCL_TCLSH) + # handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if # all listed variables are TRUE INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Tclsh DEFAULT_MSG TCL_TCLSH) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Tclsh + REQUIRED_VARS TCL_TCLSH + VERSION_VAR TCLSH_VERSION_STRING) MARK_AS_ADVANCED(TCL_TCLSH) diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index a6c2df89b..21614fb66 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -23,6 +23,7 @@ INCLUDE (CheckIncludeFiles) INCLUDE (CheckLibraryExists) +INCLUDE (CheckSymbolExists) SET(Threads_FOUND FALSE) # Do we have sproc? @@ -44,33 +45,41 @@ ELSE() # SET(CMAKE_HAVE_THREADS_LIBRARY) IF(NOT THREADS_HAVE_PTHREAD_ARG) - - # Do we have -lpthreads - CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) - IF(CMAKE_HAVE_PTHREADS_CREATE) - SET(CMAKE_THREAD_LIBS_INIT "-lpthreads") + # Check if pthread functions are in normal C library + CHECK_SYMBOL_EXISTS(pthread_create pthread.h CMAKE_HAVE_LIBC_CREATE) + IF(CMAKE_HAVE_LIBC_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "") SET(CMAKE_HAVE_THREADS_LIBRARY 1) SET(Threads_FOUND TRUE) ENDIF() - # Ok, how about -lpthread - CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) - IF(CMAKE_HAVE_PTHREAD_CREATE) - SET(CMAKE_THREAD_LIBS_INIT "-lpthread") - SET(Threads_FOUND TRUE) - SET(CMAKE_HAVE_THREADS_LIBRARY 1) - ENDIF() + IF(NOT CMAKE_HAVE_THREADS_LIBRARY) + # Do we have -lpthreads + CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE) + IF(CMAKE_HAVE_PTHREADS_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lpthreads") + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + SET(Threads_FOUND TRUE) + ENDIF() - IF(CMAKE_SYSTEM MATCHES "SunOS.*") - # On sun also check for -lthread - CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) - IF(CMAKE_HAVE_THR_CREATE) - SET(CMAKE_THREAD_LIBS_INIT "-lthread") + # Ok, how about -lpthread + CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE) + IF(CMAKE_HAVE_PTHREAD_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lpthread") SET(CMAKE_HAVE_THREADS_LIBRARY 1) SET(Threads_FOUND TRUE) ENDIF() - ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*") + IF(CMAKE_SYSTEM MATCHES "SunOS.*") + # On sun also check for -lthread + CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE) + IF(CMAKE_HAVE_THR_CREATE) + SET(CMAKE_THREAD_LIBS_INIT "-lthread") + SET(CMAKE_HAVE_THREADS_LIBRARY 1) + SET(Threads_FOUND TRUE) + ENDIF() + ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*") + ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY) ENDIF(NOT THREADS_HAVE_PTHREAD_ARG) IF(NOT CMAKE_HAVE_THREADS_LIBRARY) @@ -111,7 +120,7 @@ ELSE() ENDIF(CMAKE_HAVE_PTHREAD_H) ENDIF() -IF(CMAKE_THREAD_LIBS_INIT) +IF(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_CREATE) SET(CMAKE_USE_PTHREADS_INIT 1) SET(Threads_FOUND TRUE) ENDIF() diff --git a/Modules/FindX11.cmake b/Modules/FindX11.cmake index 04646c0af..76fb3c911 100644 --- a/Modules/FindX11.cmake +++ b/Modules/FindX11.cmake @@ -20,7 +20,7 @@ # X11_XShm_INCLUDE_PATH, (in X11_Xext_LIB), X11_XShm_FOUND # X11_Xshape_INCLUDE_PATH, (in X11_Xext_LIB), X11_Xshape_FOUND # X11_xf86misc_INCLUDE_PATH, X11_Xxf86misc_LIB, X11_xf86misc_FOUND -# X11_xf86vmode_INCLUDE_PATH, X11_xf86vmode_FOUND +# X11_xf86vmode_INCLUDE_PATH, X11_Xxf86vm_LIB X11_xf86vmode_FOUND # X11_Xfixes_INCLUDE_PATH, X11_Xfixes_LIB, X11_Xfixes_FOUND # X11_Xft_INCLUDE_PATH, X11_Xft_LIB, X11_Xft_FOUND # X11_Xi_INCLUDE_PATH, X11_Xi_LIB, X11_Xi_FOUND @@ -29,6 +29,7 @@ # X11_Xkb_INCLUDE_PATH, X11_Xkb_FOUND # X11_Xkblib_INCLUDE_PATH, X11_Xkb_FOUND # X11_Xkbfile_INCLUDE_PATH, X11_Xkbfile_LIB, X11_Xkbfile_FOUND +# X11_Xmu_INCLUDE_PATH, X11_Xmu_LIB, X11_Xmu_FOUND # X11_Xpm_INCLUDE_PATH, X11_Xpm_LIB, X11_Xpm_FOUND # X11_XTest_INCLUDE_PATH, X11_XTest_LIB, X11_XTest_FOUND # X11_Xrandr_INCLUDE_PATH, X11_Xrandr_LIB, X11_Xrandr_FOUND @@ -103,6 +104,7 @@ IF (UNIX) FIND_PATH(X11_Xkb_INCLUDE_PATH X11/extensions/XKB.h ${X11_INC_SEARCH_PATH}) FIND_PATH(X11_Xkblib_INCLUDE_PATH X11/XKBlib.h ${X11_INC_SEARCH_PATH}) FIND_PATH(X11_Xkbfile_INCLUDE_PATH X11/extensions/XKBfile.h ${X11_INC_SEARCH_PATH}) + FIND_PATH(X11_Xmu_INCLUDE_PATH X11/Xmu/Xmu.h ${X11_INC_SEARCH_PATH}) FIND_PATH(X11_Xpm_INCLUDE_PATH X11/xpm.h ${X11_INC_SEARCH_PATH}) FIND_PATH(X11_XTest_INCLUDE_PATH X11/extensions/XTest.h ${X11_INC_SEARCH_PATH}) FIND_PATH(X11_XShm_INCLUDE_PATH X11/extensions/XShm.h ${X11_INC_SEARCH_PATH}) @@ -134,6 +136,7 @@ IF (UNIX) FIND_LIBRARY(X11_Xinerama_LIB Xinerama ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xinput_LIB Xi ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xkbfile_LIB xkbfile ${X11_LIB_SEARCH_PATH}) + FIND_LIBRARY(X11_Xmu_LIB Xmu ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xpm_LIB Xpm ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xrandr_LIB Xrandr ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xrender_LIB Xrender ${X11_LIB_SEARCH_PATH}) @@ -143,6 +146,7 @@ IF (UNIX) FIND_LIBRARY(X11_XTest_LIB Xtst ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xv_LIB Xv ${X11_LIB_SEARCH_PATH}) FIND_LIBRARY(X11_Xxf86misc_LIB Xxf86misc ${X11_LIB_SEARCH_PATH}) + FIND_LIBRARY(X11_Xxf86vm_LIB Xxf86vm ${X11_LIB_SEARCH_PATH}) SET(X11_LIBRARY_DIR "") IF(X11_X11_LIB) @@ -267,10 +271,10 @@ IF (UNIX) SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86misc_INCLUDE_PATH}) ENDIF (X11_xf86misc_INCLUDE_PATH AND X11_Xxf86misc_LIB) - IF (X11_xf86vmode_INCLUDE_PATH) + IF (X11_xf86vmode_INCLUDE_PATH AND X11_Xxf86vm_LIB) SET(X11_xf86vmode_FOUND TRUE) SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_xf86vmode_INCLUDE_PATH}) - ENDIF (X11_xf86vmode_INCLUDE_PATH) + ENDIF (X11_xf86vmode_INCLUDE_PATH AND X11_Xxf86vm_LIB) IF (X11_Xcursor_INCLUDE_PATH AND X11_Xcursor_LIB) SET(X11_Xcursor_FOUND TRUE) @@ -297,6 +301,11 @@ IF (UNIX) SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xkbfile_INCLUDE_PATH} ) ENDIF (X11_Xkbfile_INCLUDE_PATH AND X11_Xkbfile_LIB AND X11_Xlib_INCLUDE_PATH) + IF (X11_Xmu_INCLUDE_PATH AND X11_Xmu_LIB) + SET(X11_Xmu_FOUND TRUE) + SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xmu_INCLUDE_PATH}) + ENDIF (X11_Xmu_INCLUDE_PATH AND X11_Xmu_LIB) + IF (X11_Xinput_INCLUDE_PATH AND X11_Xinput_LIB) SET(X11_Xinput_FOUND TRUE) SET(X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_Xinput_INCLUDE_PATH}) @@ -435,6 +444,7 @@ IF (UNIX) X11_XRes_INCLUDE_PATH X11_Xxf86misc_LIB X11_xf86misc_INCLUDE_PATH + X11_Xxf86vm_LIB X11_xf86vmode_INCLUDE_PATH X11_Xi_LIB X11_Xi_INCLUDE_PATH @@ -456,6 +466,8 @@ IF (UNIX) X11_Xkblib_INCLUDE_PATH X11_Xkbfile_INCLUDE_PATH X11_Xkbfile_LIB + X11_Xmu_INCLUDE_PATH + X11_Xmu_LIB X11_Xscreensaver_INCLUDE_PATH X11_Xscreensaver_LIB X11_Xpm_INCLUDE_PATH diff --git a/Modules/FindosgPresentation.cmake b/Modules/FindosgPresentation.cmake new file mode 100644 index 000000000..f89e25f9c --- /dev/null +++ b/Modules/FindosgPresentation.cmake @@ -0,0 +1,52 @@ +# This is part of the Findosg* suite used to find OpenSceneGraph components. +# Each component is separate and you must opt in to each module. You must +# also opt into OpenGL and OpenThreads (and Producer if needed) as these +# modules won't do it for you. This is to allow you control over your own +# system piece by piece in case you need to opt out of certain components +# or change the Find behavior for a particular module (perhaps because the +# default FindOpenGL.cmake module doesn't work with your system as an +# example). +# If you want to use a more convenient module that includes everything, +# use the FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +# +# Locate osgPresentation +# This module defines +# +# OSGPRESENTATION_FOUND - Was osgPresentation found? +# OSGPRESENTATION_INCLUDE_DIR - Where to find the headers +# OSGPRESENTATION_LIBRARIES - The libraries to link for osgPresentation (use this) +# +# OSGPRESENTATION_LIBRARY - The osgPresentation library +# OSGPRESENTATION_LIBRARY_DEBUG - The osgPresentation debug library +# +# $OSGDIR is an environment variable that would +# correspond to the ./configure --prefix=$OSGDIR +# used in building osg. +# +# Created by Eric Wing. +# Modified to work with osgPresentation by Robert Osfield, January 2012. + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Header files are presumed to be included like +# #include +# #include + +include(Findosg_functions) +OSG_FIND_PATH (OSGPRESENTATION osgPresentation/SlideEventHandler) +OSG_FIND_LIBRARY(OSGPRESENTATION osgPresentation) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgPresentation DEFAULT_MSG + OSGPRESENTATION_LIBRARY OSGPRESENTATION_INCLUDE_DIR) diff --git a/Modules/FindosgQt.cmake b/Modules/FindosgQt.cmake new file mode 100644 index 000000000..ddc91287b --- /dev/null +++ b/Modules/FindosgQt.cmake @@ -0,0 +1,52 @@ +# This is part of the Findosg* suite used to find OpenSceneGraph components. +# Each component is separate and you must opt in to each module. You must +# also opt into OpenGL and OpenThreads (and Producer if needed) as these +# modules won't do it for you. This is to allow you control over your own +# system piece by piece in case you need to opt out of certain components +# or change the Find behavior for a particular module (perhaps because the +# default FindOpenGL.cmake module doesn't work with your system as an +# example). +# If you want to use a more convenient module that includes everything, +# use the FindOpenSceneGraph.cmake instead of the Findosg*.cmake modules. +# +# Locate osgQt +# This module defines +# +# OSGQT_FOUND - Was osgQt found? +# OSGQT_INCLUDE_DIR - Where to find the headers +# OSGQT_LIBRARIES - The libraries to link for osgQt (use this) +# +# OSGQT_LIBRARY - The osgQt library +# OSGQT_LIBRARY_DEBUG - The osgQt debug library +# +# $OSGDIR is an environment variable that would +# correspond to the ./configure --prefix=$OSGDIR +# used in building osg. +# +# Created by Eric Wing. +# Modified to work with osgQt by Robert Osfield, January 2012. + +#============================================================================= +# Copyright 2007-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# Header files are presumed to be included like +# #include +# #include + +include(Findosg_functions) +OSG_FIND_PATH (OSGQT osgQt/GraphicsWindowQt) +OSG_FIND_LIBRARY(OSGQT osgQt) + +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(osgQt DEFAULT_MSG + OSGQT_LIBRARY OSGQT_INCLUDE_DIR) diff --git a/Modules/FindwxWidgets.cmake b/Modules/FindwxWidgets.cmake index 090259b0f..0bc617237 100644 --- a/Modules/FindwxWidgets.cmake +++ b/Modules/FindwxWidgets.cmake @@ -312,7 +312,7 @@ IF(wxWidgets_FIND_STYLE STREQUAL "win32") # Find wxWidgets multilib libraries. FOREACH(LIB core adv aui html media xrc dbgrid gl qa richtext - stc ribbon propgrid) + stc ribbon propgrid webview) FIND_LIBRARY(WX_${LIB}${_DBG} NAMES wxmsw${_UNV}29${_UCD}${_DBG}_${LIB} diff --git a/Modules/GNUInstallDirs.cmake b/Modules/GNUInstallDirs.cmake index a114dcb2e..0302e4bef 100644 --- a/Modules/GNUInstallDirs.cmake +++ b/Modules/GNUInstallDirs.cmake @@ -11,7 +11,7 @@ # SYSCONFDIR - read-only single-machine data (etc) # SHAREDSTATEDIR - modifiable architecture-independent data (com) # LOCALSTATEDIR - modifiable single-machine data (var) -# LIBDIR - object code libraries (lib or lib64) +# LIBDIR - object code libraries (lib or lib64 or lib/ on Debian) # INCLUDEDIR - C header files (include) # OLDINCLUDEDIR - C header files for non-gcc (/usr/include) # DATAROOTDIR - read-only architecture-independent data root (share) @@ -75,18 +75,24 @@ if(NOT DEFINED CMAKE_INSTALL_LIBDIR) # - we are NOT on debian # - we are on a 64 bits system # reason is: amd64 ABI: http://www.x86-64.org/documentation/abi.pdf - # Note that the future of multi-arch handling may be even - # more complicated than that: http://wiki.debian.org/Multiarch + # For Debian with multiarch, use 'lib/${CMAKE_LIBRARY_ARCHITECTURE}' if + # CMAKE_LIBRARY_ARCHITECTURE is set (which contains e.g. "i386-linux-gnu" + # See http://wiki.debian.org/Multiarch if(CMAKE_SYSTEM_NAME MATCHES "Linux" - AND NOT CMAKE_CROSSCOMPILING - AND NOT EXISTS "/etc/debian_version") - if(NOT DEFINED CMAKE_SIZEOF_VOID_P) - message(AUTHOR_WARNING - "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. " - "Please enable at least one language before including GNUInstallDirs.") - else() - if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(_LIBDIR_DEFAULT "lib64") + AND NOT CMAKE_CROSSCOMPILING) + if (EXISTS "/etc/debian_version") # is this a debian system ? + if(CMAKE_LIBRARY_ARCHITECTURE) + set(_LIBDIR_DEFAULT "lib/${CMAKE_LIBRARY_ARCHITECTURE}") + endif() + else() # not debian, rely on CMAKE_SIZEOF_VOID_P: + if(NOT DEFINED CMAKE_SIZEOF_VOID_P) + message(AUTHOR_WARNING + "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. " + "Please enable at least one language before including GNUInstallDirs.") + else() + if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") + set(_LIBDIR_DEFAULT "lib64") + endif() endif() endif() endif() diff --git a/Modules/GenerateExportHeader.cmake b/Modules/GenerateExportHeader.cmake index 7df274e4f..ce23d5d25 100644 --- a/Modules/GenerateExportHeader.cmake +++ b/Modules/GenerateExportHeader.cmake @@ -18,7 +18,7 @@ # [PREFIX_NAME ] # ) # -# ADD_COMPILER_EXPORT_FLAGS( [FATAL_WARNINGS] ) +# ADD_COMPILER_EXPORT_FLAGS( [] ) # # By default GENERATE_EXPORT_HEADER() generates macro names in a file name # determined by the name of the library. The ADD_COMPILER_EXPORT_FLAGS function @@ -149,46 +149,20 @@ include(CheckCXXCompilerFlag) macro(_check_cxx_compiler_attribute _ATTRIBUTE _RESULT) check_cxx_source_compiles("${_ATTRIBUTE} int somefunc() { return 0; } int main() { return somefunc();}" ${_RESULT} - # Some compilers do not fail with a bad flag - FAIL_REGEX "unrecognized .*option" # GNU - FAIL_REGEX "ignoring unknown option" # MSVC - FAIL_REGEX "warning D9002" # MSVC, any lang - FAIL_REGEX "[Uu]nknown option" # HP - FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro - FAIL_REGEX "command option .* is not recognized" # XL ) endmacro() macro(_test_compiler_hidden_visibility) - if(CMAKE_COMPILER_IS_GNUCXX) - exec_program(${CMAKE_C_COMPILER} ARGS --version - OUTPUT_VARIABLE _gcc_version_info) - string(REGEX MATCH "[345]\\.[0-9]\\.[0-9]" - _gcc_version "${_gcc_version_info}") - # gcc on mac just reports: "gcc (GCC) 3.3 20030304 ..." without the - # patch level, handle this here: - if(NOT _gcc_version) - string(REGEX REPLACE ".*\\(GCC\\).* ([34]\\.[0-9]) .*" "\\1.0" - _gcc_version "${_gcc_version_info}") - endif() - - if(${_gcc_version} VERSION_LESS "4.2") - set(GCC_TOO_OLD TRUE) - message(WARNING "GCC version older than 4.2") - endif() - endif() - - if(CMAKE_CXX_COMPILER_ID MATCHES Intel) - exec_program(${CMAKE_CXX_COMPILER} ARGS -V - OUTPUT_VARIABLE _intel_version_info) - string(REGEX REPLACE ".*Version ([0-9]+(\\.[0-9]+)+).*" "\\1" - _intel_version "${_intel_version_info}") - - if(${_intel_version} VERSION_LESS "12.0") - set(_INTEL_TOO_OLD TRUE) - message(WARNING "Intel compiler older than 12.0") - endif() + if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2") + set(GCC_TOO_OLD TRUE) + message(WARNING "GCC version older than 4.2") + elseif(CMAKE_COMPILER_IS_GNUC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.2") + set(GCC_TOO_OLD TRUE) + message(WARNING "GCC version older than 4.2") + elseif(CMAKE_CXX_COMPILER_ID MATCHES Intel AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0") + set(_INTEL_TOO_OLD TRUE) + message(WARNING "Intel compiler older than 12.0") endif() @@ -298,7 +272,7 @@ macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY) set(EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_EXPORT_MACRO_NAME}) endif() if(_GEH_EXPORT_FILE_NAME) - if(IS_ABSOLUTE _GEH_EXPORT_FILE_NAME) + if(IS_ABSOLUTE ${_GEH_EXPORT_FILE_NAME}) set(EXPORT_FILE_NAME ${_GEH_EXPORT_FILE_NAME}) else() set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${_GEH_EXPORT_FILE_NAME}") diff --git a/Modules/GetPrerequisites.cmake b/Modules/GetPrerequisites.cmake index 2efa07999..8761f400f 100644 --- a/Modules/GetPrerequisites.cmake +++ b/Modules/GetPrerequisites.cmake @@ -303,6 +303,26 @@ function(gp_resolve_item context item exepath dirs resolved_item_var) endif(item MATCHES "@loader_path") endif(NOT resolved) + if(NOT resolved) + if(item MATCHES "@rpath") + # + # @rpath references are relative to the paths built into the binaries with -rpath + # We handle this case like we do for other Unixes + # + string(REPLACE "@rpath/" "" norpath_item "${item}") + + set(ri "ri-NOTFOUND") + find_file(ri "${norpath_item}" ${exepath} ${dirs} NO_DEFAULT_PATH) + if(ri) + #message(STATUS "info: 'find_file' in exepath/dirs (${ri})") + set(resolved 1) + set(resolved_item "${ri}") + set(ri "ri-NOTFOUND") + endif(ri) + + endif(item MATCHES "@rpath") + endif(NOT resolved) + if(NOT resolved) set(ri "ri-NOTFOUND") find_file(ri "${item}" ${exepath} ${dirs} NO_DEFAULT_PATH) @@ -461,6 +481,15 @@ function(gp_resolved_file_type original_file file exepath dirs type_var) get_filename_component(path "${lower}" PATH) if("${original_path}" STREQUAL "${path}") set(is_local 1) + else() + string(LENGTH "${original_path}/" original_length) + string(LENGTH "${lower}" path_length) + if(${path_length} GREATER ${original_length}) + string(SUBSTRING "${lower}" 0 ${original_length} path) + if("${original_path}/" STREQUAL "${path}") + set(is_embedded 1) + endif() + endif() endif() endif() endif() diff --git a/Modules/NSIS.template.in b/Modules/NSIS.template.in index 6259a5bdf..819cc5cc0 100644 --- a/Modules/NSIS.template.in +++ b/Modules/NSIS.template.in @@ -922,12 +922,12 @@ Function .onInit Pop $0 UserInfo::GetAccountType Pop $1 - StrCmp $1 "Admin" 0 +3 + StrCmp $1 "Admin" 0 +4 SetShellVarContext all ;MessageBox MB_OK 'User "$0" is in the Admin group' StrCpy $SV_ALLUSERS "AllUsers" Goto done - StrCmp $1 "Power" 0 +3 + StrCmp $1 "Power" 0 +4 SetShellVarContext all ;MessageBox MB_OK 'User "$0" is in the Power Users group' StrCpy $SV_ALLUSERS "AllUsers" diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 867c788fa..f9d37c3af 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -6,6 +6,8 @@ SET(APPLE 1) # 8.x == Mac OSX 10.4 (Tiger) # 9.x == Mac OSX 10.5 (Leopard) # 10.x == Mac OSX 10.6 (Snow Leopard) +# 11.x == Mac OSX 10.7 (Lion) +# 12.x == Mac OSX 10.8 (Mountain Lion) STRING(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}") STRING(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}") @@ -54,24 +56,31 @@ SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a") # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex IF(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) FIND_PROGRAM(CMAKE_INSTALL_NAME_TOOL install_name_tool) + MARK_AS_ADVANCED(CMAKE_INSTALL_NAME_TOOL) ENDIF(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) # Set the assumed (Pre 10.5 or Default) location of the developer tools SET(OSX_DEVELOPER_ROOT "/Developer") +# Use the xcode-select tool if it's available (Xcode >= 3.0 installations) +FIND_PROGRAM(CMAKE_XCODE_SELECT xcode-select) +MARK_AS_ADVANCED(CMAKE_XCODE_SELECT) +IF(CMAKE_XCODE_SELECT) + EXECUTE_PROCESS(COMMAND ${CMAKE_XCODE_SELECT} "-print-path" + OUTPUT_VARIABLE OSX_DEVELOPER_ROOT + OUTPUT_STRIP_TRAILING_WHITESPACE) +ENDIF(CMAKE_XCODE_SELECT) + # Find installed SDKs -FILE(GLOB _CMAKE_OSX_SDKS "${OSX_DEVELOPER_ROOT}/SDKs/*") +# Start with Xcode-4.3+ default SDKs directory +SET(_CMAKE_OSX_SDKS_DIR + "${OSX_DEVELOPER_ROOT}/Platforms/MacOSX.platform/Developer/SDKs") +FILE(GLOB _CMAKE_OSX_SDKS "${_CMAKE_OSX_SDKS_DIR}/*") -# If nothing is found there, then try locating the dev tools based on the xcode-select tool -# (available in Xcode >= 3.0 installations) +# If not present, try pre-4.3 SDKs directory IF(NOT _CMAKE_OSX_SDKS) - FIND_PROGRAM(CMAKE_XCODE_SELECT xcode-select) - IF(CMAKE_XCODE_SELECT) - EXECUTE_PROCESS(COMMAND ${CMAKE_XCODE_SELECT} "-print-path" - OUTPUT_VARIABLE OSX_DEVELOPER_ROOT - OUTPUT_STRIP_TRAILING_WHITESPACE) - FILE(GLOB _CMAKE_OSX_SDKS "${OSX_DEVELOPER_ROOT}/SDKs/*") - ENDIF(CMAKE_XCODE_SELECT) +SET(_CMAKE_OSX_SDKS_DIR "${OSX_DEVELOPER_ROOT}/SDKs") + FILE(GLOB _CMAKE_OSX_SDKS "${_CMAKE_OSX_SDKS_DIR}/*") ENDIF(NOT _CMAKE_OSX_SDKS) EXECUTE_PROCESS(COMMAND sw_vers -productVersion @@ -103,16 +112,16 @@ SET(ENV_SDKROOT "$ENV{SDKROOT}") # Set CMAKE_OSX_SYSROOT_DEFAULT based on _CURRENT_OSX_VERSION, # accounting for the known specially named SDKs. SET(CMAKE_OSX_SYSROOT_DEFAULT - "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX${_CURRENT_OSX_VERSION}.sdk") + "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CURRENT_OSX_VERSION}.sdk") IF(_CURRENT_OSX_VERSION STREQUAL "10.4") SET(CMAKE_OSX_SYSROOT_DEFAULT - "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.4u.sdk") + "${_CMAKE_OSX_SDKS_DIR}/MacOSX10.4u.sdk") ENDIF(_CURRENT_OSX_VERSION STREQUAL "10.4") IF(_CURRENT_OSX_VERSION STREQUAL "10.3") SET(CMAKE_OSX_SYSROOT_DEFAULT - "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.3.9.sdk") + "${_CMAKE_OSX_SDKS_DIR}/MacOSX10.3.9.sdk") ENDIF(_CURRENT_OSX_VERSION STREQUAL "10.3") # Use environment or default as initial cache value: @@ -232,10 +241,22 @@ SET(CMAKE_SYSTEM_FRAMEWORK_PATH # default to searching for application bundles first SET(CMAKE_FIND_APPBUNDLE FIRST) # set up the default search directories for application bundles +SET(_apps_paths) +FOREACH(_path + "~/Applications" + "/Applications" + "${OSX_DEVELOPER_ROOT}/../Applications" # Xcode 4.3+ + "${OSX_DEVELOPER_ROOT}/Applications" # pre-4.3 + ) + GET_FILENAME_COMPONENT(_apps "${_path}" ABSOLUTE) + IF(EXISTS "${_apps}") + LIST(APPEND _apps_paths "${_apps}") + ENDIF() +ENDFOREACH() +LIST(REMOVE_DUPLICATES _apps_paths) SET(CMAKE_SYSTEM_APPBUNDLE_PATH - ~/Applications - /Applications - /Developer/Applications) + ${_apps_paths}) +UNSET(_apps_paths) INCLUDE(Platform/UnixPaths) LIST(APPEND CMAKE_SYSTEM_PREFIX_PATH diff --git a/Modules/Platform/Windows-Borland-C.cmake b/Modules/Platform/Windows-Borland-C.cmake index ebb74a11e..e2f76aacb 100644 --- a/Modules/Platform/Windows-Borland-C.cmake +++ b/Modules/Platform/Windows-Borland-C.cmake @@ -1,2 +1 @@ -include(Platform/Windows-Borland) -__borland_language(C) +include(Platform/Windows-Embarcadero-C) diff --git a/Modules/Platform/Windows-Borland-CXX.cmake b/Modules/Platform/Windows-Borland-CXX.cmake index 1260c0e90..809490f95 100644 --- a/Modules/Platform/Windows-Borland-CXX.cmake +++ b/Modules/Platform/Windows-Borland-CXX.cmake @@ -1,2 +1 @@ -include(Platform/Windows-Borland) -__borland_language(CXX) +include(Platform/Windows-Embarcadero-CXX) diff --git a/Modules/Platform/Windows-Embarcadero-C.cmake b/Modules/Platform/Windows-Embarcadero-C.cmake new file mode 100644 index 000000000..607fd4ebe --- /dev/null +++ b/Modules/Platform/Windows-Embarcadero-C.cmake @@ -0,0 +1,3 @@ +set(_lang C) +include(Platform/Windows-Embarcadero) +__embarcadero_language(C) diff --git a/Modules/Platform/Windows-Embarcadero-CXX.cmake b/Modules/Platform/Windows-Embarcadero-CXX.cmake new file mode 100644 index 000000000..279a4def4 --- /dev/null +++ b/Modules/Platform/Windows-Embarcadero-CXX.cmake @@ -0,0 +1,3 @@ +set(_lang CXX) +include(Platform/Windows-Embarcadero) +__embarcadero_language(CXX) diff --git a/Modules/Platform/Windows-Borland.cmake b/Modules/Platform/Windows-Embarcadero.cmake similarity index 65% rename from Modules/Platform/Windows-Borland.cmake rename to Modules/Platform/Windows-Embarcadero.cmake index 5c402bd9f..87b3767cd 100644 --- a/Modules/Platform/Windows-Borland.cmake +++ b/Modules/Platform/Windows-Embarcadero.cmake @@ -1,6 +1,6 @@ #============================================================================= -# Copyright 2002-2009 Kitware, Inc. +# Copyright 2002-2012 Kitware, Inc. # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -13,26 +13,33 @@ # License text for the above reference.) # This module is shared by multiple languages; use include blocker. -if(__WINDOWS_BORLAND) +if(__WINDOWS_EMBARCADERO) return() endif() -set(__WINDOWS_BORLAND 1) +set(__WINDOWS_EMBARCADERO 1) SET(BORLAND 1) -# Borland target type flags (bcc32 -h -t): -# -tW GUI App (implies -U__CONSOLE__) -# -tWC Console App (implies -D__CONSOLE__=1) -# -tWD Build a DLL (implies -D__DLL__=1 -D_DLL=1) -# -tWM Enable threads (implies -D__MT__=1 -D_MT=1) -# -tWR Use DLL runtime (implies -D_RTLDLL, and '-tW' too!!) -# -# Notes: -# - The flags affect linking so we pass them to the linker. -# - The flags affect preprocessing so we pass them to the compiler. -# - Since '-tWR' implies '-tW' we use '-tWR -tW-' instead. -# - Since '-tW-' disables '-tWD' we use '-tWR -tW- -tWD' for DLLs. -set(_RTLDLL "-tWR -tW-") +if("${CMAKE_${_lang}_COMPILER_VERSION}" VERSION_LESS 6.30) + # Borland target type flags (bcc32 -h -t): + set(_tW "-tW") # -tW GUI App (implies -U__CONSOLE__) + set(_tC "-tWC") # -tWC Console App (implies -D__CONSOLE__=1) + set(_tD "-tWD") # -tWD Build a DLL (implies -D__DLL__=1 -D_DLL=1) + set(_tM "-tWM") # -tWM Enable threads (implies -D__MT__=1 -D_MT=1) + set(_tR "-tWR -tW-") # -tWR Use DLL runtime (implies -D_RTLDLL, and '-tW' too!!) + # Notes: + # - The flags affect linking so we pass them to the linker. + # - The flags affect preprocessing so we pass them to the compiler. + # - Since '-tWR' implies '-tW' we use '-tWR -tW-' instead. + # - Since '-tW-' disables '-tWD' we use '-tWR -tW- -tWD' for DLLs. +else() + set(EMBARCADERO 1) + set(_tC "-tC") # Target is a console application + set(_tD "-tD") # Target is a shared library + set(_tM "-tM") # Target is multi-threaded + set(_tR "-tR") # Target uses the dynamic RTL + set(_tW "-tW") # Target is a Windows application +endif() set(_COMPILE_C "-c") set(_COMPILE_CXX "-P -c") @@ -50,14 +57,14 @@ SET(CMAKE_FIND_LIBRARY_SUFFIXES "-bcc.lib" ".lib") SET (CMAKE_MANGLE_OBJECT_FILE_NAMES "ON") # extra flags for a win32 exe -SET(CMAKE_CREATE_WIN32_EXE "-tW" ) +SET(CMAKE_CREATE_WIN32_EXE "${_tW}" ) # extra flags for a console app -SET(CMAKE_CREATE_CONSOLE_EXE "-tWC" ) +SET(CMAKE_CREATE_CONSOLE_EXE "${_tC}" ) SET (CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel.") -SET (CMAKE_EXE_LINKER_FLAGS_INIT "-tWM -lS:10000000 -lSc:10000000 ") +SET (CMAKE_EXE_LINKER_FLAGS_INIT "${_tM} -lS:10000000 -lSc:10000000 ") SET (CMAKE_EXE_LINKER_FLAGS_DEBUG_INIT "-v") SET (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO_INIT "-v") SET (CMAKE_SHARED_LINKER_FLAGS_INIT ${CMAKE_EXE_LINKER_FLAGS_INIT}) @@ -67,18 +74,19 @@ SET (CMAKE_MODULE_LINKER_FLAGS_INIT ${CMAKE_SHARED_LINKER_FLAGS_INIT}) SET (CMAKE_MODULE_LINKER_FLAGS_DEBUG_INIT ${CMAKE_SHARED_LINKER_FLAGS_DEBUG_INIT}) SET (CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO_INIT ${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO_INIT}) -macro(__borland_language lang) - set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-tWD") + +macro(__embarcadero_language lang) + set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "${_tD}") # compile a source file into an object file # place outside the response file because Borland refuses # to parse quotes from the response file. set(CMAKE_${lang}_COMPILE_OBJECT - " ${_RTLDLL} ${CMAKE_START_TEMP_FILE}-DWIN32 -o ${_COMPILE_${lang}} ${CMAKE_END_TEMP_FILE}" + " ${_tR} ${CMAKE_START_TEMP_FILE}-DWIN32 -o ${_COMPILE_${lang}} ${CMAKE_END_TEMP_FILE}" ) set(CMAKE_${lang}_LINK_EXECUTABLE - " ${_RTLDLL} -e ${CMAKE_START_TEMP_FILE} ${CMAKE_END_TEMP_FILE}" + " ${_tR} -e ${CMAKE_START_TEMP_FILE} ${CMAKE_END_TEMP_FILE}" # "implib -c -w " ) @@ -91,7 +99,7 @@ macro(__borland_language lang) # Create a module library. set(CMAKE_${lang}_CREATE_SHARED_MODULE - " ${_RTLDLL} -tWD ${CMAKE_START_TEMP_FILE}-e ${CMAKE_END_TEMP_FILE}" + " ${_tR} ${_tD} ${CMAKE_START_TEMP_FILE}-e ${CMAKE_END_TEMP_FILE}" ) # Create an import library for another target. @@ -112,7 +120,7 @@ macro(__borland_language lang) ) # Initial configuration flags. - set(CMAKE_${lang}_FLAGS_INIT "-tWM") + set(CMAKE_${lang}_FLAGS_INIT "${_tM}") set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-Od -v") set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-O1 -DNDEBUG") set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O2 -DNDEBUG") diff --git a/Modules/Platform/Windows-Intel-Fortran.cmake b/Modules/Platform/Windows-Intel-Fortran.cmake index c959287cd..5c016a8fd 100644 --- a/Modules/Platform/Windows-Intel-Fortran.cmake +++ b/Modules/Platform/Windows-Intel-Fortran.cmake @@ -6,6 +6,6 @@ set(CMAKE_Fortran_STANDARD_LIBRARIES_INIT "user32.lib") __windows_compiler_intel(Fortran) SET (CMAKE_Fortran_FLAGS_INIT "/W1 /nologo /fpp /libs:dll /threads") SET (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full /dbglibs") -SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O2 /D NDEBUG") -SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "/O1 /D NDEBUG") -SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O1 /debug:full /D NDEBUG") +SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O1 /D NDEBUG") +SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "/O2 /D NDEBUG") +SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O2 /debug:full /D NDEBUG") diff --git a/Modules/Platform/Windows-cl.cmake b/Modules/Platform/Windows-cl.cmake index ccccbc926..be6abb690 100644 --- a/Modules/Platform/Windows-cl.cmake +++ b/Modules/Platform/Windows-cl.cmake @@ -37,7 +37,7 @@ SET(CMAKE_COMPILE_RESOURCE "rc /fo ") # that is automatically copied into try_compile directories # by the global generator. SET(MSVC_IDE 1) -IF(CMAKE_GENERATOR MATCHES "Makefiles") +IF(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja") SET(MSVC_IDE 0) IF(NOT CMAKE_VC_COMPILER_TESTS_RUN) SET(CMAKE_VC_COMPILER_TESTS 1) @@ -125,7 +125,7 @@ IF(CMAKE_GENERATOR MATCHES "Makefiles") ENDIF(CMAKE_COMPILER_RETURN) MAKE_DIRECTORY("${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp3") ENDIF(NOT CMAKE_VC_COMPILER_TESTS_RUN) -ENDIF(CMAKE_GENERATOR MATCHES "Makefiles") +ENDIF(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja") IF(MSVC_C_ARCHITECTURE_ID MATCHES 64) SET(CMAKE_CL_64 1) diff --git a/Modules/Platform/eCos.cmake b/Modules/Platform/eCos.cmake index f0881c0bb..b437c1a9b 100644 --- a/Modules/Platform/eCos.cmake +++ b/Modules/Platform/eCos.cmake @@ -1,5 +1,12 @@ # support for eCos http://ecos.sourceware.org -SET(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic + +# Guard against multiple inclusion, which e.g. leads to multiple calls to add_definition() #12987 +IF(__ECOS_CMAKE_INCLUDED) + RETURN() +ENDIF() +SET(__ECOS_CMAKE_INCLUDED TRUE) + +SET(CMAKE_SHARED_LIBRARY_C_FLAGS "") # -pic SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "") # -shared SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # +s, flag for exe link to use shared lib SET(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "") # -rpath diff --git a/Modules/Qt4Macros.cmake b/Modules/Qt4Macros.cmake index 4da1a3fb4..f327125b2 100644 --- a/Modules/Qt4Macros.cmake +++ b/Modules/Qt4Macros.cmake @@ -393,7 +393,13 @@ MACRO(QT4_CREATE_TRANSLATION _qm_files) FOREACH(_pro_src ${_my_sources}) SET(_pro_srcs "${_pro_srcs} \"${_pro_src}\"") ENDFOREACH(_pro_src ${_my_sources}) - FILE(WRITE ${_ts_pro} "SOURCES = ${_pro_srcs}") + SET(_pro_includes) + GET_DIRECTORY_PROPERTY(_inc_DIRS INCLUDE_DIRECTORIES) + FOREACH(_pro_include ${_inc_DIRS}) + GET_FILENAME_COMPONENT(_abs_include "${_pro_include}" ABSOLUTE) + SET(_pro_includes "${_pro_includes} \"${_abs_include}\"") + ENDFOREACH(_pro_include ${CMAKE_CXX_INCLUDE_PATH}) + FILE(WRITE ${_ts_pro} "SOURCES = ${_pro_srcs}\nINCLUDEPATH = ${_pro_includes}\n") ENDIF(_my_sources) ADD_CUSTOM_COMMAND(OUTPUT ${_ts_file} COMMAND ${QT_LUPDATE_EXECUTABLE} diff --git a/Modules/SelectLibraryConfigurations.cmake b/Modules/SelectLibraryConfigurations.cmake index 51b4dda06..2e8ade0df 100644 --- a/Modules/SelectLibraryConfigurations.cmake +++ b/Modules/SelectLibraryConfigurations.cmake @@ -15,7 +15,6 @@ # basename_LIBRARY and basename_LIBRARIES will take only the release values. #============================================================================= -# Copyright 2009 Kitware, Inc. # Copyright 2009 Will Dicharry # Copyright 2005-2009 Kitware, Inc. # @@ -49,7 +48,8 @@ macro( select_library_configurations basename ) # if only the debug version was found, set the release value to be the # debug value. _set_library_name( ${basename} DEBUG RELEASE ) - if (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE ) + if (${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE) # if the generator supports configuration types or CMAKE_BUILD_TYPE # is set, then set optimized and debug options. if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) @@ -65,7 +65,7 @@ macro( select_library_configurations basename ) set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) set( ${basename}_LIBRARIES ${${basename}_LIBRARY_RELEASE} ) endif( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE ) - endif( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE ) + endif() set( ${basename}_LIBRARY ${${basename}_LIBRARY} CACHE FILEPATH "The ${basename} library" ) @@ -79,4 +79,3 @@ macro( select_library_configurations basename ) ${basename}_LIBRARY_DEBUG ) endmacro( select_library_configurations ) - diff --git a/Modules/UseJava.cmake b/Modules/UseJava.cmake index b78278c71..84d0afdf2 100644 --- a/Modules/UseJava.cmake +++ b/Modules/UseJava.cmake @@ -25,6 +25,15 @@ # set(CMAKE_JAVA_TARGET_OUTPUT_NAME shibboleet.jar) # add_jar(foobar foobar.java) # +# To use a different output directory than CMAKE_CURRENT_BINARY_DIR +# you can set it with: +# +# set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${PROJECT_BINARY_DIR}/bin) +# +# To define an entry point in your jar you can set it with: +# +# set(CMAKE_JAVA_JAR_ENTRY_POINT com/examples/MyProject/Main) +# # To add a VERSION to the target output name you can set it using # CMAKE_JAVA_TARGET_VERSION. This will create a jar file with the name # shibboleet-1.0.0.jar and will create a symlink shibboleet.jar @@ -112,7 +121,7 @@ # [VERSION TRUE|FALSE] # ) # -# Create jave documentation based on files or packages. For more +# Create java documentation based on files or packages. For more # details please read the javadoc manpage. # # There are two main signatures for create_javadoc. The first @@ -198,10 +207,19 @@ set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake) function(add_jar _TARGET_NAME) set(_JAVA_SOURCE_FILES ${ARGN}) + if (NOT DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR) + set(CMAKE_JAVA_TARGET_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif(NOT DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR) + + if (CMAKE_JAVA_JAR_ENTRY_POINT) + set(_ENTRY_POINT_OPTION e) + set(_ENTRY_POINT_VALUE ${CMAKE_JAVA_JAR_ENTRY_POINT}) + endif (CMAKE_JAVA_JAR_ENTRY_POINT) + if (LIBRARY_OUTPUT_PATH) set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH}) else (LIBRARY_OUTPUT_PATH) - set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) + set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${CMAKE_JAVA_TARGET_OUTPUT_DIR}) endif (LIBRARY_OUTPUT_PATH) set(CMAKE_JAVA_INCLUDE_PATH @@ -221,7 +239,7 @@ function(add_jar _TARGET_NAME) set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}") endforeach(JAVA_INCLUDE_DIR) - set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir") + set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_JAVA_TARGET_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir") set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar") if (CMAKE_JAVA_TARGET_OUTPUT_NAME AND CMAKE_JAVA_TARGET_VERSION) @@ -246,7 +264,7 @@ function(add_jar _TARGET_NAME) get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH) get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE) - file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_CURRENT_BINARY_DIR} ${_JAVA_FULL}) + file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${CMAKE_JAVA_TARGET_OUTPUT_DIR} ${_JAVA_FULL}) file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL}) string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN) string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN) @@ -312,20 +330,22 @@ function(add_jar _TARGET_NAME) endif (_JAVA_COMPILE_FILES) # create the jar file + set(_JAVA_JAR_OUTPUT_PATH + ${CMAKE_JAVA_TARGET_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME}) if (CMAKE_JNI_TARGET) add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + OUTPUT ${_JAVA_JAR_OUTPUT_PATH} COMMAND ${Java_JAR_EXECUTABLE} - -cf ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + -cf${_ENTRY_POINT_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_JAVA_RESOURCE_FILES} @java_class_filelist COMMAND ${CMAKE_COMMAND} - -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} + -D_JAVA_TARGET_DIR=${CMAKE_JAVA_TARGET_OUTPUT_DIR} -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} -P ${_JAVA_SYMLINK_SCRIPT} COMMAND ${CMAKE_COMMAND} - -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} - -D_JAVA_TARGET_OUTPUT_NAME=${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + -D_JAVA_TARGET_DIR=${CMAKE_JAVA_TARGET_OUTPUT_DIR} + -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH} -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} -P ${_JAVA_SYMLINK_SCRIPT} DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist @@ -334,12 +354,12 @@ function(add_jar _TARGET_NAME) ) else () add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + OUTPUT ${_JAVA_JAR_OUTPUT_PATH} COMMAND ${Java_JAR_EXECUTABLE} - -cf ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + -cf${_ENTRY_POINT_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_JAVA_RESOURCE_FILES} @java_class_filelist COMMAND ${CMAKE_COMMAND} - -D_JAVA_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR} + -D_JAVA_TARGET_DIR=${CMAKE_JAVA_TARGET_OUTPUT_DIR} -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME} -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK} -P ${_JAVA_SYMLINK_SCRIPT} @@ -350,14 +370,14 @@ function(add_jar _TARGET_NAME) endif (CMAKE_JNI_TARGET) # Add the target and make sure we have the latest resource files. - add_custom_target(${_TARGET_NAME} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME}) + add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH}) set_property( TARGET ${_TARGET_NAME} PROPERTY INSTALL_FILES - ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + ${_JAVA_JAR_OUTPUT_PATH} ) if (_JAVA_TARGET_OUTPUT_LINK) @@ -366,8 +386,8 @@ function(add_jar _TARGET_NAME) ${_TARGET_NAME} PROPERTY INSTALL_FILES - ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} - ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + ${_JAVA_JAR_OUTPUT_PATH} + ${CMAKE_JAVA_TARGET_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK} ) if (CMAKE_JNI_TARGET) @@ -376,7 +396,7 @@ function(add_jar _TARGET_NAME) ${_TARGET_NAME} PROPERTY JNI_SYMLINK - ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_LINK} + ${CMAKE_JAVA_TARGET_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK} ) endif (CMAKE_JNI_TARGET) endif (_JAVA_TARGET_OUTPUT_LINK) @@ -386,7 +406,7 @@ function(add_jar _TARGET_NAME) ${_TARGET_NAME} PROPERTY JAR_FILE - ${CMAKE_CURRENT_BINARY_DIR}/${_JAVA_TARGET_OUTPUT_NAME} + ${_JAVA_JAR_OUTPUT_PATH} ) set_property( diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 2a83045c2..ef7672440 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -47,20 +47,17 @@ MACRO(SWIG_MODULE_INITIALIZE name language) SET(SWIG_MODULE_${name}_LANGUAGE "${swig_uppercase_language}") SET(SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${swig_lowercase_language}") - IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$") - MESSAGE(FATAL_ERROR "SWIG Error: Language \"${language}\" not found") - ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xUNKNOWNx$") - SET(SWIG_MODULE_${name}_REAL_NAME "${name}") - IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$") + IF("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "UNKNOWN") + MESSAGE(FATAL_ERROR "SWIG Error: Language \"${language}\" not found") + ELSEIF("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "PYTHON") # when swig is used without the -interface it will produce in the module.py # a 'import _modulename' statement, which implies having a corresponding # _modulename.so (*NIX), _modulename.pyd (Win32). SET(SWIG_MODULE_${name}_REAL_NAME "_${name}") - ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPYTHONx$") - IF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$") + ELSEIF("${SWIG_MODULE_${name}_LANGUAGE}" STREQUAL "PERL") SET(SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow") - ENDIF("x${SWIG_MODULE_${name}_LANGUAGE}x" MATCHES "^xPERLx$") + ENDIF() ENDMACRO(SWIG_MODULE_INITIALIZE) # diff --git a/Modules/WriteBasicConfigVersionFile.cmake b/Modules/WriteBasicConfigVersionFile.cmake index 0b6519d41..038cb5798 100644 --- a/Modules/WriteBasicConfigVersionFile.cmake +++ b/Modules/WriteBasicConfigVersionFile.cmake @@ -1,31 +1,6 @@ # WRITE_BASIC_CONFIG_VERSION_FILE( filename VERSION major.minor.patch COMPATIBILITY (AnyNewerVersion|SameMajorVersion) ) # -# Writes a file for use as ConfigVersion.cmake file to . -# See the documentation of FIND_PACKAGE() for details on this. -# filename is the output filename, it should be in the build tree. -# major.minor.patch is the version number of the project to be installed -# The COMPATIBILITY mode AnyNewerVersion means that the installed package version -# will be considered compatible if it is newer or exactly the same as the requested version. -# If SameMajorVersion is used instead, then the behaviour differs from AnyNewerVersion -# in that the major version number must be the same as requested, e.g. version 2.0 will -# not be considered compatible if 1.0 is requested. -# If your project has more elaborated version matching rules, you will need to write your -# own custom ConfigVersion.cmake file instead of using this macro. -# -# Example: -# write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake -# VERSION 1.2.3 -# COMPATIBILITY SameMajorVersion ) -# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FooConfigVersion.cmake -# ${CMAKE_CURRENT_BINARY_DIR}/FooConfig.cmake -# DESTINATION lib/cmake/Foo ) -# -# Internally, this macro executes configure_file() to create the resulting -# version file. Depending on the COMPATIBLITY, either the file -# BasicConfigVersion-SameMajorVersion.cmake.in or BasicConfigVersion-AnyNewerVersion.cmake.in -# is used. Please note that these two files are internal to CMake and you should -# not call configure_file() on them yourself, but they can be used as starting -# point to create more sophisticted custom ConfigVersion.cmake files. +# Deprecated, see WRITE_BASIC_PACKAGE_VERSION_FILE(), it is identical. #============================================================================= # Copyright 2008-2011 Alexander Neundorf, diff --git a/Modules/readme.txt b/Modules/readme.txt index e2d7f0674..7d61d8d27 100644 --- a/Modules/readme.txt +++ b/Modules/readme.txt @@ -57,7 +57,7 @@ For example: # - This is a cool module # This module does really cool stuff. # It can do even more than you think. -# +# # It even needs to paragraphs to tell you about it. # And it defines the following variables: # VAR_COOL - this is great isn't it? @@ -119,17 +119,31 @@ able to find the package. If the REQUIRED option is given to the command it will set the variable XXX_FIND_REQUIRED to true before loading the FindXXX.cmake module. If this variable is set the module should issue a FATAL_ERROR if the -package cannot be found. For each package-specific component, say -YYY, listed after the REQUIRED option a variable XXX_FIND_REQUIRED_YYY -to true. The set of components listed after either the REQUIRED -option or the COMPONENTS option will be specified in a -XXX_FIND_COMPONENTS variable. This can be used by the FindXXX.cmake -module to determine which sub-components of the package must be found. +package cannot be found. If neither the QUIET nor REQUIRED options are given then the FindXXX.cmake module should look for the package and complain without error if the module is not found. -To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS() +A package can be provide sub-components. +Those components can be listed after the COMPONENTS (or REQUIRED) +or OPTIONAL_COMPONENTS keywords. The set of all listed components will be +specified in a XXX_FIND_COMPONENTS variable. +For each package-specific component, say Yyy, a variable XXX_FIND_REQUIRED_Yyy +will be set to true if it listed after COMPONENTS and it will be set to false +if it was listed after OPTIONAL_COMPONENTS. +Using those variables a FindXXX.cmake module and also a XXXConfig.cmake package +configuration file can determine whether and which components have been requested, +and whether they were requested as required or as optional. +For each of the requested components a XXX_Yyy_FOUND variable should be set +accordingly. +The per-package XXX_FOUND variable should be only set to true if all requested +required components have been found. A missing optional component should not +keep the XXX_FOUND variable from being set to true. +If the package provides XXX_INCLUDE_DIRS and XXX_LIBRARIES variables, the include +dirs and libraries for all components which were requested and which have been +found should be added to those two variables. + +To get this behaviour you can use the FIND_PACKAGE_HANDLE_STANDARD_ARGS() macro, as an example see FindJPEG.cmake. For internal implementation, it's a generally accepted convention that variables starting with diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index b5115b78b..f9d1c0359 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -185,6 +185,8 @@ SET(SRCS cmGeneratedFileStream.cxx cmGeneratorExpression.cxx cmGeneratorExpression.h + cmGeneratorTarget.cxx + cmGeneratorTarget.h cmGlobalGenerator.cxx cmGlobalGenerator.h cmGlobalUnixMakefileGenerator3.cxx @@ -353,6 +355,36 @@ IF (WIN32) ENDIF(NOT UNIX) ENDIF (WIN32) +# turn on Ninja by default +set(_CMAKE_DEFAULT_NINJA_VALUE TRUE) +# turn it off for platforms where it does not pass all the +# tests +if(WIN32 OR APPLE) + SET(_CMAKE_DEFAULT_NINJA_VALUE FALSE) +endif() +SET(CMAKE_ENABLE_NINJA ${_CMAKE_DEFAULT_NINJA_VALUE} CACHE BOOL + "Enable the ninja generator for CMake. currently not fully working for Windows or OSX") +MARK_AS_ADVANCED(CMAKE_ENABLE_NINJA) +IF(CMAKE_ENABLE_NINJA) + MESSAGE(STATUS "Enable ninja generator.") + SET(SRCS ${SRCS} + cmGlobalNinjaGenerator.cxx + cmGlobalNinjaGenerator.h + cmNinjaTypes.h + cmLocalNinjaGenerator.cxx + cmLocalNinjaGenerator.h + cmNinjaTargetGenerator.cxx + cmNinjaTargetGenerator.h + cmNinjaNormalTargetGenerator.cxx + cmNinjaNormalTargetGenerator.h + cmNinjaUtilityTargetGenerator.cxx + cmNinjaUtilityTargetGenerator.h + ) + ADD_DEFINITIONS(-DCMAKE_USE_NINJA) +ELSE() + MESSAGE(STATUS "Disable ninja generator.") +ENDIF() + # create a library used by the command line and the GUI ADD_LIBRARY(CMakeLib ${SRCS}) TARGET_LINK_LIBRARIES(CMakeLib cmsys @@ -449,6 +481,8 @@ SET(CPACK_SRCS CPack/cmCPackTarBZip2Generator.cxx CPack/cmCPackTarCompressGenerator.cxx CPack/cmCPackZIPGenerator.cxx + CPack/cmCPackDocumentVariables.cxx + CPack/cmCPackDocumentMacros.cxx ) IF(CYGWIN) diff --git a/Source/CPack/cmCPackArchiveGenerator.cxx b/Source/CPack/cmCPackArchiveGenerator.cxx index 0ce5b0126..6e7b8d7c8 100644 --- a/Source/CPack/cmCPackArchiveGenerator.cxx +++ b/Source/CPack/cmCPackArchiveGenerator.cxx @@ -57,13 +57,20 @@ int cmCPackArchiveGenerator::addOneComponentToArchive(cmArchiveWrite& archive, std::string dir = cmSystemTools::GetCurrentWorkingDirectory(); // Change to local toplevel cmSystemTools::ChangeDirectory(localToplevel.c_str()); + std::string filePrefix; + if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) + { + filePrefix = this->GetOption("CPACK_PACKAGE_FILE_NAME"); + filePrefix += "/"; + } std::vector::const_iterator fileIt; for (fileIt = component->Files.begin(); fileIt != component->Files.end(); ++fileIt ) { + std::string rp = filePrefix + *fileIt; cmCPackLogger(cmCPackLog::LOG_DEBUG,"Adding file: " - << (*fileIt) << std::endl); - archive.Add(*fileIt); + << rp << std::endl); + archive.Add(rp); if (!archive) { cmCPackLogger(cmCPackLog::LOG_ERROR, "ERROR while packaging files: " @@ -240,7 +247,7 @@ int cmCPackArchiveGenerator::PackageFiles() cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl); - if (SupportsComponentInstallation()) { + if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index b707e96aa..178a18d2f 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -236,7 +236,7 @@ int cmCPackDebGenerator::PackageFiles() int retval = -1; /* Are we in the component packaging case */ - if (SupportsComponentInstallation()) { + if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL GROUPS or ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. diff --git a/Source/CPack/cmCPackDocumentMacros.cxx b/Source/CPack/cmCPackDocumentMacros.cxx new file mode 100644 index 000000000..ddc75a4b4 --- /dev/null +++ b/Source/CPack/cmCPackDocumentMacros.cxx @@ -0,0 +1,16 @@ +#include "cmCPackDocumentMacros.h" + +void cmCPackDocumentMacros::GetMacrosDocumentation( + std::vector& ) +{ + // Commented-out example of use + // + // cmDocumentationEntry e("cpack_", + // "Brief Description" + // "which may be on several lines.", + // "Long description in pre-formatted format" + // " blah\n" + // " blah\n" + //); + //v.push_back(e); +} diff --git a/Source/CPack/cmCPackDocumentMacros.h b/Source/CPack/cmCPackDocumentMacros.h new file mode 100644 index 000000000..544f74f5f --- /dev/null +++ b/Source/CPack/cmCPackDocumentMacros.h @@ -0,0 +1,21 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmCPackDocumentMacros_h +#define cmCPackDocumentMacros_h +#include "cmStandardIncludes.h" +class cmCPackDocumentMacros +{ +public: + static void GetMacrosDocumentation(std::vector& v); +}; + +#endif diff --git a/Source/CPack/cmCPackDocumentVariables.cxx b/Source/CPack/cmCPackDocumentVariables.cxx new file mode 100644 index 000000000..d2e3802c6 --- /dev/null +++ b/Source/CPack/cmCPackDocumentVariables.cxx @@ -0,0 +1,80 @@ +#include "cmCPackDocumentVariables.h" +#include "cmake.h" + +void cmCPackDocumentVariables::DefineVariables(cmake* cm) +{ + // Subsection: variables defined/used by cpack, + // which are common to all CPack generators + + cm->DefineProperty + ("CPACK_PACKAGING_INSTALL_PREFIX", cmProperty::VARIABLE, + "The prefix used in the built package.", + "Each CPack generator has a default value (like /usr)." + " This default value may" + " be overwritten from the CMakeLists.txt or the cpack command line" + " by setting an alternative value.\n" + "e.g. " + " set(CPACK_PACKAGING_INSTALL_PREFIX \"/opt\")\n" + "This is not the same purpose as CMAKE_INSTALL_PREFIX which" + " is used when installing from the build tree without building" + " a package." + "", false, + "Variables common to all CPack generators"); + + cm->DefineProperty + ("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", cmProperty::VARIABLE, + "Boolean toggle to include/exclude top level directory.", + "When preparing a package CPack installs the item under" + " the so-called top level directory. The purpose of" + " is to include (set to 1 or ON or TRUE) the top level directory" + " in the package or not (set to 0 or OFF or FALSE).\n" + "Each CPack generator as a built-in default value for this" + " variable. E.g. Archive generators (ZIP, TGZ, ...) includes" + " the top level whereas RPM or DEB don't. The user may override" + " the default value byt setting this variable.\n" + "There is a similar variable " + "CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY" + "which may be used to override the behavior for the component" + "packaging case which may have different default value for" + "historical (now backward compatibility) reason.", false, + "Variables common to all CPack generators"); + + cm->DefineProperty + ("CPACK_SET_DESTDIR", cmProperty::VARIABLE, + "Boolean toggle to make CPack use DESTDIR mechanism when" + " packaging.", "DESTDIR means DESTination DIRectory." + " It is commonly used by makefile " + "users in order to install software at non-default location. It " + "is a basic relocation mechanism. " + "It is usually invoked like this:\n" + " make DESTDIR=/home/john install\n" + "which will install the concerned software using the" + " installation prefix, e.g. \"/usr/local\" prepended with " + "the DESTDIR value which finally gives \"/home/john/usr/local\"." + " When preparing a package, CPack first installs the items to be " + "packaged in a local (to the build tree) directory by using the " + "same DESTDIR mechanism. Nevertheless, if " + "CPACK_SET_DESTDIR is set then CPack will set DESTDIR before" + " doing the local install. The most noticeable difference is" + " that without CPACK_SET_DESTDIR, CPack uses " + "CPACK_PACKAGING_INSTALL_PREFIX as a prefix whereas with " + "CPACK_SET_DESTDIR set, CPack will use CMAKE_INSTALL_PREFIX as" + " a prefix.\n" + "Manually setting CPACK_SET_DESTDIR may help (or simply be" + " necessary) if some install rules uses absolute " + "DESTINATION (see CMake INSTALL command)." + " However, starting with" + " CPack/CMake 2.8.3 RPM and DEB installers tries to handle DESTDIR" + " automatically so that it is seldom necessary for the user to set" + " it.", false, + "Variables common to all CPack generators"); + + cm->DefineProperty + ("CPACK_INSTALL_SCRIPT", cmProperty::VARIABLE, + "Extra CMake script provided by the user.", + "If set this CMake script will be executed by CPack " + "during its local [CPack-private] installation " + "which is done right before packaging the files." + " The script is not called by e.g.: make install.", false, + "Variables common to all CPack generators"); +} diff --git a/Source/CPack/cmCPackDocumentVariables.h b/Source/CPack/cmCPackDocumentVariables.h new file mode 100644 index 000000000..e7971be13 --- /dev/null +++ b/Source/CPack/cmCPackDocumentVariables.h @@ -0,0 +1,21 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2009 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmCPackDocumentVariables_h +#define cmCPackDocumentVariables_h +class cmake; +class cmCPackDocumentVariables +{ +public: + static void DefineVariables(cmake* cm); +}; + +#endif diff --git a/Source/CPack/cmCPackDragNDropGenerator.cxx b/Source/CPack/cmCPackDragNDropGenerator.cxx index 83b6b64d4..6aee401ff 100644 --- a/Source/CPack/cmCPackDragNDropGenerator.cxx +++ b/Source/CPack/cmCPackDragNDropGenerator.cxx @@ -63,6 +63,12 @@ cmCPackDragNDropGenerator::~cmCPackDragNDropGenerator() //---------------------------------------------------------------------- int cmCPackDragNDropGenerator::InitializeInternal() { + // Starting with Xcode 4.3, look in "/Applications/Xcode.app" first: + // + std::vector paths; + paths.push_back("/Applications/Xcode.app/Contents/Developer/Tools"); + paths.push_back("/Developer/Tools"); + const std::string hdiutil_path = cmSystemTools::FindProgram("hdiutil", std::vector(), false); if(hdiutil_path.empty()) @@ -75,7 +81,7 @@ int cmCPackDragNDropGenerator::InitializeInternal() this->SetOptionIfNotSet("CPACK_COMMAND_HDIUTIL", hdiutil_path.c_str()); const std::string setfile_path = cmSystemTools::FindProgram("SetFile", - std::vector(1, "/Developer/Tools"), false); + paths, false); if(setfile_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -86,7 +92,7 @@ int cmCPackDragNDropGenerator::InitializeInternal() this->SetOptionIfNotSet("CPACK_COMMAND_SETFILE", setfile_path.c_str()); const std::string rez_path = cmSystemTools::FindProgram("Rez", - std::vector(1, "/Developer/Tools"), false); + paths, false); if(rez_path.empty()) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -421,6 +427,7 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, if(ifs.is_open()) { cmGeneratedFileStream osf(sla_r.c_str()); + osf << "#include \n\n"; osf << SLAHeader; osf << "\n"; osf << "data 'TEXT' (5002, \"English\") {\n"; @@ -481,13 +488,11 @@ int cmCPackDragNDropGenerator::CreateDMG(const std::string& src_dir, // Rez the SLA cmOStringStream embed_sla_command; - embed_sla_command << "/bin/bash -c \""; // need expansion of "*.r" embed_sla_command << this->GetOption("CPACK_COMMAND_REZ"); - embed_sla_command << " /Developer/Headers/FlatCarbon/*.r "; - embed_sla_command << "'" << sla_r << "'"; + embed_sla_command << " \"" << sla_r << "\""; embed_sla_command << " -a -o "; - embed_sla_command << "'" << temp_udco << "'\""; - + embed_sla_command << "\"" << temp_udco << "\""; + if(!this->RunCommand(embed_sla_command, &error)) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackGenerator.cxx b/Source/CPack/cmCPackGenerator.cxx index 083279fdd..0f832b395 100644 --- a/Source/CPack/cmCPackGenerator.cxx +++ b/Source/CPack/cmCPackGenerator.cxx @@ -691,6 +691,11 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects( // one install directory for each component. tempInstallDirectory += GetComponentInstallDirNameSuffix(installComponent); + if (this->IsOn("CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY")) + { + tempInstallDirectory += "/"; + tempInstallDirectory += this->GetOption("CPACK_PACKAGE_FILE_NAME"); + } } if (!setDestDir) @@ -1431,6 +1436,12 @@ bool cmCPackGenerator::SupportsComponentInstallation() const return false; } +//---------------------------------------------------------------------- +bool cmCPackGenerator::WantsComponentInstallation() const +{ + return (!IsOn("CPACK_MONOLITHIC_INSTALL") & SupportsComponentInstallation()); +} + //---------------------------------------------------------------------- cmCPackInstallationType* cmCPackGenerator::GetInstallationType(const char *projectName, diff --git a/Source/CPack/cmCPackGenerator.h b/Source/CPack/cmCPackGenerator.h index 52def9da7..55afb4489 100644 --- a/Source/CPack/cmCPackGenerator.h +++ b/Source/CPack/cmCPackGenerator.h @@ -189,7 +189,21 @@ protected: virtual int InstallProjectViaInstallCMakeProjects( bool setDestDir, const char* tempInstallDirectory); + /** + * Does the CPack generator support component installation?. + * Some Generators requires the user to set + * CPACK__COMPONENT_INSTALL in order to make this + * method return true. + * @return true if supported, false otherwise + */ virtual bool SupportsComponentInstallation() const; + /** + * Does the currently running generator want a component installation. + * The generator may support component installation but he may + * be requiring monolithic install using CPACK_MONOLITHIC_INSTALL. + * @return true if component installation is supported and wanted. + */ + virtual bool WantsComponentInstallation() const; virtual cmCPackInstallationType* GetInstallationType(const char *projectName, const char* name); virtual cmCPackComponent* GetComponent(const char *projectName, diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index 2b940673b..0787ef901 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -344,9 +344,9 @@ int cmCPackNSISGenerator::InitializeInternal() if ( cmSystemTools::IsOn(this->GetOption( "CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) ) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. " - "This option will be ignored." + cmCPackLogger(cmCPackLog::LOG_WARNING, + "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY set. " + "This option will be reset to 0 (for this generator only)." << std::endl); this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0); } diff --git a/Source/CPack/cmCPackOSXX11Generator.cxx b/Source/CPack/cmCPackOSXX11Generator.cxx index 75ad640c0..363ccea0c 100644 --- a/Source/CPack/cmCPackOSXX11Generator.cxx +++ b/Source/CPack/cmCPackOSXX11Generator.cxx @@ -170,23 +170,25 @@ int cmCPackOSXX11Generator::PackageFiles() << "\" create -ov -format UDZO -srcfolder \"" << diskImageDirectory.c_str() << "\" \"" << packageFileNames[0] << "\""; - int retVal = 1; cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress disk image using command: " << dmgCmd.str().c_str() << std::endl); // since we get random dashboard failures with this one // try running it more than once - int numTries = 4; + int retVal = 1; + int numTries = 10; bool res = false; while(numTries > 0) { res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0); - if(res && retVal) + if ( res && !retVal ) { numTries = -1; + break; } + cmSystemTools::Delay(500); numTries--; } if ( !res || retVal ) diff --git a/Source/CPack/cmCPackPackageMakerGenerator.cxx b/Source/CPack/cmCPackPackageMakerGenerator.cxx index 0c4b1a6f9..3a0e89bbd 100644 --- a/Source/CPack/cmCPackPackageMakerGenerator.cxx +++ b/Source/CPack/cmCPackPackageMakerGenerator.cxx @@ -319,17 +319,19 @@ int cmCPackPackageMakerGenerator::PackageFiles() << "\" \"" << packageFileNames[0] << "\""; std::string output; int retVal = 1; - int numTries = 4; + int numTries = 10; bool res = false; while(numTries > 0) { res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, this->GeneratorVerbose, 0); - if(res && retVal) + if ( res && !retVal ) { numTries = -1; + break; } + cmSystemTools::Delay(500); numTries--; } if ( !res || retVal ) @@ -353,24 +355,73 @@ int cmCPackPackageMakerGenerator::InitializeInternal() cmCPackLogger(cmCPackLog::LOG_DEBUG, "cmCPackPackageMakerGenerator::Initialize()" << std::endl); this->SetOptionIfNotSet("CPACK_PACKAGING_INSTALL_PREFIX", "/usr"); - std::vector path; - std::string pkgPath - = "/Developer/Applications/Utilities/PackageMaker.app/Contents"; - std::string versionFile = pkgPath + "/version.plist"; - if ( !cmSystemTools::FileExists(versionFile.c_str()) ) + + // Starting with Xcode 4.3, PackageMaker is a separate app, and you + // can put it anywhere you want. So... use a variable for its location. + // People who put it in unexpected places can use the variable to tell + // us where it is. + // + // Use the following locations, in "most recent installation" order, + // to search for the PackageMaker app. Assume people who copy it into + // the new Xcode 4.3 app in "/Applications" will copy it into the nested + // Applications folder inside the Xcode bundle itself. Or directly in + // the "/Applications" directory. + // + // If found, save result in the CPACK_INSTALLER_PROGRAM variable. + + std::vector paths; + paths.push_back( + "/Applications/Xcode.app/Contents/Applications" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back( + "/Applications/Utilities" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back( + "/Applications" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back( + "/Developer/Applications/Utilities" + "/PackageMaker.app/Contents/MacOS"); + paths.push_back( + "/Developer/Applications" + "/PackageMaker.app/Contents/MacOS"); + + std::string pkgPath; + const char *inst_program = this->GetOption("CPACK_INSTALLER_PROGRAM"); + if (inst_program && *inst_program) + { + pkgPath = inst_program; + } + else { - pkgPath = "/Developer/Applications/PackageMaker.app/Contents"; - std::string newVersionFile = pkgPath + "/version.plist"; - if ( !cmSystemTools::FileExists(newVersionFile.c_str()) ) + pkgPath = cmSystemTools::FindProgram("PackageMaker", paths, false); + if ( pkgPath.empty() ) { - cmCPackLogger(cmCPackLog::LOG_ERROR, - "Cannot find PackageMaker compiler version file: " - << versionFile.c_str() << " or " << newVersionFile.c_str() + cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler" << std::endl); return 0; } - versionFile = newVersionFile; + this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); } + + // Get path to the real PackageMaker, not a symlink: + pkgPath = cmSystemTools::GetRealPath(pkgPath.c_str()); + // Up from there to find the version.plist file in the "Contents" dir: + std::string contents_dir; + contents_dir = cmSystemTools::GetFilenamePath(pkgPath); + contents_dir = cmSystemTools::GetFilenamePath(contents_dir); + + std::string versionFile = contents_dir + "/version.plist"; + + if ( !cmSystemTools::FileExists(versionFile.c_str()) ) + { + cmCPackLogger(cmCPackLog::LOG_ERROR, + "Cannot find PackageMaker compiler version file: " + << versionFile.c_str() + << std::endl); + return 0; + } + std::ifstream ifs(versionFile.c_str()); if ( !ifs ) { @@ -378,6 +429,7 @@ int cmCPackPackageMakerGenerator::InitializeInternal() "Cannot open PackageMaker compiler version file" << std::endl); return 0; } + // Check the PackageMaker version cmsys::RegularExpression rexKey("CFBundleShortVersionString"); cmsys::RegularExpression rexVersion("([0-9]+.[0-9.]+)"); @@ -440,17 +492,8 @@ int cmCPackPackageMakerGenerator::InitializeInternal() this->PackageCompatibilityVersion = 10.3; } - pkgPath += "/MacOS"; - path.push_back(pkgPath); - pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false); - if ( pkgPath.empty() ) - { - cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find PackageMaker compiler" - << std::endl); - return 0; - } - this->SetOptionIfNotSet("CPACK_INSTALLER_PROGRAM", pkgPath.c_str()); - pkgPath = cmSystemTools::FindProgram("hdiutil", path, false); + std::vector no_paths; + pkgPath = cmSystemTools::FindProgram("hdiutil", no_paths, false); if ( pkgPath.empty() ) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 1a6c3bef4..413572ee7 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -201,7 +201,7 @@ int cmCPackRPMGenerator::PackageFiles() << toplevel << std::endl); /* Are we in the component packaging case */ - if (SupportsComponentInstallation()) { + if (WantsComponentInstallation()) { // CASE 1 : COMPONENT ALL-IN-ONE package // If ALL COMPONENTS in ONE package has been requested // then the package file is unique and should be open here. diff --git a/Source/CPack/cmCPackSTGZGenerator.cxx b/Source/CPack/cmCPackSTGZGenerator.cxx index 184c557b8..966a231b7 100644 --- a/Source/CPack/cmCPackSTGZGenerator.cxx +++ b/Source/CPack/cmCPackSTGZGenerator.cxx @@ -54,21 +54,32 @@ int cmCPackSTGZGenerator::InitializeInternal() //---------------------------------------------------------------------- int cmCPackSTGZGenerator::PackageFiles() { + bool retval = true; if ( !this->Superclass::PackageFiles() ) { return 0; } - return cmSystemTools::SetPermissions(packageFileNames[0].c_str(), + + /* TGZ generator (our Superclass) may + * have generated several packages (component packaging) + * so we must iterate over generated packages. + */ + for (std::vector::iterator it=packageFileNames.begin(); + it != packageFileNames.end(); ++it) + { + retval &= cmSystemTools::SetPermissions((*it).c_str(), #if defined( _MSC_VER ) || defined( __MINGW32__ ) - S_IREAD | S_IWRITE | S_IEXEC + S_IREAD | S_IWRITE | S_IEXEC #elif defined( __BORLANDC__ ) - S_IRUSR | S_IWUSR | S_IXUSR + S_IRUSR | S_IWUSR | S_IXUSR #else - S_IRUSR | S_IWUSR | S_IXUSR | - S_IRGRP | S_IWGRP | S_IXGRP | - S_IROTH | S_IWOTH | S_IXOTH + S_IRUSR | S_IWUSR | S_IXUSR | + S_IRGRP | S_IWGRP | S_IXGRP | + S_IROTH | S_IWOTH | S_IXOTH #endif - ); + ); + } + return retval; } //---------------------------------------------------------------------- diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index b1706e3eb..6f5055ca8 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -14,6 +14,8 @@ // Need these for documentation support. #include "cmake.h" #include "cmDocumentation.h" +#include "cmCPackDocumentVariables.h" +#include "cmCPackDocumentMacros.h" #include "cmCPackGeneratorFactory.h" #include "cmCPackGenerator.h" #include "cmake.h" @@ -24,6 +26,7 @@ #include "cmCPackLog.h" #include +#include #include // auto_ptr //---------------------------------------------------------------------------- @@ -71,6 +74,59 @@ static const char * cmDocumentationOptions[][3] = {"--config ", "Specify the config file.", "Specify the config file to use to create the package. By default " "CPackConfig.cmake in the current directory will be used." }, + {"--verbose,-V","enable verbose output","Run cpack with verbose output."}, + {"--debug","enable debug output (for CPack developers)", + "Run cpack with debug output (for CPack developers)."}, + {"-P ","override/define CPACK_PACKAGE_NAME", + "If the package name is not specified on cpack commmand line then" + "CPack.cmake defines it as CMAKE_PROJECT_NAME"}, + {"-R ","override/define CPACK_PACKAGE_VERSION", + "If version is not specified on cpack command line then" + "CPack.cmake defines it from CPACK_PACKAGE_VERSION_[MAJOR|MINOR|PATCH]" + "look into CPack.cmake for detail"}, + {"-B ","override/define CPACK_PACKAGE_DIRECTORY", + "The directory where CPack will be doing its packaging work." + "The resulting package will be found there. Inside this directory" + "CPack creates '_CPack_Packages' sub-directory which is the" + "CPack temporary directory."}, + {"--vendor ","override/define CPACK_PACKAGE_VENDOR", + "If vendor is not specified on cpack command line " + "(or inside CMakeLists.txt) then" + "CPack.cmake defines it with a default value"}, + {"--help-command cmd [file]", "Print help for a single command and exit.", + "Full documentation specific to the given command is displayed. " + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, + {"--help-command-list [file]", "List available commands and exit.", + "The list contains all commands for which help may be obtained by using " + "the --help-command argument followed by a command name. " + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, + {"--help-commands [file]", "Print help for all commands and exit.", + "Full documentation specific for all current command is displayed." + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, + {"--help-variable var [file]", + "Print help for a single variable and exit.", + "Full documentation specific to the given variable is displayed." + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, + {"--help-variable-list [file]", "List documented variables and exit.", + "The list contains all variables for which help may be obtained by using " + "the --help-variable argument followed by a variable name. If a file is " + "specified, the help is written into it." + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, + {"--help-variables [file]", "Print help for all variables and exit.", + "Full documentation for all variables is displayed." + "If a file is specified, the documentation is written into and the output " + "format is determined depending on the filename suffix. Supported are man " + "page, HTML, DocBook and plain text."}, {0,0,0} }; @@ -118,12 +174,15 @@ int cpackDefinitionArgument(const char* argument, const char* cValue, return 1; } + //---------------------------------------------------------------------------- // this is CPack. int main (int argc, char *argv[]) { cmSystemTools::FindExecutableDirectory(argv[0]); cmCPackLog log; + int nocwd = 0; + log.SetErrorPrefix("CPack Error: "); log.SetWarningPrefix("CPack Warning: "); log.SetOutputPrefix("CPack: "); @@ -135,6 +194,7 @@ int main (int argc, char *argv[]) { cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Current working directory cannot be established." << std::endl); + nocwd = 1; } std::string generator; @@ -160,7 +220,6 @@ int main (int argc, char *argv[]) cpackConfigFile = ""; - cmDocumentation doc; cmsys::CommandLineArguments arg; arg.Initialize(argc, argv); typedef cmsys::CommandLineArguments argT; @@ -233,17 +292,25 @@ int main (int argc, char *argv[]) generators.SetLogger(&log); cmCPackGenerator* cpackGenerator = 0; - if ( !helpFull.empty() || !helpMAN.empty() || - !helpHTML.empty() || helpVersion ) + cmDocumentation doc; + doc.addCPackStandardDocSections(); + /* Were we invoked to display doc or to do some work ? */ + if(doc.CheckOptions(argc, argv,"-G") || nocwd) { - help = true; + help = true; } + else + { + help = false; + } + + // This part is used for cpack documentation lookup as well. + cminst.AddCMakePaths(); if ( parsed && !help ) { // find out which system cpack is running on, so it can setup the search // paths, so FIND_XXX() commands can be used in scripts - cminst.AddCMakePaths(); std::string systemFile = globalMF->GetModulesFile("CMakeDetermineSystem.cmake"); if (!globalMF->ReadListFile(0, systemFile.c_str())) @@ -440,16 +507,54 @@ int main (int argc, char *argv[]) } } + /* In this case we are building the documentation object + * instance in order to create appropriate structure + * in order to satisfy the appropriate --help-xxx request + */ if ( help ) { - doc.CheckOptions(argc, argv); // Construct and print requested documentation. + doc.SetName("cpack"); doc.SetSection("Name",cmDocumentationName); doc.SetSection("Usage",cmDocumentationUsage); doc.SetSection("Description",cmDocumentationDescription); doc.PrependSection("Options",cmDocumentationOptions); + // statically (in C++ code) defined variables + cmCPackDocumentVariables::DefineVariables(&cminst); + + std::vector commands; + + std::string docedFile; + std::string docPath; + cmDocumentation::documentedModulesList_t docedModList; + + docedFile = globalMF->GetModulesFile("CPack.cmake"); + if (docedFile.length()!=0) + { + docPath = cmSystemTools::GetFilenamePath(docedFile.c_str()); + doc.getDocumentedModulesListInDir(docPath,"CPack*.cmake",docedModList); + } + + // parse the files for documentation. + cmDocumentation::documentedModulesList_t::iterator docedIt; + for (docedIt = docedModList.begin(); + docedIt!= docedModList.end(); ++docedIt) + { + doc.GetStructuredDocFromFile( + (docedIt->first).c_str(), + commands,&cminst); + } + + std::map propDocs; + cminst.GetPropertiesDocumentation(propDocs); + doc.SetSections(propDocs); + cminst.GetCommandDocumentation(commands,true,false); + // statically (in C++ code) defined macros/commands + cmCPackDocumentMacros::GetMacrosDocumentation(commands); + doc.SetSection("Commands",commands); + std::vector v; cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt; for( generatorIt = generators.GetGeneratorsList().begin(); diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index 9eb49071c..cabc39b32 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/Source/CTest/cmCTestBuildCommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_build";} + virtual const char* GetName() const { return "ctest_build";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Build the project."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_build([BUILD build_dir] [TARGET target] [RETURN_VALUE res]\n" diff --git a/Source/CTest/cmCTestBuildHandler.cxx b/Source/CTest/cmCTestBuildHandler.cxx index 34a3e60c3..27bb06c13 100644 --- a/Source/CTest/cmCTestBuildHandler.cxx +++ b/Source/CTest/cmCTestBuildHandler.cxx @@ -94,6 +94,7 @@ static const char* cmCTestErrorMatches[] = { ": Invalid argument", "^The project cannot be built\\.", "^\\[ERROR\\]", + "^Command .* failed with exit code", 0 }; diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h index 156e6f211..b343fc1e9 100644 --- a/Source/CTest/cmCTestConfigureCommand.h +++ b/Source/CTest/cmCTestConfigureCommand.h @@ -38,12 +38,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_configure";} + virtual const char* GetName() const { return "ctest_configure";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Configure the project build tree."; } @@ -51,7 +51,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_configure([BUILD build_dir] [SOURCE source_dir] [APPEND]\n" diff --git a/Source/CTest/cmCTestCoverageCommand.h b/Source/CTest/cmCTestCoverageCommand.h index 25c10dcab..2fe762c45 100644 --- a/Source/CTest/cmCTestCoverageCommand.h +++ b/Source/CTest/cmCTestCoverageCommand.h @@ -39,12 +39,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_coverage";} + virtual const char* GetName() const { return "ctest_coverage";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Collect coverage tool results."; } @@ -52,7 +52,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_coverage([BUILD build_dir] [RETURN_VALUE res] [APPEND]\n" diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 0b1c9fef8..309abb16d 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -555,7 +555,7 @@ int cmCTestCoverageHandler::ProcessHandler() covSumFile << "\tCTest->GetShortPathToFile(fullFileName.c_str())) - << "\" Covered=\"" << (tested > 0 ? "true":"false") << "\">\n" + << "\" Covered=\"" << (tested+untested > 0 ? "true":"false") << "\">\n" << "\t\t" << tested << "\n" << "\t\t" << untested << "\n" << "\t\t"; diff --git a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h index cf6104594..a763fe9e9 100644 --- a/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h +++ b/Source/CTest/cmCTestEmptyBinaryDirectoryCommand.h @@ -48,12 +48,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_empty_binary_directory";} + virtual const char* GetName() const { return "ctest_empty_binary_directory";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "empties the binary directory"; } @@ -61,7 +61,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_empty_binary_directory( directory )\n" diff --git a/Source/CTest/cmCTestMemCheckCommand.h b/Source/CTest/cmCTestMemCheckCommand.h index 8fa142f69..399fe8b22 100644 --- a/Source/CTest/cmCTestMemCheckCommand.h +++ b/Source/CTest/cmCTestMemCheckCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_memcheck";} + virtual const char* GetName() const { return "ctest_memcheck";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Run tests with a dynamic analysis tool."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_memcheck([BUILD build_dir] [RETURN_VALUE res] [APPEND]\n" diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index f0a98f9fd..035aaa9f9 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -679,7 +679,7 @@ bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput( " bytes in [0-9,]+ blocks are definitely lost" " in loss record [0-9,]+ of [0-9,]+"); cmsys::RegularExpression vgPAR( - "== .*Syscall param .* contains unaddressable byte\\(s\\)"); + "== .*Syscall param .* (contains|points to) unaddressable byte\\(s\\)"); cmsys::RegularExpression vgMPK1( "== .*[0-9,]+ bytes in [0-9,]+ blocks are possibly lost in" " loss record [0-9,]+ of [0-9,]+"); diff --git a/Source/CTest/cmCTestReadCustomFilesCommand.h b/Source/CTest/cmCTestReadCustomFilesCommand.h index 2213c8fc6..f382b0f2d 100644 --- a/Source/CTest/cmCTestReadCustomFilesCommand.h +++ b/Source/CTest/cmCTestReadCustomFilesCommand.h @@ -46,12 +46,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_read_custom_files";} + virtual const char* GetName() const { return "ctest_read_custom_files";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "read CTestCustom files."; } @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_read_custom_files( directory ... )\n" diff --git a/Source/CTest/cmCTestRunScriptCommand.h b/Source/CTest/cmCTestRunScriptCommand.h index 5765150f8..6df69afa6 100644 --- a/Source/CTest/cmCTestRunScriptCommand.h +++ b/Source/CTest/cmCTestRunScriptCommand.h @@ -47,12 +47,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_run_script";} + virtual const char* GetName() const { return "ctest_run_script";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "runs a ctest -S script"; } @@ -60,7 +60,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_run_script([NEW_PROCESS] script_file_name script_file_name1 \n" diff --git a/Source/CTest/cmCTestSleepCommand.h b/Source/CTest/cmCTestSleepCommand.h index 468cd8548..80fd6afb7 100644 --- a/Source/CTest/cmCTestSleepCommand.h +++ b/Source/CTest/cmCTestSleepCommand.h @@ -47,12 +47,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_sleep";} + virtual const char* GetName() const { return "ctest_sleep";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "sleeps for some amount of time"; } @@ -60,7 +60,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_sleep()\n" diff --git a/Source/CTest/cmCTestStartCommand.h b/Source/CTest/cmCTestStartCommand.h index afbc77b4a..6be47703e 100644 --- a/Source/CTest/cmCTestStartCommand.h +++ b/Source/CTest/cmCTestStartCommand.h @@ -55,12 +55,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_start";} + virtual const char* GetName() const { return "ctest_start";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Starts the testing for a given model"; } @@ -68,7 +68,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_start(Model [TRACK ] [APPEND] [source [binary]])\n" diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h index edc9c65b1..53ee8754e 100644 --- a/Source/CTest/cmCTestSubmitCommand.h +++ b/Source/CTest/cmCTestSubmitCommand.h @@ -48,12 +48,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_submit";} + virtual const char* GetName() const { return "ctest_submit";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Submit results to a dashboard server."; } @@ -61,7 +61,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_submit([PARTS ...] [FILES ...] [RETRY_COUNT count] " diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h index c6fd6314c..d184ff2a0 100644 --- a/Source/CTest/cmCTestTestCommand.h +++ b/Source/CTest/cmCTestTestCommand.h @@ -39,12 +39,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_test";} + virtual const char* GetName() const { return "ctest_test";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Run tests in the project build tree."; } @@ -52,7 +52,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_test([BUILD build_dir] [APPEND]\n" diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 9b12393c5..ead449edd 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -59,11 +59,11 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "subdirs";} + virtual const char* GetName() const { return "subdirs";} // Unused methods - virtual const char* GetTerseDocumentation() { return ""; } - virtual const char* GetFullDocumentation() { return ""; } + virtual const char* GetTerseDocumentation() const { return ""; } + virtual const char* GetFullDocumentation() const { return ""; } cmTypeMacro(cmCTestSubdirCommand, cmCommand); @@ -161,11 +161,11 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_subdirectory";} + virtual const char* GetName() const { return "add_subdirectory";} // Unused methods - virtual const char* GetTerseDocumentation() { return ""; } - virtual const char* GetFullDocumentation() { return ""; } + virtual const char* GetTerseDocumentation() const { return ""; } + virtual const char* GetFullDocumentation() const { return ""; } cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand); @@ -251,11 +251,11 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ADD_TEST";} + virtual const char* GetName() const { return "ADD_TEST";} // Unused methods - virtual const char* GetTerseDocumentation() { return ""; } - virtual const char* GetFullDocumentation() { return ""; } + virtual const char* GetTerseDocumentation() const { return ""; } + virtual const char* GetFullDocumentation() const { return ""; } cmTypeMacro(cmCTestAddTestCommand, cmCommand); @@ -299,11 +299,11 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "SET_TESTS_PROPERTIES";} + virtual const char* GetName() const { return "SET_TESTS_PROPERTIES";} // Unused methods - virtual const char* GetTerseDocumentation() { return ""; } - virtual const char* GetFullDocumentation() { return ""; } + virtual const char* GetTerseDocumentation() const { return ""; } + virtual const char* GetFullDocumentation() const { return ""; } cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand); diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h index 7f369283d..c578fff6f 100644 --- a/Source/CTest/cmCTestUpdateCommand.h +++ b/Source/CTest/cmCTestUpdateCommand.h @@ -39,12 +39,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_update";} + virtual const char* GetName() const { return "ctest_update";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Update the work tree from version control."; } @@ -52,7 +52,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_update([SOURCE source] [RETURN_VALUE res])\n" diff --git a/Source/CTest/cmCTestUploadCommand.h b/Source/CTest/cmCTestUploadCommand.h index 6c2a4c2ef..62f379f6d 100644 --- a/Source/CTest/cmCTestUploadCommand.h +++ b/Source/CTest/cmCTestUploadCommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "ctest_upload";} + virtual const char* GetName() const { return "ctest_upload";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Upload files to a dashboard server."; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " ctest_upload(FILES ...)\n" diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx index b1a72afa4..623d7d3a5 100644 --- a/Source/CursesDialog/ccmake.cxx +++ b/Source/CursesDialog/ccmake.cxx @@ -102,6 +102,7 @@ int main(int argc, char** argv) { cmSystemTools::FindExecutableDirectory(argv[0]); cmDocumentation doc; + doc.addCMakeStandardDocSections(); if(doc.CheckOptions(argc, argv)) { cmake hcm; diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index 6c7627f92..4fee0bbd3 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -409,12 +409,11 @@ void cmCursesMainForm::PrintKeys(int process /* = 0 */) char thirdLine[512]=""; if (process) { - sprintf(firstLine, - " "); - sprintf(secondLine, - " "); - sprintf(thirdLine, - " "); + const char* clearLine = + " "; + strcpy(firstLine, clearLine); + strcpy(secondLine, clearLine); + strcpy(thirdLine, clearLine); } else { diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 4785188f0..056e48ec3 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -10,11 +10,11 @@ # See the License for more information. #============================================================================= PROJECT(QtDialog) -SET(QT_MIN_VERSION "4.3.0") +SET(QT_MIN_VERSION "4.4.0") FIND_PACKAGE(Qt4 REQUIRED) IF(NOT QT4_FOUND) - MESSAGE(SEND_ERROR "Failed to find Qt 4.3 or greater.") + MESSAGE(SEND_ERROR "Failed to find Qt 4.4 or greater.") ELSE(NOT QT4_FOUND) INCLUDE(${QT_USE_FILE}) diff --git a/Source/QtDialog/CMakeSetup.cxx b/Source/QtDialog/CMakeSetup.cxx index 7ba7f51ec..b4f3d7216 100644 --- a/Source/QtDialog/CMakeSetup.cxx +++ b/Source/QtDialog/CMakeSetup.cxx @@ -64,6 +64,7 @@ int main(int argc, char** argv) // check docs first so that X is not need to get docs // do docs, if args were given cmDocumentation doc; + doc.addCMakeStandardDocSections(); if(argc >1 && doc.CheckOptions(argc, argv)) { // Construct and print requested documentation. diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 338eaffb4..45b4cd3c5 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -554,8 +554,7 @@ void CMakeSetupDialog::doHelp() void CMakeSetupDialog::doInterrupt() { this->enterState(Interrupting); - QMetaObject::invokeMethod(this->CMakeThread->cmakeInstance(), - "interrupt", Qt::QueuedConnection); + this->CMakeThread->cmakeInstance()->interrupt(); } void CMakeSetupDialog::doSourceBrowse() diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index a40a175f7..73050f30c 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -63,6 +63,8 @@ QCMake::QCMake(QObject* p) #endif this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this); + cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this); + std::vector generators; this->CMakeInstance->GetRegisteredGenerators(generators); std::vector::iterator iter; @@ -170,6 +172,7 @@ void QCMake::configure() this->CMakeInstance->SetWarnUnused(this->WarnUnusedMode); this->CMakeInstance->PreLoadCMakeFiles(); + InterruptFlag = 0; cmSystemTools::ResetErrorOccuredFlag(); int err = this->CMakeInstance->Configure(); @@ -188,7 +191,9 @@ void QCMake::generate() UINT lastErrorMode = SetErrorMode(0); #endif + InterruptFlag = 0; cmSystemTools::ResetErrorOccuredFlag(); + int err = this->CMakeInstance->Generate(); #ifdef Q_OS_WIN @@ -337,7 +342,13 @@ QCMakePropertyList QCMake::properties() const void QCMake::interrupt() { - cmSystemTools::SetFatalErrorOccured(); + this->InterruptFlag.ref(); +} + +bool QCMake::interruptCallback(void* cd) +{ + QCMake* self = reinterpret_cast(cd); + return self->InterruptFlag; } void QCMake::progressCallback(const char* msg, float percent, void* cd) diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index 0d10823f3..0d68586f2 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -23,6 +23,7 @@ #include #include #include +#include class cmake; @@ -78,7 +79,7 @@ public slots: void generate(); /// set the property values void setProperties(const QCMakePropertyList&); - /// interrupt the configure or generate process + /// interrupt the configure or generate process (if connecting, make a direct connection) void interrupt(); /// delete the cache in binary directory void deleteCache(); @@ -133,6 +134,7 @@ signals: protected: cmake* CMakeInstance; + static bool interruptCallback(void*); static void progressCallback(const char* msg, float percent, void* cd); static void errorCallback(const char* msg, const char* title, bool&, void* cd); @@ -145,6 +147,7 @@ protected: QString Generator; QStringList AvailableGenerators; QString CMakeExecutable; + QAtomicInt InterruptFlag; }; #endif // __QCMake_h diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h index 05e7dc28e..1f770ed39 100644 --- a/Source/cmAddCustomCommandCommand.h +++ b/Source/cmAddCustomCommandCommand.h @@ -44,12 +44,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "add_custom_command";} + virtual const char* GetName() const {return "add_custom_command";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a custom build rule to the generated build system."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "There are two main signatures for add_custom_command " diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h index 6d94fb292..50bffefde 100644 --- a/Source/cmAddCustomTargetCommand.h +++ b/Source/cmAddCustomTargetCommand.h @@ -42,13 +42,13 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() + virtual const char* GetName() const {return "add_custom_target";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a target with no output so it will always be built."; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_custom_target(Name [ALL] [command1 [args1...]]\n" diff --git a/Source/cmAddDefinitionsCommand.h b/Source/cmAddDefinitionsCommand.h index 0617f04d2..7bb37674d 100644 --- a/Source/cmAddDefinitionsCommand.h +++ b/Source/cmAddDefinitionsCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "add_definitions";} + virtual const char* GetName() const {return "add_definitions";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Adds -D define flags to the compilation of source files."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_definitions(-DFOO -DBAR ...)\n" diff --git a/Source/cmAddDependenciesCommand.h b/Source/cmAddDependenciesCommand.h index fee011c22..14a7741fa 100644 --- a/Source/cmAddDependenciesCommand.h +++ b/Source/cmAddDependenciesCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_dependencies";} + virtual const char* GetName() const { return "add_dependencies";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a dependency between top-level targets."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_dependencies(target-name depend-target1\n" diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index bac243039..6dd8e5c64 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -29,6 +29,7 @@ bool cmAddExecutableCommand bool use_macbundle = false; bool excludeFromAll = false; bool importTarget = false; + bool importGlobal = false; while ( s != args.end() ) { if (*s == "WIN32") @@ -51,6 +52,11 @@ bool cmAddExecutableCommand ++s; importTarget = true; } + else if(importTarget && *s == "GLOBAL") + { + ++s; + importGlobal = true; + } else { break; @@ -92,7 +98,8 @@ bool cmAddExecutableCommand } // Create the imported target. - this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE); + this->Makefile->AddImportedTarget(exename.c_str(), cmTarget::EXECUTABLE, + importGlobal); return true; } diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h index f90e82697..1e9f9b3be 100644 --- a/Source/cmAddExecutableCommand.h +++ b/Source/cmAddExecutableCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_executable";} + virtual const char* GetName() const { return "add_executable";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add an executable to the project using the specified source files."; @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_executable( [WIN32] [MACOSX_BUNDLE]\n" @@ -92,12 +92,12 @@ public: "\n" "The add_executable command can also create IMPORTED executable " "targets using this signature:\n" - " add_executable( IMPORTED)\n" + " add_executable( IMPORTED [GLOBAL])\n" "An IMPORTED executable target references an executable file located " "outside the project. " "No rules are generated to build it. " "The target name has scope in the directory in which it is created " - "and below. " + "and below, but the GLOBAL option extends visibility. " "It may be referenced like any target built within the project. " "IMPORTED executables are useful for convenient reference from " "commands like add_custom_command. " diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index efa29e6c9..c1d0e9d6d 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -31,6 +31,7 @@ bool cmAddLibraryCommand } bool excludeFromAll = false; bool importTarget = false; + bool importGlobal = false; std::vector::const_iterator s = args.begin(); @@ -63,6 +64,12 @@ bool cmAddLibraryCommand type = cmTarget::MODULE_LIBRARY; haveSpecifiedType = true; } + else if(libType == "OBJECT") + { + ++s; + type = cmTarget::OBJECT_LIBRARY; + haveSpecifiedType = true; + } else if(libType == "UNKNOWN") { ++s; @@ -79,6 +86,11 @@ bool cmAddLibraryCommand ++s; importTarget = true; } + else if(importTarget && *s == "GLOBAL") + { + ++s; + importGlobal = true; + } else { break; @@ -112,6 +124,14 @@ bool cmAddLibraryCommand this->SetError("called with IMPORTED argument but no library type."); return false; } + if(type == cmTarget::OBJECT_LIBRARY) + { + this->Makefile->IssueMessage( + cmake::FATAL_ERROR, + "The OBJECT library type may not be used for IMPORTED libraries." + ); + return true; + } // Make sure the target does not already exist. if(this->Makefile->FindTargetToUse(libName.c_str())) @@ -124,7 +144,7 @@ bool cmAddLibraryCommand } // Create the imported target. - this->Makefile->AddImportedTarget(libName.c_str(), type); + this->Makefile->AddImportedTarget(libName.c_str(), type, importGlobal); return true; } diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index 07fbb06ad..b1ae20289 100644 --- a/Source/cmAddLibraryCommand.h +++ b/Source/cmAddLibraryCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_library";} + virtual const char* GetName() const { return "add_library";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a library to the project using the specified source files."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_library( [STATIC | SHARED | MODULE]\n" @@ -96,12 +96,13 @@ public: "\n" "The add_library command can also create IMPORTED library " "targets using this signature:\n" - " add_library( IMPORTED)\n" + " add_library( IMPORTED\n" + " [GLOBAL])\n" "An IMPORTED library target references a library file located " "outside the project. " "No rules are generated to build it. " "The target name has scope in the directory in which it is created " - "and below. " + "and below, but the GLOBAL option extends visibility. " "It may be referenced like any target built within the project. " "IMPORTED libraries are useful for convenient reference from " "commands like target_link_libraries. " @@ -111,6 +112,26 @@ public: "(and its per-configuration version IMPORTED_LOCATION_) " "which specifies the location of the main library file on disk. " "See documentation of the IMPORTED_* properties for more information." + "\n" + "The signature\n" + " add_library( OBJECT ...)\n" + "creates a special \"object library\" target. " + "An object library compiles source files but does not archive or link " + "their object files into a library. " + "Instead other targets created by add_library or add_executable may " + "reference the objects using an expression of the form " + "$ as a source, where \"objlib\" is the " + "object library name. " + "For example:\n" + " add_library(... $ ...)\n" + " add_executable(... $ ...)\n" + "will include objlib's object files in a library and an executable " + "along with those compiled from their own sources. " + "Object libraries may contain only sources (and headers) that compile " + "to object files. " + "They may contain custom commands generating such sources, but not " + "PRE_BUILD, PRE_LINK, or POST_BUILD commands. " + "Object libraries cannot be imported, exported, installed, or linked." ; } diff --git a/Source/cmAddSubDirectoryCommand.h b/Source/cmAddSubDirectoryCommand.h index dae705eb8..3d6f51ea5 100644 --- a/Source/cmAddSubDirectoryCommand.h +++ b/Source/cmAddSubDirectoryCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_subdirectory";} + virtual const char* GetName() const { return "add_subdirectory";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a subdirectory to the build."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_subdirectory(source_dir [binary_dir] \n" diff --git a/Source/cmAddTestCommand.h b/Source/cmAddTestCommand.h index edaf12c9d..59f10f622 100644 --- a/Source/cmAddTestCommand.h +++ b/Source/cmAddTestCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "add_test";} + virtual const char* GetName() const { return "add_test";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add a test to the project with the specified arguments."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " add_test(testname Exename arg1 arg2 ... )\n" diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index eab8a592a..dc6b749b2 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -247,10 +247,14 @@ bool cmArchiveWrite::AddFile(const char* file, return false; } - // Content. - if(size_t size = static_cast(archive_entry_size(e))) + // do not copy content of symlink + if (!archive_entry_symlink(e)) { - return this->AddData(file, size); + // Content. + if(size_t size = static_cast(archive_entry_size(e))) + { + return this->AddData(file, size); + } } return true; } diff --git a/Source/cmAuxSourceDirectoryCommand.h b/Source/cmAuxSourceDirectoryCommand.h index 704e2ed99..f059e4473 100644 --- a/Source/cmAuxSourceDirectoryCommand.h +++ b/Source/cmAuxSourceDirectoryCommand.h @@ -44,12 +44,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "aux_source_directory";} + virtual const char* GetName() const { return "aux_source_directory";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Find all source files in a directory."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " aux_source_directory( )\n" diff --git a/Source/cmBootstrapCommands.cxx b/Source/cmBootstrapCommands.cxx index 554f45215..9097a7482 100644 --- a/Source/cmBootstrapCommands.cxx +++ b/Source/cmBootstrapCommands.cxx @@ -12,7 +12,7 @@ // This file is used to compile all the commands // that CMake knows about at compile time. // This is sort of a boot strapping approach since you would -// like to have CMake to build CMake. +// like to have CMake to build CMake. #include "cmCommands.h" #include "cmAddCustomCommandCommand.cxx" #include "cmAddCustomTargetCommand.cxx" @@ -38,6 +38,7 @@ #include "cmEndFunctionCommand.cxx" #include "cmEndIfCommand.cxx" #include "cmEndMacroCommand.cxx" +#include "cmEndWhileCommand.cxx" #include "cmExecProgramCommand.cxx" #include "cmExecuteProcessCommand.cxx" #include "cmExternalMakefileProjectGenerator.cxx" @@ -91,6 +92,7 @@ #include "cmTryCompileCommand.cxx" #include "cmTryRunCommand.cxx" #include "cmUnsetCommand.cxx" +#include "cmWhileCommand.cxx" void GetBootstrapCommands(std::list& commands) { @@ -111,11 +113,12 @@ void GetBootstrapCommands(std::list& commands) commands.push_back(new cmDefinePropertyCommand); commands.push_back(new cmElseCommand); commands.push_back(new cmEnableLanguageCommand); - commands.push_back(new cmEnableTestingCommand); + commands.push_back(new cmEnableTestingCommand); commands.push_back(new cmEndForEachCommand); commands.push_back(new cmEndFunctionCommand); commands.push_back(new cmEndIfCommand); commands.push_back(new cmEndMacroCommand); + commands.push_back(new cmEndWhileCommand); commands.push_back(new cmExecProgramCommand); commands.push_back(new cmExecuteProcessCommand); commands.push_back(new cmFileCommand); @@ -164,4 +167,5 @@ void GetBootstrapCommands(std::list& commands) commands.push_back(new cmTryCompileCommand); commands.push_back(new cmTryRunCommand); commands.push_back(new cmUnsetCommand); + commands.push_back(new cmWhileCommand); } diff --git a/Source/cmBreakCommand.h b/Source/cmBreakCommand.h index 72796e892..67ef37e9a 100644 --- a/Source/cmBreakCommand.h +++ b/Source/cmBreakCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "break";} + virtual const char* GetName() const {return "break";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Break from an enclosing foreach or while loop."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " break()\n" diff --git a/Source/cmBuildCommand.h b/Source/cmBuildCommand.h index 1d247d2f2..a333c5d95 100644 --- a/Source/cmBuildCommand.h +++ b/Source/cmBuildCommand.h @@ -50,12 +50,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "build_command";} + virtual const char* GetName() const {return "build_command";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get the command line to build this project."; } @@ -63,7 +63,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " build_command(\n" diff --git a/Source/cmBuildNameCommand.h b/Source/cmBuildNameCommand.h index 29a680fcd..26505a260 100644 --- a/Source/cmBuildNameCommand.h +++ b/Source/cmBuildNameCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "build_name";} + virtual const char* GetName() const {return "build_name";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use ${CMAKE_SYSTEM} and ${CMAKE_CXX_COMPILER} instead."; @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " build_name(variable)\n" @@ -69,7 +69,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmCMakeMinimumRequired.h b/Source/cmCMakeMinimumRequired.h index 112138644..d23ce79cf 100644 --- a/Source/cmCMakeMinimumRequired.h +++ b/Source/cmCMakeMinimumRequired.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "cmake_minimum_required";} + virtual const char* GetName() const {return "cmake_minimum_required";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set the minimum required version of cmake for a project."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " cmake_minimum_required(VERSION major[.minor[.patch[.tweak]]]\n" diff --git a/Source/cmCMakePolicyCommand.h b/Source/cmCMakePolicyCommand.h index afd30010f..4f1ed36ad 100644 --- a/Source/cmCMakePolicyCommand.h +++ b/Source/cmCMakePolicyCommand.h @@ -41,17 +41,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "cmake_policy";} + virtual const char* GetName() const {return "cmake_policy";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Manage CMake Policy settings."; } @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "As CMake evolves it is sometimes necessary to change existing " diff --git a/Source/cmCacheManager.cxx b/Source/cmCacheManager.cxx index ab0bb79b5..47a0e8553 100644 --- a/Source/cmCacheManager.cxx +++ b/Source/cmCacheManager.cxx @@ -13,6 +13,7 @@ #include "cmCacheManager.h" #include "cmSystemTools.h" #include "cmCacheManager.h" +#include "cmGeneratedFileStream.h" #include "cmMakefile.h" #include "cmake.h" #include "cmVersion.h" @@ -431,9 +432,8 @@ bool cmCacheManager::SaveCache(const char* path) { std::string cacheFile = path; cacheFile += "/CMakeCache.txt"; - std::string tempFile = cacheFile; - tempFile += ".tmp"; - std::ofstream fout(tempFile.c_str()); + cmGeneratedFileStream fout(cacheFile.c_str()); + fout.SetCopyIfDifferent(true); if(!fout) { cmSystemTools::Error("Unable to open cache file for save. ", @@ -561,10 +561,7 @@ bool cmCacheManager::SaveCache(const char* path) } } fout << "\n"; - fout.close(); - cmSystemTools::CopyFileIfDifferent(tempFile.c_str(), - cacheFile.c_str()); - cmSystemTools::RemoveFile(tempFile.c_str()); + fout.Close(); std::string checkCacheFile = path; checkCacheFile += cmake::GetCMakeFilesDirectory(); cmSystemTools::MakeDirectory(checkCacheFile.c_str()); diff --git a/Source/cmCommand.h b/Source/cmCommand.h index 7817eb3c1..4faaee3ac 100644 --- a/Source/cmCommand.h +++ b/Source/cmCommand.h @@ -96,7 +96,7 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() + virtual bool IsScriptable() const { return false; } @@ -105,25 +105,36 @@ public: * This determines if usage of the method is discouraged or not. * This is currently only used for generating the documentation. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return false; } + /** + * This is used to avoid including this command + * in documentation. This is mainly used by + * cmMacroHelperCommand and cmFunctionHelperCommand + * which cannot provide appropriate documentation. + */ + virtual bool ShouldAppearInDocumentation() const + { + return true; + } + /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() = 0; + virtual const char* GetName() const = 0; /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() = 0; + virtual const char* GetTerseDocumentation() const = 0; /** * More documentation. */ - virtual const char* GetFullDocumentation() = 0; + virtual const char* GetFullDocumentation() const = 0; /** * Enable the command. @@ -140,7 +151,7 @@ public: /** * Query whether the command is enabled. */ - bool GetEnabled() + bool GetEnabled() const {return this->Enabled;} /** diff --git a/Source/cmCommandArgumentParserHelper.h b/Source/cmCommandArgumentParserHelper.h index a211e952b..cdb832b5f 100644 --- a/Source/cmCommandArgumentParserHelper.h +++ b/Source/cmCommandArgumentParserHelper.h @@ -81,7 +81,6 @@ private: cmStdString InputBuffer; std::vector OutputBuffer; int CurrentLine; - int UnionsAvailable; int Verbose; void Print(const char* place, const char* str); diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index bb1e4e286..49ed96795 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -14,7 +14,6 @@ #include "cmAuxSourceDirectoryCommand.cxx" #include "cmBuildNameCommand.cxx" #include "cmElseIfCommand.cxx" -#include "cmEndWhileCommand.cxx" #include "cmExportCommand.cxx" #include "cmExportLibraryDependencies.cxx" #include "cmFLTKWrapUICommand.cxx" @@ -34,7 +33,6 @@ #include "cmVariableRequiresCommand.cxx" #include "cmVariableWatchCommand.cxx" -#include "cmWhileCommand.cxx" #include "cmWriteFileCommand.cxx" // This one must be last because it includes windows.h and @@ -53,7 +51,6 @@ void GetPredefinedCommands(std::list& commands.push_back(new cmAuxSourceDirectoryCommand); commands.push_back(new cmBuildNameCommand); commands.push_back(new cmElseIfCommand); - commands.push_back(new cmEndWhileCommand); commands.push_back(new cmExportCommand); commands.push_back(new cmExportLibraryDependenciesCommand); commands.push_back(new cmFLTKWrapUICommand); @@ -73,7 +70,6 @@ void GetPredefinedCommands(std::list& commands.push_back(new cmUtilitySourceCommand); commands.push_back(new cmVariableRequiresCommand); commands.push_back(new cmVariableWatchCommand); - commands.push_back(new cmWhileCommand); commands.push_back(new cmWriteFileCommand); #endif } diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 802cfcf70..055aab032 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -27,7 +27,7 @@ This file computes an ordered list of link items to use when linking a single target in one configuration. Each link item is identified by the string naming it. A graph of dependencies is created in which -each node corresponds to one item and directed eges lead from nodes to +each node corresponds to one item and directed edges lead from nodes to those which must *follow* them on the link line. For example, the graph @@ -42,7 +42,7 @@ search of the link dependencies starting from the main target. There are two types of items: those with known direct dependencies and those without known dependencies. We will call the two types "known -items" and "unknown items", respecitvely. Known items are those whose +items" and "unknown items", respectively. Known items are those whose names correspond to targets (built or imported) and those for which an old-style _LIB_DEPENDS variable is defined. All other items are unknown and we must infer dependencies for them. For items that look @@ -150,7 +150,7 @@ times the component needs to be seen (once for trivial components, twice for non-trivial). If at any time another component finishes and re-adds an already pending component, the pending component is reset so that it needs to be seen in its entirety again. This ensures that -all dependencies of a component are satisified no matter where it +all dependencies of a component are satisfied no matter where it appears. After the original link line has been completed, we append to it the @@ -358,7 +358,7 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe) this->AddLinkEntries(depender_index, iface->Libraries); // Handle dependent shared libraries. - this->QueueSharedDependencies(depender_index, iface->SharedDeps); + this->FollowSharedDeps(depender_index, iface); // Support for CMP0003. for(std::vector::const_iterator @@ -376,6 +376,23 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe) } } +//---------------------------------------------------------------------------- +void +cmComputeLinkDepends +::FollowSharedDeps(int depender_index, cmTarget::LinkInterface const* iface, + bool follow_interface) +{ + // Follow dependencies if we have not followed them already. + if(this->SharedDepFollowed.insert(depender_index).second) + { + if(follow_interface) + { + this->QueueSharedDependencies(depender_index, iface->Libraries); + } + this->QueueSharedDependencies(depender_index, iface->SharedDeps); + } +} + //---------------------------------------------------------------------------- void cmComputeLinkDepends @@ -430,8 +447,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) entry.Target->GetLinkInterface(this->Config)) { // Follow public and private dependencies transitively. - this->QueueSharedDependencies(index, iface->Libraries); - this->QueueSharedDependencies(index, iface->SharedDeps); + this->FollowSharedDeps(index, iface, true); } } } @@ -617,6 +633,19 @@ cmTarget* cmComputeLinkDepends::FindTargetToLink(int depender_index, tgt = 0; } + if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "Target \"" << this->Target->GetName() << "\" links to " + "OBJECT library \"" << tgt->GetName() << "\" but this is not " + "allowed. " + "One may link only to STATIC or SHARED libraries, or to executables " + "with the ENABLE_EXPORTS property set."; + this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Target->GetBacktrace()); + tgt = 0; + } + // Return the target found, if any. return tgt; } diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index e196e00ca..80a04541f 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -105,6 +105,10 @@ private: int DependerIndex; }; std::queue SharedDepQueue; + std::set SharedDepFollowed; + void FollowSharedDeps(int depender_index, + cmTarget::LinkInterface const* iface, + bool follow_interface = false); void QueueSharedDependencies(int depender_index, std::vector const& deps); void HandleSharedDependency(SharedDepEntry const& dep); diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index edf6c35f6..df78bf886 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -248,6 +248,10 @@ cmComputeLinkInformation this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator(); this->CMakeInstance = this->GlobalGenerator->GetCMakeInstance(); + // Check whether to recognize OpenBSD-style library versioned names. + this->OpenBSD = this->Makefile->GetCMakeInstance() + ->GetPropertyAsBool("FIND_LIBRARY_USE_OPENBSD_VERSIONING"); + // The configuration being linked. this->Config = config; @@ -973,7 +977,15 @@ cmComputeLinkInformation } // Finish the list. - libext += ")$"; + libext += ")"; + + // Add an optional OpenBSD version component. + if(this->OpenBSD) + { + libext += "(\\.[0-9]+\\.[0-9]+)?"; + } + + libext += "$"; return libext; } @@ -1760,6 +1772,7 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, !linking_for_install); bool use_link_rpath = outputRuntime && linking_for_install && + !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH") && this->Target->GetPropertyAsBool("INSTALL_RPATH_USE_LINK_PATH"); // Construct the RPATH. diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h index bbeed68cd..f60f8d325 100644 --- a/Source/cmComputeLinkInformation.h +++ b/Source/cmComputeLinkInformation.h @@ -128,6 +128,7 @@ private: cmsys::RegularExpression ExtractSharedLibraryName; cmsys::RegularExpression ExtractAnyLibraryName; std::string SharedRegexString; + bool OpenBSD; void AddLinkPrefix(const char* p); void AddLinkExtension(const char* e, LinkType type); std::string CreateExtensionRegex(std::vector const& exts); diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 8e701c402..ab77c6bc9 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -31,7 +31,7 @@ dependencies for each target such that no cycles are left and the build order is safe. For most target types cyclic dependencies are not allowed. However -STATIC libraries may depend on each other in a cyclic fasion. In +STATIC libraries may depend on each other in a cyclic fashion. In general the directed dependency graph forms a directed-acyclic-graph of strongly connected components. All strongly connected components should consist of only STATIC_LIBRARY targets. diff --git a/Source/cmConfigureFileCommand.h b/Source/cmConfigureFileCommand.h index be33569fe..de497a952 100644 --- a/Source/cmConfigureFileCommand.h +++ b/Source/cmConfigureFileCommand.h @@ -34,17 +34,17 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "configure_file";} + virtual const char* GetName() const { return "configure_file";} /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Copy a file to another location and modify its contents."; } @@ -52,7 +52,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " configure_file( \n" diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index dca2fb3d5..48f644b8d 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -26,6 +26,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) const char* sourceDirectory = argv[2].c_str(); const char* projectName = 0; const char* targetName = 0; + char targetNameBuf[64]; int extraArgs = 0; // look for CMAKE_FLAGS and store them @@ -152,11 +153,11 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) std::string ccFile = this->BinaryDirectory + "/CMakeCache.txt"; cmSystemTools::RemoveFile(ccFile.c_str()); - // we need to create a directory and CMakeList file etc... + // we need to create a directory and CMakeLists file etc... // first create the directories sourceDirectory = this->BinaryDirectory.c_str(); - // now create a CMakeList.txt file in that directory + // now create a CMakeLists.txt file in that directory FILE *fout = fopen(outFileName.c_str(),"w"); if (!fout) { @@ -281,16 +282,20 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv) cmakeFlags.push_back(flag); } + /* Use a random file name to avoid rapid creation and deletion + of the same executable name (some filesystems fail on that). */ + sprintf(targetNameBuf, "cmTryCompileExec%u", + cmSystemTools::RandomSeed()); + targetName = targetNameBuf; + /* Put the executable at a known location (for COPY_FILE). */ fprintf(fout, "SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"%s\")\n", this->BinaryDirectory.c_str()); /* Create the actual executable. */ - fprintf(fout, "ADD_EXECUTABLE(cmTryCompileExec \"%s\")\n",source.c_str()); - fprintf(fout, - "TARGET_LINK_LIBRARIES(cmTryCompileExec ${LINK_LIBRARIES})\n"); + fprintf(fout, "ADD_EXECUTABLE(%s \"%s\")\n", targetName, source.c_str()); + fprintf(fout, "TARGET_LINK_LIBRARIES(%s ${LINK_LIBRARIES})\n",targetName); fclose(fout); projectName = "CMAKE_TRY_COMPILE"; - targetName = "cmTryCompileExec"; // if the source is not in CMakeTmp if(source.find("CMakeTmp") == source.npos) { diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx index 953328aa6..de20cb7ef 100644 --- a/Source/cmCreateTestSourceList.cxx +++ b/Source/cmCreateTestSourceList.cxx @@ -70,7 +70,7 @@ bool cmCreateTestSourceList if (cmSystemTools::GetFilenameExtension(*i).size() < 2) { this->SetError( - "You must specify a file extenion for the test driver file."); + "You must specify a file extension for the test driver file."); return false; } std::string driver = this->Makefile->GetCurrentOutputDirectory(); diff --git a/Source/cmCreateTestSourceList.h b/Source/cmCreateTestSourceList.h index c4c6ae74b..806e5a909 100644 --- a/Source/cmCreateTestSourceList.h +++ b/Source/cmCreateTestSourceList.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "create_test_sourcelist";} + virtual const char* GetName() const {return "create_test_sourcelist";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Create a test driver and source list for building test programs."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " create_test_sourcelist(sourceListName driverName\n" diff --git a/Source/cmDefinePropertyCommand.h b/Source/cmDefinePropertyCommand.h index 1fb78015c..55ef52137 100644 --- a/Source/cmDefinePropertyCommand.h +++ b/Source/cmDefinePropertyCommand.h @@ -32,12 +32,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "define_property";} + virtual const char* GetName() const { return "define_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Define and document custom properties."; } @@ -45,7 +45,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " define_property(LocalGenerator->GetMakefile(); - if(const char* includePath = mf->GetDefinition(includePathVar.c_str())) + includePath = mf->GetDefinition(includePathVar.c_str()); + if(includePath) { cmSystemTools::ExpandListArgument(includePath, this->IncludePath); } + else + { + // Fallback to the old directory level variable if no per-target var: + includePathVar = "CMAKE_"; + includePathVar += lang; + includePathVar += "_INCLUDE_PATH"; + includePath = mf->GetDefinition(includePathVar.c_str()); + if(includePath) + { + cmSystemTools::ExpandListArgument(includePath, this->IncludePath); + } + } } diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 9e4726cd6..c1b60905d 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -30,7 +30,7 @@ class cmDependsFortranSourceInfo { public: - // The name of the soruce file. + // The name of the source file. std::string Source; // Set of provided and required modules. @@ -810,8 +810,8 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile, * -GNU * -Intel * - * Eat the stream content until all recompile only realated changes - * are left bedind. + * Eat the stream content until all recompile only related changes + * are left behind. */ if (strcmp(compilerId, "GNU") == 0 ) { @@ -852,7 +852,7 @@ bool cmDependsFortran::ModulesDiffer(const char* modFile, } } - // Compare the remainng content. If no compiler id matched above, + // Compare the remaining content. If no compiler id matched above, // including the case none was given, this will compare the whole // content. if(!cmDependsFortranStreamsDiffer(finModFile, finStampFile)) @@ -1209,7 +1209,7 @@ void cmDependsFortranParser_RuleElif(cmDependsFortranParser* parser) * cmDependsFortranParser_RuleIf(..) */ - // Allways taken unless an #ifdef or #ifndef-branch has been taken + // Always taken unless an #ifdef or #ifndef-branch has been taken // already. If the second condition isn't meet already // (parser->InPPFalseBranch == 0) correct it. if(!parser->SkipToEnd.empty() && @@ -1228,7 +1228,7 @@ void cmDependsFortranParser_RuleElse(cmDependsFortranParser* parser) return; } - // parser->InPPFalseBranch is either 0 or 1. We change it denpending on + // parser->InPPFalseBranch is either 0 or 1. We change it depending on // parser->SkipToEnd.top() if(!parser->SkipToEnd.empty() && parser->SkipToEnd.top()) diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index fe29df9be..897e516b9 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -354,8 +354,10 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "If true, do not add run time path information.", "If this is set to TRUE, then the rpath information " "is not added to compiled executables. The default " - "is to add rpath information if the platform supports it." - "This allows for easy running from the build tree.",false, + "is to add rpath information if the platform supports it. " + "This allows for easy running from the build tree. To omit RPATH" + "in the install step, but not the build step, use " + "CMAKE_SKIP_INSTALL_RPATH instead.",false, "Variables that Provide Information"); cm->DefineProperty ("CMAKE_SOURCE_DIR", cmProperty::VARIABLE, @@ -745,6 +747,26 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "this package from the cache using the cache editor or cmake -U", false, "Variables That Change Behavior"); + cm->DefineProperty + ("CMAKE_FIND_PACKAGE_WARN_NO_MODULE", cmProperty::VARIABLE, + "Tell find_package to warn if called without an explicit mode.", + "If find_package is called without an explicit mode option " + "(MODULE, CONFIG or NO_MODULE) and no Find.cmake module is " + "in CMAKE_MODULE_PATH then CMake implicitly assumes that the " + "caller intends to search for a package configuration file. " + "If no package configuration file is found then the wording " + "of the failure message must account for both the case that the " + "package is really missing and the case that the project has a " + "bug and failed to provide the intended Find module. " + "If instead the caller specifies an explicit mode option then " + "the failure message can be more specific." + "\n" + "Set CMAKE_FIND_PACKAGE_WARN_NO_MODULE to TRUE to tell find_package " + "to warn when it implicitly assumes Config mode. " + "This helps developers enforce use of an explicit mode in all calls " + "to find_package within a project.", false, + "Variables That Change Behavior"); + cm->DefineProperty ("CMAKE_USER_MAKE_RULES_OVERRIDE", cmProperty::VARIABLE, "Specify a CMake file that overrides platform information.", @@ -895,7 +917,7 @@ void cmDocumentVariables::DefineVariables(cmake* cm) cm->DefineProperty ("BORLAND", cmProperty::VARIABLE, - "True of the borland compiler is being used.", + "True if the borland compiler is being used.", "This is set to true if the Borland compiler is being used.",false, "Variables That Describe the System"); @@ -1180,6 +1202,20 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "is always built with no RPATH.",false, "Variables that Control the Build"); + cm->DefineProperty + ("CMAKE_SKIP_INSTALL_RPATH", cmProperty::VARIABLE, + "Do not include RPATHs in the install tree.", + "Normally CMake uses the build tree for the RPATH when building " + "executables etc on systems that use RPATH. When the software " + "is installed the executables etc are relinked by CMake to have " + "the install RPATH. If this variable is set to true then the software " + "is always installed without RPATH, even if RPATH is enabled when " + "building. This can be useful for example to allow running tests from " + "the build directory with RPATH enabled before the installation step. " + "To omit RPATH in both the build and install steps, use " + "CMAKE_SKIP_RPATH instead.",false, + "Variables that Control the Build"); + cm->DefineProperty ("CMAKE_EXE_LINKER_FLAGS", cmProperty::VARIABLE, "Linker flags used to create executables.", @@ -1258,6 +1294,22 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "See that target property for additional information.", false, "Variables that Control the Build"); + cm->DefineProperty + ("CMAKE_WIN32_EXECUTABLE", cmProperty::VARIABLE, + "Default value for WIN32_EXECUTABLE of targets.", + "This variable is used to initialize the " + "WIN32_EXECUTABLE property on all the targets. " + "See that target property for additional information.", + false, + "Variables that Control the Build"); + cm->DefineProperty + ("CMAKE_MACOSX_BUNDLE", cmProperty::VARIABLE, + "Default value for MACOSX_BUNDLE of targets.", + "This variable is used to initialize the " + "MACOSX_BUNDLE property on all the targets. " + "See that target property for additional information.", + false, + "Variables that Control the Build"); // Variables defined when the a language is enabled These variables will // also be defined whenever CMake has loaded its support for compiling (LANG) @@ -1300,6 +1352,15 @@ void cmDocumentVariables::DefineVariables(cmake* cm) false, "Variables for Languages"); + cm->DefineProperty + ("CMAKE__COMPILER_VERSION", cmProperty::VARIABLE, + "An internal variable subject to change.", + "Compiler version in major[.minor[.patch[.tweak]]] format. " + "This variable is reserved for internal use by CMake and is not " + "guaranteed to be set.", + false, + "Variables for Languages"); + cm->DefineProperty ("CMAKE_INTERNAL_PLATFORM_ABI", cmProperty::VARIABLE, "An internal variable subject to change.", diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index 07683d084..904a157b6 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -14,7 +14,9 @@ #include "cmSystemTools.h" #include "cmVersion.h" #include +#include +#include //---------------------------------------------------------------------------- static const char *cmDocumentationStandardOptions[][3] = @@ -220,55 +222,7 @@ cmDocumentation::cmDocumentation() :CurrentFormatter(0) { this->SetForm(TextForm); - - cmDocumentationSection *sec; - - sec = new cmDocumentationSection("Author","AUTHOR"); - sec->Append(cmDocumentationEntry - (0, - "This manual page was generated by the \"--help-man\" option.", - 0)); - this->AllSections["Author"] = sec; - - sec = new cmDocumentationSection("Copyright","COPYRIGHT"); - sec->Append(cmDocumentationCopyright); - this->AllSections["Copyright"] = sec; - - sec = new cmDocumentationSection("See Also","SEE ALSO"); - sec->Append(cmDocumentationStandardSeeAlso); - this->AllSections["Standard See Also"] = sec; - - sec = new cmDocumentationSection("Options","OPTIONS"); - sec->Append(cmDocumentationStandardOptions); - this->AllSections["Options"] = sec; - - sec = new cmDocumentationSection("Properties","PROPERTIES"); - sec->Append(cmPropertiesDocumentationDescription); - this->AllSections["Properties Description"] = sec; - - sec = new cmDocumentationSection("Generators","GENERATORS"); - sec->Append(cmDocumentationGeneratorsHeader); - this->AllSections["Generators"] = sec; - - sec = new cmDocumentationSection("Compatibility Commands", - "COMPATIBILITY COMMANDS"); - sec->Append(cmCompatCommandsDocumentationDescription); - this->AllSections["Compatibility Commands"] = sec; - - - this->PropertySections.push_back("Properties of Global Scope"); - this->PropertySections.push_back("Properties on Directories"); - this->PropertySections.push_back("Properties on Targets"); - this->PropertySections.push_back("Properties on Tests"); - this->PropertySections.push_back("Properties on Source Files"); - this->PropertySections.push_back("Properties on Cache Entries"); - - this->VariableSections.push_back("Variables that Provide Information"); - this->VariableSections.push_back("Variables That Change Behavior"); - this->VariableSections.push_back("Variables That Describe the System"); - this->VariableSections.push_back("Variables that Control the Build"); - this->VariableSections.push_back("Variables for Languages"); - + this->addCommonStandardDocSections(); this->ShowGenerators = true; } @@ -559,6 +513,8 @@ bool cmDocumentation::CreateSingleModule(const char* fname, { if(line.size() && line[0] == '#') { + /* line beginnings with ## are mark-up ignore them */ + if (line.size()>=2 && line[1] == '#') continue; // blank line if(line.size() <= 2) { @@ -709,6 +665,423 @@ cmDocumentation::Form cmDocumentation::GetFormFromFilename( return cmDocumentation::TextForm; } +//---------------------------------------------------------------------------- +void cmDocumentation::addCommonStandardDocSections() +{ + cmDocumentationSection *sec; + + sec = new cmDocumentationSection("Author","AUTHOR"); + sec->Append(cmDocumentationEntry + (0, + "This manual page was generated by the \"--help-man\" option.", + 0)); + this->AllSections["Author"] = sec; + + sec = new cmDocumentationSection("Copyright","COPYRIGHT"); + sec->Append(cmDocumentationCopyright); + this->AllSections["Copyright"] = sec; + + sec = new cmDocumentationSection("See Also","SEE ALSO"); + sec->Append(cmDocumentationStandardSeeAlso); + this->AllSections["Standard See Also"] = sec; + + sec = new cmDocumentationSection("Options","OPTIONS"); + sec->Append(cmDocumentationStandardOptions); + this->AllSections["Options"] = sec; + + sec = new cmDocumentationSection("Compatibility Commands", + "COMPATIBILITY COMMANDS"); + sec->Append(cmCompatCommandsDocumentationDescription); + this->AllSections["Compatibility Commands"] = sec; +} + +//---------------------------------------------------------------------------- +void cmDocumentation::addCMakeStandardDocSections() +{ + cmDocumentationSection *sec; + + sec = new cmDocumentationSection("Properties","PROPERTIES"); + sec->Append(cmPropertiesDocumentationDescription); + this->AllSections["Properties Description"] = sec; + + sec = new cmDocumentationSection("Generators","GENERATORS"); + sec->Append(cmDocumentationGeneratorsHeader); + this->AllSections["Generators"] = sec; + + this->PropertySections.push_back("Properties of Global Scope"); + this->PropertySections.push_back("Properties on Directories"); + this->PropertySections.push_back("Properties on Targets"); + this->PropertySections.push_back("Properties on Tests"); + this->PropertySections.push_back("Properties on Source Files"); + this->PropertySections.push_back("Properties on Cache Entries"); + + this->VariableSections.push_back("Variables that Provide Information"); + this->VariableSections.push_back("Variables That Change Behavior"); + this->VariableSections.push_back("Variables That Describe the System"); + this->VariableSections.push_back("Variables that Control the Build"); + this->VariableSections.push_back("Variables for Languages"); + +} + +//---------------------------------------------------------------------------- +void cmDocumentation::addCTestStandardDocSections() +{ + // This is currently done for backward compatibility reason + // We may suppress some of these. + addCMakeStandardDocSections(); +} + +//---------------------------------------------------------------------------- +void cmDocumentation::addCPackStandardDocSections() +{ + cmDocumentationSection *sec; + + sec = new cmDocumentationSection("Generators","GENERATORS"); + sec->Append(cmDocumentationGeneratorsHeader); + this->AllSections["Generators"] = sec; + + this->VariableSections.push_back( + "Variables common to all CPack generators"); +} + +void cmDocumentation::addAutomaticVariableSections(const std::string& section) +{ + std::vector::iterator it; + it = std::find(this->VariableSections.begin(), + this->VariableSections.end(), + section); + /* if the section does not exist then add it */ + if (it==this->VariableSections.end()) + { + this->VariableSections.push_back(section); + } +} +//---------------------------------------------------------------------------- +int cmDocumentation::getDocumentedModulesListInDir( + std::string path, + std::string globExpr, + documentedModulesList_t& docedModuleList) +{ + cmsys::Glob gl; + std::string findExpr; + std::vector files; + std::string line; + documentedModuleSectionPair_t docPair; + int nbDocumentedModules = 0; + + findExpr = path + "/" + globExpr; + if (gl.FindFiles(findExpr)) + { + files = gl.GetFiles(); + for (std::vector::iterator itf=files.begin(); + itf!=files.end();++itf) + { + std::ifstream fin((*itf).c_str()); + // file access trouble ignore it (ignore this kind of error) + if (!fin) continue; + /* read first line in order to get doc section */ + if (cmSystemTools::GetLineFromStream(fin, line)) + { + /* Doc section indicates that + * this file has structured doc in it. + */ + if (line.find("##section")!=std::string::npos) + { + // ok found one more documented module + ++nbDocumentedModules; + docPair.first = *itf; + // 10 is the size of '##section' + 1 + docPair.second = line.substr(10,std::string::npos); + docedModuleList.push_back(docPair); + } + // No else if no section is found (undocumented module) + } + // No else cannot read first line (ignore this kind of error) + line = ""; + } + } + if (nbDocumentedModules>0) + { + return 0; + } + else + { + return 1; + } +} + +//---------------------------------------------------------------------------- +static void trim(std::string& s) +{ + std::string::size_type pos = s.find_last_not_of(' '); + if(pos != std::string::npos) + { + s.erase(pos + 1); + pos = s.find_first_not_of(' '); + if(pos != std::string::npos) s.erase(0, pos); + } + else + { + s.erase(s.begin(), s.end()); + } +} + +int cmDocumentation::GetStructuredDocFromFile( + const char* fname, + std::vector& commands, + cmake* cm) +{ + typedef enum sdoce { + SDOC_NONE, SDOC_MODULE, SDOC_MACRO, SDOC_FUNCTION, SDOC_VARIABLE, + SDOC_SECTION, + SDOC_UNKNOWN} sdoc_t; + int nbDocItemFound = 0; + int docCtxIdx = 0; + std::vector docContextStack(60); + docContextStack[docCtxIdx]=SDOC_NONE; + cmDocumentationEntry e; + std::ifstream fin(fname); + if(!fin) + { + return nbDocItemFound; + } + std::string section; + std::string name; + std::string full; + std::string brief; + std::string line; + bool newCtx = false; /* we've just entered ## context */ + bool inBrief = false; /* we are currently parsing brief desc. */ + bool inFullFirstParagraph = false; /* we are currently parsing full + desc. first paragraph */ + brief = ""; + full = ""; + bool newParagraph = true; + while ( fin && cmSystemTools::GetLineFromStream(fin, line) ) + { + if(line.size() && line[0] == '#') + { + /* handle structured doc context */ + if ((line.size()>=2) && line[1]=='#') + { + /* markup word is following '##' stopping at first space + * Some markup word like 'section' may have more characters + * following but we don't handle those here. + */ + std::string mkword = line.substr(2,line.find(' ',2)-2); + if (mkword=="macro") + { + docCtxIdx++; + docContextStack[docCtxIdx]=SDOC_MACRO; + newCtx = true; + } + else if (mkword=="variable") + { + docCtxIdx++; + docContextStack[docCtxIdx]=SDOC_VARIABLE; + newCtx = true; + } + else if (mkword=="function") + { + docCtxIdx++; + docContextStack[docCtxIdx]=SDOC_FUNCTION; + newCtx = true; + } + else if (mkword=="module") + { + docCtxIdx++; + docContextStack[docCtxIdx]=SDOC_MODULE; + newCtx = true; + } + else if (mkword=="section") + { + docCtxIdx++; + docContextStack[docCtxIdx]=SDOC_SECTION; + // 10 is the size of '##section' + 1 + section = line.substr(10,std::string::npos); + /* drop the rest of the line */ + line = ""; + newCtx = true; + } + else if (mkword.substr(0,3)=="end") + { + switch (docContextStack[docCtxIdx]) { + case SDOC_MACRO: + /* for now MACRO and FUNCTION are handled in the same way */ + case SDOC_FUNCTION: + commands.push_back(cmDocumentationEntry(name.c_str(), + brief.c_str(),full.c_str())); + break; + case SDOC_VARIABLE: + this->addAutomaticVariableSections(section); + cm->DefineProperty + (name.c_str(), cmProperty::VARIABLE, + brief.c_str(), + full.c_str(),false, + section.c_str()); + break; + case SDOC_MODULE: + /* not implemented */ + break; + case SDOC_SECTION: + /* not implemented */ + break; + default: + /* ignore other cases */ + break; + } + docCtxIdx--; + newCtx = false; + ++nbDocItemFound; + } + else + { + // error out unhandled context + return nbDocItemFound; + } + /* context is set go to next doc line */ + continue; + } + + // Now parse the text attached to the context + + // The first line after the context mark-up contains:: + // name - brief until. (brief is dot terminated or + // followed by a blank line) + if (newCtx) + { + // no brief (for easy variable definition) + if (line.find("-")==std::string::npos) + { + name = line.substr(1,std::string::npos); + trim(name); + brief = ""; + inBrief = false; + full = ""; + } + // here we have a name and brief beginning + else + { + name = line.substr(1,line.find("-")-1); + trim(name); + // we are parsing the brief context + brief = line.substr(line.find("-")+1,std::string::npos); + trim(brief); + // Brief may already be terminated on the first line + if (brief.find('.')!=std::string::npos) + { + inBrief = false; + full = brief.substr(brief.find('.')+1,std::string::npos); + trim(full); + inFullFirstParagraph = true; + brief = brief.substr(0,brief.find('.')); + } + // brief is continued on following lines + else + { + inBrief = true; + full = ""; + } + } + newCtx = false; + continue; + } + // blank line + if(line.size() <= 2) + { + if (inBrief) { + inBrief = false; + full = ""; + } else { + if (full.length()>0) + { + full += "\n"; + } + // the first paragraph of full has ended + inFullFirstParagraph = false; + } + newParagraph = true; + } + // brief is terminated by '.' + else if (inBrief && (line.find('.')!=std::string::npos)) + { + /* the brief just ended */ + inBrief = false; + std::string endBrief = line.substr(1,line.find('.')); + trim(endBrief); + trim(brief); + brief += " " + endBrief; + full += line.substr(line.find('.')+1,std::string::npos); + trim(full); + inFullFirstParagraph = true; + } + // we handle full text or multi-line brief. + else + { + std::string* text; + if (inBrief) + { + text = &brief; + } + else + { + text = &full; + } + // two spaces + if(line[1] == ' ' && line[2] == ' ') + { + // there is no "full first paragraph at all." + if (line[3] == ' ') + { + inFullFirstParagraph = false; + } + + if(!newParagraph && !inFullFirstParagraph) + { + *text += "\n"; + newParagraph = true; + } + // Skip #, and leave space for pre-formatted + if (inFullFirstParagraph) + { + std::string temp = line.c_str()+1; + trim(temp); + *text += " " + temp; + } + else + { + *text += line.c_str()+1; + *text += "\n"; + } + } + else if(line[1] == ' ') + { + if(!newParagraph) + { + *text += " "; + } + newParagraph = false; + // skip # and space + *text += line.c_str()+2; + } + else + { + if(!newParagraph) + { + *text += " "; + } + newParagraph = false; + // skip # + *text += line.c_str()+1; + } + } + } + /* next line is not the first context line */ + newCtx = false; + } + return nbDocItemFound; +} + //---------------------------------------------------------------------------- bool cmDocumentation::CheckOptions(int argc, const char* const* argv, const char* exitOpt) diff --git a/Source/cmDocumentation.h b/Source/cmDocumentation.h index 34b83b1a4..11bef1677 100644 --- a/Source/cmDocumentation.h +++ b/Source/cmDocumentation.h @@ -21,6 +21,7 @@ #include "cmDocumentationFormatterText.h" #include "cmDocumentationFormatterUsage.h" #include "cmDocumentationSection.h" +#include "cmake.h" namespace cmsys { @@ -34,6 +35,21 @@ public: cmDocumentation(); ~cmDocumentation(); + + /** + * An helper type pair for [structured] documented modules. + * The comment of those module contains structure markup + * which makes it possible to retrieve the documentation + * of variables, macros and functions defined in the module. + * - first is the filename of the module + * - second is the section of the doc the module belongs too + */ + typedef std::pair documentedModuleSectionPair_t; + /** + * A list of documented module(s). + */ + typedef std::list documentedModulesList_t; + // High-level interface for standard documents: /** @@ -119,6 +135,60 @@ public: static Form GetFormFromFilename(const std::string& filename); + /** Add common (to all tools) documentation section(s) */ + void addCommonStandardDocSections(); + + /** Add the CMake standard documentation section(s) */ + void addCMakeStandardDocSections(); + + /** Add the CTest standard documentation section(s) */ + void addCTestStandardDocSections(); + + /** Add the CPack standard documentation section(s) */ + void addCPackStandardDocSections(); + + /** Add automatic variables sections */ + void addAutomaticVariableSections(const std::string& section); + + /** + * Retrieve the list of documented module located in + * path which match the globing expression globExpr. + * @param[in] path, directory where to start the search + * we will recurse into it. + * @param[in] globExpr, the globing expression used to + * match the file in path. + * @param[out] the list of obtained pairs (may be empty) + * @return 0 on success 1 on error or empty list + */ + int getDocumentedModulesListInDir( + std::string path, + std::string globExpr, + documentedModulesList_t& docModuleList); + + /** + * Get the documentation of macros, functions and variable documented + * with CMake structured documentation in a CMake script. + * (in fact it may be in any file which follow the structured doc format) + * Structured documentation begin with + * ## (double sharp) in column 1 & 2 immediately followed + * by a markup. Those ## are ignored by the legacy module + * documentation parser @see CreateSingleModule. + * Current markup are ##section, ##module, + * ##macro, ##function, ##variable and ##end. + * ##end is closing either of the previous ones. + * @param[in] fname the script file name to be parsed for documentation + * @param[in,out] commands the vector of command/macros documentation + * entry found in the script file. + * @param[in,out] the cmake object instance to which variable documentation + * will be attached (using @see cmake::DefineProperty) + * @param[in] the documentation section in which the property will be + * inserted. + * @return the number of documented items (command and variable) + * found in the file. + */ + int GetStructuredDocFromFile(const char* fname, + std::vector& commands, + cmake* cm); private: void SetForm(Form f); void SetDocName(const char* docname); diff --git a/Source/cmElseCommand.h b/Source/cmElseCommand.h index bbe31f472..5e8b79058 100644 --- a/Source/cmElseCommand.h +++ b/Source/cmElseCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "else";} + virtual const char* GetName() const { return "else";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Starts the else portion of an if block."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " else(expression)\n" diff --git a/Source/cmElseIfCommand.h b/Source/cmElseIfCommand.h index cca5fb80b..20cd81aaa 100644 --- a/Source/cmElseIfCommand.h +++ b/Source/cmElseIfCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "elseif";} + virtual const char* GetName() const { return "elseif";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Starts the elseif portion of an if block."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " elseif(expression)\n" diff --git a/Source/cmEnableLanguageCommand.h b/Source/cmEnableLanguageCommand.h index e9341195e..5958e4481 100644 --- a/Source/cmEnableLanguageCommand.h +++ b/Source/cmEnableLanguageCommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "enable_language";} + virtual const char* GetName() const {return "enable_language";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Enable a language (CXX/C/Fortran/etc)"; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " enable_language(languageName [OPTIONAL] )\n" diff --git a/Source/cmEnableTestingCommand.h b/Source/cmEnableTestingCommand.h index 736124153..b607818ce 100644 --- a/Source/cmEnableTestingCommand.h +++ b/Source/cmEnableTestingCommand.h @@ -48,12 +48,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "enable_testing";} + virtual const char* GetName() const { return "enable_testing";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Enable testing for current directory and below."; } @@ -61,7 +61,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " enable_testing()\n" diff --git a/Source/cmEndForEachCommand.h b/Source/cmEndForEachCommand.h index 7ceb39d2b..37b2d2a32 100644 --- a/Source/cmEndForEachCommand.h +++ b/Source/cmEndForEachCommand.h @@ -47,17 +47,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "endforeach";} + virtual const char* GetName() const { return "endforeach";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Ends a list of commands in a FOREACH block."; } @@ -65,7 +65,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " endforeach(expression)\n" diff --git a/Source/cmEndFunctionCommand.h b/Source/cmEndFunctionCommand.h index 2d58c9df2..54ac068f3 100644 --- a/Source/cmEndFunctionCommand.h +++ b/Source/cmEndFunctionCommand.h @@ -47,17 +47,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "endfunction";} + virtual const char* GetName() const { return "endfunction";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Ends a list of commands in a function block."; } @@ -65,7 +65,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " endfunction(expression)\n" diff --git a/Source/cmEndIfCommand.h b/Source/cmEndIfCommand.h index f0af8c60b..81d1b5ff4 100644 --- a/Source/cmEndIfCommand.h +++ b/Source/cmEndIfCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "endif";} + virtual const char* GetName() const { return "endif";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Ends a list of commands in an if block."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " endif(expression)\n" diff --git a/Source/cmEndMacroCommand.h b/Source/cmEndMacroCommand.h index 52b7e82ff..25e86b70f 100644 --- a/Source/cmEndMacroCommand.h +++ b/Source/cmEndMacroCommand.h @@ -47,17 +47,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "endmacro";} + virtual const char* GetName() const { return "endmacro";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Ends a list of commands in a macro block."; } @@ -65,7 +65,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " endmacro(expression)\n" diff --git a/Source/cmEndWhileCommand.cxx b/Source/cmEndWhileCommand.cxx index bb4d40a47..abb9e5e0b 100644 --- a/Source/cmEndWhileCommand.cxx +++ b/Source/cmEndWhileCommand.cxx @@ -12,12 +12,21 @@ #include "cmEndWhileCommand.h" bool cmEndWhileCommand -::InvokeInitialPass(std::vector const&, +::InvokeInitialPass(std::vector const& args, cmExecutionStatus &) { - this->SetError("An ENDWHILE command was found outside of a proper " - "WHILE ENDWHILE structure. Or its arguments did not " - "match the opening WHILE command."); + if (args.empty()) + { + this->SetError("An ENDWHILE command was found outside of a proper " + "WHILE ENDWHILE structure."); + } + else + { + this->SetError("An ENDWHILE command was found outside of a proper " + "WHILE ENDWHILE structure. Or its arguments did not " + "match the opening WHILE command."); + } + return false; } diff --git a/Source/cmEndWhileCommand.h b/Source/cmEndWhileCommand.h index 8e0b488f5..635ad5a7f 100644 --- a/Source/cmEndWhileCommand.h +++ b/Source/cmEndWhileCommand.h @@ -34,7 +34,7 @@ public: * Override cmCommand::InvokeInitialPass to get arguments before * expansion. */ - virtual bool InvokeInitialPass(std::vector const&, + virtual bool InvokeInitialPass(std::vector const& args, cmExecutionStatus &status); /** @@ -47,17 +47,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "endwhile";} + virtual const char* GetName() const { return "endwhile";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Ends a list of commands in a while block."; } @@ -65,7 +65,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " endwhile(expression)\n" diff --git a/Source/cmExecProgramCommand.h b/Source/cmExecProgramCommand.h index ef3a73272..723386099 100644 --- a/Source/cmExecProgramCommand.h +++ b/Source/cmExecProgramCommand.h @@ -42,18 +42,18 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() + virtual const char* GetName() const {return "exec_program";} /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the execute_process() command instead."; @@ -62,7 +62,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "Run an executable program during the processing of the CMakeList.txt" @@ -84,7 +84,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h index 3cd8f01d8..0e20a4b19 100644 --- a/Source/cmExecuteProcessCommand.h +++ b/Source/cmExecuteProcessCommand.h @@ -41,18 +41,18 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() + virtual const char* GetName() const {return "execute_process";} /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Execute one or more child processes."; } @@ -60,7 +60,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " execute_process(COMMAND [args1...]]\n" diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index cb614d4f3..1cc17545a 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -124,6 +124,14 @@ bool cmExportCommand { targets.push_back(target); } + else if(target->GetType() == cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "given OBJECT library \"" << *currentTarget + << "\" which may not be exported."; + this->SetError(e.str().c_str()); + return false; + } else { cmOStringStream e; diff --git a/Source/cmExportCommand.h b/Source/cmExportCommand.h index eb19d2ef4..ae67b4762 100644 --- a/Source/cmExportCommand.h +++ b/Source/cmExportCommand.h @@ -45,12 +45,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "export";} + virtual const char* GetName() const { return "export";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Export targets from the build tree for use by outside projects."; @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " export(TARGETS [target1 [target2 [...]]] [NAMESPACE ]\n" diff --git a/Source/cmExportLibraryDependencies.h b/Source/cmExportLibraryDependencies.h index 32c262f69..2a2ff215e 100644 --- a/Source/cmExportLibraryDependencies.h +++ b/Source/cmExportLibraryDependencies.h @@ -48,12 +48,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "export_library_dependencies";} + virtual const char* GetName() const { return "export_library_dependencies";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use INSTALL(EXPORT) or EXPORT command."; } @@ -61,7 +61,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command generates an old-style library dependencies file. " @@ -83,7 +83,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx index ee373523d..7728d740b 100644 --- a/Source/cmExprParserHelper.cxx +++ b/Source/cmExprParserHelper.cxx @@ -30,12 +30,6 @@ cmExprParserHelper::~cmExprParserHelper() this->CleanupParser(); } -void cmExprParserHelper::SetLineFile(long line, const char* file) -{ - this->FileLine = line; - this->FileName = file; -} - int cmExprParserHelper::ParseString(const char* str, int verb) { if ( !str) diff --git a/Source/cmExprParserHelper.h b/Source/cmExprParserHelper.h index 0c36b443f..690426d8d 100644 --- a/Source/cmExprParserHelper.h +++ b/Source/cmExprParserHelper.h @@ -46,8 +46,6 @@ public: int GetResult() { return this->Result; } - void SetLineFile(long line, const char* file); - const char* GetError() { return this->ErrorString.c_str(); } private: @@ -55,7 +53,6 @@ private: cmStdString InputBuffer; std::vector OutputBuffer; int CurrentLine; - int UnionsAvailable; int Verbose; void Print(const char* place, const char* str); diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 38002ec48..ccb17f099 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -392,10 +392,6 @@ void cmExtraCodeBlocksGenerator make.c_str(), makefile, compiler.c_str()); } break; - // ignore these: - case cmTarget::INSTALL_FILES: - case cmTarget::INSTALL_PROGRAMS: - case cmTarget::INSTALL_DIRECTORY: default: break; } @@ -600,16 +596,17 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout, // the include directories for this target std::set uniqIncludeDirs; - const std::vector& incDirs = - target->GetMakefile()->GetIncludeDirectories(); - for(std::vector::const_iterator dirIt=incDirs.begin(); - dirIt != incDirs.end(); + + std::vector includes; + target->GetMakefile()->GetLocalGenerator()-> + GetIncludeDirectories(includes, target); + for(std::vector::const_iterator dirIt=includes.begin(); + dirIt != includes.end(); ++dirIt) { uniqIncludeDirs.insert(*dirIt); } - std::string systemIncludeDirs = makefile->GetSafeDefinition( "CMAKE_EXTRA_GENERATOR_C_SYSTEM_INCLUDE_DIRS"); if (!systemIncludeDirs.empty()) diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 07549e918..65077b30b 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -501,6 +501,7 @@ void cmExtraEclipseCDT4Generator::CreateLinksForTargets( case cmTarget::STATIC_LIBRARY: case cmTarget::SHARED_LIBRARY: case cmTarget::MODULE_LIBRARY: + case cmTarget::OBJECT_LIBRARY: { const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ? "[exe] " : "[lib] "); @@ -893,9 +894,13 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const it != this->GlobalGenerator->GetLocalGenerators().end(); ++it) { - const std::vector& includeDirs - = (*it)->GetMakefile()->GetIncludeDirectories(); - this->AppendIncludeDirectories(fout, includeDirs, emmited); + cmTargets & targets = (*it)->GetMakefile()->GetTargets(); + for (cmTargets::iterator l = targets.begin(); l != targets.end(); ++l) + { + std::vector includeDirs; + (*it)->GetIncludeDirectories(includeDirs, &l->second); + this->AppendIncludeDirectories(fout, includeDirs, emmited); + } } // now also the system include directories, in case we found them in // CMakeSystemSpecificInformation.cmake. This makes Eclipse find the @@ -1013,6 +1018,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const case cmTarget::STATIC_LIBRARY: case cmTarget::SHARED_LIBRARY: case cmTarget::MODULE_LIBRARY: + case cmTarget::OBJECT_LIBRARY: { const char* prefix = (ti->second.GetType()==cmTarget::EXECUTABLE ? "[exe] " : "[lib] "); @@ -1045,10 +1051,6 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const } } break; - // ignore these: - case cmTarget::INSTALL_FILES: - case cmTarget::INSTALL_PROGRAMS: - case cmTarget::INSTALL_DIRECTORY: default: break; } diff --git a/Source/cmFLTKWrapUICommand.h b/Source/cmFLTKWrapUICommand.h index 6ecdbcce8..cb0f9d534 100644 --- a/Source/cmFLTKWrapUICommand.h +++ b/Source/cmFLTKWrapUICommand.h @@ -52,12 +52,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "fltk_wrap_ui";} + virtual const char* GetName() const { return "fltk_wrap_ui";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Create FLTK user interfaces Wrappers."; } @@ -65,7 +65,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " fltk_wrap_ui(resultingLibraryName source1\n" diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 6df5ab38f..3f14fa1e1 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -12,6 +12,7 @@ #include "cmFileCommand.h" #include "cmake.h" #include "cmHexFileConverter.h" +#include "cmInstallType.h" #include "cmFileTimeComparison.h" #include "cmCryptoHash.h" @@ -1690,7 +1691,7 @@ struct cmFileInstaller: public cmFileCopier { cmFileInstaller(cmFileCommand* command): cmFileCopier(command, "INSTALL"), - InstallType(cmTarget::INSTALL_FILES), + InstallType(cmInstallType_FILES), Optional(false), DestDirLength(0) { @@ -1711,7 +1712,7 @@ struct cmFileInstaller: public cmFileCopier } protected: - cmTarget::TargetType InstallType; + cmInstallType InstallType; bool Optional; int DestDirLength; std::string Rename; @@ -1745,7 +1746,7 @@ protected: virtual bool Install(const char* fromFile, const char* toFile) { // Support installing from empty source to make a directory. - if(this->InstallType == cmTarget::INSTALL_DIRECTORY && !*fromFile) + if(this->InstallType == cmInstallType_DIRECTORY && !*fromFile) { return this->InstallDirectory(fromFile, toFile, MatchProperties()); } @@ -1767,14 +1768,14 @@ protected: // Add execute permissions based on the target type. switch(this->InstallType) { - case cmTarget::SHARED_LIBRARY: - case cmTarget::MODULE_LIBRARY: + case cmInstallType_SHARED_LIBRARY: + case cmInstallType_MODULE_LIBRARY: if(this->Makefile->IsOn("CMAKE_INSTALL_SO_NO_EXE")) { break; } - case cmTarget::EXECUTABLE: - case cmTarget::INSTALL_PROGRAMS: + case cmInstallType_EXECUTABLE: + case cmInstallType_PROGRAMS: this->FilePermissions |= mode_owner_execute; this->FilePermissions |= mode_group_execute; this->FilePermissions |= mode_world_execute; @@ -1796,8 +1797,8 @@ bool cmFileInstaller::Parse(std::vector const& args) if(!this->Rename.empty()) { - if(this->InstallType != cmTarget::INSTALL_FILES && - this->InstallType != cmTarget::INSTALL_PROGRAMS) + if(this->InstallType != cmInstallType_FILES && + this->InstallType != cmInstallType_PROGRAMS) { this->FileCommand->SetError("INSTALL option RENAME may be used " "only with FILES or PROGRAMS."); @@ -1936,31 +1937,31 @@ bool cmFileInstaller { if ( stype == "EXECUTABLE" ) { - this->InstallType = cmTarget::EXECUTABLE; + this->InstallType = cmInstallType_EXECUTABLE; } else if ( stype == "FILE" ) { - this->InstallType = cmTarget::INSTALL_FILES; + this->InstallType = cmInstallType_FILES; } else if ( stype == "PROGRAM" ) { - this->InstallType = cmTarget::INSTALL_PROGRAMS; + this->InstallType = cmInstallType_PROGRAMS; } else if ( stype == "STATIC_LIBRARY" ) { - this->InstallType = cmTarget::STATIC_LIBRARY; + this->InstallType = cmInstallType_STATIC_LIBRARY; } else if ( stype == "SHARED_LIBRARY" ) { - this->InstallType = cmTarget::SHARED_LIBRARY; + this->InstallType = cmInstallType_SHARED_LIBRARY; } else if ( stype == "MODULE" ) { - this->InstallType = cmTarget::MODULE_LIBRARY; + this->InstallType = cmInstallType_MODULE_LIBRARY; } else if ( stype == "DIRECTORY" ) { - this->InstallType = cmTarget::INSTALL_DIRECTORY; + this->InstallType = cmInstallType_DIRECTORY; } else { diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 9e2ed0fbd..ced26c49b 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -41,17 +41,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "file";} + virtual const char* GetName() const { return "file";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "File manipulation command."; } @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " file(WRITE filename \"message to write\"... )\n" @@ -152,7 +152,8 @@ public: "TO_CMAKE_PATH will convert path into a cmake style path with unix /. " " The input can be a single path or a system path like \"$ENV{PATH}\". " " Note the double quotes around the ENV call TO_CMAKE_PATH only takes " - " one argument.\n" + " one argument. This command will also convert the native list" + " delimiters for a list of paths like the PATH environment variable.\n" "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from " " a cmake style path into the native path style \\ for windows and / " "for UNIX.\n" diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 183da4a79..fb8bcf78d 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -108,11 +108,11 @@ void cmFindBase::GenerateDocumentation() } //---------------------------------------------------------------------------- -const char* cmFindBase::GetFullDocumentation() +const char* cmFindBase::GetFullDocumentation() const { if(this->GenericDocumentation.empty()) { - this->GenerateDocumentation(); + const_cast(this)->GenerateDocumentation(); } return this->GenericDocumentation.c_str(); } diff --git a/Source/cmFindBase.h b/Source/cmFindBase.h index de319b1d1..37ab2ecd2 100644 --- a/Source/cmFindBase.h +++ b/Source/cmFindBase.h @@ -31,7 +31,7 @@ public: virtual bool ParseArguments(std::vector const& args); cmTypeMacro(cmFindBase, cmFindCommon); - virtual const char* GetFullDocumentation(); + virtual const char* GetFullDocumentation() const; protected: virtual void GenerateDocumentation(); diff --git a/Source/cmFindFileCommand.h b/Source/cmFindFileCommand.h index dd2e01d9d..7d349d33c 100644 --- a/Source/cmFindFileCommand.h +++ b/Source/cmFindFileCommand.h @@ -33,12 +33,12 @@ public: { return new cmFindFileCommand; } - virtual const char* GetName() { return "find_file";} + virtual const char* GetName() const { return "find_file";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Find the full path to a file."; } diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx index 2fa2ccaa2..6cdbbf2dc 100644 --- a/Source/cmFindLibraryCommand.cxx +++ b/Source/cmFindLibraryCommand.cxx @@ -57,7 +57,13 @@ void cmFindLibraryCommand::GenerateDocumentation() "the full path to the framework /A.framework. " "When a full path to a framework is used as a library, " "CMake will use a -framework A, and a -F to " - "link the framework to the target. "; + "link the framework to the target." + "\n" + "If the global property FIND_LIBRARY_USE_LIB64_PATHS is set all search " + "paths will be tested as normal, with \"64/\" appended, and with all " + "matches of \"lib/\" replaced with \"lib64/\". This property is " + "automatically set for the platforms that are known to need it if at " + "least one of the languages supported by the PROJECT command is enabled."; } // cmFindLibraryCommand @@ -354,13 +360,23 @@ void cmFindLibraryHelper::RegexFromList(std::string& out, //---------------------------------------------------------------------------- bool cmFindLibraryHelper::HasValidSuffix(std::string const& name) { - // Check if the given name ends in a valid library suffix. for(std::vector::const_iterator si = this->Suffixes.begin(); si != this->Suffixes.end(); ++si) { - std::string const& suffix = *si; - if(name.length() > suffix.length() && - name.substr(name.size()-suffix.length()) == suffix) + std::string suffix = *si; + if(name.length() <= suffix.length()) + { + continue; + } + // Check if the given name ends in a valid library suffix. + if(name.substr(name.size()-suffix.length()) == suffix) + { + return true; + } + // Check if a valid library suffix is somewhere in the name, + // this may happen e.g. for versioned shared libraries: libfoo.so.2 + suffix += "."; + if(name.find(suffix) != name.npos) { return true; } diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h index 7930f521d..b880be266 100644 --- a/Source/cmFindLibraryCommand.h +++ b/Source/cmFindLibraryCommand.h @@ -44,17 +44,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "find_library";} + virtual const char* GetName() const {return "find_library";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Find a library."; } diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index 7d3f09bda..ef16ce85f 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -57,7 +57,8 @@ cmFindPackageCommand::cmFindPackageCommand() this->NoUserRegistry = false; this->NoSystemRegistry = false; this->NoBuilds = false; - this->NoModule = false; + this->UseConfigFiles = true; + this->UseFindModules = true; this->DebugMode = false; this->UseLib64Paths = false; this->PolicyScope = true; @@ -72,6 +73,7 @@ cmFindPackageCommand::cmFindPackageCommand() this->VersionFoundPatch = 0; this->VersionFoundTweak = 0; this->VersionFoundCount = 0; + this->RequiredCMakeVersion = 0; } //---------------------------------------------------------------------------- @@ -86,19 +88,25 @@ void cmFindPackageCommand::GenerateDocumentation() cmSystemTools::ReplaceString(this->GenericDocumentationPathsOrder, "FIND_XXX", "find_package"); this->CommandDocumentation = - " find_package( [version] [EXACT] [QUIET]\n" + " find_package( [version] [EXACT] [QUIET] [MODULE]\n" " [[REQUIRED|COMPONENTS] [components...]]\n" + " [OPTIONAL_COMPONENTS components...]\n" " [NO_POLICY_SCOPE])\n" "Finds and loads settings from an external project. " "_FOUND will be set to indicate whether the package was found. " "When the package is found package-specific information is provided " "through variables documented by the package itself. " "The QUIET option disables messages if the package cannot be found. " + "The MODULE option disables the second signature documented below. " "The REQUIRED option stops processing with an error message if the " - "package cannot be found. " - "A package-specific list of components may be listed after the " - "REQUIRED option or after the COMPONENTS option if no REQUIRED " - "option is given. " + "package cannot be found." + "\n" + "A package-specific list of required components may be listed after the " + "COMPONENTS option or directly after the REQUIRED option. " + "Additional optional components may be listed after OPTIONAL_COMPONENTS. " + "Available components and their influence on whether a package is " + "considered to be found are defined by the target package." + "\n" "The [version] argument requests a version with which the package found " "should be compatible (format is major[.minor[.patch[.tweak]]]). " "The EXACT option requests that the version be matched exactly. " @@ -124,10 +132,12 @@ void cmFindPackageCommand::GenerateDocumentation() "and producing any needed messages. " "Many find-modules provide limited or no support for versioning; " "check the module documentation. " - "If no module is found the command proceeds to Config mode.\n" + "If no module is found and the MODULE option is not given the command " + "proceeds to Config mode.\n" "The complete Config mode command signature is:\n" " find_package( [version] [EXACT] [QUIET]\n" - " [[REQUIRED|COMPONENTS] [components...]] [NO_MODULE]\n" + " [[REQUIRED|COMPONENTS] [components...]]\n" + " [CONFIG|NO_MODULE]\n" " [NO_POLICY_SCOPE]\n" " [NAMES name1 [name2 ...]]\n" " [CONFIGS config1 [config2 ...]]\n" @@ -145,9 +155,10 @@ void cmFindPackageCommand::GenerateDocumentation() " [CMAKE_FIND_ROOT_PATH_BOTH |\n" " ONLY_CMAKE_FIND_ROOT_PATH |\n" " NO_CMAKE_FIND_ROOT_PATH])\n" - "The NO_MODULE option may be used to skip Module mode explicitly. " - "It is also implied by use of options not specified in the reduced " - "signature. " + "The CONFIG option may be used to skip Module mode explicitly and " + "switch to Config mode. It is synonymous to using NO_MODULE. " + "Config mode is also implied by use of options not specified in the " + "reduced signature. " "\n" "Config mode attempts to locate a configuration file provided by the " "package to be found. A cache entry called _DIR is created to " @@ -192,7 +203,7 @@ void cmFindPackageCommand::GenerateDocumentation() "If no such version file is available then the configuration file " "is assumed to not be compatible with any requested version. " "A basic version file containing generic version matching code can be " - "created using the macro write_basic_config_version_file(), see its " + "created using the macro write_basic_package_version_file(), see its " "documentation for more details. " "When a version file is found it is loaded to check the requested " "version number. " @@ -348,11 +359,11 @@ void cmFindPackageCommand::GenerateDocumentation() } //---------------------------------------------------------------------------- -const char* cmFindPackageCommand::GetFullDocumentation() +const char* cmFindPackageCommand::GetFullDocumentation() const { if(this->CommandDocumentation.empty()) { - this->GenerateDocumentation(); + const_cast(this)->GenerateDocumentation(); } return this->CommandDocumentation.c_str(); } @@ -367,6 +378,15 @@ bool cmFindPackageCommand return false; } + // Lookup required version of CMake. + if(const char* rv = + this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) + { + unsigned int v[3] = {0,0,0}; + sscanf(rv, "%u.%u.%u", &v[0], &v[1], &v[2]); + this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0],v[1],v[2]); + } + // Check for debug mode. this->DebugMode = this->Makefile->IsOn("CMAKE_FIND_DEBUG_MODE"); @@ -395,6 +415,8 @@ bool cmFindPackageCommand this->Name = args[0]; std::string components; const char* components_sep = ""; + std::set requiredComponents; + std::set optionalComponents; // Check ancient compatibility. this->Compatibility_1_6 = @@ -405,11 +427,13 @@ bool cmFindPackageCommand this->SearchPathSuffixes.push_back(""); // Parse the arguments. - enum Doing { DoingNone, DoingComponents, DoingNames, DoingPaths, - DoingPathSuffixes, DoingConfigs, DoingHints }; + enum Doing { DoingNone, DoingComponents, DoingOptionalComponents, DoingNames, + DoingPaths, DoingPathSuffixes, DoingConfigs, DoingHints }; Doing doing = DoingNone; cmsys::RegularExpression version("^[0-9.]+$"); bool haveVersion = false; + std::set configArgs; + std::set moduleArgs; for(unsigned int i=1; i < args.size(); ++i) { if(args[i] == "QUIET") @@ -423,9 +447,19 @@ bool cmFindPackageCommand this->Compatibility_1_6 = false; doing = DoingNone; } + else if(args[i] == "MODULE") + { + moduleArgs.insert(i); + doing = DoingNone; + } + else if(args[i] == "CONFIG") + { + configArgs.insert(i); + doing = DoingNone; + } else if(args[i] == "NO_MODULE") { - this->NoModule = true; + configArgs.insert(i); doing = DoingNone; } else if(args[i] == "REQUIRED") @@ -438,33 +472,38 @@ bool cmFindPackageCommand this->Compatibility_1_6 = false; doing = DoingComponents; } + else if(args[i] == "OPTIONAL_COMPONENTS") + { + this->Compatibility_1_6 = false; + doing = DoingOptionalComponents; + } else if(args[i] == "NAMES") { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingNames; } else if(args[i] == "PATHS") { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingPaths; } else if(args[i] == "HINTS") { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingHints; } else if(args[i] == "PATH_SUFFIXES") { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingPathSuffixes; } else if(args[i] == "CONFIGS") { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingConfigs; } @@ -477,36 +516,47 @@ bool cmFindPackageCommand else if(args[i] == "NO_CMAKE_PACKAGE_REGISTRY") { this->NoUserRegistry = true; - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingNone; } else if(args[i] == "NO_CMAKE_SYSTEM_PACKAGE_REGISTRY") { this->NoSystemRegistry = true; - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingNone; } else if(args[i] == "NO_CMAKE_BUILDS_PATH") { this->NoBuilds = true; - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingNone; } else if(this->CheckCommonArgument(args[i])) { - this->NoModule = true; + configArgs.insert(i); this->Compatibility_1_6 = false; doing = DoingNone; } - else if(doing == DoingComponents) + else if((doing == DoingComponents) || (doing == DoingOptionalComponents)) { - // Set a variable telling the find script this component + // Set a variable telling the find script whether this component // is required. + const char* isRequired = "1"; + if (doing == DoingOptionalComponents) + { + isRequired = "0"; + optionalComponents.insert(args[i]); + } + else + { + requiredComponents.insert(args[i]); + } + std::string req_var = this->Name + "_FIND_REQUIRED_" + args[i]; - this->AddFindDefinition(req_var.c_str(), "1"); + this->AddFindDefinition(req_var.c_str(), isRequired); // Append to the list of required components. components += components_sep; @@ -538,6 +588,7 @@ bool cmFindPackageCommand e << "given CONFIGS option followed by invalid file name \"" << args[i] << "\". The names given must be file names without " << "a path and with a \".cmake\" extension."; + this->SetError(e.str().c_str()); return false; } this->Configs.push_back(args[i]); @@ -556,6 +607,45 @@ bool cmFindPackageCommand } } + std::vector doubledComponents; + std::set_intersection(requiredComponents.begin(), requiredComponents.end(), + optionalComponents.begin(), optionalComponents.end(), + std::back_inserter(doubledComponents)); + if(!doubledComponents.empty()) + { + cmOStringStream e; + e << "called with components that are both required and optional:\n"; + for(unsigned int i=0; iSetError(e.str().c_str()); + return false; + } + + // Maybe choose one mode exclusively. + this->UseFindModules = configArgs.empty(); + this->UseConfigFiles = moduleArgs.empty(); + if(!this->UseFindModules && !this->UseConfigFiles) + { + cmOStringStream e; + e << "given options exclusive to Module mode:\n"; + for(std::set::const_iterator si = moduleArgs.begin(); + si != moduleArgs.end(); ++si) + { + e << " " << args[*si] << "\n"; + } + e << "and options exclusive to Config mode:\n"; + for(std::set::const_iterator si = configArgs.begin(); + si != configArgs.end(); ++si) + { + e << " " << args[*si] << "\n"; + } + e << "The options are incompatible."; + this->SetError(e.str().c_str()); + return false; + } + // Ignore EXACT with no version. if(this->Version.empty() && this->VersionExact) { @@ -635,7 +725,7 @@ bool cmFindPackageCommand this->SetModuleVariables(components); // See if there is a Find.cmake module. - if(!this->NoModule) + if(this->UseFindModules) { bool foundModule = false; if(!this->FindModule(foundModule)) @@ -650,6 +740,37 @@ bool cmFindPackageCommand } } + if(this->UseFindModules && this->UseConfigFiles && + this->Makefile->IsOn("CMAKE_FIND_PACKAGE_WARN_NO_MODULE")) + { + cmOStringStream aw; + if(this->RequiredCMakeVersion >= CMake_VERSION_ENCODE(2,8,8)) + { + aw << "find_package called without either MODULE or CONFIG option and " + "no Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. " + "Add MODULE to exclusively request Module mode and fail if " + "Find" << this->Name << ".cmake is missing. " + "Add CONFIG to exclusively request Config mode and search for a " + "package configuration file provided by " << this->Name << + " (" << this->Name << "Config.cmake or " << + cmSystemTools::LowerCase(this->Name) << "-config.cmake). "; + } + else + { + aw << "find_package called without NO_MODULE option and no " + "Find" << this->Name << ".cmake module is in CMAKE_MODULE_PATH. " + "Add NO_MODULE to exclusively request Config mode and search for a " + "package configuration file provided by " << this->Name << + " (" << this->Name << "Config.cmake or " << + cmSystemTools::LowerCase(this->Name) << "-config.cmake). " + "Otherwise make Find" << this->Name << ".cmake available in " + "CMAKE_MODULE_PATH."; + } + aw << "\n" + "(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.)"; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, aw.str()); + } + // No find module. Assume the project has a CMake config file. Use // a _DIR cache variable to locate it. this->Variable = this->Name; @@ -830,48 +951,66 @@ bool cmFindPackageCommand::HandlePackageMode() // Try to load the config file if the directory is known bool fileFound = false; - if(!cmSystemTools::IsOff(def)) + if (this->UseConfigFiles) { - // Get the directory from the variable value. - std::string dir = def; - cmSystemTools::ConvertToUnixSlashes(dir); - - // Treat relative paths with respect to the current source dir. - if(!cmSystemTools::FileIsFullPath(dir.c_str())) + if(!cmSystemTools::IsOff(def)) { - dir = "/" + dir; - dir = this->Makefile->GetCurrentDirectory() + dir; + // Get the directory from the variable value. + std::string dir = def; + cmSystemTools::ConvertToUnixSlashes(dir); + + // Treat relative paths with respect to the current source dir. + if(!cmSystemTools::FileIsFullPath(dir.c_str())) + { + dir = "/" + dir; + dir = this->Makefile->GetCurrentDirectory() + dir; + } + // The file location was cached. Look for the correct file. + std::string file; + if (this->FindConfigFile(dir, file)) + { + this->FileFound = file; + fileFound = true; + } + def = this->Makefile->GetDefinition(this->Variable.c_str()); } - // The file location was cached. Look for the correct file. - std::string file; - if (this->FindConfigFile(dir, file)) + + // Search for the config file if it is not already found. + if(cmSystemTools::IsOff(def) || !fileFound) { - this->FileFound = file; - fileFound = true; + fileFound = this->FindConfig(); + def = this->Makefile->GetDefinition(this->Variable.c_str()); } - def = this->Makefile->GetDefinition(this->Variable.c_str()); - } - // Search for the config file if it is not already found. - if(cmSystemTools::IsOff(def) || !fileFound) - { - fileFound = this->FindConfig(); - def = this->Makefile->GetDefinition(this->Variable.c_str()); + // Sanity check. + if(fileFound && this->FileFound.empty()) + { + this->Makefile->IssueMessage( + cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!"); + fileFound = false; + } } - // Sanity check. - if(fileFound && this->FileFound.empty()) - { - this->Makefile->IssueMessage( - cmake::INTERNAL_ERROR, "fileFound is true but FileFound is empty!"); - fileFound = false; - } + std::string foundVar = this->Name; + foundVar += "_FOUND"; // If the directory for the config file was found, try to read the file. bool result = true; bool found = false; + bool configFileSetFOUNDFalse = false; + if(fileFound) { + if ((this->Makefile->IsDefinitionSet(foundVar.c_str())) + && (this->Makefile->IsOn(foundVar.c_str()) == false)) + { + // by removing Foo_FOUND here if it is FALSE, we don't really change + // the situation for the Config file which is about to be included, + // but we make it possible to detect later on whether the Config file + // has set Foo_FOUND to FALSE itself: + this->Makefile->RemoveDefinition(foundVar.c_str()); + } + // Set the version variables before loading the config file. // It may override them. this->StoreVersionFound(); @@ -881,6 +1020,15 @@ bool cmFindPackageCommand::HandlePackageMode() { // The package has been found. found = true; + + // Check whether the Config file has set Foo_FOUND to FALSE: + if ((this->Makefile->IsDefinitionSet(foundVar.c_str())) + && (this->Makefile->IsOn(foundVar.c_str()) == false)) + { + // we get here if the Config file has set Foo_FOUND actively to FALSE + found = false; + configFileSetFOUNDFalse = true; + } } else { @@ -888,13 +1036,22 @@ bool cmFindPackageCommand::HandlePackageMode() result = false; } } - else if(!this->Quiet || this->Required) + + if (result && !found && (!this->Quiet || this->Required)) { // The variable is not set. cmOStringStream e; + cmOStringStream aw; + if (configFileSetFOUNDFalse) + { + e << "Found package configuration file:\n" + " " << this->FileFound << "\n" + "but it set " << foundVar << " to FALSE so package \"" << + this->Name << "\" is considered to be NOT FOUND."; + } // If there are files in ConsideredConfigs, it means that FooConfig.cmake // have been found, but they didn't have appropriate versions. - if (this->ConsideredConfigs.size() > 0) + else if (this->ConsideredConfigs.size() > 0) { e << "Could not find a configuration file for package \"" << this->Name << "\" that " @@ -911,46 +1068,83 @@ bool cmFindPackageCommand::HandlePackageMode() } else { - e << "Could not find "; - if(!this->NoModule) - { - e << "module Find" << this->Name << ".cmake or "; - } - e << "a configuration file for package " << this->Name << ".\n"; - if(!this->NoModule) - { - e << "Adjust CMAKE_MODULE_PATH to find Find" - << this->Name << ".cmake or set "; - } - else - { - e << "Set "; - } - e << this->Variable << " to the directory containing a CMake " - << "configuration file for " << this->Name << ". "; - if(this->Configs.size() == 1) + std::string requestedVersionString; + if(!this->Version.empty()) { - e << "The file will be called " << this->Configs[0]; + requestedVersionString = " (requested version "; + requestedVersionString += this->Version; + requestedVersionString += ")"; } - else + + if (this->UseConfigFiles) { - e << "The file will have one of the following names:\n"; - for(std::vector::const_iterator ci=this->Configs.begin(); - ci != this->Configs.end(); ++ci) + if(this->UseFindModules) { - e << " " << *ci << "\n"; + e << "By not providing \"Find" << this->Name << ".cmake\" in " + "CMAKE_MODULE_PATH this project has asked CMake to find a " + "package configuration file provided by \""<Name<< "\", " + "but CMake did not find one.\n"; } + + if(this->Configs.size() == 1) + { + e << "Could not find a package configuration file named \"" + << this->Configs[0] << "\" provided by package \"" + << this->Name << "\"" << requestedVersionString <<".\n"; + } + else + { + e << "Could not find a package configuration file provided by \"" + << this->Name << "\"" << requestedVersionString + << " with any of the following names:\n"; + for(std::vector::const_iterator ci = + this->Configs.begin(); + ci != this->Configs.end(); ++ci) + { + e << " " << *ci << "\n"; + } + } + + e << "Add the installation prefix of \"" << this->Name << "\" to " + "CMAKE_PREFIX_PATH or set \"" << this->Variable << "\" to a " + "directory containing one of the above files. " + "If \"" << this->Name << "\" provides a separate development " + "package or SDK, be sure it has been installed."; + } + else // if(!this->UseFindModules && !this->UseConfigFiles) + { + e << "No \"Find" << this->Name << ".cmake\" found in " + << "CMAKE_MODULE_PATH."; + + aw<< "Find"<< this->Name <<".cmake must either be part of this " + "project itself, in this case adjust CMAKE_MODULE_PATH so that " + "it points to the correct location inside its source tree.\n" + "Or it must be installed by a package which has already been " + "found via find_package(). In this case make sure that " + "package has indeed been found and adjust CMAKE_MODULE_PATH to " + "contain the location where that package has installed " + "Find" << this->Name << ".cmake. This must be a location " + "provided by that package. This error in general means that " + "the buildsystem of this project is relying on a Find-module " + "without ensuring that it is actually available.\n"; } } this->Makefile->IssueMessage( this->Required? cmake::FATAL_ERROR : cmake::WARNING, e.str()); + if (this->Required) + { + cmSystemTools::SetFatalErrorOccured(); + } + + if (!aw.str().empty()) + { + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,aw.str()); + } } // Set a variable marking whether the package was found. - std::string foundVar = this->Name; - foundVar += "_FOUND"; this->Makefile->AddDefinition(foundVar.c_str(), found? "1":"0"); // Set a variable naming the configuration file that was found. @@ -1226,6 +1420,15 @@ void cmFindPackageCommand::AppendSuccessInformation() } this->Makefile->GetCMakeInstance()->SetProperty(versionInfoPropName.c_str(), versionInfo.c_str()); + if (this->Required) + { + std::string requiredInfoPropName = "_CMAKE_"; + requiredInfoPropName += this->Name; + requiredInfoPropName += "_TYPE"; + this->Makefile->GetCMakeInstance()->SetProperty( + requiredInfoPropName.c_str(), "REQUIRED"); + } + // Restore original state of "_FIND_" variables we set. this->RestoreFindDefinitions(); diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index e73635284..edb70a6a1 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -44,17 +44,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "find_package";} + virtual const char* GetName() const { return "find_package";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Load settings for an external project."; } @@ -62,7 +62,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation(); + virtual const char* GetFullDocumentation() const; cmTypeMacro(cmFindPackageCommand, cmFindCommon); protected: @@ -130,10 +130,12 @@ private: unsigned int VersionFoundPatch; unsigned int VersionFoundTweak; unsigned int VersionFoundCount; + unsigned int RequiredCMakeVersion; bool Quiet; bool Required; bool Compatibility_1_6; - bool NoModule; + bool UseConfigFiles; + bool UseFindModules; bool NoUserRegistry; bool NoSystemRegistry; bool NoBuilds; diff --git a/Source/cmFindPathCommand.h b/Source/cmFindPathCommand.h index bd9477983..a61299011 100644 --- a/Source/cmFindPathCommand.h +++ b/Source/cmFindPathCommand.h @@ -44,17 +44,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "find_path";} + virtual const char* GetName() const {return "find_path";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Find the directory containing a file."; } diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx index 7c56ad7ce..00f5419c2 100644 --- a/Source/cmFindProgramCommand.cxx +++ b/Source/cmFindProgramCommand.cxx @@ -175,6 +175,8 @@ std::string cmFindProgramCommand::GetBundleExecutable(std::string bundlePath) // And finally to a c++ string executable = bundlePath + "/Contents/MacOS/" + std::string(buffer); + // Only release CFURLRef if it's not null + CFRelease( executableURL ); } // Any CF objects returned from functions with "create" or @@ -182,7 +184,6 @@ std::string cmFindProgramCommand::GetBundleExecutable(std::string bundlePath) CFRelease( bundlePathCFS ); CFRelease( bundleURL ); CFRelease( appBundle ); - CFRelease( executableURL ); #endif return executable; diff --git a/Source/cmFindProgramCommand.h b/Source/cmFindProgramCommand.h index 654e834bf..c1b14f912 100644 --- a/Source/cmFindProgramCommand.h +++ b/Source/cmFindProgramCommand.h @@ -43,17 +43,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "find_program";} + virtual const char* GetName() const { return "find_program";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Find an executable program."; } diff --git a/Source/cmForEachCommand.h b/Source/cmForEachCommand.h index 026fd31ef..ae50005be 100644 --- a/Source/cmForEachCommand.h +++ b/Source/cmForEachCommand.h @@ -16,11 +16,6 @@ #include "cmFunctionBlocker.h" #include "cmListFileCache.h" -/** \class cmForEachFunctionBlocker - * \brief subclass of function blocker - * - * - */ class cmForEachFunctionBlocker : public cmFunctionBlocker { public: @@ -37,11 +32,7 @@ private: int Depth; }; -/** \class cmForEachCommand - * \brief starts an if block - * - * cmForEachCommand starts an if block - */ +/// Starts foreach() ... endforeach() block class cmForEachCommand : public cmCommand { public: @@ -63,17 +54,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "foreach";} + virtual const char* GetName() const { return "foreach";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Evaluate a group of commands for each value in a list."; } @@ -81,7 +72,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " foreach(loop_var arg1 arg2 ...)\n" diff --git a/Source/cmFunctionBlocker.h b/Source/cmFunctionBlocker.h index c3b29e148..9ee0b5c2d 100644 --- a/Source/cmFunctionBlocker.h +++ b/Source/cmFunctionBlocker.h @@ -17,11 +17,6 @@ #include "cmListFileCache.h" class cmMakefile; -/** \class cmFunctionBlocker - * \brief A class that defines an interface for blocking cmake functions - * - * This is the superclass for any classes that need to block a cmake function - */ class cmFunctionBlocker { public: diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index ec4fd16bc..ce36145f4 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -22,6 +22,17 @@ public: ///! clean up any memory allocated by the function ~cmFunctionHelperCommand() {}; + /** + * This is used to avoid including this command + * in documentation. This is mainly used by + * cmMacroHelperCommand and cmFunctionHelperCommand + * which cannot provide appropriate documentation. + */ + virtual bool ShouldAppearInDocumentation() const + { + return false; + } + /** * This is a virtual constructor for the command. */ @@ -38,7 +49,7 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * This is called when the command is first encountered in @@ -53,12 +64,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return this->Args[0].c_str(); } + virtual const char* GetName() const { return this->Args[0].c_str(); } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { std::string docs = "Function named: "; docs += this->GetName(); @@ -68,7 +79,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return this->GetTerseDocumentation(); } diff --git a/Source/cmFunctionCommand.h b/Source/cmFunctionCommand.h index a16924485..43c8e2983 100644 --- a/Source/cmFunctionCommand.h +++ b/Source/cmFunctionCommand.h @@ -15,11 +15,6 @@ #include "cmCommand.h" #include "cmFunctionBlocker.h" -/** \class cmFunctionFunctionBlocker - * \brief subclass of function blocker - * - * - */ class cmFunctionFunctionBlocker : public cmFunctionBlocker { public: @@ -35,11 +30,7 @@ public: int Depth; }; -/** \class cmFunctionCommand - * \brief starts an if block - * - * cmFunctionCommand starts an if block - */ +/// Starts function() ... endfunction() block class cmFunctionCommand : public cmCommand { public: @@ -61,17 +52,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "function";} + virtual const char* GetName() const { return "function";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Start recording a function for later invocation as a command."; } @@ -79,7 +70,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " function( [arg1 [arg2 [arg3 ...]]])\n" diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx new file mode 100644 index 000000000..42dd42819 --- /dev/null +++ b/Source/cmGeneratorTarget.cxx @@ -0,0 +1,184 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmGeneratorTarget.h" + +#include "cmTarget.h" +#include "cmMakefile.h" +#include "cmLocalGenerator.h" +#include "cmGlobalGenerator.h" +#include "cmSourceFile.h" + +//---------------------------------------------------------------------------- +cmGeneratorTarget::cmGeneratorTarget(cmTarget* t): Target(t) +{ + this->Makefile = this->Target->GetMakefile(); + this->LocalGenerator = this->Makefile->GetLocalGenerator(); + this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator(); + this->ClassifySources(); + this->LookupObjectLibraries(); +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::ClassifySources() +{ + cmsys::RegularExpression header(CM_HEADER_REGEX); + bool isObjLib = this->Target->GetType() == cmTarget::OBJECT_LIBRARY; + std::vector badObjLib; + std::vector const& sources = this->Target->GetSourceFiles(); + for(std::vector::const_iterator si = sources.begin(); + si != sources.end(); ++si) + { + cmSourceFile* sf = *si; + std::string ext = cmSystemTools::LowerCase(sf->GetExtension()); + cmTarget::SourceFileFlags tsFlags = + this->Target->GetTargetSourceFileFlags(sf); + if(sf->GetCustomCommand()) + { + this->CustomCommands.push_back(sf); + } + else if(tsFlags.Type != cmTarget::SourceFileTypeNormal) + { + this->OSXContent.push_back(sf); + if(isObjLib) { badObjLib.push_back(sf); } + } + else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY")) + { + this->HeaderSources.push_back(sf); + } + else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT")) + { + this->ExternalObjects.push_back(sf); + if(isObjLib) { badObjLib.push_back(sf); } + } + else if(sf->GetLanguage()) + { + this->ObjectSources.push_back(sf); + } + else if(ext == "def") + { + this->ModuleDefinitionFile = sf->GetFullPath(); + if(isObjLib) { badObjLib.push_back(sf); } + } + else if(ext == "idl") + { + this->IDLSources.push_back(sf); + if(isObjLib) { badObjLib.push_back(sf); } + } + else if(header.find(sf->GetFullPath().c_str())) + { + this->HeaderSources.push_back(sf); + } + else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str())) + { + // We only get here if a source file is not an external object + // and has an extension that is listed as an ignored file type. + // No message or diagnosis should be given. + this->ExtraSources.push_back(sf); + } + else + { + this->ExtraSources.push_back(sf); + if(isObjLib && ext != "txt") + { + badObjLib.push_back(sf); + } + } + } + + if(!badObjLib.empty()) + { + cmOStringStream e; + e << "OBJECT library \"" << this->Target->GetName() << "\" contains:\n"; + for(std::vector::iterator i = badObjLib.begin(); + i != badObjLib.end(); ++i) + { + e << " " << (*i)->GetLocation().GetName() << "\n"; + } + e << "but may contain only headers and sources that compile."; + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Target->GetBacktrace()); + } +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::LookupObjectLibraries() +{ + std::vector const& objLibs = + this->Target->GetObjectLibraries(); + for(std::vector::const_iterator oli = objLibs.begin(); + oli != objLibs.end(); ++oli) + { + std::string const& objLibName = *oli; + if(cmTarget* objLib = this->Makefile->FindTargetToUse(objLibName.c_str())) + { + if(objLib->GetType() == cmTarget::OBJECT_LIBRARY) + { + if(this->Target->GetType() != cmTarget::EXECUTABLE && + this->Target->GetType() != cmTarget::STATIC_LIBRARY && + this->Target->GetType() != cmTarget::SHARED_LIBRARY && + this->Target->GetType() != cmTarget::MODULE_LIBRARY) + { + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::FATAL_ERROR, + "Only executables and non-OBJECT libraries may " + "reference target objects.", + this->Target->GetBacktrace()); + return; + } + this->Target->AddUtility(objLib->GetName()); + this->ObjectLibraries.push_back(objLib); + } + else + { + cmOStringStream e; + e << "Objects of target \"" << objLibName + << "\" referenced but is not an OBJECT library."; + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Target->GetBacktrace()); + return; + } + } + else + { + cmOStringStream e; + e << "Objects of target \"" << objLibName + << "\" referenced but no such target exists."; + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::FATAL_ERROR, e.str(), + this->Target->GetBacktrace()); + return; + } + } +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::UseObjectLibraries(std::vector& objs) +{ + for(std::vector::const_iterator + ti = this->ObjectLibraries.begin(); + ti != this->ObjectLibraries.end(); ++ti) + { + cmTarget* objLib = *ti; + cmGeneratorTarget* ogt = + this->GlobalGenerator->GetGeneratorTarget(objLib); + for(std::vector::const_iterator + si = ogt->ObjectSources.begin(); + si != ogt->ObjectSources.end(); ++si) + { + std::string obj = ogt->ObjectDirectory; + obj += ogt->Objects[*si]; + objs.push_back(obj); + } + } +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h new file mode 100644 index 000000000..3e5065603 --- /dev/null +++ b/Source/cmGeneratorTarget.h @@ -0,0 +1,64 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmGeneratorTarget_h +#define cmGeneratorTarget_h + +#include "cmStandardIncludes.h" + +class cmCustomCommand; +class cmGlobalGenerator; +class cmLocalGenerator; +class cmMakefile; +class cmSourceFile; +class cmTarget; + +class cmGeneratorTarget +{ +public: + cmGeneratorTarget(cmTarget*); + + cmTarget* Target; + cmMakefile* Makefile; + cmLocalGenerator* LocalGenerator; + cmGlobalGenerator* GlobalGenerator; + + /** Sources classified by purpose. */ + std::vector CustomCommands; + std::vector ExtraSources; + std::vector HeaderSources; + std::vector ObjectSources; + std::vector ExternalObjects; + std::vector OSXContent; + std::vector IDLSources; + std::string ModuleDefinitionFile; + + std::map Objects; + std::set ExplicitObjectName; + + /** Full path with trailing slash to the top-level directory + holding object files for this target. Includes the build + time config name placeholder if needed for the generator. */ + std::string ObjectDirectory; + + std::vector ObjectLibraries; + + void UseObjectLibraries(std::vector& objs); + +private: + void ClassifySources(); + void LookupObjectLibraries(); + + cmGeneratorTarget(cmGeneratorTarget const&); + void operator=(cmGeneratorTarget const&); +}; + +#endif diff --git a/Source/cmGetCMakePropertyCommand.h b/Source/cmGetCMakePropertyCommand.h index d82be7015..0a5917cfd 100644 --- a/Source/cmGetCMakePropertyCommand.h +++ b/Source/cmGetCMakePropertyCommand.h @@ -32,17 +32,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_cmake_property";} + virtual const char* GetName() const { return "get_cmake_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property of the CMake instance."; } @@ -50,7 +50,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_cmake_property(VAR property)\n" diff --git a/Source/cmGetDirectoryPropertyCommand.h b/Source/cmGetDirectoryPropertyCommand.h index b7a5f7100..901b90cff 100644 --- a/Source/cmGetDirectoryPropertyCommand.h +++ b/Source/cmGetDirectoryPropertyCommand.h @@ -32,17 +32,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_directory_property";} + virtual const char* GetName() const { return "get_directory_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property of DIRECTORY scope."; } @@ -50,7 +50,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_directory_property( [DIRECTORY ] )\n" diff --git a/Source/cmGetFilenameComponentCommand.h b/Source/cmGetFilenameComponentCommand.h index aff4d7ea1..0c8e57a26 100644 --- a/Source/cmGetFilenameComponentCommand.h +++ b/Source/cmGetFilenameComponentCommand.h @@ -41,17 +41,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_filename_component";} + virtual const char* GetName() const { return "get_filename_component";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a specific component of a full filename."; } @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_filename_component( FileName\n" diff --git a/Source/cmGetPropertyCommand.h b/Source/cmGetPropertyCommand.h index d318b19cb..dca262725 100644 --- a/Source/cmGetPropertyCommand.h +++ b/Source/cmGetPropertyCommand.h @@ -34,17 +34,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_property";} + virtual const char* GetName() const { return "get_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property."; } @@ -52,7 +52,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_property(\n" diff --git a/Source/cmGetSourceFilePropertyCommand.h b/Source/cmGetSourceFilePropertyCommand.h index 56469f80f..6d52503b5 100644 --- a/Source/cmGetSourceFilePropertyCommand.h +++ b/Source/cmGetSourceFilePropertyCommand.h @@ -32,12 +32,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_source_file_property";} + virtual const char* GetName() const { return "get_source_file_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property for a source file."; } @@ -45,7 +45,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_source_file_property(VAR file property)\n" diff --git a/Source/cmGetTargetPropertyCommand.h b/Source/cmGetTargetPropertyCommand.h index 71c75efb3..b60abea4c 100644 --- a/Source/cmGetTargetPropertyCommand.h +++ b/Source/cmGetTargetPropertyCommand.h @@ -32,12 +32,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_target_property";} + virtual const char* GetName() const { return "get_target_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property from a target."; } @@ -45,7 +45,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_target_property(VAR target property)\n" diff --git a/Source/cmGetTestPropertyCommand.h b/Source/cmGetTestPropertyCommand.h index d9f5d9bfa..af6bafaf3 100644 --- a/Source/cmGetTestPropertyCommand.h +++ b/Source/cmGetTestPropertyCommand.h @@ -32,12 +32,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "get_test_property";} + virtual const char* GetName() const { return "get_test_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Get a property of the test."; } @@ -45,7 +45,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " get_test_property(test property VAR)\n" diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 124519ada..545f9e87f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -24,6 +24,7 @@ #include "cmExportInstallFileGenerator.h" #include "cmComputeTargetDepends.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" #include @@ -74,6 +75,7 @@ cmGlobalGenerator::~cmGlobalGenerator() delete this->ExtraGenerator; } + this->ClearGeneratorTargets(); this->ClearExportSets(); } @@ -807,6 +809,7 @@ bool cmGlobalGenerator::IsDependedOn(const char* project, void cmGlobalGenerator::Configure() { this->FirstTimeProgress = 0.0f; + this->ClearGeneratorTargets(); this->ClearExportSets(); // Delete any existing cmLocalGenerators unsigned int i; @@ -947,6 +950,9 @@ void cmGlobalGenerator::Generate() this->LocalGenerators[i]->GenerateTargetManifest(); } + // Create per-target generator information. + this->CreateGeneratorTargets(); + // Compute the inter-target dependencies. if(!this->ComputeTargetDepends()) { @@ -1056,6 +1062,55 @@ void cmGlobalGenerator::CreateAutomocTargets() #endif } +//---------------------------------------------------------------------------- +void cmGlobalGenerator::CreateGeneratorTargets() +{ + // Construct per-target generator information. + for(unsigned int i=0; i < this->LocalGenerators.size(); ++i) + { + cmTargets& targets = + this->LocalGenerators[i]->GetMakefile()->GetTargets(); + for(cmTargets::iterator ti = targets.begin(); + ti != targets.end(); ++ti) + { + cmTarget* t = &ti->second; + cmGeneratorTarget* gt = new cmGeneratorTarget(t); + this->GeneratorTargets[t] = gt; + this->ComputeTargetObjects(gt); + } + } +} + +//---------------------------------------------------------------------------- +void cmGlobalGenerator::ClearGeneratorTargets() +{ + for(GeneratorTargetsType::iterator i = this->GeneratorTargets.begin(); + i != this->GeneratorTargets.end(); ++i) + { + delete i->second; + } + this->GeneratorTargets.clear(); +} + +//---------------------------------------------------------------------------- +cmGeneratorTarget* cmGlobalGenerator::GetGeneratorTarget(cmTarget* t) const +{ + GeneratorTargetsType::const_iterator ti = this->GeneratorTargets.find(t); + if(ti == this->GeneratorTargets.end()) + { + this->CMakeInstance->IssueMessage( + cmake::INTERNAL_ERROR, "Missing cmGeneratorTarget instance!", + cmListFileBacktrace()); + return 0; + } + return ti->second; +} + +//---------------------------------------------------------------------------- +void cmGlobalGenerator::ComputeTargetObjects(cmGeneratorTarget*) const +{ + // Implemented in generator subclasses that need this. +} void cmGlobalGenerator::CheckLocalGenerators() { @@ -1067,9 +1122,9 @@ void cmGlobalGenerator::CheckLocalGenerators() { manager = this->LocalGenerators[i]->GetMakefile()->GetCacheManager(); this->LocalGenerators[i]->ConfigureFinalPass(); - const cmTargets & targets = + cmTargets & targets = this->LocalGenerators[i]->GetMakefile()->GetTargets(); - for (cmTargets::const_iterator l = targets.begin(); + for (cmTargets::iterator l = targets.begin(); l != targets.end(); l++) { const cmTarget::LinkLibraryVectorType& libs = @@ -1095,27 +1150,28 @@ void cmGlobalGenerator::CheckLocalGenerators() notFoundMap[varName] = text; } } - } - const std::vector& incs = - this->LocalGenerators[i]->GetMakefile()->GetIncludeDirectories(); + std::vector incs; + this->LocalGenerators[i]->GetIncludeDirectories(incs, &l->second); - for( std::vector::const_iterator incDir = incs.begin(); - incDir != incs.end(); ++incDir) - { - if(incDir->size() > 9 && - cmSystemTools::IsNOTFOUND(incDir->c_str())) + for( std::vector::const_iterator incDir = incs.begin(); + incDir != incs.end(); ++incDir) { - std::string varName = incDir->substr(0, incDir->size()-9); - cmCacheManager::CacheIterator it = - manager->GetCacheIterator(varName.c_str()); - if(it.GetPropertyAsBool("ADVANCED")) + if(incDir->size() > 9 && + cmSystemTools::IsNOTFOUND(incDir->c_str())) { - varName += " (ADVANCED)"; + std::string varName = incDir->substr(0, incDir->size()-9); + cmCacheManager::CacheIterator it = + manager->GetCacheIterator(varName.c_str()); + if(it.GetPropertyAsBool("ADVANCED")) + { + varName += " (ADVANCED)"; + } + std::string text = notFoundMap[varName]; + text += "\n used as include directory in directory "; + text += this->LocalGenerators[i] + ->GetMakefile()->GetCurrentDirectory(); + notFoundMap[varName] = text; } - std::string text = notFoundMap[varName]; - text += "\n used as include directory in directory "; - text += this->LocalGenerators[i]->GetMakefile()->GetCurrentDirectory(); - notFoundMap[varName] = text; } } this->CMakeInstance->UpdateProgress @@ -1666,6 +1722,11 @@ cmGlobalGenerator::FindTarget(const char* project, const char* name) { return i->second; } + i = this->ImportedTargets.find(name); + if ( i != this->ImportedTargets.end() ) + { + return i->second; + } } return 0; } @@ -1708,7 +1769,7 @@ void cmGlobalGenerator::SetCMakeInstance(cmake* cm) void cmGlobalGenerator::CreateDefaultGlobalTargets(cmTargets* targets) { cmMakefile* mf = this->LocalGenerators[0]->GetMakefile(); - const char* cmakeCfgIntDir = this->GetCMakeCFGInitDirectory(); + const char* cmakeCfgIntDir = this->GetCMakeCFGIntDir(); const char* cmakeCommand = mf->GetRequiredDefinition("CMAKE_COMMAND"); // CPack @@ -2046,10 +2107,16 @@ cmGlobalGenerator::GetTargetDirectDepends(cmTarget & target) return this->TargetDependencies[&target]; } -void cmGlobalGenerator::AddTarget(cmTargets::value_type &v) +void cmGlobalGenerator::AddTarget(cmTarget* t) { - assert(!v.second.IsImported()); - this->TotalTargets[v.first] = &v.second; + if(t->IsImported()) + { + this->ImportedTargets[t->GetName()] = t; + } + else + { + this->TotalTargets[t->GetName()] = t; + } } void cmGlobalGenerator::SetExternalMakefileProjectGenerator( diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index ded3345db..80b948bc4 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -19,6 +19,7 @@ #include "cmTargetDepend.h" // For cmTargetDependSet #include "cmSystemTools.h" // for cmSystemTools::OutputOption class cmake; +class cmGeneratorTarget; class cmMakefile; class cmLocalGenerator; class cmExternalMakefileProjectGenerator; @@ -183,7 +184,7 @@ public: const char* GetLanguageOutputExtension(cmSourceFile const&); ///! What is the configurations directory variable called? - virtual const char* GetCMakeCFGInitDirectory() { return "."; } + virtual const char* GetCMakeCFGIntDir() const { return "."; } /** Get whether the generator should use a script for link commands. */ bool GetUseLinkScript() const { return this->UseLinkScript; } @@ -230,7 +231,7 @@ public: std::set const& GetDirectoryContent(std::string const& dir, bool needDisk = true); - void AddTarget(cmTargets::value_type &v); + void AddTarget(cmTarget* t); virtual const char* GetAllTargetName() const { return "ALL_BUILD"; } virtual const char* GetInstallTargetName() const { return "INSTALL"; } @@ -251,6 +252,9 @@ public: // via a target_link_libraries or add_dependencies TargetDependSet const& GetTargetDirectDepends(cmTarget & target); + /** Get per-target generator information. */ + cmGeneratorTarget* GetGeneratorTarget(cmTarget*) const; + const std::map >& GetProjectMap() const {return this->ProjectMap;} @@ -333,6 +337,7 @@ protected: // All targets in the entire project. std::map TotalTargets; + std::map ImportedTargets; virtual const char* GetPredefinedTargetsFolder(); virtual bool UseFolderProperty(); @@ -369,6 +374,13 @@ private: typedef std::map TargetDependMap; TargetDependMap TargetDependencies; + // Per-target generator information. + typedef std::map GeneratorTargetsType; + GeneratorTargetsType GeneratorTargets; + void CreateGeneratorTargets(); + void ClearGeneratorTargets(); + virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; + // Cache directory content and target files to be built. struct DirectoryContent: public std::set { diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx new file mode 100644 index 000000000..9cbd50233 --- /dev/null +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -0,0 +1,822 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmGlobalNinjaGenerator.h" +#include "cmLocalNinjaGenerator.h" +#include "cmMakefile.h" +#include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" +#include "cmVersion.h" + +const char* cmGlobalNinjaGenerator::NINJA_BUILD_FILE = "build.ninja"; +const char* cmGlobalNinjaGenerator::NINJA_RULES_FILE = "rules.ninja"; +const char* cmGlobalNinjaGenerator::INDENT = " "; + +void cmGlobalNinjaGenerator::Indent(std::ostream& os, int count) +{ + for(int i = 0; i < count; ++i) + os << cmGlobalNinjaGenerator::INDENT; +} + +void cmGlobalNinjaGenerator::WriteDivider(std::ostream& os) +{ + os + << "# ======================================" + << "=======================================\n"; +} + +void cmGlobalNinjaGenerator::WriteComment(std::ostream& os, + const std::string& comment) +{ + if (comment.empty()) + return; + + std::string replace = comment; + std::string::size_type lpos = 0; + std::string::size_type rpos; + while((rpos = replace.find('\n', lpos)) != std::string::npos) + { + os << "# " << replace.substr(lpos, rpos - lpos) << "\n"; + lpos = rpos + 1; + } + os << "# " << replace.substr(lpos) << "\n"; +} + +static bool IsIdentChar(char c) +{ + return + ('a' <= c && c <= 'z') || + ('+' <= c && c <= '9') || // +,-./ and numbers + ('A' <= c && c <= 'Z') || + (c == '_') || (c == '$') || (c == '\\') || + (c == ' ') || (c == ':'); +} + +std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident, + std::ostream &vars) { + if (std::find_if(ident.begin(), ident.end(), + std::not1(std::ptr_fun(IsIdentChar))) != ident.end()) { + static unsigned VarNum = 0; + std::ostringstream names; + names << "ident" << VarNum++; + vars << names.str() << " = " << ident << "\n"; + return "$" + names.str(); + } else { + std::string result = ident; + cmSystemTools::ReplaceString(result, " ", "$ "); + cmSystemTools::ReplaceString(result, ":", "$:"); + return result; + } +} + +std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit) +{ + std::string result = lit; + cmSystemTools::ReplaceString(result, "$", "$$"); + return result; +} + +std::string cmGlobalNinjaGenerator::EncodePath(const std::string &path) +{ + std::string result = path; +#ifdef _WIN32 + cmSystemTools::ReplaceString(result, "/", "\\"); +#endif + return EncodeLiteral(result); +} + +void cmGlobalNinjaGenerator::WriteBuild(std::ostream& os, + const std::string& comment, + const std::string& rule, + const cmNinjaDeps& outputs, + const cmNinjaDeps& explicitDeps, + const cmNinjaDeps& implicitDeps, + const cmNinjaDeps& orderOnlyDeps, + const cmNinjaVars& variables) +{ + // Make sure there is a rule. + if(rule.empty()) + { + cmSystemTools::Error("No rule for WriteBuildStatement! called " + "with comment: ", + comment.c_str()); + return; + } + + // Make sure there is at least one output file. + if(outputs.empty()) + { + cmSystemTools::Error("No output files for WriteBuildStatement! called " + "with comment: ", + comment.c_str()); + return; + } + + cmGlobalNinjaGenerator::WriteComment(os, comment); + + std::ostringstream builds; + + // TODO: Better formatting for when there are multiple input/output files. + + // Write outputs files. + builds << "build"; + for(cmNinjaDeps::const_iterator i = outputs.begin(); + i != outputs.end(); + ++i) + builds << " " << EncodeIdent(EncodePath(*i), os); + builds << ":"; + + // Write the rule. + builds << " " << rule; + + // Write explicit dependencies. + for(cmNinjaDeps::const_iterator i = explicitDeps.begin(); + i != explicitDeps.end(); + ++i) + builds << " " << EncodeIdent(EncodePath(*i), os); + + // Write implicit dependencies. + if(!implicitDeps.empty()) + { + builds << " |"; + for(cmNinjaDeps::const_iterator i = implicitDeps.begin(); + i != implicitDeps.end(); + ++i) + builds << " " << EncodeIdent(EncodePath(*i), os); + } + + // Write order-only dependencies. + if(!orderOnlyDeps.empty()) + { + builds << " ||"; + for(cmNinjaDeps::const_iterator i = orderOnlyDeps.begin(); + i != orderOnlyDeps.end(); + ++i) + builds << " " << EncodeIdent(EncodePath(*i), os); + } + + builds << "\n"; + + os << builds.str(); + + // Write the variables bound to this build statement. + for(cmNinjaVars::const_iterator i = variables.begin(); + i != variables.end(); + ++i) + cmGlobalNinjaGenerator::WriteVariable(os, i->first, i->second, "", 1); +} + +void cmGlobalNinjaGenerator::WritePhonyBuild(std::ostream& os, + const std::string& comment, + const cmNinjaDeps& outputs, + const cmNinjaDeps& explicitDeps, + const cmNinjaDeps& implicitDeps, + const cmNinjaDeps& orderOnlyDeps, + const cmNinjaVars& variables) +{ + cmGlobalNinjaGenerator::WriteBuild(os, + comment, + "phony", + outputs, + explicitDeps, + implicitDeps, + orderOnlyDeps, + variables); +} + +void cmGlobalNinjaGenerator::AddCustomCommandRule() +{ + this->AddRule("CUSTOM_COMMAND", + "$COMMAND", + "$DESC", + "Rule for running custom commands.", + /*depfile*/ "", + /*restat*/ true); +} + +void +cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command, + const std::string& description, + const std::string& comment, + const cmNinjaDeps& outputs, + const cmNinjaDeps& deps, + const cmNinjaDeps& orderOnlyDeps) +{ + this->AddCustomCommandRule(); + + cmNinjaVars vars; + vars["COMMAND"] = command; + vars["DESC"] = EncodeLiteral(description); + + cmGlobalNinjaGenerator::WriteBuild(*this->BuildFileStream, + comment, + "CUSTOM_COMMAND", + outputs, + deps, + cmNinjaDeps(), + orderOnlyDeps, + vars); +} + +void cmGlobalNinjaGenerator::WriteRule(std::ostream& os, + const std::string& name, + const std::string& command, + const std::string& description, + const std::string& comment, + const std::string& depfile, + bool restat, + bool generator) +{ + // Make sure the rule has a name. + if(name.empty()) + { + cmSystemTools::Error("No name given for WriteRuleStatement! called " + "with comment: ", + comment.c_str()); + return; + } + + // Make sure a command is given. + if(command.empty()) + { + cmSystemTools::Error("No command given for WriteRuleStatement! called " + "with comment: ", + comment.c_str()); + return; + } + + cmGlobalNinjaGenerator::WriteComment(os, comment); + + // Write the rule. + os << "rule " << name << "\n"; + + // Write the depfile if any. + if(!depfile.empty()) + { + cmGlobalNinjaGenerator::Indent(os, 1); + os << "depfile = " << depfile << "\n"; + } + + // Write the command. + cmGlobalNinjaGenerator::Indent(os, 1); + os << "command = " << command << "\n"; + + // Write the description if any. + if(!description.empty()) + { + cmGlobalNinjaGenerator::Indent(os, 1); + os << "description = " << description << "\n"; + } + + if(restat) + { + cmGlobalNinjaGenerator::Indent(os, 1); + os << "restat = 1\n"; + } + + if(generator) + { + cmGlobalNinjaGenerator::Indent(os, 1); + os << "generator = 1\n"; + } +} + +void cmGlobalNinjaGenerator::WriteVariable(std::ostream& os, + const std::string& name, + const std::string& value, + const std::string& comment, + int indent) +{ + // Make sure we have a name. + if(name.empty()) + { + cmSystemTools::Error("No name given for WriteVariable! called " + "with comment: ", + comment.c_str()); + return; + } + + // Do not add a variable if the value is empty. + std::string val = cmSystemTools::TrimWhitespace(value); + if(val.empty()) + { + return; + } + + cmGlobalNinjaGenerator::WriteComment(os, comment); + cmGlobalNinjaGenerator::Indent(os, indent); + os << name << " = " << val << "\n"; +} + +void cmGlobalNinjaGenerator::WriteInclude(std::ostream& os, + const std::string& filename, + const std::string& comment) +{ + cmGlobalNinjaGenerator::WriteComment(os, comment); + os << "include " << filename << "\n"; +} + +void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os, + const cmNinjaDeps& targets, + const std::string& comment) +{ + cmGlobalNinjaGenerator::WriteComment(os, comment); + os << "default"; + for(cmNinjaDeps::const_iterator i = targets.begin(); i != targets.end(); ++i) + os << " " << *i; + os << "\n"; +} + + +cmGlobalNinjaGenerator::cmGlobalNinjaGenerator() + : cmGlobalGenerator() + , BuildFileStream(0) + , RulesFileStream(0) + , Rules() + , AllDependencies() +{ + // // Ninja is not ported to non-Unix OS yet. + // this->ForceUnixPaths = true; + this->FindMakeProgramFile = "CMakeNinjaFindMake.cmake"; +} + +//---------------------------------------------------------------------------- +// Virtual public methods. + +cmLocalGenerator* cmGlobalNinjaGenerator::CreateLocalGenerator() +{ + cmLocalGenerator* lg = new cmLocalNinjaGenerator; + lg->SetGlobalGenerator(this); + return lg; +} + +void cmGlobalNinjaGenerator +::GetDocumentation(cmDocumentationEntry& entry) const +{ + entry.Name = this->GetName(); + entry.Brief = "Generates build.ninja files (experimental)."; + entry.Full = + "A build.ninja file is generated into the build tree. Recent " + "versions of the ninja program can build the project through the " + "\"all\" target. An \"install\" target is also provided."; +} + +// Implemented in all cmGlobaleGenerator sub-classes. +// Used in: +// Source/cmLocalGenerator.cxx +// Source/cmake.cxx +void cmGlobalNinjaGenerator::Generate() +{ + this->OpenBuildFileStream(); + this->OpenRulesFileStream(); + + this->cmGlobalGenerator::Generate(); + + this->WriteAssumedSourceDependencies(); + this->WriteTargetAliases(*this->BuildFileStream); + this->WriteBuiltinTargets(*this->BuildFileStream); + + this->CloseRulesFileStream(); + this->CloseBuildFileStream(); +} + +// Implemented in all cmGlobaleGenerator sub-classes. +// Used in: +// Source/cmMakefile.cxx: +void cmGlobalNinjaGenerator +::EnableLanguage(std::vectorconst& languages, + cmMakefile *mf, + bool optional) +{ + this->cmGlobalGenerator::EnableLanguage(languages, mf, optional); + std::string path; + for(std::vector::const_iterator l = languages.begin(); + l != languages.end(); ++l) + { + if(*l == "NONE") + { + continue; + } + if(*l == "Fortran") + { + std::string message = "The \""; + message += this->GetName(); + message += "\" generator does not support the language \""; + message += *l; + message += "\" yet."; + cmSystemTools::Error(message.c_str()); + } + this->ResolveLanguageCompiler(*l, mf, optional); + } +} + +// Implemented by: +// cmGlobalUnixMakefileGenerator3 +// cmGlobalVisualStudio10Generator +// cmGlobalVisualStudio6Generator +// cmGlobalVisualStudio7Generator +// cmGlobalXCodeGenerator +// Called by: +// cmGlobalGenerator::Build() +std::string cmGlobalNinjaGenerator +::GenerateBuildCommand(const char* makeProgram, + const char* projectName, + const char* additionalOptions, + const char* targetName, + const char* config, + bool ignoreErrors, + bool fast) +{ + // Project name and config are not used yet. + (void)projectName; + (void)config; + // Ninja does not have -i equivalent option yet. + (void)ignoreErrors; + // We do not handle fast build yet. + (void)fast; + + std::string makeCommand = + cmSystemTools::ConvertToUnixOutputPath(makeProgram); + + if(additionalOptions) + { + makeCommand += " "; + makeCommand += additionalOptions; + } + if(targetName) + { + if(strcmp(targetName, "clean") == 0) + { + makeCommand += " -t clean"; + } + else + { + makeCommand += " "; + makeCommand += targetName; + } + } + + return makeCommand; +} + +//---------------------------------------------------------------------------- +// Non-virtual public methods. + +void cmGlobalNinjaGenerator::AddRule(const std::string& name, + const std::string& command, + const std::string& description, + const std::string& comment, + const std::string& depfile, + bool restat, + bool generator) +{ + // Do not add the same rule twice. + if (this->HasRule(name)) + return; + + this->Rules.insert(name); + cmGlobalNinjaGenerator::WriteRule(*this->RulesFileStream, + name, + command, + description, + comment, + depfile, + restat, + generator); +} + +bool cmGlobalNinjaGenerator::HasRule(const std::string &name) +{ + RulesSetType::const_iterator rule = this->Rules.find(name); + return (rule != this->Rules.end()); +} + +//---------------------------------------------------------------------------- +// Private virtual overrides + +// TODO: Refactor to combine with cmGlobalUnixMakefileGenerator3 impl. +void cmGlobalNinjaGenerator::ComputeTargetObjects(cmGeneratorTarget* gt) const +{ + cmTarget* target = gt->Target; + + // Compute full path to object file directory for this target. + std::string dir_max; + dir_max += gt->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += gt->LocalGenerator->GetTargetDirectory(*target); + dir_max += "/"; + gt->ObjectDirectory = dir_max; + + // Compute the name of each object file. + for(std::vector::iterator + si = gt->ObjectSources.begin(); + si != gt->ObjectSources.end(); ++si) + { + cmSourceFile* sf = *si; + std::string objectName = gt->LocalGenerator + ->GetObjectFileNameWithoutTarget(*sf, dir_max); + gt->Objects[sf] = objectName; + } +} + +//---------------------------------------------------------------------------- +// Private methods + +void cmGlobalNinjaGenerator::OpenBuildFileStream() +{ + // Compute Ninja's build file path. + std::string buildFilePath = + this->GetCMakeInstance()->GetHomeOutputDirectory(); + buildFilePath += "/"; + buildFilePath += cmGlobalNinjaGenerator::NINJA_BUILD_FILE; + + // Get a stream where to generate things. + if (!this->BuildFileStream) + { + this->BuildFileStream = new cmGeneratedFileStream(buildFilePath.c_str()); + if (!this->BuildFileStream) + { + // An error message is generated by the constructor if it cannot + // open the file. + return; + } + } + + // Write the do not edit header. + this->WriteDisclaimer(*this->BuildFileStream); + + // Write a comment about this file. + *this->BuildFileStream + << "# This file contains all the build statements describing the\n" + << "# compilation DAG.\n\n" + ; +} + +void cmGlobalNinjaGenerator::CloseBuildFileStream() +{ + if (this->BuildFileStream) + { + delete this->BuildFileStream; + this->BuildFileStream = 0; + } + else + { + cmSystemTools::Error("Build file stream was not open."); + } +} + +void cmGlobalNinjaGenerator::OpenRulesFileStream() +{ + // Compute Ninja's build file path. + std::string rulesFilePath = + this->GetCMakeInstance()->GetHomeOutputDirectory(); + rulesFilePath += "/"; + rulesFilePath += cmGlobalNinjaGenerator::NINJA_RULES_FILE; + + // Get a stream where to generate things. + if (!this->RulesFileStream) + { + this->RulesFileStream = new cmGeneratedFileStream(rulesFilePath.c_str()); + if (!this->RulesFileStream) + { + // An error message is generated by the constructor if it cannot + // open the file. + return; + } + } + + // Write the do not edit header. + this->WriteDisclaimer(*this->RulesFileStream); + + // Write comment about this file. + *this->RulesFileStream + << "# This file contains all the rules used to get the outputs files\n" + << "# built from the input files.\n" + << "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n" + ; +} + +void cmGlobalNinjaGenerator::CloseRulesFileStream() +{ + if (this->RulesFileStream) + { + delete this->RulesFileStream; + this->RulesFileStream = 0; + } + else + { + cmSystemTools::Error("Rules file stream was not open."); + } +} + +void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os) +{ + os + << "# CMAKE generated file: DO NOT EDIT!\n" + << "# Generated by \"" << this->GetName() << "\"" + << " Generator, CMake Version " + << cmVersion::GetMajorVersion() << "." + << cmVersion::GetMinorVersion() << "\n\n"; +} + +void cmGlobalNinjaGenerator::AddDependencyToAll(cmTarget* target) +{ + this->AppendTargetOutputs(target, this->AllDependencies); +} + +void cmGlobalNinjaGenerator::WriteAssumedSourceDependencies() +{ + for (std::map >::iterator + i = this->AssumedSourceDependencies.begin(); + i != this->AssumedSourceDependencies.end(); ++i) { + cmNinjaDeps deps; + std::copy(i->second.begin(), i->second.end(), std::back_inserter(deps)); + WriteCustomCommandBuild(/*command=*/"", /*description=*/"", + "Assume dependencies for generated source file.", + cmNinjaDeps(1, i->first), deps); + } +} + +void +cmGlobalNinjaGenerator +::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs) +{ + const char* configName = + target->GetMakefile()->GetDefinition("CMAKE_BUILD_TYPE"); + cmLocalNinjaGenerator *ng = + static_cast(this->LocalGenerators[0]); + + switch (target->GetType()) { + case cmTarget::EXECUTABLE: + case cmTarget::SHARED_LIBRARY: + case cmTarget::STATIC_LIBRARY: + case cmTarget::MODULE_LIBRARY: + outputs.push_back(ng->ConvertToNinjaPath( + target->GetFullPath(configName).c_str())); + break; + + case cmTarget::OBJECT_LIBRARY: + case cmTarget::UTILITY: { + std::string path = ng->ConvertToNinjaPath( + target->GetMakefile()->GetStartOutputDirectory()); + if (path.empty() || path == ".") + outputs.push_back(target->GetName()); + else { + path += "/"; + path += target->GetName(); + outputs.push_back(path); + } + break; + } + + case cmTarget::GLOBAL_TARGET: + // Always use the target in HOME instead of an unused duplicate in a + // subdirectory. + outputs.push_back(target->GetName()); + break; + + default: + return; + } +} + +void +cmGlobalNinjaGenerator +::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs) +{ + if (target->GetType() == cmTarget::GLOBAL_TARGET) { + // Global targets only depend on other utilities, which may not appear in + // the TargetDepends set (e.g. "all"). + std::set const& utils = target->GetUtilities(); + std::copy(utils.begin(), utils.end(), std::back_inserter(outputs)); + } else { + cmTargetDependSet const& targetDeps = + this->GetTargetDirectDepends(*target); + for (cmTargetDependSet::const_iterator i = targetDeps.begin(); + i != targetDeps.end(); ++i) { + this->AppendTargetOutputs(*i, outputs); + } + } +} + +void cmGlobalNinjaGenerator::AddTargetAlias(const std::string& alias, + cmTarget* target) { + cmNinjaDeps outputs; + this->AppendTargetOutputs(target, outputs); + // Mark the target's outputs as ambiguous to ensure that no other target uses + // the output as an alias. + for (cmNinjaDeps::iterator i = outputs.begin(); i != outputs.end(); ++i) + TargetAliases[*i] = 0; + + // Insert the alias into the map. If the alias was already present in the + // map and referred to another target, mark it as ambiguous. + std::pair newAlias = + TargetAliases.insert(make_pair(alias, target)); + if (newAlias.second && newAlias.first->second != target) + newAlias.first->second = 0; +} + +void cmGlobalNinjaGenerator::WriteTargetAliases(std::ostream& os) +{ + cmGlobalNinjaGenerator::WriteDivider(os); + os << "# Target aliases.\n\n"; + + for (TargetAliasMap::iterator i = TargetAliases.begin(); + i != TargetAliases.end(); ++i) { + // Don't write ambiguous aliases. + if (!i->second) + continue; + + cmNinjaDeps deps; + this->AppendTargetOutputs(i->second, deps); + + cmGlobalNinjaGenerator::WritePhonyBuild(os, + "", + cmNinjaDeps(1, i->first), + deps); + } +} + +void cmGlobalNinjaGenerator::WriteBuiltinTargets(std::ostream& os) +{ + // Write headers. + cmGlobalNinjaGenerator::WriteDivider(os); + os << "# Built-in targets\n\n"; + + this->WriteTargetAll(os); + this->WriteTargetRebuildManifest(os); +} + +void cmGlobalNinjaGenerator::WriteTargetAll(std::ostream& os) +{ + cmNinjaDeps outputs; + outputs.push_back("all"); + + cmGlobalNinjaGenerator::WritePhonyBuild(os, + "The main all target.", + outputs, + this->AllDependencies); + + cmGlobalNinjaGenerator::WriteDefault(os, + outputs, + "Make the all target the default."); +} + +void cmGlobalNinjaGenerator::WriteTargetRebuildManifest(std::ostream& os) +{ + cmLocalGenerator *lg = this->LocalGenerators[0]; + cmMakefile* mfRoot = lg->GetMakefile(); + + std::ostringstream cmd; + cmd << lg->ConvertToOutputFormat( + mfRoot->GetRequiredDefinition("CMAKE_COMMAND"), + cmLocalGenerator::SHELL) + << " -H" + << lg->ConvertToOutputFormat(mfRoot->GetHomeDirectory(), + cmLocalGenerator::SHELL) + << " -B" + << lg->ConvertToOutputFormat(mfRoot->GetHomeOutputDirectory(), + cmLocalGenerator::SHELL); + WriteRule(*this->RulesFileStream, + "RERUN_CMAKE", + cmd.str(), + "Re-running CMake...", + "Rule for re-running cmake.", + /*depfile=*/ "", + /*restat=*/ false, + /*generator=*/ true); + + cmNinjaDeps implicitDeps; + for (std::vector::const_iterator i = + this->LocalGenerators.begin(); i != this->LocalGenerators.end(); ++i) { + const std::vector& lf = (*i)->GetMakefile()->GetListFiles(); + implicitDeps.insert(implicitDeps.end(), lf.begin(), lf.end()); + } + std::sort(implicitDeps.begin(), implicitDeps.end()); + implicitDeps.erase(std::unique(implicitDeps.begin(), implicitDeps.end()), + implicitDeps.end()); + implicitDeps.push_back("CMakeCache.txt"); + + WriteBuild(os, + "Re-run CMake if any of its inputs changed.", + "RERUN_CMAKE", + /*outputs=*/ cmNinjaDeps(1, NINJA_BUILD_FILE), + /*explicitDeps=*/ cmNinjaDeps(), + implicitDeps, + /*orderOnlyDeps=*/ cmNinjaDeps(), + /*variables=*/ cmNinjaVars()); + + WritePhonyBuild(os, + "A missing CMake input file is not an error.", + implicitDeps, + cmNinjaDeps()); +} diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h new file mode 100644 index 000000000..321758185 --- /dev/null +++ b/Source/cmGlobalNinjaGenerator.h @@ -0,0 +1,338 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmGlobalNinjaGenerator_h +# define cmGlobalNinjaGenerator_h + +# include "cmGlobalGenerator.h" +# include "cmNinjaTypes.h" + +class cmLocalGenerator; +class cmGeneratedFileStream; +class cmGeneratorTarget; + +/** + * \class cmGlobalNinjaGenerator + * \brief Write a build.ninja file. + * + * The main differences between this generator and the UnixMakefile + * generator family are: + * - We don't care about VERBOSE variable or RULE_MESSAGES property since + * it is handle by Ninja's -v option. + * - We don't care about computing any progress status since Ninja manages + * it itself. + * - We don't care about generating a clean target since Ninja already have + * a clean tool. + * - We generate one build.ninja and one rules.ninja per project. + * - We try to minimize the number of generated rules: one per target and + * language. + * - We use Ninja special variable $in and $out to produce nice output. + * - We extensively use Ninja variable overloading system to minimize the + * number of generated rules. + */ +class cmGlobalNinjaGenerator : public cmGlobalGenerator +{ +public: + /// The default name of Ninja's build file. Typically: build.ninja. + static const char* NINJA_BUILD_FILE; + + /// The default name of Ninja's rules file. Typically: rules.ninja. + /// It is included in the main build.ninja file. + static const char* NINJA_RULES_FILE; + + /// The indentation string used when generating Ninja's build file. + static const char* INDENT; + + /// Write @a count times INDENT level to output stream @a os. + static void Indent(std::ostream& os, int count); + + /// Write a divider in the given output stream @a os. + static void WriteDivider(std::ostream& os); + + static std::string EncodeIdent(const std::string &ident, std::ostream &vars); + static std::string EncodeLiteral(const std::string &lit); + static std::string EncodePath(const std::string &path); + + /** + * Write the given @a comment to the output stream @a os. It + * handles new line character properly. + */ + static void WriteComment(std::ostream& os, const std::string& comment); + + /** + * Write a build statement to @a os with the @a comment using + * the @a rule the list of @a outputs files and inputs. + * It also writes the variables bound to this build statement. + * @warning no escaping of any kind is done here. + */ + static void WriteBuild(std::ostream& os, + const std::string& comment, + const std::string& rule, + const cmNinjaDeps& outputs, + const cmNinjaDeps& explicitDeps, + const cmNinjaDeps& implicitDeps, + const cmNinjaDeps& orderOnlyDeps, + const cmNinjaVars& variables); + + /** + * Helper to write a build statement with the special 'phony' rule. + */ + static void WritePhonyBuild(std::ostream& os, + const std::string& comment, + const cmNinjaDeps& outputs, + const cmNinjaDeps& explicitDeps, + const cmNinjaDeps& implicitDeps = cmNinjaDeps(), + const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps(), + const cmNinjaVars& variables = cmNinjaVars()); + + void WriteCustomCommandBuild(const std::string& command, + const std::string& description, + const std::string& comment, + const cmNinjaDeps& outputs, + const cmNinjaDeps& deps = cmNinjaDeps(), + const cmNinjaDeps& orderOnlyDeps = cmNinjaDeps()); + + /** + * Write a rule statement named @a name to @a os with the @a comment, + * the mandatory @a command, the @a depfile and the @a description. + * It also writes the variables bound to this rule statement. + * @warning no escaping of any kind is done here. + */ + static void WriteRule(std::ostream& os, + const std::string& name, + const std::string& command, + const std::string& description, + const std::string& comment = "", + const std::string& depfile = "", + bool restat = false, + bool generator = false); + + /** + * Write a variable named @a name to @a os with value @a value and an + * optional @a comment. An @a indent level can be specified. + * @warning no escaping of any kind is done here. + */ + static void WriteVariable(std::ostream& os, + const std::string& name, + const std::string& value, + const std::string& comment = "", + int indent = 0); + + /** + * Write an include statement including @a filename with an optional + * @a comment to the @a os stream. + */ + static void WriteInclude(std::ostream& os, + const std::string& filename, + const std::string& comment = ""); + + /** + * Write a default target statement specifying @a targets as + * the default targets. + */ + static void WriteDefault(std::ostream& os, + const cmNinjaDeps& targets, + const std::string& comment = ""); + +public: + /// Default constructor. + cmGlobalNinjaGenerator(); + + /// Convenience method for creating an instance of this class. + static cmGlobalGenerator* New() { + return new cmGlobalNinjaGenerator; } + + /// Destructor. + virtual ~cmGlobalNinjaGenerator() { } + + /// Overloaded methods. @see cmGlobalGenerator::CreateLocalGenerator() + virtual cmLocalGenerator* CreateLocalGenerator(); + + /// Overloaded methods. @see cmGlobalGenerator::GetName(). + virtual const char* GetName() const { + return cmGlobalNinjaGenerator::GetActualName(); } + + /// @return the name of this generator. + static const char* GetActualName() { return "Ninja"; } + + /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation() + virtual void GetDocumentation(cmDocumentationEntry& entry) const; + + /// Overloaded methods. @see cmGlobalGenerator::Generate() + virtual void Generate(); + + /// Overloaded methods. @see cmGlobalGenerator::EnableLanguage() + virtual void EnableLanguage(std::vectorconst& languages, + cmMakefile* mf, + bool optional); + + /// Overloaded methods. @see cmGlobalGenerator::GenerateBuildCommand() + virtual std::string GenerateBuildCommand(const char* makeProgram, + const char* projectName, + const char* additionalOptions, + const char* targetName, + const char* config, + bool ignoreErrors, + bool fast); + + // Setup target names + virtual const char* GetAllTargetName() const { return "all"; } + virtual const char* GetInstallTargetName() const { return "install"; } + virtual const char* GetInstallLocalTargetName() const { + return "install/local"; + } + virtual const char* GetInstallStripTargetName() const { + return "install/strip"; + } + virtual const char* GetTestTargetName() const { return "test"; } + virtual const char* GetPackageTargetName() const { return "package"; } + virtual const char* GetPackageSourceTargetName() const { + return "package_source"; + } + virtual const char* GetEditCacheTargetName() const { + return "edit_cache"; + } + virtual const char* GetRebuildCacheTargetName() const { + return "rebuild_cache"; + } + virtual const char* GetCleanTargetName() const { return "clean"; } + +public: + cmGeneratedFileStream* GetBuildFileStream() const + { return this->BuildFileStream; } + + cmGeneratedFileStream* GetRulesFileStream() const + { return this->RulesFileStream; } + + /** + * Add a rule to the generated build system. + * Call WriteRule() behind the scene but perform some check before like: + * - Do not add twice the same rule. + */ + void AddRule(const std::string& name, + const std::string& command, + const std::string& description, + const std::string& comment = "", + const std::string& depfile = "", + bool restat = false, + bool generator = false); + + bool HasRule(const std::string& name); + + void AddCustomCommandRule(); + +protected: + + /// Overloaded methods. + /// @see cmGlobalGenerator::CheckALLOW_DUPLICATE_CUSTOM_TARGETS() + virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; } + +private: + + /// @see cmGlobalGenerator::ComputeTargetObjects + virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; + +private: + // In order to access the AddDependencyToAll() functions and co. + friend class cmLocalNinjaGenerator; + + // In order to access the SeenCustomCommand() function. + friend class cmNinjaTargetGenerator; + friend class cmNinjaNormalTargetGenerator; + friend class cmNinjaUtilityTargetGenerator; + +private: + void OpenBuildFileStream(); + void CloseBuildFileStream(); + + void OpenRulesFileStream(); + void CloseRulesFileStream(); + + /// Write the common disclaimer text at the top of each build file. + void WriteDisclaimer(std::ostream& os); + + void AddDependencyToAll(cmTarget* target); + + void WriteAssumedSourceDependencies(); + + void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); + void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); + + void AddTargetAlias(const std::string& alias, cmTarget* target); + void WriteTargetAliases(std::ostream& os); + + void WriteBuiltinTargets(std::ostream& os); + void WriteTargetAll(std::ostream& os); + void WriteTargetRebuildManifest(std::ostream& os); + + /// Called when we have seen the given custom command. Returns true + /// if we has seen it before. + bool SeenCustomCommand(cmCustomCommand const *cc) { + return !this->CustomCommands.insert(cc).second; + } + + /// Called when we have seen the given custom command output. + void SeenCustomCommandOutput(const std::string &output) { + this->CustomCommandOutputs.insert(output); + // We don't need the assumed dependencies anymore, because we have + // an output. + this->AssumedSourceDependencies.erase(output); + } + + bool HasCustomCommandOutput(const std::string &output) { + return this->CustomCommandOutputs.find(output) != + this->CustomCommandOutputs.end(); + } + + void AddAssumedSourceDependencies(const std::string &source, + const cmNinjaDeps &deps) { + std::set &ASD = this->AssumedSourceDependencies[source]; + // Because we may see the same source file multiple times (same source + // specified in multiple targets), compute the union of any assumed + // dependencies. + ASD.insert(deps.begin(), deps.end()); + } + +private: + /// The file containing the build statement. (the relation ship of the + /// compilation DAG). + cmGeneratedFileStream* BuildFileStream; + /// The file containing the rule statements. (The action attached to each + /// edge of the compilation DAG). + cmGeneratedFileStream* RulesFileStream; + + /// The type used to store the set of rules added to the generated build + /// system. + typedef std::set RulesSetType; + + /// The set of rules added to the generated build system. + RulesSetType Rules; + + /// The set of dependencies to add to the "all" target. + cmNinjaDeps AllDependencies; + + /// The set of custom commands we have seen. + std::set CustomCommands; + + /// The set of custom command outputs we have seen. + std::set CustomCommandOutputs; + + /// The mapping from source file to assumed dependencies. + std::map > AssumedSourceDependencies; + + typedef std::map TargetAliasMap; + TargetAliasMap TargetAliases; + + static cmLocalGenerator* LocalGenerator; +}; + +#endif // ! cmGlobalNinjaGenerator_h diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index a23c0d8d3..e63de9cae 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -17,6 +17,7 @@ #include "cmGeneratedFileStream.h" #include "cmSourceFile.h" #include "cmTarget.h" +#include "cmGeneratorTarget.h" cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3() { @@ -70,6 +71,38 @@ void cmGlobalUnixMakefileGenerator3 "default make target. A \"make install\" target is also provided."; } +//---------------------------------------------------------------------------- +void +cmGlobalUnixMakefileGenerator3 +::ComputeTargetObjects(cmGeneratorTarget* gt) const +{ + cmTarget* target = gt->Target; + cmLocalUnixMakefileGenerator3* lg = + static_cast(gt->LocalGenerator); + + // Compute full path to object file directory for this target. + std::string dir_max; + dir_max += gt->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += gt->LocalGenerator->GetTargetDirectory(*target); + dir_max += "/"; + gt->ObjectDirectory = dir_max; + + // Compute the name of each object file. + for(std::vector::iterator + si = gt->ObjectSources.begin(); + si != gt->ObjectSources.end(); ++si) + { + cmSourceFile* sf = *si; + bool hasSourceExtension = true; + std::string objectName = gt->LocalGenerator + ->GetObjectFileNameWithoutTarget(*sf, dir_max, + &hasSourceExtension); + gt->Objects[sf] = objectName; + lg->AddLocalObjectFile(target, sf, objectName, hasSourceExtension); + } +} + //---------------------------------------------------------------------------- std::string EscapeJSON(const std::string& s) { std::string result; @@ -378,6 +411,7 @@ void cmGlobalUnixMakefileGenerator3 (l->second.GetType() == cmTarget::STATIC_LIBRARY) || (l->second.GetType() == cmTarget::SHARED_LIBRARY) || (l->second.GetType() == cmTarget::MODULE_LIBRARY) || + (l->second.GetType() == cmTarget::OBJECT_LIBRARY) || (l->second.GetType() == cmTarget::UTILITY)) { std::string tname = lg->GetRelativeTargetDirectory(l->second); @@ -413,6 +447,7 @@ cmGlobalUnixMakefileGenerator3 (l->second.GetType() == cmTarget::STATIC_LIBRARY) || (l->second.GetType() == cmTarget::SHARED_LIBRARY) || (l->second.GetType() == cmTarget::MODULE_LIBRARY) || + (l->second.GetType() == cmTarget::OBJECT_LIBRARY) || (l->second.GetType() == cmTarget::UTILITY)) { // Add this to the list of depends rules in this directory. @@ -587,6 +622,7 @@ cmGlobalUnixMakefileGenerator3 (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) || + (t->second.GetType() == cmTarget::OBJECT_LIBRARY) || (t->second.GetType() == cmTarget::UTILITY))) { // Add a rule to build the target by name. @@ -673,6 +709,7 @@ cmGlobalUnixMakefileGenerator3 || (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) + || (t->second.GetType() == cmTarget::OBJECT_LIBRARY) || (t->second.GetType() == cmTarget::UTILITY))) { std::string makefileName; @@ -982,6 +1019,7 @@ void cmGlobalUnixMakefileGenerator3::WriteHelpRule (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) || + (t->second.GetType() == cmTarget::OBJECT_LIBRARY) || (t->second.GetType() == cmTarget::GLOBAL_TARGET) || (t->second.GetType() == cmTarget::UTILITY)) { diff --git a/Source/cmGlobalUnixMakefileGenerator3.h b/Source/cmGlobalUnixMakefileGenerator3.h index 9663b5592..e6dd09d6d 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.h +++ b/Source/cmGlobalUnixMakefileGenerator3.h @@ -182,6 +182,8 @@ protected: size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg); cmGeneratedFileStream *CommandDatabase; +private: + virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const; }; #endif diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index 18b483d09..750b89c4c 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -72,7 +72,7 @@ public: * Studio? */ virtual std::string GetUserMacrosRegKeyBase(); - virtual const char* GetCMakeCFGInitDirectory() + virtual const char* GetCMakeCFGIntDir() const { return "$(Configuration)";} bool Find64BitTools(cmMakefile* mf); protected: diff --git a/Source/cmGlobalVisualStudio6Generator.h b/Source/cmGlobalVisualStudio6Generator.h index 77d537075..da08a125b 100644 --- a/Source/cmGlobalVisualStudio6Generator.h +++ b/Source/cmGlobalVisualStudio6Generator.h @@ -82,7 +82,7 @@ public: std::string& dir); ///! What is the configurations directory variable called? - virtual const char* GetCMakeCFGInitDirectory() { return "$(IntDir)"; } + virtual const char* GetCMakeCFGIntDir() const { return "$(IntDir)"; } protected: virtual const char* GetIDEVersion() { return "6.0"; } diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index adfb757f1..c92998e7e 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -87,7 +87,7 @@ public: std::string& dir); ///! What is the configurations directory variable called? - virtual const char* GetCMakeCFGInitDirectory() { return "$(OutDir)"; } + virtual const char* GetCMakeCFGIntDir() const { return "$(OutDir)"; } /** Return true if the target project file should have the option LinkLibraryDependencies and link to .sln dependencies. */ diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 449d09016..2a918c925 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -12,8 +12,10 @@ #include "cmGlobalVisualStudioGenerator.h" #include "cmCallVisualStudioMacro.h" -#include "cmLocalGenerator.h" +#include "cmGeneratorTarget.h" +#include "cmLocalVisualStudioGenerator.h" #include "cmMakefile.h" +#include "cmSourceFile.h" #include "cmTarget.h" //---------------------------------------------------------------------------- @@ -93,10 +95,78 @@ void cmGlobalVisualStudioGenerator::Generate() // of Visual Studio. this->ConfigureCMakeVisualStudioMacros(); + // Add CMakeLists.txt with custom command to rerun CMake. + for(std::vector::const_iterator + lgi = this->LocalGenerators.begin(); + lgi != this->LocalGenerators.end(); ++lgi) + { + cmLocalVisualStudioGenerator* lg = + static_cast(*lgi); + lg->AddCMakeListsRules(); + } + // Run all the local generators. this->cmGlobalGenerator::Generate(); } +//---------------------------------------------------------------------------- +void +cmGlobalVisualStudioGenerator +::ComputeTargetObjects(cmGeneratorTarget* gt) const +{ + cmLocalVisualStudioGenerator* lg = + static_cast(gt->LocalGenerator); + std::string dir_max = lg->ComputeLongestObjectDirectory(*gt->Target); + + // Count the number of object files with each name. Note that + // windows file names are not case sensitive. + std::map counts; + for(std::vector::const_iterator + si = gt->ObjectSources.begin(); + si != gt->ObjectSources.end(); ++si) + { + cmSourceFile* sf = *si; + std::string objectNameLower = cmSystemTools::LowerCase( + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); + objectNameLower += ".obj"; + counts[objectNameLower] += 1; + } + + // For all source files producing duplicate names we need unique + // object name computation. + for(std::vector::const_iterator + si = gt->ObjectSources.begin(); + si != gt->ObjectSources.end(); ++si) + { + cmSourceFile* sf = *si; + std::string objectName = + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); + objectName += ".obj"; + if(counts[cmSystemTools::LowerCase(objectName)] > 1) + { + gt->ExplicitObjectName.insert(sf); + objectName = lg->GetObjectFileNameWithoutTarget(*sf, dir_max); + } + gt->Objects[sf] = objectName; + } + + std::string dir = gt->Makefile->GetCurrentOutputDirectory(); + dir += "/"; + std::string tgtDir = lg->GetTargetDirectory(*gt->Target); + if(!tgtDir.empty()) + { + dir += tgtDir; + dir += "/"; + } + const char* cd = this->GetCMakeCFGIntDir(); + if(cd && *cd) + { + dir += cd; + dir += "/"; + } + gt->ObjectDirectory = dir; +} + //---------------------------------------------------------------------------- bool IsVisualStudioMacrosFileRegistered(const std::string& macrosFile, const std::string& regKeyBase, @@ -314,6 +384,12 @@ bool cmGlobalVisualStudioGenerator::ComputeTargetDepends() return true; } +//---------------------------------------------------------------------------- +static bool VSLinkable(cmTarget* t) +{ + return t->IsLinkable() || t->GetType() == cmTarget::OBJECT_LIBRARY; +} + //---------------------------------------------------------------------------- void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target) { @@ -398,7 +474,7 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target) di != utilDepends.end(); ++di) { cmTarget* dep = *di; - if(allowLinkable || !dep->IsLinkable() || linked.count(dep)) + if(allowLinkable || !VSLinkable(dep) || linked.count(dep)) { // Direct dependency allowed. vsTargetDepend.insert(dep->GetName()); diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index bc96f4e0a..b62ba229d 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -97,6 +97,8 @@ protected: typedef std::map UtilityDependsMap; UtilityDependsMap UtilityDepends; private: + void ComputeTargetObjects(cmGeneratorTarget* gt) const; + void FollowLinkDepends(cmTarget* target, std::set& linked); class TargetSetMap: public std::map {}; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 859503f51..998843f45 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -19,6 +19,7 @@ #include "cmComputeLinkInformation.h" #include "cmSourceFile.h" #include "cmCustomCommandGenerator.h" +#include "cmGeneratorTarget.h" #include @@ -135,8 +136,17 @@ cmGlobalGenerator* cmGlobalXCodeGenerator::New() { #if defined(CMAKE_BUILD_WITH_CMAKE) cmXcodeVersionParser parser; - parser.ParseFile - ("/Developer/Applications/Xcode.app/Contents/version.plist"); + if (cmSystemTools::FileExists( + "/Applications/Xcode.app/Contents/version.plist")) + { + parser.ParseFile + ("/Applications/Xcode.app/Contents/version.plist"); + } + else + { + parser.ParseFile + ("/Developer/Applications/Xcode.app/Contents/version.plist"); + } cmsys::auto_ptr gg(new cmGlobalXCodeGenerator(parser.Version)); if (gg->XcodeVersion == 20) @@ -179,8 +189,6 @@ void cmGlobalXCodeGenerator::EnableLanguage(std::vectorconst& mf->AddDefinition("CMAKE_GENERATOR_CC", "gcc"); mf->AddDefinition("CMAKE_GENERATOR_CXX", "g++"); mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1"); - // initialize Architectures so it can be used by - // GetTargetObjectFileDirectories this->cmGlobalGenerator::EnableLanguage(lang, mf, optional); const char* osxArch = mf->GetDefinition("CMAKE_OSX_ARCHITECTURES"); @@ -296,6 +304,10 @@ void cmGlobalXCodeGenerator::Generate() } this->ForceLinkerLanguages(); this->cmGlobalGenerator::Generate(); + if(cmSystemTools::GetErrorOccuredFlag()) + { + return; + } for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it) { cmLocalGenerator* root = it->second[0]; @@ -410,6 +422,8 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, // this will make sure that when the next target is built // things are up-to-date if((target.GetType() == cmTarget::EXECUTABLE || +// Nope - no post-build for OBJECT_LIRBRARY +// target.GetType() == cmTarget::OBJECT_LIBRARY || target.GetType() == cmTarget::STATIC_LIBRARY || target.GetType() == cmTarget::SHARED_LIBRARY || target.GetType() == cmTarget::MODULE_LIBRARY)) @@ -563,14 +577,42 @@ cmXCodeObject* cmGlobalXCodeGenerator } //---------------------------------------------------------------------------- -cmStdString GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf) +cmStdString +GetGroupMapKeyFromPath(cmTarget& cmtarget, const std::string& fullpath) { cmStdString key(cmtarget.GetName()); key += "-"; - key += sf->GetFullPath(); + key += fullpath; return key; } +//---------------------------------------------------------------------------- +cmStdString +GetGroupMapKey(cmTarget& cmtarget, cmSourceFile* sf) +{ + return GetGroupMapKeyFromPath(cmtarget, sf->GetFullPath()); +} + +//---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeSourceFileFromPath( + const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang) +{ + // Using a map and the full path guarantees that we will always get the same + // fileRef object for any given full path. + // + cmXCodeObject* fileRef = + this->CreateXCodeFileReferenceFromPath(fullpath, cmtarget, lang); + + cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile); + buildFile->SetComment(fileRef->GetComment()); + buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef)); + + return buildFile; +} + //---------------------------------------------------------------------------- cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, @@ -605,14 +647,16 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, flags += flagsBuild.GetString(); } - // Using a map and the full path guarantees that we will always get the same - // fileRef object for any given full path. - // - cmXCodeObject* fileRef = this->CreateXCodeFileReference(sf, cmtarget); + const char* lang = + this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + if (!lang) + { + lang = ""; + } - cmXCodeObject* buildFile = this->CreateObject(cmXCodeObject::PBXBuildFile); - buildFile->SetComment(fileRef->GetComment()); - buildFile->AddAttribute("fileRef", this->CreateObjectReference(fileRef)); + cmXCodeObject* buildFile = + this->CreateXCodeSourceFileFromPath(sf->GetFullPath(), cmtarget, lang); + cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject(); cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); @@ -664,36 +708,12 @@ cmGlobalXCodeGenerator::CreateXCodeSourceFile(cmLocalGenerator* lg, } //---------------------------------------------------------------------------- -cmXCodeObject* -cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, - cmTarget& cmtarget) +std::string +GetSourcecodeValueFromFileExtension(const std::string& _ext, + const std::string& lang) { - std::string fname = sf->GetFullPath(); - cmXCodeObject* fileRef = this->FileRefs[fname]; - if(!fileRef) - { - fileRef = this->CreateObject(cmXCodeObject::PBXFileReference); - std::string comment = fname; - //comment += " in "; - //std::string gname = group->GetObject("name")->GetString(); - //comment += gname.substr(1, gname.size()-2); - fileRef->SetComment(fname.c_str()); - this->FileRefs[fname] = fileRef; - } - cmStdString key = GetGroupMapKey(cmtarget, sf); - cmXCodeObject* group = this->GroupMap[key]; - cmXCodeObject* children = group->GetObject("children"); - if (!children->HasObject(fileRef)) - { - children->AddObject(fileRef); - } - fileRef->AddAttribute("fileEncoding", this->CreateString("4")); - - const char* lang = - this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + std::string ext = cmSystemTools::LowerCase(_ext); std::string sourcecode = "sourcecode"; - std::string ext = sf->GetExtension(); - ext = cmSystemTools::LowerCase(ext); if(ext == "o") { @@ -728,25 +748,25 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, { sourcecode += ".cpp.h"; } - else if(lang && strcmp(lang, "CXX") == 0) + else if(ext == "png" || ext == "gif" || ext == "jpg") { - sourcecode += ".cpp.cpp"; + sourcecode = "image"; } - else if(lang && strcmp(lang, "C") == 0) + else if(ext == "txt") { - sourcecode += ".c.c"; + sourcecode += ".text"; } - else if(lang && strcmp(lang, "Fortran") == 0) + else if(lang == "CXX") { - sourcecode += ".fortran.f90"; + sourcecode += ".cpp.cpp"; } - else if(ext == "png" || ext == "gif" || ext == "jpg") + else if(lang == "C") { - sourcecode = "image"; + sourcecode += ".c.c"; } - else if(ext == "txt") + else if(lang == "Fortran") { - sourcecode += ".text"; + sourcecode += ".fortran.f90"; } //else // { @@ -756,11 +776,51 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, // // valid lastKnownFileType value. // } + return sourcecode; +} + +//---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeFileReferenceFromPath( + const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang) +{ + std::string fname = fullpath; + cmXCodeObject* fileRef = this->FileRefs[fname]; + if(!fileRef) + { + fileRef = this->CreateObject(cmXCodeObject::PBXFileReference); + std::string comment = fname; + fileRef->SetComment(fname.c_str()); + this->FileRefs[fname] = fileRef; + } + cmStdString key = GetGroupMapKeyFromPath(cmtarget, fullpath); + cmXCodeObject* group = this->GroupMap[key]; + cmXCodeObject* children = group->GetObject("children"); + if (!children->HasObject(fileRef)) + { + children->AddObject(fileRef); + } + fileRef->AddAttribute("fileEncoding", this->CreateString("4")); + + // Compute the extension. + std::string ext; + std::string realExt = + cmSystemTools::GetFilenameLastExtension(fullpath); + if(!realExt.empty()) + { + // Extension without the leading '.'. + ext = realExt.substr(1); + } + + std::string sourcecode = GetSourcecodeValueFromFileExtension(ext, lang); + fileRef->AddAttribute("lastKnownFileType", this->CreateString(sourcecode.c_str())); // Store the file path relative to the top of the source tree. - std::string path = this->RelativeToSource(sf->GetFullPath().c_str()); + std::string path = this->RelativeToSource(fullpath.c_str()); std::string name = cmSystemTools::GetFilenameName(path.c_str()); const char* sourceTree = (cmSystemTools::FileIsFullPath(path.c_str())? "" : "SOURCE_ROOT"); @@ -774,6 +834,22 @@ cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, return fileRef; } +//---------------------------------------------------------------------------- +cmXCodeObject* +cmGlobalXCodeGenerator::CreateXCodeFileReference(cmSourceFile* sf, + cmTarget& cmtarget) +{ + const char* lang = + this->CurrentLocalGenerator->GetSourceFileLanguage(*sf); + if (!lang) + { + lang = ""; + } + + return this->CreateXCodeFileReferenceFromPath( + sf->GetFullPath(), cmtarget, lang); +} + //---------------------------------------------------------------------------- bool cmGlobalXCodeGenerator::SpecialTargetEmitted(std::string const& tname) { @@ -882,6 +958,20 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, } } + // Add object library contents as external objects. (Equivalent to + // the externalObjFiles above, except each one is not a cmSourceFile + // within the target.) + std::vector objs; + this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs); + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + std::string obj = *oi; + cmXCodeObject* xsf = + this->CreateXCodeSourceFileFromPath(obj, cmtarget, ""); + externalObjFiles.push_back(xsf); + } + // some build phases only apply to bundles and/or frameworks bool isFrameworkTarget = cmtarget.IsFrameworkOnApple(); bool isBundleTarget = cmtarget.GetPropertyAsBool("MACOSX_BUNDLE"); @@ -1487,7 +1577,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, std::string defFlags; bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) || (target.GetType() == cmTarget::MODULE_LIBRARY)); - bool binary = ((target.GetType() == cmTarget::STATIC_LIBRARY) || + bool binary = ((target.GetType() == cmTarget::OBJECT_LIBRARY) || + (target.GetType() == cmTarget::STATIC_LIBRARY) || (target.GetType() == cmTarget::EXECUTABLE) || shared); @@ -1574,7 +1665,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, } const char* linkFlagsProp = "LINK_FLAGS"; - if(target.GetType() == cmTarget::STATIC_LIBRARY) + if(target.GetType() == cmTarget::OBJECT_LIBRARY || + target.GetType() == cmTarget::STATIC_LIBRARY) { linkFlagsProp = "STATIC_LIBRARY_FLAGS"; } @@ -1628,11 +1720,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, std::string pnprefix; std::string pnbase; std::string pnsuffix; - target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName); - // Store the product name for all target types. - buildSettings->AddAttribute("PRODUCT_NAME", - this->CreateString(pnbase.c_str())); + target.GetFullNameComponents(pnprefix, pnbase, pnsuffix, configName); // Set attributes to specify the proper name for the target. std::string pndir = this->CurrentMakefile->GetCurrentOutputDirectory(); @@ -1656,17 +1745,44 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->CreateString(pndir.c_str())); pndir = target.GetDirectory(configName); } + buildSettings->AddAttribute("EXECUTABLE_PREFIX", this->CreateString(pnprefix.c_str())); buildSettings->AddAttribute("EXECUTABLE_SUFFIX", this->CreateString(pnsuffix.c_str())); } + else if(target.GetType() == cmTarget::OBJECT_LIBRARY) + { + pnprefix = "lib"; + pnbase = target.GetName(); + pnsuffix = ".a"; + + if(this->XcodeVersion >= 21) + { + std::string pncdir = this->GetObjectsNormalDirectory( + this->CurrentProject, configName, &target); + buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", + this->CreateString(pncdir.c_str())); + } + else + { + buildSettings->AddAttribute("OBJROOT", + this->CreateString(pndir.c_str())); + pndir = this->GetObjectsNormalDirectory( + this->CurrentProject, configName, &target); + } + } + + // Store the product name for all target types. + buildSettings->AddAttribute("PRODUCT_NAME", + this->CreateString(pnbase.c_str())); buildSettings->AddAttribute("SYMROOT", this->CreateString(pndir.c_str())); // Handle settings for each target type. switch(target.GetType()) { + case cmTarget::OBJECT_LIBRARY: case cmTarget::STATIC_LIBRARY: { buildSettings->AddAttribute("LIBRARY_STYLE", @@ -1811,7 +1927,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, BuildObjectListOrString dirs(this, this->XcodeVersion >= 30); BuildObjectListOrString fdirs(this, this->XcodeVersion >= 30); std::vector includes; - this->CurrentLocalGenerator->GetIncludeDirectories(includes); + this->CurrentLocalGenerator->GetIncludeDirectories(includes, &target); std::set emitted; emitted.insert("/System/Library/Frameworks"); for(std::vector::iterator i = includes.begin(); @@ -2170,6 +2286,7 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget) { switch(cmtarget.GetType()) { + case cmTarget::OBJECT_LIBRARY: case cmTarget::STATIC_LIBRARY: return "archive.ar"; case cmTarget::MODULE_LIBRARY: @@ -2193,6 +2310,7 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget) { switch(cmtarget.GetType()) { + case cmTarget::OBJECT_LIBRARY: case cmTarget::STATIC_LIBRARY: return "com.apple.product-type.library.static"; case cmTarget::MODULE_LIBRARY: @@ -2250,7 +2368,17 @@ cmGlobalXCodeGenerator::CreateXCodeTarget(cmTarget& cmtarget, { fileRef->AddAttribute("explicitFileType", this->CreateString(fileType)); } - std::string fullName = cmtarget.GetFullName(defConfig.c_str()); + std::string fullName; + if(cmtarget.GetType() == cmTarget::OBJECT_LIBRARY) + { + fullName = "lib"; + fullName += cmtarget.GetName(); + fullName += ".a"; + } + else + { + fullName = cmtarget.GetFullName(defConfig.c_str()); + } fileRef->AddAttribute("path", this->CreateString(fullName.c_str())); fileRef->AddAttribute("refType", this->CreateString("0")); fileRef->AddAttribute("sourceTree", @@ -2455,7 +2583,8 @@ void cmGlobalXCodeGenerator } // Skip link information for static libraries. - if(cmtarget->GetType() == cmTarget::STATIC_LIBRARY) + if(cmtarget->GetType() == cmTarget::OBJECT_LIBRARY || + cmtarget->GetType() == cmTarget::STATIC_LIBRARY) { return; } @@ -2603,6 +2732,7 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root, std::vector classes = cmtarget.GetSourceFiles(); + // Put cmSourceFile instances in proper groups: for(std::vector::const_iterator s = classes.begin(); s != classes.end(); s++) { @@ -2616,6 +2746,21 @@ void cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root, cmStdString key = GetGroupMapKey(cmtarget, sf); this->GroupMap[key] = pbxgroup; } + + // Put OBJECT_LIBRARY objects in proper groups: + std::vector objs; + this->GetGeneratorTarget(&cmtarget)->UseObjectLibraries(objs); + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + std::string const& source = *oi; + cmSourceGroup& sourceGroup = + mf->FindSourceGroup(source.c_str(), sourceGroups); + cmXCodeObject* pbxgroup = + this->CreateOrGetPBXGroup(cmtarget, &sourceGroup); + cmStdString key = GetGroupMapKeyFromPath(cmtarget, source); + this->GroupMap[key] = pbxgroup; + } } } } @@ -2878,6 +3023,7 @@ void cmGlobalXCodeGenerator cmXCodeObject* buildConfigurations = this->CreateObject(cmXCodeObject::OBJECT_LIST); std::vector configs; + const char *defaultConfigName = "Debug"; if(this->XcodeVersion == 15) { cmXCodeObject* configDebug = @@ -2894,6 +3040,10 @@ void cmGlobalXCodeGenerator for(unsigned int i = 0; i < this->CurrentConfigurationTypes.size(); ++i) { const char* name = this->CurrentConfigurationTypes[i].c_str(); + if (0 == i) + { + defaultConfigName = name; + } cmXCodeObject* config = this->CreateObject(cmXCodeObject::XCBuildConfiguration); config->AddAttribute("name", this->CreateString(name)); @@ -2915,7 +3065,7 @@ void cmGlobalXCodeGenerator configlist->AddAttribute("defaultConfigurationIsVisible", this->CreateString("0")); configlist->AddAttribute("defaultConfigurationName", - this->CreateString("Debug")); + this->CreateString(defaultConfigName)); cmXCodeObject* buildSettings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); const char* osxArch = @@ -3047,6 +3197,26 @@ void cmGlobalXCodeGenerator this->RootObject->AddAttribute("targets", allTargets); } +//---------------------------------------------------------------------------- +std::string +cmGlobalXCodeGenerator::GetObjectsNormalDirectory( + const std::string &projName, + const std::string &configName, + const cmTarget *t) const +{ + std::string dir = + t->GetMakefile()->GetCurrentOutputDirectory(); + dir += "/"; + dir += projName; + dir += ".build/"; + dir += configName; + dir += "/"; + dir += t->GetName(); + dir += ".build/Objects-normal/"; + + return dir; +} + //---------------------------------------------------------------------------- void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( @@ -3116,6 +3286,8 @@ cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( cmTarget* t =target->GetTarget(); if(t->GetType() == cmTarget::EXECUTABLE || +// Nope - no post-build for OBJECT_LIRBRARY +// t->GetType() == cmTarget::OBJECT_LIBRARY || t->GetType() == cmTarget::STATIC_LIBRARY || t->GetType() == cmTarget::SHARED_LIBRARY || t->GetType() == cmTarget::MODULE_LIBRARY) @@ -3171,15 +3343,8 @@ cmGlobalXCodeGenerator::CreateXCodeDependHackTarget( // then remove those exectuables as well if(this->Architectures.size() > 1) { - std::string universal = - t->GetMakefile()->GetCurrentOutputDirectory(); - universal += "/"; - universal += this->CurrentProject; - universal += ".build/"; - universal += configName; - universal += "/"; - universal += t->GetName(); - universal += ".build/Objects-normal/"; + std::string universal = this->GetObjectsNormalDirectory( + this->CurrentProject, configName, t); for( std::vector::iterator arch = this->Architectures.begin(); arch != this->Architectures.end(); ++arch) @@ -3285,7 +3450,7 @@ cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout, } //---------------------------------------------------------------------------- -const char* cmGlobalXCodeGenerator::GetCMakeCFGInitDirectory() +const char* cmGlobalXCodeGenerator::GetCMakeCFGIntDir() const { return this->XcodeVersion >= 21 ? "$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)" : "."; @@ -3362,37 +3527,6 @@ std::string cmGlobalXCodeGenerator::XCodeEscapePath(const char* p) return ret; } -//---------------------------------------------------------------------------- -void cmGlobalXCodeGenerator:: -GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs) -{ - std::string dir = this->CurrentMakefile->GetCurrentOutputDirectory(); - dir += "/"; - dir += this->CurrentMakefile->GetProjectName(); - dir += ".build/"; - dir += this->GetCMakeCFGInitDirectory(); - dir += "/"; - dir += target->GetName(); - dir += ".build/Objects-normal/"; - std::string dirsave = dir; - if(this->Architectures.size()) - { - for(std::vector::iterator i = this->Architectures.begin(); - i != this->Architectures.end(); ++i) - { - dir += *i; - dirs.push_back(dir); - dir = dirsave; - } - } - else - { - dirs.push_back(dir); - } -} - //---------------------------------------------------------------------------- void cmGlobalXCodeGenerator @@ -3569,3 +3703,51 @@ bool cmGlobalXCodeGenerator::IsMultiConfig() // Newer Xcode versions are multi config: return true; } + + //---------------------------------------------------------------------------- +void +cmGlobalXCodeGenerator +::ComputeTargetObjects(cmGeneratorTarget* gt) const +{ + // Count the number of object files with each name. Warn about duplicate + // names since Xcode names them uniquely automatically with a numeric suffix + // to avoid exact duplicate file names. Note that Mac file names are not + // typically case sensitive, hence the LowerCase. + std::map counts; + for(std::vector::const_iterator + si = gt->ObjectSources.begin(); + si != gt->ObjectSources.end(); ++si) + { + cmSourceFile* sf = *si; + std::string objectName = + cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath()); + objectName += ".o"; + + std::string objectNameLower = cmSystemTools::LowerCase(objectName); + counts[objectNameLower] += 1; + if (2 == counts[objectNameLower]) + { + // TODO: emit warning about duplicate name? + } + + gt->Objects[sf] = objectName; + } + + const char* configName = this->GetCMakeCFGIntDir(); + std::string dir = this->GetObjectsNormalDirectory( + this->CurrentProject, configName, gt->Target); + if(this->XcodeVersion >= 21) + { + dir += "$(CURRENT_ARCH)/"; + } + else + { +#ifdef __ppc__ + dir += "ppc/"; +#endif +#ifdef __i386 + dir += "i386/"; +#endif + } + gt->ObjectDirectory = dir; +} diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index ed54be3b9..800963b9c 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -74,11 +74,8 @@ public: std::string& dir); ///! What is the configurations directory variable called? - virtual const char* GetCMakeCFGInitDirectory(); + virtual const char* GetCMakeCFGIntDir() const; - void GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs); void SetCurrentLocalGenerator(cmLocalGenerator*); /** Return true if the generated build tree may contain multiple builds. @@ -156,6 +153,12 @@ private: std::vector& generators); void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root, std::vector& generators); + cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang); + cmXCodeObject* CreateXCodeSourceFileFromPath(const std::string &fullpath, + cmTarget& cmtarget, + const std::string &lang); cmXCodeObject* CreateXCodeFileReference(cmSourceFile* sf, cmTarget& cmtarget); cmXCodeObject* CreateXCodeSourceFile(cmLocalGenerator* gen, @@ -203,6 +206,13 @@ protected: std::vector XCodeObjects; cmXCodeObject* RootObject; private: + void ComputeTargetObjects(cmGeneratorTarget* gt) const; + + std::string GetObjectsNormalDirectory( + const std::string &projName, + const std::string &configName, + const cmTarget *t) const; + void addObject(cmXCodeObject *obj); std::string PostBuildMakeTarget(std::string const& tName, std::string const& configName); diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 22ba28f93..4eed47728 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -910,6 +910,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, if (newArgs.size() != 1) { errorString = "Unknown arguments specified"; + status = cmake::FATAL_ERROR; return false; } diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index 4996bc400..83ea8a474 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -15,11 +15,6 @@ #include "cmCommand.h" #include "cmFunctionBlocker.h" -/** \class cmIfFunctionBlocker - * \brief subclass of function blocker - * - * - */ class cmIfFunctionBlocker : public cmFunctionBlocker { public: @@ -39,11 +34,7 @@ public: unsigned int ScopeDepth; }; -/** \class cmIfCommand - * \brief starts an if block - * - * cmIfCommand starts an if block - */ +/// Starts an if block class cmIfCommand : public cmCommand { public: @@ -72,12 +63,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "if";} + virtual const char* GetName() const { return "if";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Conditionally execute a group of commands."; } @@ -85,12 +76,12 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " if(expression)\n" diff --git a/Source/cmIncludeCommand.h b/Source/cmIncludeCommand.h index d933ef3f6..c46c02d71 100644 --- a/Source/cmIncludeCommand.h +++ b/Source/cmIncludeCommand.h @@ -43,17 +43,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "include";} + virtual const char* GetName() const {return "include";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Read CMake listfile code from the given file."; } @@ -61,7 +61,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " include( [OPTIONAL] [RESULT_VARIABLE ]\n" diff --git a/Source/cmIncludeDirectoryCommand.h b/Source/cmIncludeDirectoryCommand.h index 3b35d55de..dcc116aa8 100644 --- a/Source/cmIncludeDirectoryCommand.h +++ b/Source/cmIncludeDirectoryCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "include_directories";} + virtual const char* GetName() const { return "include_directories";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Add include directories to the build."; } @@ -54,17 +54,25 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)\n" - "Add the given directories to those searched by the compiler for " - "include files. By default the directories are appended onto " - "the current list of directories. This default behavior can be " - "changed by setting CMAKE_INCLUDE_DIRECTORIES_BEFORE to ON. " - "By using BEFORE or AFTER you can select between appending and " - "prepending, independent from the default. " - "If the SYSTEM option is given the compiler will be told that the " + "Add the given directories to those the compiler uses to search " + "for include files. " + "These directories are added to the directory property " + "INCLUDE_DIRECTORIES for the current CMakeLists file. " + "They are also added to the target property INCLUDE_DIRECTORIES " + "for each target in the current CMakeLists file. " + "The target property values are the ones used by the generators." + "\n" + "By default the directories are appended onto the current list of " + "directories. " + "This default behavior can be changed by setting " + "CMAKE_INCLUDE_DIRECTORIES_BEFORE to ON. " + "By using AFTER or BEFORE explicitly, you can select between " + "appending and prepending, independent of the default. " + "If the SYSTEM option is given, the compiler will be told the " "directories are meant as system include directories on some " "platforms."; } diff --git a/Source/cmIncludeExternalMSProjectCommand.h b/Source/cmIncludeExternalMSProjectCommand.h index 52690410a..911a7722f 100644 --- a/Source/cmIncludeExternalMSProjectCommand.h +++ b/Source/cmIncludeExternalMSProjectCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "include_external_msproject";} + virtual const char* GetName() const {return "include_external_msproject";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Include an external Microsoft project file in a workspace."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " include_external_msproject(projectname location\n" diff --git a/Source/cmIncludeRegularExpressionCommand.h b/Source/cmIncludeRegularExpressionCommand.h index 6ddbbedd7..7c633c0a3 100644 --- a/Source/cmIncludeRegularExpressionCommand.h +++ b/Source/cmIncludeRegularExpressionCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "include_regular_expression";} + virtual const char* GetName() const {return "include_regular_expression";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set the regular expression used for dependency checking."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " include_regular_expression(regex_match [regex_complain])\n" diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 14deb24d4..c65648737 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -350,33 +350,42 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) targetIt!=targetList.GetVector().end(); ++targetIt) { - // Lookup this target in the current directory. - if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str())) + // Lookup this target in the current directory. + if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str())) + { + // Found the target. Check its type. + if(target->GetType() != cmTarget::EXECUTABLE && + target->GetType() != cmTarget::STATIC_LIBRARY && + target->GetType() != cmTarget::SHARED_LIBRARY && + target->GetType() != cmTarget::MODULE_LIBRARY && + target->GetType() != cmTarget::OBJECT_LIBRARY) { - // Found the target. Check its type. - if(target->GetType() != cmTarget::EXECUTABLE && - target->GetType() != cmTarget::STATIC_LIBRARY && - target->GetType() != cmTarget::SHARED_LIBRARY && - target->GetType() != cmTarget::MODULE_LIBRARY) - { - cmOStringStream e; - e << "TARGETS given target \"" << (*targetIt) - << "\" which is not an executable, library, or module."; - this->SetError(e.str().c_str()); - return false; - } - // Store the target in the list to be installed. - targets.push_back(target); + cmOStringStream e; + e << "TARGETS given target \"" << (*targetIt) + << "\" which is not an executable, library, or module."; + this->SetError(e.str().c_str()); + return false; } - else + else if(target->GetType() == cmTarget::OBJECT_LIBRARY) { - // Did not find the target. cmOStringStream e; - e << "TARGETS given target \"" << (*targetIt) - << "\" which does not exist in this directory."; + e << "TARGETS given OBJECT library \"" << (*targetIt) + << "\" which may not be installed."; this->SetError(e.str().c_str()); return false; } + // Store the target in the list to be installed. + targets.push_back(target); + } + else + { + // Did not find the target. + cmOStringStream e; + e << "TARGETS given target \"" << (*targetIt) + << "\" which does not exist in this directory."; + this->SetError(e.str().c_str()); + return false; + } } // Keep track of whether we will be performing an installation of @@ -602,98 +611,98 @@ bool cmInstallCommand::HandleTargetsMode(std::vector const& args) break; } - // These well-known sets of files are installed *automatically* for FRAMEWORK - // SHARED library targets on the Mac as part of installing the FRAMEWORK. - // For other target types or on other platforms, they are not installed - // automatically and so we need to create install files generators for them. - // - bool createInstallGeneratorsForTargetFileSets = true; + // These well-known sets of files are installed *automatically* for + // FRAMEWORK SHARED library targets on the Mac as part of installing the + // FRAMEWORK. For other target types or on other platforms, they are not + // installed automatically and so we need to create install files + // generators for them. + bool createInstallGeneratorsForTargetFileSets = true; - if(target.IsFrameworkOnApple()) - { - createInstallGeneratorsForTargetFileSets = false; - } - - if(createInstallGeneratorsForTargetFileSets && !namelinkOnly) - { - const char* files = target.GetProperty("PRIVATE_HEADER"); - if ((files) && (*files)) + if(target.IsFrameworkOnApple()) { - std::vector relFiles; - cmSystemTools::ExpandListArgument(files, relFiles); - std::vector absFiles; - if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) - { - return false; - } - - // Create the files install generator. - if (!privateHeaderArgs.GetDestination().empty()) - { - privateHeaderGenerator = CreateInstallFilesGenerator(absFiles, - privateHeaderArgs, false); - } - else - { - cmOStringStream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " - << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION."; - cmSystemTools::Message(e.str().c_str(), "Warning"); - } + createInstallGeneratorsForTargetFileSets = false; } - files = target.GetProperty("PUBLIC_HEADER"); - if ((files) && (*files)) + if(createInstallGeneratorsForTargetFileSets && !namelinkOnly) { - std::vector relFiles; - cmSystemTools::ExpandListArgument(files, relFiles); - std::vector absFiles; - if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) + const char* files = target.GetProperty("PRIVATE_HEADER"); + if ((files) && (*files)) { - return false; - } + std::vector relFiles; + cmSystemTools::ExpandListArgument(files, relFiles); + std::vector absFiles; + if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles)) + { + return false; + } - // Create the files install generator. - if (!publicHeaderArgs.GetDestination().empty()) - { - publicHeaderGenerator = CreateInstallFilesGenerator(absFiles, - publicHeaderArgs, false); - } - else - { - cmOStringStream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " - << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION."; - cmSystemTools::Message(e.str().c_str(), "Warning"); + // Create the files install generator. + if (!privateHeaderArgs.GetDestination().empty()) + { + privateHeaderGenerator = + CreateInstallFilesGenerator(absFiles, privateHeaderArgs, false); + } + else + { + cmOStringStream e; + e << "INSTALL TARGETS - target " << target.GetName() << " has " + << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION."; + cmSystemTools::Message(e.str().c_str(), "Warning"); + } } - } - files = target.GetProperty("RESOURCE"); - if ((files) && (*files)) - { - std::vector relFiles; - cmSystemTools::ExpandListArgument(files, relFiles); - std::vector absFiles; - if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles)) + files = target.GetProperty("PUBLIC_HEADER"); + if ((files) && (*files)) { - return false; - } + std::vector relFiles; + cmSystemTools::ExpandListArgument(files, relFiles); + std::vector absFiles; + if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles)) + { + return false; + } - // Create the files install generator. - if (!resourceArgs.GetDestination().empty()) - { - resourceGenerator = CreateInstallFilesGenerator(absFiles, - resourceArgs, false); + // Create the files install generator. + if (!publicHeaderArgs.GetDestination().empty()) + { + publicHeaderGenerator = + CreateInstallFilesGenerator(absFiles, publicHeaderArgs, false); + } + else + { + cmOStringStream e; + e << "INSTALL TARGETS - target " << target.GetName() << " has " + << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION."; + cmSystemTools::Message(e.str().c_str(), "Warning"); + } } - else + + files = target.GetProperty("RESOURCE"); + if ((files) && (*files)) { - cmOStringStream e; - e << "INSTALL TARGETS - target " << target.GetName() << " has " - << "RESOURCE files but no RESOURCE DESTINATION."; - cmSystemTools::Message(e.str().c_str(), "Warning"); + std::vector relFiles; + cmSystemTools::ExpandListArgument(files, relFiles); + std::vector absFiles; + if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles)) + { + return false; + } + + // Create the files install generator. + if (!resourceArgs.GetDestination().empty()) + { + resourceGenerator = CreateInstallFilesGenerator(absFiles, + resourceArgs, false); + } + else + { + cmOStringStream e; + e << "INSTALL TARGETS - target " << target.GetName() << " has " + << "RESOURCE files but no RESOURCE DESTINATION."; + cmSystemTools::Message(e.str().c_str(), "Warning"); + } } } - } // Keep track of whether we're installing anything in each category installsArchive = installsArchive || archiveGenerator != 0; diff --git a/Source/cmInstallCommand.h b/Source/cmInstallCommand.h index 8f6232272..3403c386f 100644 --- a/Source/cmInstallCommand.h +++ b/Source/cmInstallCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "install";} + virtual const char* GetName() const { return "install";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Specify rules to run at install time."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command generates installation rules for a project. " @@ -168,9 +168,7 @@ public: "On non-DLL platforms mySharedLib will be installed to /lib " "and /some/full/path. On DLL platforms the mySharedLib DLL will be " "installed to /bin and /some/full/path and its import library " - "will be installed to /lib/static and /some/full/path. " - "On non-DLL platforms mySharedLib will be installed to /lib " - "and /some/full/path." + "will be installed to /lib/static and /some/full/path." "\n" "The EXPORT option associates the installed target files with an " "export called . " diff --git a/Source/cmInstallDirectoryGenerator.cxx b/Source/cmInstallDirectoryGenerator.cxx index ab32f9488..ddf7d08cc 100644 --- a/Source/cmInstallDirectoryGenerator.cxx +++ b/Source/cmInstallDirectoryGenerator.cxx @@ -42,7 +42,7 @@ cmInstallDirectoryGenerator::GenerateScriptActions(std::ostream& os, { // Write code to install the directories. const char* no_rename = 0; - this->AddInstallRule(os, cmTarget::INSTALL_DIRECTORY, + this->AddInstallRule(os, cmInstallType_DIRECTORY, this->Directories, this->Optional, this->FilePermissions.c_str(), diff --git a/Source/cmInstallExportGenerator.cxx b/Source/cmInstallExportGenerator.cxx index 69e3f2c8e..28a19d740 100644 --- a/Source/cmInstallExportGenerator.cxx +++ b/Source/cmInstallExportGenerator.cxx @@ -16,7 +16,6 @@ #include "cmake.h" #include "cmInstallTargetGenerator.h" #include "cmGeneratedFileStream.h" -#include "cmTarget.h" #include "cmMakefile.h" #include "cmLocalGenerator.h" #include "cmGlobalGenerator.h" @@ -186,7 +185,7 @@ cmInstallExportGenerator::GenerateScriptConfigs(std::ostream& os, files.push_back(i->second); std::string config_test = this->CreateConfigTest(i->first.c_str()); os << indent << "IF(" << config_test << ")\n"; - this->AddInstallRule(os, cmTarget::INSTALL_FILES, files, false, + this->AddInstallRule(os, cmInstallType_FILES, files, false, this->FilePermissions.c_str(), 0, 0, 0, indent.Next()); os << indent << "ENDIF(" << config_test << ")\n"; @@ -225,6 +224,6 @@ void cmInstallExportGenerator::GenerateScriptActions(std::ostream& os, // Install the main export file. std::vector files; files.push_back(this->MainImportFile); - this->AddInstallRule(os, cmTarget::INSTALL_FILES, files, false, + this->AddInstallRule(os, cmInstallType_FILES, files, false, this->FilePermissions.c_str(), 0, 0, 0, indent); } diff --git a/Source/cmInstallFilesCommand.h b/Source/cmInstallFilesCommand.h index da439200f..d3c7ed67f 100644 --- a/Source/cmInstallFilesCommand.h +++ b/Source/cmInstallFilesCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "install_files";} + virtual const char* GetName() const { return "install_files";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the install(FILES ) command instead."; } @@ -63,7 +63,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command has been superceded by the install command. It " @@ -92,7 +92,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmInstallFilesGenerator.cxx b/Source/cmInstallFilesGenerator.cxx index 28f055fc9..ec02bc76a 100644 --- a/Source/cmInstallFilesGenerator.cxx +++ b/Source/cmInstallFilesGenerator.cxx @@ -11,8 +11,6 @@ ============================================================================*/ #include "cmInstallFilesGenerator.h" -#include "cmTarget.h" - //---------------------------------------------------------------------------- cmInstallFilesGenerator ::cmInstallFilesGenerator(std::vector const& files, @@ -43,8 +41,8 @@ void cmInstallFilesGenerator::GenerateScriptActions(std::ostream& os, const char* no_dir_permissions = 0; this->AddInstallRule(os, (this->Programs - ? cmTarget::INSTALL_PROGRAMS - : cmTarget::INSTALL_FILES), + ? cmInstallType_PROGRAMS + : cmInstallType_FILES), this->Files, this->Optional, this->FilePermissions.c_str(), no_dir_permissions, diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx index d7505dc9f..807168e0d 100644 --- a/Source/cmInstallGenerator.cxx +++ b/Source/cmInstallGenerator.cxx @@ -12,7 +12,6 @@ #include "cmInstallGenerator.h" #include "cmSystemTools.h" -#include "cmTarget.h" //---------------------------------------------------------------------------- cmInstallGenerator @@ -35,7 +34,7 @@ cmInstallGenerator void cmInstallGenerator ::AddInstallRule( std::ostream& os, - int type, + cmInstallType type, std::vector const& files, bool optional /* = false */, const char* permissions_file /* = 0 */, @@ -49,14 +48,13 @@ void cmInstallGenerator std::string stype; switch(type) { - case cmTarget::INSTALL_DIRECTORY:stype = "DIRECTORY"; break; - case cmTarget::INSTALL_PROGRAMS: stype = "PROGRAM"; break; - case cmTarget::EXECUTABLE: stype = "EXECUTABLE"; break; - case cmTarget::STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break; - case cmTarget::SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break; - case cmTarget::MODULE_LIBRARY: stype = "MODULE"; break; - case cmTarget::INSTALL_FILES: - default: stype = "FILE"; break; + case cmInstallType_DIRECTORY: stype = "DIRECTORY"; break; + case cmInstallType_PROGRAMS: stype = "PROGRAM"; break; + case cmInstallType_EXECUTABLE: stype = "EXECUTABLE"; break; + case cmInstallType_STATIC_LIBRARY: stype = "STATIC_LIBRARY"; break; + case cmInstallType_SHARED_LIBRARY: stype = "SHARED_LIBRARY"; break; + case cmInstallType_MODULE_LIBRARY: stype = "MODULE"; break; + case cmInstallType_FILES: stype = "FILE"; break; } os << indent; std::string dest = this->GetInstallDestination(); diff --git a/Source/cmInstallGenerator.h b/Source/cmInstallGenerator.h index aa9a47c09..c89ab8ac5 100644 --- a/Source/cmInstallGenerator.h +++ b/Source/cmInstallGenerator.h @@ -12,6 +12,7 @@ #ifndef cmInstallGenerator_h #define cmInstallGenerator_h +#include "cmInstallType.h" #include "cmScriptGenerator.h" class cmLocalGenerator; @@ -29,7 +30,7 @@ public: virtual ~cmInstallGenerator(); void AddInstallRule( - std::ostream& os, int type, + std::ostream& os, cmInstallType type, std::vector const& files, bool optional = false, const char* permissions_file = 0, diff --git a/Source/cmInstallProgramsCommand.h b/Source/cmInstallProgramsCommand.h index 1d0d25e5b..29c84a09f 100644 --- a/Source/cmInstallProgramsCommand.h +++ b/Source/cmInstallProgramsCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "install_programs";} + virtual const char* GetName() const { return "install_programs";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the install(PROGRAMS ) command instead."; } @@ -64,7 +64,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command has been superceded by the install command. It " @@ -89,7 +89,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index ac1c94944..5f9b6585e 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -82,8 +82,23 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, std::vector filesFrom; std::vector filesTo; std::string literal_args; - cmTarget::TargetType type = this->Target->GetType(); - if(type == cmTarget::EXECUTABLE) + cmTarget::TargetType targetType = this->Target->GetType(); + cmInstallType type = cmInstallType(); + switch(targetType) + { + case cmTarget::EXECUTABLE: type = cmInstallType_EXECUTABLE; break; + case cmTarget::STATIC_LIBRARY: type = cmInstallType_STATIC_LIBRARY; break; + case cmTarget::SHARED_LIBRARY: type = cmInstallType_SHARED_LIBRARY; break; + case cmTarget::MODULE_LIBRARY: type = cmInstallType_MODULE_LIBRARY; break; + case cmTarget::OBJECT_LIBRARY: + case cmTarget::UTILITY: + case cmTarget::GLOBAL_TARGET: + case cmTarget::UNKNOWN_LIBRARY: + this->Target->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, + "cmInstallTargetGenerator created with non-installable target."); + return; + } + if(targetType == cmTarget::EXECUTABLE) { // There is a bug in cmInstallCommand if this fails. assert(this->NamelinkMode == NamelinkModeNone); @@ -110,7 +125,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, } // An import library looks like a static library. - type = cmTarget::STATIC_LIBRARY; + type = cmInstallType_STATIC_LIBRARY; } else { @@ -121,7 +136,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, if(this->Target->IsAppBundleOnApple()) { // Install the whole app bundle directory. - type = cmTarget::INSTALL_DIRECTORY; + type = cmInstallType_DIRECTORY; literal_args += " USE_SOURCE_PERMISSIONS"; from1 += ".app"; @@ -173,7 +188,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, } // An import library looks like a static library. - type = cmTarget::STATIC_LIBRARY; + type = cmInstallType_STATIC_LIBRARY; } else if(this->Target->IsFrameworkOnApple()) { @@ -181,7 +196,7 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(std::ostream& os, assert(this->NamelinkMode == NamelinkModeNone); // Install the whole framework directory. - type = cmTarget::INSTALL_DIRECTORY; + type = cmInstallType_DIRECTORY; literal_args += " USE_SOURCE_PERMISSIONS"; std::string from1 = fromDirConfig + targetName + ".framework"; diff --git a/Source/cmInstallTargetsCommand.h b/Source/cmInstallTargetsCommand.h index 32641f830..e05462faa 100644 --- a/Source/cmInstallTargetsCommand.h +++ b/Source/cmInstallTargetsCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "install_targets";} + virtual const char* GetName() const { return "install_targets";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the install(TARGETS ) command instead."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command has been superceded by the install command. It " @@ -69,7 +69,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmInstallType.h b/Source/cmInstallType.h new file mode 100644 index 000000000..a8373682c --- /dev/null +++ b/Source/cmInstallType.h @@ -0,0 +1,29 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmInstallType_h +#define cmInstallType_h + +/** + * Enumerate types known to file(INSTALL). + */ +enum cmInstallType +{ + cmInstallType_EXECUTABLE, + cmInstallType_STATIC_LIBRARY, + cmInstallType_SHARED_LIBRARY, + cmInstallType_MODULE_LIBRARY, + cmInstallType_FILES, + cmInstallType_PROGRAMS, + cmInstallType_DIRECTORY +}; + +#endif diff --git a/Source/cmLinkDirectoriesCommand.h b/Source/cmLinkDirectoriesCommand.h index aa13589a3..a7cd58340 100644 --- a/Source/cmLinkDirectoriesCommand.h +++ b/Source/cmLinkDirectoriesCommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "link_directories";} + virtual const char* GetName() const { return "link_directories";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Specify directories in which the linker will look for libraries."; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " link_directories(directory1 directory2 ...)\n" diff --git a/Source/cmLinkLibrariesCommand.h b/Source/cmLinkLibrariesCommand.h index e43512663..2c0212cef 100644 --- a/Source/cmLinkLibrariesCommand.h +++ b/Source/cmLinkLibrariesCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "link_libraries";} + virtual const char* GetName() const { return "link_libraries";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the target_link_libraries() command instead."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "Link libraries to all targets added later.\n" @@ -70,7 +70,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmListCommand.h b/Source/cmListCommand.h index d2152957f..f20aa8a8f 100644 --- a/Source/cmListCommand.h +++ b/Source/cmListCommand.h @@ -39,17 +39,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "list";} + virtual const char* GetName() const { return "list";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "List operations."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " list(LENGTH )\n" diff --git a/Source/cmLoadCacheCommand.h b/Source/cmLoadCacheCommand.h index 8ecee4ae1..ac50f8d39 100644 --- a/Source/cmLoadCacheCommand.h +++ b/Source/cmLoadCacheCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "load_cache";} + virtual const char* GetName() const { return "load_cache";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Load in the values from another project's CMake cache."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " load_cache(pathToCacheFile READ_WITH_PREFIX\n" diff --git a/Source/cmLoadCommandCommand.cxx b/Source/cmLoadCommandCommand.cxx index 98de41179..3a0115c96 100644 --- a/Source/cmLoadCommandCommand.cxx +++ b/Source/cmLoadCommandCommand.cxx @@ -69,12 +69,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return info.Name; } + virtual const char* GetName() const { return info.Name; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { if (this->info.GetTerseDocumentation) { @@ -123,7 +123,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { if (this->info.GetFullDocumentation) { diff --git a/Source/cmLoadCommandCommand.h b/Source/cmLoadCommandCommand.h index db18428da..651701948 100644 --- a/Source/cmLoadCommandCommand.h +++ b/Source/cmLoadCommandCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "load_command";} + virtual const char* GetName() const {return "load_command";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Load a command into a running CMake."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " load_command(COMMAND_NAME [loc2 ...])\n" diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ffbeb4856..13ede5d70 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -556,7 +556,7 @@ void cmLocalGenerator::GenerateTargetManifest() void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname, const char* lang, cmSourceFile& source, - cmTarget& ) + cmTarget& target) { std::string objectDir = cmSystemTools::GetFilenamePath(std::string(ofname)); objectDir = this->Convert(objectDir.c_str(),START_OUTPUT,SHELL); @@ -574,7 +574,11 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname, std::string flags; flags += this->Makefile->GetSafeDefinition(varString.c_str()); flags += " "; - flags += this->GetIncludeFlags(lang); + { + std::vector includes; + this->GetIncludeDirectories(includes, &target, lang); + flags += this->GetIncludeFlags(includes, lang); + } flags += this->Makefile->GetDefineFlags(); // Construct the command lines. @@ -1192,24 +1196,16 @@ cmLocalGenerator::ConvertToIncludeReference(std::string const& path) } //---------------------------------------------------------------------------- -const char* cmLocalGenerator::GetIncludeFlags(const char* lang, - bool forResponseFile) +std::string cmLocalGenerator::GetIncludeFlags( + const std::vector &includes, + const char* lang, bool forResponseFile) { if(!lang) { return ""; } - std::string key = lang; - key += forResponseFile? "@" : ""; - if(this->LanguageToIncludeFlags.count(key)) - { - return this->LanguageToIncludeFlags[key].c_str(); - } cmOStringStream includeFlags; - std::vector includes; - this->GetIncludeDirectories(includes, lang); - std::vector::iterator i; std::string flagVar = "CMAKE_INCLUDE_FLAG_"; flagVar += lang; @@ -1251,6 +1247,7 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang, #ifdef __APPLE__ emitted.insert("/System/Library/Frameworks"); #endif + std::vector::const_iterator i; for(i = includes.begin(); i != includes.end(); ++i) { if(this->Makefile->IsOn("APPLE") @@ -1311,16 +1308,12 @@ const char* cmLocalGenerator::GetIncludeFlags(const char* lang, { flags[flags.size()-1] = ' '; } - this->LanguageToIncludeFlags[key] = flags; - - // Use this temorary variable for the return value to work-around a - // bogus GCC 2.95 warning. - const char* ret = this->LanguageToIncludeFlags[key].c_str(); - return ret; + return flags; } //---------------------------------------------------------------------------- void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, + cmTarget* target, const char* lang) { // Need to decide whether to automatically include the source and @@ -1375,8 +1368,12 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, // Store the automatic include paths. if(includeBinaryDir) { - dirs.push_back(this->Makefile->GetStartOutputDirectory()); - emitted.insert(this->Makefile->GetStartOutputDirectory()); + if(emitted.find( + this->Makefile->GetStartOutputDirectory()) == emitted.end()) + { + dirs.push_back(this->Makefile->GetStartOutputDirectory()); + emitted.insert(this->Makefile->GetStartOutputDirectory()); + } } if(includeSourceDir) { @@ -1402,9 +1399,12 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } } - // Get the project-specified include directories. - std::vector& includes = - this->Makefile->GetIncludeDirectories(); + // Get the target-specific include directories. + std::vector includes; + if(target) + { + includes = target->GetIncludeDirectories(); + } // Support putting all the in-project include directories first if // it is requested by the project. @@ -1412,7 +1412,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, { const char* topSourceDir = this->Makefile->GetHomeDirectory(); const char* topBinaryDir = this->Makefile->GetHomeOutputDirectory(); - for(std::vector::iterator i = includes.begin(); + for(std::vector::const_iterator i = includes.begin(); i != includes.end(); ++i) { // Emit this directory only if it is a subdirectory of the @@ -1431,7 +1431,7 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector& dirs, } // Construct the final ordered include directory list. - for(std::vector::iterator i = includes.begin(); + for(std::vector::const_iterator i = includes.begin(); i != includes.end(); ++i) { if(emitted.insert(*i).second) @@ -1503,7 +1503,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, linkFlags += this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); linkFlags += this->Convert(sf->GetFullPath().c_str(), - START_OUTPUT, SHELL); + FULL, SHELL); linkFlags += " "; } } @@ -1583,6 +1583,16 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); linkFlags += " "; } + if (target.IsExecutableWithExports()) + { + std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; + exportFlagVar += linkLanguage; + exportFlagVar += "_FLAG"; + + linkFlags += + this->Makefile->GetSafeDefinition(exportFlagVar.c_str()); + linkFlags += " "; + } const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"); if(targetLinkFlags) { @@ -1902,24 +1912,17 @@ bool cmLocalGenerator::GetRealDependency(const char* inName, case cmTarget::SHARED_LIBRARY: case cmTarget::MODULE_LIBRARY: case cmTarget::UNKNOWN_LIBRARY: - { - // Get the location of the target's output file and depend on it. - if(const char* location = target->GetLocation(config)) - { - dep = location; - return true; - } - } - break; + dep = target->GetLocation(config); + return true; + case cmTarget::OBJECT_LIBRARY: + // An object library has no single file on which to depend. + // This was listed to get the target-level dependency. + return false; case cmTarget::UTILITY: case cmTarget::GLOBAL_TARGET: // A utility target has no file on which to depend. This was listed // only to get the target-level dependency. return false; - case cmTarget::INSTALL_FILES: - case cmTarget::INSTALL_PROGRAMS: - case cmTarget::INSTALL_DIRECTORY: - break; } } @@ -2974,17 +2977,6 @@ cmLocalGenerator::GetTargetDirectory(cmTarget const&) const return ""; } - -//---------------------------------------------------------------------------- -void -cmLocalGenerator::GetTargetObjectFileDirectories(cmTarget* , - std::vector& - ) -{ - cmSystemTools::Error("GetTargetObjectFileDirectories" - " called on cmLocalGenerator"); -} - //---------------------------------------------------------------------------- unsigned int cmLocalGenerator::GetBackwardsCompatibility() { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 0c5b9d074..3e938197a 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -146,8 +146,8 @@ public: ///! Append flags to a string. virtual void AppendFlags(std::string& flags, const char* newFlags); ///! Get the include flags for the current makefile and language - const char* GetIncludeFlags(const char* lang, - bool forResponseFile = false); + std::string GetIncludeFlags(const std::vector &includes, + const char* lang, bool forResponseFile = false); /** * Encode a list of preprocessor definitions for the compiler @@ -160,15 +160,18 @@ public: void AppendFeatureOptions(std::string& flags, const char* lang, const char* feature); - /** Translate a dependency as given in CMake code to the name to - appear in a generated build file. If the given name is that of - a utility target, returns false. If the given name is that of - a CMake target it will be transformed to the real output - location of that target for the given configuration. If the - given name is the full path to a file it will be returned. - Otherwise the name is treated as a relative path with respect to - the source directory of this generator. This should only be - used for dependencies of custom commands. */ + /** \brief Get absolute path to dependency \a name + * + * Translate a dependency as given in CMake code to the name to + * appear in a generated build file. + * - If \a name is a utility target, returns false. + * - If \a name is a CMake target, it will be transformed to the real output + * location of that target for the given configuration. + * - If \a name is the full path to a file, it will be returned. + * - Otherwise \a name is treated as a relative path with respect to + * the source directory of this generator. This should only be + * used for dependencies of custom commands. + */ bool GetRealDependency(const char* name, const char* config, std::string& dep); @@ -195,6 +198,7 @@ public: /** Get the include flags for the current makefile and language. */ void GetIncludeDirectories(std::vector& dirs, + cmTarget* target, const char* lang = "C"); /** Compute the language used to compile the given source file. */ @@ -247,7 +251,7 @@ public: std::string EscapeForShellOldStyle(const char* str); /** Escape the given string as an argument in a CMake script. */ - std::string EscapeForCMake(const char* str); + static std::string EscapeForCMake(const char* str); enum FortranFormat { @@ -257,14 +261,6 @@ public: }; FortranFormat GetFortranFormat(const char* value); - /** Return the directories into which object files will be put. - * There maybe more than one for fat binary systems like OSX. - */ - virtual void - GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs); - /** * Convert the given remote path to a relative path with respect to * the given local path. The local path must be given in component @@ -392,7 +388,6 @@ protected: std::vector StartOutputDirectoryComponents; cmLocalGenerator* Parent; std::vector Children; - std::map LanguageToIncludeFlags; std::map UniqueObjectNamesMap; std::string::size_type ObjectPathMax; std::set ObjectMaxPathViolations; diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx new file mode 100644 index 000000000..425b21917 --- /dev/null +++ b/Source/cmLocalNinjaGenerator.cxx @@ -0,0 +1,393 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmLocalNinjaGenerator.h" +#include "cmCustomCommandGenerator.h" +#include "cmMakefile.h" +#include "cmGlobalNinjaGenerator.h" +#include "cmNinjaTargetGenerator.h" +#include "cmGeneratedFileStream.h" +#include "cmSourceFile.h" +#include "cmComputeLinkInformation.h" +#include "cmake.h" + +#include + +cmLocalNinjaGenerator::cmLocalNinjaGenerator() + : cmLocalGenerator() + , ConfigName("") + , HomeRelativeOutputPath("") +{ + this->IsMakefileGenerator = true; +#ifdef _WIN32 + this->WindowsShell = true; +#endif + this->TargetImplib = "$TARGET_IMPLIB"; +} + +//---------------------------------------------------------------------------- +// Virtual public methods. + +cmLocalNinjaGenerator::~cmLocalNinjaGenerator() +{ +} + +void cmLocalNinjaGenerator::Generate() +{ + this->SetConfigName(); + + this->WriteProcessedMakefile(this->GetBuildFileStream()); + this->WriteProcessedMakefile(this->GetRulesFileStream()); + + this->WriteBuildFileTop(); + + cmTargets& targets = this->GetMakefile()->GetTargets(); + for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t) + { + cmNinjaTargetGenerator* tg = cmNinjaTargetGenerator::New(&t->second); + if(tg) + { + tg->Generate(); + // Add the target to "all" if required. + if (!this->GetGlobalNinjaGenerator()->IsExcluded( + this->GetGlobalNinjaGenerator()->LocalGenerators[0], + t->second)) + this->GetGlobalNinjaGenerator()->AddDependencyToAll(&t->second); + delete tg; + } + } + + this->WriteCustomCommandBuildStatements(); +} + +// Implemented in: +// cmLocalUnixMakefileGenerator3. +// Used in: +// Source/cmMakefile.cxx +// Source/cmGlobalGenerator.cxx +void cmLocalNinjaGenerator::Configure() +{ + // Compute the path to use when referencing the current output + // directory from the top output directory. + this->HomeRelativeOutputPath = + this->Convert(this->Makefile->GetStartOutputDirectory(), HOME_OUTPUT); + if(this->HomeRelativeOutputPath == ".") + { + this->HomeRelativeOutputPath = ""; + } + this->cmLocalGenerator::Configure(); + +} + +// TODO: Picked up from cmLocalUnixMakefileGenerator3. Refactor it. +std::string cmLocalNinjaGenerator +::GetTargetDirectory(cmTarget const& target) const +{ + std::string dir = cmake::GetCMakeFilesDirectoryPostSlash(); + dir += target.GetName(); +#if defined(__VMS) + dir += "_dir"; +#else + dir += ".dir"; +#endif + return dir; +} + +//---------------------------------------------------------------------------- +// Non-virtual public methods. + +const cmGlobalNinjaGenerator* +cmLocalNinjaGenerator::GetGlobalNinjaGenerator() const +{ + return + static_cast(this->GetGlobalGenerator()); +} + +cmGlobalNinjaGenerator* cmLocalNinjaGenerator::GetGlobalNinjaGenerator() +{ + return static_cast(this->GetGlobalGenerator()); +} + +//---------------------------------------------------------------------------- +// Virtual protected methods. + +std::string +cmLocalNinjaGenerator::ConvertToLinkReference(std::string const& lib) +{ + return this->Convert(lib.c_str(), HOME_OUTPUT, SHELL); +} + +std::string +cmLocalNinjaGenerator::ConvertToIncludeReference(std::string const& path) +{ + return this->Convert(path.c_str(), HOME_OUTPUT, SHELL); +} + +//---------------------------------------------------------------------------- +// Private methods. + +cmGeneratedFileStream& cmLocalNinjaGenerator::GetBuildFileStream() const +{ + return *this->GetGlobalNinjaGenerator()->GetBuildFileStream(); +} + +cmGeneratedFileStream& cmLocalNinjaGenerator::GetRulesFileStream() const +{ + return *this->GetGlobalNinjaGenerator()->GetRulesFileStream(); +} + +const cmake* cmLocalNinjaGenerator::GetCMakeInstance() const +{ + return this->GetGlobalGenerator()->GetCMakeInstance(); +} + +cmake* cmLocalNinjaGenerator::GetCMakeInstance() +{ + return this->GetGlobalGenerator()->GetCMakeInstance(); +} + +bool cmLocalNinjaGenerator::isRootMakefile() const +{ + return (strcmp(this->Makefile->GetCurrentDirectory(), + this->GetCMakeInstance()->GetHomeDirectory()) == 0); +} + +void cmLocalNinjaGenerator::WriteBuildFileTop() +{ + // We do that only once for the top CMakeLists.txt file. + if(!this->isRootMakefile()) + return; + + // For the build file. + this->WriteProjectHeader(this->GetBuildFileStream()); + this->WriteNinjaFilesInclusion(this->GetBuildFileStream()); + + // For the rule file. + this->WriteProjectHeader(this->GetRulesFileStream()); +} + +void cmLocalNinjaGenerator::WriteProjectHeader(std::ostream& os) +{ + cmGlobalNinjaGenerator::WriteDivider(os); + os + << "# Project: " << this->GetMakefile()->GetProjectName() << std::endl + << "# Configuration: " << this->ConfigName << std::endl + ; + cmGlobalNinjaGenerator::WriteDivider(os); +} + +void cmLocalNinjaGenerator::WriteNinjaFilesInclusion(std::ostream& os) +{ + cmGlobalNinjaGenerator::WriteDivider(os); + os + << "# Include auxiliary files.\n" + << "\n" + ; + cmGlobalNinjaGenerator::WriteInclude(os, + cmGlobalNinjaGenerator::NINJA_RULES_FILE, + "Include rules file."); + os << "\n"; +} + +void cmLocalNinjaGenerator::SetConfigName() +{ + // Store the configuration name that will be generated. + if(const char* config = + this->GetMakefile()->GetDefinition("CMAKE_BUILD_TYPE")) + { + // Use the build type given by the user. + this->ConfigName = config; + } + else + { + // No configuration type given. + this->ConfigName = ""; + } +} + +void cmLocalNinjaGenerator::WriteProcessedMakefile(std::ostream& os) +{ + cmGlobalNinjaGenerator::WriteDivider(os); + os + << "# Write statements declared in CMakeLists.txt:" << std::endl + << "# " << this->Makefile->GetCurrentListFile() << std::endl + ; + if(this->isRootMakefile()) + os << "# Which is the root file." << std::endl; + cmGlobalNinjaGenerator::WriteDivider(os); + os << std::endl; +} + +std::string cmLocalNinjaGenerator::ConvertToNinjaPath(const char *path) +{ + std::string convPath = this->Convert(path, cmLocalGenerator::HOME_OUTPUT); +#ifdef _WIN32 + cmSystemTools::ReplaceString(convPath, "/", "\\"); +#endif + return convPath; +} + +void +cmLocalNinjaGenerator +::AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs) +{ + this->GetGlobalNinjaGenerator()->AppendTargetOutputs(target, outputs); +} + +void +cmLocalNinjaGenerator +::AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs) +{ + this->GetGlobalNinjaGenerator()->AppendTargetDepends(target, outputs); +} + +void cmLocalNinjaGenerator::AppendCustomCommandDeps(const cmCustomCommand *cc, + cmNinjaDeps &ninjaDeps) +{ + const std::vector &deps = cc->GetDepends(); + for (std::vector::const_iterator i = deps.begin(); + i != deps.end(); ++i) { + std::string dep; + if (this->GetRealDependency(i->c_str(), this->GetConfigName(), dep)) + ninjaDeps.push_back(ConvertToNinjaPath(dep.c_str())); + } +} + +std::string cmLocalNinjaGenerator::BuildCommandLine( + const std::vector &cmdLines) +{ + // If we have no commands but we need to build a command anyway, use ":". + // This happens when building a POST_BUILD value for link targets that + // don't use POST_BUILD. + if (cmdLines.empty()) +#ifdef _WIN32 + return "cd."; +#else + return ":"; +#endif + + // TODO: This will work only on Unix platforms. I don't + // want to use a link.txt file because I will lose the benefit of the + // $in variables. A discussion about dealing with multiple commands in + // a rule is started here: + // groups.google.com/group/ninja-build/browse_thread/thread/d515f23a78986008 + std::ostringstream cmd; + for (std::vector::const_iterator li = cmdLines.begin(); + li != cmdLines.end(); ++li) { + if (li != cmdLines.begin()) + cmd << " && "; + cmd << *li; + } + return cmd.str(); +} + +void cmLocalNinjaGenerator::AppendCustomCommandLines(const cmCustomCommand *cc, + std::vector &cmdLines) +{ + cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile); + if (ccg.GetNumberOfCommands() > 0) { + const char* wd = cc->GetWorkingDirectory(); + if (!wd) + wd = this->GetMakefile()->GetStartOutputDirectory(); + + std::ostringstream cdCmd; + cdCmd << "cd " << this->ConvertToOutputFormat(wd, SHELL); + cmdLines.push_back(cdCmd.str()); + } + for (unsigned i = 0; i != ccg.GetNumberOfCommands(); ++i) { + cmdLines.push_back(this->ConvertToOutputFormat(ccg.GetCommand(i).c_str(), + SHELL)); + std::string& cmd = cmdLines.back(); + ccg.AppendArguments(i, cmd); + } +} + +void +cmLocalNinjaGenerator::WriteCustomCommandBuildStatement( + cmCustomCommand const *cc, const cmNinjaDeps& orderOnlyDeps) +{ + if (this->GetGlobalNinjaGenerator()->SeenCustomCommand(cc)) + return; + + const std::vector &outputs = cc->GetOutputs(); + cmNinjaDeps ninjaOutputs(outputs.size()), ninjaDeps; + + std::transform(outputs.begin(), outputs.end(), + ninjaOutputs.begin(), MapToNinjaPath()); + this->AppendCustomCommandDeps(cc, ninjaDeps); + + for (cmNinjaDeps::iterator i = ninjaOutputs.begin(); i != ninjaOutputs.end(); + ++i) + this->GetGlobalNinjaGenerator()->SeenCustomCommandOutput(*i); + + std::vector cmdLines; + this->AppendCustomCommandLines(cc, cmdLines); + + if (cmdLines.empty()) { + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "Phony custom command for " + + ninjaOutputs[0], + ninjaOutputs, + ninjaDeps, + cmNinjaDeps(), + orderOnlyDeps, + cmNinjaVars()); + } else { + this->GetGlobalNinjaGenerator()->WriteCustomCommandBuild( + this->BuildCommandLine(cmdLines), + this->ConstructComment(*cc), + "Custom command for " + ninjaOutputs[0], + ninjaOutputs, + ninjaDeps, + orderOnlyDeps); + } +} + +void cmLocalNinjaGenerator::AddCustomCommandTarget(cmCustomCommand const* cc, + cmTarget* target) +{ + this->CustomCommandTargets[cc].insert(target); +} + +void cmLocalNinjaGenerator::WriteCustomCommandBuildStatements() +{ + for (CustomCommandTargetMap::iterator i = this->CustomCommandTargets.begin(); + i != this->CustomCommandTargets.end(); ++i) { + // A custom command may appear on multiple targets. However, some build + // systems exist where the target dependencies on some of the targets are + // overspecified, leading to a dependency cycle. If we assume all target + // dependencies are a superset of the true target dependencies for this + // custom command, we can take the set intersection of all target + // dependencies to obtain a correct dependency list. + // + // FIXME: This won't work in certain obscure scenarios involving indirect + // dependencies. + std::set::iterator j = i->second.begin(); + assert(j != i->second.end()); + std::vector ccTargetDeps; + this->AppendTargetDepends(*j, ccTargetDeps); + std::sort(ccTargetDeps.begin(), ccTargetDeps.end()); + ++j; + + for (; j != i->second.end(); ++j) { + std::vector jDeps, depsIntersection; + this->AppendTargetDepends(*j, jDeps); + std::sort(jDeps.begin(), jDeps.end()); + std::set_intersection(ccTargetDeps.begin(), ccTargetDeps.end(), + jDeps.begin(), jDeps.end(), + std::back_inserter(depsIntersection)); + ccTargetDeps = depsIntersection; + } + + this->WriteCustomCommandBuildStatement(i->first, ccTargetDeps); + } +} diff --git a/Source/cmLocalNinjaGenerator.h b/Source/cmLocalNinjaGenerator.h new file mode 100644 index 000000000..ea44b2fe2 --- /dev/null +++ b/Source/cmLocalNinjaGenerator.h @@ -0,0 +1,133 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmLocalNinjaGenerator_h +# define cmLocalNinjaGenerator_h + +# include "cmLocalGenerator.h" +# include "cmNinjaTypes.h" + +class cmGlobalNinjaGenerator; +class cmGeneratedFileStream; +class cmake; + +/** + * \class cmLocalNinjaGenerator + * \brief Write a local build.ninja file. + * + * cmLocalNinjaGenerator produces a local build.ninja file from its + * member Makefile. + */ +class cmLocalNinjaGenerator : public cmLocalGenerator +{ +public: + /// Default constructor. + cmLocalNinjaGenerator(); + + /// Destructor. + virtual ~cmLocalNinjaGenerator(); + + /// Overloaded methods. @see cmLocalGenerator::Generate() + virtual void Generate(); + + /// Overloaded methods. @see cmLocalGenerator::Configure() + virtual void Configure(); + + /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory() + virtual std::string GetTargetDirectory(cmTarget const& target) const; + +public: + const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const; + cmGlobalNinjaGenerator* GetGlobalNinjaGenerator(); + + /** + * Shortcut to get the cmake instance throw the global generator. + * @return an instance of the cmake object. + */ + const cmake* GetCMakeInstance() const; + cmake* GetCMakeInstance(); + + const char* GetConfigName() const + { return this->ConfigName.c_str(); } + + /// @return whether we are processing the top CMakeLists.txt file. + bool isRootMakefile() const; + + /// @returns the relative path between the HomeOutputDirectory and this + /// local generators StartOutputDirectory. + std::string GetHomeRelativeOutputPath() const + { return this->HomeRelativeOutputPath; } + +protected: + virtual std::string ConvertToLinkReference(std::string const& lib); + virtual std::string ConvertToIncludeReference(std::string const& path); + +private: + friend class cmGlobalNinjaGenerator; + + // In order to access to protected member of the local generator. + friend class cmNinjaTargetGenerator; + friend class cmNinjaNormalTargetGenerator; + friend class cmNinjaUtilityTargetGenerator; + +private: + cmGeneratedFileStream& GetBuildFileStream() const; + cmGeneratedFileStream& GetRulesFileStream() const; + + void WriteBuildFileTop(); + void WriteProjectHeader(std::ostream& os); + void WriteNinjaFilesInclusion(std::ostream& os); + void WriteProcessedMakefile(std::ostream& os); + + void SetConfigName(); + + std::string ConvertToNinjaPath(const char *path); + + struct map_to_ninja_path; + friend struct map_to_ninja_path; + struct map_to_ninja_path { + cmLocalNinjaGenerator *LocalGenerator; + map_to_ninja_path(cmLocalNinjaGenerator *LocalGen) + : LocalGenerator(LocalGen) {} + std::string operator()(const std::string &path) { + return LocalGenerator->ConvertToNinjaPath(path.c_str()); + } + }; + map_to_ninja_path MapToNinjaPath() { + return map_to_ninja_path(this); + } + + void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs); + void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs); + + void AppendCustomCommandDeps(const cmCustomCommand *cc, + cmNinjaDeps &ninjaDeps); + std::string BuildCommandLine(const std::vector &cmdLines); + void AppendCustomCommandLines(const cmCustomCommand *cc, + std::vector &cmdLines); + void WriteCustomCommandRule(); + void WriteCustomCommandBuildStatement(cmCustomCommand const *cc, + const cmNinjaDeps& orderOnlyDeps); + + void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target); + void WriteCustomCommandBuildStatements(); + +private: + std::string ConfigName; + std::string HomeRelativeOutputPath; + + typedef std::map > + CustomCommandTargetMap; + CustomCommandTargetMap CustomCommandTargets; +}; + +#endif // ! cmLocalNinjaGenerator_h diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 6be3eb92e..a645303af 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -144,6 +144,20 @@ void cmLocalUnixMakefileGenerator3::Generate() this->WriteDirectoryInformationFile(); } +//---------------------------------------------------------------------------- +void cmLocalUnixMakefileGenerator3::AddLocalObjectFile( + cmTarget* target, cmSourceFile* sf, std::string objNoTargetDir, + bool hasSourceExtension) +{ + if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str())) + { + objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir); + } + LocalObjectInfo& info = this->LocalObjectFiles[objNoTargetDir]; + info.HasSourceExtension = hasSourceExtension; + info.push_back(LocalObjectEntry(target, sf->GetLanguage())); +} + //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3::GetIndividualFileTargets (std::vector& targets) @@ -232,6 +246,7 @@ void cmLocalUnixMakefileGenerator3::WriteLocalMakefile() if(ei->Language == "C" || ei->Language == "CXX") { lang_is_c_or_cxx = true; + break; } } @@ -343,6 +358,7 @@ void cmLocalUnixMakefileGenerator3 (t->second.GetType() == cmTarget::STATIC_LIBRARY) || (t->second.GetType() == cmTarget::SHARED_LIBRARY) || (t->second.GetType() == cmTarget::MODULE_LIBRARY) || + (t->second.GetType() == cmTarget::OBJECT_LIBRARY) || (t->second.GetType() == cmTarget::UTILITY)) { emitted.insert(t->second.GetName()); @@ -451,28 +467,6 @@ void cmLocalUnixMakefileGenerator3::WriteDirectoryInformationFile() << "\n"; } - // Store the include search path for this directory. - infoFileStream - << "# The C and CXX include file search paths:\n"; - infoFileStream - << "SET(CMAKE_C_INCLUDE_PATH\n"; - std::vector includeDirs; - this->GetIncludeDirectories(includeDirs); - for(std::vector::iterator i = includeDirs.begin(); - i != includeDirs.end(); ++i) - { - infoFileStream - << " \"" << this->Convert(i->c_str(),HOME_OUTPUT).c_str() << "\"\n"; - } - infoFileStream - << " )\n"; - infoFileStream - << "SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n"; - infoFileStream - << "SET(CMAKE_Fortran_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n"; - infoFileStream - << "SET(CMAKE_ASM_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH})\n"; - // Store the include regular expressions for this directory. infoFileStream << "\n" @@ -561,6 +555,21 @@ cmLocalUnixMakefileGenerator3 space = " "; } + // Warn about paths not supported by Make tools. + std::string::size_type pos = tgt.find_first_of("="); + if(pos != std::string::npos) + { + cmOStringStream m; + m << + "Make rule for\n" + " " << tgt << "\n" + "has '=' on left hand side. " + "The make tool may not support this."; + cmListFileBacktrace bt; + this->GlobalGenerator->GetCMakeInstance() + ->IssueMessage(cmake::WARNING, m.str(), bt); + } + // Mark the rule as symbolic if requested. if(symbolic) { @@ -2000,45 +2009,6 @@ void cmLocalUnixMakefileGenerator3 } } -//---------------------------------------------------------------------------- -std::string -cmLocalUnixMakefileGenerator3 -::GetObjectFileName(cmTarget& target, - const cmSourceFile& source, - std::string* nameWithoutTargetDir, - bool* hasSourceExtension) -{ - // Make sure we never hit this old case. - if(source.GetProperty("MACOSX_PACKAGE_LOCATION")) - { - std::string msg = "MACOSX_PACKAGE_LOCATION set on source file: "; - msg += source.GetFullPath(); - this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, - msg.c_str()); - } - - // Start with the target directory. - std::string obj = this->GetTargetDirectory(target); - obj += "/"; - - // Get the object file name without the target directory. - std::string dir_max; - dir_max += this->Makefile->GetCurrentOutputDirectory(); - dir_max += "/"; - dir_max += obj; - std::string objectName = - this->GetObjectFileNameWithoutTarget(source, dir_max, - hasSourceExtension); - if(nameWithoutTargetDir) - { - *nameWithoutTargetDir = objectName; - } - - // Append the object name to the target directory. - obj += objectName; - return obj; -} - //---------------------------------------------------------------------------- void cmLocalUnixMakefileGenerator3::WriteDisclaimer(std::ostream& os) { @@ -2273,14 +2243,3 @@ void cmLocalUnixMakefileGenerator3 } } } - - -void cmLocalUnixMakefileGenerator3 -::GetTargetObjectFileDirectories(cmTarget* target, - std::vector& dirs) -{ - std::string dir = this->Makefile->GetCurrentOutputDirectory(); - dir += "/"; - dir += this->GetTargetDirectory(*target); - dirs.push_back(dir); -} diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 45ac21de3..e3749590b 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -225,24 +225,9 @@ public: // write the target rules for the local Makefile into the stream void WriteLocalAllRules(std::ostream& ruleFileStream); - struct LocalObjectEntry - { - cmTarget* Target; - std::string Language; - LocalObjectEntry(): Target(0), Language() {} - LocalObjectEntry(cmTarget* t, const char* lang): - Target(t), Language(lang) {} - }; - struct LocalObjectInfo: public std::vector - { - bool HasSourceExtension; - bool HasPreprocessRule; - bool HasAssembleRule; - LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false), - HasAssembleRule(false) {} - }; - std::map const& GetLocalObjectFiles() - { return this->LocalObjectFiles;} + void AddLocalObjectFile(cmTarget* target, cmSourceFile* sf, + std::string objNoTargetDir, + bool hasSourceExtension); std::vector const& GetLocalHelp() { return this->LocalHelp; } @@ -257,9 +242,6 @@ public: { return !this->SkipAssemblySourceRules; } - // Get the directories into which the .o files will go for this target - void GetTargetObjectFileDirectories(cmTarget* target, - std::vector& dirs); // Fill the vector with the target names for the object files, // preprocessed files and assembly files. Currently only used by the @@ -301,14 +283,6 @@ protected: void WriteTargetRequiresRule(std::ostream& ruleFileStream, cmTarget& target, const std::vector& objects); - void WriteObjectConvenienceRule(std::ostream& ruleFileStream, - const char* comment, const char* output, - LocalObjectInfo const& info); - - std::string GetObjectFileName(cmTarget& target, - const cmSourceFile& source, - std::string* nameWithoutTargetDir = 0, - bool* hasSourceExtension = 0); void AppendRuleDepend(std::vector& depends, const char* ruleFileName); @@ -378,7 +352,27 @@ private: bool SkipPreprocessedSourceRules; bool SkipAssemblySourceRules; + struct LocalObjectEntry + { + cmTarget* Target; + std::string Language; + LocalObjectEntry(): Target(0), Language() {} + LocalObjectEntry(cmTarget* t, const char* lang): + Target(t), Language(lang) {} + }; + struct LocalObjectInfo: public std::vector + { + bool HasSourceExtension; + bool HasPreprocessRule; + bool HasAssembleRule; + LocalObjectInfo():HasSourceExtension(false), HasPreprocessRule(false), + HasAssembleRule(false) {} + }; std::map LocalObjectFiles; + void WriteObjectConvenienceRule(std::ostream& ruleFileStream, + const char* comment, const char* output, + LocalObjectInfo const& info); + std::vector LocalHelp; /* does the work for each target */ diff --git a/Source/cmLocalVisualStudio10Generator.cxx b/Source/cmLocalVisualStudio10Generator.cxx index 8b22705b3..bf0e99709 100644 --- a/Source/cmLocalVisualStudio10Generator.cxx +++ b/Source/cmLocalVisualStudio10Generator.cxx @@ -74,24 +74,6 @@ void cmLocalVisualStudio10Generator::Generate() { cmTargets &tgts = this->Makefile->GetTargets(); - // Create the regeneration custom rule. - if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) - { - // Create a rule to regenerate the build system when the target - // specification source changes. - if(cmSourceFile* sf = this->CreateVCProjBuildRule()) - { - // Add the rule to targets that need it. - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) - { - if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) - { - l->second.AddSourceFile(sf); - } - } - } - } - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) { if(static_cast(this->GlobalGenerator) diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 1dfcbea02..99a4c95fc 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -15,6 +15,7 @@ #include "cmSystemTools.h" #include "cmSourceFile.h" #include "cmCacheManager.h" +#include "cmGeneratorTarget.h" #include "cmake.h" #include "cmComputeLinkInformation.h" @@ -84,6 +85,23 @@ void cmLocalVisualStudio6Generator::AddHelperCommands() this->CreateCustomTargetsAndCommands(lang); } +void cmLocalVisualStudio6Generator::AddCMakeListsRules() +{ + cmTargets &tgts = this->Makefile->GetTargets(); + for(cmTargets::iterator l = tgts.begin(); + l != tgts.end(); l++) + { + // Add a rule to regenerate the build system when the target + // specification source changes. + const char* suppRegenRule = + this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION"); + if (!cmSystemTools::IsOn(suppRegenRule)) + { + this->AddDSPBuildRule(l->second); + } + } +} + void cmLocalVisualStudio6Generator::Generate() { this->OutputDSPFile(); @@ -103,64 +121,9 @@ void cmLocalVisualStudio6Generator::OutputDSPFile() } } - // Setup /I and /LIBPATH options for the resulting DSP file. VS 6 - // truncates long include paths so make it as short as possible if - // the length threatens this problem. - unsigned int maxIncludeLength = 3000; - bool useShortPath = false; - for(int j=0; j < 2; ++j) - { - std::vector includes; - this->GetIncludeDirectories(includes); - std::vector::iterator i; - for(i = includes.begin(); i != includes.end(); ++i) - { - std::string tmp = - this->ConvertToOptionallyRelativeOutputPath(i->c_str()); - if(useShortPath) - { - cmSystemTools::GetShortPath(tmp.c_str(), tmp); - } - this->IncludeOptions += " /I "; - - // quote if not already quoted - if (tmp[0] != '"') - { - this->IncludeOptions += "\""; - this->IncludeOptions += tmp; - this->IncludeOptions += "\""; - } - else - { - this->IncludeOptions += tmp; - } - } - if(j == 0 && this->IncludeOptions.size() > maxIncludeLength) - { - this->IncludeOptions = ""; - useShortPath = true; - } - else - { - break; - } - } - // Create the DSP or set of DSP's for libraries and executables - cmTargets &tgts = this->Makefile->GetTargets(); - for(cmTargets::iterator l = tgts.begin(); - l != tgts.end(); l++) - { - // Add a rule to regenerate the build system when the target - // specification source changes. - const char* suppRegenRule = - this->Makefile->GetDefinition("CMAKE_SUPPRESS_REGENERATION"); - if (!cmSystemTools::IsOn(suppRegenRule)) - { - this->AddDSPBuildRule(l->second); - } - } + cmTargets &tgts = this->Makefile->GetTargets(); // build any targets for(cmTargets::iterator l = tgts.begin(); @@ -169,6 +132,7 @@ void cmLocalVisualStudio6Generator::OutputDSPFile() switch(l->second.GetType()) { case cmTarget::STATIC_LIBRARY: + case cmTarget::OBJECT_LIBRARY: this->SetBuildType(STATIC_LIBRARY, l->first.c_str(), l->second); break; case cmTarget::SHARED_LIBRARY: @@ -379,9 +343,6 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, } } - // Compute which sources need unique object computation. - this->ComputeObjectNameRequirements(sourceGroups); - // Write the DSP file's header. this->WriteDSPHeader(fout, libName, target, sourceGroups); @@ -401,6 +362,8 @@ void cmLocalVisualStudio6Generator ::WriteGroup(const cmSourceGroup *sg, cmTarget& target, std::ostream &fout, const char *libName) { + cmGeneratorTarget* gt = + this->GlobalGenerator->GetGeneratorTarget(&target); const std::vector &sourceFiles = sg->GetSourceFiles(); // If the group is empty, don't write it at all. @@ -417,28 +380,6 @@ void cmLocalVisualStudio6Generator this->WriteDSPBeginGroup(fout, name.c_str(), ""); } - // Compute the maximum length configuration name. - std::string config_max; - for(std::vector::iterator i = this->Configurations.begin(); - i != this->Configurations.end(); ++i) - { - // Strip the subdirectory name out of the configuration name. - std::string config = this->GetConfigName(*i); - if(config.size() > config_max.size()) - { - config_max = config; - } - } - - // Compute the maximum length full path to the intermediate - // files directory for any configuration. This is used to construct - // object file names that do not produce paths that are too long. - std::string dir_max; - dir_max += this->Makefile->GetCurrentOutputDirectory(); - dir_max += "/"; - dir_max += config_max; - dir_max += "/"; - // Loop through each source in the source group. for(std::vector::const_iterator sf = sourceFiles.begin(); sf != sourceFiles.end(); ++sf) @@ -449,11 +390,9 @@ void cmLocalVisualStudio6Generator std::string compileFlags; std::vector depends; std::string objectNameDir; - if(this->NeedObjectName.find(*sf) != this->NeedObjectName.end()) + if(gt->ExplicitObjectName.find(*sf) != gt->ExplicitObjectName.end()) { - objectNameDir = - cmSystemTools::GetFilenamePath( - this->GetObjectFileNameWithoutTarget(*(*sf), dir_max)); + objectNameDir = cmSystemTools::GetFilenamePath(gt->Objects[*sf]); } // Add per-source file flags. @@ -895,6 +834,61 @@ inline std::string removeQuotes(const std::string& s) return s; } + +std::string +cmLocalVisualStudio6Generator::GetTargetIncludeOptions(cmTarget &target) +{ + std::string includeOptions; + + // Setup /I and /LIBPATH options for the resulting DSP file. VS 6 + // truncates long include paths so make it as short as possible if + // the length threatens this problem. + unsigned int maxIncludeLength = 3000; + bool useShortPath = false; + for(int j=0; j < 2; ++j) + { + std::vector includes; + this->GetIncludeDirectories(includes, &target); + + std::vector::iterator i; + for(i = includes.begin(); i != includes.end(); ++i) + { + std::string tmp = + this->ConvertToOptionallyRelativeOutputPath(i->c_str()); + if(useShortPath) + { + cmSystemTools::GetShortPath(tmp.c_str(), tmp); + } + includeOptions += " /I "; + + // quote if not already quoted + if (tmp[0] != '"') + { + includeOptions += "\""; + includeOptions += tmp; + includeOptions += "\""; + } + else + { + includeOptions += tmp; + } + } + + if(j == 0 && includeOptions.size() > maxIncludeLength) + { + includeOptions = ""; + useShortPath = true; + } + else + { + break; + } + } + + return includeOptions; +} + + // Code in blocks surrounded by a test for this definition is needed // only for compatibility with user project's replacement DSP // templates. The CMake templates no longer use them. @@ -1132,6 +1126,9 @@ void cmLocalVisualStudio6Generator } #endif + // Get include options for this target. + std::string includeOptions = this->GetTargetIncludeOptions(target); + // Get extra linker options for this target type. std::string extraLinkOptions; std::string extraLinkOptionsDebug; @@ -1249,8 +1246,18 @@ void cmLocalVisualStudio6Generator outputNameMinSizeRel = target.GetFullName("MinSizeRel"); outputNameRelWithDebInfo = target.GetFullName("RelWithDebInfo"); } + else if(target.GetType() == cmTarget::OBJECT_LIBRARY) + { + outputName = target.GetName(); + outputName += ".lib"; + outputNameDebug = outputName; + outputNameRelease = outputName; + outputNameMinSizeRel = outputName; + outputNameRelWithDebInfo = outputName; + } // Compute the output directory for the target. + std::string outputDirOld; std::string outputDirDebug; std::string outputDirRelease; std::string outputDirMinSizeRel; @@ -1260,6 +1267,11 @@ void cmLocalVisualStudio6Generator target.GetType() == cmTarget::SHARED_LIBRARY || target.GetType() == cmTarget::MODULE_LIBRARY) { +#ifdef CM_USE_OLD_VS6 + outputDirOld = + removeQuotes(this->ConvertToOptionallyRelativeOutputPath + (target.GetDirectory().c_str())); +#endif outputDirDebug = removeQuotes(this->ConvertToOptionallyRelativeOutputPath( target.GetDirectory("Debug").c_str())); @@ -1273,6 +1285,14 @@ void cmLocalVisualStudio6Generator removeQuotes(this->ConvertToOptionallyRelativeOutputPath( target.GetDirectory("RelWithDebInfo").c_str())); } + else if(target.GetType() == cmTarget::OBJECT_LIBRARY) + { + std::string outputDir = cmake::GetCMakeFilesDirectoryPostSlash(); + outputDirDebug = outputDir + "Debug"; + outputDirRelease = outputDir + "Release"; + outputDirMinSizeRel = outputDir + "MinSizeRel"; + outputDirRelWithDebInfo = outputDir + "RelWithDebInfo"; + } // Compute the proper link information for the target. std::string optionsDebug; @@ -1413,6 +1433,16 @@ void cmLocalVisualStudio6Generator staticLibOptionsRelWithDebInfo += " "; staticLibOptionsRelWithDebInfo = libflagsRelWithDebInfo; } + std::string objects; + this->OutputObjects(target, "LIB", objects); + if(!objects.empty()) + { + objects = "\n" + objects; + staticLibOptionsDebug += objects; + staticLibOptionsRelease += objects; + staticLibOptionsMinSizeRel += objects; + staticLibOptionsRelWithDebInfo += objects; + } } // Add the export symbol definition for shared library objects. @@ -1441,7 +1471,8 @@ void cmLocalVisualStudio6Generator libnameExports.c_str()); cmSystemTools::ReplaceString(line, "CMAKE_MFC_FLAG", mfcFlag); - if(target.GetType() == cmTarget::STATIC_LIBRARY ) + if(target.GetType() == cmTarget::STATIC_LIBRARY || + target.GetType() == cmTarget::OBJECT_LIBRARY) { cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG", staticLibOptionsDebug.c_str()); @@ -1510,7 +1541,7 @@ void cmLocalVisualStudio6Generator optionsRelWithDebInfo.c_str()); cmSystemTools::ReplaceString(line, "BUILD_INCLUDES", - this->IncludeOptions.c_str()); + includeOptions.c_str()); cmSystemTools::ReplaceString(line, "TARGET_VERSION_FLAG", targetVersionFlag.c_str()); cmSystemTools::ReplaceString(line, "TARGET_IMPLIB_FLAG_DEBUG", @@ -1540,7 +1571,7 @@ void cmLocalVisualStudio6Generator (exePath.c_str())).c_str()); #endif - if(targetBuilds) + if(targetBuilds || target.GetType() == cmTarget::OBJECT_LIBRARY) { cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_DEBUG", outputDirDebug.c_str()); @@ -1550,13 +1581,11 @@ void cmLocalVisualStudio6Generator outputDirMinSizeRel.c_str()); cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY_RELWITHDEBINFO", outputDirRelWithDebInfo.c_str()); -#ifdef CM_USE_OLD_VS6 - std::string outPath = target.GetDirectory(); - cmSystemTools::ReplaceString - (line, "OUTPUT_DIRECTORY", - removeQuotes(this->ConvertToOptionallyRelativeOutputPath - (outPath.c_str())).c_str()); -#endif + if(!outputDirOld.empty()) + { + cmSystemTools::ReplaceString(line, "OUTPUT_DIRECTORY", + outputDirOld.c_str()); + } } cmSystemTools::ReplaceString(line, @@ -1573,7 +1602,7 @@ void cmLocalVisualStudio6Generator std::string flagsDebug = " "; std::string flagsDebugRel = " "; if(target.GetType() >= cmTarget::EXECUTABLE && - target.GetType() <= cmTarget::MODULE_LIBRARY) + target.GetType() <= cmTarget::OBJECT_LIBRARY) { const char* linkLanguage = target.GetLinkerLanguage(); if(!linkLanguage) @@ -1605,11 +1634,13 @@ void cmLocalVisualStudio6Generator flagsDebugRel = this->Makefile->GetSafeDefinition(flagVar.c_str()); flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" "; } - - // if unicode is not found, then add -D_MBCS + + // if _UNICODE and _SBCS are not found, then add -D_MBCS std::string defs = this->Makefile->GetDefineFlags(); if(flags.find("D_UNICODE") == flags.npos && - defs.find("D_UNICODE") == flags.npos) + defs.find("D_UNICODE") == flags.npos && + flags.find("D_SBCS") == flags.npos && + defs.find("D_SBCS") == flags.npos) { flags += " /D \"_MBCS\""; } @@ -1726,6 +1757,8 @@ void cmLocalVisualStudio6Generator ItemVector const& linkLibs = cli.GetItems(); std::vector const& linkDirs = cli.GetDirectories(); + this->OutputObjects(target, "LINK", options); + // Build the link options code. for(std::vector::const_iterator d = linkDirs.begin(); d != linkDirs.end(); ++d) @@ -1770,6 +1803,28 @@ void cmLocalVisualStudio6Generator } } +//---------------------------------------------------------------------------- +void cmLocalVisualStudio6Generator +::OutputObjects(cmTarget& target, const char* tool, + std::string& options) +{ + // VS 6 does not support per-config source locations so we + // list object library content on the link line instead. + cmGeneratorTarget* gt = + this->GlobalGenerator->GetGeneratorTarget(&target); + std::vector objs; + gt->UseObjectLibraries(objs); + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + options += "# ADD "; + options += tool; + options += "32 "; + options += this->ConvertToOptionallyRelativeOutputPath(oi->c_str()); + options += "\n"; + } +} + std::string cmLocalVisualStudio6Generator ::GetTargetDirectory(cmTarget const&) const @@ -1778,15 +1833,34 @@ cmLocalVisualStudio6Generator return ""; } -void cmLocalVisualStudio6Generator -::GetTargetObjectFileDirectories(cmTarget* , - std::vector& - dirs) +//---------------------------------------------------------------------------- +std::string +cmLocalVisualStudio6Generator +::ComputeLongestObjectDirectory(cmTarget&) const { - std::string dir = this->Makefile->GetCurrentOutputDirectory(); - dir += "/"; - dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory(); - dirs.push_back(dir); + // Compute the maximum length configuration name. + std::string config_max; + for(std::vector::const_iterator + i = this->Configurations.begin(); + i != this->Configurations.end(); ++i) + { + // Strip the subdirectory name out of the configuration name. + std::string config = this->GetConfigName(*i); + if(config.size() > config_max.size()) + { + config_max = config; + } + } + + // Compute the maximum length full path to the intermediate + // files directory for any configuration. This is used to construct + // object file names that do not produce paths that are too long. + std::string dir_max; + dir_max += this->Makefile->GetCurrentOutputDirectory(); + dir_max += "/"; + dir_max += config_max; + dir_max += "/"; + return dir_max; } std::string diff --git a/Source/cmLocalVisualStudio6Generator.h b/Source/cmLocalVisualStudio6Generator.h index 195d654bc..1decc3531 100644 --- a/Source/cmLocalVisualStudio6Generator.h +++ b/Source/cmLocalVisualStudio6Generator.h @@ -34,6 +34,7 @@ public: virtual ~cmLocalVisualStudio6Generator(); virtual void AddHelperCommands(); + virtual void AddCMakeListsRules(); /** * Generate the makefile for this directory. @@ -50,9 +51,7 @@ public: void SetBuildType(BuildType, const char* libName, cmTarget&); virtual std::string GetTargetDirectory(cmTarget const& target) const; - void GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs); + virtual std::string ComputeLongestObjectDirectory(cmTarget&) const; private: std::string DSPHeaderTemplate; std::string DSPFooterTemplate; @@ -89,7 +88,9 @@ private: void ComputeLinkOptions(cmTarget& target, const char* configName, const std::string extraOptions, std::string& options); - std::string IncludeOptions; + void OutputObjects(cmTarget& target, const char* tool, + std::string& options); + std::string GetTargetIncludeOptions(cmTarget &target); std::vector Configurations; std::string GetConfigName(std::string const& configuration) const; diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 11a038763..9faf46ddf 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -17,6 +17,7 @@ #include "cmSystemTools.h" #include "cmSourceFile.h" #include "cmCacheManager.h" +#include "cmGeneratorTarget.h" #include "cmake.h" #include "cmComputeLinkInformation.h" @@ -38,6 +39,7 @@ public: LocalGenerator(e) {} typedef cmComputeLinkInformation::ItemVector ItemVector; void OutputLibraries(std::ostream& fout, ItemVector const& libs); + void OutputObjects(std::ostream& fout, cmTarget* t, const char* isep = 0); private: cmLocalVisualStudio7Generator* LocalGenerator; }; @@ -98,6 +100,28 @@ void cmLocalVisualStudio7Generator::Generate() this->WriteStampFiles(); } +void cmLocalVisualStudio7Generator::AddCMakeListsRules() +{ + cmTargets &tgts = this->Makefile->GetTargets(); + // Create the regeneration custom rule. + if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) + { + // Create a rule to regenerate the build system when the target + // specification source changes. + if(cmSourceFile* sf = this->CreateVCProjBuildRule()) + { + // Add the rule to targets that need it. + for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) + { + if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) + { + l->second.AddSourceFile(sf); + } + } + } + } +} + void cmLocalVisualStudio7Generator::FixGlobalTargets() { // Visual Studio .NET 2003 Service Pack 1 will not run post-build @@ -154,24 +178,6 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles() // Get the set of targets in this directory. cmTargets &tgts = this->Makefile->GetTargets(); - // Create the regeneration custom rule. - if(!this->Makefile->IsOn("CMAKE_SUPPRESS_REGENERATION")) - { - // Create a rule to regenerate the build system when the target - // specification source changes. - if(cmSourceFile* sf = this->CreateVCProjBuildRule()) - { - // Add the rule to targets that need it. - for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); ++l) - { - if(l->first != CMAKE_CHECK_BUILD_SYSTEM_TARGET) - { - l->second.AddSourceFile(sf); - } - } - } - } - // Create the project file for each target. for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) @@ -641,6 +647,8 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, bool targetBuilds = true; switch(target.GetType()) { + case cmTarget::OBJECT_LIBRARY: + targetBuilds = false; // TODO: PDB for object library? case cmTarget::STATIC_LIBRARY: projectType = "typeStaticLibrary"; configType = "4"; @@ -774,6 +782,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, { fout << "\t\t\tCharacterSet=\"1\">\n"; } + else if(targetOptions.UsingSBCS()) + { + fout << "\t\t\tCharacterSet=\"0\">\n"; + } else { fout << "\t\t\tCharacterSet=\"2\">\n"; @@ -807,7 +819,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, targetOptions.OutputAdditionalOptions(fout, "\t\t\t\t", "\n"); fout << "\t\t\t\tAdditionalIncludeDirectories=\""; std::vector includes; - this->GetIncludeDirectories(includes); + this->GetIncludeDirectories(includes, &target); std::vector::iterator i = includes.begin(); for(;i != includes.end(); ++i) { @@ -996,6 +1008,22 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, } switch(target.GetType()) { + case cmTarget::OBJECT_LIBRARY: + { + std::string libpath = this->GetTargetDirectory(target); + libpath += "/"; + libpath += configName; + libpath += "/"; + libpath += target.GetName(); + libpath += ".lib"; + const char* tool = + this->FortranProject? "VFLibrarianTool":"VCLibrarianTool"; + fout << "\t\t\tConvertToXMLOutputPathSingle(libpath.c_str()) << "\"/>\n"; + break; + } case cmTarget::STATIC_LIBRARY: { std::string targetNameFull = target.GetFullName(configName); @@ -1010,6 +1038,15 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, fout << "\t\t\tGetVersion() < VS8) + { + cmOStringStream libdeps; + this->Internal->OutputObjects(libdeps, &target); + if(!libdeps.str().empty()) + { + fout << "\t\t\t\tAdditionalDependencies=\"" << libdeps.str() << "\"\n"; + } + } std::string libflags; if(const char* flags = target.GetProperty("STATIC_LIBRARY_FLAGS")) { @@ -1070,8 +1107,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " - << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()) - << " "; + << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + if(this->GetVersion() < VS8) + { + this->Internal->OutputObjects(fout, &target, " "); + } + fout << " "; this->Internal->OutputLibraries(fout, cli.GetItems()); fout << "\"\n"; temp = target.GetDirectory(configName); @@ -1151,8 +1192,12 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, // Use the NOINHERIT macro to avoid getting VS project default // libraries which may be set by the user to something bad. fout << "\t\t\t\tAdditionalDependencies=\"$(NOINHERIT) " - << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()) - << " "; + << this->Makefile->GetSafeDefinition(standardLibsVar.c_str()); + if(this->GetVersion() < VS8) + { + this->Internal->OutputObjects(fout, &target, " "); + } + fout << " "; this->Internal->OutputLibraries(fout, cli.GetItems()); fout << "\"\n"; temp = target.GetDirectory(configName); @@ -1238,6 +1283,30 @@ cmLocalVisualStudio7GeneratorInternals } } +//---------------------------------------------------------------------------- +void +cmLocalVisualStudio7GeneratorInternals +::OutputObjects(std::ostream& fout, cmTarget* t, const char* isep) +{ + // VS < 8 does not support per-config source locations so we + // list object library content on the link line instead. + cmLocalVisualStudio7Generator* lg = this->LocalGenerator; + cmGeneratorTarget* gt = + lg->GetGlobalGenerator()->GetGeneratorTarget(t); + std::vector objs; + gt->UseObjectLibraries(objs); + const char* sep = isep? isep : ""; + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + std::string rel = lg->Convert(oi->c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED); + fout << sep << lg->ConvertToXMLOutputPath(rel.c_str()); + sep = " "; + } +} + //---------------------------------------------------------------------------- void cmLocalVisualStudio7Generator @@ -1306,9 +1375,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, sourceGroup.AssignSource(*i); } - // Compute which sources need unique object computation. - this->ComputeObjectNameRequirements(sourceGroups); - // open the project this->WriteProjectStart(fout, libName, target, sourceGroups); // write the configuration information @@ -1324,7 +1390,27 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, this->WriteGroup(&sg, target, fout, libName, configs); } - //} + if(this->GetVersion() >= VS8) + { + // VS >= 8 support per-config source locations so we + // list object library content as external objects. + cmGeneratorTarget* gt = + this->GlobalGenerator->GetGeneratorTarget(&target); + std::vector objs; + gt->UseObjectLibraries(objs); + if(!objs.empty()) + { + // TODO: Separate sub-filter for each object library used? + fout << "\t\t\n"; + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + std::string o = this->ConvertToXMLOutputPathSingle(oi->c_str()); + fout << "\t\t\t\n"; + } + fout << "\t\t\n"; + } + } fout << "\t\n"; @@ -1348,8 +1434,7 @@ public: cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg, cmTarget& target, cmSourceFile const& sf, - std::vector* configs, - std::string const& dir_max); + std::vector* configs); std::map FileConfigMap; }; @@ -1357,13 +1442,14 @@ cmLocalVisualStudio7GeneratorFCInfo ::cmLocalVisualStudio7GeneratorFCInfo(cmLocalVisualStudio7Generator* lg, cmTarget& target, cmSourceFile const& sf, - std::vector* configs, - std::string const& dir_max) + std::vector* configs) { + cmGeneratorTarget* gt = + lg->GetGlobalGenerator()->GetGeneratorTarget(&target); std::string objectName; - if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end()) + if(gt->ExplicitObjectName.find(&sf) != gt->ExplicitObjectName.end()) { - objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max); + objectName = gt->Objects[&sf]; } // Compute per-source, per-config information. @@ -1474,11 +1560,11 @@ cmLocalVisualStudio7GeneratorFCInfo } } - -void cmLocalVisualStudio7Generator -::ComputeMaxDirectoryLength(std::string& maxdir, - cmTarget& target) -{ +//---------------------------------------------------------------------------- +std::string +cmLocalVisualStudio7Generator +::ComputeLongestObjectDirectory(cmTarget& target) const +{ std::vector *configs = static_cast (this->GlobalGenerator)->GetConfigurations(); @@ -1503,7 +1589,7 @@ void cmLocalVisualStudio7Generator dir_max += "/"; dir_max += config_max; dir_max += "/"; - maxdir = dir_max; + return dir_max; } void cmLocalVisualStudio7Generator @@ -1526,19 +1612,13 @@ void cmLocalVisualStudio7Generator this->WriteVCProjBeginGroup(fout, name.c_str(), ""); } - // Compute the maximum length full path to the intermediate - // files directory for any configuration. This is used to construct - // object file names that do not produce paths that are too long. - std::string dir_max; - this->ComputeMaxDirectoryLength(dir_max, target); - // Loop through each source in the source group. std::string objectName; for(std::vector::const_iterator sf = sourceFiles.begin(); sf != sourceFiles.end(); ++sf) { std::string source = (*sf)->GetFullPath(); - FCInfo fcinfo(this, target, *(*sf), configs, dir_max); + FCInfo fcinfo(this, target, *(*sf), configs); if (source != libName || target.GetType() == cmTarget::UTILITY || target.GetType() == cmTarget::GLOBAL_TARGET ) @@ -2114,19 +2194,6 @@ std::string cmLocalVisualStudio7Generator return dir; } -void cmLocalVisualStudio7Generator:: -GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs) -{ - std::string dir = this->Makefile->GetCurrentOutputDirectory(); - dir += "/"; - dir += this->GetTargetDirectory(*target); - dir += "/"; - dir += this->GetGlobalGenerator()->GetCMakeCFGInitDirectory(); - dirs.push_back(dir); -} - //---------------------------------------------------------------------------- #include static bool cmLVS6G_IsFAT(const char* dir) diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index 5b634b8c6..9aa408eda 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -54,23 +54,17 @@ public: void SetBuildType(BuildType,const char *name); void SetPlatformName(const char* n) { this->PlatformName = n;} - void GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs); void SetExtraFlagTable(cmVS7FlagTable const* table) { this->ExtraFlagTable = table; } virtual std::string GetTargetDirectory(cmTarget const&) const; cmSourceFile* CreateVCProjBuildRule(); void WriteStampFiles(); - // Compute the maximum length full path to the intermediate - // files directory for any configuration. This is used to construct - // object file names that do not produce paths that are too long. - void ComputeMaxDirectoryLength(std::string& maxdir, - cmTarget& target); + virtual std::string ComputeLongestObjectDirectory(cmTarget&) const; virtual void ReadAndStoreExternalGUID(const char* name, const char* path); + virtual void AddCMakeListsRules(); protected: void CreateSingleVCProj(const char *lname, cmTarget &tgt); private: diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index de1ac30fe..4bcf4defd 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -64,96 +64,6 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target, return pcc; } -//---------------------------------------------------------------------------- -bool cmLocalVisualStudioGenerator::SourceFileCompiles(const cmSourceFile* sf) -{ - // Identify the language of the source file. - if(const char* lang = this->GetSourceFileLanguage(*sf)) - { - // Check whether this source will actually be compiled. - return (!sf->GetCustomCommand() && - !sf->GetPropertyAsBool("HEADER_FILE_ONLY") && - !sf->GetPropertyAsBool("EXTERNAL_OBJECT")); - } - else - { - // Unknown source file language. Assume it will not be compiled. - return false; - } -} - -//---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::CountObjectNames( - const std::vector& groups, - std::map& counts) -{ - for(unsigned int i = 0; i < groups.size(); ++i) - { - cmSourceGroup sg = groups[i]; - std::vector const& srcs = sg.GetSourceFiles(); - for(std::vector::const_iterator s = srcs.begin(); - s != srcs.end(); ++s) - { - const cmSourceFile* sf = *s; - if(this->SourceFileCompiles(sf)) - { - std::string objectName = cmSystemTools::LowerCase( - cmSystemTools::GetFilenameWithoutLastExtension( - sf->GetFullPath())); - objectName += ".obj"; - counts[objectName] += 1; - } - } - this->CountObjectNames(sg.GetGroupChildren(), counts); - } -} - -//---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::InsertNeedObjectNames( - const std::vector& groups, - std::map& count) -{ - for(unsigned int i = 0; i < groups.size(); ++i) - { - cmSourceGroup sg = groups[i]; - std::vector const& srcs = sg.GetSourceFiles(); - for(std::vector::const_iterator s = srcs.begin(); - s != srcs.end(); ++s) - { - const cmSourceFile* sf = *s; - if(this->SourceFileCompiles(sf)) - { - std::string objectName = cmSystemTools::LowerCase( - cmSystemTools::GetFilenameWithoutLastExtension(sf->GetFullPath())); - objectName += ".obj"; - if(count[objectName] > 1) - { - this->NeedObjectName.insert(sf); - } - } - } - this->InsertNeedObjectNames(sg.GetGroupChildren(), count); - } -} - - -//---------------------------------------------------------------------------- -void cmLocalVisualStudioGenerator::ComputeObjectNameRequirements -(std::vector const& sourceGroups) -{ - // Clear the current set of requirements. - this->NeedObjectName.clear(); - - // Count the number of object files with each name. Note that - // windows file names are not case sensitive. - std::map objectNameCounts; - this->CountObjectNames(sourceGroups, objectNameCounts); - - // For all source files producing duplicate names we need unique - // object name computation. - this->InsertNeedObjectNames(sourceGroups, objectNameCounts); -} - //---------------------------------------------------------------------------- const char* cmLocalVisualStudioGenerator::ReportErrorLabel() const { diff --git a/Source/cmLocalVisualStudioGenerator.h b/Source/cmLocalVisualStudioGenerator.h index fcf1f21f0..9968592d1 100644 --- a/Source/cmLocalVisualStudioGenerator.h +++ b/Source/cmLocalVisualStudioGenerator.h @@ -56,6 +56,10 @@ public: /** Version of Visual Studio. */ VSVersion GetVersion() const { return this->Version; } + virtual std::string ComputeLongestObjectDirectory(cmTarget&) const = 0; + + virtual void AddCMakeListsRules() = 0; + protected: virtual const char* ReportErrorLabel() const; virtual bool CustomCommandUseLocal() const { return false; } @@ -64,16 +68,6 @@ protected: cmsys::auto_ptr MaybeCreateImplibDir(cmTarget& target, const char* config, bool isFortran); - // Safe object file name generation. - void ComputeObjectNameRequirements(std::vector const&); - bool SourceFileCompiles(const cmSourceFile* sf); - void CountObjectNames(const std::vector& groups, - std::map& count); - void InsertNeedObjectNames(const std::vector& groups, - std::map& count); - std::set NeedObjectName; - friend class cmVisualStudio10TargetGenerator; - VSVersion Version; }; diff --git a/Source/cmLocalXCodeGenerator.cxx b/Source/cmLocalXCodeGenerator.cxx index b98987041..551ebd30a 100644 --- a/Source/cmLocalXCodeGenerator.cxx +++ b/Source/cmLocalXCodeGenerator.cxx @@ -33,16 +33,3 @@ cmLocalXCodeGenerator::GetTargetDirectory(cmTarget const&) const // No per-target directory for this generator (yet). return ""; } - -//---------------------------------------------------------------------------- -void cmLocalXCodeGenerator:: -GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs) -{ - cmGlobalXCodeGenerator* g = - (cmGlobalXCodeGenerator*)this->GetGlobalGenerator(); - g->SetCurrentLocalGenerator(this); - g->GetTargetObjectFileDirectories(target, - dirs); -} diff --git a/Source/cmLocalXCodeGenerator.h b/Source/cmLocalXCodeGenerator.h index 1ab805da6..eab228f6b 100644 --- a/Source/cmLocalXCodeGenerator.h +++ b/Source/cmLocalXCodeGenerator.h @@ -27,9 +27,6 @@ public: cmLocalXCodeGenerator(); virtual ~cmLocalXCodeGenerator(); - void GetTargetObjectFileDirectories(cmTarget* target, - std::vector& - dirs); virtual std::string GetTargetDirectory(cmTarget const& target) const; private: diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 774f32b44..259922759 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -22,6 +22,17 @@ public: ///! clean up any memory allocated by the macro ~cmMacroHelperCommand() {}; + /** + * This is used to avoid including this command + * in documentation. This is mainly used by + * cmMacroHelperCommand and cmFunctionHelperCommand + * which cannot provide appropriate documentation. + */ + virtual bool ShouldAppearInDocumentation() const + { + return false; + } + /** * This is a virtual constructor for the command. */ @@ -39,7 +50,7 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * This is called when the command is first encountered in @@ -54,12 +65,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return this->Args[0].c_str(); } + virtual const char* GetName() const { return this->Args[0].c_str(); } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { std::string docs = "Macro named: "; docs += this->GetName(); @@ -69,7 +80,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return this->GetTerseDocumentation(); } diff --git a/Source/cmMacroCommand.h b/Source/cmMacroCommand.h index 93e10b271..36e4b2f6b 100644 --- a/Source/cmMacroCommand.h +++ b/Source/cmMacroCommand.h @@ -15,11 +15,6 @@ #include "cmCommand.h" #include "cmFunctionBlocker.h" -/** \class cmMacroFunctionBlocker - * \brief subclass of function blocker - * - * - */ class cmMacroFunctionBlocker : public cmFunctionBlocker { public: @@ -35,11 +30,7 @@ public: int Depth; }; -/** \class cmMacroCommand - * \brief starts an if block - * - * cmMacroCommand starts an if block - */ +/// Starts macro() ... endmacro() block class cmMacroCommand : public cmCommand { public: @@ -61,17 +52,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "macro";} + virtual const char* GetName() const { return "macro";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Start recording a macro for later invocation as a command."; } @@ -79,7 +70,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " macro( [arg1 [arg2 [arg3 ...]]])\n" diff --git a/Source/cmMakeDepend.cxx b/Source/cmMakeDepend.cxx index 0b4eea5b0..6055c5585 100644 --- a/Source/cmMakeDepend.cxx +++ b/Source/cmMakeDepend.cxx @@ -54,16 +54,33 @@ void cmMakeDepend::SetMakefile(cmMakefile* makefile) this->Makefile->IncludeFileRegularExpression.c_str()); this->ComplainFileRegularExpression.compile( this->Makefile->ComplainFileRegularExpression.c_str()); - - // Now extract any include paths from the makefile flags - const std::vector& includes = - this->Makefile->GetIncludeDirectories(); - for(std::vector::const_iterator j = includes.begin(); - j != includes.end(); ++j) + + // Now extract any include paths from the targets + std::set uniqueIncludes; + std::vector orderedAndUniqueIncludes; + cmTargets & targets = this->Makefile->GetTargets(); + for (cmTargets::iterator l = targets.begin(); l != targets.end(); ++l) + { + const std::vector& includes = + l->second.GetIncludeDirectories(); + for(std::vector::const_iterator j = includes.begin(); + j != includes.end(); ++j) + { + std::string path = *j; + this->Makefile->ExpandVariablesInString(path); + if(uniqueIncludes.insert(path).second) + { + orderedAndUniqueIncludes.push_back(path); + } + } + } + + for(std::vector::const_iterator + it = orderedAndUniqueIncludes.begin(); + it != orderedAndUniqueIncludes.end(); + ++it) { - std::string path = *j; - this->Makefile->ExpandVariablesInString(path); - this->AddSearchPath(path.c_str()); + this->AddSearchPath(it->c_str()); } } diff --git a/Source/cmMakeDirectoryCommand.h b/Source/cmMakeDirectoryCommand.h index 63b91d190..4e6e1d5ab 100644 --- a/Source/cmMakeDirectoryCommand.h +++ b/Source/cmMakeDirectoryCommand.h @@ -44,17 +44,17 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "make_directory";} + virtual const char* GetName() const { return "make_directory";} /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the file(MAKE_DIRECTORY ) command instead."; } @@ -62,7 +62,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " make_directory(directory)\n" @@ -72,7 +72,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7939d7322..e7e5edaa3 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -116,7 +116,6 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) this->Targets = mf.Targets; this->SourceFiles = mf.SourceFiles; this->Tests = mf.Tests; - this->IncludeDirectories = mf.IncludeDirectories; this->LinkDirectories = mf.LinkDirectories; this->SystemIncludeDirectories = mf.SystemIncludeDirectories; this->ListFiles = mf.ListFiles; @@ -210,9 +209,9 @@ cmMakefile::~cmMakefile() { delete *i; } - for(unsigned int i=0; i < this->UsedCommands.size(); i++) + for(unsigned int i=0; i < this->FinalPassCommands.size(); i++) { - delete this->UsedCommands[i]; + delete this->FinalPassCommands[i]; } std::vector::iterator pos; for (pos = this->FunctionBlockers.begin(); @@ -278,8 +277,6 @@ void cmMakefile::Print() this->cmHomeDirectory.c_str() << std::endl; std::cout << " this->ProjectName; " << this->ProjectName.c_str() << std::endl; - this->PrintStringVector("this->IncludeDirectories;", - this->IncludeDirectories); this->PrintStringVector("this->LinkDirectories", this->LinkDirectories); #if defined(CMAKE_BUILD_WITH_CMAKE) for( std::vector::const_iterator i = @@ -421,7 +418,7 @@ bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, else if(pcmd->HasFinalPass()) { // use the command - this->UsedCommands.push_back(pcmd.release()); + this->FinalPassCommands.push_back(pcmd.release()); } } else if ( this->GetCMakeInstance()->GetWorkingMode() == cmake::SCRIPT_MODE @@ -781,10 +778,10 @@ void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg) ("Source Files", "\\.(C|M|c|c\\+\\+|cc|cpp|cxx|f|f90|for|fpp" "|ftn|m|mm|rc|def|r|odl|idl|hpj|bat)$"); - this->AddSourceGroup("Header Files", - "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$"); + this->AddSourceGroup("Header Files", CM_HEADER_REGEX); this->AddSourceGroup("CMake Rules", "\\.rule$"); this->AddSourceGroup("Resources", "\\.plist$"); + this->AddSourceGroup("Object Files", "\\.(lo|o|obj)$"); #endif this->WarnUnused = this->GetCMakeInstance()->GetWarnUnused(); @@ -813,8 +810,8 @@ void cmMakefile::FinalPass() // give all the commands a chance to do something // after the file has been parsed before generation - for(std::vector::iterator i = this->UsedCommands.begin(); - i != this->UsedCommands.end(); ++i) + for(std::vector::iterator i = this->FinalPassCommands.begin(); + i != this->FinalPassCommands.end(); ++i) { (*i)->FinalPass(); } @@ -856,6 +853,14 @@ cmMakefile::AddCustomCommandToTarget(const char* target, cmTargets::iterator ti = this->Targets.find(target); if(ti != this->Targets.end()) { + if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "Target \"" << target << "\" is an OBJECT library " + "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands."; + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } // Add the command to the appropriate build step for the target. std::vector no_output; cmCustomCommand cc(this, no_output, depends, @@ -948,7 +953,7 @@ cmMakefile::AddCustomCommandToOutput(const std::vector& outputs, outName += ".rule"; const char* dir = this->LocalGenerator->GetGlobalGenerator()-> - GetCMakeCFGInitDirectory(); + GetCMakeCFGIntDir(); if(dir && dir[0] == '$') { cmSystemTools::ReplaceString(outName, dir, @@ -1478,7 +1483,8 @@ void cmMakefile::InitializeFromParent() this->Internal->VarStack.top() = parent->Internal->VarStack.top().Closure(); // copy include paths - this->IncludeDirectories = parent->IncludeDirectories; + this->SetProperty("INCLUDE_DIRECTORIES", + parent->GetProperty("INCLUDE_DIRECTORIES")); this->SystemIncludeDirectories = parent->SystemIncludeDirectories; // define flags @@ -1603,42 +1609,61 @@ void cmMakefile::AddSubDirectory(const char* srcPath, const char *binPath, } } -void cmMakefile::AddIncludeDirectory(const char* inc, bool before) +//---------------------------------------------------------------------------- +void AddStringToProperty(cmProperty *prop, const char* name, const char* s, + bool before) { - // if there is a newline then break it into multiple arguments - if (!inc) + if (!prop) { return; } - // Don't add an include directory that is already present. Yes, - // this linear search results in n^2 behavior, but n won't be - // getting much bigger than 20. We cannot use a set because of - // order dependency of the include path. - std::vector::iterator i = - std::find(this->IncludeDirectories.begin(), - this->IncludeDirectories.end(), inc); - if(i == this->IncludeDirectories.end()) + // Don't worry about duplicates at this point. We eliminate them when + // we convert the property to a vector in GetIncludeDirectories. + + if (before) { - if (before) + const char *val = prop->GetValue(); + cmOStringStream oss; + + if(val && *val) { - // WARNING: this *is* expensive (linear time) since it's a vector - this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc); + oss << s << ";" << val; } else { - this->IncludeDirectories.push_back(inc); + oss << s; } + + std::string newVal = oss.str(); + prop->Set(name, newVal.c_str()); } else { - if(before) - { - // if this before and already in the path then remove it - this->IncludeDirectories.erase(i); - // WARNING: this *is* expensive (linear time) since it's a vector - this->IncludeDirectories.insert(this->IncludeDirectories.begin(), inc); - } + prop->Append(name, s); + } +} + +//---------------------------------------------------------------------------- +void cmMakefile::AddIncludeDirectory(const char* inc, bool before) +{ + if (!inc) + { + return; + } + + // Directory property: + cmProperty *prop = + this->GetProperties().GetOrCreateProperty("INCLUDE_DIRECTORIES"); + AddStringToProperty(prop, "INCLUDE_DIRECTORIES", inc, before); + + // Property on each target: + for (cmTargets::iterator l = this->Targets.begin(); + l != this->Targets.end(); ++l) + { + cmTarget &t = l->second; + prop = t.GetProperties().GetOrCreateProperty("INCLUDE_DIRECTORIES"); + AddStringToProperty(prop, "INCLUDE_DIRECTORIES", inc, before); } } @@ -1895,8 +1920,11 @@ cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, // wrong type ? default to STATIC if ( (type != cmTarget::STATIC_LIBRARY) && (type != cmTarget::SHARED_LIBRARY) - && (type != cmTarget::MODULE_LIBRARY)) + && (type != cmTarget::MODULE_LIBRARY) + && (type != cmTarget::OBJECT_LIBRARY)) { + this->IssueMessage(cmake::INTERNAL_ERROR, + "cmMakefile::AddLibrary given invalid target type."); type = cmTarget::STATIC_LIBRARY; } @@ -1937,7 +1965,7 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name) cmTarget& target = it->second; target.SetType(type, name); target.SetMakefile(this); - this->LocalGenerator->GetGlobalGenerator()->AddTarget(*it); + this->LocalGenerator->GetGlobalGenerator()->AddTarget(&it->second); return &it->second; } @@ -2093,17 +2121,37 @@ void cmMakefile::AddExtraDirectory(const char* dir) } -// expance CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the +// expand CMAKE_BINARY_DIR and CMAKE_SOURCE_DIR in the // include and library directories. void cmMakefile::ExpandVariables() { // Now expand variables in the include and link strings - for(std::vector::iterator d = this->IncludeDirectories.begin(); - d != this->IncludeDirectories.end(); ++d) + + // May not be necessary anymore... But may need a policy for strict + // backwards compatibility + const char *includeDirs = this->GetProperty("INCLUDE_DIRECTORIES"); + if (includeDirs) { - this->ExpandVariablesInString(*d, true, true); + std::string dirs = includeDirs; + this->ExpandVariablesInString(dirs, true, true); + this->SetProperty("INCLUDE_DIRECTORIES", dirs.c_str()); + } + + // Also for each target's INCLUDE_DIRECTORIES property: + for (cmTargets::iterator l = this->Targets.begin(); + l != this->Targets.end(); ++l) + { + cmTarget &t = l->second; + includeDirs = t.GetProperty("INCLUDE_DIRECTORIES"); + if (includeDirs) + { + std::string dirs = includeDirs; + this->ExpandVariablesInString(dirs, true, true); + t.SetProperty("INCLUDE_DIRECTORIES", dirs.c_str()); + } } + for(std::vector::iterator d = this->LinkDirectories.begin(); d != this->LinkDirectories.end(); ++d) { @@ -2828,7 +2876,7 @@ void cmMakefile::EnableLanguage(std::vector const & lang, { this->AddDefinition("CMAKE_CFG_INTDIR", this->LocalGenerator->GetGlobalGenerator() - ->GetCMakeCFGInitDirectory()); + ->GetCMakeCFGIntDir()); this->LocalGenerator->GetGlobalGenerator()->EnableLanguage(lang, this, optional); } @@ -3317,16 +3365,6 @@ void cmMakefile::SetProperty(const char* prop, const char* value) // handle special props std::string propname = prop; - if ( propname == "INCLUDE_DIRECTORIES" ) - { - std::vector varArgsExpanded; - if(value) - { - cmSystemTools::ExpandListArgument(value, varArgsExpanded); - } - this->SetIncludeDirectories(varArgsExpanded); - return; - } if ( propname == "LINK_DIRECTORIES" ) { @@ -3368,17 +3406,6 @@ void cmMakefile::AppendProperty(const char* prop, const char* value, // handle special props std::string propname = prop; - if ( propname == "INCLUDE_DIRECTORIES" ) - { - std::vector varArgsExpanded; - cmSystemTools::ExpandListArgument(value, varArgsExpanded); - for(std::vector::const_iterator vi = varArgsExpanded.begin(); - vi != varArgsExpanded.end(); ++vi) - { - this->AddIncludeDirectory(vi->c_str()); - } - return; - } if ( propname == "LINK_DIRECTORIES" ) { @@ -3474,23 +3501,6 @@ const char *cmMakefile::GetProperty(const char* prop, output += this->DefineFlagsOrig; return output.c_str(); } - else if (!strcmp("INCLUDE_DIRECTORIES",prop) ) - { - cmOStringStream str; - for (std::vector::const_iterator - it = this->GetIncludeDirectories().begin(); - it != this->GetIncludeDirectories().end(); - ++ it ) - { - if ( it != this->GetIncludeDirectories().begin()) - { - str << ";"; - } - str << it->c_str(); - } - output = str.str(); - return output.c_str(); - } else if (!strcmp("LINK_DIRECTORIES",prop)) { cmOStringStream str; @@ -3861,9 +3871,22 @@ void cmMakefile::DefineProperties(cmake *cm) cm->DefineProperty ("INCLUDE_DIRECTORIES", cmProperty::DIRECTORY, "List of preprocessor include file search directories.", - "This read-only property specifies the list of directories given " - "so far to the include_directories command. " - "It is intended for debugging purposes.", false); + "This property specifies the list of directories given " + "so far to the include_directories command. " + "This property exists on directories and targets. " + "In addition to accepting values from the include_directories " + "command, values may be set directly on any directory or any " + "target using the set_property command. " + "A target gets its initial value for this property from the value " + "of the directory property. " + "A directory gets its initial value from its parent directory if " + "it has one. " + "Both directory and target property values are adjusted by calls " + "to the include_directories command." + "\n" + "The target property values are used by the generators to set " + "the include paths for the compiler. " + "See also the include_directories command."); cm->DefineProperty ("LINK_DIRECTORIES", cmProperty::DIRECTORY, @@ -3894,7 +3917,8 @@ void cmMakefile::DefineProperties(cmake *cm) //---------------------------------------------------------------------------- cmTarget* -cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type) +cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type, + bool global) { // Create the target. cmsys::auto_ptr target(new cmTarget); @@ -3904,6 +3928,10 @@ cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type) // Add to the set of available imported targets. this->ImportedTargets[name] = target.get(); + if(global) + { + this->LocalGenerator->GetGlobalGenerator()->AddTarget(target.get()); + } // Transfer ownership to this cmMakefile object. this->ImportedTargetsOwned.push_back(target.get()); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 123678783..960ba39db 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -203,7 +203,8 @@ public: void RemoveDefineFlag(const char* definition); /** Create a new imported target with the name and type given. */ - cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type); + cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type, + bool global); cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name); @@ -520,22 +521,6 @@ public: returned may be imported or built within the project. */ cmTarget* FindTargetToUse(const char* name); - /** - * Get a list of include directories in the build. - */ - std::vector& GetIncludeDirectories() - { - return this->IncludeDirectories; - } - const std::vector& GetIncludeDirectories() const - { - return this->IncludeDirectories; - } - void SetIncludeDirectories(const std::vector& vec) - { - this->IncludeDirectories = vec; - } - /** * Mark include directories as system directories. */ @@ -619,12 +604,6 @@ public: */ bool CanIWriteThisFile(const char* fileName); - /** - * Get the vector of used command instances. - */ - const std::vector& GetUsedCommands() const - {return this->UsedCommands;} - #if defined(CMAKE_BUILD_WITH_CMAKE) /** * Get the vector source groups. @@ -879,9 +858,7 @@ protected: // Tests std::map Tests; - // The include and link-library paths. These may have order - // dependency, so they must be vectors (not set). - std::vector IncludeDirectories; + // The link-library paths. Order matters, use std::vector (not std::set). std::vector LinkDirectories; // The set of include directories that are marked as system include @@ -912,7 +889,7 @@ protected: std::vector SourceGroups; #endif - std::vector UsedCommands; + std::vector FinalPassCommands; cmLocalGenerator* LocalGenerator; bool IsFunctionBlocked(const cmListFileFunction& lff, cmExecutionStatus &status); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index b4174cc36..38aa59dbf 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -101,6 +101,9 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles() this->WriteModuleLibraryRules(true); } break; + case cmTarget::OBJECT_LIBRARY: + this->WriteObjectLibraryRules(); + break; default: // If language is not known, this is an error. cmSystemTools::Error("Unknown Library Type"); @@ -121,6 +124,29 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles() this->CloseFileStreams(); } +//---------------------------------------------------------------------------- +void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules() +{ + std::vector commands; + std::vector depends; + + // Add post-build rules. + this->LocalGenerator-> + AppendCustomCommands(commands, this->Target->GetPostBuildCommands(), + this->Target); + + // Depend on the object files. + this->AppendObjectDepends(depends); + + // Write the rule. + this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0, + this->Target->GetName(), + depends, commands, true); + + // Write the main driver rule to build everything in this target. + this->WriteTargetDriverRule(this->Target->GetName(), false); +} + //---------------------------------------------------------------------------- void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() { diff --git a/Source/cmMakefileLibraryTargetGenerator.h b/Source/cmMakefileLibraryTargetGenerator.h index f3c47dbfd..e6a5867ea 100644 --- a/Source/cmMakefileLibraryTargetGenerator.h +++ b/Source/cmMakefileLibraryTargetGenerator.h @@ -25,6 +25,7 @@ public: virtual void WriteRuleFiles(); protected: + void WriteObjectLibraryRules(); void WriteStaticLibraryRules(); void WriteSharedLibraryRules(bool relink); void WriteModuleLibraryRules(bool relink); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index a3a832bc8..a0e04813d 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -11,6 +11,7 @@ ============================================================================*/ #include "cmMakefileTargetGenerator.h" +#include "cmGeneratorTarget.h" #include "cmGeneratedFileStream.h" #include "cmGlobalGenerator.h" #include "cmGlobalUnixMakefileGenerator3.h" @@ -42,6 +43,7 @@ cmMakefileTargetGenerator::cmMakefileTargetGenerator(cmTarget* target) this->GlobalGenerator = static_cast( this->LocalGenerator->GetGlobalGenerator()); + this->GeneratorTarget = this->GlobalGenerator->GetGeneratorTarget(target); cmake* cm = this->GlobalGenerator->GetCMakeInstance(); this->NoRuleMessages = false; if(const char* ruleStatus = cm->GetProperty("RULE_MESSAGES")) @@ -63,6 +65,7 @@ cmMakefileTargetGenerator::New(cmTarget *tgt) case cmTarget::STATIC_LIBRARY: case cmTarget::SHARED_LIBRARY: case cmTarget::MODULE_LIBRARY: + case cmTarget::OBJECT_LIBRARY: result = new cmMakefileLibraryTargetGenerator(tgt); break; case cmTarget::UTILITY: @@ -131,58 +134,49 @@ void cmMakefileTargetGenerator::WriteTargetBuildRules() // First generate the object rule files. Save a list of all object // files for this target. - const std::vector& sources = this->Target->GetSourceFiles(); - for(std::vector::const_iterator source = sources.begin(); - source != sources.end(); ++source) + for(std::vector::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) { - cmTarget::SourceFileFlags tsFlags = - this->Target->GetTargetSourceFileFlags(*source); - if(cmCustomCommand* cc = (*source)->GetCustomCommand()) - { - this->GenerateCustomRuleFile(*cc); - if (clean) - { - const std::vector& outputs = cc->GetOutputs(); - for(std::vector::const_iterator o = outputs.begin(); - o != outputs.end(); ++o) - { - this->CleanFiles.push_back - (this->Convert(o->c_str(), - cmLocalGenerator::START_OUTPUT, - cmLocalGenerator::UNCHANGED)); - } - } - } - else if(tsFlags.Type != cmTarget::SourceFileTypeNormal) + cmCustomCommand const* cc = (*si)->GetCustomCommand(); + this->GenerateCustomRuleFile(*cc); + if (clean) { - this->WriteMacOSXContentRules(*(*source), tsFlags.MacFolder); - } - else if(!(*source)->GetPropertyAsBool("HEADER_FILE_ONLY")) - { - if(!this->GlobalGenerator->IgnoreFile - ((*source)->GetExtension().c_str())) - { - // Generate this object file's rule file. - this->WriteObjectRuleFiles(*(*source)); - } - else if((*source)->GetPropertyAsBool("EXTERNAL_OBJECT")) - { - // This is an external object file. Just add it. - this->ExternalObjects.push_back((*source)->GetFullPath()); - } - else if(cmSystemTools::UpperCase((*source)->GetExtension()) == "DEF") - { - this->ModuleDefinitionFile = (*source)->GetFullPath(); - } - else + const std::vector& outputs = cc->GetOutputs(); + for(std::vector::const_iterator o = outputs.begin(); + o != outputs.end(); ++o) { - // We only get here if a source file is not an external object - // and has an extension that is listed as an ignored file type - // for this language. No message or diagnosis should be - // given. + this->CleanFiles.push_back + (this->Convert(o->c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::UNCHANGED)); } } } + for(std::vector::const_iterator + si = this->GeneratorTarget->OSXContent.begin(); + si != this->GeneratorTarget->OSXContent.end(); ++si) + { + cmTarget::SourceFileFlags tsFlags = + this->Target->GetTargetSourceFileFlags(*si); + this->WriteMacOSXContentRules(**si, tsFlags.MacFolder); + } + for(std::vector::const_iterator + si = this->GeneratorTarget->ExternalObjects.begin(); + si != this->GeneratorTarget->ExternalObjects.end(); ++si) + { + this->ExternalObjects.push_back((*si)->GetFullPath()); + } + for(std::vector::const_iterator + si = this->GeneratorTarget->ObjectSources.begin(); + si != this->GeneratorTarget->ObjectSources.end(); ++si) + { + // Generate this object file's rule file. + this->WriteObjectRuleFiles(**si); + } + + // Add object library contents as external objects. + this->GeneratorTarget->UseObjectLibraries(this->ExternalObjects); } @@ -428,12 +422,10 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source) } // Get the full path name of the object file. - bool hasSourceExtension; - std::string objNoTargetDir; - std::string obj = - this->LocalGenerator->GetObjectFileName(*this->Target, source, - &objNoTargetDir, - &hasSourceExtension); + std::string const& objectName = this->GeneratorTarget->Objects[&source]; + std::string obj = this->LocalGenerator->GetTargetDirectory(*this->Target); + obj += "/"; + obj += objectName; // Avoid generating duplicate rules. if(this->ObjectFiles.find(obj) == this->ObjectFiles.end()) @@ -487,18 +479,6 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(cmSourceFile& source) AddImplicitDepends(*this->Target, lang, objFullPath.c_str(), srcFullPath.c_str()); - - // add this to the list of objects for this local generator - if(cmSystemTools::FileIsFullPath(objNoTargetDir.c_str())) - { - objNoTargetDir = cmSystemTools::GetFilenameName(objNoTargetDir); - } - cmLocalUnixMakefileGenerator3::LocalObjectInfo& info = - this->LocalGenerator->LocalObjectFiles[objNoTargetDir]; - info.HasSourceExtension = hasSourceExtension; - info.push_back( - cmLocalUnixMakefileGenerator3::LocalObjectEntry(this->Target, lang) - ); } //---------------------------------------------------------------------------- @@ -1069,6 +1049,35 @@ void cmMakefileTargetGenerator::WriteTargetDependRules() << "SET(CMAKE_Fortran_TARGET_MODULE_DIR \"" << mdir << "\")\n"; } + // Target-specific include directories: + *this->InfoFileStream + << "\n" + << "# The include file search paths:\n"; + *this->InfoFileStream + << "SET(CMAKE_C_TARGET_INCLUDE_PATH\n"; + std::vector includes; + this->LocalGenerator->GetIncludeDirectories(includes, this->Target); + for(std::vector::iterator i = includes.begin(); + i != includes.end(); ++i) + { + *this->InfoFileStream + << " \"" + << this->LocalGenerator->Convert(i->c_str(), + cmLocalGenerator::HOME_OUTPUT) + << "\"\n"; + } + *this->InfoFileStream + << " )\n"; + *this->InfoFileStream + << "SET(CMAKE_CXX_TARGET_INCLUDE_PATH " + << "${CMAKE_C_TARGET_INCLUDE_PATH})\n"; + *this->InfoFileStream + << "SET(CMAKE_Fortran_TARGET_INCLUDE_PATH " + << "${CMAKE_C_TARGET_INCLUDE_PATH})\n"; + *this->InfoFileStream + << "SET(CMAKE_ASM_TARGET_INCLUDE_PATH " + << "${CMAKE_C_TARGET_INCLUDE_PATH})\n"; + // and now write the rule to use it std::vector depends; std::vector commands; @@ -1534,7 +1543,7 @@ std::string cmMakefileTargetGenerator::GetFrameworkFlags() emitted.insert("/System/Library/Frameworks"); #endif std::vector includes; - this->LocalGenerator->GetIncludeDirectories(includes); + this->LocalGenerator->GetIncludeDirectories(includes, this->Target); std::vector::iterator i; // check all include directories for frameworks as this // will already have added a -F for the framework @@ -1591,7 +1600,7 @@ void cmMakefileTargetGenerator //---------------------------------------------------------------------------- void cmMakefileTargetGenerator -::AppendLinkDepends(std::vector& depends) +::AppendObjectDepends(std::vector& depends) { // Add dependencies on the compiled object files. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath(); @@ -1604,25 +1613,32 @@ void cmMakefileTargetGenerator depends.push_back(objTarget); } - // Add dependencies on targets that must be built first. - this->AppendTargetDepends(depends); + // Add dependencies on the external object files. + for(std::vector::const_iterator obj + = this->ExternalObjects.begin(); + obj != this->ExternalObjects.end(); ++obj) + { + depends.push_back(*obj); + } // Add a dependency on the rule file itself. this->LocalGenerator->AppendRuleDepend(depends, this->BuildFileNameFull.c_str()); +} - // Add a dependency on the link definitions file, if any. - if(!this->ModuleDefinitionFile.empty()) - { - depends.push_back(this->ModuleDefinitionFile); - } +//---------------------------------------------------------------------------- +void cmMakefileTargetGenerator +::AppendLinkDepends(std::vector& depends) +{ + this->AppendObjectDepends(depends); - // Add dependencies on the external object files. - for(std::vector::const_iterator obj - = this->ExternalObjects.begin(); - obj != this->ExternalObjects.end(); ++obj) + // Add dependencies on targets that must be built first. + this->AppendTargetDepends(depends); + + // Add a dependency on the link definitions file, if any. + if(!this->GeneratorTarget->ModuleDefinitionFile.empty()) { - depends.push_back(*obj); + depends.push_back(this->GeneratorTarget->ModuleDefinitionFile); } // Add user-specified dependencies. @@ -1829,8 +1845,12 @@ void cmMakefileTargetGenerator::AddIncludeFlags(std::string& flags, responseVar += "_USE_RESPONSE_FILE_FOR_INCLUDES"; bool useResponseFile = this->Makefile->IsOn(responseVar.c_str()); + + std::vector includes; + this->LocalGenerator->GetIncludeDirectories(includes, this->Target, lang); + std::string includeFlags = - this->LocalGenerator->GetIncludeFlags(lang, useResponseFile); + this->LocalGenerator->GetIncludeFlags(includes, lang, useResponseFile); if(includeFlags.empty()) { return; @@ -1930,7 +1950,7 @@ void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags) this->Makefile->GetDefinition("CMAKE_Fortran_MODPATH_FLAG")) { std::vector includes; - this->LocalGenerator->GetIncludeDirectories(includes); + this->LocalGenerator->GetIncludeDirectories(includes, this->Target); for(std::vector::const_iterator idi = includes.begin(); idi != includes.end(); ++idi) { @@ -1946,7 +1966,7 @@ void cmMakefileTargetGenerator::AddFortranFlags(std::string& flags) //---------------------------------------------------------------------------- void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags) { - if(this->ModuleDefinitionFile.empty()) + if(this->GeneratorTarget->ModuleDefinitionFile.empty()) { return; } @@ -1963,7 +1983,7 @@ void cmMakefileTargetGenerator::AddModuleDefinitionFlag(std::string& flags) // vs6's "cl -link" pass it to the linker. std::string flag = defFileFlag; flag += (this->LocalGenerator->ConvertToLinkReference( - this->ModuleDefinitionFile.c_str())); + this->GeneratorTarget->ModuleDefinitionFile.c_str())); this->LocalGenerator->AppendFlags(flags, flag.c_str()); } diff --git a/Source/cmMakefileTargetGenerator.h b/Source/cmMakefileTargetGenerator.h index 8fba13f6e..e1e554b6e 100644 --- a/Source/cmMakefileTargetGenerator.h +++ b/Source/cmMakefileTargetGenerator.h @@ -17,6 +17,7 @@ class cmCustomCommand; class cmDependInformation; class cmDepends; +class cmGeneratorTarget; class cmGeneratedFileStream; class cmGlobalUnixMakefileGenerator3; class cmLocalUnixMakefileGenerator3; @@ -117,6 +118,9 @@ protected: // append intertarget dependencies void AppendTargetDepends(std::vector& depends); + // Append object file dependencies. + void AppendObjectDepends(std::vector& depends); + // Append link rule dependencies (objects, etc.). void AppendLinkDepends(std::vector& depends); @@ -157,6 +161,7 @@ protected: void RemoveForbiddenFlags(const char* flagVar, const char* linkLang, std::string& linkFlags); cmTarget *Target; + cmGeneratorTarget* GeneratorTarget; cmLocalUnixMakefileGenerator3 *LocalGenerator; cmGlobalUnixMakefileGenerator3 *GlobalGenerator; cmMakefile *Makefile; @@ -198,9 +203,6 @@ protected: std::vector Objects; std::vector ExternalObjects; - // The windows module definition source file (.def), if any. - std::string ModuleDefinitionFile; - // Set of object file names that will be built in this directory. std::set ObjectFiles; diff --git a/Source/cmMarkAsAdvancedCommand.h b/Source/cmMarkAsAdvancedCommand.h index 26e0a07fd..3658dbbd3 100644 --- a/Source/cmMarkAsAdvancedCommand.h +++ b/Source/cmMarkAsAdvancedCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "mark_as_advanced";} + virtual const char* GetName() const {return "mark_as_advanced";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Mark cmake cached variables as advanced."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " mark_as_advanced([CLEAR|FORCE] VAR VAR2 VAR...)\n" @@ -75,7 +75,7 @@ public: * make many of the modules usable in cmake/ctest scripts, (among them * FindUnixMake.cmake used by the CTEST_BUILD command. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } cmTypeMacro(cmMarkAsAdvancedCommand, cmCommand); }; diff --git a/Source/cmMathCommand.h b/Source/cmMathCommand.h index d31f34ba9..d62290428 100644 --- a/Source/cmMathCommand.h +++ b/Source/cmMathCommand.h @@ -14,10 +14,7 @@ #include "cmCommand.h" -/** \class cmMathCommand - * \brief Common string operations - * - */ +/// Mathematical expressions: math(EXPR ...) command. class cmMathCommand : public cmCommand { public: @@ -39,17 +36,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "math";} + virtual const char* GetName() const { return "math";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Mathematical expressions."; } @@ -57,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " math(EXPR )\n" diff --git a/Source/cmMessageCommand.h b/Source/cmMessageCommand.h index 932ee773f..03ab94b1c 100644 --- a/Source/cmMessageCommand.h +++ b/Source/cmMessageCommand.h @@ -39,17 +39,17 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "message";} + virtual const char* GetName() const { return "message";} /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Display a message to the user."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " message([STATUS|WARNING|AUTHOR_WARNING|FATAL_ERROR|SEND_ERROR]\n" diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx new file mode 100644 index 000000000..2bad32c5d --- /dev/null +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -0,0 +1,500 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmNinjaNormalTargetGenerator.h" +#include "cmLocalNinjaGenerator.h" +#include "cmGlobalNinjaGenerator.h" +#include "cmSourceFile.h" +#include "cmGeneratedFileStream.h" +#include "cmMakefile.h" + +#include + +cmNinjaNormalTargetGenerator:: +cmNinjaNormalTargetGenerator(cmTarget* target) + : cmNinjaTargetGenerator(target) + , TargetNameOut() + , TargetNameSO() + , TargetNameReal() + , TargetNameImport() + , TargetNamePDB() +{ + this->TargetLinkLanguage = target->GetLinkerLanguage(this->GetConfigName()); + if (target->GetType() == cmTarget::EXECUTABLE) + target->GetExecutableNames(this->TargetNameOut, + this->TargetNameReal, + this->TargetNameImport, + this->TargetNamePDB, + GetLocalGenerator()->GetConfigName()); + else + target->GetLibraryNames(this->TargetNameOut, + this->TargetNameSO, + this->TargetNameReal, + this->TargetNameImport, + this->TargetNamePDB, + GetLocalGenerator()->GetConfigName()); + + if(target->GetType() != cmTarget::OBJECT_LIBRARY) + { + // on Windows the output dir is already needed at compile time + // ensure the directory exists (OutDir test) + std::string outpath = target->GetDirectory(this->GetConfigName()); + cmSystemTools::MakeDirectory(outpath.c_str()); + } +} + +cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() +{ +} + +void cmNinjaNormalTargetGenerator::Generate() +{ + if (!this->TargetLinkLanguage) { + cmSystemTools::Error("CMake can not determine linker language for target:", + this->GetTarget()->GetName()); + return; + } + + // Write the rules for each language. + this->WriteLanguagesRules(); + + // Write the build statements + this->WriteObjectBuildStatements(); + + if(this->GetTarget()->GetType() == cmTarget::OBJECT_LIBRARY) + { + this->WriteObjectLibStatement(); + } + else + { + this->WriteLinkRule(); + this->WriteLinkStatement(); + } + + this->GetBuildFileStream() << "\n"; + this->GetRulesFileStream() << "\n"; +} + +void cmNinjaNormalTargetGenerator::WriteLanguagesRules() +{ + cmGlobalNinjaGenerator::WriteDivider(this->GetRulesFileStream()); + this->GetRulesFileStream() + << "# Rules for each languages for " + << cmTarget::GetTargetTypeName(this->GetTarget()->GetType()) + << " target " + << this->GetTargetName() + << "\n\n"; + + std::set languages; + this->GetTarget()->GetLanguages(languages); + for(std::set::const_iterator l = languages.begin(); + l != languages.end(); + ++l) + this->WriteLanguageRules(*l); +} + +const char *cmNinjaNormalTargetGenerator::GetVisibleTypeName() const +{ + switch (this->GetTarget()->GetType()) { + case cmTarget::STATIC_LIBRARY: + return "static library"; + case cmTarget::SHARED_LIBRARY: + return "shared library"; + case cmTarget::MODULE_LIBRARY: + return "shared module"; + case cmTarget::EXECUTABLE: + return "executable"; + default: + return 0; + } +} + +std::string +cmNinjaNormalTargetGenerator +::LanguageLinkerRule() const +{ + return std::string(this->TargetLinkLanguage) + + "_" + + cmTarget::GetTargetTypeName(this->GetTarget()->GetType()) + + "_LINKER"; +} + +void +cmNinjaNormalTargetGenerator +::WriteLinkRule() +{ + cmTarget::TargetType targetType = this->GetTarget()->GetType(); + std::string ruleName = this->LanguageLinkerRule(); + + if (!this->GetGlobalGenerator()->HasRule(ruleName)) { + cmLocalGenerator::RuleVariables vars; + vars.RuleLauncher = "RULE_LAUNCH_LINK"; + vars.CMTarget = this->GetTarget(); + vars.Language = this->TargetLinkLanguage; + vars.Objects = "$in"; + std::string objdir = + this->GetLocalGenerator()->GetHomeRelativeOutputPath(); + objdir += objdir.empty() ? "" : "/"; + objdir += cmake::GetCMakeFilesDirectoryPostSlash(); + objdir += this->GetTargetName(); + objdir += ".dir"; + objdir = this->GetLocalGenerator()->Convert(objdir.c_str(), + cmLocalGenerator::START_OUTPUT, + cmLocalGenerator::SHELL); + vars.ObjectDir = objdir.c_str(); + vars.Target = "$out"; + vars.TargetSOName = "$SONAME"; + vars.TargetInstallNameDir = "$INSTALLNAME_DIR"; + vars.TargetPDB = "$TARGET_PDB"; + + // Setup the target version. + std::string targetVersionMajor; + std::string targetVersionMinor; + { + cmOStringStream majorStream; + cmOStringStream minorStream; + int major; + int minor; + this->GetTarget()->GetTargetVersion(major, minor); + majorStream << major; + minorStream << minor; + targetVersionMajor = majorStream.str(); + targetVersionMinor = minorStream.str(); + } + vars.TargetVersionMajor = targetVersionMajor.c_str(); + vars.TargetVersionMinor = targetVersionMinor.c_str(); + + vars.LinkLibraries = "$LINK_LIBRARIES"; + vars.Flags = "$FLAGS"; + vars.LinkFlags = "$LINK_FLAGS"; + + std::string langFlags; + this->GetLocalGenerator()->AddLanguageFlags(langFlags, + this->TargetLinkLanguage, + this->GetConfigName()); + if (targetType != cmTarget::EXECUTABLE) + langFlags += " $ARCH_FLAGS"; + vars.LanguageCompileFlags = langFlags.c_str(); + + // Rule for linking library. + std::vector linkCmds = this->ComputeLinkCmd(); + for(std::vector::iterator i = linkCmds.begin(); + i != linkCmds.end(); + ++i) + { + this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); + } + linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); + linkCmds.push_back("$POST_BUILD"); + std::string linkCmd = + this->GetLocalGenerator()->BuildCommandLine(linkCmds); + + // Write the linker rule. + std::ostringstream comment; + comment << "Rule for linking " << this->TargetLinkLanguage << " " + << this->GetVisibleTypeName() << "."; + std::ostringstream description; + description << "Linking " << this->TargetLinkLanguage << " " + << this->GetVisibleTypeName() << " $out"; + this->GetGlobalGenerator()->AddRule(ruleName, + linkCmd, + description.str(), + comment.str()); + } + + if (this->TargetNameOut != this->TargetNameReal) { + std::string cmakeCommand = + this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"), + cmLocalGenerator::SHELL); + if (targetType == cmTarget::EXECUTABLE) + this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_EXECUTABLE", + cmakeCommand + + " -E cmake_symlink_executable" + " $in $out && $POST_BUILD", + "Creating executable symlink $out", + "Rule for creating executable symlink."); + else + this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_LIBRARY", + cmakeCommand + + " -E cmake_symlink_library" + " $in $SONAME $out && $POST_BUILD", + "Creating library symlink $out", + "Rule for creating library symlink."); + } +} + +std::vector +cmNinjaNormalTargetGenerator +::ComputeLinkCmd() +{ + std::vector linkCmds; + cmTarget::TargetType targetType = this->GetTarget()->GetType(); + switch (targetType) { + case cmTarget::STATIC_LIBRARY: { + // Check if you have a non archive way to create the static library. + { + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + linkCmdVar += "_CREATE_STATIC_LIBRARY"; + if (const char *linkCmd = + this->GetMakefile()->GetDefinition(linkCmdVar.c_str())) + { + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + return linkCmds; + } + } + + // We have archive link commands set. First, delete the existing archive. + std::string cmakeCommand = + this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"), + cmLocalGenerator::SHELL); + linkCmds.push_back(cmakeCommand + " -E remove $out"); + + // TODO: Use ARCHIVE_APPEND for archives over a certain size. + { + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + linkCmdVar += "_ARCHIVE_CREATE"; + const char *linkCmd = + this->GetMakefile()->GetRequiredDefinition(linkCmdVar.c_str()); + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + } + { + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + linkCmdVar += "_ARCHIVE_FINISH"; + const char *linkCmd = + this->GetMakefile()->GetRequiredDefinition(linkCmdVar.c_str()); + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + } + return linkCmds; + } + case cmTarget::SHARED_LIBRARY: + case cmTarget::MODULE_LIBRARY: + case cmTarget::EXECUTABLE: { + std::string linkCmdVar = "CMAKE_"; + linkCmdVar += this->TargetLinkLanguage; + switch (targetType) { + case cmTarget::SHARED_LIBRARY: + linkCmdVar += "_CREATE_SHARED_LIBRARY"; + break; + case cmTarget::MODULE_LIBRARY: + linkCmdVar += "_CREATE_SHARED_MODULE"; + break; + case cmTarget::EXECUTABLE: + linkCmdVar += "_LINK_EXECUTABLE"; + break; + default: + assert(0 && "Unexpected target type"); + } + + const char *linkCmd = + this->GetMakefile()->GetRequiredDefinition(linkCmdVar.c_str()); + cmSystemTools::ExpandListArgument(linkCmd, linkCmds); + return linkCmds; + } + default: + assert(0 && "Unexpected target type"); + } + return std::vector(); +} + +void cmNinjaNormalTargetGenerator::WriteLinkStatement() +{ + cmTarget::TargetType targetType = this->GetTarget()->GetType(); + + // Write comments. + cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream()); + this->GetBuildFileStream() + << "# Link build statements for " + << cmTarget::GetTargetTypeName(targetType) + << " target " + << this->GetTargetName() + << "\n\n"; + + cmNinjaDeps emptyDeps; + cmNinjaVars vars; + + std::string targetOutput = ConvertToNinjaPath( + this->GetTarget()->GetFullPath(this->GetConfigName()).c_str()); + std::string targetOutputReal = ConvertToNinjaPath( + this->GetTarget()->GetFullPath(this->GetConfigName(), + /*implib=*/false, + /*realpath=*/true).c_str()); + std::string targetOutputImplib = ConvertToNinjaPath( + this->GetTarget()->GetFullPath(this->GetConfigName(), + /*implib=*/true).c_str()); + + // Compute the comment. + std::ostringstream comment; + comment << "Link the " << this->GetVisibleTypeName() << " " + << targetOutputReal; + + // Compute outputs. + cmNinjaDeps outputs; + outputs.push_back(targetOutputReal); + + // Compute specific libraries to link with. + cmNinjaDeps explicitDeps = this->GetObjects(), + implicitDeps = this->ComputeLinkDeps(); + + this->GetLocalGenerator()->GetTargetFlags(vars["LINK_LIBRARIES"], + vars["FLAGS"], + vars["LINK_FLAGS"], + *this->GetTarget()); + + this->AddModuleDefinitionFlag(vars["LINK_FLAGS"]); + + // Compute architecture specific link flags. Yes, these go into a different + // variable for executables, probably due to a mistake made when duplicating + // code between the Makefile executable and library generators. + this->GetLocalGenerator() + ->AddArchitectureFlags(targetType == cmTarget::EXECUTABLE + ? vars["FLAGS"] + : vars["ARCH_FLAGS"], + this->GetTarget(), + this->TargetLinkLanguage, + this->GetConfigName()); + vars["SONAME"] = this->TargetNameSO; + + if (targetType == cmTarget::SHARED_LIBRARY) { + std::string install_name_dir = + this->GetTarget()->GetInstallNameDirForBuildTree(this->GetConfigName()); + + if (!install_name_dir.empty()) { + vars["INSTALLNAME_DIR"] = + this->GetLocalGenerator()->Convert(install_name_dir.c_str(), + cmLocalGenerator::NONE, + cmLocalGenerator::SHELL, false); + } + } + + if (!this->TargetNameImport.empty()) { + vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat( + targetOutputImplib.c_str(), cmLocalGenerator::SHELL); + } + + vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + + std::vector *cmdLists[3] = { + &this->GetTarget()->GetPreBuildCommands(), + &this->GetTarget()->GetPreLinkCommands(), + &this->GetTarget()->GetPostBuildCommands() + }; + + std::vector preLinkCmdLines, postBuildCmdLines; + std::vector *cmdLineLists[3] = { + &preLinkCmdLines, + &preLinkCmdLines, + &postBuildCmdLines + }; + + for (unsigned i = 0; i != 3; ++i) { + for (std::vector::const_iterator + ci = cmdLists[i]->begin(); + ci != cmdLists[i]->end(); ++ci) { + this->GetLocalGenerator()->AppendCustomCommandLines(&*ci, + *cmdLineLists[i]); + } + } + + // If we have any PRE_LINK commands, we need to go back to HOME_OUTPUT for + // the link commands. + if (!preLinkCmdLines.empty()) { + std::string path = this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetMakefile()->GetHomeOutputDirectory(), + cmLocalGenerator::SHELL); + preLinkCmdLines.push_back("cd " + path); + } + + vars["PRE_LINK"] = + this->GetLocalGenerator()->BuildCommandLine(preLinkCmdLines); + std::string postBuildCmdLine = + this->GetLocalGenerator()->BuildCommandLine(postBuildCmdLines); + + cmNinjaVars symlinkVars; + if (targetOutput == targetOutputReal) { + vars["POST_BUILD"] = postBuildCmdLine; + } else { + vars["POST_BUILD"] = ":"; + symlinkVars["POST_BUILD"] = postBuildCmdLine; + } + + // Write the build statement for this target. + cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), + comment.str(), + this->LanguageLinkerRule(), + outputs, + explicitDeps, + implicitDeps, + emptyDeps, + vars); + + if (targetOutput != targetOutputReal) { + if (targetType == cmTarget::EXECUTABLE) { + cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), + "Create executable symlink " + targetOutput, + "CMAKE_SYMLINK_EXECUTABLE", + cmNinjaDeps(1, targetOutput), + cmNinjaDeps(1, targetOutputReal), + emptyDeps, + emptyDeps, + symlinkVars); + } else { + symlinkVars["SONAME"] = this->GetTargetFilePath(this->TargetNameSO); + cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), + "Create library symlink " + targetOutput, + "CMAKE_SYMLINK_LIBRARY", + cmNinjaDeps(1, targetOutput), + cmNinjaDeps(1, targetOutputReal), + emptyDeps, + emptyDeps, + symlinkVars); + } + } + + if (!this->TargetNameImport.empty()) { + // Since using multiple outputs would mess up the $out variable, use an + // alias for the import library. + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "Alias for import library.", + cmNinjaDeps(1, targetOutputImplib), + cmNinjaDeps(1, targetOutputReal)); + } + + // Add aliases for the file name and the target name. + this->GetGlobalGenerator()->AddTargetAlias(this->TargetNameOut, + this->GetTarget()); + this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), + this->GetTarget()); +} + +//---------------------------------------------------------------------------- +void cmNinjaNormalTargetGenerator::WriteObjectLibStatement() +{ + // Write a phony output that depends on all object files. + cmNinjaDeps outputs; + this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs); + cmNinjaDeps depends = this->GetObjects(); + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "Object library " + + this->GetTargetName(), + outputs, + depends); + + // Add aliases for the target name. + this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), + this->GetTarget()); +} diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h new file mode 100644 index 000000000..1702cafe8 --- /dev/null +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -0,0 +1,48 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmNinjaNormalTargetGenerator_h +# define cmNinjaNormalTargetGenerator_h + +# include "cmNinjaTargetGenerator.h" +# include "cmNinjaTypes.h" + +class cmSourceFile; + +class cmNinjaNormalTargetGenerator : public cmNinjaTargetGenerator +{ +public: + cmNinjaNormalTargetGenerator(cmTarget* target); + ~cmNinjaNormalTargetGenerator(); + + void Generate(); + +private: + std::string LanguageLinkerRule() const; + const char* GetVisibleTypeName() const; + void WriteLanguagesRules(); + void WriteLinkRule(); + void WriteLinkStatement(); + void WriteObjectLibStatement(); + std::vector ComputeLinkCmd(); + +private: + // Target name info. + std::string TargetNameOut; + std::string TargetNameSO; + std::string TargetNameReal; + std::string TargetNameImport; + std::string TargetNamePDB; + const char *TargetLinkLanguage; +}; + +#endif // ! cmNinjaNormalTargetGenerator_h diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx new file mode 100644 index 000000000..c6469f2c9 --- /dev/null +++ b/Source/cmNinjaTargetGenerator.cxx @@ -0,0 +1,536 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmNinjaTargetGenerator.h" +#include "cmGlobalNinjaGenerator.h" +#include "cmLocalNinjaGenerator.h" +#include "cmGeneratedFileStream.h" +#include "cmGeneratorTarget.h" +#include "cmNinjaNormalTargetGenerator.h" +#include "cmNinjaUtilityTargetGenerator.h" +#include "cmSystemTools.h" +#include "cmMakefile.h" +#include "cmComputeLinkInformation.h" +#include "cmSourceFile.h" +#include "cmCustomCommandGenerator.h" + +#include + +cmNinjaTargetGenerator * +cmNinjaTargetGenerator::New(cmTarget* target) +{ + switch (target->GetType()) + { + case cmTarget::EXECUTABLE: + case cmTarget::SHARED_LIBRARY: + case cmTarget::STATIC_LIBRARY: + case cmTarget::MODULE_LIBRARY: + case cmTarget::OBJECT_LIBRARY: + return new cmNinjaNormalTargetGenerator(target); + + case cmTarget::UTILITY: + return new cmNinjaUtilityTargetGenerator(target);; + + case cmTarget::GLOBAL_TARGET: { + // We only want to process global targets that live in the home + // (i.e. top-level) directory. CMake creates copies of these targets + // in every directory, which we don't need. + cmMakefile *mf = target->GetMakefile(); + if (strcmp(mf->GetStartDirectory(), mf->GetHomeDirectory()) == 0) + return new cmNinjaUtilityTargetGenerator(target); + // else fallthrough + } + + default: + return 0; + } +} + +cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmTarget* target) + : Target(target), + Makefile(target->GetMakefile()), + LocalGenerator( + static_cast(Makefile->GetLocalGenerator())), + Objects() +{ + this->GeneratorTarget = + this->GetGlobalGenerator()->GetGeneratorTarget(target); +} + +cmNinjaTargetGenerator::~cmNinjaTargetGenerator() +{ +} + +cmGeneratedFileStream& cmNinjaTargetGenerator::GetBuildFileStream() const +{ + return *this->GetGlobalGenerator()->GetBuildFileStream(); +} + +cmGeneratedFileStream& cmNinjaTargetGenerator::GetRulesFileStream() const +{ + return *this->GetGlobalGenerator()->GetRulesFileStream(); +} + +cmGlobalNinjaGenerator* cmNinjaTargetGenerator::GetGlobalGenerator() const +{ + return this->LocalGenerator->GetGlobalNinjaGenerator(); +} + +const char* cmNinjaTargetGenerator::GetConfigName() const +{ + return this->LocalGenerator->ConfigName.c_str(); +} + +// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. +const char* cmNinjaTargetGenerator::GetFeature(const char* feature) +{ + return this->Target->GetFeature(feature, this->GetConfigName()); +} + +// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. +bool cmNinjaTargetGenerator::GetFeatureAsBool(const char* feature) +{ + return cmSystemTools::IsOn(this->GetFeature(feature)); +} + +// TODO: Picked up from cmMakefileTargetGenerator. Refactor it. +void cmNinjaTargetGenerator::AddFeatureFlags(std::string& flags, + const char* lang) +{ + // Add language-specific flags. + this->LocalGenerator->AddLanguageFlags(flags, lang, this->GetConfigName()); + + if(this->GetFeatureAsBool("INTERPROCEDURAL_OPTIMIZATION")) + { + this->LocalGenerator->AppendFeatureOptions(flags, lang, "IPO"); + } +} + +// TODO: Most of the code is picked up from +// void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink), +// void cmMakefileTargetGenerator::WriteTargetLanguageFlags() +// Refactor it. +std::string +cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source, + const std::string& language) +{ + std::string flags; + + this->AddFeatureFlags(flags, language.c_str()); + + this->GetLocalGenerator()->AddArchitectureFlags(flags, + this->GetTarget(), + language.c_str(), + this->GetConfigName()); + + // TODO: Fortran support. + // // Fortran-specific flags computed for this target. + // if(*l == "Fortran") + // { + // this->AddFortranFlags(flags); + // } + + // Add shared-library flags if needed. + { + bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) || + (this->Target->GetType() == cmTarget::MODULE_LIBRARY)); + this->GetLocalGenerator()->AddSharedFlags(flags, language.c_str(), shared); + } + + // TODO: Handle response file. + // Add include directory flags. + { + std::vector includes; + this->LocalGenerator->GetIncludeDirectories(includes, this->Target, + language.c_str()); + std::string includeFlags = + this->LocalGenerator->GetIncludeFlags(includes, language.c_str(), false); + this->LocalGenerator->AppendFlags(flags, includeFlags.c_str()); + } + + // Append old-style preprocessor definition flags. + this->LocalGenerator->AppendFlags(flags, this->Makefile->GetDefineFlags()); + + // Add target-specific and source-specific flags. + this->LocalGenerator->AppendFlags(flags, + this->Target->GetProperty("COMPILE_FLAGS")); + this->LocalGenerator->AppendFlags(flags, + source->GetProperty("COMPILE_FLAGS")); + + // TODO: Handle Apple frameworks. + + return flags; +} + +// TODO: Refactor with +// void cmMakefileTargetGenerator::WriteTargetLanguageFlags(). +std::string +cmNinjaTargetGenerator:: +ComputeDefines(cmSourceFile *source, const std::string& language) +{ + std::string defines; + + // Add the export symbol definition for shared library objects. + if(const char* exportMacro = this->Target->GetExportMacro()) + { + this->LocalGenerator->AppendDefines(defines, exportMacro, + language.c_str()); + } + + // Add preprocessor definitions for this target and configuration. + this->LocalGenerator->AppendDefines + (defines, + this->Makefile->GetProperty("COMPILE_DEFINITIONS"), + language.c_str()); + this->LocalGenerator->AppendDefines + (defines, + this->Target->GetProperty("COMPILE_DEFINITIONS"), + language.c_str()); + this->LocalGenerator->AppendDefines + (defines, + source->GetProperty("COMPILE_DEFINITIONS"), + language.c_str()); + { + std::string defPropName = "COMPILE_DEFINITIONS_"; + defPropName += cmSystemTools::UpperCase(this->GetConfigName()); + this->LocalGenerator->AppendDefines + (defines, + this->Makefile->GetProperty(defPropName.c_str()), + language.c_str()); + this->LocalGenerator->AppendDefines + (defines, + this->Target->GetProperty(defPropName.c_str()), + language.c_str()); + this->LocalGenerator->AppendDefines + (defines, + source->GetProperty(defPropName.c_str()), + language.c_str()); + } + + return defines; +} + +cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const +{ + // Static libraries never depend on other targets for linking. + if (this->Target->GetType() == cmTarget::STATIC_LIBRARY || + this->Target->GetType() == cmTarget::OBJECT_LIBRARY) + return cmNinjaDeps(); + + cmComputeLinkInformation* cli = + this->Target->GetLinkInformation(this->GetConfigName()); + if(!cli) + return cmNinjaDeps(); + + const std::vector &deps = cli->GetDepends(); + cmNinjaDeps result(deps.size()); + std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath()); + + // Add a dependency on the link definitions file, if any. + if(!this->ModuleDefinitionFile.empty()) + { + result.push_back(this->ModuleDefinitionFile); + } + + return result; +} + +std::string +cmNinjaTargetGenerator +::GetSourceFilePath(cmSourceFile* source) const +{ + return ConvertToNinjaPath(source->GetFullPath().c_str()); +} + +std::string +cmNinjaTargetGenerator +::GetObjectFilePath(cmSourceFile* source) const +{ + std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); + if(!path.empty()) + path += "/"; + std::string const& objectName = this->GeneratorTarget->Objects[source]; + path += this->LocalGenerator->GetTargetDirectory(*this->Target); + path += "/"; + path += objectName; + return path; +} + +std::string cmNinjaTargetGenerator::GetTargetOutputDir() const +{ + std::string dir = this->Target->GetDirectory(this->GetConfigName()); + return ConvertToNinjaPath(dir.c_str()); +} + +std::string +cmNinjaTargetGenerator +::GetTargetFilePath(const std::string& name) const +{ + std::string path = this->GetTargetOutputDir(); + if (path.empty() || path == ".") + return name; + path += "/"; + path += name; + return path; +} + +std::string cmNinjaTargetGenerator::GetTargetName() const +{ + return this->Target->GetName(); +} + +std::string cmNinjaTargetGenerator::GetTargetPDB() const +{ + std::string targetFullPathPDB; + if(this->Target->GetType() == cmTarget::EXECUTABLE || + this->Target->GetType() == cmTarget::STATIC_LIBRARY || + this->Target->GetType() == cmTarget::SHARED_LIBRARY || + this->Target->GetType() == cmTarget::MODULE_LIBRARY) + { + targetFullPathPDB = this->Target->GetDirectory(this->GetConfigName()); + targetFullPathPDB += "/"; + targetFullPathPDB += this->Target->GetPDBName(this->GetConfigName()); + } + + return ConvertToNinjaPath(targetFullPathPDB.c_str()); +} + + +void +cmNinjaTargetGenerator +::WriteLanguageRules(const std::string& language) +{ + this->GetRulesFileStream() + << "# Rules for language " << language << "\n\n"; + this->WriteCompileRule(language); + this->GetRulesFileStream() << "\n"; +} + +void +cmNinjaTargetGenerator +::WriteCompileRule(const std::string& language) +{ + cmLocalGenerator::RuleVariables vars; + vars.RuleLauncher = "RULE_LAUNCH_COMPILE"; + vars.CMTarget = this->GetTarget(); + std::string lang = language; + vars.Language = lang.c_str(); + vars.Source = "$in"; + vars.Object = "$out"; + std::string flags = "$FLAGS"; + vars.Defines = "$DEFINES"; + vars.TargetPDB = "$TARGET_PDB"; + + std::string depfile; + std::string depfileFlagsName = "CMAKE_DEPFILE_FLAGS_" + language; + const char *depfileFlags = + this->GetMakefile()->GetDefinition(depfileFlagsName.c_str()); + if (depfileFlags) { + std::string depfileFlagsStr = depfileFlags; + depfile = "$out.d"; + cmSystemTools::ReplaceString(depfileFlagsStr, "", + depfile.c_str()); + cmSystemTools::ReplaceString(depfileFlagsStr, "", + "$out"); + cmSystemTools::ReplaceString(depfileFlagsStr, "", + this->GetMakefile()->GetDefinition("CMAKE_C_COMPILER")); + flags += " " + depfileFlagsStr; + } + vars.Flags = flags.c_str(); + + + // Rule for compiling object file. + std::string compileCmdVar = "CMAKE_"; + compileCmdVar += language; + compileCmdVar += "_COMPILE_OBJECT"; + std::string compileCmd = + this->GetMakefile()->GetRequiredDefinition(compileCmdVar.c_str()); + std::vector compileCmds; + cmSystemTools::ExpandListArgument(compileCmd, compileCmds); + + for (std::vector::iterator i = compileCmds.begin(); + i != compileCmds.end(); ++i) + this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); + + std::string cmdLine = + this->GetLocalGenerator()->BuildCommandLine(compileCmds); + + // Write the rule for compiling file of the given language. + std::ostringstream comment; + comment << "Rule for compiling " << language << " files."; + std::ostringstream description; + description << "Building " << language << " object $out"; + this->GetGlobalGenerator()->AddRule(this->LanguageCompilerRule(language), + cmdLine, + description.str(), + comment.str(), + depfile); +} + +void +cmNinjaTargetGenerator +::WriteObjectBuildStatements() +{ + // Write comments. + cmGlobalNinjaGenerator::WriteDivider(this->GetBuildFileStream()); + this->GetBuildFileStream() + << "# Object build statements for " + << cmTarget::GetTargetTypeName(this->GetTarget()->GetType()) + << " target " + << this->GetTargetName() + << "\n\n"; + + for(std::vector::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) + { + cmCustomCommand const* cc = (*si)->GetCustomCommand(); + this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); + } + // TODO: this->GeneratorTarget->OSXContent + for(std::vector::const_iterator + si = this->GeneratorTarget->ExternalObjects.begin(); + si != this->GeneratorTarget->ExternalObjects.end(); ++si) + { + this->Objects.push_back(this->GetSourceFilePath(*si)); + } + for(std::vector::const_iterator + si = this->GeneratorTarget->ObjectSources.begin(); + si != this->GeneratorTarget->ObjectSources.end(); ++si) + { + this->WriteObjectBuildStatement(*si); + } + if(!this->GeneratorTarget->ModuleDefinitionFile.empty()) + { + this->ModuleDefinitionFile = this->ConvertToNinjaPath( + this->GeneratorTarget->ModuleDefinitionFile.c_str()); + } + + { + // Add object library contents as external objects. + std::vector objs; + this->GeneratorTarget->UseObjectLibraries(objs); + for(std::vector::iterator oi = objs.begin(); + oi != objs.end(); ++oi) + { + this->Objects.push_back(ConvertToNinjaPath(oi->c_str())); + } + } + + this->GetBuildFileStream() << "\n"; +} + +void +cmNinjaTargetGenerator +::WriteObjectBuildStatement(cmSourceFile* source) +{ + cmNinjaDeps emptyDeps; + + std::string comment; + const char* language = source->GetLanguage(); + std::string rule = this->LanguageCompilerRule(language); + + cmNinjaDeps outputs; + std::string objectFileName = this->GetObjectFilePath(source); + outputs.push_back(objectFileName); + // Add this object to the list of object files. + this->Objects.push_back(objectFileName); + + cmNinjaDeps explicitDeps; + std::string sourceFileName = this->GetSourceFilePath(source); + explicitDeps.push_back(sourceFileName); + + // Ensure that the target dependencies are built before any source file in + // the target, using order-only dependencies. + cmNinjaDeps orderOnlyDeps; + this->GetLocalGenerator()->AppendTargetDepends(this->Target, orderOnlyDeps); + + if(const char* objectDeps = source->GetProperty("OBJECT_DEPENDS")) { + std::vector depList; + cmSystemTools::ExpandListArgument(objectDeps, depList); + std::transform(depList.begin(), depList.end(), + std::back_inserter(orderOnlyDeps), MapToNinjaPath()); + } + + // Add order-only dependencies on custom command outputs. + for(std::vector::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) + { + cmCustomCommand const* cc = (*si)->GetCustomCommand(); + const std::vector& ccoutputs = cc->GetOutputs(); + std::transform(ccoutputs.begin(), ccoutputs.end(), + std::back_inserter(orderOnlyDeps), MapToNinjaPath()); + } + + // If the source file is GENERATED and does not have a custom command + // (either attached to this source file or another one), assume that one of + // the target dependencies, OBJECT_DEPENDS or header file custom commands + // will rebuild the file. + if (source->GetPropertyAsBool("GENERATED") && !source->GetCustomCommand() && + !this->GetGlobalGenerator()->HasCustomCommandOutput(sourceFileName)) { + this->GetGlobalGenerator()->AddAssumedSourceDependencies(sourceFileName, + orderOnlyDeps); + } + + cmNinjaVars vars; + vars["FLAGS"] = this->ComputeFlagsForObject(source, language); + vars["DEFINES"] = this->ComputeDefines(source, language); + vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + + cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), + comment, + rule, + outputs, + explicitDeps, + emptyDeps, + orderOnlyDeps, + vars); + + if(const char* objectOutputs = source->GetProperty("OBJECT_OUTPUTS")) { + std::vector outputList; + cmSystemTools::ExpandListArgument(objectOutputs, outputList); + std::transform(outputList.begin(), outputList.end(), outputList.begin(), + MapToNinjaPath()); + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "Additional output files.", + outputList, + outputs); + } +} + +//---------------------------------------------------------------------------- +void +cmNinjaTargetGenerator +::AddModuleDefinitionFlag(std::string& flags) +{ + if(this->ModuleDefinitionFile.empty()) + { + return; + } + + // TODO: Create a per-language flag variable. + const char* defFileFlag = + this->Makefile->GetDefinition("CMAKE_LINK_DEF_FILE_FLAG"); + if(!defFileFlag) + { + return; + } + + // Append the flag and value. Use ConvertToLinkReference to help + // vs6's "cl -link" pass it to the linker. + std::string flag = defFileFlag; + flag += (this->LocalGenerator->ConvertToLinkReference( + this->ModuleDefinitionFile.c_str())); + this->LocalGenerator->AppendFlags(flags, flag.c_str()); +} diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h new file mode 100644 index 000000000..b64ce1e1e --- /dev/null +++ b/Source/cmNinjaTargetGenerator.h @@ -0,0 +1,126 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmNinjaTargetGenerator_h +#define cmNinjaTargetGenerator_h + +#include "cmStandardIncludes.h" +#include "cmNinjaTypes.h" +#include "cmLocalNinjaGenerator.h" + +class cmTarget; +class cmGlobalNinjaGenerator; +class cmGeneratedFileStream; +class cmGeneratorTarget; +class cmMakefile; +class cmSourceFile; +class cmCustomCommand; + +class cmNinjaTargetGenerator +{ +public: + /// Create a cmNinjaTargetGenerator according to the @a target's type. + static cmNinjaTargetGenerator* New(cmTarget* target); + + /// Build a NinjaTargetGenerator. + cmNinjaTargetGenerator(cmTarget* target); + + /// Destructor. + virtual ~cmNinjaTargetGenerator(); + + virtual void Generate() = 0; + + std::string GetTargetPDB() const; + std::string GetTargetName() const; + +protected: + cmGeneratedFileStream& GetBuildFileStream() const; + cmGeneratedFileStream& GetRulesFileStream() const; + + cmTarget* GetTarget() const + { return this->Target; } + + cmLocalNinjaGenerator* GetLocalGenerator() const + { return this->LocalGenerator; } + + cmGlobalNinjaGenerator* GetGlobalGenerator() const; + + cmMakefile* GetMakefile() const + { return this->Makefile; } + + const char* GetConfigName() const; + + std::string LanguageCompilerRule(const std::string& lang) const + { return lang + "_COMPILER"; } + + const char* GetFeature(const char* feature); + bool GetFeatureAsBool(const char* feature); + void AddFeatureFlags(std::string& flags, const char* lang); + + /** + * Compute the flags for compilation of object files for a given @a language. + * @note Generally it is the value of the variable whose name is computed + * by LanguageFlagsVarName(). + */ + std::string ComputeFlagsForObject(cmSourceFile *source, + const std::string& language); + + std::string ComputeDefines(cmSourceFile *source, + const std::string& language); + + std::string ConvertToNinjaPath(const char *path) const { + return this->GetLocalGenerator()->ConvertToNinjaPath(path); + } + cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const { + return this->GetLocalGenerator()->MapToNinjaPath(); + } + + /// @return the list of link dependency for the given target @a target. + cmNinjaDeps ComputeLinkDeps() const; + + /// @return the source file path for the given @a source. + std::string GetSourceFilePath(cmSourceFile* source) const; + + /// @return the object file path for the given @a source. + std::string GetObjectFilePath(cmSourceFile* source) const; + + /// @return the file path where the target named @a name is generated. + std::string GetTargetFilePath(const std::string& name) const; + + /// @return the output path for the target. + virtual std::string GetTargetOutputDir() const; + + void WriteLanguageRules(const std::string& language); + void WriteCompileRule(const std::string& language); + void WriteObjectBuildStatements(); + void WriteObjectBuildStatement(cmSourceFile* source); + void WriteCustomCommandBuildStatement(cmCustomCommand *cc); + + cmNinjaDeps GetObjects() const + { return this->Objects; } + + // Helper to add flag for windows .def file. + void AddModuleDefinitionFlag(std::string& flags); + +private: + cmTarget* Target; + cmGeneratorTarget* GeneratorTarget; + cmMakefile* Makefile; + cmLocalNinjaGenerator* LocalGenerator; + /// List of object files for this target. + cmNinjaDeps Objects; + + // The windows module definition source file (.def), if any. + std::string ModuleDefinitionFile; +}; + +#endif // ! cmNinjaTargetGenerator_h diff --git a/Source/cmNinjaTypes.h b/Source/cmNinjaTypes.h new file mode 100644 index 000000000..498f6b639 --- /dev/null +++ b/Source/cmNinjaTypes.h @@ -0,0 +1,19 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmNinjaTypes_h +# define cmNinjaTypes_h + +typedef std::vector cmNinjaDeps; +typedef std::map cmNinjaVars; + +#endif // ! cmNinjaTypes_h diff --git a/Source/cmNinjaUtilityTargetGenerator.cxx b/Source/cmNinjaUtilityTargetGenerator.cxx new file mode 100644 index 000000000..9c2fd13dd --- /dev/null +++ b/Source/cmNinjaUtilityTargetGenerator.cxx @@ -0,0 +1,116 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmNinjaUtilityTargetGenerator.h" +#include "cmCustomCommand.h" +#include "cmGeneratedFileStream.h" +#include "cmGlobalNinjaGenerator.h" +#include "cmMakefile.h" +#include "cmSourceFile.h" +#include "cmTarget.h" + +cmNinjaUtilityTargetGenerator::cmNinjaUtilityTargetGenerator(cmTarget *target) + : cmNinjaTargetGenerator(target) {} + +cmNinjaUtilityTargetGenerator::~cmNinjaUtilityTargetGenerator() {} + +void cmNinjaUtilityTargetGenerator::Generate() +{ + std::vector commands; + cmNinjaDeps deps, outputs; + + const std::vector *cmdLists[2] = { + &this->GetTarget()->GetPreBuildCommands(), + &this->GetTarget()->GetPostBuildCommands() + }; + + for (unsigned i = 0; i != 2; ++i) { + for (std::vector::const_iterator + ci = cmdLists[i]->begin(); ci != cmdLists[i]->end(); ++ci) { + this->GetLocalGenerator()->AppendCustomCommandDeps(&*ci, deps); + this->GetLocalGenerator()->AppendCustomCommandLines(&*ci, commands); + } + } + + const std::vector& sources = + this->GetTarget()->GetSourceFiles(); + for(std::vector::const_iterator source = sources.begin(); + source != sources.end(); ++source) + { + if(cmCustomCommand* cc = (*source)->GetCustomCommand()) + { + this->GetLocalGenerator()->AddCustomCommandTarget(cc, this->GetTarget()); + + // Depend on all custom command outputs. + const std::vector& ccOutputs = cc->GetOutputs(); + std::transform(ccOutputs.begin(), ccOutputs.end(), + std::back_inserter(deps), MapToNinjaPath()); + } + } + + this->GetLocalGenerator()->AppendTargetOutputs(this->GetTarget(), outputs); + this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(), deps); + + if (commands.empty()) { + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "Utility command for " + + this->GetTargetName(), + outputs, + deps); + } else { + std::string command = + this->GetLocalGenerator()->BuildCommandLine(commands); + const char *echoStr = this->GetTarget()->GetProperty("EchoString"); + std::string desc; + if (echoStr) + desc = echoStr; + else + desc = "Running utility command for " + this->GetTargetName(); + + // TODO: fix problematic global targets. For now, search and replace the + // makefile vars. + cmSystemTools::ReplaceString( + command, + "$(CMAKE_SOURCE_DIR)", + this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTarget()->GetMakefile()->GetHomeDirectory(), + cmLocalGenerator::SHELL).c_str()); + cmSystemTools::ReplaceString( + command, + "$(CMAKE_BINARY_DIR)", + this->GetLocalGenerator()->ConvertToOutputFormat( + this->GetTarget()->GetMakefile()->GetHomeOutputDirectory(), + cmLocalGenerator::SHELL).c_str()); + cmSystemTools::ReplaceString(command, "$(ARGS)", ""); + + if (command.find('$') != std::string::npos) + return; + + std::string utilCommandName = cmake::GetCMakeFilesDirectoryPostSlash(); + utilCommandName += this->GetTargetName() + ".util"; + + this->GetGlobalGenerator()->WriteCustomCommandBuild( + command, + desc, + "Utility command for " + this->GetTargetName(), + cmNinjaDeps(1, utilCommandName), + deps); + + cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(), + "", + outputs, + cmNinjaDeps(1, utilCommandName)); + } + + this->GetGlobalGenerator()->AddTargetAlias(this->GetTargetName(), + this->GetTarget()); +} diff --git a/Source/cmNinjaUtilityTargetGenerator.h b/Source/cmNinjaUtilityTargetGenerator.h new file mode 100644 index 000000000..8b82ce49a --- /dev/null +++ b/Source/cmNinjaUtilityTargetGenerator.h @@ -0,0 +1,30 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2011 Peter Collingbourne + Copyright 2011 Nicolas Despres + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmNinjaUtilityTargetGenerator_h +# define cmNinjaUtilityTargetGenerator_h + +# include "cmNinjaTargetGenerator.h" +# include "cmNinjaTypes.h" + +class cmSourceFile; + +class cmNinjaUtilityTargetGenerator : public cmNinjaTargetGenerator +{ +public: + cmNinjaUtilityTargetGenerator(cmTarget* target); + ~cmNinjaUtilityTargetGenerator(); + + void Generate(); +}; + +#endif // ! cmNinjaUtilityTargetGenerator_h diff --git a/Source/cmOptionCommand.h b/Source/cmOptionCommand.h index fa5abd87c..da3133237 100644 --- a/Source/cmOptionCommand.h +++ b/Source/cmOptionCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "option";} + virtual const char* GetName() const {return "option";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Provides an option that the user can optionally select."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " option( \"help string describing option\"\n" @@ -68,7 +68,7 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } cmTypeMacro(cmOptionCommand, cmCommand); }; diff --git a/Source/cmOutputRequiredFilesCommand.h b/Source/cmOutputRequiredFilesCommand.h index 6038472c5..85d9095e2 100644 --- a/Source/cmOutputRequiredFilesCommand.h +++ b/Source/cmOutputRequiredFilesCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "output_required_files";} + virtual const char* GetName() const { return "output_required_files";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Approximate C preprocessor dependency scanning."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "This command exists only because ancient CMake versions provided it. " @@ -67,7 +67,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 2160f37d6..3106248c5 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -21,8 +21,9 @@ class cmPolicy; /** \class cmPolicies * \brief Handles changes in CMake behavior and policies * - * See the cmake wiki section on policies for an overview of this class's - * purpose + * See the cmake wiki section on + * policies + * for an overview of this class's purpose */ class cmPolicies { @@ -30,32 +31,46 @@ public: cmPolicies(); ~cmPolicies(); - enum PolicyStatus { OLD, WARN, NEW, REQUIRED_IF_USED, REQUIRED_ALWAYS }; + /// Status of a policy + enum PolicyStatus { + OLD, ///< Use old behavior + WARN, ///< Use old behavior but issue a warning + NEW, ///< Use new behavior + /// Issue an error if user doesn't set policy status to NEW and hits the + /// check + REQUIRED_IF_USED, + REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW. + }; static const char* PolicyStatusNames[]; + /// Policy identifiers enum PolicyID { - CMP0000, // Policy version specification - CMP0001, // Ignore old compatibility variable - CMP0002, // Target names must be unique - CMP0003, // Linking does not include extra -L paths - CMP0004, // Libraries linked may not have leading or trailing whitespace - CMP0005, // Definition value escaping - CMP0006, // BUNDLE install rules needed for MACOSX_BUNDLE targets - CMP0007, // list command handling of empty elements - CMP0008, // Full-path libraries must be a valid library file name - CMP0009, // GLOB_RECURSE should not follow symlinks by default - CMP0010, // Bad variable reference syntax is an error - CMP0011, // Strong policy scope for include and find_package - CMP0012, // Recognize numbers and boolean constants in if() - CMP0013, // Duplicate binary directories not allowed - CMP0014, // Input directories must have CMakeLists.txt - CMP0015, // link_directories() treats paths relative to source dir - CMP0016, // target_link_libraries() fails if only argument is not a target - CMP0017, // Prefer files in CMAKE_ROOT when including from CMAKE_ROOT - - // Always the last entry. Useful mostly to avoid adding a comma - // the last policy when adding a new one. + CMP0000, ///< Policy version specification + CMP0001, ///< Ignore old compatibility variable + CMP0002, ///< Target names must be unique + CMP0003, ///< Linking does not include extra -L paths + CMP0004, ///< Libraries linked may not have leading or trailing whitespace + CMP0005, ///< Definition value escaping + CMP0006, ///< BUNDLE install rules needed for MACOSX_BUNDLE targets + CMP0007, ///< list command handling of empty elements + CMP0008, ///< Full-path libraries must be a valid library file name + CMP0009, ///< GLOB_RECURSE should not follow symlinks by default + CMP0010, ///< Bad variable reference syntax is an error + CMP0011, ///< Strong policy scope for include and find_package + CMP0012, ///< Recognize numbers and boolean constants in if() + CMP0013, ///< Duplicate binary directories not allowed + CMP0014, ///< Input directories must have CMakeLists.txt + CMP0015, ///< link_directories() treats paths relative to source dir + /// target_link_libraries() fails if only argument is not a target + CMP0016, + CMP0017, ///< Prefer files in CMAKE_ROOT when including from CMAKE_ROOT + + /** \brief Always the last entry. + * + * Useful mostly to avoid adding a comma the last policy when adding a new + * one. + */ CMPCOUNT }; diff --git a/Source/cmProjectCommand.cxx b/Source/cmProjectCommand.cxx index 6e3b6afec..fcf0a4903 100644 --- a/Source/cmProjectCommand.cxx +++ b/Source/cmProjectCommand.cxx @@ -77,6 +77,24 @@ bool cmProjectCommand languages.push_back("CXX"); } this->Makefile->EnableLanguage(languages, false); + std::string extraInclude = "CMAKE_PROJECT_" + args[0] + "_INCLUDE"; + const char* include = this->Makefile->GetDefinition(extraInclude.c_str()); + if(include) + { + std::string fullFilePath; + bool readit = + this->Makefile->ReadListFile( this->Makefile->GetCurrentListFile(), + include); + if(!readit && !cmSystemTools::GetFatalErrorOccured()) + { + std::string m = + "could not find file:\n" + " "; + m += include; + this->SetError(m.c_str()); + return false; + } + } return true; } diff --git a/Source/cmProjectCommand.h b/Source/cmProjectCommand.h index fc2b7a2bd..4b051afee 100644 --- a/Source/cmProjectCommand.h +++ b/Source/cmProjectCommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "project";} + virtual const char* GetName() const {return "project";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set a name for the entire project."; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " project( [languageName1 languageName2 ... ] )\n" @@ -68,7 +68,10 @@ public: "By default C and CXX are enabled. E.g. if you do not have a " "C++ compiler, you can disable the check for it by explicitly listing " "the languages you want to support, e.g. C. By using the special " - "language \"NONE\" all checks for any language can be disabled."; + "language \"NONE\" all checks for any language can be disabled. " + "If a variable exists called CMAKE_PROJECT__INCLUDE_FILE, " + "the file pointed to by that variable will be included as the last step " + "of the project command."; } cmTypeMacro(cmProjectCommand, cmCommand); diff --git a/Source/cmPropertyDefinition.h b/Source/cmPropertyDefinition.h index f68db87f6..16bd148a7 100644 --- a/Source/cmPropertyDefinition.h +++ b/Source/cmPropertyDefinition.h @@ -14,45 +14,56 @@ #include "cmProperty.h" -class cmPropertyDefinition +/** \class cmPropertyDefinition + * \brief Property meta-information + * + * This class contains the following meta-information about property: + * - Name; + * - Various documentation strings; + * - The scope of the property; + * - If the property is chained. + */ +class cmPropertyDefinition { public: - // Define this property + /// Define this property void DefineProperty(const char *name, cmProperty::ScopeType scope, const char *ShortDescription, const char *FullDescription, const char *DocumentationSection, bool chained); - // get the documentation string + /// Get the documentation string cmDocumentationEntry GetDocumentation() const; - // basic constructor + /// Default constructor cmPropertyDefinition() { this->Chained = false; }; - // is it chained? - bool IsChained() {return this->Chained; }; + /// Is the property chained? + bool IsChained() const { return this->Chained; }; - // Get the section if any + /// Get the section if any const std::string &GetDocumentationSection() const { return this->DocumentationSection; }; - - // get the scope + + /// Get the scope cmProperty::ScopeType GetScope() const { return this->Scope; }; - // get the docs + /// Get the documentation (short version) const std::string &GetShortDescription() const { - return this->ShortDescription; }; + return this->ShortDescription; }; + + /// Get the documentation (full version) const std::string &GetFullDescription() const { return this->FullDescription; }; - + protected: std::string Name; std::string ShortDescription; std::string FullDescription; std::string DocumentationSection; - cmProperty::ScopeType Scope; + cmProperty::ScopeType Scope; bool Chained; }; diff --git a/Source/cmQTWrapCPPCommand.h b/Source/cmQTWrapCPPCommand.h index f972e1058..0184927c9 100644 --- a/Source/cmQTWrapCPPCommand.h +++ b/Source/cmQTWrapCPPCommand.h @@ -45,12 +45,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "qt_wrap_cpp";} + virtual const char* GetName() const { return "qt_wrap_cpp";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Create Qt Wrappers."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " qt_wrap_cpp(resultingLibraryName DestName\n" diff --git a/Source/cmQTWrapUICommand.h b/Source/cmQTWrapUICommand.h index 67e914f80..744ae9838 100644 --- a/Source/cmQTWrapUICommand.h +++ b/Source/cmQTWrapUICommand.h @@ -43,12 +43,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "qt_wrap_ui";} + virtual const char* GetName() const { return "qt_wrap_ui";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Create Qt user interfaces Wrappers."; } @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " qt_wrap_ui(resultingLibraryName HeadersDestName\n" diff --git a/Source/cmQtAutomoc.cxx b/Source/cmQtAutomoc.cxx index 0d0d80cff..ca27530fb 100644 --- a/Source/cmQtAutomoc.cxx +++ b/Source/cmQtAutomoc.cxx @@ -20,6 +20,9 @@ #include #include +#if defined(__APPLE__) +#include +#endif #include "cmQtAutomoc.h" @@ -202,13 +205,20 @@ void cmQtAutomoc::SetupAutomocTarget(cmTarget* target) cmMakefile::ScopePushPop varScope(makefile); static_cast(varScope); - makefile->AddDefinition("_moc_target_name", automocTargetName.c_str()); - makefile->AddDefinition("_moc_incs", _moc_incs.c_str()); - makefile->AddDefinition("_moc_defs", _moc_defs.c_str()); - makefile->AddDefinition("_moc_compile_defs", _moc_compile_defs.c_str()); - makefile->AddDefinition("_moc_options", _moc_options.c_str()); - makefile->AddDefinition("_moc_files", _moc_files.c_str()); - makefile->AddDefinition("_moc_headers", _moc_headers.c_str()); + makefile->AddDefinition("_moc_target_name", + cmLocalGenerator::EscapeForCMake(automocTargetName.c_str()).c_str()); + makefile->AddDefinition("_moc_incs", + cmLocalGenerator::EscapeForCMake(_moc_incs.c_str()).c_str()); + makefile->AddDefinition("_moc_defs", + cmLocalGenerator::EscapeForCMake(_moc_defs.c_str()).c_str()); + makefile->AddDefinition("_moc_compile_defs", + cmLocalGenerator::EscapeForCMake(_moc_compile_defs.c_str()).c_str()); + makefile->AddDefinition("_moc_options", + cmLocalGenerator::EscapeForCMake(_moc_options.c_str()).c_str()); + makefile->AddDefinition("_moc_files", + cmLocalGenerator::EscapeForCMake(_moc_files.c_str()).c_str()); + makefile->AddDefinition("_moc_headers", + cmLocalGenerator::EscapeForCMake(_moc_headers.c_str()).c_str()); makefile->AddDefinition("_moc_relaxed_mode", relaxedMode ? "TRUE" : "FALSE"); const char* cmakeRoot = makefile->GetSafeDefinition("CMAKE_ROOT"); @@ -340,8 +350,9 @@ void cmQtAutomoc::WriteOldMocDefinitionsFile(const char* targetDirectory) std::fstream outfile; outfile.open(filename.c_str(), std::ios::out | std::ios::trunc); - outfile << "set(AM_OLD_MOC_DEFINITIONS \"" - << this->Join(this->MocDefinitions, ' ') << "\")\n"; + outfile << "set(AM_OLD_MOC_DEFINITIONS " + << cmLocalGenerator::EscapeForCMake( + this->Join(this->MocDefinitions, ' ').c_str()) << ")\n"; outfile.close(); } diff --git a/Source/cmRemoveCommand.h b/Source/cmRemoveCommand.h index bae2ee13f..c62d58f64 100644 --- a/Source/cmRemoveCommand.h +++ b/Source/cmRemoveCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "remove";} + virtual const char* GetName() const {return "remove";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the list(REMOVE_ITEM ) command instead."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " remove(VAR VALUE VALUE ...)\n" @@ -68,7 +68,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmRemoveDefinitionsCommand.h b/Source/cmRemoveDefinitionsCommand.h index 519bc42db..f0e906d15 100644 --- a/Source/cmRemoveDefinitionsCommand.h +++ b/Source/cmRemoveDefinitionsCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "remove_definitions";} + virtual const char* GetName() const {return "remove_definitions";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Removes -D define flags added by add_definitions."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " remove_definitions(-DFOO -DBAR ...)\n" diff --git a/Source/cmReturnCommand.h b/Source/cmReturnCommand.h index 3739e8386..690ab79ca 100644 --- a/Source/cmReturnCommand.h +++ b/Source/cmReturnCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "return";} + virtual const char* GetName() const {return "return";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Return from a file, directory or function."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " return()\n" diff --git a/Source/cmSeparateArgumentsCommand.h b/Source/cmSeparateArgumentsCommand.h index 736f0662c..6a51a9223 100644 --- a/Source/cmSeparateArgumentsCommand.h +++ b/Source/cmSeparateArgumentsCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "separate_arguments";} + virtual const char* GetName() const {return "separate_arguments";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Parse space-separated arguments into a semicolon-separated list."; @@ -59,7 +59,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " separate_arguments( _COMMAND \"\")\n" diff --git a/Source/cmSetCommand.h b/Source/cmSetCommand.h index 2990d241a..66b129e32 100644 --- a/Source/cmSetCommand.h +++ b/Source/cmSetCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "set";} + virtual const char* GetName() const {return "set";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set a CMAKE variable to a given value."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " set( \n" diff --git a/Source/cmSetDirectoryPropertiesCommand.h b/Source/cmSetDirectoryPropertiesCommand.h index 227571fa2..ee401582a 100644 --- a/Source/cmSetDirectoryPropertiesCommand.h +++ b/Source/cmSetDirectoryPropertiesCommand.h @@ -32,17 +32,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "set_directory_properties";} + virtual const char* GetName() const { return "set_directory_properties";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set a property of the directory."; } @@ -58,7 +58,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " set_directory_properties(PROPERTIES prop1 value1 prop2 value2)\n" diff --git a/Source/cmSetPropertyCommand.h b/Source/cmSetPropertyCommand.h index 3a0169ed6..830299d46 100644 --- a/Source/cmSetPropertyCommand.h +++ b/Source/cmSetPropertyCommand.h @@ -34,12 +34,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "set_property";} + virtual const char* GetName() const { return "set_property";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Set a named property in a given scope."; } @@ -47,7 +47,7 @@ public: /** * Longer documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " set_property( Depends; }; +// TODO: Factor out into platform information modules. +#define CM_HEADER_REGEX "\\.(h|hh|h\\+\\+|hm|hpp|hxx|in|txx|inl)$" + #endif diff --git a/Source/cmSourceGroup.cxx b/Source/cmSourceGroup.cxx index 19ae8fc35..2b34f2bfc 100644 --- a/Source/cmSourceGroup.cxx +++ b/Source/cmSourceGroup.cxx @@ -119,12 +119,6 @@ const std::vector& cmSourceGroup::GetSourceFiles() const return this->SourceFiles; } -//---------------------------------------------------------------------------- -std::vector& cmSourceGroup::GetSourceFiles() -{ - return this->SourceFiles; -} - //---------------------------------------------------------------------------- void cmSourceGroup::AddChild(cmSourceGroup child) { diff --git a/Source/cmSourceGroup.h b/Source/cmSourceGroup.h index 71ccb513e..641dcbd57 100644 --- a/Source/cmSourceGroup.h +++ b/Source/cmSourceGroup.h @@ -100,7 +100,6 @@ public: * source group. */ const std::vector& GetSourceFiles() const; - std::vector& GetSourceFiles(); std::vector const& GetGroupChildren() const; private: diff --git a/Source/cmSourceGroupCommand.h b/Source/cmSourceGroupCommand.h index 31508cee5..6a29fc810 100644 --- a/Source/cmSourceGroupCommand.h +++ b/Source/cmSourceGroupCommand.h @@ -41,12 +41,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "source_group";} + virtual const char* GetName() const {return "source_group";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Define a grouping for sources in the makefile."; } @@ -54,7 +54,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " source_group(name [REGULAR_EXPRESSION regex] " diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h index 452f4a1bd..3e585a5b3 100644 --- a/Source/cmStringCommand.h +++ b/Source/cmStringCommand.h @@ -45,17 +45,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "string";} + virtual const char* GetName() const { return "string";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "String operations."; } @@ -63,7 +63,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " string(REGEX MATCH \n" diff --git a/Source/cmSubdirCommand.h b/Source/cmSubdirCommand.h index 3dad67d13..eedbfff92 100644 --- a/Source/cmSubdirCommand.h +++ b/Source/cmSubdirCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "subdirs";} + virtual const char* GetName() const { return "subdirs";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the add_subdirectory() command instead."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "Add a list of subdirectories to the build.\n" @@ -79,7 +79,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmSubdirDependsCommand.h b/Source/cmSubdirDependsCommand.h index 347f97a9d..daf97cd2f 100644 --- a/Source/cmSubdirDependsCommand.h +++ b/Source/cmSubdirDependsCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "subdir_depends";} + virtual const char* GetName() const { return "subdir_depends";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Does nothing."; } @@ -55,7 +55,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " subdir_depends(subdir dep1 dep2 ...)\n" @@ -64,7 +64,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 8eec1e2af..1376a485b 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -131,6 +131,8 @@ void (*cmSystemTools::s_ErrorCallback)(const char*, const char*, void (*cmSystemTools::s_StdoutCallback)(const char*, int len, void*); void* cmSystemTools::s_ErrorCallbackClientData = 0; void* cmSystemTools::s_StdoutCallbackClientData = 0; +bool (*cmSystemTools::s_InterruptCallback)(void*); +void* cmSystemTools::s_InterruptCallbackClientData = 0; // replace replace with with as many times as it shows up in source. // write the result into source. @@ -196,6 +198,20 @@ std::string cmSystemTools::EscapeQuotes(const char* str) return result; } +std::string cmSystemTools::TrimWhitespace(const std::string& s) +{ + std::string::const_iterator start = s.begin(); + while(start != s.end() && *start == ' ') + ++start; + if (start == s.end()) + return ""; + + std::string::const_iterator stop = s.end()-1; + while(*stop == ' ') + --stop; + return std::string(start, stop+1); +} + void cmSystemTools::Error(const char* m1, const char* m2, const char* m3, const char* m4) { @@ -220,6 +236,20 @@ void cmSystemTools::Error(const char* m1, const char* m2, cmSystemTools::Message(message.c_str(),"Error"); } +void cmSystemTools::SetInterruptCallback(InterruptCallback f, void* clientData) +{ + s_InterruptCallback = f; + s_InterruptCallbackClientData = clientData; +} + +bool cmSystemTools::GetInterruptFlag() +{ + if(s_InterruptCallback) + { + return (*s_InterruptCallback)(s_InterruptCallbackClientData); + } + return false; +} void cmSystemTools::SetErrorCallback(ErrorCallback f, void* clientData) { @@ -1866,7 +1896,11 @@ long copy_data(struct archive *ar, struct archive *aw) long r; const void *buff; size_t size; +#if defined(ARCHIVE_VERSION_NUMBER) && ARCHIVE_VERSION_NUMBER >= 3000000 + __LA_INT64_T offset; +#else off_t offset; +#endif for (;;) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 641c89fae..5f21de2d2 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -30,8 +30,8 @@ class cmSystemTools: public cmsys::SystemTools public: typedef cmsys::SystemTools Superclass; - /** Expand out any arguements in the vector that have ; separated - * strings into multiple arguements. A new vector is created + /** Expand out any arguments in the vector that have ; separated + * strings into multiple arguments. A new vector is created * containing the expanded versions of all arguments in argsIn. */ static void ExpandList(std::vector const& argsIn, @@ -49,6 +49,11 @@ public: ///! Escape quotes in a string. static std::string EscapeQuotes(const char* str); + /** + * Returns a string that has whitespace removed from the start and the end. + */ + static std::string TrimWhitespace(const std::string& s); + typedef void (*ErrorCallback)(const char*, const char*, bool&, void*); /** * Set the function used by GUI's to display error messages @@ -78,6 +83,11 @@ public: ///! Send a string to stderr. Stdout callbacks will not be invoced. static void Stderr(const char* s, int length); + + typedef bool (*InterruptCallback)(void*); + static void SetInterruptCallback(InterruptCallback f, void* clientData=0); + static bool GetInterruptFlag(); + ///! Return true if there was an error at any point. static bool GetErrorOccuredFlag() { @@ -96,7 +106,7 @@ public: ///! Return true if there was an error at any point. static bool GetFatalErrorOccured() { - return cmSystemTools::s_FatalErrorOccured; + return cmSystemTools::s_FatalErrorOccured || GetInterruptFlag(); } ///! Set the error occured flag and fatal error back to false @@ -467,8 +477,10 @@ private: static bool s_DisableRunCommandOutput; static ErrorCallback s_ErrorCallback; static StdoutCallback s_StdoutCallback; + static InterruptCallback s_InterruptCallback; static void* s_ErrorCallbackClientData; static void* s_StdoutCallbackClientData; + static void* s_InterruptCallbackClientData; static std::string s_Windows9xComspecSubstitute; }; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 6a937b8d3..cfa99764b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -37,18 +37,14 @@ const char* cmTarget::GetTargetTypeName(TargetType targetType) return "MODULE_LIBRARY"; case cmTarget::SHARED_LIBRARY: return "SHARED_LIBRARY"; + case cmTarget::OBJECT_LIBRARY: + return "OBJECT_LIBRARY"; case cmTarget::EXECUTABLE: return "EXECUTABLE"; case cmTarget::UTILITY: return "UTILITY"; case cmTarget::GLOBAL_TARGET: return "GLOBAL_TARGET"; - case cmTarget::INSTALL_FILES: - return "INSTALL_FILES"; - case cmTarget::INSTALL_PROGRAMS: - return "INSTALL_PROGRAMS"; - case cmTarget::INSTALL_DIRECTORY: - return "INSTALL_DIRECTORY"; case cmTarget::UNKNOWN_LIBRARY: return "UNKNOWN_LIBRARY"; } @@ -323,7 +319,8 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET, "Configurations provided for an IMPORTED target.", - "Lists configuration names available for an IMPORTED target. " + "Set this to the list of configuration names available for an " + "IMPORTED target. " "The names correspond to configurations defined in the project from " "which the target is imported. " "If the importing project uses a different set of configurations " @@ -334,14 +331,12 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_IMPLIB", cmProperty::TARGET, "Full path to the import library for an IMPORTED target.", - "Specifies the location of the \".lib\" part of a windows DLL. " + "Set this to the location of the \".lib\" part of a windows DLL. " "Ignored for non-imported targets."); cm->DefineProperty ("IMPORTED_IMPLIB_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_IMPLIB property.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_IMPLIB property.", "Configuration names correspond to those provided by the project " "from which the target is imported."); @@ -351,8 +346,10 @@ void cmTarget::DefineProperties(cmake *cm) "Shared libraries may be linked to other shared libraries as part " "of their implementation. On some platforms the linker searches " "for the dependent libraries of shared libraries they are including " - "in the link. This property lists " - "the dependent shared libraries of an imported library. The list " + "in the link. " + "Set this property to the list of dependent shared libraries of an " + "imported library. " + "The list " "should be disjoint from the list of interface libraries in the " "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring " "dependent shared libraries to be found at link time CMake uses this " @@ -361,9 +358,7 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_LINK_DEPENDENT_LIBRARIES_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_LINK_DEPENDENT_LIBRARIES.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.", "Configuration names correspond to those provided by the project " "from which the target is imported. " "If set, this property completely overrides the generic property " @@ -372,8 +367,8 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET, "Transitive link interface of an IMPORTED target.", - "Lists libraries whose interface is included when an IMPORTED library " - "target is linked to another target. " + "Set this to the list of libraries whose interface is included when " + "an IMPORTED library target is linked to another target. " "The libraries will be included on the link line for the target. " "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies " "to all imported target types, including STATIC libraries. " @@ -381,9 +376,7 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_LINK_INTERFACE_LIBRARIES_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_LINK_INTERFACE_LIBRARIES.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.", "Configuration names correspond to those provided by the project " "from which the target is imported. " "If set, this property completely overrides the generic property " @@ -392,8 +385,8 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET, "Languages compiled into an IMPORTED static library.", - "Lists languages of soure files compiled to produce a STATIC IMPORTED " - "library (such as \"C\" or \"CXX\"). " + "Set this to the list of languages of source files compiled to " + "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). " "CMake accounts for these languages when computing how to link a " "target to the imported library. " "For example, when a C executable links to an imported C++ static " @@ -405,9 +398,7 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_LINK_INTERFACE_LANGUAGES_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_LINK_INTERFACE_LANGUAGES.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.", "Configuration names correspond to those provided by the project " "from which the target is imported. " "If set, this property completely overrides the generic property " @@ -419,16 +410,14 @@ void cmTarget::DefineProperties(cmake *cm) "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets."); cm->DefineProperty ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_", cmProperty::TARGET, - "Per-configuration repetition count for cycles of IMPORTED archives.", - "This is the configuration-specific version of " - "IMPORTED_LINK_INTERFACE_MULTIPLICITY. " + "-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.", "If set, this property completely overrides the generic property " "for the named configuration."); cm->DefineProperty ("IMPORTED_LOCATION", cmProperty::TARGET, "Full path to the main file on disk for an IMPORTED target.", - "Specifies the location of an IMPORTED target file on disk. " + "Set this to the location of an IMPORTED target file on disk. " "For executables this is the location of the executable file. " "For bundles on OS X this is the location of the executable file " "inside Contents/MacOS under the application bundle folder. " @@ -440,28 +429,29 @@ void cmTarget::DefineProperties(cmake *cm) "symlink just inside the framework folder. " "For DLLs this is the location of the \".dll\" part of the library. " "For UNKNOWN libraries this is the location of the file to be linked. " - "Ignored for non-imported targets."); + "Ignored for non-imported targets." + "\n" + "Projects may skip IMPORTED_LOCATION if the configuration-specific " + "property IMPORTED_LOCATION_ is set. " + "To get the location of an imported target read one of the " + "LOCATION or LOCATION_ properties."); cm->DefineProperty ("IMPORTED_LOCATION_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_LOCATION property.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_LOCATION property.", "Configuration names correspond to those provided by the project " "from which the target is imported."); cm->DefineProperty ("IMPORTED_SONAME", cmProperty::TARGET, "The \"soname\" of an IMPORTED target of shared library type.", - "Specifies the \"soname\" embedded in an imported shared library. " + "Set this to the \"soname\" embedded in an imported shared library. " "This is meaningful only on platforms supporting the feature. " "Ignored for non-imported targets."); cm->DefineProperty ("IMPORTED_SONAME_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_SONAME property.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_SONAME property.", "Configuration names correspond to those provided by the project " "from which the target is imported."); @@ -477,9 +467,7 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("IMPORTED_NO_SONAME_", cmProperty::TARGET, - "Per-configuration version of IMPORTED_NO_SONAME property.", - "This property is used when loading settings for the " - "configuration of an imported target. " + "-specific version of IMPORTED_NO_SONAME property.", "Configuration names correspond to those provided by the project " "from which the target is imported."); @@ -493,6 +481,26 @@ void cmTarget::DefineProperties(cmake *cm) "Installing a target with EXCLUDE_FROM_ALL set to true has " "undefined behavior."); + cm->DefineProperty + ("INCLUDE_DIRECTORIES", cmProperty::TARGET, + "List of preprocessor include file search directories.", + "This property specifies the list of directories given " + "so far to the include_directories command. " + "This property exists on directories and targets. " + "In addition to accepting values from the include_directories " + "command, values may be set directly on any directory or any " + "target using the set_property command. " + "A target gets its initial value for this property from the value " + "of the directory property. " + "A directory gets its initial value from its parent directory if " + "it has one. " + "Both directory and target property values are adjusted by calls " + "to the include_directories command." + "\n" + "The target property values are used by the generators to set " + "the include paths for the compiler. " + "See also the include_directories command."); + cm->DefineProperty ("INSTALL_NAME_DIR", cmProperty::TARGET, "Mac OSX directory name for installed targets.", @@ -685,8 +693,8 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("MAP_IMPORTED_CONFIG_", cmProperty::TARGET, "Map from project configuration to IMPORTED target's configuration.", - "List configurations of an imported target that may be used for " - "the current project's configuration. " + "Set this to the list of configurations of an imported target that " + "may be used for the current project's configuration. " "Targets imported from another project may not provide the same set " "of configuration names available in the current project. " "Setting this property tells CMake what imported configurations are " @@ -839,9 +847,10 @@ void cmTarget::DefineProperties(cmake *cm) cm->DefineProperty ("SUFFIX", cmProperty::TARGET, - "What comes after the library name.", + "What comes after the target name.", "A target property that can be set to override the suffix " - "(such as \".so\") on a library name."); + "(such as \".so\" or \".exe\") on the name of a library, module or " + "executable."); cm->DefineProperty ("TYPE", cmProperty::TARGET, @@ -875,7 +884,9 @@ void cmTarget::DefineProperties(cmake *cm) "of of just main()." "This makes it a GUI executable instead of a console application. " "See the CMAKE_MFC_FLAG variable documentation to configure use " - "of MFC for WinMain executables."); + "of MFC for WinMain executables. " + "This property is initialized by the value of the variable " + "CMAKE_WIN32_EXECUTABLE if it is set when a target is created."); cm->DefineProperty ("MACOSX_BUNDLE", cmProperty::TARGET, @@ -885,7 +896,9 @@ void cmTarget::DefineProperties(cmake *cm) "This makes it a GUI executable that can be launched from " "the Finder. " "See the MACOSX_BUNDLE_INFO_PLIST target property for information " - "about creation of the Info.plist file for the application bundle."); + "about creation of the Info.plist file for the application bundle. " + "This property is initialized by the value of the variable " + "CMAKE_MACOSX_BUNDLE if it is set when a target is created."); cm->DefineProperty ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET, @@ -972,7 +985,12 @@ void cmTarget::DefineProperties(cmake *cm) "When this property is not set the modules will be placed in the " "build directory corresponding to the target's source directory. " "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target " - "is created its value is used to initialize this property."); + "is created its value is used to initialize this property." + "\n" + "Note that some compilers will automatically search the module output " + "directory for modules USEd during compilation but others will not. " + "If your sources USE modules their location must be specified by " + "INCLUDE_DIRECTORIES regardless of this property."); cm->DefineProperty ("GNUtoMS", cmProperty::TARGET, @@ -1055,10 +1073,10 @@ void cmTarget::DefineProperties(cmake *cm) "Can be set to one or more UUIDs recognized by Visual Studio " "to indicate the type of project. This value is copied " "verbatim into the generated project file. Example for a " - "managed C++ unit testing project: \"" - "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};" - "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\". UUIDs are " - "semicolon-delimited."); + "managed C++ unit testing project:\n" + " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};" + "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n" + "UUIDs are semicolon-delimited."); cm->DefineProperty ("VS_GLOBAL_KEYWORD", cmProperty::TARGET, "Visual Studio project keyword.", @@ -1072,6 +1090,16 @@ void cmTarget::DefineProperties(cmake *cm) "Adds one or more semicolon-delimited .NET references to a " "generated Visual Studio project. For example, \"System;" "System.Windows.Forms\"."); + cm->DefineProperty + ("VS_WINRT_EXTENSIONS", cmProperty::TARGET, + "Visual Studio project C++/CX language extensions for Windows Runtime", + "Can be set to enable C++/CX language extensions."); + cm->DefineProperty + ("VS_WINRT_REFERENCES", cmProperty::TARGET, + "Visual Studio project Windows Runtime Metadata references", + "Adds one or more semicolon-delimited WinRT references to a " + "generated Visual Studio project. For example, \"Windows;" + "Windows.UI.Core\"."); cm->DefineProperty ("VS_GLOBAL_", cmProperty::TARGET, "Visual Studio project-specific global variable.", @@ -1081,17 +1109,6 @@ void cmTarget::DefineProperties(cmake *cm) "better if VS_GLOBAL_QtVersion is set to the version " "FindQt4.cmake found. For example, \"4.7.3\""); -#if 0 - cm->DefineProperty - ("OBJECT_FILES", cmProperty::TARGET, - "Used to get the resulting list of object files that make up a " - "target.", - "This can be used to put object files from one library " - "into another library. It is a read only property. It " - "converts the source list for the target into a list of full " - "paths to object names that will be produced by the target."); -#endif - #define CM_TARGET_FILE_TYPES_DOC \ "There are three kinds of target files that may be built: " \ "archive, library, and runtime. " \ @@ -1182,16 +1199,6 @@ void cmTarget::DefineProperties(cmake *cm) void cmTarget::SetType(TargetType type, const char* name) { this->Name = name; - if(type == cmTarget::INSTALL_FILES || - type == cmTarget::INSTALL_PROGRAMS || - type == cmTarget::INSTALL_DIRECTORY) - { - this->Makefile-> - IssueMessage(cmake::INTERNAL_ERROR, - "SetType called on cmTarget for INSTALL_FILES, " - "INSTALL_PROGRAMS, or INSTALL_DIRECTORY "); - return; - } // only add dependency information for library targets this->TargetTypeValue = type; if(this->TargetTypeValue >= STATIC_LIBRARY @@ -1238,6 +1245,8 @@ void cmTarget::SetMakefile(cmMakefile* mf) this->SetPropertyDefault("AUTOMOC", 0); this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0); this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0); + this->SetPropertyDefault("WIN32_EXECUTABLE", 0); + this->SetPropertyDefault("MACOSX_BUNDLE", 0); // Collect the set of configuration types. std::vector configNames; @@ -1277,6 +1286,11 @@ void cmTarget::SetMakefile(cmMakefile* mf) // Save the backtrace of target construction. this->Makefile->GetBacktrace(this->Internal->Backtrace); + // Initialize the INCLUDE_DIRECTORIES property based on the current value + // of the same directory property: + this->SetProperty("INCLUDE_DIRECTORIES", + this->Makefile->GetProperty("INCLUDE_DIRECTORIES")); + // Record current policies for later use. this->PolicyStatusCMP0003 = this->Makefile->GetPolicyStatus(cmPolicies::CMP0003); @@ -1716,7 +1730,15 @@ void cmTarget::AddSources(std::vector const& srcs) for(std::vector::const_iterator i = srcs.begin(); i != srcs.end(); ++i) { - this->AddSource(i->c_str()); + const char* src = i->c_str(); + if(src[0] == '$' && src[1] == '<') + { + this->ProcessSourceExpression(*i); + } + else + { + this->AddSource(src); + } } } @@ -1734,6 +1756,24 @@ cmSourceFile* cmTarget::AddSource(const char* s) return sf; } +//---------------------------------------------------------------------------- +void cmTarget::ProcessSourceExpression(std::string const& expr) +{ + if(strncmp(expr.c_str(), "$') + { + std::string objLibName = expr.substr(17, expr.size()-18); + this->ObjectLibraries.push_back(objLibName); + } + else + { + cmOStringStream e; + e << "Unrecognized generator expression:\n" + << " " << expr; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + } +} + //---------------------------------------------------------------------------- struct cmTarget::SourceFileFlags cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) @@ -2595,54 +2635,6 @@ const char *cmTarget::GetProperty(const char* prop) return this->GetProperty(prop, cmProperty::TARGET); } -//---------------------------------------------------------------------------- -void cmTarget::ComputeObjectFiles() -{ - if (this->IsImported()) - { - return; - } -#if 0 - std::vector dirs; - this->Makefile->GetLocalGenerator()-> - GetTargetObjectFileDirectories(this, - dirs); - std::string objectFiles; - std::string objExtensionLookup1 = "CMAKE_"; - std::string objExtensionLookup2 = "_OUTPUT_EXTENSION"; - - for(std::vector::iterator d = dirs.begin(); - d != dirs.end(); ++d) - { - for(std::vector::iterator s = this->SourceFiles.begin(); - s != this->SourceFiles.end(); ++s) - { - cmSourceFile* sf = *s; - if(const char* lang = sf->GetLanguage()) - { - std::string lookupObj = objExtensionLookup1 + lang; - lookupObj += objExtensionLookup2; - const char* obj = this->Makefile->GetDefinition(lookupObj.c_str()); - if(obj) - { - if(objectFiles.size()) - { - objectFiles += ";"; - } - std::string objFile = *d; - objFile += "/"; - objFile += this->Makefile->GetLocalGenerator()-> - GetSourceObjectName(*sf); - objFile += obj; - objectFiles += objFile; - } - } - } - } - this->SetProperty("OBJECT_FILES", objectFiles.c_str()); -#endif -} - //---------------------------------------------------------------------------- const char *cmTarget::GetProperty(const char* prop, cmProperty::ScopeType scope) @@ -3600,7 +3592,8 @@ bool cmTarget::HaveBuildTreeRPATH() bool cmTarget::HaveInstallTreeRPATH() { const char* install_rpath = this->GetProperty("INSTALL_RPATH"); - return install_rpath && *install_rpath; + return (install_rpath && *install_rpath) && + !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"); } //---------------------------------------------------------------------------- @@ -3707,7 +3700,8 @@ std::string cmTarget::GetInstallNameDirForInstallTree(const char* config, { std::string dir; - if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH")) + if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") && + !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH")) { const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR"); if(install_name_dir && *install_name_dir) @@ -4580,7 +4574,21 @@ void cmTarget::ComputeLinkImplementation(const char* config, // This target needs runtime libraries for its source languages. std::set languages; + // Get languages used in our source files. this->GetLanguages(languages); + // Get languages used in object library sources. + for(std::vector::iterator i = this->ObjectLibraries.begin(); + i != this->ObjectLibraries.end(); ++i) + { + if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str())) + { + if(objLib->GetType() == cmTarget::OBJECT_LIBRARY) + { + objLib->GetLanguages(languages); + } + } + } + // Copy the set of langauges to the link implementation. for(std::set::iterator li = languages.begin(); li != languages.end(); ++li) { @@ -4673,6 +4681,30 @@ cmTarget::GetLinkInformation(const char* config) return i->second; } +//---------------------------------------------------------------------------- +std::vector cmTarget::GetIncludeDirectories() +{ + std::vector includes; + const char *prop = this->GetProperty("INCLUDE_DIRECTORIES"); + if(prop) + { + cmSystemTools::ExpandListArgument(prop, includes); + } + + std::set uniqueIncludes; + std::vector orderedAndUniqueIncludes; + for(std::vector::const_iterator + li = includes.begin(); li != includes.end(); ++li) + { + if(uniqueIncludes.insert(*li).second) + { + orderedAndUniqueIncludes.push_back(*li); + } + } + + return orderedAndUniqueIncludes; +} + //---------------------------------------------------------------------------- cmTargetLinkInformationMap ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived() diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 59f018483..d41c827a8 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -59,8 +59,8 @@ class cmTarget public: cmTarget(); enum TargetType { EXECUTABLE, STATIC_LIBRARY, - SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, GLOBAL_TARGET, - INSTALL_FILES, INSTALL_PROGRAMS, INSTALL_DIRECTORY, + SHARED_LIBRARY, MODULE_LIBRARY, + OBJECT_LIBRARY, UTILITY, GLOBAL_TARGET, UNKNOWN_LIBRARY}; static const char* GetTargetTypeName(TargetType targetType); enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD }; @@ -117,6 +117,10 @@ public: */ std::vector const& GetSourceFiles(); void AddSourceFile(cmSourceFile* sf); + std::vector const& GetObjectLibraries() const + { + return this->ObjectLibraries; + } /** Get sources that must be built before the given source. */ std::vector const* GetSourceDepends(cmSourceFile* sf); @@ -404,9 +408,6 @@ public: // Define the properties static void DefineProperties(cmake *cm); - // Compute the OBJECT_FILES property only when requested - void ComputeObjectFiles(); - /** Get the macro to define when building sources in this target. If no macro should be defined null is returned. */ const char* GetExportMacro(); @@ -458,6 +459,9 @@ public: directory. */ bool UsesDefaultOutputDir(const char* config, bool implib); + /** Get the include directories for this target. */ + std::vector GetIncludeDirectories(); + private: /** * A list of direct dependencies. Use in conjunction with DependencyMap. @@ -549,6 +553,7 @@ private: std::vector PostBuildCommands; TargetType TargetTypeValue; std::vector SourceFiles; + std::vector ObjectLibraries; LinkLibraryVectorType LinkLibraries; LinkLibraryVectorType PrevLinkedLibraries; bool LinkLibrariesAnalyzed; @@ -590,6 +595,8 @@ private: void MaybeInvalidatePropertyCache(const char* prop); + void ProcessSourceExpression(std::string const& expr); + // The cmMakefile instance that owns this target. This should // always be set. cmMakefile* Makefile; diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 36c4ca8bd..dbea1c3bb 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -84,6 +84,16 @@ bool cmTargetLinkLibrariesCommand return true; } + if(this->Target->GetType() == cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "Object library target \"" << args[0] << "\" " + << "may not link to anything."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + cmSystemTools::SetFatalErrorOccured(); + return true; + } + // but we might not have any libs after variable expansion if(args.size() < 2) { diff --git a/Source/cmTargetLinkLibrariesCommand.h b/Source/cmTargetLinkLibrariesCommand.h index 8df4ac0e8..be866c37f 100644 --- a/Source/cmTargetLinkLibrariesCommand.h +++ b/Source/cmTargetLinkLibrariesCommand.h @@ -42,12 +42,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "target_link_libraries";} + virtual const char* GetName() const { return "target_link_libraries";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Link a target to given libraries."; @@ -56,7 +56,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " target_link_libraries( [item1 [item2 [...]]]\n" diff --git a/Source/cmTryCompileCommand.h b/Source/cmTryCompileCommand.h index 0d57633f7..68ec666ec 100644 --- a/Source/cmTryCompileCommand.h +++ b/Source/cmTryCompileCommand.h @@ -40,19 +40,19 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "try_compile";} + virtual const char* GetName() const { return "try_compile";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Try building some code."; } /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " try_compile(RESULT_VAR \n" diff --git a/Source/cmTryRunCommand.h b/Source/cmTryRunCommand.h index f86d86369..06a9118b6 100644 --- a/Source/cmTryRunCommand.h +++ b/Source/cmTryRunCommand.h @@ -40,12 +40,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "try_run";} + virtual const char* GetName() const { return "try_run";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Try compiling and then running some code."; } @@ -53,7 +53,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR\n" diff --git a/Source/cmUnsetCommand.h b/Source/cmUnsetCommand.h index 28f8cf48b..9cf95d98d 100644 --- a/Source/cmUnsetCommand.h +++ b/Source/cmUnsetCommand.h @@ -40,17 +40,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() {return "unset";} + virtual const char* GetName() const {return "unset";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Unset a variable, cache variable, or environment variable."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " unset( [CACHE])\n" diff --git a/Source/cmUseMangledMesaCommand.h b/Source/cmUseMangledMesaCommand.h index fec2265ed..2f52960c4 100644 --- a/Source/cmUseMangledMesaCommand.h +++ b/Source/cmUseMangledMesaCommand.h @@ -45,12 +45,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "use_mangled_mesa";} + virtual const char* GetName() const { return "use_mangled_mesa";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Copy mesa headers for use in combination with system GL."; } @@ -58,7 +58,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " use_mangled_mesa(PATH_TO_MESA OUTPUT_DIRECTORY)\n" @@ -71,10 +71,10 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmUtilitySourceCommand.h b/Source/cmUtilitySourceCommand.h index 6c23814c4..32afddadc 100644 --- a/Source/cmUtilitySourceCommand.h +++ b/Source/cmUtilitySourceCommand.h @@ -44,12 +44,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "utility_source";} + virtual const char* GetName() const { return "utility_source";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Specify the source tree of a third-party utility."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " utility_source(cache_entry executable_name\n" @@ -76,7 +76,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmVariableRequiresCommand.h b/Source/cmVariableRequiresCommand.h index f165f3947..91c351e60 100644 --- a/Source/cmVariableRequiresCommand.h +++ b/Source/cmVariableRequiresCommand.h @@ -39,12 +39,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "variable_requires";} + virtual const char* GetName() const { return "variable_requires";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the if() command instead."; } @@ -52,7 +52,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return "Assert satisfaction of an option's required variables.\n" @@ -70,7 +70,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h index e2fb934fa..cb80736e6 100644 --- a/Source/cmVariableWatchCommand.h +++ b/Source/cmVariableWatchCommand.h @@ -49,7 +49,7 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** This command does not really have a final pass but it needs to stay alive since it owns variable watch callback information. */ @@ -58,12 +58,12 @@ public: /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "variable_watch";} + virtual const char* GetName() const { return "variable_watch";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Watch the CMake variable for change."; } @@ -71,7 +71,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " variable_watch( [])\n" diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index a219ae923..6caaad1bc 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -11,6 +11,7 @@ ============================================================================*/ #include "cmVisualStudio10TargetGenerator.h" #include "cmGlobalVisualStudio10Generator.h" +#include "cmGeneratorTarget.h" #include "cmTarget.h" #include "cmComputeLinkInformation.h" #include "cmGeneratedFileStream.h" @@ -62,6 +63,7 @@ cmVisualStudio10TargetGenerator(cmTarget* target, { this->GlobalGenerator = gg; this->Target = target; + this->GeneratorTarget = gg->GetGeneratorTarget(target); this->Makefile = target->GetMakefile(); this->LocalGenerator = (cmLocalVisualStudio7Generator*) @@ -70,7 +72,6 @@ cmVisualStudio10TargetGenerator(cmTarget* target, this->GlobalGenerator->CreateGUID(this->Name.c_str()); this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str()); this->Platform = gg->GetPlatformName(); - this->ComputeObjectNames(); this->BuildFileStream = 0; } @@ -147,7 +148,7 @@ void cmVisualStudio10TargetGenerator::Generate() this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str()); this->Target->SetProperty("GENERATOR_FILE_NAME_EXT", ".vcxproj"); - if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY) + if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY) { if(!this->ComputeClOptions()) { @@ -252,9 +253,9 @@ void cmVisualStudio10TargetGenerator::Generate() this->WritePathAndIncrementalLinkOptions(); this->WriteItemDefinitionGroups(); this->WriteCustomCommands(); - this->WriteObjSources(); - this->WriteCLSources(); + this->WriteAllSources(); this->WriteDotNetReferences(); + this->WriteWinRTReferences(); this->WriteProjectReferences(); this->WriteString( "Target->GetProperty("VS_DOTNET_REFERENCES"); - if(vsDotNetReferences) + std::vector references; + if(const char* vsDotNetReferences = + this->Target->GetProperty("VS_DOTNET_REFERENCES")) + { + cmSystemTools::ExpandListArgument(vsDotNetReferences, references); + } + if(!references.empty()) { - std::string references(vsDotNetReferences); - std::string::size_type position = 0; - this->WriteString("\n", 1); - while(references.length() > 0) + for(std::vector::iterator ri = references.begin(); + ri != references.end(); ++ri) { - if((position = references.find(";")) == std::string::npos) - { - position = references.length() + 1; - } - this->WriteString("BuildFileStream) << - cmVS10EscapeXML(references.substr(0, position)) << "\">\n"; + (*this->BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n"; this->WriteString("true" "\n", 3); this->WriteString("true" "\n", 3); this->WriteString("\n", 2); - - references.erase(0, position + 1); } + this->WriteString("\n", 1); + } +} +void cmVisualStudio10TargetGenerator::WriteWinRTReferences() +{ + std::vector references; + if(const char* vsWinRTReferences = + this->Target->GetProperty("VS_WINRT_REFERENCES")) + { + cmSystemTools::ExpandListArgument(vsWinRTReferences, references); + } + if(!references.empty()) + { + this->WriteString("\n", 1); + for(std::vector::iterator ri = references.begin(); + ri != references.end(); ++ri) + { + this->WriteString("BuildFileStream) << cmVS10EscapeXML(*ri) << "\">\n"; + this->WriteString("true\n", 3); + this->WriteString("\n", 2); + } this->WriteString("\n", 1); } } @@ -341,6 +358,7 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() case cmTarget::MODULE_LIBRARY: configType += "DynamicLibrary"; break; + case cmTarget::OBJECT_LIBRARY: case cmTarget::STATIC_LIBRARY: configType += "StaticLibrary"; break; @@ -371,11 +389,17 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() mfcLine += useOfMfcValue + "\n"; this->WriteString(mfcLine.c_str(), 2); - if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY && - this->ClOptions[*i]->UsingUnicode()) + if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY && + this->ClOptions[*i]->UsingUnicode() || + this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) { this->WriteString("Unicode\n", 2); } + else if (this->Target->GetType() <= cmTarget::MODULE_LIBRARY && + this->ClOptions[*i]->UsingSBCS()) + { + this->WriteString("NotSet\n", 2); + } else { this->WriteString("MultiByte\n", 2); @@ -387,6 +411,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() pts += "\n"; this->WriteString(pts.c_str(), 2); } + if(this->Target->GetPropertyAsBool("VS_WINRT_EXTENSIONS")) + { + this->WriteString("true\n", 2); + } this->WriteString("\n", 1); } } @@ -394,12 +422,11 @@ void cmVisualStudio10TargetGenerator::WriteProjectConfigurationValues() void cmVisualStudio10TargetGenerator::WriteCustomCommands() { this->SourcesVisited.clear(); - std::vector const& sources = this->Target->GetSourceFiles(); - for(std::vector::const_iterator source = sources.begin(); - source != sources.end(); ++source) + for(std::vector::const_iterator + si = this->GeneratorTarget->CustomCommands.begin(); + si != this->GeneratorTarget->CustomCommands.end(); ++si) { - cmSourceFile* sf = *source; - this->WriteCustomCommand(sf); + this->WriteCustomCommand(*si); } } @@ -607,6 +634,25 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteGroupSources("Midl", idls, sourceGroups); this->WriteGroupSources("CustomBuild", customBuild, sourceGroups); + // Add object library contents as external objects. + std::vector objs; + this->GeneratorTarget->UseObjectLibraries(objs); + if(!objs.empty()) + { + this->WriteString("\n", 1); + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) + { + std::string obj = *oi; + this->WriteString("ConvertToWindowsSlash(obj); + (*this->BuildFileStream ) << obj << "\">\n"; + this->WriteString("Object Libraries\n", 3); + this->WriteString("\n", 2); + } + this->WriteString("\n", 1); + } + this->WriteString("\n", 1); for(std::set::iterator g = groupsUsed.begin(); g != groupsUsed.end(); ++g) @@ -630,6 +676,18 @@ void cmVisualStudio10TargetGenerator::WriteGroups() this->WriteString("\n", 2); } } + if(!objs.empty()) + { + this->WriteString("\n", 2); + std::string guidName = "SG_Filter_Object Libraries"; + this->GlobalGenerator->CreateGUID(guidName.c_str()); + this->WriteString("", 3); + std::string guid = + this->GlobalGenerator->GetGUID(guidName.c_str()); + (*this->BuildFileStream) << "{" << guid << "}" + << "\n"; + this->WriteString("\n", 2); + } this->WriteString("\n", 1); this->WriteGroupSources("None", none, sourceGroups); this->WriteString("\n", 0); @@ -736,107 +794,56 @@ WriteGroupSources(const char* name, this->WriteString("\n", 1); } -void cmVisualStudio10TargetGenerator::WriteObjSources() -{ - if(this->Target->GetType() > cmTarget::MODULE_LIBRARY) - { - return; - } - bool first = true; - std::vectorconst & sources = this->Target->GetSourceFiles(); - for(std::vector::const_iterator source = sources.begin(); - source != sources.end(); ++source) - { - std::string ext = - cmSystemTools::LowerCase((*source)->GetExtension()); - if(ext == "obj" || ext == "o") - { - if(first) - { - this->WriteString("\n", 1); - first = false; - } - // If an object file is generated, then vs10 - // will use it in the build, and we have to list - // it as None instead of Object - if((*source)->GetPropertyAsBool("GENERATED")) - { - this->WriteString("WriteString("BuildFileStream ) << (*source)->GetFullPath() << "\" />\n"; - } - } - if(!first) +void cmVisualStudio10TargetGenerator::WriteSource( + const char* tool, cmSourceFile* sf, bool end) +{ + std::string sourceFile = sf->GetFullPath(); + // do not use a relative path here because it means that you + // can not use as long a path to the file. + this->ConvertToWindowsSlash(sourceFile); + this->WriteString("<", 2); + (*this->BuildFileStream ) << tool << + " Include=\"" << sourceFile << (end? "\" />\n" : "\" "); +} + +void cmVisualStudio10TargetGenerator::WriteSources( + const char* tool, std::vector const& sources) +{ + for(std::vector::const_iterator + si = sources.begin(); si != sources.end(); ++si) { - this->WriteString("\n", 1); + this->WriteSource(tool, *si); } } - -void cmVisualStudio10TargetGenerator::WriteCLSources() +void cmVisualStudio10TargetGenerator::WriteAllSources() { if(this->Target->GetType() > cmTarget::UTILITY) { return; } this->WriteString("\n", 1); - std::vectorconst& sources = this->Target->GetSourceFiles(); - for(std::vector::const_iterator source = sources.begin(); - source != sources.end(); ++source) + + this->WriteSources("ClInclude", this->GeneratorTarget->HeaderSources); + this->WriteSources("Midl", this->GeneratorTarget->IDLSources); + + for(std::vector::const_iterator + si = this->GeneratorTarget->ObjectSources.begin(); + si != this->GeneratorTarget->ObjectSources.end(); ++si) { - std::string ext = cmSystemTools::LowerCase((*source)->GetExtension()); - if((*source)->GetCustomCommand() || ext == "o" || ext == "obj") - { - continue; - } - // If it is not a custom command and it is not a pre-built obj file, - // then add it as a source (c/c++/header/rc/idl) file - bool header = (*source)->GetPropertyAsBool("HEADER_FILE_ONLY") - || this->GlobalGenerator->IgnoreFile(ext.c_str()); - const char* lang = (*source)->GetLanguage(); - bool cl = lang && (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") ==0); - bool rc = lang && (strcmp(lang, "RC") == 0); - bool idl = ext == "idl"; - std::string sourceFile = (*source)->GetFullPath(); - // do not use a relative path here because it means that you - // can not use as long a path to the file. - this->ConvertToWindowsSlash(sourceFile); - // output the source file - if(header) - { - this->WriteString("WriteString("WriteString("WriteString("WriteString("BuildFileStream ) << sourceFile << "\""; + const char* lang = (*si)->GetLanguage(); + bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0; + bool rc = strcmp(lang, "RC") == 0; + const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None"); + this->WriteSource(tool, *si, false); // ouput any flags specific to this source file - if(!header && cl && this->OutputSourceSpecificFlags(*source)) + if(cl && this->OutputSourceSpecificFlags(*si)) { // if the source file has specific flags the tag // is ended on a new line this->WriteString("\n", 2); } - else if(!header && rc && this->OutputSourceSpecificFlags(*source)) + else if(rc && this->OutputSourceSpecificFlags(*si)) { this->WriteString("\n", 2); } @@ -845,32 +852,32 @@ void cmVisualStudio10TargetGenerator::WriteCLSources() (*this->BuildFileStream ) << " />\n"; } } - this->WriteString("\n", 1); -} -void cmVisualStudio10TargetGenerator::ComputeObjectNames() -{ - // We may be modifying the source groups temporarily, so make a copy. - std::vector sourceGroups = this->Makefile->GetSourceGroups(); + for(std::vector::const_iterator + si = this->GeneratorTarget->ExternalObjects.begin(); + si != this->GeneratorTarget->ExternalObjects.end(); ++si) + { + // If an object file is generated in this target, then vs10 will use + // it in the build, and we have to list it as None instead of Object. + std::vector const* d = this->Target->GetSourceDepends(*si); + this->WriteSource((d && !d->empty())? "None":"Object", *si); + } - // get the classes from the source lists then add them to the groups - std::vectorconst & classes = this->Target->GetSourceFiles(); - for(std::vector::const_iterator i = classes.begin(); - i != classes.end(); i++) + this->WriteSources("None", this->GeneratorTarget->ExtraSources); + + // Add object library contents as external objects. + std::vector objs; + this->GeneratorTarget->UseObjectLibraries(objs); + for(std::vector::const_iterator + oi = objs.begin(); oi != objs.end(); ++oi) { - // Add the file to the list of sources. - std::string source = (*i)->GetFullPath(); - if(cmSystemTools::UpperCase((*i)->GetExtension()) == "DEF") - { - this->ModuleDefinitionFile = (*i)->GetFullPath(); - } - cmSourceGroup& sourceGroup = - this->Makefile->FindSourceGroup(source.c_str(), sourceGroups); - sourceGroup.AssignSource(*i); + std::string obj = *oi; + this->WriteString("ConvertToWindowsSlash(obj); + (*this->BuildFileStream ) << obj << "\" />\n"; } - // Compute which sources need unique object computation. - this->LocalGenerator->ComputeObjectNameRequirements(sourceGroups); + this->WriteString("\n", 1); } bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( @@ -879,16 +886,11 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( cmSourceFile& sf = *source; cmLocalVisualStudio7Generator* lg = this->LocalGenerator; - // Compute the maximum length full path to the intermediate - // files directory for any configuration. This is used to construct - // object file names that do not produce paths that are too long. - std::string dir_max; - lg->ComputeMaxDirectoryLength(dir_max, *this->Target); - std::string objectName; - if(lg->NeedObjectName.find(&sf) != lg->NeedObjectName.end()) + if(this->GeneratorTarget->ExplicitObjectName.find(&sf) + != this->GeneratorTarget->ExplicitObjectName.end()) { - objectName = lg->GetObjectFileNameWithoutTarget(sf, dir_max); + objectName = this->GeneratorTarget->Objects[&sf]; } std::string flags; std::string defines; @@ -1009,20 +1011,29 @@ void cmVisualStudio10TargetGenerator::WritePathAndIncrementalLinkOptions() } else { - std::string targetNameFull = - this->Target->GetFullName(config->c_str()); std::string intermediateDir = this->LocalGenerator-> GetTargetDirectory(*this->Target); intermediateDir += "/"; intermediateDir += *config; intermediateDir += "/"; + std::string outDir; + std::string targetNameFull; + if(ttype == cmTarget::OBJECT_LIBRARY) + { + outDir = intermediateDir; + targetNameFull = this->Target->GetName(); + targetNameFull += ".lib"; + } + else + { + outDir = this->Target->GetDirectory(config->c_str()) + "/"; + targetNameFull = this->Target->GetFullName(config->c_str()); + } this->ConvertToWindowsSlash(intermediateDir); - std::string outDir = this->Target->GetDirectory(config->c_str()); this->ConvertToWindowsSlash(outDir); this->WritePlatformConfigTag("OutDir", config->c_str(), 3); *this->BuildFileStream << outDir - << "\\" << "\n"; this->WritePlatformConfigTag("IntDir", config->c_str(), 3); @@ -1256,11 +1267,15 @@ void cmVisualStudio10TargetGenerator::WriteClOptions( *this->BuildFileStream << configName << "\n"; this->WriteString("$(IntDir)\n", 3); - this->WriteString("", 3); - *this->BuildFileStream << this->Target->GetDirectory(configName.c_str()) - << "/" - << this->Target->GetPDBName(configName.c_str()) - << "\n"; + if(this->Target->GetType() != cmTarget::OBJECT_LIBRARY) + { + // TODO: PDB for object library? + this->WriteString("", 3); + *this->BuildFileStream << this->Target->GetDirectory(configName.c_str()) + << "/" + << this->Target->GetPDBName(configName.c_str()) + << "\n"; + } this->WriteString("\n", 2); } @@ -1490,12 +1505,12 @@ void cmVisualStudio10TargetGenerator::WriteLinkOptions(std::string const& imLib += targetNameImport; linkOptions.AddFlag("ImportLibrary", imLib.c_str()); - linkOptions.AddFlag("ProgramDataBaseFileName", pdb.c_str()); + linkOptions.AddFlag("ProgramDataBaseFile", pdb.c_str()); linkOptions.Parse(flags.c_str()); - if(!this->ModuleDefinitionFile.empty()) + if(!this->GeneratorTarget->ModuleDefinitionFile.empty()) { linkOptions.AddFlag("ModuleDefinitionFile", - this->ModuleDefinitionFile.c_str()); + this->GeneratorTarget->ModuleDefinitionFile.c_str()); } linkOptions.RemoveFlag("GenerateManifest"); @@ -1564,14 +1579,14 @@ void cmVisualStudio10TargetGenerator::WriteItemDefinitionGroups() static_cast (this->GlobalGenerator)->GetConfigurations(); std::vector includes; - this->LocalGenerator->GetIncludeDirectories(includes); + this->LocalGenerator->GetIncludeDirectories(includes, this->Target); for(std::vector::iterator i = configs->begin(); i != configs->end(); ++i) { this->WritePlatformConfigTag("ItemDefinitionGroup", i->c_str(), 1); *this->BuildFileStream << "\n"; // output cl compile flags - if(this->Target->GetType() <= cmTarget::MODULE_LIBRARY) + if(this->Target->GetType() <= cmTarget::OBJECT_LIBRARY) { this->WriteClOptions(*i, includes); // output rc compile flags diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h index 67025091d..20a443ba4 100644 --- a/Source/cmVisualStudio10TargetGenerator.h +++ b/Source/cmVisualStudio10TargetGenerator.h @@ -15,6 +15,7 @@ class cmTarget; class cmMakefile; +class cmGeneratorTarget; class cmGeneratedFileStream; class cmGlobalVisualStudio10Generator; class cmSourceFile; @@ -46,9 +47,11 @@ private: void WriteString(const char* line, int indentLevel); void WriteProjectConfigurations(); void WriteProjectConfigurationValues(); - void WriteCLSources(); + void WriteSource(const char* tool, cmSourceFile* sf, bool end = true); + void WriteSources(const char* tool, std::vector const&); + void WriteAllSources(); void WriteDotNetReferences(); - void WriteObjSources(); + void WriteWinRTReferences(); void WritePathAndIncrementalLinkOptions(); void WriteItemDefinitionGroups(); bool ComputeClOptions(); @@ -74,7 +77,6 @@ private: void WriteEvents(std::string const& configName); void WriteEvent(const char* name, std::vector & commands, std::string const& configName); - void ComputeObjectNames(); void WriteGroupSources(const char* name, std::vector const& sources, std::vector& ); @@ -86,9 +88,9 @@ private: typedef cmVisualStudioGeneratorOptions Options; typedef std::map OptionsMap; OptionsMap ClOptions; - std::string ModuleDefinitionFile; std::string PathToVcxproj; cmTarget* Target; + cmGeneratorTarget* GeneratorTarget; cmMakefile* Makefile; std::string Platform; std::string GUID; diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index 41230e71c..9369af60c 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -117,6 +117,20 @@ bool cmVisualStudioGeneratorOptions::UsingUnicode() } return false; } +//---------------------------------------------------------------------------- +bool cmVisualStudioGeneratorOptions::UsingSBCS() +{ + // Look for the a _SBCS definition. + for(std::vector::const_iterator di = this->Defines.begin(); + di != this->Defines.end(); ++di) + { + if(*di == "_SBCS") + { + return true; + } + } + return false; +} //---------------------------------------------------------------------------- void cmVisualStudioGeneratorOptions::Parse(const char* flags) diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index 51a13629f..a1a55daff 100644 --- a/Source/cmVisualStudioGeneratorOptions.h +++ b/Source/cmVisualStudioGeneratorOptions.h @@ -48,6 +48,7 @@ public: // Check for specific options. bool UsingUnicode(); + bool UsingSBCS(); bool IsDebug(); // Write options to output. diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 7eafda273..400034582 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -25,7 +25,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, else if (!cmSystemTools::Strucmp(lff.Name.c_str(),"endwhile")) { // if this is the endwhile for this while loop then execute - if (!this->Depth) + if (!this->Depth) { // Remove the function blocker for this scope or bail. cmsys::auto_ptr @@ -33,16 +33,16 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, if(!fb.get()) { return false; } std::string errorString; - + std::vector expandedArguments; mf.ExpandArguments(this->Args, expandedArguments); cmake::MessageType messageType; - bool isTrue = + bool isTrue = cmIfCommand::IsTrue(expandedArguments,errorString, &mf, messageType); while (isTrue) - { + { if (errorString.size()) { std::string err = "had incorrect arguments: "; @@ -86,7 +86,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, } expandedArguments.clear(); mf.ExpandArguments(this->Args, expandedArguments); - isTrue = + isTrue = cmIfCommand::IsTrue(expandedArguments,errorString, &mf, messageType); } @@ -101,7 +101,7 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, // record the command this->Functions.push_back(lff); - + // always return true return true; } @@ -123,7 +123,7 @@ ShouldRemove(const cmListFileFunction& lff, cmMakefile& ) } bool cmWhileCommand -::InvokeInitialPass(const std::vector& args, +::InvokeInitialPass(const std::vector& args, cmExecutionStatus &) { if(args.size() < 1) @@ -131,12 +131,12 @@ bool cmWhileCommand this->SetError("called with incorrect number of arguments"); return false; } - + // create a function blocker cmWhileFunctionBlocker *f = new cmWhileFunctionBlocker(); f->Args = args; this->Makefile->AddFunctionBlocker(f); - + return true; } diff --git a/Source/cmWhileCommand.h b/Source/cmWhileCommand.h index 04649a358..e111ae40d 100644 --- a/Source/cmWhileCommand.h +++ b/Source/cmWhileCommand.h @@ -16,11 +16,6 @@ #include "cmFunctionBlocker.h" #include "cmListFileCache.h" -/** \class cmWhileFunctionBlocker - * \brief subclass of function blocker - * - * - */ class cmWhileFunctionBlocker : public cmFunctionBlocker { public: @@ -37,11 +32,7 @@ private: int Depth; }; -/** \class cmWhileCommand - * \brief starts a while loop - * - * cmWhileCommand starts a while loop - */ +/// \brief Starts a while loop class cmWhileCommand : public cmCommand { public: @@ -70,17 +61,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "while";} + virtual const char* GetName() const { return "while";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Evaluate a group of commands while a condition is true"; } @@ -88,7 +79,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " while(condition)\n" diff --git a/Source/cmWriteFileCommand.h b/Source/cmWriteFileCommand.h index 97ec72712..8808d32bb 100644 --- a/Source/cmWriteFileCommand.h +++ b/Source/cmWriteFileCommand.h @@ -39,17 +39,17 @@ public: /** * This determines if the command is invoked when in script mode. */ - virtual bool IsScriptable() { return true; } + virtual bool IsScriptable() const { return true; } /** * The name of the command as specified in CMakeList.txt. */ - virtual const char* GetName() { return "write_file";} + virtual const char* GetName() const { return "write_file";} /** * Succinct documentation. */ - virtual const char* GetTerseDocumentation() + virtual const char* GetTerseDocumentation() const { return "Deprecated. Use the file(WRITE ) command instead."; } @@ -57,7 +57,7 @@ public: /** * More documentation. */ - virtual const char* GetFullDocumentation() + virtual const char* GetFullDocumentation() const { return " write_file(filename \"message to write\"... [APPEND])\n" @@ -73,7 +73,7 @@ public: } /** This command is kept for compatibility with older CMake versions. */ - virtual bool IsDiscouraged() + virtual bool IsDiscouraged() const { return true; } diff --git a/Source/cmake.cxx b/Source/cmake.cxx index d691f46dc..846aef57f 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -84,6 +84,10 @@ #endif #include "cmGlobalUnixMakefileGenerator3.h" +#ifdef CMAKE_USE_NINJA +# include "cmGlobalNinjaGenerator.h" +#endif + #if defined(CMAKE_HAVE_VS_GENERATORS) #include "cmCallVisualStudioMacro.h" #endif @@ -131,7 +135,7 @@ void cmNeedBackwardsCompatibility(const std::string& variable, " that has not been defined. Some variables were always defined " "by CMake in versions prior to 1.6. To fix this you might need to set " "the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If " - "you are writing a CMakeList file, (or have already set " + "you are writing a CMakeLists file, (or have already set " "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need " "to include a CMake module to test for the feature this variable " "defines."; @@ -598,14 +602,10 @@ bool cmake::FindPackage(const std::vector& args) std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); std::vector includeDirs; cmSystemTools::ExpandListArgument(includes, includeDirs); - for(std::vector::const_iterator dirIt=includeDirs.begin(); - dirIt != includeDirs.end(); - ++dirIt) - { - mf->AddIncludeDirectory(dirIt->c_str(), false); - } - std::string includeFlags = lg->GetIncludeFlags(language.c_str(), false); + std::string includeFlags = lg->GetIncludeFlags(includeDirs, + language.c_str(), false); + std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); } @@ -1433,7 +1433,7 @@ int cmake::ExecuteCMakeCommand(std::vector& args) // Command to start progress for a build else if (args[1] == "cmake_progress_start" && args.size() == 4) { - // bascially remove the directory + // basically remove the directory std::string dirName = args[2]; dirName += "/Progress"; cmSystemTools::RemoveADirectory(dirName.c_str()); @@ -1930,7 +1930,7 @@ void cmake::SetGlobalGenerator(cmGlobalGenerator *gg) { delete this->GlobalGenerator; // restore the original environment variables CXX and CC - // Restor CC + // Restore CC std::string env = "CC="; if(this->CCEnvironment.size()) { @@ -2126,32 +2126,8 @@ int cmake::Configure() } -bool cmake::RejectUnsupportedPaths(const char* desc, std::string const& path) -{ - // Some characters are not well-supported by native build systems. - std::string::size_type pos = path.find_first_of("="); - if(pos == std::string::npos) - { - return false; - } - cmOStringStream e; - e << "The path to the " << desc << " directory:\n" - << " " << path << "\n" - << "contains unsupported character '" << path[pos] << "'.\n" - << "Please use a different " << desc << " directory name."; - cmListFileBacktrace bt; - this->IssueMessage(cmake::FATAL_ERROR, e.str(), bt); - return true; -} - int cmake::ActualConfigure() { - if(this->RejectUnsupportedPaths("source", this->cmHomeDirectory) || - this->RejectUnsupportedPaths("binary", this->HomeOutputDirectory)) - { - return 1; - } - // Construct right now our path conversion table before it's too late: this->UpdateConversionPathTable(); this->CleanupCommandsAndMacros(); @@ -2204,8 +2180,11 @@ int cmake::ActualConfigure() std::string installedCompiler; // Try to find the newest VS installed on the computer and // use that as a default if -G is not specified - std::string vsregBase = - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\"; + const std::string vsregBase = + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"; + std::vector vsVerions; + vsVerions.push_back("VisualStudio\\"); + vsVerions.push_back("VCExpress\\"); struct VSRegistryEntryName { const char* MSVersion; @@ -2219,14 +2198,18 @@ int cmake::ActualConfigure() {"9.0", "Visual Studio 9 2008"}, {"10.0", "Visual Studio 10"}, {0, 0}}; - for(int i =0; version[i].MSVersion != 0; i++) + for(size_t b=0; b < vsVerions.size() && installedCompiler.empty(); b++) { - std::string reg = vsregBase + version[i].MSVersion; - reg += ";InstallDir]"; - cmSystemTools::ExpandRegistryValues(reg); - if (!(reg == "/registry")) + for(int i =0; version[i].MSVersion != 0; i++) { - installedCompiler = version[i].GeneratorName; + std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion; + reg += ";InstallDir]"; + cmSystemTools::ExpandRegistryValues(reg, + cmSystemTools::KeyWOW64_32); + if (!(reg == "/registry")) + { + installedCompiler = version[i].GeneratorName; + } } } cmGlobalGenerator* gen @@ -2614,6 +2597,10 @@ void cmake::AddDefaultGenerators() #endif this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] = &cmGlobalUnixMakefileGenerator3::New; +#ifdef CMAKE_USE_NINJA + this->Generators[cmGlobalNinjaGenerator::GetActualName()] = + &cmGlobalNinjaGenerator::New; +#endif #ifdef CMAKE_USE_XCODE this->Generators[cmGlobalXCodeGenerator::GetActualName()] = &cmGlobalXCodeGenerator::New; @@ -2625,7 +2612,7 @@ int cmake::LoadCache() // could we not read the cache if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory())) { - // if it does exist, but isn;t readable then warn the user + // if it does exist, but isn't readable then warn the user std::string cacheFile = this->GetHomeOutputDirectory(); cacheFile += "/CMakeCache.txt"; if(cmSystemTools::FileExists(cacheFile.c_str())) @@ -2677,7 +2664,9 @@ void cmake::GetCommandDocumentation(std::vector& v, j != this->Commands.end(); ++j) { if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged())) - || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged()))) + || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged())) + || (!((*j).second->ShouldAppearInDocumentation())) + ) { continue; } @@ -3384,19 +3373,21 @@ void cmake::DefineProperties(cmake *cm) cm->DefineProperty ("ENABLED_FEATURES", cmProperty::GLOBAL, "List of features which are enabled during the CMake run.", - "List of features which are enabled during the CMake run. Be default " + "List of features which are enabled during the CMake run. By default " "it contains the names of all packages which were found. This is " "determined using the _FOUND variables. Packages which are " "searched QUIET are not listed. A project can add its own features to " - "this list.This property is used by the macros in FeatureSummary.cmake."); + "this list. " + "This property is used by the macros in FeatureSummary.cmake."); cm->DefineProperty ("DISABLED_FEATURES", cmProperty::GLOBAL, "List of features which are disabled during the CMake run.", - "List of features which are disabled during the CMake run. Be default " + "List of features which are disabled during the CMake run. By default " "it contains the names of all packages which were not found. This is " "determined using the _FOUND variables. Packages which are " "searched QUIET are not listed. A project can add its own features to " - "this list.This property is used by the macros in FeatureSummary.cmake."); + "this list. " + "This property is used by the macros in FeatureSummary.cmake."); cm->DefineProperty ("PACKAGES_FOUND", cmProperty::GLOBAL, "List of packages which were found during the CMake run.", diff --git a/Source/cmake.h b/Source/cmake.h index ae56e8590..94c6f128f 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -9,28 +9,6 @@ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more information. ============================================================================*/ -// This class represents a cmake invocation. It is the top level class when -// running cmake. Most cmake based GUIS should primarily create an instance -// of this class and communicate with it. -// -// The basic process for a GUI is as follows: -// -// 1) Create a cmake instance -// 2) Set the Home & Start directories, generator, and cmake command. this -// can be done using the Set methods or by using SetArgs and passing in -// command line arguments. -// 3) Load the cache by calling LoadCache (duh) -// 4) if you are using command line arguments with -D or -C flags then -// call SetCacheArgs (or if for some other reason you want to modify the -// cache, do it now. -// 5) Finally call Configure -// 6) Let the user change values and go back to step 5 -// 7) call Generate -// -// If your GUI allows the user to change the start & home directories then -// you must at a minimum redo steps 2 through 7. -// - #ifndef cmake_h #define cmake_h @@ -53,6 +31,30 @@ class cmListFileBacktrace; class cmTarget; class cmGeneratedFileStream; +/** \brief Represents a cmake invocation. + * + * This class represents a cmake invocation. It is the top level class when + * running cmake. Most cmake based GUIS should primarily create an instance + * of this class and communicate with it. + * + * The basic process for a GUI is as follows: + * + * -# Create a cmake instance + * -# Set the Home & Start directories, generator, and cmake command. this + * can be done using the Set methods or by using SetArgs and passing in + * command line arguments. + * -# Load the cache by calling LoadCache (duh) + * -# if you are using command line arguments with -D or -C flags then + * call SetCacheArgs (or if for some other reason you want to modify the + * cache), do it now. + * -# Finally call Configure + * -# Let the user change values and go back to step 5 + * -# call Generate + + * If your GUI allows the user to change the start & home directories then + * you must at a minimum redo steps 2 through 7. + */ + class cmake { public: @@ -66,31 +68,33 @@ class cmake }; - /** Describes the working modes of cmake. - * NORMAL_MODE: cmake runs to create project files - * SCRIPT_MODE: in script mode there is no generator and no cache. Also, - * language are not enabled, so add_executable and things do - * not do anything. Started by using -P - * FIND_PACKAGE_MODE: cmake runs in pkg-config like mode, i.e. it just - * searches for a package and prints the results to stdout. - * This is similar to SCRIPT_MODE, but commands like - * add_library() work too, since they may be used e.g. in - * exported target files. Started via --find-package - */ + /** \brief Describes the working modes of cmake */ enum WorkingMode { - NORMAL_MODE, + NORMAL_MODE, ///< Cmake runs to create project files + /** \brief Script mode (started by using -P). + * + * In script mode there is no generator and no cache. Also, + * languages are not enabled, so add_executable and things do + * nothing. + */ SCRIPT_MODE, + /** \brief A pkg-config like mode + * + * In this mode cmake just searches for a package and prints the results to + * stdout. This is similar to SCRIPT_MODE, but commands like add_library() + * work too, since they may be used e.g. in exported target files. Started + * via --find-package. + */ FIND_PACKAGE_MODE }; typedef std::map RegisteredCommandsMap; - ///! construct an instance of cmake + /// Default constructor cmake(); - ///! destruct an instance of cmake + /// Destructor ~cmake(); - ///! construct an instance of cmake static const char *GetCMakeFilesDirectory() {return "/CMakeFiles";}; static const char *GetCMakeFilesDirectoryPostSlash() { return "CMakeFiles/";}; @@ -98,8 +102,8 @@ class cmake //@{ /** * Set/Get the home directory (or output directory) in the project. The - * home directory is the top directory of the project. It is where - * cmake was run. Remember that CMake processes + * home directory is the top directory of the project. It is the + * path-to-source cmake was run with. Remember that CMake processes * CMakeLists files by recursing up the tree starting at the StartDirectory * and going up until it reaches the HomeDirectory. */ @@ -164,12 +168,6 @@ class cmake int Configure(); int ActualConfigure(); - /** - * Configure the cmMakefiles. This routine will create a GlobalGenerator if - * one has not already been set. It will then Call Configure on the - * GlobalGenerator. This in turn will read in an process all the CMakeList - * files for the tree. It will not produce any actual Makefiles, or - * workspaces. Generate does that. */ int LoadCache(); void PreLoadCMakeFiles(); @@ -296,7 +294,7 @@ class cmake void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; } WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; } - ///! Debug the try compile stuff by not delelting the files + ///! Debug the try compile stuff by not deleting the files bool GetDebugTryCompile(){return this->DebugTryCompile;} void DebugTryCompileOn(){this->DebugTryCompile = true;} @@ -374,7 +372,7 @@ class cmake /** Display a message to the user. */ void IssueMessage(cmake::MessageType t, std::string const& text, cmListFileBacktrace const& backtrace); - // * run the --build option + ///! run the --build option int Build(const std::string& dir, const std::string& target, const std::string& config, @@ -438,7 +436,7 @@ protected: void SetDirectoriesFromFile(const char* arg); //! Make sure all commands are what they say they are and there is no - //macros. + /// macros. void CleanupCommandsAndMacros(); void GenerateGraphViz(const char* fileName) const; @@ -468,8 +466,6 @@ protected: ///! Find the full path to one of the cmake programs like ctest, cpack, etc. std::string FindCMakeProgram(const char* name) const; - - bool RejectUnsupportedPaths(const char* desc, std::string const& path); private: cmake(const cmake&); // Not implemented. void operator=(const cmake&); // Not implemented. diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 436236db1..c3de8ca8d 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -355,6 +355,7 @@ int do_cmake(int ac, char** av) #ifdef CMAKE_BUILD_WITH_CMAKE cmDocumentation doc; + doc.addCMakeStandardDocSections(); if(doc.CheckOptions(ac, av, "-E") || nocwd) { // Construct and print requested documentation. diff --git a/Source/cmakexbuild.cxx b/Source/cmakexbuild.cxx index 89d0ec5d1..8eaae4795 100644 --- a/Source/cmakexbuild.cxx +++ b/Source/cmakexbuild.cxx @@ -15,7 +15,7 @@ // This is a wrapper program for xcodebuild // it calls xcodebuild, and does two things -// it removes much of the output, all the setevn +// it removes much of the output, all the setenv // stuff. Also, it checks for the text file busy // error, and re-runs xcodebuild until that error does // not show up. diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 85cecea89..d41627e26 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -291,6 +291,7 @@ int main (int argc, char *argv[]) << "*********************************" << std::endl); } cmDocumentation doc; + doc.addCTestStandardDocSections(); if(doc.CheckOptions(argc, argv) || nocwd) { // Construct and print requested documentation. diff --git a/Source/kwsys/kwsysDateStamp.cmake b/Source/kwsys/kwsysDateStamp.cmake index 2f009e086..f15760753 100644 --- a/Source/kwsys/kwsysDateStamp.cmake +++ b/Source/kwsys/kwsysDateStamp.cmake @@ -12,10 +12,10 @@ #============================================================================= # KWSys version date year component. Format is CCYY. -SET(KWSYS_DATE_STAMP_YEAR 2011) +SET(KWSYS_DATE_STAMP_YEAR 2012) # KWSys version date month component. Format is MM. -SET(KWSYS_DATE_STAMP_MONTH 12) +SET(KWSYS_DATE_STAMP_MONTH 04) # KWSys version date day component. Format is DD. -SET(KWSYS_DATE_STAMP_DAY 30) +SET(KWSYS_DATE_STAMP_DAY 18) diff --git a/Templates/CPackConfig.cmake.in b/Templates/CPackConfig.cmake.in index 7150feb72..79b8d93ae 100644 --- a/Templates/CPackConfig.cmake.in +++ b/Templates/CPackConfig.cmake.in @@ -1,29 +1,12 @@ # This file will be configured to contain variables for CPack. These variables # should be set in the CMake list file of the project before CPack module is -# included. Example variables are: -# CPACK_GENERATOR - Generator used to create package -# CPACK_INSTALL_CMAKE_PROJECTS - For each project (path, name, component) -# CPACK_CMAKE_GENERATOR - CMake Generator used for the projects -# CPACK_INSTALL_COMMANDS - Extra commands to install components -# CPACK_INSTALLED_DIRECTORIES - Extra directories to install -# CPACK_PACKAGE_DESCRIPTION_FILE - Description file for the package -# CPACK_PACKAGE_DESCRIPTION_SUMMARY - Summary of the package -# CPACK_PACKAGE_EXECUTABLES - List of pairs of executables and labels -# CPACK_PACKAGE_FILE_NAME - Name of the package generated -# CPACK_PACKAGE_ICON - Icon used for the package -# CPACK_PACKAGE_INSTALL_DIRECTORY - Name of directory for the installer -# CPACK_PACKAGE_NAME - Package project name -# CPACK_PACKAGE_VENDOR - Package project vendor -# CPACK_PACKAGE_VERSION - Package project version -# CPACK_PACKAGE_VERSION_MAJOR - Package project version (major) -# CPACK_PACKAGE_VERSION_MINOR - Package project version (minor) -# CPACK_PACKAGE_VERSION_PATCH - Package project version (patch) - -# There are certain generator specific ones - -# NSIS Generator: -# CPACK_PACKAGE_INSTALL_REGISTRY_KEY - Name of the registry key for the installer -# CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS - Extra commands used during uninstall -# CPACK_NSIS_EXTRA_INSTALL_COMMANDS - Extra commands used during install +# included. The list of available CPACK_xxx variables and their associated +# documentation may be obtained using +# cpack --help-variable-list +# +# Some variables are common to all generators (e.g. CPACK_PACKAGE_NAME) +# and some are specific to a generator +# (e.g. CPACK_NSIS_EXTRA_INSTALL_COMMANDS). The generator specific variables +# usually begin with CPACK__xxxx. @_CPACK_OTHER_VARIABLES_@ diff --git a/Tests/BuildDepends/CMakeLists.txt b/Tests/BuildDepends/CMakeLists.txt index 31392b5e4..aa32d67a0 100644 --- a/Tests/BuildDepends/CMakeLists.txt +++ b/Tests/BuildDepends/CMakeLists.txt @@ -40,6 +40,8 @@ if("${CMAKE_GENERATOR}" MATCHES "Make") endif() list(APPEND _cmake_options "-DTEST_LINK_DEPENDS=${TEST_LINK_DEPENDS}") +list(APPEND _cmake_options "-DCMAKE_FORCE_DEPFILES=1") + file(MAKE_DIRECTORY ${BuildDepends_BINARY_DIR}/Project) message("Creating Project/foo.cxx") write_file(${BuildDepends_BINARY_DIR}/Project/foo.cxx diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt index 6209c8fcd..8f24afe9a 100644 --- a/Tests/BundleUtilities/CMakeLists.txt +++ b/Tests/BundleUtilities/CMakeLists.txt @@ -82,3 +82,52 @@ add_custom_target(testbundleutils2_test ALL DEPENDS testbundleutils1 module2 ) add_dependencies(testbundleutils2_test testbundleutils2) + + +if(APPLE AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 9.0) +###### Test a Bundle application using dependencies +###### and @rpaths on Mac OS X 10.5 or greater + + # a shared library + add_library(shared-3 SHARED shared.cpp shared.h) + + # another shared library + add_library(shared2-3 SHARED shared2.cpp shared2.h) + + # a framework library + add_library(framework-3 SHARED framework.cpp framework.h) + set_target_properties(framework-3 PROPERTIES FRAMEWORK 1) + + # build dependencies with @rpath install name + set_target_properties(shared-3 shared2-3 framework-3 PROPERTIES + INSTALL_NAME_DIR "@rpath" + BUILD_WITH_INSTALL_RPATH 1) + + # a loadable module (depends on shared2) + # testbundleutils1 will load this at runtime + add_library(module3 MODULE module.cpp module.h) + set_target_properties(module3 PROPERTIES PREFIX "" LINK_FLAGS "-Wl,-rpath,@loader_path/") + get_target_property(module_loc module3 LOCATION) + target_link_libraries(module3 shared2-3) + + # a non-bundle application + add_executable(testbundleutils3 testbundleutils3.cpp) + target_link_libraries(testbundleutils3 shared-3 framework-3 ${CMAKE_DL_LIBS}) + get_target_property(loc testbundleutils3 LOCATION) + + set_target_properties(testbundleutils3 module3 PROPERTIES + LINK_FLAGS "-Wl,-rpath,@loader_path/") + + # add custom target to install and test the app + add_custom_target(testbundleutils3_test ALL + COMMAND ${CMAKE_COMMAND} + "-DINPUT=${loc}" + "-DMODULE=${module_loc}" + "-DINPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}" + "-DOUTPUTDIR=${CMAKE_CURRENT_BINARY_DIR}/testdir3" + -P "${CMAKE_CURRENT_SOURCE_DIR}/bundleutils.cmake" + DEPENDS testbundleutils3 module3 + ) + + add_dependencies(testbundleutils3_test testbundleutils3) +endif() diff --git a/Tests/BundleUtilities/testbundleutils3.cpp b/Tests/BundleUtilities/testbundleutils3.cpp new file mode 100644 index 000000000..9df13e988 --- /dev/null +++ b/Tests/BundleUtilities/testbundleutils3.cpp @@ -0,0 +1,33 @@ + +#include "framework.h" +#include "shared.h" +#include "stdio.h" + +#if defined(WIN32) +#include +#else +#include "dlfcn.h" +#endif + +int main(int, char**) +{ + framework(); + shared(); + +#if defined(WIN32) + HANDLE lib = LoadLibraryA("module3.dll"); + if(!lib) + { + printf("Failed to open module3\n"); + } +#else + void* lib = dlopen("module3.so", RTLD_LAZY); + if(!lib) + { + printf("Failed to open module3\n%s\n", dlerror()); + } +#endif + + + return lib == 0 ? 1 : 0; +} diff --git a/Tests/CMakeCommands/build_command/RunCMake.cmake b/Tests/CMakeCommands/build_command/RunCMake.cmake deleted file mode 100644 index 55d935960..000000000 --- a/Tests/CMakeCommands/build_command/RunCMake.cmake +++ /dev/null @@ -1,86 +0,0 @@ -if(NOT DEFINED CMake_SOURCE_DIR) - message(FATAL_ERROR "CMake_SOURCE_DIR not defined") -endif() - -if(NOT DEFINED dir) - message(FATAL_ERROR "dir not defined") -endif() - -if(NOT DEFINED gen) - message(FATAL_ERROR "gen not defined") -endif() - -message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") - -# Run cmake: -# -function(run_cmake build_dir extra_args expected_result expected_output expected_error) - message(STATUS "run_cmake build_dir='${build_dir}' extra_args='${extra_args}'") - - # Ensure build_dir exists: - # - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${build_dir}) - - # Run cmake: - # - execute_process(COMMAND ${CMAKE_COMMAND} - ${extra_args} - -G ${gen} ${CMake_SOURCE_DIR}/Tests/CMakeCommands/build_command - RESULT_VARIABLE result - OUTPUT_VARIABLE stdout - ERROR_VARIABLE stderr - WORKING_DIRECTORY ${build_dir} - ) - - message(STATUS "result='${result}'") - message(STATUS "stdout='${stdout}'") - message(STATUS "stderr='${stderr}'") - message(STATUS "") - - # Verify result and output match expectations: - # - if("0" STREQUAL "${expected_result}") - if(NOT "${result}" STREQUAL "0") - message(FATAL_ERROR - "error: result='${result}' is non-zero and different than expected_result='${expected_result}'") - endif() - else() - if("${result}" STREQUAL "0") - message(FATAL_ERROR - "error: result='${result}' is zero and different than expected_result='${expected_result}'") - endif() - endif() - - foreach(e ${expected_output}) - if(NOT stdout MATCHES "${e}") - message(FATAL_ERROR - "error: stdout does not match expected_output item e='${e}'") - else() - message(STATUS "info: stdout matches '${e}'") - endif() - endforeach() - - foreach(e ${expected_error}) - if(NOT stderr MATCHES "${e}") - message(FATAL_ERROR - "error: stderr does not match expected_error item e='${e}'") - else() - message(STATUS "info: stderr matches '${e}'") - endif() - endforeach() - - message(STATUS "result, stdout and stderr match all expectations: test passes") - message(STATUS "") -endfunction() - - -# Expect this case to succeed: -run_cmake("${dir}/b1" "" 0 - "Build files have been written to:" - "skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF") - - -# Expect this one to fail: -run_cmake("${dir}/b2" "-DTEST_ERROR_CONDITIONS:BOOL=ON" 1 - "Configuring incomplete, errors occurred!" - "build_command requires at least one argument naming a CMake variable;build_command unknown argument ") diff --git a/Tests/CMakeCommands/target_link_libraries/depC.cpp b/Tests/CMakeCommands/target_link_libraries/depC.cpp index 93410a8f2..60bed592f 100644 --- a/Tests/CMakeCommands/target_link_libraries/depC.cpp +++ b/Tests/CMakeCommands/target_link_libraries/depC.cpp @@ -10,4 +10,4 @@ DepA DepC::getA() { DepA a; return a; -} \ No newline at end of file +} diff --git a/Tests/CMakeLib/CMakeLists.txt b/Tests/CMakeLib/CMakeLists.txt index 41bf03437..4e819f470 100644 --- a/Tests/CMakeLib/CMakeLists.txt +++ b/Tests/CMakeLib/CMakeLists.txt @@ -5,6 +5,8 @@ include_directories( ) set(CMakeLib_TESTS + testGeneratedFileStream + testSystemTools testUTF8 testXMLParser testXMLSafe diff --git a/Tests/CMakeLib/testGeneratedFileStream.cxx b/Tests/CMakeLib/testGeneratedFileStream.cxx new file mode 100644 index 000000000..f8ca4af94 --- /dev/null +++ b/Tests/CMakeLib/testGeneratedFileStream.cxx @@ -0,0 +1,100 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2011 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmGeneratedFileStream.h" +#include "cmSystemTools.h" + +#define cmFailed(m1, m2) \ + std::cout << "FAILED: " << m1 << m2 << "\n"; failed=1 + +int testGeneratedFileStream(int, char*[]) +{ + int failed = 0; + cmGeneratedFileStream gm; + std::string file1 = "generatedFile1"; + std::string file2 = "generatedFile2"; + std::string file3 = "generatedFile3"; + std::string file4 = "generatedFile4"; + std::string file1tmp = file1 + ".tmp"; + std::string file2tmp = file2 + ".tmp"; + std::string file3tmp = file3 + ".tmp"; + std::string file4tmp = file4 + ".tmp"; + gm.Open(file1.c_str()); + gm << "This is generated file 1"; + gm.Close(); + gm.Open(file2.c_str()); + gm << "This is generated file 2"; + gm.Close(); + gm.Open(file3.c_str()); + gm << "This is generated file 3"; + gm.Close(); + gm.Open(file4.c_str()); + gm << "This is generated file 4"; + gm.Close(); + if ( cmSystemTools::FileExists(file1.c_str()) ) + { + if ( cmSystemTools::FileExists(file2.c_str()) ) + { + if ( cmSystemTools::FileExists(file3.c_str()) ) + { + if ( cmSystemTools::FileExists(file4.c_str()) ) + { + if ( cmSystemTools::FileExists(file1tmp.c_str()) ) + { + cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str()); + } + else if ( cmSystemTools::FileExists(file2tmp.c_str()) ) + { + cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str()); + } + else if ( cmSystemTools::FileExists(file3tmp.c_str()) ) + { + cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str()); + } + else if ( cmSystemTools::FileExists(file4tmp.c_str()) ) + { + cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str()); + } + else + { + std::cout << "cmGeneratedFileStream works\n"; + } + } + else + { + cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str()); + } + } + else + { + cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str()); + } + } + else + { + cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str()); + } + } + else + { + cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str()); + } + cmSystemTools::RemoveFile(file1.c_str()); + cmSystemTools::RemoveFile(file2.c_str()); + cmSystemTools::RemoveFile(file3.c_str()); + cmSystemTools::RemoveFile(file4.c_str()); + cmSystemTools::RemoveFile(file1tmp.c_str()); + cmSystemTools::RemoveFile(file2tmp.c_str()); + cmSystemTools::RemoveFile(file3tmp.c_str()); + cmSystemTools::RemoveFile(file4tmp.c_str()); + + return failed; +} diff --git a/Tests/CMakeLib/testSystemTools.cxx b/Tests/CMakeLib/testSystemTools.cxx new file mode 100644 index 000000000..9309ae332 --- /dev/null +++ b/Tests/CMakeLib/testSystemTools.cxx @@ -0,0 +1,33 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2011 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#include "cmSystemTools.h" + +#define cmPassed(m) std::cout << "Passed: " << m << "\n" +#define cmFailed(m) std::cout << "FAILED: " << m << "\n"; failed=1 + +int testSystemTools(int, char*[]) +{ + int failed = 0; + // ---------------------------------------------------------------------- + // Test cmSystemTools::UpperCase + std::string str = "abc"; + std::string strupper = "ABC"; + if(cmSystemTools::UpperCase(str) == strupper) + { + cmPassed("cmSystemTools::UpperCase is working"); + } + else + { + cmFailed("cmSystemTools::UpperCase is working"); + } + return failed; +} diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 42b3ef79b..c0b7cd617 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -16,6 +16,11 @@ MACRO(ADD_TEST_MACRO NAME COMMAND) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/${dir}") ENDMACRO(ADD_TEST_MACRO) +MACRO(REGEX_ESCAPE_STRING _OUT _IN) + # Escape special regex metacharacters with a backslash + string(REGEX REPLACE "([$^.[|*+?()]|])" "\\\\\\1" ${_OUT} "${_IN}") +ENDMACRO(REGEX_ESCAPE_STRING _OUT _IN) + INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake) # Fake a user home directory to avoid polluting the real one. @@ -47,6 +52,8 @@ IF(BUILD_TESTING) ENDIF() ADD_SUBDIRECTORY(CMakeLib) + ADD_SUBDIRECTORY(CMakeOnly) + ADD_SUBDIRECTORY(RunCMake) ADD_SUBDIRECTORY(FindPackageModeMakefileTest) @@ -162,10 +169,37 @@ IF(BUILD_TESTING) IF(CMAKE_Fortran_COMPILER) ADD_TEST_MACRO(FortranOnly FortranOnly) ENDIF() + # test Visual Studio GNU Fortran mixing with cmake_add_fortran_subdirectory + # run this project if we have a working fortran compiler or + # the test is enabled with CMAKE_TEST_CMAKE_ADD_FORTRAN cache variable. + # If you enable the test, CMake should find the MinGW fortran install, + # or in some cases you might need to set the PATH so that cmake can find + # the gfortran from mingw. + IF(CMAKE_Fortran_COMPILER OR CMAKE_TEST_CMAKE_ADD_FORTRAN) + SET(CMAKE_SKIP_VSGNUFortran FALSE) + # disable test for apple builds using ifort if they are building + # more than one architecture, as ifort does not support that. + IF(APPLE AND (CMAKE_Fortran_COMPILER MATCHES ifort)) + LIST(LENGTH CMAKE_OSX_ARCHITECTURES len) + IF("${len}" GREATER 1) + MESSAGE(STATUS "Skip VSGNUFortran for ifort dual cpu mac build") + SET(CMAKE_SKIP_VSGNUFortran TRUE) + ENDIF() + ENDIF() + IF((CMAKE_C_COMPILER MATCHES lsb) + AND (CMAKE_Fortran_COMPILER MATCHES ifort)) + MESSAGE(STATUS "Skip VSGNUFortran for ifort and lsb compilers") + SET(CMAKE_SKIP_VSGNUFortran TRUE) + ENDIF() + IF(NOT CMAKE_SKIP_VSGNUFortran) + ADD_TEST_MACRO(VSGNUFortran ${CMAKE_COMMAND} -P runtest.cmake) + ENDIF() + ENDIF() ADD_TEST_MACRO(COnly COnly) ADD_TEST_MACRO(CxxOnly CxxOnly) ADD_TEST_MACRO(IPO COnly/COnly) ADD_TEST_MACRO(OutDir runtime/OutDir) + ADD_TEST_MACRO(ObjectLibrary UseCshared) ADD_TEST_MACRO(NewlineArgs NewlineArgs) ADD_TEST_MACRO(SetLang SetLang) ADD_TEST_MACRO(ExternalOBJ ExternalOBJ) @@ -200,12 +234,35 @@ IF(BUILD_TESTING) LIST(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX}) + IF(NOT QT4_FOUND) + FIND_PACKAGE(Qt4) + ENDIF(NOT QT4_FOUND) + + IF(QT4_FOUND) + # test whether the Qt4 which has been found works, on some machines + # which run nightly builds there were errors like "wrong file format" + # for libQtCore.so. So first check it works, and only if it does add + # the automoc test. + INCLUDE(CheckCXXSourceCompiles) + SET(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}") + SET(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + + SET(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES}) + SET(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES}) + + CHECK_CXX_SOURCE_COMPILES("#include \n int main() {return (qApp == 0 ? 0 : 1); }\n" + QT4_WORKS) + + SET(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}") + SET(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") + ENDIF() # run test for BundleUtilities on supported platforms/compilers if(MSVC OR CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") if(NOT "${CMAKE_TEST_GENERATOR}" STREQUAL "Watcom WMake") + ADD_TEST(BundleUtilities ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/BundleUtilities" @@ -215,6 +272,24 @@ IF(BUILD_TESTING) --build-project BundleUtilities ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/BundleUtilities") + + # run test for DeployQt4 on supported platforms/compilers (which depends on BundleUtilities) + # this test also depends on the existence of the standard qtiff plugin + if(QT4_WORKS AND QT_QTSQL_FOUND) + ADD_TEST(Qt4Deploy ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/Qt4Deploy" + "${CMake_BINARY_DIR}/Tests/Qt4Deploy" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-project Qt4Deploy + --build-options + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Qt4Deploy") + endif() + endif() endif() @@ -240,8 +315,6 @@ IF(BUILD_TESTING) ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader) - ADD_TEST_MACRO(Module.CheckCXXCompilerFlag CheckCXXCompilerFlag) - ADD_TEST(LinkFlags-prepare ${CMAKE_CTEST_COMMAND} -C \${CTEST_CONFIGURATION_TYPE} --build-and-test @@ -335,6 +408,15 @@ IF(BUILD_TESTING) --build-target car --test-command car ) + + IF(${CMAKE_TEST_GENERATOR} MATCHES "Ninja") + # The Ninja generator does not create a recursive build system. Start + # from the root directory. + SET(SubProject_SUBDIR) + ELSE() + SET(SubProject_SUBDIR "/foo") + ENDIF() + # For stage 2, do not run cmake again. # Then build the foo sub project which should build # the bar library which should be referenced because @@ -342,13 +424,14 @@ IF(BUILD_TESTING) # directly in the foo sub project ADD_TEST(SubProject-Stage2 ${CMAKE_CTEST_COMMAND} --build-and-test - "${CMake_SOURCE_DIR}/Tests/SubProject/foo" - "${CMake_BINARY_DIR}/Tests/SubProject/foo" + "${CMake_SOURCE_DIR}/Tests/SubProject${SubProject_SUBDIR}" + "${CMake_BINARY_DIR}/Tests/SubProject${SubProject_SUBDIR}" --build-generator ${CMAKE_TEST_GENERATOR} --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} --build-nocmake --build-project foo --build-target foo + --build-exe-dir "${CMake_BINARY_DIR}/Tests/SubProject/foo" --test-command foo ) SET_TESTS_PROPERTIES ( SubProject-Stage2 PROPERTIES DEPENDS SubProject) @@ -560,6 +643,14 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ set(CTEST_package_X11_TEST ${CTEST_TEST_CPACK}) set(CTEST_RUN_CPackComponentsForAll ${CTEST_TEST_CPACK}) + if (CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_CURRENT_BINARY_DIR MATCHES ".* .*") + find_program(RPMBUILD NAMES rpmbuild) + endif(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT CMAKE_CURRENT_BINARY_DIR MATCHES ".* .*") + # Do not try to build RPM + if (NOT RPMBUILD) + set(CPACK_BINARY_RPM OFF) + endif(NOT RPMBUILD) + find_program(NSIS_MAKENSIS_EXECUTABLE NAMES makensis PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS] DOC "makensis program location" @@ -766,77 +857,36 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/LoadCommandOneConfig") - # Como does not seem to support shared libraries. - GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_CXX_COMPILER} NAME_WE) - IF(CMAKE_BASE_NAME MATCHES "^como$") - SET(COMPILER_IS_COMO 1) - ENDIF(CMAKE_BASE_NAME MATCHES "^como$") - IF(NOT COMPILER_IS_COMO) - SET(COMPLEX_TEST_CMAKELIB 1) - IF(CMAKE_TEST_DIFFERENT_GENERATOR OR CMAKE_TEST_SYSTEM_LIBRARIES) - SET(COMPLEX_TEST_CMAKELIB 0) - ENDIF(CMAKE_TEST_DIFFERENT_GENERATOR OR CMAKE_TEST_SYSTEM_LIBRARIES) - IF(BORLAND) - SET(COMPLEX_TEST_CMAKELIB 0) - ENDIF(BORLAND) - ADD_TEST(complex ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/Complex" - "${CMake_BINARY_DIR}/Tests/Complex" - --build-two-config - --build-config-sample "${CMAKE_CTEST_COMMAND}" - --build-generator ${CMAKE_TEST_GENERATOR} - --build-project Complex - --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} - --build-exe-dir "${CMake_BINARY_DIR}/Tests/Complex/bin" - --build-options - -DCOMPLEX_TEST_CMAKELIB:BOOL=${COMPLEX_TEST_CMAKELIB} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - --test-command complex - ) - LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Complex") + ADD_TEST(complex ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/Complex" + "${CMake_BINARY_DIR}/Tests/Complex" + --build-two-config + --build-config-sample "${CMAKE_CTEST_COMMAND}" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project Complex + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/Complex/bin" + --build-options + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + --test-command complex + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Complex") - ADD_TEST(complexOneConfig ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/ComplexOneConfig" - "${CMake_BINARY_DIR}/Tests/ComplexOneConfig" - --build-generator ${CMAKE_TEST_GENERATOR} - --build-project Complex - --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} - --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexOneConfig/bin" - --build-options - -DCOMPLEX_TEST_CMAKELIB:BOOL=${COMPLEX_TEST_CMAKELIB} - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - --test-command complex) - LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ComplexOneConfig") - # because of the registry write these tests depend on each other - SET_TESTS_PROPERTIES ( complex PROPERTIES DEPENDS complexOneConfig) - -# This fails on VS 70 -# works on Xcode and makefiles -# ADD_TEST(ConvLibrary ${CMAKE_CTEST_COMMAND} -# --build-and-test -# "${CMake_SOURCE_DIR}/Tests/ConvLibrary" -# "${CMake_BINARY_DIR}/Tests/ConvLibrary" -# --build-two-config -# --build-generator ${CMAKE_TEST_GENERATOR} -# --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} -# --build-project ConvLibrary -# --test-command bartest) - - -# ADD_TEST(complexRelativePaths ${CMAKE_CTEST_COMMAND} -# --build-and-test -# "${CMake_SOURCE_DIR}/Tests/ComplexRelativePaths" -# "${CMake_BINARY_DIR}/Tests/ComplexRelativePaths" -# --build-generator ${CMAKE_TEST_GENERATOR} -# --build-project complex -# --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} -# --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexRelativePaths/bin" -# --build-options -DCMAKE_USE_RELATIVE_PATHS:BOOL=ON -# --test-command complex) - - ENDIF(NOT COMPILER_IS_COMO) + ADD_TEST(complexOneConfig ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/ComplexOneConfig" + "${CMake_BINARY_DIR}/Tests/ComplexOneConfig" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project Complex + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/ComplexOneConfig/bin" + --build-options + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + --test-command complex) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/ComplexOneConfig") + # because of the registry write these tests depend on each other + SET_TESTS_PROPERTIES ( complex PROPERTIES DEPENDS complexOneConfig) ADD_TEST(Example ${CMAKE_CTEST_COMMAND} --build-and-test @@ -863,43 +913,20 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ ) LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Environment") - IF(NOT QT4_FOUND) - FIND_PACKAGE(Qt4) - ENDIF(NOT QT4_FOUND) - - IF(QT4_FOUND) - # test whether the Qt4 which has been found works, on some machines - # which run nightly builds there were errors like "wrong file format" - # for libQtCore.so. So first check it works, and only if it does add - # the automoc test. - INCLUDE(CheckCXXSourceCompiles) - SET(_save_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}") - SET(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") - - SET(CMAKE_REQUIRED_INCLUDES ${QT_INCLUDES}) - SET(CMAKE_REQUIRED_LIBRARIES ${QT_QTCORE_LIBRARIES}) - - CHECK_CXX_SOURCE_COMPILES("#include \n int main() {return (qApp == 0 ? 0 : 1); }\n" - QT4_WORKS_FOR_AUTOMOC_TEST) - - SET(CMAKE_REQUIRED_INCLUDES "${_save_CMAKE_REQUIRED_INCLUDES}") - SET(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") - - IF(QT4_WORKS_FOR_AUTOMOC_TEST) - ADD_TEST(QtAutomoc ${CMAKE_CTEST_COMMAND} - --build-and-test - "${CMake_SOURCE_DIR}/Tests/QtAutomoc" - "${CMake_BINARY_DIR}/Tests/QtAutomoc" - --build-generator ${CMAKE_TEST_GENERATOR} - --build-project QtAutomoc - --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} - --build-exe-dir "${CMake_BINARY_DIR}/Tests/QtAutomoc" - --force-new-ctest-process - --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} - --test-command ${CMAKE_CTEST_COMMAND} -V - ) - LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/QtAutomoc") - ENDIF() + IF(QT4_WORKS AND QT_QTGUI_FOUND) + ADD_TEST(QtAutomoc ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/QtAutomoc" + "${CMake_BINARY_DIR}/Tests/QtAutomoc" + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project QtAutomoc + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/QtAutomoc" + --force-new-ctest-process + --build-options -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} + --test-command ${CMAKE_CTEST_COMMAND} -V + ) + LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/QtAutomoc") ENDIF() ADD_TEST(ExternalProject ${CMAKE_CTEST_COMMAND} @@ -1322,6 +1349,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ endif() IF(${CMAKE_TEST_GENERATOR} MATCHES "Visual Studio") + IF(NOT MSVC60) + ADD_TEST_MACRO(SBCS SBCS) + ENDIF(NOT MSVC60) + ADD_TEST(VSExternalInclude ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/VSExternalInclude" @@ -1654,9 +1685,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ -S "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir1/test1.cmake" -V --output-log "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir1/testOut1.log" ) + REGEX_ESCAPE_STRING(CTEST_TEST_ESCAPED_SOURCE_DIR "${CMake_SOURCE_DIR}") SET_TESTS_PROPERTIES(CTestTestConfigFileInBuildDir1 PROPERTIES DEPENDS CTestTestNoBuild PASS_REGULAR_EXPRESSION - "Reading ctest configuration file: ${CMake_SOURCE_DIR}.Tests.CTestTestConfigFileInBuildDir.CTestConfig.cmake") + "Reading ctest configuration file: ${CTEST_TEST_ESCAPED_SOURCE_DIR}.Tests.CTestTestConfigFileInBuildDir.CTestConfig.cmake") CONFIGURE_FILE( "${CMake_SOURCE_DIR}/Tests/CTestTestConfigFileInBuildDir/test2.cmake.in" @@ -1670,10 +1702,11 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ -S "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/test2.cmake" -V --output-log "${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/testOut2.log" ) + REGEX_ESCAPE_STRING(CTEST_TEST_ESCAPED_BINARY_DIR "${CMake_BINARY_DIR}") SET_TESTS_PROPERTIES(CTestTestConfigFileInBuildDir2 PROPERTIES DEPENDS CTestTestNoBuild REQUIRED_FILES ${CMake_BINARY_DIR}/Tests/CTestTestConfigFileInBuildDir2/CTestConfig.cmake PASS_REGULAR_EXPRESSION - "Reading ctest configuration file: ${CMake_BINARY_DIR}.Tests.CTestTestConfigFileInBuildDir2.CTestConfig.cmake") + "Reading ctest configuration file: ${CTEST_TEST_ESCAPED_BINARY_DIR}.Tests.CTestTestConfigFileInBuildDir2.CTestConfig.cmake") # Use macro, not function so that build can still be driven by CMake 2.4. # After 2.6 is required, this could be a function without the extra 'set' @@ -1711,13 +1744,6 @@ ${CMake_BINARY_DIR}/bin/cmake -DVERSION=master -P ${CMake_SOURCE_DIR}/Utilities/ add_config_tests(Release) add_config_tests(RelWithDebInfo) - add_test(CMakeCommands.build_command ${CMAKE_CMAKE_COMMAND} - -DCMake_SOURCE_DIR=${CMake_SOURCE_DIR} - -Ddir=${CMake_BINARY_DIR}/Tests/CMakeCommands/build_command - -Dgen=${CMAKE_TEST_GENERATOR} - -P "${CMake_SOURCE_DIR}/Tests/CMakeCommands/build_command/RunCMake.cmake" - ) - ADD_TEST_MACRO(CMakeCommands.target_link_libraries target_link_libraries) CONFIGURE_FILE( diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt new file mode 100644 index 000000000..660420874 --- /dev/null +++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt @@ -0,0 +1,85 @@ +cmake_minimum_required (VERSION 2.8) +project(AllFindModules) + +if (POLICY CMP0017) + cmake_policy(SET CMP0017 NEW) +endif () + +# Avoid ctest truncation of output +message(STATUS "CTEST_FULL_OUTPUT") + +file(GLOB FIND_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../Modules/Find*.cmake" ) + +macro(do_find MODULE_NAME) + message(STATUS " Checking Find${MODULE_NAME}") + find_package(${MODULE_NAME}) +endmacro(do_find) + +# It is only possible to use either Qt3 or Qt4 in one project. +# Since FindQt will complain if both are found we explicitly request Qt4 here +# and filter out FindQt3. FindKDE3 also depends on Qt3 and +# is therefore also blocked +set(DESIRED_QT_VERSION 4) +set(NO_QT4_MODULES "Qt3" "KDE3") + +# These modules are named Find*.cmake, but are nothing that works in +# find_package(). +set(NO_FIND_MODULES "PackageHandleStandardArgs" "PackageMessage") + +foreach(FIND_MODULE ${FIND_MODULES}) + string(REGEX REPLACE ".*/Find(.*)\\.cmake$" "\\1" MODULE_NAME "${FIND_MODULE}") + + list(FIND NO_QT4_MODULES ${MODULE_NAME} NO_QT4_INDEX) + list(FIND NO_FIND_MODULES ${MODULE_NAME} NO_FIND_INDEX) + if (NO_QT4_INDEX EQUAL -1 AND NO_FIND_INDEX EQUAL -1) + do_find(${MODULE_NAME}) + endif () + +endforeach(FIND_MODULE) + +# Qt4 is not present, so we can check Qt3 +if (NOT QT4_FOUND) + set(DESIRED_QT_VERSION 3) + foreach(FIND_MODULE ${NO_QT4_MODULES} "Qt") + do_find(${FIND_MODULE}) + endforeach(FIND_MODULE) +endif (NOT QT4_FOUND) + +macro(check_version_string MODULE_NAME VERSION_VAR) + if (${MODULE_NAME}_FOUND) + if (DEFINED ${VERSION_VAR}) + message(STATUS "${VERSION_VAR}='${${VERSION_VAR}}'") + if (NOT ${VERSION_VAR} MATCHES "^[0-9]") + message(SEND_ERROR "unexpected: ${VERSION_VAR} does not begin with a decimal digit") + endif() + if ("${${VERSION_VAR}}" STREQUAL "") + message(SEND_ERROR "unexpected: ${VERSION_VAR} is empty") + endif() + if (${VERSION_VAR} VERSION_EQUAL 0) + message(SEND_ERROR "unexpected: ${VERSION_VAR} is VERSION_EQUAL 0") + endif() + if (NOT ${VERSION_VAR} VERSION_GREATER 0) + message(SEND_ERROR "unexpected: ${VERSION_VAR} is NOT VERSION_GREATER 0") + endif() + else() + message(SEND_ERROR "${MODULE_NAME}_FOUND is set but version number variable ${VERSION_VAR} is NOT DEFINED") + endif() + endif () +endmacro(check_version_string) + +# If any of these modules reported that it was found a version number should have been +# reported. + +foreach(VTEST ALSA ARMADILLO BZIP2 CUPS CURL EXPAT FREETYPE GETTEXT GIT HSPELL + JASPER LIBXML2 LIBXSLT PERL PostgreSQL TIFF ZLIB) + check_version_string(${VTEST} ${VTEST}_VERSION_STRING) +endforeach(VTEST) + +foreach(VTEST BISON Boost CUDA DOXYGEN FLEX GIF GTK2 LibArchive OPENSCENEGRAPH + RUBY SWIG) + check_version_string(${VTEST} ${VTEST}_VERSION) +endforeach(VTEST) + +check_version_string(PYTHONINTERP PYTHON_VERSION_STRING) +check_version_string(SUBVERSION Subversion_VERSION_SVN) +check_version_string(PKGCONFIG PKG_CONFIG_VERSION_STRING) diff --git a/Tests/CMakeOnly/CMakeLists.txt b/Tests/CMakeOnly/CMakeLists.txt new file mode 100644 index 000000000..a1551ca03 --- /dev/null +++ b/Tests/CMakeOnly/CMakeLists.txt @@ -0,0 +1,30 @@ +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Test.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake @ONLY) + +macro(add_CMakeOnly_test test) + add_test(CMakeOnly.${test} ${CMAKE_CMAKE_COMMAND} + -DTEST=${test} + -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake + ) +endmacro() + +add_CMakeOnly_test(LinkInterfaceLoop) +set_property(TEST CMakeOnly.LinkInterfaceLoop PROPERTY TIMEOUT 90) + +add_CMakeOnly_test(CheckSymbolExists) + +add_CMakeOnly_test(CheckCXXSymbolExists) + +add_CMakeOnly_test(CheckCXXCompilerFlag) + +add_CMakeOnly_test(CheckLanguage) + +add_CMakeOnly_test(AllFindModules) + +add_CMakeOnly_test(TargetScope) + +add_test(CMakeOnly.ProjectInclude ${CMAKE_CMAKE_COMMAND} + -DTEST=ProjectInclude + -DCMAKE_ARGS=-DCMAKE_PROJECT_ProjectInclude_INCLUDE=${CMAKE_CURRENT_SOURCE_DIR}/ProjectInclude/include.cmake + -P ${CMAKE_CURRENT_BINARY_DIR}/Test.cmake + ) diff --git a/Tests/Module/CheckCXXCompilerFlag/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt similarity index 86% rename from Tests/Module/CheckCXXCompilerFlag/CMakeLists.txt rename to Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt index 77f50060f..e205330b0 100644 --- a/Tests/Module/CheckCXXCompilerFlag/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckCXXCompilerFlag/CMakeLists.txt @@ -56,19 +56,3 @@ if(CMAKE_COMPILER_IS_GNUCXX) else() message("Unhandled Platform") endif() - -# -# This is a no-op executable... If this test is going to fail, it fails during -# the configure step while cmake is configuring this CMakeLists.txt file... -# - -file(WRITE - "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" - "int main() { return 0; } -" -) - -add_executable( - CheckCXXCompilerFlag - "${CMAKE_CURRENT_BINARY_DIR}/main.cxx" -) diff --git a/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt new file mode 100644 index 000000000..1c978c181 --- /dev/null +++ b/Tests/CMakeOnly/CheckCXXSymbolExists/CMakeLists.txt @@ -0,0 +1,62 @@ +# This test will verify if CheckCXXSymbolExists only report symbols available +# for linking that really are. You can find some documentation on this in +# bug 11333 where we found out that gcc would optimize out the actual +# reference to the symbol, so symbols that are in fact _not_ available in the +# given libraries (but seen in header) were reported as present. +# +# If you change this test do not forget to change the CheckSymbolExists +# test, too. + +PROJECT(CheckCXXSymbolExists CXX) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) + +SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/../CheckSymbolExists") + +INCLUDE(CheckCXXSymbolExists) + +foreach(_config_type Release RelWithDebInfo MinSizeRel Debug) + set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type}) + unset(CSE_RESULT_${_config_type} CACHE) + MESSAGE(STATUS "Testing configuration ${_config_type}") + check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type}) + + IF (CSE_RESULT_${_config_type}) + MESSAGE(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}") + ENDIF (CSE_RESULT_${_config_type}) +endforeach() + +set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE}) +unset(CSE_RESULT_ERRNO_CERRNO CACHE) + +MESSAGE(STATUS "Checking ") + +check_cxx_symbol_exists(errno "cerrno" CSE_RESULT_ERRNO_CERRNO) + +IF (NOT CSE_RESULT_ERRNO_CERRNO) + unset(CSE_RESULT_ERRNO_ERRNOH CACHE) + + MESSAGE(STATUS "Checking ") + + check_cxx_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO_ERRNOH) + + IF (NOT CSE_RESULT_ERRNO_ERRNOH) + MESSAGE(SEND_ERROR "CheckCXXSymbolExists did not find errno in and ") + ELSE (NOT CSE_RESULT_ERRNO_ERRNOH) + MESSAGE(STATUS "errno found in ") + ENDIF (NOT CSE_RESULT_ERRNO_ERRNOH) +ELSE (NOT CSE_RESULT_ERRNO_CERRNO) + MESSAGE(STATUS "errno found in ") +ENDIF (NOT CSE_RESULT_ERRNO_CERRNO) + +IF (CMAKE_COMPILER_IS_GNUCXX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") + unset(CSE_RESULT_O3 CACHE) + MESSAGE(STATUS "Testing with optimization -O3") + + check_cxx_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3) + + IF (CSE_RESULT_O3) + MESSAGE(SEND_ERROR "CheckCXXSymbolExists reported a nonexistent symbol as existing with optimization -O3") + ENDIF (CSE_RESULT_O3) +ENDIF (CMAKE_COMPILER_IS_GNUCXX) diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt new file mode 100644 index 000000000..f5336dc03 --- /dev/null +++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required (VERSION 2.8) +project(CheckLanguage NONE) +include(CheckLanguage) + +set(langs ) +set(expect_C 1) +set(expect_CXX 1) +unset(expect_Fortran) +set(expect_NoSuchLanguage 0) +foreach(lang C CXX Fortran NoSuchLanguage) + check_language(${lang}) + if(NOT DEFINED CMAKE_${lang}_COMPILER) + message(FATAL_ERROR "check_language(${lang}) did not set result") + endif() + if(DEFINED expect_${lang}) + if(expect_${lang} AND NOT CMAKE_${lang}_COMPILER) + message(FATAL_ERROR "check_language(${lang}) should not fail!") + elseif(NOT expect_${lang} AND CMAKE_${lang}_COMPILER) + message(FATAL_ERROR "check_language(${lang}) should not succeed!") + endif() + endif() +endforeach() diff --git a/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt new file mode 100644 index 000000000..7c969d3be --- /dev/null +++ b/Tests/CMakeOnly/CheckSymbolExists/CMakeLists.txt @@ -0,0 +1,51 @@ +# This test will verify if CheckSymbolExists only report symbols available +# for linking that really are. You can find some documentation on this in +# bug 11333 where we found out that gcc would optimize out the actual +# reference to the symbol, so symbols that are in fact _not_ available in the +# given libraries (but seen in header) were reported as present. +# +# If you change this test do not forget to change the CheckCXXSymbolExists +# test, too. + +PROJECT(CheckSymbolExists C) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) + +SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}") + +INCLUDE(CheckSymbolExists) + +foreach(_config_type Release RelWithDebInfo MinSizeRel Debug) + set(CMAKE_TRY_COMPILE_CONFIGURATION ${_config_type}) + unset(CSE_RESULT_${_config_type} CACHE) + MESSAGE(STATUS "Testing configuration ${_config_type}") + + check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_${_config_type}) + + IF (CSE_RESULT_${_config_type}) + MESSAGE(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing in configuration ${_config_type}") + ENDIF (CSE_RESULT_${_config_type}) +endforeach() + +set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE}) +unset(CSE_RESULT_ERRNO CACHE) + +check_symbol_exists(errno "errno.h" CSE_RESULT_ERRNO) + +IF (NOT CSE_RESULT_ERRNO) + MESSAGE(SEND_ERROR "CheckSymbolExists did not find errno in ") +ELSE (NOT CSE_RESULT_ERRNO) + MESSAGE(STATUS "errno found as expected") +ENDIF (NOT CSE_RESULT_ERRNO) + +IF (CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3") + unset(CSE_RESULT_O3 CACHE) + MESSAGE(STATUS "Testing with optimization -O3") + + check_symbol_exists(non_existent_function_for_symbol_test "cm_cse.h" CSE_RESULT_O3) + + IF (CSE_RESULT_O3) + MESSAGE(SEND_ERROR "CheckSymbolExists reported a nonexistent symbol as existing with optimization -O3") + ENDIF (CSE_RESULT_O3) +ENDIF (CMAKE_COMPILER_IS_GNUCC) diff --git a/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h new file mode 100644 index 000000000..4f41c7696 --- /dev/null +++ b/Tests/CMakeOnly/CheckSymbolExists/cm_cse.h @@ -0,0 +1,6 @@ +#ifndef _CSE_DUMMY_H +#define _CSE_DUMMY_H + +int non_existent_function_for_symbol_test(); + +#endif diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt b/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt new file mode 100644 index 000000000..56e449afd --- /dev/null +++ b/Tests/CMakeOnly/LinkInterfaceLoop/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required (VERSION 2.8) +project(LinkInterfaceLoop C) + +# Add a shared library that incorrectly names itself as a +# dependency, thus forming a cycle. +add_library(A SHARED IMPORTED) +set_target_properties(A PROPERTIES + IMPORTED_LINK_DEPENDENT_LIBRARIES A + IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dirA/A" + ) + +# Add a shared library that incorrectly names itself in +# its link interface, thus forming a cycle. +add_library(B SHARED IMPORTED) +set_target_properties(B PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES B + IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/dirB/B" + ) + +# Add a shared library with an empty link interface +# that depends on two shared libraries. +add_library(C SHARED lib.c) +set_property(TARGET C PROPERTY LINK_INTERFACE_LIBRARIES "") +target_link_libraries(C B A) + +add_executable(main main.c) +target_link_libraries(main C) diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/lib.c b/Tests/CMakeOnly/LinkInterfaceLoop/lib.c new file mode 100644 index 000000000..fede1d61f --- /dev/null +++ b/Tests/CMakeOnly/LinkInterfaceLoop/lib.c @@ -0,0 +1 @@ +int lib(void) { return 0; } diff --git a/Tests/CMakeOnly/LinkInterfaceLoop/main.c b/Tests/CMakeOnly/LinkInterfaceLoop/main.c new file mode 100644 index 000000000..78f2de106 --- /dev/null +++ b/Tests/CMakeOnly/LinkInterfaceLoop/main.c @@ -0,0 +1 @@ +int main(void) { return 0; } diff --git a/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt new file mode 100644 index 000000000..a9abb4ad7 --- /dev/null +++ b/Tests/CMakeOnly/ProjectInclude/CMakeLists.txt @@ -0,0 +1,4 @@ +project(ProjectInclude) +if(NOT AUTO_INCLUDE) + message(FATAL_ERROR "include file not found") +endif() diff --git a/Tests/CMakeOnly/ProjectInclude/include.cmake b/Tests/CMakeOnly/ProjectInclude/include.cmake new file mode 100644 index 000000000..527ebe7d0 --- /dev/null +++ b/Tests/CMakeOnly/ProjectInclude/include.cmake @@ -0,0 +1 @@ +set(AUTO_INCLUDE TRUE) diff --git a/Tests/CMakeOnly/TargetScope/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/CMakeLists.txt new file mode 100644 index 000000000..fa5d8e234 --- /dev/null +++ b/Tests/CMakeOnly/TargetScope/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required (VERSION 2.8) +project(TargetScope NONE) + +add_subdirectory(Sub) + +if(TARGET SubLibLocal) + message(FATAL_ERROR "SubLibLocal visible in top directory") +endif() +if(NOT TARGET SubLibGlobal) + message(FATAL_ERROR "SubLibGlobal not visible in top directory") +endif() + +add_subdirectory(Sib) diff --git a/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt new file mode 100644 index 000000000..7f6f4e8fd --- /dev/null +++ b/Tests/CMakeOnly/TargetScope/Sib/CMakeLists.txt @@ -0,0 +1,6 @@ +if(TARGET SubLibLocal) + message(FATAL_ERROR "SubLibLocal visible in sibling directory") +endif() +if(NOT TARGET SubLibGlobal) + message(FATAL_ERROR "SubLibGlobal not visible in sibling directory") +endif() diff --git a/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt new file mode 100644 index 000000000..27318f585 --- /dev/null +++ b/Tests/CMakeOnly/TargetScope/Sub/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(SubLibLocal UNKNOWN IMPORTED) +add_library(SubLibGlobal UNKNOWN IMPORTED GLOBAL) +add_subdirectory(Sub) +if(NOT TARGET SubLibLocal) + message(FATAL_ERROR "SubLibLocal not visible in own directory") +endif() +if(NOT TARGET SubLibGlobal) + message(FATAL_ERROR "SubLibGlobal not visible in own directory") +endif() diff --git a/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt b/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt new file mode 100644 index 000000000..a351daadf --- /dev/null +++ b/Tests/CMakeOnly/TargetScope/Sub/Sub/CMakeLists.txt @@ -0,0 +1,6 @@ +if(NOT TARGET SubLibLocal) + message(FATAL_ERROR "SubLibLocal not visible in subdirectory") +endif() +if(NOT TARGET SubLibGlobal) + message(FATAL_ERROR "SubLibGlobal not visible in subdirectory") +endif() diff --git a/Tests/CMakeOnly/Test.cmake.in b/Tests/CMakeOnly/Test.cmake.in new file mode 100644 index 000000000..42af06891 --- /dev/null +++ b/Tests/CMakeOnly/Test.cmake.in @@ -0,0 +1,13 @@ +set(source_dir "@CMAKE_CURRENT_SOURCE_DIR@/${TEST}") +set(binary_dir "@CMAKE_CURRENT_BINARY_DIR@/${TEST}-build") +file(REMOVE_RECURSE "${binary_dir}") +file(MAKE_DIRECTORY "${binary_dir}") +execute_process( + COMMAND ${CMAKE_COMMAND} ${CMAKE_ARGS} + "${source_dir}" -G "@CMAKE_TEST_GENERATOR@" + WORKING_DIRECTORY "${binary_dir}" + RESULT_VARIABLE result + ) +if(result) + message(FATAL_ERROR "CMake failed to configure ${TEST}") +endif() diff --git a/Tests/CMakeTests/CMakeLists.txt b/Tests/CMakeTests/CMakeLists.txt index fc1426e8e..c42c490b0 100644 --- a/Tests/CMakeTests/CMakeLists.txt +++ b/Tests/CMakeTests/CMakeLists.txt @@ -22,6 +22,7 @@ AddCMakeTest(ConfigureFile "") AddCMakeTest(SeparateArguments "") AddCMakeTest(ImplicitLinkInfo "") AddCMakeTest(ModuleNotices "") +AddCMakeTest(GetProperty "") AddCMakeTest(If "") AddCMakeTest(String "") AddCMakeTest(Math "") @@ -29,6 +30,7 @@ AddCMakeTest(CMakeMinimumRequired "") AddCMakeTest(CompilerIdVendor "") AddCMakeTest(ProcessorCount "") AddCMakeTest(PushCheckState "") +AddCMakeTest(While "") AddCMakeTest(FileDownload "") set_property(TEST CMake.FileDownload PROPERTY @@ -55,14 +57,13 @@ AddCMakeTest(GetPrerequisites "${GetPrerequisites_PreArgs}") # suite. It detects if any changes have been made to the CMake source tree # by any previous configure, build or test steps. # -if(do_cvs_tests OR GIT_EXECUTABLE) +if(GIT_EXECUTABLE) string(REPLACE "\\" "/" ENV_HOME "$ENV{HOME}") set(CheckSourceTree_PreArgs "-DCMake_BINARY_DIR:PATH=${CMake_BINARY_DIR}" "-DCMake_SOURCE_DIR:PATH=${CMake_SOURCE_DIR}" - "-DCVS_EXECUTABLE:STRING=${CVS_EXECUTABLE}" "-DGIT_EXECUTABLE:STRING=${GIT_EXECUTABLE}" "-DHOME:STRING=${ENV_HOME}" ) AddCMakeTest(CheckSourceTree "${CheckSourceTree_PreArgs}") -endif(do_cvs_tests OR GIT_EXECUTABLE) +endif() diff --git a/Tests/CMakeTests/CheckSourceTreeTest.cmake.in b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in index 73f8b013d..59b28904d 100644 --- a/Tests/CMakeTests/CheckSourceTreeTest.cmake.in +++ b/Tests/CMakeTests/CheckSourceTreeTest.cmake.in @@ -5,7 +5,6 @@ message("CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") message("") message("CMake_BINARY_DIR='${CMake_BINARY_DIR}'") message("CMake_SOURCE_DIR='${CMake_SOURCE_DIR}'") -message("CVS_EXECUTABLE='${CVS_EXECUTABLE}'") message("GIT_EXECUTABLE='${GIT_EXECUTABLE}'") message("HOME='${HOME}'") message("ENV{DASHBOARD_TEST_FROM_CTEST}='$ENV{DASHBOARD_TEST_FROM_CTEST}'") @@ -43,7 +42,7 @@ message("in_source_build='${in_source_build}'") message("") -# If this does not appear to be a git or CVS checkout, just pass the test here +# If this does not appear to be a git checkout, just pass the test here # and now. (Do not let the test fail if it is run in a tree *exported* from a # repository or unpacked from a .zip file source installer...) # @@ -52,29 +51,13 @@ if(EXISTS "${CMake_SOURCE_DIR}/.git") set(is_git_checkout 1) endif() -set(is_cvs_checkout 0) -if(EXISTS "${CMake_SOURCE_DIR}/CVS/Root") - set(is_cvs_checkout 1) -endif() - message("is_git_checkout='${is_git_checkout}'") -message("is_cvs_checkout='${is_cvs_checkout}'") message("") -if(NOT is_cvs_checkout) if(NOT is_git_checkout) - message("source tree is neither git nor CVS checkout... test passes by early return...") + message("source tree is not a git checkout... test passes by early return...") return() endif() -endif() - -if(is_cvs_checkout) -if(is_git_checkout) - message("warning: source tree has both git *and* CVS file system bits???") - # should this condition be a FATAL_ERROR test failure...? -endif() -endif() - # This test looks for the following types of changes in the source tree: # @@ -83,51 +66,13 @@ set(conflicts 0) set(modifications 0) set(nonadditions 0) -# ov == output variable... conditionally filled in by either cvs or git below: +# ov == output variable... conditionally filled in by either git below: # set(cmd "") set(ov "") set(ev "") set(rv "") - -if(is_cvs_checkout AND CVS_EXECUTABLE) - # Check with "cvs -q -n up -dP" if there are any local modifications to the - # CMake source tree: - # - message("=============================================================================") - message("This is a cvs checkout, using cvs to verify source tree....") - message("") - - execute_process(COMMAND ${CVS_EXECUTABLE} --version - WORKING_DIRECTORY ${CMake_SOURCE_DIR} - OUTPUT_VARIABLE version_output - OUTPUT_STRIP_TRAILING_WHITESPACE) - message("=== output of 'cvs --version' ===") - message("${version_output}") - message("=== end output ===") - message("") - - file(READ "${CMake_SOURCE_DIR}/CVS/Root" contents) - message("=== content of CVS/Root ===") - message("${contents}") - message("=== end content ===") - message("") - - file(READ "${CMake_SOURCE_DIR}/CVS/Repository" contents) - message("=== content of CVS/Repository ===") - message("${contents}") - message("=== end content ===") - message("") - - message("Copy/paste this command to reproduce:") - message("cd \"${CMake_SOURCE_DIR}\" && \"${CVS_EXECUTABLE}\" -q -n up -dP") - message("") - - set(cmd ${CVS_EXECUTABLE} -q -n up -dP) -endif() - - # If no GIT_EXECUTABLE, see if we can figure out which git was used # for the ctest_update step on this dashboard... # @@ -268,8 +213,8 @@ endif() if(cmd) - # Use the HOME value passed in to the script for calling cvs/git so it can - # find its .cvspass or user/global config settings... + # Use the HOME value passed in to the script for calling git so it can + # find its user/global config settings... # set(original_ENV_HOME "$ENV{HOME}") set(ENV{HOME} "${HOME}") @@ -322,28 +267,6 @@ if(NOT ov STREQUAL "") endif() if(consider) - if(is_cvs_checkout) - if(line MATCHES "^A ") - message(" locally added file/directory detected...") - set(additions 1) - endif() - - if(line MATCHES "^C ") - message(" conflict detected...") - set(conflicts 1) - endif() - - if(line MATCHES "^M ") - message(" locally modified file detected...") - set(modifications 1) - endif() - - if(line MATCHES "^\\? ") - message(" locally non-added file/directory detected...") - set(nonadditions 1) - endif() - endif() - if(is_git_checkout) if(line MATCHES "^#[ \t]*modified:") message(" locally modified file detected...") diff --git a/Tests/CMakeTests/GetProperty-Bad-Argument.cmake b/Tests/CMakeTests/GetProperty-Bad-Argument.cmake new file mode 100644 index 000000000..382dabb50 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Bad-Argument.cmake @@ -0,0 +1 @@ +get_property(FOO GLOBAL PROPERTY FOO FOO) diff --git a/Tests/CMakeTests/GetProperty-Bad-Directory.cmake b/Tests/CMakeTests/GetProperty-Bad-Directory.cmake new file mode 100644 index 000000000..cdbfa807c --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Bad-Directory.cmake @@ -0,0 +1 @@ +get_property(FOO DIRECTORY NonExistentSubDir PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-Bad-Scope.cmake b/Tests/CMakeTests/GetProperty-Bad-Scope.cmake new file mode 100644 index 000000000..ea8566b50 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Bad-Scope.cmake @@ -0,0 +1 @@ +get_property(FOO FOO FOO) diff --git a/Tests/CMakeTests/GetProperty-Bad-Target.cmake b/Tests/CMakeTests/GetProperty-Bad-Target.cmake new file mode 100644 index 000000000..9992dabed --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Bad-Target.cmake @@ -0,0 +1 @@ +get_property(FOO TARGET FOO PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-Bad-Test.cmake b/Tests/CMakeTests/GetProperty-Bad-Test.cmake new file mode 100644 index 000000000..44bf3ebc5 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Bad-Test.cmake @@ -0,0 +1 @@ +get_property(FOO TEST FOO PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-Doc-Properties.cmake b/Tests/CMakeTests/GetProperty-Doc-Properties.cmake new file mode 100644 index 000000000..6c2c3620e --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Doc-Properties.cmake @@ -0,0 +1,10 @@ +get_property(FOO_BRIEF GLOBAL PROPERTY FOO BRIEF_DOCS) +get_property(FOO_FULL GLOBAL PROPERTY FOO FULL_DOCS) + +if (NOT FOO_BRIEF STREQUAL "NOTFOUND") + message(SEND_ERROR "property FOO has BRIEF_DOCS set to '${FOO_BRIEF}'") +endif () + +if (NOT FOO_FULL STREQUAL "NOTFOUND") + message(SEND_ERROR "property FOO has FULL_DOCS set to '${FOO_FULL}'") +endif () diff --git a/Tests/CMakeTests/GetProperty-Global-Name.cmake b/Tests/CMakeTests/GetProperty-Global-Name.cmake new file mode 100644 index 000000000..497700cb3 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Global-Name.cmake @@ -0,0 +1 @@ +get_property(FOO GLOBAL FOO PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-Missing-Argument.cmake b/Tests/CMakeTests/GetProperty-Missing-Argument.cmake new file mode 100644 index 000000000..f0d004dc4 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Missing-Argument.cmake @@ -0,0 +1 @@ +get_property() diff --git a/Tests/CMakeTests/GetProperty-No-Cache.cmake b/Tests/CMakeTests/GetProperty-No-Cache.cmake new file mode 100644 index 000000000..9719fe775 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-No-Cache.cmake @@ -0,0 +1 @@ +get_property(FOO CACHE PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-No-Property.cmake b/Tests/CMakeTests/GetProperty-No-Property.cmake new file mode 100644 index 000000000..bee230d9b --- /dev/null +++ b/Tests/CMakeTests/GetProperty-No-Property.cmake @@ -0,0 +1 @@ +get_property(FOO GLOBAL PROPERTY) diff --git a/Tests/CMakeTests/GetProperty-No-Source.cmake b/Tests/CMakeTests/GetProperty-No-Source.cmake new file mode 100644 index 000000000..89773c810 --- /dev/null +++ b/Tests/CMakeTests/GetProperty-No-Source.cmake @@ -0,0 +1 @@ +get_property(FOO SOURCE PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-No-Target.cmake b/Tests/CMakeTests/GetProperty-No-Target.cmake new file mode 100644 index 000000000..8f1fa23af --- /dev/null +++ b/Tests/CMakeTests/GetProperty-No-Target.cmake @@ -0,0 +1 @@ +get_property(FOO TARGET PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-No-Test.cmake b/Tests/CMakeTests/GetProperty-No-Test.cmake new file mode 100644 index 000000000..045bd56ec --- /dev/null +++ b/Tests/CMakeTests/GetProperty-No-Test.cmake @@ -0,0 +1 @@ +get_property(FOO TEST PROPERTY FOO) diff --git a/Tests/CMakeTests/GetProperty-Variable-Name.cmake b/Tests/CMakeTests/GetProperty-Variable-Name.cmake new file mode 100644 index 000000000..9190f80ad --- /dev/null +++ b/Tests/CMakeTests/GetProperty-Variable-Name.cmake @@ -0,0 +1 @@ +get_property(FOO VARIABLE FOO PROPERTY FOO) diff --git a/Tests/CMakeTests/GetPropertyTest.cmake.in b/Tests/CMakeTests/GetPropertyTest.cmake.in new file mode 100644 index 000000000..ab96e5b52 --- /dev/null +++ b/Tests/CMakeTests/GetPropertyTest.cmake.in @@ -0,0 +1,98 @@ +include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake") + +set(Missing-Argument-RESULT 1) +set(Missing-Argument-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Missing-Argument.cmake:1 \\(get_property\\):.*get_property called with incorrect number of arguments.*") + +check_cmake_test(GetProperty + Missing-Argument +) + +set(Bad-Scope-RESULT 1) +set(Bad-Scope-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Bad-Scope.cmake:1 \\(get_property\\):.*get_property given invalid scope FOO\\..*") + +check_cmake_test(GetProperty + Bad-Scope +) + +set(Bad-Argument-RESULT 1) +set(Bad-Argument-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Bad-Argument.cmake:1 \\(get_property\\):.*get_property given invalid argument \"FOO\"\\..*") + +check_cmake_test(GetProperty + Bad-Argument +) + +set(No-Property-RESULT 1) +set(No-Property-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-No-Property.cmake:1 \\(get_property\\):.*get_property not given a PROPERTY argument\\..*") + +check_cmake_test(GetProperty + No-Property +) + +set(Doc-Properties-RESULT 0) + +check_cmake_test(GetProperty + Doc-Properties +) + +set(Global-Name-RESULT 1) +set(Global-Name-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Global-Name.cmake:1 \\(get_property\\):.*get_property given name for GLOBAL scope\\..*") + +check_cmake_test(GetProperty + Global-Name +) + +set(Bad-Directory-RESULT 1) +set(Bad-Directory-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Bad-Directory.cmake:1 \\(get_property\\):.*get_property DIRECTORY scope provided but requested directory was not.*found\\..*") + +check_cmake_test(GetProperty + Bad-Directory +) + +set(No-Target-RESULT 1) +set(No-Target-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-No-Target.cmake:1 \\(get_property\\):.*get_property not given name for TARGET scope\\..*") + +check_cmake_test(GetProperty + No-Target +) + +set(Bad-Target-RESULT 1) +set(Bad-Target-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Bad-Target.cmake:1 \\(get_property\\):.*get_property could not find TARGET FOO\\..*") + +check_cmake_test(GetProperty + Bad-Target +) + +set(No-Source-RESULT 1) +set(No-Source-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-No-Source.cmake:1 \\(get_property\\):.*get_property not given name for SOURCE scope\\..*") + +check_cmake_test(GetProperty + No-Source +) + +set(No-Test-RESULT 1) +set(No-Test-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-No-Test.cmake:1 \\(get_property\\):.*get_property not given name for TEST scope\\..*") + +check_cmake_test(GetProperty + No-Test +) + +set(Bad-Test-RESULT 1) +set(Bad-Test-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Bad-Test.cmake:1 \\(get_property\\):.*get_property given TEST name that does not exist: FOO.*") + +check_cmake_test(GetProperty + Bad-Test +) + +set(Variable-Name-RESULT 1) +set(Variable-Name-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-Variable-Name.cmake:1 \\(get_property\\):.*get_property given name for VARIABLE scope\\..*") + +check_cmake_test(GetProperty + Variable-Name +) + +set(No-Cache-RESULT 1) +set(No-Cache-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?GetProperty-No-Cache.cmake:1 \\(get_property\\):.*get_property not given name for CACHE scope\\..*") + +check_cmake_test(GetProperty + No-Cache +) diff --git a/Tests/CMakeTests/If-Invalid-Argument.cmake b/Tests/CMakeTests/If-Invalid-Argument.cmake new file mode 100644 index 000000000..b4fb97f41 --- /dev/null +++ b/Tests/CMakeTests/If-Invalid-Argument.cmake @@ -0,0 +1,2 @@ +if (NOT foo bar STREQUAL "foo bar") +endif() diff --git a/Tests/CMakeTests/IfTest.cmake.in b/Tests/CMakeTests/IfTest.cmake.in index e5211b4fa..639e22672 100644 --- a/Tests/CMakeTests/IfTest.cmake.in +++ b/Tests/CMakeTests/IfTest.cmake.in @@ -156,3 +156,11 @@ foreach(_bad 2x -2x) endforeach() test_vars("") + +set(Invalid-Argument-RESULT 1) +set(Invalid-Argument-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?If-Invalid-Argument.cmake:1 \\(if\\):.*Unknown arguments specified.*") + +include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake") +check_cmake_test(If + Invalid-Argument +) diff --git a/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake b/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake new file mode 100644 index 000000000..886d98c7c --- /dev/null +++ b/Tests/CMakeTests/While-Endwhile-Alone-Args.cmake @@ -0,0 +1 @@ +endwhile(a) diff --git a/Tests/CMakeTests/While-Endwhile-Alone.cmake b/Tests/CMakeTests/While-Endwhile-Alone.cmake new file mode 100644 index 000000000..82c09a07b --- /dev/null +++ b/Tests/CMakeTests/While-Endwhile-Alone.cmake @@ -0,0 +1 @@ +endwhile() diff --git a/Tests/CMakeTests/While-Endwhile-Mismatch.cmake b/Tests/CMakeTests/While-Endwhile-Mismatch.cmake new file mode 100644 index 000000000..5c338d697 --- /dev/null +++ b/Tests/CMakeTests/While-Endwhile-Mismatch.cmake @@ -0,0 +1,2 @@ +while(a) +endwhile(b) diff --git a/Tests/CMakeTests/While-Missing-Argument.cmake b/Tests/CMakeTests/While-Missing-Argument.cmake new file mode 100644 index 000000000..32eaa2698 --- /dev/null +++ b/Tests/CMakeTests/While-Missing-Argument.cmake @@ -0,0 +1 @@ +while() diff --git a/Tests/CMakeTests/While-Missing-Endwhile.cmake b/Tests/CMakeTests/While-Missing-Endwhile.cmake new file mode 100644 index 000000000..1abaaaf2b --- /dev/null +++ b/Tests/CMakeTests/While-Missing-Endwhile.cmake @@ -0,0 +1 @@ +while(a) diff --git a/Tests/CMakeTests/WhileTest.cmake.in b/Tests/CMakeTests/WhileTest.cmake.in new file mode 100644 index 000000000..4693f2d8f --- /dev/null +++ b/Tests/CMakeTests/WhileTest.cmake.in @@ -0,0 +1,53 @@ +set(NUMBERS "") +set(COUNT 0) + +while(COUNT LESS 200) + set(NUMBERS "${NUMBERS} ${COUNT}") + set(COUNT "2${COUNT}") + + set(NCOUNT 3) + while(NCOUNT LESS 31) + set(NUMBERS "${NUMBERS} ${NCOUNT}") + set(NCOUNT "${NCOUNT}0") + endwhile() +endwhile(COUNT LESS 200) + +if(NOT NUMBERS STREQUAL " 0 3 30 20 3 30") + message(SEND_ERROR "while loop nesting error, result: '${NUMBERS}'") +endif() + +set(Missing-Argument-RESULT 1) +set(Missing-Argument-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?While-Missing-Argument.cmake:1 \\(while\\):.*while called with incorrect number of arguments.*") + +include("@CMAKE_CURRENT_SOURCE_DIR@/CheckCMakeTest.cmake") +check_cmake_test(While + Missing-Argument +) + +set(Missing-Endwhile-RESULT 1) +set(Missing-Endwhile-STDERR ".*CMake Error in (@CMAKE_CURRENT_SOURCE_DIR@/)?While-Missing-Endwhile.cmake:.*A logical block opening on the line.*(@CMAKE_CURRENT_SOURCE_DIR@/)?While-Missing-Endwhile.cmake:1 \\(while\\).*is not closed\\..*") + +check_cmake_test(While + Missing-Endwhile +) + +set(Endwhile-Mismatch-RESULT 0) +set(Endwhile-Mismatch-STDERR ".*CMake Warning \\(dev\\) in (@CMAKE_CURRENT_SOURCE_DIR@/)?While-Endwhile-Mismatch.cmake:.*A logical block opening on the line.*(@CMAKE_CURRENT_SOURCE_DIR@/)?While-Endwhile-Mismatch.cmake:1 \\(while\\).*with mis-matching arguments\\..*") + +check_cmake_test(While + Endwhile-Mismatch +) + +set(Endwhile-Alone-RESULT 1) +set(Endwhile-Alone-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?While-Endwhile-Alone.cmake:1 \\(endwhile\\):.*An ENDWHILE command was found outside of a proper WHILE ENDWHILE.*structure\\.\n.*$") + +check_cmake_test(While + Endwhile-Alone +) + +set(Endwhile-Alone-Args-RESULT 1) +set(Endwhile-Alone-Args-STDERR ".*CMake Error at (@CMAKE_CURRENT_SOURCE_DIR@/)?While-Endwhile-Alone-Args.cmake:1 \\(endwhile\\):.*An ENDWHILE command was found outside of a proper WHILE ENDWHILE.*structure\\. Or its arguments did not.*$") + +check_cmake_test(While + Endwhile-Alone-Args +) diff --git a/Tests/COnly/CMakeLists.txt b/Tests/COnly/CMakeLists.txt index 77420555f..5ef0f1eea 100644 --- a/Tests/COnly/CMakeLists.txt +++ b/Tests/COnly/CMakeLists.txt @@ -19,3 +19,5 @@ if("${LANG}" STREQUAL "C") else("${LANG}" STREQUAL "C") message(FATAL_ERROR "Bad language for file conly.c") endif("${LANG}" STREQUAL "C") + +add_library(testCModule MODULE testCModule.c) diff --git a/Tests/COnly/testCModule.c b/Tests/COnly/testCModule.c new file mode 100644 index 000000000..1a89292b3 --- /dev/null +++ b/Tests/COnly/testCModule.c @@ -0,0 +1,6 @@ +#ifdef _WIN32 +# define TEST_EXPORT __declspec(dllexport) +#else +# define TEST_EXPORT +#endif +TEST_EXPORT int testCModule(void) { return 0; } diff --git a/Tests/CTestUpdateCVS.cmake.in b/Tests/CTestUpdateCVS.cmake.in index a04673e25..f7f5db65d 100644 --- a/Tests/CTestUpdateCVS.cmake.in +++ b/Tests/CTestUpdateCVS.cmake.in @@ -18,6 +18,19 @@ set(CVS "@CVS_EXECUTABLE@") message(" cvs = ${CVS}") set(REPO ${TOP}/repo) + +# The MSYS cvs tool interprets "c:/" as a "machine:" name for SSH. +# Detect the MSYS cvs and convert the repo path to an MSYS path. +if(WIN32) + if(EXISTS "${CVS}") + file(STRINGS "${CVS}" cvs_is_msys LIMIT_COUNT 1 REGEX "[Mm][Ss][Yy][Ss]") + if(cvs_is_msys) + message(" '${CVS}' is from MSYS (contains '${cvs_is_msys}')") + string(REGEX REPLACE "^([A-Za-z]):" "/\\1" REPO "${REPO}") + endif() + endif() +endif() + set(CVSCMD ${CVS} -d${REPO}) # CVSNT requires an extra option to 'cvs init'. diff --git a/Tests/CTestUpdateHG.cmake.in b/Tests/CTestUpdateHG.cmake.in index 543ddd92a..640d2c6f3 100644 --- a/Tests/CTestUpdateHG.cmake.in +++ b/Tests/CTestUpdateHG.cmake.in @@ -28,7 +28,10 @@ run_child( WORKING_DIRECTORY ${TOP}/repo.hg COMMAND ${HG} init ) -set(REPO file://${TOP}/repo.hg) +if(NOT "${TOP}" MATCHES "^/") + set(slash /) +endif() +set(REPO file://${slash}${TOP}/repo.hg) #----------------------------------------------------------------------------- # Import initial content into the repository. diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt index 8d6029a9f..ec3ad3985 100644 --- a/Tests/Complex/CMakeLists.txt +++ b/Tests/Complex/CMakeLists.txt @@ -17,9 +17,6 @@ ENDIF(POLICY CMP0003) # Test building without per-rule echo lines in Makefiles. SET_PROPERTY(GLOBAL PROPERTY RULE_MESSAGES OFF) -# Choose whether to test CMakeLib. -OPTION(COMPLEX_TEST_CMAKELIB "Test CMakeLib" OFF) - SET(CPACK_SOURCE_IGNORE_FILES "~$;\\.cvsignore$;^C:/hoffman/My Builds/testcase.*/CVS/;^C:/hoffman/My Builds/testcase.*/\\.svn/;^C:/hoffman/My Builds/testcase.*/sweigart/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/eos2001/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_tables_new/;^C:/hoffman/My Builds/testcase/COPYING$;^C:/hoffman/My Builds/testcase/INSTALL$;^C:/hoffman/My Builds/testcase/Makefile$;^C:/hoffman/My Builds/testcase/Makefile\\.in$;^C:/hoffman/My Builds/testcase/.*\\.lo$;^C:/hoffman/My Builds/testcase/.*\\.la$;^C:/hoffman/My Builds/testcase/mkinstalldirs$;^C:/hoffman/My Builds/testcase/missing$;^C:/hoffman/My Builds/testcase/ltmain\\.sh$;^C:/hoffman/My Builds/testcase/libtool$;^C:/hoffman/My Builds/testcase/install-sh$;^C:/hoffman/My Builds/testcase/configure$;^C:/hoffman/My Builds/testcase/config\\.sub$;^C:/hoffman/My Builds/testcase/config\\.status$;^C:/hoffman/My Builds/testcase/config\\.log$;^C:/hoffman/My Builds/testcase/config\\.guess$;^C:/hoffman/My Builds/testcase/autom4te\\.cache$;^C:/hoffman/My Builds/testcase/aclocal\\.m4$;^C:/hoffman/My Builds/testcase/depcomp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10_corr$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_scvh$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.rgbtip\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.zahb\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.085\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.mem$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.tex\\.bak$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j16\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j26\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j36\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_JNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Jseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_KNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Kseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check34_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check35_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check36_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check43_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check44_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check45_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check46_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check47_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check48_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/Makefile$;^C:/hoffman/My Builds/testcase/www/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/.*\\.flc$;^C:/hoffman/My Builds/testcase/src/Makefile$;^C:/hoffman/My Builds/testcase/src/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/\\.deps$;^C:/hoffman/My Builds/testcase/src/\\.libs$;^C:/hoffman/My Builds/testcase/src/.*\\.la$;^C:/hoffman/My Builds/testcase/src/.*\\.lo$;^C:/hoffman/My Builds/testcase/src/make\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/statef.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_15$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_rel$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/hot_post_agb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgb_tip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/start_shellflash\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/white_dwarf\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/3order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/5order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/8order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check8_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check5_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effoo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/tc\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/include/Makefile\\.in$;^C:/hoffman/My Builds/testcase/include/Makefile$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/0\\.1\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_eos1a-eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_0\\.1\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_eos1a-eos1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/fort\\.91$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/oldversion_grid$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2005Ap&SS\\.298\\.\\.135S\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2007Ap&SS\\.307\\.\\.263C\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/astro-ph\\.9909168_eprint_submitted_to_High_Press\\.Res\\.16,331\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/statef_grid-newversion$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/old$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/make\\.out.*$;^C:/hoffman/My Builds/testcase/utils/.*\\.flc$;^C:/hoffman/My Builds/testcase/utils/Makefile$;^C:/hoffman/My Builds/testcase/utils/Makefile\\.in$;^C:/hoffman/My Builds/testcase/utils/\\.deps$;^C:/hoffman/My Builds/testcase/utils/\\.libs$;^C:/hoffman/My Builds/testcase/utils/.*\\.la$;^C:/hoffman/My Builds/testcase/utils/.*\\.lo$;^C:/hoffman/My Builds/testcase/utils/free_eos_test$;^C:/hoffman/My Builds/testcase/utils/test_rosenbrock$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check5\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check8\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_checknr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effoo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence_20070613$;^C:/hoffman/My Builds/testcase/www/eospaper/text$;^C:/hoffman/My Builds/testcase/www/eospaper/cassisi_book_fig$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.1\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/2\\.0\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.2\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.3\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.4\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.5\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.6\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/figures$;^C:/hoffman/My Builds/testcase/www/eospaper/old$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_JNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Jseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_KNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Kseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check34\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check35\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check36\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check44\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check45\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check46\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_1_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_2_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_linear_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_nr_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_series_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.1\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.3\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_linear\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_nr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.rgbtip\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.zahb\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.rgbtip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_linear$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_noexchange$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_nr$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/delta\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos1gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos2gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb_adjust/coulomb_adjust\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/rtc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/make\\.out.*$") # @@ -119,8 +116,6 @@ ENDIF(${fooCACHE_TEST_VAR2} MATCHES bar) # INCLUDE_DIRECTORIES( Library - ${Complex_SOURCE_DIR}/../../Source - ${Complex_BINARY_DIR}/../../Source ) INCLUDE_DIRECTORIES(BEFORE @@ -204,7 +199,9 @@ CONFIGURE_FILE( ${Complex_SOURCE_DIR}/Library/dummy ${Complex_BINARY_DIR}/Library/dummylib.lib COPYONLY IMMEDIATE) -FOREACH (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl) +FOREACH (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl + ${CMAKE_SHARED_LIBRARY_SUFFIX}.2 + ${CMAKE_STATIC_LIBRARY_SUFFIX}.2) CONFIGURE_FILE( ${Complex_SOURCE_DIR}/Library/dummy ${Complex_BINARY_DIR}/Library/libdummylib${ext} @@ -221,6 +218,34 @@ FIND_LIBRARY(FIND_DUMMY_LIB PATHS ${Complex_BINARY_DIR}/Library DOC "find dummy lib") +# This doesn't work for platforms that have a shared library and an import +# library, like Windows with .dll and .lib. Limit is to ".so" now because it's +# known to work there. +IF(CMAKE_SHARED_LIBRARY_SUFFIX STREQUAL ".so") + FIND_LIBRARY(FIND_DUMMY_SHLIB_VERSIONED + NAMES libdummylib${CMAKE_SHARED_LIBRARY_SUFFIX}.2 + PATHS ${Complex_BINARY_DIR}/Library + DOC "find versioned dummy shared lib" + NO_DEFAULT_PATH) + + IF(NOT FIND_DUMMY_SHLIB_VERSIONED MATCHES "/libdummylib${CMAKE_SHARED_LIBRARY_SUFFIX}.2") + MESSAGE(SEND_ERROR "FIND_DUMMY_SHLIB_VERSIONED is not set correctly: " + "${FIND_DUMMY_SHLIB_VERSIONED}") + ENDIF() +ENDIF() + +# Static library, should work everywhere +FIND_LIBRARY(FIND_DUMMY_STLIB_VERSIONED + NAMES libdummylib${CMAKE_STATIC_LIBRARY_SUFFIX}.2 + PATHS ${Complex_BINARY_DIR}/Library + DOC "find versioned dummy static lib" + NO_DEFAULT_PATH) + +IF(NOT FIND_DUMMY_STLIB_VERSIONED MATCHES "/libdummylib${CMAKE_STATIC_LIBRARY_SUFFIX}.2") + MESSAGE(SEND_ERROR "FIND_DUMMY_STLIB_VERSIONED is not set correctly: " + "${FIND_DUMMY_STLIB_VERSIONED}") +ENDIF() + # # Test SET_SOURCE_FILES_PROPERTIES # diff --git a/Tests/Complex/Executable/A.cxx b/Tests/Complex/Executable/A.cxx index 0cc995af0..fb3eb0819 100644 --- a/Tests/Complex/Executable/A.cxx +++ b/Tests/Complex/Executable/A.cxx @@ -1,7 +1,9 @@ // Include code from a header that should not be compiled separately. #include "A.hh" +#include int main() { - return A(); + printf("#define A_VALUE %d\n", A()); + return 0; } diff --git a/Tests/Complex/Executable/CMakeLists.txt b/Tests/Complex/Executable/CMakeLists.txt index 08cc7d45b..345836257 100644 --- a/Tests/Complex/Executable/CMakeLists.txt +++ b/Tests/Complex/Executable/CMakeLists.txt @@ -5,25 +5,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") -IF(COMPLEX_TEST_CMAKELIB) - # Link to CMake lib - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib) - # prefer the new curl if it is around - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0/lib) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES( - ${Complex_BINARY_DIR}/../../Utilities/cmlibarchive/libarchive - ${Complex_BINARY_DIR}/../../Utilities/cmbzip2 - ) -ENDIF(COMPLEX_TEST_CMAKELIB) - # Create an imported target for if(TARGET) test below. ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED) @@ -55,14 +36,13 @@ SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES HEADER_FILE_ONLY 1) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt) -ADD_EXECUTABLE(complex complex testcflags.c ) +ADD_CUSTOM_COMMAND(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM) +ADD_EXECUTABLE(complex complex testcflags.c Aout.h) # Sub1/NameConflictTest.c Sub2/NameConflictTest.c) ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx complex_nobuild.c) -IF(COMPLEX_TEST_CMAKELIB) - TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmlibarchive cmbzip2 cmcurl) -ENDIF(COMPLEX_TEST_CMAKELIB) IF (UNIX) TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS}) diff --git a/Tests/Complex/Executable/complex.cxx b/Tests/Complex/Executable/complex.cxx index 0ecd8fe2e..1901d9914 100644 --- a/Tests/Complex/Executable/complex.cxx +++ b/Tests/Complex/Executable/complex.cxx @@ -3,23 +3,21 @@ #include "cmTestGeneratedHeader.h" #include "cmVersion.h" #include "ExtraSources/file1.h" +#include "Aout.h" #include "file2.h" #include "sharedFile.h" extern "C" { #include "testConly.h" } -#ifdef COMPLEX_TEST_CMAKELIB -#include "cmStandardIncludes.h" -#include "cmSystemTools.h" -#include "cmDynamicLoader.h" -#include "cmSystemTools.h" -#include "cmGeneratedFileStream.h" -#include -#else #include #include #include #include + +#include +#include +#if !defined(S_ISDIR) +# define S_ISDIR(mode) ((mode) & _S_IFDIR) #endif #ifdef COMPLEX_TEST_LINK_STATIC @@ -67,18 +65,18 @@ void cmPassed(const char* Message, const char* m2="") # error Per-configuration directory-level definition not inherited. #endif -#ifdef COMPLEX_TEST_CMAKELIB // ====================================================================== void TestAndRemoveFile(const char* filename) { - if (!cmSystemTools::FileExists(filename)) + struct stat st; + if(stat(filename, &st) < 0) { cmFailed("Could not find file: ", filename); } else { - if (!cmSystemTools::RemoveFile(filename)) + if (remove(filename) < 0) { cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); } @@ -93,104 +91,16 @@ void TestAndRemoveFile(const char* filename) void TestDir(const char* filename) { - if (!cmSystemTools::FileExists(filename)) + struct stat st; + if(stat(filename, &st) < 0 || !S_ISDIR(st.st_mode)) { cmFailed("Could not find dir: ", filename); } else { - if (!cmSystemTools::FileIsDirectory(filename)) - { - cmFailed("Unable to check if file is a directory: ", filename); - } - else - { - cmPassed("Find dir: ", filename); - } - } -} - -// ====================================================================== - -void TestCMGeneratedFileSTream() -{ - cmGeneratedFileStream gm; - std::string file1 = std::string(BINARY_DIR) + std::string("/generatedFile1"); - std::string file2 = std::string(BINARY_DIR) + std::string("/generatedFile2"); - std::string file3 = std::string(BINARY_DIR) + std::string("/generatedFile3"); - std::string file4 = std::string(BINARY_DIR) + std::string("/generatedFile4"); - std::string file1tmp = file1 + ".tmp"; - std::string file2tmp = file2 + ".tmp"; - std::string file3tmp = file3 + ".tmp"; - std::string file4tmp = file4 + ".tmp"; - gm.Open(file1.c_str()); - gm << "This is generated file 1"; - gm.Close(); - gm.Open(file2.c_str()); - gm << "This is generated file 2"; - gm.Close(); - gm.Open(file3.c_str()); - gm << "This is generated file 3"; - gm.Close(); - gm.Open(file4.c_str()); - gm << "This is generated file 4"; - gm.Close(); - if ( cmSystemTools::FileExists(file1.c_str()) ) - { - if ( cmSystemTools::FileExists(file2.c_str()) ) - { - if ( cmSystemTools::FileExists(file3.c_str()) ) - { - if ( cmSystemTools::FileExists(file4.c_str()) ) - { - if ( cmSystemTools::FileExists(file1tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file2tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file3tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file4tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str()); - } - else - { - cmPassed("cmGeneratedFileStream works."); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str()); + cmPassed("Find dir: ", filename); } - cmSystemTools::RemoveFile(file1.c_str()); - cmSystemTools::RemoveFile(file2.c_str()); - cmSystemTools::RemoveFile(file3.c_str()); - cmSystemTools::RemoveFile(file1tmp.c_str()); - cmSystemTools::RemoveFile(file2tmp.c_str()); - cmSystemTools::RemoveFile(file3tmp.c_str()); } -#endif // Here is a stupid function that tries to use std::string methods // so that the dec cxx compiler will instantiate the stuff that @@ -232,113 +142,6 @@ extern "C" int NameConflictTest2(); int main() { - std::string lib = BINARY_DIR; - lib += "/lib/"; -#ifdef CMAKE_INTDIR - lib += CMAKE_INTDIR; - lib += "/"; -#endif - std::string exe = BINARY_DIR; - exe += "/bin/"; -#ifdef CMAKE_INTDIR - exe += CMAKE_INTDIR; - exe += "/"; -#endif - -#ifdef COMPLEX_TEST_CMAKELIB - // Test a single character executable to test a: in makefiles - exe += "A"; - exe += cmSystemTools::GetExecutableExtension(); - int ret; - std::string errorMessage; - exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); - if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) - { - if(ret != 10) - { - errorMessage += exe; - errorMessage += " did not return 10"; - } - } - else - { - errorMessage += exe; - errorMessage += ": failed to run."; - } - if(errorMessage.size()) - { - cmFailed(errorMessage.c_str()); - } - else - { - cmPassed("run Single Character executable A returned 10 as expected."); - } - - lib += CMAKE_SHARED_MODULE_PREFIX; - lib += "CMakeTestModule"; - lib += CMAKE_SHARED_MODULE_SUFFIX; - cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str()); - if(!handle) - { - std::string err = "Can not open CMakeTestModule:\n"; - err += lib; - cmFailed(err.c_str()); - } - else - { - cmsys::DynamicLoader::SymbolPointer fun = - cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); - if(!fun) - { - fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction"); - } - typedef int (*TEST_FUNCTION)(); - TEST_FUNCTION testFun = (TEST_FUNCTION)fun; - if(!testFun) - { - cmFailed("Could not find symbol ModuleFunction in library "); - } - else - { - int ret = (*testFun)(); - if(!ret) - { - cmFailed("ModuleFunction call did not return valid return."); - } - cmPassed("Module loaded and ModuleFunction called correctly."); - } - } - cmDynamicLoader::FlushCache(); // fix memory leaks - if(sharedFunction() != 1) - { - cmFailed("Call to sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to sharedFunction from shared library worked."); - } - if(CsharedFunction() != 1) - { - cmFailed("Call to C sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to C sharedFunction from shared library worked."); - } - - // ---------------------------------------------------------------------- - // Test cmSystemTools::UpperCase - std::string str = "abc"; - std::string strupper = "ABC"; - if(cmSystemTools::UpperCase(str) == strupper) - { - cmPassed("cmSystemTools::UpperCase is working"); - } - else - { - cmFailed("cmSystemTools::UpperCase is working"); - } -#endif #if 0 if(NameConflictTest1() == 0 && NameConflictTest2() == 0) { @@ -839,8 +642,7 @@ int main() "FILENAME_VAR_PATH_NAME is not defined."); #else if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0)) + (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0)) { cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); } @@ -901,8 +703,7 @@ int main() "PATH_VAR_NAME is not defined."); #else if((strcmp(PATH_VAR_NAME, "Complex") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0)) + (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0)) { cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME); } @@ -984,7 +785,6 @@ int main() } #endif -#ifdef COMPLEX_TEST_CMAKELIB // ---------------------------------------------------------------------- // Some pre-build/pre-link/post-build custom-commands have been // attached to the lib (see Library/). @@ -1030,7 +830,6 @@ int main() // only created during a build. TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt"); -#endif // ---------------------------------------------------------------------- // Test FIND_LIBRARY @@ -1197,11 +996,6 @@ int main() cmPassed("CMake SET CACHE FORCE"); #endif -#ifdef COMPLEX_TEST_CMAKELIB - // Test the generated file stream. - TestCMGeneratedFileSTream(); -#endif - #ifdef COMPLEX_TEST_LINK_STATIC if(TestLinkGetType()) { @@ -1213,6 +1007,12 @@ int main() } #endif +#if defined(A_VALUE) && A_VALUE == 10 + cmPassed("Single-character executable A worked."); +#else + cmFailed("Single-character executable A failed."); +#endif + // ---------------------------------------------------------------------- // Summary diff --git a/Tests/Complex/Library/CMakeLists.txt b/Tests/Complex/Library/CMakeLists.txt index 281e48a55..c8efc3022 100644 --- a/Tests/Complex/Library/CMakeLists.txt +++ b/Tests/Complex/Library/CMakeLists.txt @@ -43,7 +43,6 @@ ENDIF(WIN32) # SET(SharedLibrarySources sharedFile) ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources}) -ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c) DEFINE_PROPERTY( diff --git a/Tests/Complex/Library/moduleFile.c b/Tests/Complex/Library/moduleFile.c deleted file mode 100644 index 608d750f1..000000000 --- a/Tests/Complex/Library/moduleFile.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "moduleFile.h" - -int ModuleFunction() -{ - return 1; -} diff --git a/Tests/Complex/Library/moduleFile.h b/Tests/Complex/Library/moduleFile.h deleted file mode 100644 index 6b561e109..000000000 --- a/Tests/Complex/Library/moduleFile.h +++ /dev/null @@ -1,12 +0,0 @@ -#if defined(_WIN32) || defined(WIN32) /* Win32 version */ -#ifdef CMakeTestModule_EXPORTS -# define CMakeTest_EXPORT __declspec(dllexport) -#else -# define CMakeTest_EXPORT __declspec(dllimport) -#endif -#else -/* unix needs nothing */ -#define CMakeTest_EXPORT -#endif - -CMakeTest_EXPORT int ModuleFunction(); diff --git a/Tests/Complex/cmTestConfigure.h.in b/Tests/Complex/cmTestConfigure.h.in index d7952da1e..7741b6fd5 100644 --- a/Tests/Complex/cmTestConfigure.h.in +++ b/Tests/Complex/cmTestConfigure.h.in @@ -4,8 +4,6 @@ #cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR -#cmakedefine COMPLEX_TEST_CMAKELIB - #define STRING_VAR "${STRING_VAR}" // Test FOREACH diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt index 8d6029a9f..b50501905 100644 --- a/Tests/ComplexOneConfig/CMakeLists.txt +++ b/Tests/ComplexOneConfig/CMakeLists.txt @@ -17,9 +17,6 @@ ENDIF(POLICY CMP0003) # Test building without per-rule echo lines in Makefiles. SET_PROPERTY(GLOBAL PROPERTY RULE_MESSAGES OFF) -# Choose whether to test CMakeLib. -OPTION(COMPLEX_TEST_CMAKELIB "Test CMakeLib" OFF) - SET(CPACK_SOURCE_IGNORE_FILES "~$;\\.cvsignore$;^C:/hoffman/My Builds/testcase.*/CVS/;^C:/hoffman/My Builds/testcase.*/\\.svn/;^C:/hoffman/My Builds/testcase.*/sweigart/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/eos2001/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_tables_new/;^C:/hoffman/My Builds/testcase/COPYING$;^C:/hoffman/My Builds/testcase/INSTALL$;^C:/hoffman/My Builds/testcase/Makefile$;^C:/hoffman/My Builds/testcase/Makefile\\.in$;^C:/hoffman/My Builds/testcase/.*\\.lo$;^C:/hoffman/My Builds/testcase/.*\\.la$;^C:/hoffman/My Builds/testcase/mkinstalldirs$;^C:/hoffman/My Builds/testcase/missing$;^C:/hoffman/My Builds/testcase/ltmain\\.sh$;^C:/hoffman/My Builds/testcase/libtool$;^C:/hoffman/My Builds/testcase/install-sh$;^C:/hoffman/My Builds/testcase/configure$;^C:/hoffman/My Builds/testcase/config\\.sub$;^C:/hoffman/My Builds/testcase/config\\.status$;^C:/hoffman/My Builds/testcase/config\\.log$;^C:/hoffman/My Builds/testcase/config\\.guess$;^C:/hoffman/My Builds/testcase/autom4te\\.cache$;^C:/hoffman/My Builds/testcase/aclocal\\.m4$;^C:/hoffman/My Builds/testcase/depcomp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10_corr$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_scvh$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.rgbtip\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.zahb\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.085\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.mem$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.tex\\.bak$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j16\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j26\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j36\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_JNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Jseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_KNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Kseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check34_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check35_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check36_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check43_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check44_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check45_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check46_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check47_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check48_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/Makefile$;^C:/hoffman/My Builds/testcase/www/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/.*\\.flc$;^C:/hoffman/My Builds/testcase/src/Makefile$;^C:/hoffman/My Builds/testcase/src/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/\\.deps$;^C:/hoffman/My Builds/testcase/src/\\.libs$;^C:/hoffman/My Builds/testcase/src/.*\\.la$;^C:/hoffman/My Builds/testcase/src/.*\\.lo$;^C:/hoffman/My Builds/testcase/src/make\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/statef.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_15$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_rel$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/hot_post_agb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgb_tip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/start_shellflash\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/white_dwarf\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/3order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/5order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/8order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check8_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check5_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effoo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/tc\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/include/Makefile\\.in$;^C:/hoffman/My Builds/testcase/include/Makefile$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/0\\.1\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_eos1a-eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_0\\.1\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_eos1a-eos1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/fort\\.91$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/oldversion_grid$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2005Ap&SS\\.298\\.\\.135S\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2007Ap&SS\\.307\\.\\.263C\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/astro-ph\\.9909168_eprint_submitted_to_High_Press\\.Res\\.16,331\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/statef_grid-newversion$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/old$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/make\\.out.*$;^C:/hoffman/My Builds/testcase/utils/.*\\.flc$;^C:/hoffman/My Builds/testcase/utils/Makefile$;^C:/hoffman/My Builds/testcase/utils/Makefile\\.in$;^C:/hoffman/My Builds/testcase/utils/\\.deps$;^C:/hoffman/My Builds/testcase/utils/\\.libs$;^C:/hoffman/My Builds/testcase/utils/.*\\.la$;^C:/hoffman/My Builds/testcase/utils/.*\\.lo$;^C:/hoffman/My Builds/testcase/utils/free_eos_test$;^C:/hoffman/My Builds/testcase/utils/test_rosenbrock$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check5\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check8\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_checknr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effoo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence_20070613$;^C:/hoffman/My Builds/testcase/www/eospaper/text$;^C:/hoffman/My Builds/testcase/www/eospaper/cassisi_book_fig$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.1\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/2\\.0\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.2\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.3\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.4\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.5\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.6\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/figures$;^C:/hoffman/My Builds/testcase/www/eospaper/old$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_JNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Jseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_KNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Kseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check34\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check35\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check36\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check44\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check45\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check46\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_1_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_2_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_linear_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_nr_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_series_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.1\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.3\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_linear\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_nr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.rgbtip\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.zahb\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.rgbtip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_linear$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_noexchange$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_nr$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/delta\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos1gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos2gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb_adjust/coulomb_adjust\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/rtc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/make\\.out.*$") # @@ -119,8 +116,6 @@ ENDIF(${fooCACHE_TEST_VAR2} MATCHES bar) # INCLUDE_DIRECTORIES( Library - ${Complex_SOURCE_DIR}/../../Source - ${Complex_BINARY_DIR}/../../Source ) INCLUDE_DIRECTORIES(BEFORE diff --git a/Tests/ComplexOneConfig/Executable/A.cxx b/Tests/ComplexOneConfig/Executable/A.cxx index 0cc995af0..fb3eb0819 100644 --- a/Tests/ComplexOneConfig/Executable/A.cxx +++ b/Tests/ComplexOneConfig/Executable/A.cxx @@ -1,7 +1,9 @@ // Include code from a header that should not be compiled separately. #include "A.hh" +#include int main() { - return A(); + printf("#define A_VALUE %d\n", A()); + return 0; } diff --git a/Tests/ComplexOneConfig/Executable/CMakeLists.txt b/Tests/ComplexOneConfig/Executable/CMakeLists.txt index 98b29bbf2..345836257 100644 --- a/Tests/ComplexOneConfig/Executable/CMakeLists.txt +++ b/Tests/ComplexOneConfig/Executable/CMakeLists.txt @@ -5,25 +5,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") -IF(COMPLEX_TEST_CMAKELIB) - # Link to CMake lib - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib) - # prefer the new curl if it is around - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0/lib) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES( - ${Complex_BINARY_DIR}/../../Utilities/cmlibarchive/libarchive - ${Complex_BINARY_DIR}/../../Utilities/cmbzip2 - ) -ENDIF(COMPLEX_TEST_CMAKELIB) - # Create an imported target for if(TARGET) test below. ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED) @@ -49,13 +30,19 @@ LINK_LIBRARIES(${COMPLEX_LIBS}) SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES HEADER_FILE_ONLY 1) +# Test forcing a .c file to not build. +# This makes sure a mixed language library is created +# with header file only sources +SET_SOURCE_FILES_PROPERTIES(complex_nobuild.c PROPERTIES + HEADER_FILE_ONLY 1) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt) -ADD_EXECUTABLE(complex complex testcflags.c ) +ADD_CUSTOM_COMMAND(OUTPUT Aout.h COMMAND A > Aout.h VERBATIM) +ADD_EXECUTABLE(complex complex testcflags.c Aout.h) # Sub1/NameConflictTest.c Sub2/NameConflictTest.c) -ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx) -IF(COMPLEX_TEST_CMAKELIB) - TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmlibarchive cmbzip2 cmcurl) -ENDIF(COMPLEX_TEST_CMAKELIB) +ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx + complex_nobuild.c) IF (UNIX) TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS}) diff --git a/Tests/ComplexOneConfig/Executable/complex.cxx b/Tests/ComplexOneConfig/Executable/complex.cxx index 0ecd8fe2e..1901d9914 100644 --- a/Tests/ComplexOneConfig/Executable/complex.cxx +++ b/Tests/ComplexOneConfig/Executable/complex.cxx @@ -3,23 +3,21 @@ #include "cmTestGeneratedHeader.h" #include "cmVersion.h" #include "ExtraSources/file1.h" +#include "Aout.h" #include "file2.h" #include "sharedFile.h" extern "C" { #include "testConly.h" } -#ifdef COMPLEX_TEST_CMAKELIB -#include "cmStandardIncludes.h" -#include "cmSystemTools.h" -#include "cmDynamicLoader.h" -#include "cmSystemTools.h" -#include "cmGeneratedFileStream.h" -#include -#else #include #include #include #include + +#include +#include +#if !defined(S_ISDIR) +# define S_ISDIR(mode) ((mode) & _S_IFDIR) #endif #ifdef COMPLEX_TEST_LINK_STATIC @@ -67,18 +65,18 @@ void cmPassed(const char* Message, const char* m2="") # error Per-configuration directory-level definition not inherited. #endif -#ifdef COMPLEX_TEST_CMAKELIB // ====================================================================== void TestAndRemoveFile(const char* filename) { - if (!cmSystemTools::FileExists(filename)) + struct stat st; + if(stat(filename, &st) < 0) { cmFailed("Could not find file: ", filename); } else { - if (!cmSystemTools::RemoveFile(filename)) + if (remove(filename) < 0) { cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); } @@ -93,104 +91,16 @@ void TestAndRemoveFile(const char* filename) void TestDir(const char* filename) { - if (!cmSystemTools::FileExists(filename)) + struct stat st; + if(stat(filename, &st) < 0 || !S_ISDIR(st.st_mode)) { cmFailed("Could not find dir: ", filename); } else { - if (!cmSystemTools::FileIsDirectory(filename)) - { - cmFailed("Unable to check if file is a directory: ", filename); - } - else - { - cmPassed("Find dir: ", filename); - } - } -} - -// ====================================================================== - -void TestCMGeneratedFileSTream() -{ - cmGeneratedFileStream gm; - std::string file1 = std::string(BINARY_DIR) + std::string("/generatedFile1"); - std::string file2 = std::string(BINARY_DIR) + std::string("/generatedFile2"); - std::string file3 = std::string(BINARY_DIR) + std::string("/generatedFile3"); - std::string file4 = std::string(BINARY_DIR) + std::string("/generatedFile4"); - std::string file1tmp = file1 + ".tmp"; - std::string file2tmp = file2 + ".tmp"; - std::string file3tmp = file3 + ".tmp"; - std::string file4tmp = file4 + ".tmp"; - gm.Open(file1.c_str()); - gm << "This is generated file 1"; - gm.Close(); - gm.Open(file2.c_str()); - gm << "This is generated file 2"; - gm.Close(); - gm.Open(file3.c_str()); - gm << "This is generated file 3"; - gm.Close(); - gm.Open(file4.c_str()); - gm << "This is generated file 4"; - gm.Close(); - if ( cmSystemTools::FileExists(file1.c_str()) ) - { - if ( cmSystemTools::FileExists(file2.c_str()) ) - { - if ( cmSystemTools::FileExists(file3.c_str()) ) - { - if ( cmSystemTools::FileExists(file4.c_str()) ) - { - if ( cmSystemTools::FileExists(file1tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file2tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file3tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file4tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str()); - } - else - { - cmPassed("cmGeneratedFileStream works."); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str()); + cmPassed("Find dir: ", filename); } - cmSystemTools::RemoveFile(file1.c_str()); - cmSystemTools::RemoveFile(file2.c_str()); - cmSystemTools::RemoveFile(file3.c_str()); - cmSystemTools::RemoveFile(file1tmp.c_str()); - cmSystemTools::RemoveFile(file2tmp.c_str()); - cmSystemTools::RemoveFile(file3tmp.c_str()); } -#endif // Here is a stupid function that tries to use std::string methods // so that the dec cxx compiler will instantiate the stuff that @@ -232,113 +142,6 @@ extern "C" int NameConflictTest2(); int main() { - std::string lib = BINARY_DIR; - lib += "/lib/"; -#ifdef CMAKE_INTDIR - lib += CMAKE_INTDIR; - lib += "/"; -#endif - std::string exe = BINARY_DIR; - exe += "/bin/"; -#ifdef CMAKE_INTDIR - exe += CMAKE_INTDIR; - exe += "/"; -#endif - -#ifdef COMPLEX_TEST_CMAKELIB - // Test a single character executable to test a: in makefiles - exe += "A"; - exe += cmSystemTools::GetExecutableExtension(); - int ret; - std::string errorMessage; - exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); - if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) - { - if(ret != 10) - { - errorMessage += exe; - errorMessage += " did not return 10"; - } - } - else - { - errorMessage += exe; - errorMessage += ": failed to run."; - } - if(errorMessage.size()) - { - cmFailed(errorMessage.c_str()); - } - else - { - cmPassed("run Single Character executable A returned 10 as expected."); - } - - lib += CMAKE_SHARED_MODULE_PREFIX; - lib += "CMakeTestModule"; - lib += CMAKE_SHARED_MODULE_SUFFIX; - cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str()); - if(!handle) - { - std::string err = "Can not open CMakeTestModule:\n"; - err += lib; - cmFailed(err.c_str()); - } - else - { - cmsys::DynamicLoader::SymbolPointer fun = - cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); - if(!fun) - { - fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction"); - } - typedef int (*TEST_FUNCTION)(); - TEST_FUNCTION testFun = (TEST_FUNCTION)fun; - if(!testFun) - { - cmFailed("Could not find symbol ModuleFunction in library "); - } - else - { - int ret = (*testFun)(); - if(!ret) - { - cmFailed("ModuleFunction call did not return valid return."); - } - cmPassed("Module loaded and ModuleFunction called correctly."); - } - } - cmDynamicLoader::FlushCache(); // fix memory leaks - if(sharedFunction() != 1) - { - cmFailed("Call to sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to sharedFunction from shared library worked."); - } - if(CsharedFunction() != 1) - { - cmFailed("Call to C sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to C sharedFunction from shared library worked."); - } - - // ---------------------------------------------------------------------- - // Test cmSystemTools::UpperCase - std::string str = "abc"; - std::string strupper = "ABC"; - if(cmSystemTools::UpperCase(str) == strupper) - { - cmPassed("cmSystemTools::UpperCase is working"); - } - else - { - cmFailed("cmSystemTools::UpperCase is working"); - } -#endif #if 0 if(NameConflictTest1() == 0 && NameConflictTest2() == 0) { @@ -839,8 +642,7 @@ int main() "FILENAME_VAR_PATH_NAME is not defined."); #else if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0)) + (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0)) { cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); } @@ -901,8 +703,7 @@ int main() "PATH_VAR_NAME is not defined."); #else if((strcmp(PATH_VAR_NAME, "Complex") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0)) + (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0)) { cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME); } @@ -984,7 +785,6 @@ int main() } #endif -#ifdef COMPLEX_TEST_CMAKELIB // ---------------------------------------------------------------------- // Some pre-build/pre-link/post-build custom-commands have been // attached to the lib (see Library/). @@ -1030,7 +830,6 @@ int main() // only created during a build. TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt"); -#endif // ---------------------------------------------------------------------- // Test FIND_LIBRARY @@ -1197,11 +996,6 @@ int main() cmPassed("CMake SET CACHE FORCE"); #endif -#ifdef COMPLEX_TEST_CMAKELIB - // Test the generated file stream. - TestCMGeneratedFileSTream(); -#endif - #ifdef COMPLEX_TEST_LINK_STATIC if(TestLinkGetType()) { @@ -1213,6 +1007,12 @@ int main() } #endif +#if defined(A_VALUE) && A_VALUE == 10 + cmPassed("Single-character executable A worked."); +#else + cmFailed("Single-character executable A failed."); +#endif + // ---------------------------------------------------------------------- // Summary diff --git a/Tests/ComplexRelativePaths/Executable/complex_nobuild.cxx b/Tests/ComplexOneConfig/Executable/complex_nobuild.c similarity index 100% rename from Tests/ComplexRelativePaths/Executable/complex_nobuild.cxx rename to Tests/ComplexOneConfig/Executable/complex_nobuild.c diff --git a/Tests/ComplexOneConfig/Library/CMakeLists.txt b/Tests/ComplexOneConfig/Library/CMakeLists.txt index 281e48a55..c8efc3022 100644 --- a/Tests/ComplexOneConfig/Library/CMakeLists.txt +++ b/Tests/ComplexOneConfig/Library/CMakeLists.txt @@ -43,7 +43,6 @@ ENDIF(WIN32) # SET(SharedLibrarySources sharedFile) ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources}) -ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c) DEFINE_PROPERTY( diff --git a/Tests/ComplexOneConfig/Library/moduleFile.c b/Tests/ComplexOneConfig/Library/moduleFile.c deleted file mode 100644 index 608d750f1..000000000 --- a/Tests/ComplexOneConfig/Library/moduleFile.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "moduleFile.h" - -int ModuleFunction() -{ - return 1; -} diff --git a/Tests/ComplexOneConfig/Library/moduleFile.h b/Tests/ComplexOneConfig/Library/moduleFile.h deleted file mode 100644 index 6b561e109..000000000 --- a/Tests/ComplexOneConfig/Library/moduleFile.h +++ /dev/null @@ -1,12 +0,0 @@ -#if defined(_WIN32) || defined(WIN32) /* Win32 version */ -#ifdef CMakeTestModule_EXPORTS -# define CMakeTest_EXPORT __declspec(dllexport) -#else -# define CMakeTest_EXPORT __declspec(dllimport) -#endif -#else -/* unix needs nothing */ -#define CMakeTest_EXPORT -#endif - -CMakeTest_EXPORT int ModuleFunction(); diff --git a/Tests/ComplexOneConfig/cmTestConfigure.h.in b/Tests/ComplexOneConfig/cmTestConfigure.h.in index d7952da1e..7741b6fd5 100644 --- a/Tests/ComplexOneConfig/cmTestConfigure.h.in +++ b/Tests/ComplexOneConfig/cmTestConfigure.h.in @@ -4,8 +4,6 @@ #cmakedefine ONE_VAR_IS_DEFINED #cmakedefine ZERO_VAR -#cmakedefine COMPLEX_TEST_CMAKELIB - #define STRING_VAR "${STRING_VAR}" // Test FOREACH diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt deleted file mode 100644 index 8d6029a9f..000000000 --- a/Tests/ComplexRelativePaths/CMakeLists.txt +++ /dev/null @@ -1,381 +0,0 @@ -# -# A more complex test case -# -SET(CMAKE_BACKWARDS_COMPATIBILITY 1.4) -PROJECT (Complex) - -# Try setting a new policy. The IF test is for coverage. -IF(POLICY CMP0003) - CMAKE_POLICY(SET CMP0003 NEW) - - CMAKE_POLICY(GET CMP0003 P3) - IF(NOT "${P3}" STREQUAL "NEW") - MESSAGE(FATAL_ERROR "CMAKE_POLICY(GET) did not report NEW!") - ENDIF(NOT "${P3}" STREQUAL "NEW") -ENDIF(POLICY CMP0003) - -# Test building without per-rule echo lines in Makefiles. -SET_PROPERTY(GLOBAL PROPERTY RULE_MESSAGES OFF) - -# Choose whether to test CMakeLib. -OPTION(COMPLEX_TEST_CMAKELIB "Test CMakeLib" OFF) - -SET(CPACK_SOURCE_IGNORE_FILES "~$;\\.cvsignore$;^C:/hoffman/My Builds/testcase.*/CVS/;^C:/hoffman/My Builds/testcase.*/\\.svn/;^C:/hoffman/My Builds/testcase.*/sweigart/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/eos2001/;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_tables_new/;^C:/hoffman/My Builds/testcase/COPYING$;^C:/hoffman/My Builds/testcase/INSTALL$;^C:/hoffman/My Builds/testcase/Makefile$;^C:/hoffman/My Builds/testcase/Makefile\\.in$;^C:/hoffman/My Builds/testcase/.*\\.lo$;^C:/hoffman/My Builds/testcase/.*\\.la$;^C:/hoffman/My Builds/testcase/mkinstalldirs$;^C:/hoffman/My Builds/testcase/missing$;^C:/hoffman/My Builds/testcase/ltmain\\.sh$;^C:/hoffman/My Builds/testcase/libtool$;^C:/hoffman/My Builds/testcase/install-sh$;^C:/hoffman/My Builds/testcase/configure$;^C:/hoffman/My Builds/testcase/config\\.sub$;^C:/hoffman/My Builds/testcase/config\\.status$;^C:/hoffman/My Builds/testcase/config\\.log$;^C:/hoffman/My Builds/testcase/config\\.guess$;^C:/hoffman/My Builds/testcase/autom4te\\.cache$;^C:/hoffman/My Builds/testcase/aclocal\\.m4$;^C:/hoffman/My Builds/testcase/depcomp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.075\\.model_cassisi_eos1_10_corr$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model_cassisi_scvh$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.rgbtip\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.zahb\\.modelc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/0\\.085\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.mem$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange\\.tex\\.bak$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j16\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j26\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/j36\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k10\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k12\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k20\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k22\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k30\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/k32\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/1_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/2_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/linear_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/noexchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/nr_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dgamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/series_exchange_dlnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_JNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Jseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_KNR_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_Kseries_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check34_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check35_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check36_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check43_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check44_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check45_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check46_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check47_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check48_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/Makefile$;^C:/hoffman/My Builds/testcase/www/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/.*\\.flc$;^C:/hoffman/My Builds/testcase/src/Makefile$;^C:/hoffman/My Builds/testcase/src/Makefile\\.in$;^C:/hoffman/My Builds/testcase/src/\\.deps$;^C:/hoffman/My Builds/testcase/src/\\.libs$;^C:/hoffman/My Builds/testcase/src/.*\\.la$;^C:/hoffman/My Builds/testcase/src/.*\\.lo$;^C:/hoffman/My Builds/testcase/src/make\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/statef.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.1\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/0\\.3\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_15$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/1\\.0\\.model_rel$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/hot_post_agb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgb_tip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/rgbtip\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/start_shellflash\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/white_dwarf\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_13$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.1\\.0\\.model_23$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/model-loci/zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/15lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23gamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fermi_dirac_approx/23lnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/thermodynamic_consistency/.*\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_fit\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/3order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/5order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/8order_data\\.tex$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check8_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check5_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/effoo_check3_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda15lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23gamma1\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/fda23lnp\\.yplot$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/thermodynamic_consistency/tc\\.results$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_compare_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/opal_solar_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/opal_solar/statef_opal_model_1995\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/include/Makefile\\.in$;^C:/hoffman/My Builds/testcase/include/Makefile$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/0\\.1\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_eos1a-eos1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/1\\.0\\.model_pteh$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_0\\.1\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_eos1a-eos1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/model-loci/statef_model_1\\.0\\.model_pteh\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/fort\\.91$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/thermodynamic_consistency/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/oldversion_grid$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2005Ap&SS\\.298\\.\\.135S\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/2007Ap&SS\\.307\\.\\.263C\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/astro-ph\\.9909168_eprint_submitted_to_High_Press\\.Res\\.16,331\\.pdf$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/convergence\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/statef_grid-newversion$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/purehe_context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/old$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/make\\.out.*$;^C:/hoffman/My Builds/testcase/utils/.*\\.flc$;^C:/hoffman/My Builds/testcase/utils/Makefile$;^C:/hoffman/My Builds/testcase/utils/Makefile\\.in$;^C:/hoffman/My Builds/testcase/utils/\\.deps$;^C:/hoffman/My Builds/testcase/utils/\\.libs$;^C:/hoffman/My Builds/testcase/utils/.*\\.la$;^C:/hoffman/My Builds/testcase/utils/.*\\.lo$;^C:/hoffman/My Builds/testcase/utils/free_eos_test$;^C:/hoffman/My Builds/testcase/utils/test_rosenbrock$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check1\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check5\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_check8\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/eff_checknr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/eff_check/effoo_check3\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence_20070613$;^C:/hoffman/My Builds/testcase/www/eospaper/text$;^C:/hoffman/My Builds/testcase/www/eospaper/cassisi_book_fig$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.1\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/2\\.0\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.2\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.3\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.4\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.5\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/1\\.6\\.0$;^C:/hoffman/My Builds/testcase/www/eospaper/figures$;^C:/hoffman/My Builds/testcase/www/eospaper/old$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.ps.*$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/context\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/nocoulomb_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dgamma1_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/pteh_dlnp_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/make\\.out.*$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_JNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Jseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_KNR\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_Kseries\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check34\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check35\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check36\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check44\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check45\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/exchange_check46\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_1_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_2_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_linear_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_nr_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/statef_compare_series_exchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/series_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/nr_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/linear_exchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/noexchange_dgamma1\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/1_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/exchange_check/2_exchange_dlnp\\.gnuplot$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/convergence/pureh_newversion_grid/.*\\.err$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dgamma1$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/dlnp$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/dhtau/statef_compare\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.1\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_0\\.3\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_linear\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_noexchange\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.model_nr\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.rgbtip\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/statef_model_1\\.0\\.zahb\\.model\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.zahb\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.rgbtip\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_linear$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_noexchange$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model_nr$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.1\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/1\\.0\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/model-loci/0\\.3\\.model$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/contour\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/eos_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/exchange/context/statef_grid\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/delta\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos1gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/eff_fit/rho-T-loci/gong/m0085eos2gong\\.ascii$;^C:/hoffman/My Builds/testcase/www/eospaper/coulomb/coulomb_adjust/coulomb_adjust\\.out$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.ps$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/.*\\.pyc$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/head\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/body\\.tmp$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/prior-dvi\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.aux$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.log$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/solution\\.dvi$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/rtc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/tc_yplot\\.in$;^C:/hoffman/My Builds/testcase/www/eospaper/solution/make\\.out.*$") - -# -# Define a macro -# -MACRO(ASSERT value msg) - IF (NOT ${value}) - MESSAGE ("Assertion failure:" ${msg} ) - ENDIF (NOT ${value}) -ENDMACRO(ASSERT) - -# invoke the macro -ASSERT(Complex_BINARY_DIR "The PROJECT command is broken") - -# -# Define a var args macro, it must take two or four args -# -MACRO(TEST_ARGC value1 value2) - ADD_DEFINITIONS(${value1} ${value2}) - IF (${ARGC} MATCHES 4) - ADD_DEFINITIONS(${ARGV2} ${ARGV3}) - ENDIF (${ARGC} MATCHES 4) -ENDMACRO(TEST_ARGC) - -# invoke the macro -TEST_ARGC(-DCMAKE_ARGV1 -DCMAKE_ARGV2 -DCMAKE_ARGV3 -DCMAKE_ARGV4) - -MACRO(TEST_VAR_ARG fa) - IF("${ARGV}" MATCHES "^1;2;3$") - MESSAGE(STATUS "ARGV works") - ELSE("${ARGV}" MATCHES "^1;2;3$") - MESSAGE(FATAL_ERROR "ARGV does not work; got \"${ARGV}\" instead of \"1;2;3\"") - ENDIF("${ARGV}" MATCHES "^1;2;3$") - IF("${ARGN}" MATCHES "^2;3$") - MESSAGE(STATUS "ARGN works") - ELSE("${ARGN}" MATCHES "^2;3$") - MESSAGE(FATAL_ERROR "ARGV does not work; got \"${ARGN}\" instead of \"2;3\"") - ENDIF("${ARGN}" MATCHES "^2;3$") -ENDMACRO(TEST_VAR_ARG) - -TEST_VAR_ARG(1 2 3) - -# Floating-point comparison test. -IF(2.4 LESS 2.4) - MESSAGE(FATAL_ERROR "Failed: 2.4 LESS 2.4") -ENDIF(2.4 LESS 2.4) -IF(2.4 GREATER 2.4) - MESSAGE(FATAL_ERROR "Failed: 2.4 GREATER 2.4") -ENDIF(2.4 GREATER 2.4) -IF(NOT 2.4 EQUAL 2.4) - MESSAGE(FATAL_ERROR "Failed: NOT 2.4 EQUAL 2.4") -ENDIF(NOT 2.4 EQUAL 2.4) - -IF(CMAKE_SYSTEM MATCHES "OSF1-V.*") - IF(NOT CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ") - ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX) -ENDIF(CMAKE_SYSTEM MATCHES "OSF1-V.*") - - -ADD_DEFINITIONS(-DCMAKE_IS_FUN) -ADD_DEFINITIONS(-DCMAKE_IS_REALLY_FUN) -SET_PROPERTY(DIRECTORY - PROPERTY COMPILE_DEFINITIONS_RELEASE - CMAKE_IS_FUN_IN_RELEASE_MODE - ) - -SET(TEST_SEP "a b c") -SEPARATE_ARGUMENTS(TEST_SEP) - - -# -# Include vars from a file and from a cache -# -IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake) - INCLUDE(${Complex_SOURCE_DIR}/VarTests.cmake) -ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake) -INCLUDE(fileshouldnotbehere OPTIONAL) -LOAD_CACHE(${Complex_SOURCE_DIR}/Cache - EXCLUDE - CACHE_TEST_VAR_EXCLUDED - INCLUDE_INTERNALS - CACHE_TEST_VAR_INTERNAL) - -LOAD_CACHE(${Complex_SOURCE_DIR}/Cache READ_WITH_PREFIX foo CACHE_TEST_VAR2) -IF(${fooCACHE_TEST_VAR2} MATCHES bar) - MESSAGE("Load cache worked: ${fooCACHE_TEST_VAR2}") -ELSE(${fooCACHE_TEST_VAR2} MATCHES bar) - MESSAGE(FATAL_ERROR "Load cache with prefix failed: ${fooCACHE_TEST_VAR2}") -ENDIF(${fooCACHE_TEST_VAR2} MATCHES bar) - - - -# -# Specify include and lib dirs -# (BEFORE is for coverage) -# -INCLUDE_DIRECTORIES( - Library - ${Complex_SOURCE_DIR}/../../Source - ${Complex_BINARY_DIR}/../../Source -) - -INCLUDE_DIRECTORIES(BEFORE - ${Complex_BINARY_DIR} -) -INCLUDE_DIRECTORIES(SYSTEM Library/SystemDir) - -INCLUDE_REGULAR_EXPRESSION("^(cmTest|file|sharedFile|test).*$" "^cmMissing") - -LINK_DIRECTORIES( - ${Complex_BINARY_DIR}/Library -) - -# -# check for SET CACHE FORCE -# -SET(FORCE_TEST 1 CACHE STRING "a test") -SET(FORCE_TEST 0 CACHE STRING "a test" FORCE) - -# -# Lib and exe path -# -SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib/static") -SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/lib") -SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${Complex_BINARY_DIR}/bin") - -MESSAGE (Test " " escape " " semi-colon " " \; \;) -# -# Exec program (TODO: test a result) -# Increase coverage. -# -MESSAGE("\nIgnore this message") -OPTION(NO_EXEC_PROGRAM "Do not test EXEC_PROGRAM" 0) -IF (NOT NO_EXEC_PROGRAM) - EXEC_PROGRAM(${CMAKE_COMMAND} ARGS -E echo NO_EXEC_PROGRAM "${Complex_BINARY_DIR}") -ELSE (NOT NO_EXEC_PROGRAM) - MESSAGE("Set this option ON") -ENDIF (NOT NO_EXEC_PROGRAM) - -MARK_AS_ADVANCED(NO_EXEC_PROGRAM) -MARK_AS_ADVANCED(CLEAR NO_EXEC_PROGRAM) - -# Execute a process. Add coverage for this command. -EXECUTE_PROCESS( - COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG" - OUTPUT_VARIABLE TEST_OUT - ) -IF("${TEST_OUT}" MATCHES "^ABCDEFG\n$") -ELSE("${TEST_OUT}" MATCHES "^ABCDEFG\n$") - MESSAGE(SEND_ERROR "EXECUTE_PROCESS output test failed: [${TEST_OUT}]") -ENDIF("${TEST_OUT}" MATCHES "^ABCDEFG\n$") - -# This test has some problems on UNIX systems. Disabling for now. -# -# EXECUTE_PROCESS( -# COMMAND ${CMAKE_COMMAND} -E echo "ABCDEFG" -# COMMAND /process/does/not/exist -# OUTPUT_QUIET -# ERROR_QUIET -# RESULT_VARIABLE RESULT -# ) -# IF("${RESULT}" MATCHES "^0$") -# MESSAGE(SEND_ERROR -# "EXECUTE_PROCESS result test failed with RESULT=[${RESULT}]") -# ELSE("${RESULT}" MATCHES "^0$") -# MESSAGE(STATUS "EXECUTE_PROCESS result test passed with RESULT=[${RESULT}]") -# ENDIF("${RESULT}" MATCHES "^0$") - -# -# Create directory. -# The 'complex' executable will then test if this dir exists, -# sadly it won't be able to remove it. -# -MAKE_DIRECTORY("${Complex_BINARY_DIR}/make_dir") - -# -# Test FIND_LIBARY -# Create a dummy empty lib -# -CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/Library/dummy - ${Complex_BINARY_DIR}/Library/dummylib.lib - COPYONLY IMMEDIATE) -FOREACH (ext ${CMAKE_SHLIB_SUFFIX};.so;.a;.sl) - CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/Library/dummy - ${Complex_BINARY_DIR}/Library/libdummylib${ext} - COPYONLY IMMEDIATE) -ENDFOREACH (ext) - -FIND_LIBRARY(FIND_DUMMY_LIB - dummylib - PATHS - ${Complex_BINARY_DIR}/Library DOC "find dummy lib") - -FIND_LIBRARY(FIND_DUMMY_LIB - NAMES dummylib dummylib2 - PATHS - ${Complex_BINARY_DIR}/Library DOC "find dummy lib") - -# -# Test SET_SOURCE_FILES_PROPERTIES -# -SET_SOURCE_FILES_PROPERTIES(nonexisting_file2 - GENERATED - ABSTRACT - WRAP_EXCLUDE - COMPILE_FLAGS "-foo -bar") - -GET_SOURCE_FILE_PROPERTY(FILE_HAS_ABSTRACT nonexisting_file2 ABSTRACT) -GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file2 WRAP_EXCLUDE) -GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file2 COMPILE_FLAGS) - -SET_SOURCE_FILES_PROPERTIES(nonexisting_file3 PROPERTIES - GENERATED 1 - ABSTRACT 1 - WRAP_EXCLUDE 1 - COMPILE_FLAGS "-foo -bar") -GET_SOURCE_FILE_PROPERTY(FILE_HAS_ABSTRACT nonexisting_file3 ABSTRACT) -GET_SOURCE_FILE_PROPERTY(FILE_HAS_WRAP_EXCLUDE nonexisting_file3 WRAP_EXCLUDE) -GET_SOURCE_FILE_PROPERTY(FILE_COMPILE_FLAGS nonexisting_file3 COMPILE_FLAGS) - -# -# Test registry (win32) -# Create a file, put its path in a registry key, try to find the file in that -# path using that registry key, then remove the file and the key -# -IF (WIN32) - IF (NOT UNIX) - SET(dir "${Complex_BINARY_DIR}/registry_dir") - SET(file "registry_test_dummy") - SET(hkey "HKEY_CURRENT_USER\\Software\\Kitware\\CMake\\Tests\\Complex;registry_test") - CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/Library/dummy - "${dir}/${file}" - COPYONLY IMMEDIATE) - EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"") - FIND_PATH(REGISTRY_TEST_PATH - ${file} - "[${hkey}]" DOC "Registry_Test_Path") - EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"") - EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"") - ENDIF (NOT UNIX) -ENDIF (WIN32) - -# -# Test a set and a remove -# -SET(REMOVE_STRING a b c d e f) -SET(removeVar1 c e) -REMOVE(REMOVE_STRING ${removeVar1} f) - -# -# Test an IF inside a FOREACH. -# -FOREACH(x "a") - IF(${x} MATCHES "a") - # Should always execute. - SET(IF_INSIDE_FOREACH_THEN_EXECUTED 1) - ELSE(${x} MATCHES "a") - # Should never execute. - SET(IF_INSIDE_FOREACH_ELSE_EXECUTED 1) - ENDIF(${x} MATCHES "a") -ENDFOREACH(x) - -# test WHILE command -SET (while_var 1) -WHILE (while_var LESS 1000) - SET(while_var ${while_var}0) -ENDWHILE(while_var LESS 1000) - -SET(SHOULD_BE_ZERO ) -SET(SHOULD_BE_ONE 1) - -# test elseif functionality, the mess below tries to catch problem -# of clauses being executed early or late etc -set (RESULT 3) -if (RESULT EQUAL 1) - if (RESULT EQUAL 2) - set (ELSEIF_RESULT 1) - elseif (RESULT EQUAL 3) - set (ELSEIF_RESULT 1) - endif (RESULT EQUAL 2) -elseif (RESULT EQUAL 2) - set (ELSEIF_RESULT 1) -elseif (RESULT EQUAL 3) - if (RESULT EQUAL 2) - set (ELSEIF_RESULT 1) - elseif (RESULT EQUAL 3) - if (NOT ELSEIF_RESULT EQUAL 1) - set (ELSEIF_RESULT 2) - endif (NOT ELSEIF_RESULT EQUAL 1) - endif (RESULT EQUAL 2) -elseif (RESULT EQUAL 4) - if (RESULT EQUAL 2) - set (ELSEIF_RESULT 1) - elseif (RESULT EQUAL 3) - set (ELSEIF_RESULT 1) - endif (RESULT EQUAL 2) -else (RESULT EQUAL 1) - if (RESULT EQUAL 2) - set (ELSEIF_RESULT 1) - elseif (RESULT EQUAL 3) - set (ELSEIF_RESULT 1) - endif (RESULT EQUAL 2) -endif (RESULT EQUAL 1) - -if (NOT ELSEIF_RESULT EQUAL 2) - set (ELSEIF_RESULT 0) -endif (NOT ELSEIF_RESULT EQUAL 2) - -# test handling of parenthetical groups in conditionals -if (2 GREATER 1 AND (4 LESS 3 OR 5 LESS 6) AND NOT (7 GREATER 8)) - set(CONDITIONAL_PARENTHESES 1) -endif() - - -# -# Configure file -# (plug vars to #define so that they can be tested) -# -CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/cmTestConfigure.h.in - ${Complex_BINARY_DIR}/cmTestConfigure.h) - -SET(STRING_WITH_QUOTES "\"hello world\"") -# test CONFIGURE_FILE with ESCAPE_QUOTES on -CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/cmTestConfigureEscape.h.in - ${Complex_BINARY_DIR}/cmTestConfigureEscape.h ESCAPE_QUOTES) - -# Test regular expression commands. -STRING(REGEX MATCH "b" RESULT "abc") -IF(NOT RESULT) - MESSAGE(SEND_ERROR "STRING(REGEX MATCH ... ) test failed.") -ENDIF(NOT RESULT) -STRING(REGEX MATCHALL "b" RESULT "abcb") -IF(NOT RESULT) - MESSAGE(SEND_ERROR "STRING(REGEX MATCHALL ... ) test failed.") -ENDIF(NOT RESULT) -STRING(REGEX REPLACE ".([bd])." "[\\1]" RESULT "a(b)c(d)e") -IF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") - SET(STRING_REGEX_PASSED 1) -ENDIF("x${RESULT}" MATCHES "^xa\\[b\\]c\\[d\\]e$") -IF(NOT STRING_REGEX_PASSED) - MESSAGE(SEND_ERROR - "STRING(REGEX REPLACE ... ) test failed (\"${RESULT}\" v. \"a[b]c[d]e\")") -ENDIF(NOT STRING_REGEX_PASSED) - - -# -# Create the libs and the main exe -# -ADD_SUBDIRECTORY(Library) -ADD_SUBDIRECTORY(Executable) -SUBDIR_DEPENDS(Executable Library) -EXPORT_LIBRARY_DEPENDENCIES(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake) -INCLUDE(${Complex_BINARY_DIR}/ComplexLibraryDepends.cmake OPTIONAL) diff --git a/Tests/ComplexRelativePaths/Cache/CMakeCache.txt b/Tests/ComplexRelativePaths/Cache/CMakeCache.txt deleted file mode 100644 index 17c55aa01..000000000 --- a/Tests/ComplexRelativePaths/Cache/CMakeCache.txt +++ /dev/null @@ -1,34 +0,0 @@ -# This is the CMakeCache file. -# For build in directory: d:/build/kitware/cmake/CMake-nmake/Tests/Complex -# You can edit this file to change values found and used by cmake. -# If you do not want to change any of the values, simply exit the editor. -# If you do want to change a value, simply edit, save, and exit the editor. -# The syntax for the file is as follows: -# KEY:TYPE=VALUE -# KEY is the name of a varible in the cache. -# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!. -# VALUE is the current value for the KEY. - -######################## -# EXTERNAL cache entries -######################## - -//A var. -CACHE_TEST_VAR1:STRING=foo - -//A var. -CACHE_TEST_VAR2:FILEPATH=bar - -//A var. -CACHE_TEST_VAR3:BOOL=1 - -//A var. -CACHE_TEST_VAR_EXCLUDED:BOOL=1 - - -######################## -# INTERNAL cache entries -######################## - -//A var. -CACHE_TEST_VAR_INTERNAL:INTERNAL=bar diff --git a/Tests/ComplexRelativePaths/Executable/A.cxx b/Tests/ComplexRelativePaths/Executable/A.cxx deleted file mode 100644 index 0cc995af0..000000000 --- a/Tests/ComplexRelativePaths/Executable/A.cxx +++ /dev/null @@ -1,7 +0,0 @@ -// Include code from a header that should not be compiled separately. -#include "A.hh" - -int main() -{ - return A(); -} diff --git a/Tests/ComplexRelativePaths/Executable/A.h b/Tests/ComplexRelativePaths/Executable/A.h deleted file mode 100644 index 25c45fcbf..000000000 --- a/Tests/ComplexRelativePaths/Executable/A.h +++ /dev/null @@ -1,4 +0,0 @@ -// This header should not be compiled directly but through inclusion -// in A.cxx through A.hh. -extern int A(); -int A() { return 10; } diff --git a/Tests/ComplexRelativePaths/Executable/A.hh b/Tests/ComplexRelativePaths/Executable/A.hh deleted file mode 100644 index e6bab022e..000000000 --- a/Tests/ComplexRelativePaths/Executable/A.hh +++ /dev/null @@ -1,2 +0,0 @@ -// This header should not be compiled directly but through inclusion in A.cxx -#include "A.h" diff --git a/Tests/ComplexRelativePaths/Executable/A.txt b/Tests/ComplexRelativePaths/Executable/A.txt deleted file mode 100644 index 8ee9462be..000000000 --- a/Tests/ComplexRelativePaths/Executable/A.txt +++ /dev/null @@ -1 +0,0 @@ -This file should not be compiled! diff --git a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt b/Tests/ComplexRelativePaths/Executable/CMakeLists.txt deleted file mode 100644 index 98b29bbf2..000000000 --- a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt +++ /dev/null @@ -1,183 +0,0 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 1.3) -# -# Create exe. -# -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") - -IF(COMPLEX_TEST_CMAKELIB) - # Link to CMake lib - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source/kwsys) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmexpat) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmzlib) - # prefer the new curl if it is around - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0/lib) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl-7.19.0) - IF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Utilities/cmcurl) - ENDIF(EXISTS ${Complex_BINARY_DIR}/../../Utilities/cmcurl) - LINK_DIRECTORIES( - ${Complex_BINARY_DIR}/../../Utilities/cmlibarchive/libarchive - ${Complex_BINARY_DIR}/../../Utilities/cmbzip2 - ) -ENDIF(COMPLEX_TEST_CMAKELIB) - -# Create an imported target for if(TARGET) test below. -ADD_LIBRARY(ExeImportedTarget UNKNOWN IMPORTED) - -# Test if(TARGET) command. -IF(NOT TARGET CMakeTestLibrary) - MESSAGE(FATAL_ERROR "IF(NOT TARGET CMakeTestLibrary) returned true!") -ENDIF(NOT TARGET CMakeTestLibrary) -IF(NOT TARGET ExeImportedTarget) - MESSAGE(FATAL_ERROR "IF(NOT TARGET ExeImportedTarget) returned true!") -ENDIF(NOT TARGET ExeImportedTarget) -IF(TARGET LibImportedTarget) - MESSAGE(FATAL_ERROR "IF(TARGET LibImportedTarget) returned true!") -ENDIF(TARGET LibImportedTarget) -IF(TARGET NotATarget) - MESSAGE(FATAL_ERROR "IF(TARGET NotATarget) returned true!") -ENDIF(TARGET NotATarget) - - # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to -SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) -LINK_LIBRARIES(${COMPLEX_LIBS}) - -# Test forcing a .cxx file to not build. -SET_SOURCE_FILES_PROPERTIES(complex_nobuild.cxx PROPERTIES - HEADER_FILE_ONLY 1) - -ADD_EXECUTABLE(A A.cxx A.hh A.h A.txt) -ADD_EXECUTABLE(complex complex testcflags.c ) -# Sub1/NameConflictTest.c Sub2/NameConflictTest.c) -ADD_EXECUTABLE(complex.file complex.file.cxx complex_nobuild.cxx) -IF(COMPLEX_TEST_CMAKELIB) - TARGET_LINK_LIBRARIES(complex CMakeLib cmsys cmexpat cmzlib cmlibarchive cmbzip2 cmcurl) -ENDIF(COMPLEX_TEST_CMAKELIB) - -IF (UNIX) - TARGET_LINK_LIBRARIES(complex ${CMAKE_DL_LIBS}) -ELSE(UNIX) - IF (NOT BORLAND) - IF(NOT MINGW) - TARGET_LINK_LIBRARIES(complex rpcrt4.lib) - ENDIF(NOT MINGW) - ENDIF(NOT BORLAND) -ENDIF (UNIX) - -# Test linking to static lib when a shared lib has the same name. -IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS) - ADD_DEFINITIONS(-DCOMPLEX_TEST_LINK_STATIC) - TARGET_LINK_LIBRARIES(complex CMakeTestLinkStatic) -ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS) - -# can we get the path to a source file -GET_SOURCE_FILE_PROPERTY(A_LOCATION A.cxx LOCATION) -IF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx") - ADD_DEFINITIONS(-DCMAKE_FOUND_ACXX) -ENDIF ("${A_LOCATION}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/A.cxx") - -# get the directory parent -GET_DIRECTORY_PROPERTY(P_VALUE PARENT_DIRECTORY) -IF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}") - ADD_DEFINITIONS(-DCMAKE_FOUND_PARENT) -ENDIF ("${P_VALUE}" STREQUAL "${CMAKE_SOURCE_DIR}") - -# get the stack of listfiles -INCLUDE(Included.cmake) -IF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake") - ADD_DEFINITIONS(-DCMAKE_FOUND_LISTFILE_STACK) -ENDIF ("${LF_VALUE}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt;${CMAKE_CURRENT_SOURCE_DIR}/Included.cmake") - -# Test add/remove definitions. -ADD_DEFINITIONS( - -DCOMPLEX_DEFINED_PRE - -DCOMPLEX_DEFINED - -DCOMPLEX_DEFINED_POST - -DCOMPLEX_DEFINED - ) -REMOVE_DEFINITIONS(-DCOMPLEX_DEFINED) - -# Test pre-build/pre-link/post-build rules for an executable. -ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Executable/prebuild.txt") -ADD_CUSTOM_COMMAND(TARGET complex PRE_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Executable/prelink.txt") -ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Executable/postbuild.txt") -ADD_CUSTOM_COMMAND(TARGET complex POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy - "${Complex_BINARY_DIR}/Executable/postbuild.txt" - "${Complex_BINARY_DIR}/Executable/postbuild2.txt") - -SET_SOURCE_FILES_PROPERTIES(complex - COMPILE_FLAGS - "-DFILE_HAS_EXTRA_COMPILE_FLAGS" - #" -DFILE_DEFINE_STRING=\\\"hello\\\"" - OBJECT_DEPENDS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h -) -SET_TARGET_PROPERTIES(complex PROPERTIES COMPILE_FLAGS "-DCOMPLEX_TARGET_FLAG") -ADD_CUSTOM_COMMAND( - TARGET complex - SOURCE ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in - COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${Complex_SOURCE_DIR}/cmTestGeneratedHeader.h.in - ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h - OUTPUTS ${Complex_BINARY_DIR}/cmTestGeneratedHeader.h - DEPENDS ${CMAKE_COMMAND} -) - -# Test creating an executable that is not built by default. -ADD_EXECUTABLE(notInAllExe EXCLUDE_FROM_ALL notInAllExe.cxx) -TARGET_LINK_LIBRARIES(notInAllExe notInAllLib) - -# Test user-value flag mapping for the VS IDE. -IF(MSVC) - SET_TARGET_PROPERTIES(notInAllExe PROPERTIES - LINK_FLAGS "/NODEFAULTLIB:LIBC;LIBCMT;MSVCRT") -ENDIF(MSVC) - -# Test creating a custom target that builds not-in-all targets. -ADD_CUSTOM_TARGET(notInAllCustom) -ADD_DEPENDENCIES(notInAllCustom notInAllExe) - -# -# Output the files required by 'complex' to a file. -# -# This test has been moved to the 'required' subdir so that it -# has no side-effects on the current Makefile (duplicated source file -# due to source list expansion done twice). -# -ADD_SUBDIRECTORY(Temp) - -IF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX) - ADD_EXECUTABLE(testSystemDir testSystemDir.cxx) - SET_TARGET_PROPERTIES(testSystemDir PROPERTIES COMPILE_FLAGS "-Werror") -ENDIF(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_INCLUDE_SYSTEM_FLAG_CXX) - -# -# Extra coverage.Not used. -# -INSTALL_TARGETS(/tmp complex) -INSTALL_PROGRAMS(/tmp complex) - -CONFIGURE_FILE( - ${Complex_SOURCE_DIR}/Executable/cmVersion.h.in - ${Complex_BINARY_DIR}/cmVersion.h) - -SOURCE_GROUP(A_GROUP ".cxx") -SOURCE_GROUP(B_GROUP REGULAR_EXPRESSION "cxx") -SOURCE_GROUP(C_GROUP FILES complex.cxx) - -FILE(WRITE ${Complex_BINARY_DIR}/A/libA.a "test") -FILE(WRITE ${Complex_BINARY_DIR}/A/libC.a "test") -FILE(WRITE ${Complex_BINARY_DIR}/B/libB.a "test") -FILE(WRITE ${Complex_BINARY_DIR}/B/libA.a "test") -FILE(WRITE ${Complex_BINARY_DIR}/C/libC.a "test") -FILE(WRITE ${Complex_BINARY_DIR}/C/libB.a "test") diff --git a/Tests/ComplexRelativePaths/Executable/Included.cmake b/Tests/ComplexRelativePaths/Executable/Included.cmake deleted file mode 100644 index 2d1ea3e8c..000000000 --- a/Tests/ComplexRelativePaths/Executable/Included.cmake +++ /dev/null @@ -1,2 +0,0 @@ -GET_DIRECTORY_PROPERTY(LF_VALUE LISTFILE_STACK) - diff --git a/Tests/ComplexRelativePaths/Executable/Sub1/NameConflictTest.c b/Tests/ComplexRelativePaths/Executable/Sub1/NameConflictTest.c deleted file mode 100644 index 87203861f..000000000 --- a/Tests/ComplexRelativePaths/Executable/Sub1/NameConflictTest.c +++ /dev/null @@ -1,4 +0,0 @@ -int NameConflictTest1() -{ - return 0; -} diff --git a/Tests/ComplexRelativePaths/Executable/Sub2/NameConflictTest.c b/Tests/ComplexRelativePaths/Executable/Sub2/NameConflictTest.c deleted file mode 100644 index 4a3257255..000000000 --- a/Tests/ComplexRelativePaths/Executable/Sub2/NameConflictTest.c +++ /dev/null @@ -1,4 +0,0 @@ -int NameConflictTest2() -{ - return 0; -} diff --git a/Tests/ComplexRelativePaths/Executable/Temp/CMakeLists.txt b/Tests/ComplexRelativePaths/Executable/Temp/CMakeLists.txt deleted file mode 100644 index f00955029..000000000 --- a/Tests/ComplexRelativePaths/Executable/Temp/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# -# Output the files required by 'complex' to a file. -# The 'complex' executable will then test if this file exists and remove it. -# The contents of this file is not tested (absolute paths). -# -OUTPUT_REQUIRED_FILES( - ${Complex_SOURCE_DIR}/Executable/complex.cxx - ${Complex_BINARY_DIR}/Executable/Temp/complex-required.txt) diff --git a/Tests/ComplexRelativePaths/Executable/cmVersion.h.in b/Tests/ComplexRelativePaths/Executable/cmVersion.h.in deleted file mode 100644 index de7522d1d..000000000 --- a/Tests/ComplexRelativePaths/Executable/cmVersion.h.in +++ /dev/null @@ -1 +0,0 @@ -#define CMAKE_MINIMUM_REQUIRED_VERSION "${CMAKE_MINIMUM_REQUIRED_VERSION}" diff --git a/Tests/ComplexRelativePaths/Executable/complex.cxx b/Tests/ComplexRelativePaths/Executable/complex.cxx deleted file mode 100644 index 0ecd8fe2e..000000000 --- a/Tests/ComplexRelativePaths/Executable/complex.cxx +++ /dev/null @@ -1,1226 +0,0 @@ -#include "cmTestConfigure.h" -#include "cmTestConfigureEscape.h" -#include "cmTestGeneratedHeader.h" -#include "cmVersion.h" -#include "ExtraSources/file1.h" -#include "file2.h" -#include "sharedFile.h" -extern "C" { -#include "testConly.h" -} -#ifdef COMPLEX_TEST_CMAKELIB -#include "cmStandardIncludes.h" -#include "cmSystemTools.h" -#include "cmDynamicLoader.h" -#include "cmSystemTools.h" -#include "cmGeneratedFileStream.h" -#include -#else -#include -#include -#include -#include -#endif - -#ifdef COMPLEX_TEST_LINK_STATIC -extern "C" -{ - int TestLinkGetType(); -} -#endif - -int cm_passed = 0; -int cm_failed = 0; -// ====================================================================== - -void cmFailed(const char* Message, const char* m2= "", const char* m3 = "") -{ - std::cout << "FAILED: " << Message << m2 << m3 << "\n"; - cm_failed++; -} - -// ====================================================================== - -void cmPassed(const char* Message, const char* m2="") -{ - std::cout << "Passed: " << Message << m2 << "\n"; - cm_passed++; -} - -#ifndef COMPLEX_DEFINED_PRE -# error "COMPLEX_DEFINED_PRE not defined!" -#endif - -#ifdef COMPLEX_DEFINED -# error "COMPLEX_DEFINED is defined but it should not!" -#endif - -#ifndef COMPLEX_DEFINED_POST -# error "COMPLEX_DEFINED_POST not defined!" -#endif - -#ifndef CMAKE_IS_REALLY_FUN -# error This is a problem. Looks like ADD_DEFINITIONS and REMOVE_DEFINITIONS does not work -#endif - -#if defined(NDEBUG) && !defined(CMAKE_IS_FUN_IN_RELEASE_MODE) -# error Per-configuration directory-level definition not inherited. -#endif - -#ifdef COMPLEX_TEST_CMAKELIB -// ====================================================================== - -void TestAndRemoveFile(const char* filename) -{ - if (!cmSystemTools::FileExists(filename)) - { - cmFailed("Could not find file: ", filename); - } - else - { - if (!cmSystemTools::RemoveFile(filename)) - { - cmFailed("Unable to remove file. It does not imply that this test failed, but it *will* be corrupted thereafter if this file is not removed: ", filename); - } - else - { - cmPassed("Find and remove file: ", filename); - } - } -} - -// ====================================================================== - -void TestDir(const char* filename) -{ - if (!cmSystemTools::FileExists(filename)) - { - cmFailed("Could not find dir: ", filename); - } - else - { - if (!cmSystemTools::FileIsDirectory(filename)) - { - cmFailed("Unable to check if file is a directory: ", filename); - } - else - { - cmPassed("Find dir: ", filename); - } - } -} - -// ====================================================================== - -void TestCMGeneratedFileSTream() -{ - cmGeneratedFileStream gm; - std::string file1 = std::string(BINARY_DIR) + std::string("/generatedFile1"); - std::string file2 = std::string(BINARY_DIR) + std::string("/generatedFile2"); - std::string file3 = std::string(BINARY_DIR) + std::string("/generatedFile3"); - std::string file4 = std::string(BINARY_DIR) + std::string("/generatedFile4"); - std::string file1tmp = file1 + ".tmp"; - std::string file2tmp = file2 + ".tmp"; - std::string file3tmp = file3 + ".tmp"; - std::string file4tmp = file4 + ".tmp"; - gm.Open(file1.c_str()); - gm << "This is generated file 1"; - gm.Close(); - gm.Open(file2.c_str()); - gm << "This is generated file 2"; - gm.Close(); - gm.Open(file3.c_str()); - gm << "This is generated file 3"; - gm.Close(); - gm.Open(file4.c_str()); - gm << "This is generated file 4"; - gm.Close(); - if ( cmSystemTools::FileExists(file1.c_str()) ) - { - if ( cmSystemTools::FileExists(file2.c_str()) ) - { - if ( cmSystemTools::FileExists(file3.c_str()) ) - { - if ( cmSystemTools::FileExists(file4.c_str()) ) - { - if ( cmSystemTools::FileExists(file1tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file1tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file2tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file2tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file3tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file3tmp.c_str()); - } - else if ( cmSystemTools::FileExists(file4tmp.c_str()) ) - { - cmFailed("Something wrong with cmGeneratedFileStream. Temporary file is still here: ", file4tmp.c_str()); - } - else - { - cmPassed("cmGeneratedFileStream works."); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file4.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Found file: ", file3.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file2.c_str()); - } - } - else - { - cmFailed("Something wrong with cmGeneratedFileStream. Cannot find file: ", file1.c_str()); - } - cmSystemTools::RemoveFile(file1.c_str()); - cmSystemTools::RemoveFile(file2.c_str()); - cmSystemTools::RemoveFile(file3.c_str()); - cmSystemTools::RemoveFile(file1tmp.c_str()); - cmSystemTools::RemoveFile(file2tmp.c_str()); - cmSystemTools::RemoveFile(file3tmp.c_str()); -} -#endif - -// Here is a stupid function that tries to use std::string methods -// so that the dec cxx compiler will instantiate the stuff that -// we are using from the CMakeLib library.... -void ForceStringUse() -{ - std::vector v; - std::vector v2; - v = v2; - std::string cachetest = CACHE_TEST_VAR_INTERNAL; - v.push_back(cachetest); - v2 = v; - std::string x(5,'x'); - char buff[5]; - x.copy(buff, 1, 0); - x[0] = 'a'; - std::string::size_type pos = 0; - x.replace(pos, pos, pos, 'x'); - std::string copy = cachetest; - cachetest.find("bar"); - cachetest.rfind("bar"); - copy.append(cachetest); - copy = cachetest.substr(0, cachetest.size()); -} - - -// defined in testcflags.c -extern "C" int TestCFlags(char* m); -extern "C" int TestTargetCompileFlags(char* m); - -#if 0 -// defined in Sub1/NameConflictTest.c -extern "C" int NameConflictTest1(); -// defined in Sub2/NameConflictTest.c -extern "C" int NameConflictTest2(); -#endif - -// ====================================================================== - -int main() -{ - std::string lib = BINARY_DIR; - lib += "/lib/"; -#ifdef CMAKE_INTDIR - lib += CMAKE_INTDIR; - lib += "/"; -#endif - std::string exe = BINARY_DIR; - exe += "/bin/"; -#ifdef CMAKE_INTDIR - exe += CMAKE_INTDIR; - exe += "/"; -#endif - -#ifdef COMPLEX_TEST_CMAKELIB - // Test a single character executable to test a: in makefiles - exe += "A"; - exe += cmSystemTools::GetExecutableExtension(); - int ret; - std::string errorMessage; - exe = cmSystemTools::ConvertToRunCommandPath(exe.c_str()); - if(cmSystemTools::RunSingleCommand(exe.c_str(), 0, &ret)) - { - if(ret != 10) - { - errorMessage += exe; - errorMessage += " did not return 10"; - } - } - else - { - errorMessage += exe; - errorMessage += ": failed to run."; - } - if(errorMessage.size()) - { - cmFailed(errorMessage.c_str()); - } - else - { - cmPassed("run Single Character executable A returned 10 as expected."); - } - - lib += CMAKE_SHARED_MODULE_PREFIX; - lib += "CMakeTestModule"; - lib += CMAKE_SHARED_MODULE_SUFFIX; - cmsys::DynamicLoader::LibraryHandle handle = cmDynamicLoader::OpenLibrary(lib.c_str()); - if(!handle) - { - std::string err = "Can not open CMakeTestModule:\n"; - err += lib; - cmFailed(err.c_str()); - } - else - { - cmsys::DynamicLoader::SymbolPointer fun = - cmsys::DynamicLoader::GetSymbolAddress(handle, "ModuleFunction"); - if(!fun) - { - fun = cmsys::DynamicLoader::GetSymbolAddress(handle, "_ModuleFunction"); - } - typedef int (*TEST_FUNCTION)(); - TEST_FUNCTION testFun = (TEST_FUNCTION)fun; - if(!testFun) - { - cmFailed("Could not find symbol ModuleFunction in library "); - } - else - { - int ret = (*testFun)(); - if(!ret) - { - cmFailed("ModuleFunction call did not return valid return."); - } - cmPassed("Module loaded and ModuleFunction called correctly."); - } - } - cmDynamicLoader::FlushCache(); // fix memory leaks - if(sharedFunction() != 1) - { - cmFailed("Call to sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to sharedFunction from shared library worked."); - } - if(CsharedFunction() != 1) - { - cmFailed("Call to C sharedFunction from shared library failed."); - } - else - { - cmPassed("Call to C sharedFunction from shared library worked."); - } - - // ---------------------------------------------------------------------- - // Test cmSystemTools::UpperCase - std::string str = "abc"; - std::string strupper = "ABC"; - if(cmSystemTools::UpperCase(str) == strupper) - { - cmPassed("cmSystemTools::UpperCase is working"); - } - else - { - cmFailed("cmSystemTools::UpperCase is working"); - } -#endif -#if 0 - if(NameConflictTest1() == 0 && NameConflictTest2() == 0) - { - cmPassed("Sub dir with same named source works"); - } - else - { - cmFailed("Sub dir with same named source fails"); - } -#endif - if(file1() != 1) - { - cmFailed("Call to file1 function from library failed."); - } - else - { - cmPassed("Call to file1 function returned 1."); - } -#ifndef COMPLEX_TARGET_FLAG - cmFailed("COMPILE_FLAGS did not work with SET_TARGET_PROPERTIES"); -#else - cmPassed("COMPILE_FLAGS did work with SET_TARGET_PROPERTIES"); -#endif - -#ifdef ELSEIF_RESULT - cmPassed("ELSEIF did work"); -#else - cmFailed("ELSEIF did not work"); -#endif - -#ifdef CONDITIONAL_PARENTHESES - cmPassed("CONDITIONAL_PARENTHESES did work"); -#else - cmFailed("CONDITIONAL_PARENTHESES did not work"); -#endif - - if(file2() != 1) - { - cmFailed("Call to file2 function from library failed."); - } - else - { - cmPassed("Call to file2 function returned 1."); - } -#ifndef TEST_CXX_FLAGS - cmFailed("CMake CMAKE_CXX_FLAGS is not being passed to the compiler!"); -#else - cmPassed("CMake CMAKE_CXX_FLAGS is being passed to the compiler."); -#endif - std::string gen = CMAKE_GENERATOR; - // visual studio is currently broken for c flags - char msg[1024]; - if(gen.find("Visual") == gen.npos) - { -#ifdef TEST_C_FLAGS - cmFailed("CMake CMAKE_C_FLAGS are being passed to c++ files the compiler!"); -#else - cmPassed("CMake CMAKE_C_FLAGS are not being passed to c++ files."); -#endif - if(TestCFlags(msg)) - { - cmPassed( - "CMake CMAKE_C_FLAGS are being passed to c files and CXX flags are not."); - } - else - { - cmFailed(msg); - } - } - if(TestTargetCompileFlags(msg)) - { - cmPassed(msg); - } - else - { - cmFailed(msg); - } - - // ---------------------------------------------------------------------- - // Test ADD_DEFINITIONS - -#ifndef CMAKE_IS_FUN - cmFailed("CMake is not fun, so it is broken and should be fixed."); -#else - cmPassed("CMAKE_IS_FUN is defined."); -#endif - -#if defined(CMAKE_ARGV1) && defined(CMAKE_ARGV2) && defined(CMAKE_ARGV3) && defined(CMAKE_ARGV4) - cmPassed("Variable args for MACROs are working."); -#else - cmFailed("Variable args for MACROs are failing."); -#endif - - // ---------------------------------------------------------------------- - // Test GET_SOURCE_FILE_PROPERTY for location -#ifndef CMAKE_FOUND_ACXX - cmFailed("CMake did not get the location of A.cxx correctly"); -#else - cmPassed("CMake found A.cxx properly"); -#endif - - // ---------------------------------------------------------------------- - // Test GET_DIRECTORY_PROPERTY for parent -#ifndef CMAKE_FOUND_PARENT - cmFailed("CMake did not get the location of the parent directory properly"); -#else - cmPassed("CMake found the parent directory properly"); -#endif - - // ---------------------------------------------------------------------- - // Test GET_DIRECTORY_PROPERTY for listfiles -#ifndef CMAKE_FOUND_LISTFILE_STACK - cmFailed("CMake did not get the listfile stack properly"); -#else - cmPassed("CMake found the listfile stack properly"); -#endif - - // ---------------------------------------------------------------------- - // Test SET, VARIABLE_REQUIRES - -#ifdef SHOULD_NOT_BE_DEFINED - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED is defined."); -#endif - -#ifndef ONE_VAR - cmFailed("cmakedefine is broken, ONE_VAR is not defined."); -#else - cmPassed("ONE_VAR is defined."); -#endif - -#ifndef ONE_VAR_IS_DEFINED - cmFailed("cmakedefine, SET or VARIABLE_REQUIRES is broken, " - "ONE_VAR_IS_DEFINED is not defined."); -#else - cmPassed("ONE_VAR_IS_DEFINED is defined."); -#endif - -#ifdef ZERO_VAR - cmFailed("cmakedefine is broken, ZERO_VAR is defined."); -#else - cmPassed("ZERO_VAR is not defined."); -#endif - -#ifndef STRING_VAR - cmFailed("the CONFIGURE_FILE command is broken, STRING_VAR is not defined."); -#else - if(strcmp(STRING_VAR, "CMake is great") != 0) - { - cmFailed("the SET or CONFIGURE_FILE command is broken. STRING_VAR == ", - STRING_VAR); - } - else - { - cmPassed("STRING_VAR == ", STRING_VAR); - } -#endif - - // ---------------------------------------------------------------------- - // Test various IF/ELSE combinations - -#ifdef SHOULD_NOT_BE_DEFINED_NOT - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_NOT is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_NOT - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_NOT is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_NOT2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_NOT2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_NOT2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_NOT2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_NOT2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_NOT2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_AND - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_AND is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_AND - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_AND is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_AND2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_AND2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_AND2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_AND2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_AND2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_AND2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_OR - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_OR is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_OR - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_OR is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_OR2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_OR2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_OR2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_OR2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_OR2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_OR2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_MATCHES - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_MATCHES - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_MATCHES is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_MATCHES2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_MATCHES2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_MATCHES2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_MATCHES2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_MATCHES2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_MATCHES2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_COMMAND - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_COMMAND - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_COMMAND is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_COMMAND2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_COMMAND2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_COMMAND2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_COMMAND2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_COMMAND2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_COMMAND2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_EXISTS - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_EXISTS - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_EXISTS is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_EXISTS2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EXISTS2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_EXISTS2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_EXISTS2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EXISTS2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_EXISTS2 is defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY is defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_IS_DIRECTORY2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_IS_DIRECTORY2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_IS_DIRECTORY2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_LESS - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_LESS is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_LESS - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_LESS is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_LESS2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_LESS2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_LESS2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_LESS2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_LESS2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_LESS2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_GREATER - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_GREATER is not defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_EQUAL - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_EQUAL is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_EQUAL is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_EQUAL - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_EQUAL is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_EQUAL is defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_GREATER - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_GREATER is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_GREATER2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_GREATER2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_GREATER2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_GREATER2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_GREATER2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_GREATER2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_STRLESS - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_STRLESS - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_STRLESS is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_STRLESS2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRLESS2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_STRLESS2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_STRLESS2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRLESS2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_STRLESS2 is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_STRGREATER - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_STRGREATER is defined."); -#endif - -#ifdef SHOULD_NOT_BE_DEFINED_STRGREATER2 - cmFailed("IF or SET is broken, SHOULD_NOT_BE_DEFINED_STRGREATER2 is defined."); -#else - cmPassed("SHOULD_NOT_BE_DEFINED_STRGREATER2 is not defined."); -#endif - -#ifndef SHOULD_BE_DEFINED_STRGREATER2 - cmFailed("IF or SET is broken, SHOULD_BE_DEFINED_STRGREATER2 is not defined.\n"); -#else - cmPassed("SHOULD_BE_DEFINED_STRGREATER2 is defined."); -#endif - - // ---------------------------------------------------------------------- - // Test FOREACH - -#ifndef FOREACH_VAR1 - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_VAR1 is not defined."); -#else - if(strcmp(FOREACH_VAR1, "VALUE1") != 0) - { - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_VAR1 == ", FOREACH_VAR1); - } - else - { - cmPassed("FOREACH_VAR1 == ", FOREACH_VAR1); - } -#endif - -#ifndef FOREACH_VAR2 - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_VAR2 is not defined."); -#else - if(strcmp(FOREACH_VAR2, "VALUE2") != 0) - { - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_VAR2 == ", FOREACH_VAR2); - } - else - { - cmPassed("FOREACH_VAR2 == ", FOREACH_VAR2); - } -#endif - -#ifndef FOREACH_CONCAT - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_CONCAT is not defined."); -#else - if(strcmp(FOREACH_CONCAT, "abcdefg") != 0) - { - cmFailed("the FOREACH, SET or CONFIGURE_FILE command is broken, " - "FOREACH_CONCAT == ", FOREACH_CONCAT); - } - else - { - cmPassed("FOREACH_CONCAT == ", FOREACH_CONCAT); - } -#endif - - // ---------------------------------------------------------------------- - // Test WHILE - - if(WHILE_VALUE != 1000) - { - cmFailed("WHILE command is not working"); - } - else - { - cmPassed("WHILE command is working"); - } - - // ---------------------------------------------------------------------- - // Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#ifndef FILENAME_VAR_PATH_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME is not defined."); -#else - if((strcmp(FILENAME_VAR_PATH_NAME, "Complex") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexOneConfig") == 0) || - (strcmp(FILENAME_VAR_PATH_NAME, "ComplexRelativePaths") == 0)) - { - cmPassed("FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_PATH_NAME == ", FILENAME_VAR_PATH_NAME); - } -#endif - -#ifndef FILENAME_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME, "VarTests.cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } - else - { - cmPassed("FILENAME_VAR_NAME == ", FILENAME_VAR_NAME); - } -#endif - -#ifndef FILENAME_VAR_EXT - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT is not defined."); -#else - if(strcmp(FILENAME_VAR_EXT, ".cmake") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } - else - { - cmPassed("FILENAME_VAR_EXT == ", FILENAME_VAR_EXT); - } -#endif - -#ifndef FILENAME_VAR_NAME_WE - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE is not defined."); -#else - if(strcmp(FILENAME_VAR_NAME_WE, "VarTests") != 0) - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } - else - { - cmPassed("FILENAME_VAR_NAME_WE == ", FILENAME_VAR_NAME_WE); - } -#endif - -#ifndef PATH_VAR_NAME - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME is not defined."); -#else - if((strcmp(PATH_VAR_NAME, "Complex") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexOneConfig") == 0) || - (strcmp(PATH_VAR_NAME, "ComplexRelativePaths") == 0)) - { - cmPassed("PATH_VAR_NAME == ", PATH_VAR_NAME); - } - else - { - cmFailed("the FIND_FILE or GET_FILENAME_COMPONENT command is broken, " - "PATH_VAR_NAME == ", PATH_VAR_NAME); - } -#endif - - // ---------------------------------------------------------------------- - // Test LOAD_CACHE - -#ifndef CACHE_TEST_VAR1 - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR1 is not defined."); -#else - if(strcmp(CACHE_TEST_VAR1, "foo") != 0) - { - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1); - } - else - { - cmPassed("CACHE_TEST_VAR1 == ", CACHE_TEST_VAR1); - } -#endif - -#ifndef CACHE_TEST_VAR2 - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR2 is not defined."); -#else - if(strcmp(CACHE_TEST_VAR2, "bar") != 0) - { - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2); - } - else - { - cmPassed("CACHE_TEST_VAR2 == ", CACHE_TEST_VAR2); - } -#endif - -#ifndef CACHE_TEST_VAR3 - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR3 is not defined."); -#else - if(strcmp(CACHE_TEST_VAR3, "1") != 0) - { - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3); - } - else - { - cmPassed("CACHE_TEST_VAR3 == ", CACHE_TEST_VAR3); - } -#endif - -#ifdef CACHE_TEST_VAR_EXCLUDED - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command or cmakedefine is broken, " - "CACHE_TEST_VAR_EXCLUDED is defined (should not have been loaded)."); -#else - cmPassed("CACHE_TEST_VAR_EXCLUDED is not defined."); -#endif - -#ifndef CACHE_TEST_VAR_INTERNAL - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR_INTERNAL is not defined."); -#else - std::string cachetest = CACHE_TEST_VAR_INTERNAL; - if(cachetest != "bar") - { - cmFailed("the LOAD_CACHE or CONFIGURE_FILE command is broken, " - "CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL); - } - else - { - cmPassed("CACHE_TEST_VAR_INTERNAL == ", CACHE_TEST_VAR_INTERNAL); - } -#endif - -#ifdef COMPLEX_TEST_CMAKELIB - // ---------------------------------------------------------------------- - // Some pre-build/pre-link/post-build custom-commands have been - // attached to the lib (see Library/). - // Each runs ${CREATE_FILE_EXE} which will create a file. - // It also copies that file again using cmake -E. - // Similar rules have been added to this executable. - // - // WARNING: if you run 'complex' manually, this *will* fail, because - // the file was removed the last time 'complex' was run, and it is - // only created during a build. - - TestAndRemoveFile(BINARY_DIR "/Library/prebuild.txt"); - TestAndRemoveFile(BINARY_DIR "/Library/prelink.txt"); - TestAndRemoveFile(BINARY_DIR "/Library/postbuild.txt"); - TestAndRemoveFile(BINARY_DIR "/Library/postbuild2.txt"); - TestAndRemoveFile(BINARY_DIR "/Executable/prebuild.txt"); - TestAndRemoveFile(BINARY_DIR "/Executable/prelink.txt"); - TestAndRemoveFile(BINARY_DIR "/Executable/postbuild.txt"); - TestAndRemoveFile(BINARY_DIR "/Executable/postbuild2.txt"); - - // ---------------------------------------------------------------------- - // A custom target has been created (see Library/). - // It runs ${CREATE_FILE_EXE} which will create a file. - // - // WARNING: if you run 'complex' manually, this *will* fail, because - // the file was removed the last time 'complex' was run, and it is - // only created during a build. - - TestAndRemoveFile(BINARY_DIR "/Library/custom_target1.txt"); - - // ---------------------------------------------------------------------- - // A directory has been created. - - TestDir(BINARY_DIR "/make_dir"); - - // ---------------------------------------------------------------------- - // Test OUTPUT_REQUIRED_FILES - // The files required by 'complex' have been output to a file. - // The contents of this file is not tested (absolute paths). - // - // WARNING: if you run 'complex' manually, this *will* fail, because - // the file was removed the last time 'complex' was run, and it is - // only created during a build. - - TestAndRemoveFile(BINARY_DIR "/Executable/Temp/complex-required.txt"); -#endif - - // ---------------------------------------------------------------------- - // Test FIND_LIBRARY - -#ifndef FIND_DUMMY_LIB - cmFailed("the CONFIGURE_FILE command is broken, " - "FIND_DUMMY_LIB is not defined."); -#else - if(strstr(FIND_DUMMY_LIB, "dummylib") == NULL) - { - cmFailed("the FIND_LIBRARY or CONFIGURE_FILE command is broken, " - "FIND_DUMMY_LIB == ", FIND_DUMMY_LIB); - } - else - { - cmPassed("FIND_DUMMY_LIB == ", FIND_DUMMY_LIB); - } -#endif - - // ---------------------------------------------------------------------- - // Test SET_SOURCE_FILES_PROPERTIES - -#ifndef FILE_HAS_EXTRA_COMPILE_FLAGS - cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_HAS_EXTRA_COMPILE_FLAGS flag"); -#else - cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_HAS_EXTRA_COMPILE_FLAGS flag"); -#endif - -#if 0 // Disable until implemented everywhere. -#ifndef FILE_DEFINE_STRING - cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag"); -#else - if(strcmp(FILE_DEFINE_STRING, "hello") != 0) - { - cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting FILE_DEFINE_STRING flag correctly"); - } - else - { - cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting FILE_DEFINE_STRING flag"); - } -#endif -#endif - -#ifndef FILE_HAS_ABSTRACT - cmFailed("SET_SOURCE_FILES_PROPERTIES failed at setting ABSTRACT flag"); -#else - cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting ABSTRACT flag"); -#endif - -#ifndef FILE_HAS_WRAP_EXCLUDE - cmFailed("FILE_HAS_WRAP_EXCLUDE failed at setting WRAP_EXCLUDE flag"); -#else - cmPassed("FILE_HAS_WRAP_EXCLUDE succeeded in setting WRAP_EXCLUDE flag"); -#endif - -#ifndef FILE_COMPILE_FLAGS - cmFailed("the CONFIGURE_FILE command is broken, FILE_COMPILE_FLAGS is not defined."); -#else - if(strcmp(FILE_COMPILE_FLAGS, "-foo -bar") != 0) - { - cmFailed("the SET_SOURCE_FILES_PROPERTIES or CONFIGURE_FILE command is broken. FILE_COMPILE_FLAGS == ", - FILE_COMPILE_FLAGS); - } - else - { - cmPassed("SET_SOURCE_FILES_PROPERTIES succeeded in setting extra flags == ", FILE_COMPILE_FLAGS); - } -#endif - - // ---------------------------------------------------------------------- - // Test registry (win32) -#if defined(_WIN32) && !defined(__CYGWIN__) -#ifndef REGISTRY_TEST_PATH - cmFailed("the CONFIGURE_FILE command is broken, REGISTRY_TEST_PATH is not defined."); -#else - std::cout << "REGISTRY_TEST_PATH == " << REGISTRY_TEST_PATH << "\n"; - if(stricmp(REGISTRY_TEST_PATH, BINARY_DIR "/registry_dir") != 0) - { - cmFailed("the 'read registry value' function or CONFIGURE_FILE command is broken. REGISTRY_TEST_PATH == ", - REGISTRY_TEST_PATH, " is not " BINARY_DIR "/registry_dir"); - } - else - { - cmPassed("REGISTRY_TEST_PATH == ", REGISTRY_TEST_PATH); - } -#endif -#endif // defined(_WIN32) && !defined(__CYGWIN__) - - if(strcmp(CMAKE_MINIMUM_REQUIRED_VERSION, "1.3") == 0) - { - cmPassed("CMAKE_MINIMUM_REQUIRED_VERSION is set to 1.3"); - } - else - { - cmFailed("CMAKE_MINIMUM_REQUIRED_VERSION is not set to the expected 1.3"); - } - - // ---------------------------------------------------------------------- - // Test REMOVE command - if (strcmp("a;b;d",REMOVE_STRING) == 0) - { - cmPassed("REMOVE is working"); - } - else - { - cmFailed("REMOVE is not working"); - } - - // ---------------------------------------------------------------------- - // Test SEPARATE_ARGUMENTS - if(strcmp("a;b;c", TEST_SEP) == 0) - { - cmPassed("SEPARATE_ARGUMENTS is working"); - } - else - { - cmFailed("SEPARATE_ARGUMENTS is not working"); - } - - // ---------------------------------------------------------------------- - // Test Escape Quotes - if(strcmp("\"hello world\"", STRING_WITH_QUOTES) == 0) - { - cmPassed("ESCAPE_QUOTES is working"); - } - else - { - cmFailed("ESCAPE_QUOTES is not working"); - } - - - // ---------------------------------------------------------------------- - // Test if IF command inside a FOREACH works. -#if defined(IF_INSIDE_FOREACH_THEN_EXECUTED) && !defined(IF_INSIDE_FOREACH_ELSE_EXECUTED) - cmPassed("IF inside a FOREACH block works"); -#else - cmFailed("IF inside a FOREACH block is broken"); -#endif - -#if defined(GENERATED_HEADER_INCLUDED) - cmPassed("Generated header included by non-generated source works."); -#else - cmFailed("Generated header included by non-generated source failed."); -#endif - if(SHOULD_BE_ZERO == 0) - { - cmPassed("cmakedefine01 is working for 0"); - } - else - { - cmFailed("cmakedefine01 is not working for 0"); - } - if(SHOULD_BE_ONE == 1) - { - cmPassed("cmakedefine01 is working for 1"); - } - else - { - cmFailed("cmakedefine01 is not working for 1"); - } -#ifdef FORCE_TEST - cmFailed("CMake SET CACHE FORCE"); -#else - cmPassed("CMake SET CACHE FORCE"); -#endif - -#ifdef COMPLEX_TEST_CMAKELIB - // Test the generated file stream. - TestCMGeneratedFileSTream(); -#endif - -#ifdef COMPLEX_TEST_LINK_STATIC - if(TestLinkGetType()) - { - cmPassed("Link to static over shared worked."); - } - else - { - cmFailed("Link to static over shared failed."); - } -#endif - - // ---------------------------------------------------------------------- - // Summary - - std::cout << "Passed: " << cm_passed << "\n"; - if(cm_failed) - { - std::cout << "Failed: " << cm_failed << "\n"; - return cm_failed; - } - return 0; -} diff --git a/Tests/ComplexRelativePaths/Executable/complex.file.cxx b/Tests/ComplexRelativePaths/Executable/complex.file.cxx deleted file mode 100644 index e873fa644..000000000 --- a/Tests/ComplexRelativePaths/Executable/complex.file.cxx +++ /dev/null @@ -1,8 +0,0 @@ -#if 0 -#include "cmMissingHeader.h" -#endif - -int main(int , char**) -{ - return 0; -} diff --git a/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx b/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx deleted file mode 100644 index 70275cd51..000000000 --- a/Tests/ComplexRelativePaths/Executable/notInAllExe.cxx +++ /dev/null @@ -1,10 +0,0 @@ -extern int notInAllLibFunc(); - -int main() -{ - return notInAllLibFunc(); -} - -#if 1 -# error "This target should not be compiled by ALL." -#endif diff --git a/Tests/ComplexRelativePaths/Executable/testSystemDir.cxx b/Tests/ComplexRelativePaths/Executable/testSystemDir.cxx deleted file mode 100644 index e4815c679..000000000 --- a/Tests/ComplexRelativePaths/Executable/testSystemDir.cxx +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main() { return foo(); } diff --git a/Tests/ComplexRelativePaths/Executable/testcflags.c b/Tests/ComplexRelativePaths/Executable/testcflags.c deleted file mode 100644 index f4d584844..000000000 --- a/Tests/ComplexRelativePaths/Executable/testcflags.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -int TestTargetCompileFlags(char* m) -{ -#ifndef COMPLEX_TARGET_FLAG - strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS did not work"); - return 0; -#endif - strcpy(m, "CMAKE SET_TARGET_PROPERTIES COMPILE_FLAGS worked"); - return 1; -} - -int TestCFlags(char* m) -{ - /* TEST_CXX_FLAGS should not be defined in a c file */ -#ifdef TEST_CXX_FLAGS - strcpy(m, "CMake CMAKE_CXX_FLAGS (TEST_CXX_FLAGS) found in c file."); - return 0; -#endif - /* TEST_C_FLAGS should be defined in a c file */ -#ifndef TEST_C_FLAGS - strcpy(m, "CMake CMAKE_C_FLAGS (TEST_C_FLAGS) not found in c file."); - return 0; -#endif - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/CMakeLists.txt b/Tests/ComplexRelativePaths/Library/CMakeLists.txt deleted file mode 100644 index 281e48a55..000000000 --- a/Tests/ComplexRelativePaths/Library/CMakeLists.txt +++ /dev/null @@ -1,141 +0,0 @@ -REMOVE_DEFINITIONS(-DCMAKE_IS_REALLY_FUN) - -# -# Small utility used to create file -# UTILITY_SOURCE is used for coverage and for getting the exact name -# of the executable. -# -UTILITY_SOURCE(CREATE_FILE_EXE create_file "." create_file.cxx) -ADD_EXECUTABLE(create_file create_file.cxx) -SET_TARGET_PROPERTIES(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".") - -# -# Create static library -# SOURCE_FILES_REMOVE is used for Coverage. empty.h is included for coverage -# -AUX_SOURCE_DIRECTORY(ExtraSources LibrarySources) -SET(LibrarySources ${LibrarySources} - file2 - empty - create_file.cxx - GENERATED - nonexisting_file) -REMOVE(LibrarySources create_file.cxx GENERATED nonexisting_file) -ADD_LIBRARY(CMakeTestLibrary ${LibrarySources}) - -IF(WIN32) - IF(NOT CYGWIN) - IF(NOT BORLAND) - IF(NOT MINGW) - TARGET_LINK_LIBRARIES(CMakeTestLibrary - debug - user32.lib) - TARGET_LINK_LIBRARIES(CMakeTestLibrary - optimized - kernel32.lib) - ENDIF(NOT MINGW) - ENDIF(NOT BORLAND) - ENDIF(NOT CYGWIN) -ENDIF(WIN32) - -# -# Create shared library -# -SET(SharedLibrarySources sharedFile) -ADD_LIBRARY(CMakeTestLibraryShared SHARED ${SharedLibrarySources}) -ADD_LIBRARY(CMakeTestModule MODULE moduleFile.c) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_C_FLAGS") -ADD_LIBRARY(CMakeTestCLibraryShared SHARED testConly.c) -DEFINE_PROPERTY( - TARGET PROPERTY FOO - BRIEF_DOCS "a test property" - FULL_DOCS "A simple etst proerty that means nothign and is used for nothing" - ) -SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES FOO BAR) -IF(NOT BEOS AND NOT WIN32) # No libm on BeOS. - SET_TARGET_PROPERTIES(CMakeTestCLibraryShared PROPERTIES LINK_FLAGS "-lm") -ENDIF(NOT BEOS AND NOT WIN32) -GET_TARGET_PROPERTY(FOO_BAR_VAR CMakeTestCLibraryShared FOO) -IF(${FOO_BAR_VAR} MATCHES "BAR") -ELSE(${FOO_BAR_VAR} MATCHES "BAR") - MESSAGE(SEND_ERROR "SET_TARGET_PROPERTIES or GET_TARGET_PROPERTY failed, FOO_BAR_VAR should be BAR, but is ${FOO_BAR_VAR}") -ENDIF(${FOO_BAR_VAR} MATCHES "BAR") - -# Create static and shared lib of same name. -IF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS) - ADD_LIBRARY(CMakeTestLinkStatic STATIC TestLink.c) - ADD_LIBRARY(CMakeTestLinkShared SHARED TestLink.c) - SET_TARGET_PROPERTIES(CMakeTestLinkStatic CMakeTestLinkShared - PROPERTIES OUTPUT_NAME CMakeTestLink) -ENDIF(CMAKE_EXE_LINK_STATIC_CXX_FLAGS) - -# -# Attach pre-build/pre-link/post-build custom-commands to the lib. -# Each runs ${CREATE_FILE_EXE} which will create a file. -# The 'complex' executable will then test if this file exists and remove it. -# -ADD_DEPENDENCIES(CMakeTestLibraryShared create_file) -MESSAGE("complex bin dir is ${Complex_BINARY_DIR}") -ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Library/prebuild.txt") -ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared PRE_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Library/prelink.txt") -ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD - COMMAND ${CREATE_FILE_EXE} - ARGS "${Complex_BINARY_DIR}/Library/postbuild.txt") -ADD_CUSTOM_COMMAND(TARGET CMakeTestLibraryShared POST_BUILD - COMMAND ${CMAKE_COMMAND} - ARGS -E copy - "${Complex_BINARY_DIR}/Library/postbuild.txt" - "${Complex_BINARY_DIR}/Library/postbuild2.txt") - -# -# Add a custom target. -# It runs ${CREATE_FILE_EXE} which will create a file. -# The 'complex' executable will then test if this file exists and remove it. -# -ADD_CUSTOM_TARGET(custom_target1 - ALL - ${CREATE_FILE_EXE} - "${Complex_BINARY_DIR}/Library/custom_target1.txt") - -ADD_DEPENDENCIES(custom_target1 create_file) - -# -# Extra coverage -# -SET_SOURCE_FILES_PROPERTIES(file2 PROPERTIES ABSTRACT 1) - -INSTALL_FILES(/tmp .h ${Complex_BINARY_DIR}/cmTestConfigure.h) -INSTALL_FILES(/tmp .cxx ${Complex_BINARY_DIR}/cmTestConfigure.h) - -# Test creating a library that is not built by default. -ADD_LIBRARY(notInAllLib EXCLUDE_FROM_ALL notInAllLib.cxx) - -# Create an imported target for if(TARGET) test in Executable dir. -# That test should not see this target. -ADD_LIBRARY(LibImportedTarget UNKNOWN IMPORTED) - -# Test generation of preprocessed sources. -IF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM) - IF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE) - # Skip running this part of the test on certain platforms - # until they are fixed. - SET(MAYBE_ALL ALL) - LIST(LENGTH CMAKE_OSX_ARCHITECTURES ARCH_COUNT) - IF(ARCH_COUNT GREATER 1) - # OSX does not support preprocessing more than one architecture. - SET(MAYBE_ALL) - ENDIF(ARCH_COUNT GREATER 1) - - # Custom target to try preprocessing invocation. - ADD_CUSTOM_TARGET(test_preprocess ${MAYBE_ALL} - COMMAND ${CMAKE_COMMAND} -E remove CMakeFiles/create_file.dir/create_file.i - COMMAND ${CMAKE_MAKE_PROGRAM} create_file.i - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/test_preprocess.cmake - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) - ENDIF(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE) -ENDIF("${CMAKE_GENERATOR}" MATCHES "Makefile" AND CMAKE_MAKE_PROGRAM) diff --git a/Tests/ComplexRelativePaths/Library/ExtraSources/file1.cxx b/Tests/ComplexRelativePaths/Library/ExtraSources/file1.cxx deleted file mode 100644 index e22812e51..000000000 --- a/Tests/ComplexRelativePaths/Library/ExtraSources/file1.cxx +++ /dev/null @@ -1,4 +0,0 @@ -int file1() -{ - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/ExtraSources/file1.h b/Tests/ComplexRelativePaths/Library/ExtraSources/file1.h deleted file mode 100644 index ce0d818a3..000000000 --- a/Tests/ComplexRelativePaths/Library/ExtraSources/file1.h +++ /dev/null @@ -1 +0,0 @@ -int file1(); diff --git a/Tests/ComplexRelativePaths/Library/SystemDir/testSystemDir.h b/Tests/ComplexRelativePaths/Library/SystemDir/testSystemDir.h deleted file mode 100644 index 73be3538e..000000000 --- a/Tests/ComplexRelativePaths/Library/SystemDir/testSystemDir.h +++ /dev/null @@ -1,2 +0,0 @@ -// Purposely leave off the return type to create a warning. -foo() { return 0; } diff --git a/Tests/ComplexRelativePaths/Library/TestLink.c b/Tests/ComplexRelativePaths/Library/TestLink.c deleted file mode 100644 index 25dee082f..000000000 --- a/Tests/ComplexRelativePaths/Library/TestLink.c +++ /dev/null @@ -1,8 +0,0 @@ -int TestLinkGetType() -{ -#ifdef CMakeTestLinkShared_EXPORTS - return 0; -#else - return 1; -#endif -} diff --git a/Tests/ComplexRelativePaths/Library/create_file.cxx b/Tests/ComplexRelativePaths/Library/create_file.cxx deleted file mode 100644 index d41551980..000000000 --- a/Tests/ComplexRelativePaths/Library/create_file.cxx +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include - -int main (int argc, char *argv[]) -{ - if (argc < 2) - { - fprintf(stderr, "Missing name of file to create.\n"); - return EXIT_FAILURE; - } - - FILE *stream = fopen(argv[1], "w"); - if(stream == NULL) - { - fprintf(stderr, "Unable to open %s for writing!\n", argv[1]); - return EXIT_FAILURE; - } - - if(fclose(stream)) - { - fprintf(stderr, "Unable to close %s!\n", argv[1]); - return EXIT_FAILURE; - } - - fprintf(stdout, ">> Creating %s!\n", argv[1]); - - return EXIT_SUCCESS; -} diff --git a/Tests/ComplexRelativePaths/Library/file2.cxx b/Tests/ComplexRelativePaths/Library/file2.cxx deleted file mode 100644 index 863fcaa51..000000000 --- a/Tests/ComplexRelativePaths/Library/file2.cxx +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#ifdef CMAKE_IS_REALLY_FUN -This is a problem. Looks like REMOVE_DEFINITION does not work -#endif - -int file2() -{ - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/file2.h b/Tests/ComplexRelativePaths/Library/file2.h deleted file mode 100644 index dea4b80b1..000000000 --- a/Tests/ComplexRelativePaths/Library/file2.h +++ /dev/null @@ -1 +0,0 @@ -int file2(); diff --git a/Tests/ComplexRelativePaths/Library/moduleFile.c b/Tests/ComplexRelativePaths/Library/moduleFile.c deleted file mode 100644 index 608d750f1..000000000 --- a/Tests/ComplexRelativePaths/Library/moduleFile.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "moduleFile.h" - -int ModuleFunction() -{ - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/moduleFile.h b/Tests/ComplexRelativePaths/Library/moduleFile.h deleted file mode 100644 index 6b561e109..000000000 --- a/Tests/ComplexRelativePaths/Library/moduleFile.h +++ /dev/null @@ -1,12 +0,0 @@ -#if defined(_WIN32) || defined(WIN32) /* Win32 version */ -#ifdef CMakeTestModule_EXPORTS -# define CMakeTest_EXPORT __declspec(dllexport) -#else -# define CMakeTest_EXPORT __declspec(dllimport) -#endif -#else -/* unix needs nothing */ -#define CMakeTest_EXPORT -#endif - -CMakeTest_EXPORT int ModuleFunction(); diff --git a/Tests/ComplexRelativePaths/Library/notInAllLib.cxx b/Tests/ComplexRelativePaths/Library/notInAllLib.cxx deleted file mode 100644 index 5d928f44a..000000000 --- a/Tests/ComplexRelativePaths/Library/notInAllLib.cxx +++ /dev/null @@ -1,5 +0,0 @@ -int notInAllLibFunc() { return 0; } - -#if 1 -# error "This target should not be compiled by ALL." -#endif diff --git a/Tests/ComplexRelativePaths/Library/sharedFile.cxx b/Tests/ComplexRelativePaths/Library/sharedFile.cxx deleted file mode 100644 index cafac68f4..000000000 --- a/Tests/ComplexRelativePaths/Library/sharedFile.cxx +++ /dev/null @@ -1,6 +0,0 @@ -#include "sharedFile.h" - -int sharedFunction() -{ - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/sharedFile.h b/Tests/ComplexRelativePaths/Library/sharedFile.h deleted file mode 100644 index 65ac2e2ba..000000000 --- a/Tests/ComplexRelativePaths/Library/sharedFile.h +++ /dev/null @@ -1,12 +0,0 @@ -#if defined(_WIN32) || defined(WIN32) /* Win32 version */ -#ifdef CMakeTestLibraryShared_EXPORTS -# define CMakeTest_EXPORT __declspec(dllexport) -#else -# define CMakeTest_EXPORT __declspec(dllimport) -#endif -#else -/* unix needs nothing */ -#define CMakeTest_EXPORT -#endif - -CMakeTest_EXPORT int sharedFunction(); diff --git a/Tests/ComplexRelativePaths/Library/testConly.c b/Tests/ComplexRelativePaths/Library/testConly.c deleted file mode 100644 index 2d83f778e..000000000 --- a/Tests/ComplexRelativePaths/Library/testConly.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "testConly.h" -#include - -int CsharedFunction() -{ -#ifndef TEST_C_FLAGS - printf("TEST_C_FLAGS failed\n"); - return 0; -#else - printf("Passed: TEST_C_FLAGS passed\n"); -#endif - return 1; -} diff --git a/Tests/ComplexRelativePaths/Library/testConly.h b/Tests/ComplexRelativePaths/Library/testConly.h deleted file mode 100644 index f1470a8d7..000000000 --- a/Tests/ComplexRelativePaths/Library/testConly.h +++ /dev/null @@ -1,13 +0,0 @@ -#if defined(_WIN32) || defined(WIN32) /* Win32 version */ -#ifdef CMakeTestCLibraryShared_EXPORTS -# define CMakeTest_EXPORT __declspec(dllexport) -#else -# define CMakeTest_EXPORT __declspec(dllimport) -#endif -#else -/* unix needs nothing */ -#define CMakeTest_EXPORT -#endif - -CMakeTest_EXPORT int CsharedFunction(); - diff --git a/Tests/ComplexRelativePaths/Library/test_preprocess.cmake b/Tests/ComplexRelativePaths/Library/test_preprocess.cmake deleted file mode 100644 index d2d9fc652..000000000 --- a/Tests/ComplexRelativePaths/Library/test_preprocess.cmake +++ /dev/null @@ -1,7 +0,0 @@ -SET(TEST_FILE CMakeFiles/create_file.dir/create_file.i) -FILE(READ ${TEST_FILE} CONTENTS) -IF("${CONTENTS}" MATCHES "Unable to close") - MESSAGE(STATUS "${TEST_FILE} created successfully!") -ELSE("${CONTENTS}" MATCHES "Unable to close") - MESSAGE(FATAL_ERROR "${TEST_FILE} creation failed!") -ENDIF("${CONTENTS}" MATCHES "Unable to close") diff --git a/Tests/ComplexRelativePaths/VarTests.cmake b/Tests/ComplexRelativePaths/VarTests.cmake deleted file mode 100644 index c146d1be0..000000000 --- a/Tests/ComplexRelativePaths/VarTests.cmake +++ /dev/null @@ -1,198 +0,0 @@ -# -# Test SET -# -SET (ZERO_VAR 0) -SET (ZERO_VAR2 0) - -IF(ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED) -ELSE(ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED) -ENDIF(ZERO_VAR) - -SET(ONE_VAR 1) -SET(ONE_VAR2 1) -SET(STRING_VAR "CMake is great" CACHE STRING "test a cache variable") - -# -# Test VARIABLE_REQUIRES -# -VARIABLE_REQUIRES(ONE_VAR - ONE_VAR_IS_DEFINED ONE_VAR) - -# -# Test various IF/ELSE combinations -# -IF(NOT ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_NOT) -ELSE(NOT ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_NOT) -ENDIF(NOT ZERO_VAR) - -IF(NOT ONE_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_NOT2) -ELSE(NOT ONE_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_NOT2) -ENDIF(NOT ONE_VAR) - -IF(ONE_VAR AND ONE_VAR2) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_AND) -ELSE(ONE_VAR AND ONE_VAR2) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_AND) -ENDIF(ONE_VAR AND ONE_VAR2) - -IF(ONE_VAR AND ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_AND2) -ELSE(ONE_VAR AND ZERO_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_AND2) -ENDIF(ONE_VAR AND ZERO_VAR) - -IF(ZERO_VAR OR ONE_VAR2) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_OR) -ELSE(ZERO_VAR OR ONE_VAR2) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_OR) -ENDIF(ZERO_VAR OR ONE_VAR2) - -IF(ZERO_VAR OR ZERO_VAR2) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_OR2) -ELSE(ZERO_VAR OR ZERO_VAR2) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_OR2) -ENDIF(ZERO_VAR OR ZERO_VAR2) - -IF(STRING_VAR MATCHES "^CMake") - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_MATCHES) -ELSE(STRING_VAR MATCHES "^CMake") - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_MATCHES) -ENDIF(STRING_VAR MATCHES "^CMake") - -IF(STRING_VAR MATCHES "^foo") - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_MATCHES2) -ELSE(STRING_VAR MATCHES "^foo") - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_MATCHES2) -ENDIF(STRING_VAR MATCHES "^foo") - -IF(COMMAND "IF") - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_COMMAND) -ELSE(COMMAND "IF") - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_COMMAND) -ENDIF(COMMAND "IF") - -IF(COMMAND "ROQUEFORT") - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_COMMAND2) -ELSE(COMMAND "ROQUEFORT") - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_COMMAND2) -ENDIF(COMMAND "ROQUEFORT") - -IF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_EXISTS) -ELSE(EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_EXISTS) -ENDIF (EXISTS ${Complex_SOURCE_DIR}/VarTests.cmake) - -IF (EXISTS ${Complex_SOURCE_DIR}/roquefort.txt) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_EXISTS2) -ELSE(EXISTS ${Complex_SOURCE_DIR}/roquefort.txt) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_EXISTS2) -ENDIF (EXISTS ${Complex_SOURCE_DIR}/roquefort.txt) - -IF (IS_DIRECTORY ${Complex_SOURCE_DIR}) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_IS_DIRECTORY) -ENDIF (IS_DIRECTORY ${Complex_SOURCE_DIR}) - -IF (NOT IS_DIRECTORY ${Complex_SOURCE_DIR}/VarTests.cmake) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_IS_DIRECTORY2) -ENDIF (NOT IS_DIRECTORY ${Complex_SOURCE_DIR}/VarTests.cmake) - -SET (SNUM1_VAR "1") -SET (SNUM2_VAR "2") -SET (SNUM3_VAR "1") - - -IF (SNUM1_VAR LESS SNUM2_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_LESS) -ELSE (SNUM1_VAR LESS SNUM2_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_LESS) -ENDIF (SNUM1_VAR LESS SNUM2_VAR) - -IF (SNUM2_VAR LESS SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_LESS2) -ELSE (SNUM2_VAR LESS SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_LESS2) -ENDIF (SNUM2_VAR LESS SNUM1_VAR) - -IF (SNUM2_VAR GREATER SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_GREATER) -ELSE (SNUM2_VAR GREATER SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_GREATER) -ENDIF (SNUM2_VAR GREATER SNUM1_VAR) - -IF (SNUM2_VAR EQUAL SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_EQUAL) -ELSE (SNUM2_VAR EQUAL SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_EQUAL) -ENDIF (SNUM2_VAR EQUAL SNUM1_VAR) - -IF (SNUM3_VAR EQUAL SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_EQUAL) -ELSE (SNUM3_VAR EQUAL SNUM1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_EQUAL) -ENDIF (SNUM3_VAR EQUAL SNUM1_VAR) - -IF (SNUM1_VAR GREATER SNUM2_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_GREATER2) -ELSE (SNUM1_VAR GREATER SNUM2_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_GREATER2) -ENDIF (SNUM1_VAR GREATER SNUM2_VAR) - -SET (SSTR1_VAR "abc") -SET (SSTR2_VAR "bcd") - -IF (SSTR1_VAR STRLESS SSTR2_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_STRLESS) -ELSE (SSTR1_VAR STRLESS SSTR2_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_STRLESS) -ENDIF (SSTR1_VAR STRLESS SSTR2_VAR) - -IF (SSTR2_VAR STRLESS SSTR1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_STRLESS2) -ELSE (SSTR2_VAR STRLESS SSTR1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_STRLESS2) -ENDIF (SSTR2_VAR STRLESS SSTR1_VAR) - -IF (SSTR2_VAR STRGREATER SSTR1_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_STRGREATER) -ELSE (SSTR2_VAR STRGREATER SSTR1_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_STRGREATER) -ENDIF (SSTR2_VAR STRGREATER SSTR1_VAR) - -IF (SSTR1_VAR STRGREATER SSTR2_VAR) - ADD_DEFINITIONS(-DSHOULD_NOT_BE_DEFINED_STRGREATER2) -ELSE (SSTR1_VAR STRGREATER SSTR2_VAR) - ADD_DEFINITIONS(-DSHOULD_BE_DEFINED_STRGREATER2) -ENDIF (SSTR1_VAR STRGREATER SSTR2_VAR) - -# -# Test FOREACH -# -FOREACH (INDEX 1 2) - SET(FOREACH_VAR${INDEX} "VALUE${INDEX}") -ENDFOREACH(INDEX) - -SET(FOREACH_CONCAT "") -FOREACH (INDEX a;b;c;d;e;f;g) - SET(FOREACH_CONCAT "${FOREACH_CONCAT}${INDEX}") -ENDFOREACH(INDEX) - -# -# Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations -# -FIND_FILE(FILENAME_VAR "VarTests.cmake" ${Complex_SOURCE_DIR}) - -GET_FILENAME_COMPONENT(FILENAME_VAR_PATH ${FILENAME_VAR} PATH) -GET_FILENAME_COMPONENT(FILENAME_VAR_PATH_NAME ${FILENAME_VAR_PATH} NAME) -GET_FILENAME_COMPONENT(FILENAME_VAR_NAME ${FILENAME_VAR} NAME) -GET_FILENAME_COMPONENT(FILENAME_VAR_EXT ${FILENAME_VAR} EXT) -GET_FILENAME_COMPONENT(FILENAME_VAR_NAME_WE ${FILENAME_VAR} NAME_WE CACHE) - -FIND_PATH(PATH_VAR "cmTestConfigure.h.in" ${Complex_SOURCE_DIR}) -GET_FILENAME_COMPONENT(PATH_VAR_NAME ${PATH_VAR} NAME) diff --git a/Tests/ComplexRelativePaths/cmTestConfigure.h.in b/Tests/ComplexRelativePaths/cmTestConfigure.h.in deleted file mode 100644 index d7952da1e..000000000 --- a/Tests/ComplexRelativePaths/cmTestConfigure.h.in +++ /dev/null @@ -1,87 +0,0 @@ -// Test SET, VARIABLE_REQUIRES - -#cmakedefine ONE_VAR -#cmakedefine ONE_VAR_IS_DEFINED -#cmakedefine ZERO_VAR - -#cmakedefine COMPLEX_TEST_CMAKELIB - -#define STRING_VAR "${STRING_VAR}" - -// Test FOREACH - -#define FOREACH_VAR1 "${FOREACH_VAR1}" -#define FOREACH_VAR2 "${FOREACH_VAR2}" -#define FOREACH_CONCAT "${FOREACH_CONCAT}" - -// Test WHILE -#define WHILE_VALUE ${while_var} - -// Test FIND_FILE, FIND_PATH and various GET_FILENAME_COMPONENT combinations - -#define FILENAME_VAR_PATH_NAME "${FILENAME_VAR_PATH_NAME}" -#define FILENAME_VAR_NAME "${FILENAME_VAR_NAME}" -#define FILENAME_VAR_EXT "${FILENAME_VAR_EXT}" -#define FILENAME_VAR_NAME_WE "${FILENAME_VAR_NAME_WE}" - -#define PATH_VAR_NAME "${PATH_VAR_NAME}" - -// Test LOAD_CACHE - -#define CACHE_TEST_VAR1 "${CACHE_TEST_VAR1}" -#define CACHE_TEST_VAR2 "${CACHE_TEST_VAR2}" -#define CACHE_TEST_VAR3 "${CACHE_TEST_VAR3}" -#cmakedefine CACHE_TEST_VAR_EXCLUDED -#define CACHE_TEST_VAR_INTERNAL "${CACHE_TEST_VAR_INTERNAL}" - -// Test internal CMake vars from C++ flags - -#cmakedefine CMAKE_NO_STD_NAMESPACE -#cmakedefine CMAKE_NO_ANSI_STREAM_HEADERS -#cmakedefine CMAKE_NO_ANSI_STRING_STREAM -#cmakedefine CMAKE_NO_ANSI_FOR_SCOPE - -#cmakedefine01 SHOULD_BE_ZERO -#cmakedefine01 SHOULD_BE_ONE -// Needed to check for files - -#define BINARY_DIR "${Complex_BINARY_DIR}" - -// Test FIND_LIBRARY - -#define FIND_DUMMY_LIB "${FIND_DUMMY_LIB}" - -// Test SET_SOURCE_FILES_PROPERTIES - -#cmakedefine FILE_HAS_ABSTRACT -#cmakedefine FILE_HAS_WRAP_EXCLUDE -#define FILE_COMPILE_FLAGS "${FILE_COMPILE_FLAGS}" - -#define TEST_SEP "${TEST_SEP}" - -// Test registry read - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define REGISTRY_TEST_PATH "${REGISTRY_TEST_PATH}" -#endif - -// Test Remove command -#define REMOVE_STRING "${REMOVE_STRING}" - -// Test IF inside FOREACH -#cmakedefine IF_INSIDE_FOREACH_THEN_EXECUTED -#cmakedefine IF_INSIDE_FOREACH_ELSE_EXECUTED - -// Test SET CACHE FORCE -#cmakedefine FORCE_TEST -#define CMAKE_GENERATOR "${CMAKE_GENERATOR}" - -#define CMAKE_SHARED_MODULE_PREFIX "${CMAKE_SHARED_MODULE_PREFIX}" -#define CMAKE_SHARED_MODULE_SUFFIX "${CMAKE_SHARED_MODULE_SUFFIX}" - -// test elseif -#cmakedefine ELSEIF_RESULT - -// test parenthesis in conditionals -#cmakedefine CONDITIONAL_PARENTHESES - diff --git a/Tests/ComplexRelativePaths/cmTestConfigureEscape.h.in b/Tests/ComplexRelativePaths/cmTestConfigureEscape.h.in deleted file mode 100644 index 39a8bd627..000000000 --- a/Tests/ComplexRelativePaths/cmTestConfigureEscape.h.in +++ /dev/null @@ -1 +0,0 @@ -#define STRING_WITH_QUOTES "${STRING_WITH_QUOTES}" diff --git a/Tests/ComplexRelativePaths/cmTestGeneratedHeader.h.in b/Tests/ComplexRelativePaths/cmTestGeneratedHeader.h.in deleted file mode 100644 index 0e9dd3ff3..000000000 --- a/Tests/ComplexRelativePaths/cmTestGeneratedHeader.h.in +++ /dev/null @@ -1 +0,0 @@ -#define GENERATED_HEADER_INCLUDED diff --git a/Tests/Contracts/Trilinos-10-6/Patch.cmake b/Tests/Contracts/Trilinos-10-6/Patch.cmake index a7aae2724..76051eb98 100644 --- a/Tests/Contracts/Trilinos-10-6/Patch.cmake +++ b/Tests/Contracts/Trilinos-10-6/Patch.cmake @@ -2,6 +2,7 @@ if(NOT DEFINED source_dir) message(FATAL_ERROR "variable 'source_dir' not defined") endif() + if(NOT EXISTS "${source_dir}/CMakeLists.txt") message(FATAL_ERROR "error: No CMakeLists.txt file to patch!") endif() @@ -18,3 +19,20 @@ MESSAGE(\"Trilinos_WARNINGS_AS_ERRORS_FLAGS='\${Trilinos_WARNINGS_AS_ERRORS_FLAG ") file(APPEND "${source_dir}/CMakeLists.txt" "${text}") + + +if(NOT EXISTS "${source_dir}/CTestConfig.cmake") + message(FATAL_ERROR "error: No CTestConfig.cmake file to patch!") +endif() + +set(text " + +# +# Use newer than 10.6.1 CTestConfig settings from the Trilinos project. +# Send the Trilinos dashboards to the new Trilinos CDash server instance. +# +SET(CTEST_NIGHTLY_START_TIME \"04:00:00 UTC\") # 10 PM MDT or 9 PM MST +SET(CTEST_DROP_SITE \"testing.sandia.gov\") +") + +file(APPEND "${source_dir}/CTestConfig.cmake" "${text}") diff --git a/Tests/ConvLibrary/CMakeLists.txt b/Tests/ConvLibrary/CMakeLists.txt deleted file mode 100644 index afc1cb653..000000000 --- a/Tests/ConvLibrary/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required (VERSION 2.6) -project(ConvLibrary) - -# create a source list -set(foo_sources foo.cxx bar.c sub1/car.cxx) -# create a library foo from the sources -add_library(foo ${foo_sources}) -# get the object files from the target -get_target_property(OBJECT_FILES foo OBJECT_FILES) -message("${OBJECT_FILES}") -# set the object files as generated -set_source_files_properties(${OBJECT_FILES} PROPERTIES GENERATED true) -# create a library bar that contains the object files from foo -add_library(bar ${OBJECT_FILES}) -# set the linker language since bar only has .obj -set_target_properties(bar PROPERTIES LINKER_LANGUAGE CXX) -# make sure foo is built before bar -add_dependencies(bar foo) -add_executable(bartest bartest.cxx) -target_link_libraries(bartest bar) diff --git a/Tests/ConvLibrary/bar.c b/Tests/ConvLibrary/bar.c deleted file mode 100644 index d063082f5..000000000 --- a/Tests/ConvLibrary/bar.c +++ /dev/null @@ -1,4 +0,0 @@ -int bar() -{ - return 20; -} diff --git a/Tests/ConvLibrary/bartest.cxx b/Tests/ConvLibrary/bartest.cxx deleted file mode 100644 index ab9577304..000000000 --- a/Tests/ConvLibrary/bartest.cxx +++ /dev/null @@ -1,37 +0,0 @@ -extern "C" int bar(); -int foo(); -int car(); - -#include -int main() -{ - if(foo() == 10) - { - printf("foo is 10!\n"); - } - else - { - printf("foo is not 10 error!\n"); - return -1; - } - if(bar() == 20) - { - printf("bar is 20!\n"); - } - else - { - printf("bar is not 20 error!\n"); - return -1; - } - if(car() == 30) - { - printf("car is 30!\n"); - } - else - { - printf("car is not 30 error!\n"); - return -1; - } - printf("Test past\n"); - return 0; -} diff --git a/Tests/ConvLibrary/foo.cxx b/Tests/ConvLibrary/foo.cxx deleted file mode 100644 index 1f46ef49e..000000000 --- a/Tests/ConvLibrary/foo.cxx +++ /dev/null @@ -1,4 +0,0 @@ -int foo() -{ - return 10; -} diff --git a/Tests/ConvLibrary/sub1/car.cxx b/Tests/ConvLibrary/sub1/car.cxx deleted file mode 100644 index aa66726b2..000000000 --- a/Tests/ConvLibrary/sub1/car.cxx +++ /dev/null @@ -1,4 +0,0 @@ -int car() -{ - return 30; -} diff --git a/Tests/CxxOnly/CMakeLists.txt b/Tests/CxxOnly/CMakeLists.txt index 5d278906c..e62f3c797 100644 --- a/Tests/CxxOnly/CMakeLists.txt +++ b/Tests/CxxOnly/CMakeLists.txt @@ -9,3 +9,5 @@ add_library(testcxx1.my STATIC libcxx1.cxx ${EXTRA_SRCS}) add_library(testcxx2 SHARED libcxx2.cxx) add_executable (CxxOnly cxxonly.cxx) target_link_libraries(CxxOnly testcxx1.my testcxx2) + +add_library(testCxxModule MODULE testCxxModule.cxx) diff --git a/Tests/CxxOnly/testCxxModule.cxx b/Tests/CxxOnly/testCxxModule.cxx new file mode 100644 index 000000000..dd16d2bfa --- /dev/null +++ b/Tests/CxxOnly/testCxxModule.cxx @@ -0,0 +1,6 @@ +#ifdef _WIN32 +# define TEST_EXPORT __declspec(dllexport) +#else +# define TEST_EXPORT +#endif +TEST_EXPORT int testCxxModule(void) { return 0; } diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt index e65e362ec..a21e1b0f8 100644 --- a/Tests/ExportImport/Import/A/CMakeLists.txt +++ b/Tests/ExportImport/Import/A/CMakeLists.txt @@ -137,3 +137,14 @@ add_library(imp_lib1 STATIC imp_lib1.c) target_link_libraries(imp_lib1 exp_testLib2) add_library(imp_lib1b STATIC imp_lib1.c) target_link_libraries(imp_lib1b bld_testLib2) + +#----------------------------------------------------------------------------- +# Test that handling imported targets, including transitive dependencies, +# works in CheckFunctionExists (...and hopefully all other try_compile() checks +include(CheckFunctionExists) +unset(HAVE_TESTLIB1_FUNCTION CACHE) +set(CMAKE_REQUIRED_LIBRARIES exp_testLib2) +check_function_exists(testLib1 HAVE_TESTLIB1_FUNCTION) +if (NOT HAVE_TESTLIB1_FUNCTION) + message(SEND_ERROR "Using imported target testLib2 in check_function_exists() failed !") +endif() diff --git a/Tests/ExternalOBJ/CMakeLists.txt b/Tests/ExternalOBJ/CMakeLists.txt index f12de11d7..683e7997c 100644 --- a/Tests/ExternalOBJ/CMakeLists.txt +++ b/Tests/ExternalOBJ/CMakeLists.txt @@ -59,3 +59,5 @@ ADD_EXECUTABLE(ExternalOBJ executable.cxx ${CUSTOM_OBJECT}) # not didn't work. So, repeat the executable using the object # directly and not from the output of the copy. ADD_EXECUTABLE(ExternalOBJ2 executable.cxx ${EXTERNAL_OBJECT}) + +ADD_SUBDIRECTORY(Sub) diff --git a/Tests/ExternalOBJ/Sub/CMakeLists.txt b/Tests/ExternalOBJ/Sub/CMakeLists.txt new file mode 100644 index 000000000..35cd30c7d --- /dev/null +++ b/Tests/ExternalOBJ/Sub/CMakeLists.txt @@ -0,0 +1,3 @@ +set_property(SOURCE ${CUSTOM_OBJECT} PROPERTY GENERATED 1) +add_executable(ExternalOBJSub ../executable.cxx ${CUSTOM_OBJECT}) +add_dependencies(ExternalOBJSub ExternalOBJ) # depend on generating target diff --git a/Tests/ExternalProject/CMakeLists.txt b/Tests/ExternalProject/CMakeLists.txt index ac701298f..7a7626199 100644 --- a/Tests/ExternalProject/CMakeLists.txt +++ b/Tests/ExternalProject/CMakeLists.txt @@ -280,6 +280,18 @@ if(do_cvs_tests) set_property(TARGET ${proj} PROPERTY FOLDER "SetupRepos/Local/Deeply/Nested/For/Testing") + # The MSYS cvs tool interprets "c:/" as a "machine:" name for SSH. + # Detect the MSYS cvs and convert the repo path to an MSYS path. + if(WIN32) + if(EXISTS "${CVS_EXECUTABLE}") + file(STRINGS "${CVS_EXECUTABLE}" cvs_is_msys LIMIT_COUNT 1 REGEX "[Mm][Ss][Yy][Ss]") + if(cvs_is_msys) + message(STATUS "'${CVS_EXECUTABLE}' is from MSYS (contains '${cvs_is_msys}')") + string(REGEX REPLACE "^([A-Za-z]):" "/\\1" local_cvs_repo "${local_cvs_repo}") + endif() + endif() + endif() + # CVS by date stamp: # set(proj TutorialStep1-CVS-20090626) diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index 9a4bdfeb5..586209456 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -37,6 +37,12 @@ FIND_PACKAGE(VersionTestB 1.2) FIND_PACKAGE(VersionTestC 1.2.3) FIND_PACKAGE(VersionTestD 1.2.3.4) + +FIND_PACKAGE(LotsOfComponents COMPONENTS AComp OPTIONAL_COMPONENTS BComp CComp) +IF(NOT LOTSOFCOMPONENTS_FOUND) + MESSAGE(SEND_ERROR "LotsOfComponents not found !") +ENDIF() + #----------------------------------------------------------------------------- # Test system package registry if possible. SET(CMakeTestSystemPackage "") @@ -82,6 +88,7 @@ SET(PACKAGES RecursiveA RecursiveB RecursiveC ArchA ArchB ArchC ArchD EnvA EnvB + SetFoundTRUE SetFoundFALSE ${CMakeTestSystemPackage} ) FOREACH(p ${PACKAGES}) @@ -117,6 +124,10 @@ FIND_PACKAGE(VersionedC 4.0 EXACT NAMES zot) FIND_PACKAGE(VersionedD 1.1 EXACT NAMES Baz) FIND_PACKAGE(VersionedE 1.2 EXACT NAMES Baz) +# Test Config files which set Xyz_FOUND themselves: +FIND_PACKAGE(SetFoundTRUE NO_MODULE) +FIND_PACKAGE(SetFoundFALSE NO_MODULE) + # Test wrong initial path when result is present. SET(WrongA_DIR "${VersionedD_DIR}") FIND_PACKAGE(WrongA 1.2 EXACT NAMES Baz) @@ -201,6 +212,8 @@ SET(ArchC_EXPECTED "lib/arch/zot-3.1/zot-config.cmake") SET(ArchD_EXPECTED "lib/arch/cmake/zot-4.0/zot-config.cmake") SET(EnvA_EXPECTED "lib/zot-3.1/zot-config.cmake") SET(EnvB_MISSING "EnvB_DIR-NOTFOUND") +SET(SetFoundTRUE_EXPECTED "cmake/SetFoundTRUEConfig.cmake") +SET(SetFoundFALSE_MISSING "${CMAKE_CURRENT_SOURCE_DIR}/cmake") SET(CMakeTestSystemPackage_EXPECTED "SystemPackage/CMakeTestSystemPackageConfig.cmake") # Check the results. @@ -212,6 +225,11 @@ FOREACH(p ${PACKAGES}) "Package ${p} should have been [${${p}_MISSING}] but " "was [${${p}_DIR}]") ENDIF() + IF(${p}_FOUND) + MESSAGE(SEND_ERROR + "Package ${p} should not have been found, but ${p}_FOUND is set to " + "\"${${p}_FOUND}\"") + ENDIF() ELSEIF(${p}_FOUND) # Convert to relative path for comparison to expected location. FILE(RELATIVE_PATH REL_${p}_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}" @@ -305,13 +323,49 @@ STRING(REGEX REPLACE "-.*$" "" version ${CMAKE_VERSION}) FIND_PACKAGE(CMakeTestExportPackage 1.${version} EXACT REQUIRED) #----------------------------------------------------------------------------- -# Test write_basic_config_version_file(). +# Test configure_package_config_file(). -include(WriteBasicConfigVersionFile) +include(CMakePackageConfigHelpers) -write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake - VERSION 1.2.3 - COMPATIBILITY AnyNewerVersion) +set(INCLUDE_INSTALL_DIR include ) +set(SHARE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/" ) +set(CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}" ) + +configure_package_config_file(RelocatableConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}" + PATH_VARS INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR CURRENT_BUILD_DIR + ) + +set(Relocatable_FIND_COMPONENTS AComp BComp CComp) +set(Relocatable_FIND_REQUIRED_BComp 1) +include("${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake") + +if(NOT "${RELOC_INCLUDE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/include") + message(SEND_ERROR "RELOC_INCLUDE_DIR set by configure_package_config_file() is set to \"${RELOC_INCLUDE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/include\")") +endif() + +if(NOT "${RELOC_SHARE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/share/") + message(SEND_ERROR "RELOC_SHARE_DIR set by configure_package_config_file() is set to \"${RELOC_SHARE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/share/\")") +endif() + +if(NOT "${RELOC_BUILD_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") + message(SEND_ERROR "RELOC_BUILD_DIR set by configure_package_config_file() is set to \"${RELOC_BUILD_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}\")") +endif() + +if(NOT DEFINED Relocatable_FOUND) + message(SEND_ERROR "Relocatable_FOUND not defined !") +endif() + +if(Relocatable_FOUND) + message(SEND_ERROR "Relocatable_FOUND set to TRUE !") +endif() + +#----------------------------------------------------------------------------- +# Test write_basic_config_version_file(). + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake + VERSION 1.2.3 + COMPATIBILITY AnyNewerVersion) set(PACKAGE_FIND_VERSION 2.3.4) include(${CMAKE_CURRENT_BINARY_DIR}/Foo123ConfigVersion.cmake) @@ -345,6 +399,7 @@ endif() ####################### +include(WriteBasicConfigVersionFile) write_basic_config_version_file(${CMAKE_CURRENT_BINARY_DIR}/Boo123ConfigVersion.cmake VERSION 1.2.3 @@ -394,3 +449,73 @@ endif() if(PACKAGE_VERSION_UNSUITABLE) message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !") endif() + +####################### + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake + VERSION 1.2.3.17 + COMPATIBILITY ExactVersion) + +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_FIND_VERSION 2.3.4) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Bar123 with version 1.2.3 (2.3.4 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Bar123 with version 1.2.3 (1.2 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Found Bar123 with version 1.2.3 (1 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2.3.4) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3.4 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + +set(PACKAGE_FIND_VERSION 1.2.3) +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3 was requested) !") +endif() +if(PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT set, although it should not be !") +endif() + + +set(PACKAGE_FIND_VERSION 1.2.3.17) +set(PACKAGE_VERSION_EXACT FALSE) +set(PACKAGE_VERSION_COMPATIBLE FALSE) +include(${CMAKE_CURRENT_BINARY_DIR}/Bar123ConfigVersion.cmake) +if(NOT PACKAGE_VERSION_COMPATIBLE) + message(SEND_ERROR "Did not find Bar123 with version 1.2.3 (1.2.3.17 was requested) !") +endif() +if(NOT PACKAGE_VERSION_EXACT) + message(SEND_ERROR "PACKAGE_VERSION_EXACT not set, although it should be !") +endif() + +if(PACKAGE_VERSION_UNSUITABLE) + message(SEND_ERROR "PACKAGE_VERSION_UNSUITABLE set, but must not be !") +endif() diff --git a/Tests/FindPackageTest/FindLotsOfComponents.cmake b/Tests/FindPackageTest/FindLotsOfComponents.cmake new file mode 100644 index 000000000..9076d86ed --- /dev/null +++ b/Tests/FindPackageTest/FindLotsOfComponents.cmake @@ -0,0 +1,10 @@ +set(LOC_FOO TRUE) + +set(LotsOfComponents_AComp_FOUND TRUE) +set(LotsOfComponents_BComp_FOUND FALSE) +set(LotsOfComponents_CComp_FOUND TRUE) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(LotsOfComponents REQUIRED_VARS LOC_FOO + HANDLE_COMPONENTS) diff --git a/Tests/FindPackageTest/RelocatableConfig.cmake.in b/Tests/FindPackageTest/RelocatableConfig.cmake.in new file mode 100644 index 000000000..4a4b4e9c6 --- /dev/null +++ b/Tests/FindPackageTest/RelocatableConfig.cmake.in @@ -0,0 +1,11 @@ +@PACKAGE_INIT@ + +set(RELOC_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set(RELOC_SHARE_DIR "@PACKAGE_SHARE_INSTALL_DIR@") +set_and_check(RELOC_BUILD_DIR "@PACKAGE_CURRENT_BUILD_DIR@") + +set(Relocatable_AComp_FOUND TRUE) +set(Relocatable_BComp_FOUND FALSE) +set(Relocatable_CComp_FOUND FALSE) + +check_required_components(Relocatable) diff --git a/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake b/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake new file mode 100644 index 000000000..ae6bd1454 --- /dev/null +++ b/Tests/FindPackageTest/cmake/SetFoundFALSEConfig.cmake @@ -0,0 +1 @@ +set(SetFoundFALSE_FOUND FALSE) diff --git a/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake b/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake new file mode 100644 index 000000000..19d071144 --- /dev/null +++ b/Tests/FindPackageTest/cmake/SetFoundTRUEConfig.cmake @@ -0,0 +1 @@ +set(SetFoundTRUE_FOUND TRUE) diff --git a/Tests/IncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/CMakeLists.txt index 60b8c22b2..60f5e5e6f 100644 --- a/Tests/IncludeDirectories/CMakeLists.txt +++ b/Tests/IncludeDirectories/CMakeLists.txt @@ -45,3 +45,5 @@ else() set_target_properties(IncludeDirectories PROPERTIES COMPILE_FLAGS "-ITarProp") endif() + +add_subdirectory(TargetIncludeDirectories) diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt new file mode 100644 index 000000000..2cf36f513 --- /dev/null +++ b/Tests/IncludeDirectories/TargetIncludeDirectories/CMakeLists.txt @@ -0,0 +1,26 @@ + +cmake_minimum_required(VERSION 2.8) + +project(TargetIncludeDirectories) + +macro(create_header _name) + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${_name}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_name}/${_name}.h" + "//${_name}.h + ") +endmacro() + +create_header(bar) +create_header(bat) +create_header(foo) +create_header(baz) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +include_directories("${CMAKE_CURRENT_BINARY_DIR}/bar") + +add_executable(TargetIncludeDirectories main.cpp) +set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/bat") +set_property(TARGET TargetIncludeDirectories APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/foo") + +include_directories("${CMAKE_CURRENT_BINARY_DIR}/baz") diff --git a/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp new file mode 100644 index 000000000..8aa35320f --- /dev/null +++ b/Tests/IncludeDirectories/TargetIncludeDirectories/main.cpp @@ -0,0 +1,10 @@ + +#include "bar.h" +#include "bat.h" +#include "foo.h" +#include "baz.h" + +int main(int, char**) +{ + return 0; +} diff --git a/Tests/LoadCommand/CMakeCommands/CMakeLists.txt b/Tests/LoadCommand/CMakeCommands/CMakeLists.txt index 953d05c99..5cdbc59bf 100644 --- a/Tests/LoadCommand/CMakeCommands/CMakeLists.txt +++ b/Tests/LoadCommand/CMakeCommands/CMakeLists.txt @@ -5,9 +5,6 @@ IF (MUDSLIDE_TYPE MATCHES MUCHO) ADD_DEFINITIONS(-DMUCHO_MUDSLIDE) ENDIF (MUDSLIDE_TYPE MATCHES MUCHO) -IF(WATCOM) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -ENDIF(WATCOM) INCLUDE_DIRECTORIES(${CMAKE_ROOT}/include ${CMAKE_ROOT}/Source) ADD_LIBRARY(cmCMAKE_TEST_COMMAND MODULE cmTestCommand.c) diff --git a/Tests/LoadCommand/CMakeLists.txt b/Tests/LoadCommand/CMakeLists.txt index e99105a74..846cbb084 100644 --- a/Tests/LoadCommand/CMakeLists.txt +++ b/Tests/LoadCommand/CMakeLists.txt @@ -12,12 +12,6 @@ INCLUDE (CheckFunctionExists) CHECK_FUNCTION_EXISTS(printf HAVE_PRINTF) CHECK_FUNCTION_EXISTS(vsblabla HAVE_VSBLABLA) -INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) -CHECK_INCLUDE_FILE("sys/prctl.h" HAVE_SYS_PRCTL_H) - -INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake) -CHECK_LIBRARY_EXISTS(m ceil "" HAVE_LIBM) - CONFIGURE_FILE(${LoadCommand_SOURCE_DIR}/LoadedCommand.h.in ${LoadCommand_BINARY_DIR}/LoadedCommand.h) diff --git a/Tests/LoadCommand/LoadedCommand.h.in b/Tests/LoadCommand/LoadedCommand.h.in index 7a0a15d4d..7516a66e5 100644 --- a/Tests/LoadCommand/LoadedCommand.h.in +++ b/Tests/LoadCommand/LoadedCommand.h.in @@ -5,9 +5,3 @@ /* Check for functions */ #cmakedefine HAVE_PRINTF #cmakedefine HAVE_VSBLABLA - -/* Check for headers */ -#cmakedefine HAVE_SYS_PRCTL_H - -/* Check for libraries */ -#cmakedefine HAVE_LIBM diff --git a/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp b/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp index 445a65204..eec46d3f2 100644 --- a/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp +++ b/Tests/Module/GenerateExportHeader/nodeprecated/src/main.cpp @@ -6,4 +6,4 @@ int main(int, char**) SomeClass sc; sc.someMethod(); return 0; -} \ No newline at end of file +} diff --git a/Tests/Module/GenerateExportHeader/override_symbol/main.cpp b/Tests/Module/GenerateExportHeader/override_symbol/main.cpp index 445a65204..eec46d3f2 100644 --- a/Tests/Module/GenerateExportHeader/override_symbol/main.cpp +++ b/Tests/Module/GenerateExportHeader/override_symbol/main.cpp @@ -6,4 +6,4 @@ int main(int, char**) SomeClass sc; sc.someMethod(); return 0; -} \ No newline at end of file +} diff --git a/Tests/Module/GenerateExportHeader/override_symbol/someclass.cpp b/Tests/Module/GenerateExportHeader/override_symbol/someclass.cpp index 7326b780a..427ec297c 100644 --- a/Tests/Module/GenerateExportHeader/override_symbol/someclass.cpp +++ b/Tests/Module/GenerateExportHeader/override_symbol/someclass.cpp @@ -4,4 +4,4 @@ void SomeClass::someMethod() const { -} \ No newline at end of file +} diff --git a/Tests/Module/GenerateExportHeader/prefix/main.cpp b/Tests/Module/GenerateExportHeader/prefix/main.cpp index d04ae3c9c..507f6fd15 100644 --- a/Tests/Module/GenerateExportHeader/prefix/main.cpp +++ b/Tests/Module/GenerateExportHeader/prefix/main.cpp @@ -5,4 +5,4 @@ int main(int argc, char **argv) { UsePrefixClass upc; return upc.someMethod(); -} \ No newline at end of file +} diff --git a/Tests/Module/GenerateExportHeader/prefix/useprefixclass.cpp b/Tests/Module/GenerateExportHeader/prefix/useprefixclass.cpp index 8337ab845..1fd2cb2b4 100644 --- a/Tests/Module/GenerateExportHeader/prefix/useprefixclass.cpp +++ b/Tests/Module/GenerateExportHeader/prefix/useprefixclass.cpp @@ -4,4 +4,4 @@ int UsePrefixClass::someMethod() const { return 0; -} \ No newline at end of file +} diff --git a/Tests/ModuleDefinition/CMakeLists.txt b/Tests/ModuleDefinition/CMakeLists.txt index b463a3c00..a30f64363 100644 --- a/Tests/ModuleDefinition/CMakeLists.txt +++ b/Tests/ModuleDefinition/CMakeLists.txt @@ -4,6 +4,14 @@ project(ModuleDefinition C) # Test .def file source recognition for DLLs. add_library(example_dll SHARED example_dll.c example_dll.def) +# Test generated .def file. +add_custom_command(OUTPUT example_dll_gen.def + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/example_dll_gen.def.in + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/example_dll_gen.def.in + ${CMAKE_CURRENT_BINARY_DIR}/example_dll_gen.def + ) +add_library(example_dll_gen SHARED example_dll_gen.c example_dll_gen.def) + # Test /DEF: flag recognition for VS. if(MSVC OR "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$") add_library(example_dll_2 SHARED example_dll_2.c) @@ -16,7 +24,7 @@ endif() # Test .def file source recognition for EXEs. add_executable(example_exe example_exe.c example_exe.def) set_property(TARGET example_exe PROPERTY ENABLE_EXPORTS 1) -target_link_libraries(example_exe example_dll ${example_dll_2}) +target_link_libraries(example_exe example_dll example_dll_gen ${example_dll_2}) # Test linking to the executable. add_library(example_mod_1 MODULE example_mod_1.c) diff --git a/Tests/ModuleDefinition/example_dll_gen.c b/Tests/ModuleDefinition/example_dll_gen.c new file mode 100644 index 000000000..be5d1eed7 --- /dev/null +++ b/Tests/ModuleDefinition/example_dll_gen.c @@ -0,0 +1 @@ +int example_dll_gen_function(void) { return 0; } diff --git a/Tests/ModuleDefinition/example_dll_gen.def.in b/Tests/ModuleDefinition/example_dll_gen.def.in new file mode 100644 index 000000000..c489dbc83 --- /dev/null +++ b/Tests/ModuleDefinition/example_dll_gen.def.in @@ -0,0 +1,2 @@ +EXPORTS +example_dll_gen_function diff --git a/Tests/ModuleDefinition/example_exe.c b/Tests/ModuleDefinition/example_exe.c index c521b3a4c..253ae8b70 100644 --- a/Tests/ModuleDefinition/example_exe.c +++ b/Tests/ModuleDefinition/example_exe.c @@ -1,4 +1,5 @@ extern int __declspec(dllimport) example_dll_function(void); +extern int __declspec(dllimport) example_dll_gen_function(void); #ifdef EXAMPLE_DLL_2 extern int __declspec(dllimport) example_dll_2_function(void); #endif @@ -7,6 +8,7 @@ int main(void) { return example_dll_function() + + example_dll_gen_function() + #ifdef EXAMPLE_DLL_2 example_dll_2_function() + #endif diff --git a/Tests/ObjectLibrary/A/CMakeLists.txt b/Tests/ObjectLibrary/A/CMakeLists.txt new file mode 100644 index 000000000..121a8acba --- /dev/null +++ b/Tests/ObjectLibrary/A/CMakeLists.txt @@ -0,0 +1,17 @@ +# Add -fPIC so objects can be used in shared libraries. +# TODO: Need property for this. +if(CMAKE_SHARED_LIBRARY_C_FLAGS AND NOT WATCOM) + set(CMAKE_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_C_FLAGS}") +endif() + +add_definitions(-DA_DEF) + +add_custom_command( + OUTPUT a1.c + DEPENDS a1.c.in + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in + ${CMAKE_CURRENT_BINARY_DIR}/a1.c + ) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +add_library(A OBJECT a1.c a2.c) diff --git a/Tests/ObjectLibrary/A/a.h b/Tests/ObjectLibrary/A/a.h new file mode 100644 index 000000000..7259f982e --- /dev/null +++ b/Tests/ObjectLibrary/A/a.h @@ -0,0 +1,6 @@ +#ifndef A_DEF +# error "A_DEF not defined" +#endif +#ifdef B_DEF +# error "B_DEF must not be defined" +#endif diff --git a/Tests/ObjectLibrary/A/a1.c.in b/Tests/ObjectLibrary/A/a1.c.in new file mode 100644 index 000000000..d1eaf58fd --- /dev/null +++ b/Tests/ObjectLibrary/A/a1.c.in @@ -0,0 +1,2 @@ +#include "a.h" +int a1(void) { return 0; } diff --git a/Tests/ObjectLibrary/A/a2.c b/Tests/ObjectLibrary/A/a2.c new file mode 100644 index 000000000..d8f225eb7 --- /dev/null +++ b/Tests/ObjectLibrary/A/a2.c @@ -0,0 +1,2 @@ +#include "a.h" +int a2(void) { return 0; } diff --git a/Tests/ObjectLibrary/AB.def b/Tests/ObjectLibrary/AB.def new file mode 100644 index 000000000..3f2b5c054 --- /dev/null +++ b/Tests/ObjectLibrary/AB.def @@ -0,0 +1,5 @@ +EXPORTS +a1 +a2 +b1 +b2 diff --git a/Tests/ObjectLibrary/B/CMakeLists.txt b/Tests/ObjectLibrary/B/CMakeLists.txt new file mode 100644 index 000000000..67172d132 --- /dev/null +++ b/Tests/ObjectLibrary/B/CMakeLists.txt @@ -0,0 +1,15 @@ +if("${CMAKE_GENERATOR}" MATCHES "Visual Studio 6") + # VS 6 generator does not use per-target object locations. + set(vs6 _vs6) +endif() + +# Add -fPIC so objects can be used in shared libraries. +# TODO: Need property for this. +if(CMAKE_SHARED_LIBRARY_C_FLAGS AND NOT WATCOM) + set(CMAKE_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} ${CMAKE_C_FLAGS}") +endif() + +add_definitions(-DB_DEF) +add_library(B OBJECT b1.c b2.c) +add_library(Bexport OBJECT b1${vs6}.c b2${vs6}.c) +set_property(TARGET Bexport PROPERTY COMPILE_DEFINITIONS Bexport) diff --git a/Tests/ObjectLibrary/B/b.h b/Tests/ObjectLibrary/B/b.h new file mode 100644 index 000000000..11b22f427 --- /dev/null +++ b/Tests/ObjectLibrary/B/b.h @@ -0,0 +1,11 @@ +#ifdef A_DEF +# error "A_DEF must not be defined" +#endif +#ifndef B_DEF +# error "B_DEF not defined" +#endif +#if defined(_WIN32) && defined(Bexport) +# define EXPORT_B __declspec(dllexport) +#else +# define EXPORT_B +#endif diff --git a/Tests/ObjectLibrary/B/b1.c b/Tests/ObjectLibrary/B/b1.c new file mode 100644 index 000000000..fdeffe491 --- /dev/null +++ b/Tests/ObjectLibrary/B/b1.c @@ -0,0 +1,2 @@ +#include "b.h" +EXPORT_B int b1(void) { return 0; } diff --git a/Tests/ObjectLibrary/B/b1_vs6.c b/Tests/ObjectLibrary/B/b1_vs6.c new file mode 100644 index 000000000..b606e10e6 --- /dev/null +++ b/Tests/ObjectLibrary/B/b1_vs6.c @@ -0,0 +1 @@ +#include "b1.c" diff --git a/Tests/ObjectLibrary/B/b2.c b/Tests/ObjectLibrary/B/b2.c new file mode 100644 index 000000000..6e0d17cbe --- /dev/null +++ b/Tests/ObjectLibrary/B/b2.c @@ -0,0 +1,2 @@ +#include "b.h" +EXPORT_B int b2(void) { return 0; } diff --git a/Tests/ObjectLibrary/B/b2_vs6.c b/Tests/ObjectLibrary/B/b2_vs6.c new file mode 100644 index 000000000..d96a43e04 --- /dev/null +++ b/Tests/ObjectLibrary/B/b2_vs6.c @@ -0,0 +1 @@ +#include "b2.c" diff --git a/Tests/ObjectLibrary/CMakeLists.txt b/Tests/ObjectLibrary/CMakeLists.txt new file mode 100644 index 000000000..87234159f --- /dev/null +++ b/Tests/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 2.8) +project(ObjectLibrary C) + +add_subdirectory(A) +add_subdirectory(B) + +add_library(Cstatic STATIC c.c $ $) +add_executable(UseCstatic main.c) +target_link_libraries(UseCstatic Cstatic) + +add_library(Cshared SHARED c.c $ $) +add_executable(UseCshared main.c) +set_property(TARGET UseCshared PROPERTY COMPILE_DEFINITIONS SHARED_C) +target_link_libraries(UseCshared Cshared) + +add_executable(UseCinternal main.c c.c $ $) + +if("${CMAKE_GENERATOR}" MATCHES "^Visual Studio (6|7|7 .NET 2003)$") + # VS 6 and 7 generators do not add objects as sources so we need a + # dummy object to convince the IDE to build the targets below. + set(dummy dummy.obj) # In MinGW: gcc -c dummy.c -o dummy.obj +elseif("${CMAKE_GENERATOR}" MATCHES "Xcode") + # Xcode does not seem to support targets without sources. + set(dummy dummy.c) +endif() + +# Test static library without its own sources. +add_library(ABstatic STATIC ${dummy} $ $) +add_executable(UseABstatic mainAB.c) +target_link_libraries(UseABstatic ABstatic) + +# Test module definition file to export object library symbols in the test +# below if the platform needs and supports it. +set(ABshared_SRCS $) +if(CMAKE_LINK_DEF_FILE_FLAG OR NOT WIN32) + list(APPEND ABshared_SRCS $ AB.def) +else() + set(NO_A NO_A) + list(APPEND ABshared_SRCS $) +endif() + +# Test shared library without its own sources. +add_library(ABshared SHARED ${dummy} ${ABshared_SRCS}) +add_executable(UseABshared mainAB.c) +set_property(TARGET UseABshared PROPERTY COMPILE_DEFINITIONS SHARED_B ${NO_A}) +target_link_libraries(UseABshared ABshared) + +# Test executable without its own sources. +add_library(ABmain OBJECT mainAB.c) +add_executable(UseABinternal ${dummy} + $ $ $ + ) diff --git a/Tests/ObjectLibrary/c.c b/Tests/ObjectLibrary/c.c new file mode 100644 index 000000000..968095b8b --- /dev/null +++ b/Tests/ObjectLibrary/c.c @@ -0,0 +1,19 @@ +#if defined(_WIN32) && defined(Cshared_EXPORTS) +# define EXPORT_C __declspec(dllexport) +#else +# define EXPORT_C +#endif + +extern int a1(void); +extern int a2(void); +extern int b1(void); +extern int b2(void); +EXPORT_C int c(void) +{ + return 0 + + a1() + + a2() + + b1() + + b2() + ; +} diff --git a/Tests/ObjectLibrary/dummy.c b/Tests/ObjectLibrary/dummy.c new file mode 100644 index 000000000..2b17d816d --- /dev/null +++ b/Tests/ObjectLibrary/dummy.c @@ -0,0 +1 @@ +int dummy(void) {return 0;} diff --git a/Tests/ObjectLibrary/dummy.obj b/Tests/ObjectLibrary/dummy.obj new file mode 100644 index 000000000..77f6f2f1b Binary files /dev/null and b/Tests/ObjectLibrary/dummy.obj differ diff --git a/Tests/ObjectLibrary/main.c b/Tests/ObjectLibrary/main.c new file mode 100644 index 000000000..6819f1c6d --- /dev/null +++ b/Tests/ObjectLibrary/main.c @@ -0,0 +1,16 @@ +#if defined(_WIN32) && defined(SHARED_C) +# define IMPORT_C __declspec(dllimport) +#else +# define IMPORT_C +#endif +extern IMPORT_C int b1(void); +extern IMPORT_C int b2(void); +extern IMPORT_C int c(void); +int main(void) +{ + return 0 + + c() + + b1() + + b2() + ; +} diff --git a/Tests/ObjectLibrary/mainAB.c b/Tests/ObjectLibrary/mainAB.c new file mode 100644 index 000000000..556898b83 --- /dev/null +++ b/Tests/ObjectLibrary/mainAB.c @@ -0,0 +1,22 @@ +#if defined(_WIN32) && defined(SHARED_B) +# define IMPORT_B __declspec(dllimport) +#else +# define IMPORT_B +#endif +extern IMPORT_B int b1(void); +extern IMPORT_B int b2(void); +#ifndef NO_A +extern int a1(void); +extern int a2(void); +#endif +int main(void) +{ + return 0 +#ifndef NO_A + + a1() + + a2() +#endif + + b1() + + b2() + ; +} diff --git a/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt index c7cc09016..c362e79ba 100644 --- a/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt +++ b/Tests/OutOfSource/OutOfSourceSubdir/CMakeLists.txt @@ -24,6 +24,12 @@ IF ("${PROJECT_SOURCE_DIR}" STREQUAL "${ANOTHER_PROJ_SOURCE_DIR}") MATH(EXPR MAXPATH "${MAXPATH} - 46") ENDIF() + # Ninja imposes a maximum path component count of 30. Permit more + # path components in the source path. + IF(${CMAKE_GENERATOR} MATCHES "Ninja") + MATH(EXPR MAXPATH "${MAXPATH} - 44") + ENDIF() + # MAXPATH less 25 for last /and/deeper/simple.cxx part and small safety MATH(EXPR MAXPATH "${MAXPATH} - 25") STRING(LENGTH "${DEEPDIR}" DEEPDIR_LEN) diff --git a/Tests/PrecompiledHeader/CMakeLists.txt b/Tests/PrecompiledHeader/CMakeLists.txt index d423cae30..3374e325f 100644 --- a/Tests/PrecompiledHeader/CMakeLists.txt +++ b/Tests/PrecompiledHeader/CMakeLists.txt @@ -47,7 +47,8 @@ SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES # Setup dependencies for precompiled header creation and use. The VS # IDE takes care of this automatically. -IF("${CMAKE_GENERATOR}" MATCHES "Makefile") +IF("${CMAKE_GENERATOR}" MATCHES "Makefile" OR + "${CMAKE_GENERATOR}" MATCHES "Ninja") # This source file creates the precompiled header as a side-effect. SET_SOURCE_FILES_PROPERTIES(foo_precompile.c PROPERTIES OBJECT_OUTPUTS "${PCH_DIR}/foo_precompiled.pch") diff --git a/Tests/Qt4Deploy/CMakeLists.txt b/Tests/Qt4Deploy/CMakeLists.txt new file mode 100644 index 000000000..646ea9f3b --- /dev/null +++ b/Tests/Qt4Deploy/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 2.8) + +project(Qt4Deploy) +set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install) + +find_package(Qt4 REQUIRED QtMain QtCore QtSql) +include(${QT_USE_FILE}) + +add_executable(testdeploy MACOSX_BUNDLE testdeploy.cpp) +target_link_libraries(testdeploy ${QT_LIBRARIES}) +set_target_properties(testdeploy PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}") + +if(CMAKE_CONFIGURATION_TYPES AND QT_QTCORE_LIBRARY_RELEASE AND QT_QTCORE_LIBRARY_DEBUG) + # note: installing debug Qt libraries from a Qt installation configured with + # -debug-and-release not yet supported (very low priority). + install(CODE " + if(\"\${CMAKE_INSTALL_CONFIG_NAME}\" MATCHES \"^([Dd][Ee][Bb][Uu][Gg])$\") + return() + endif() + ") +endif() + +# install the Qt4 app with qsqlite plugin +install(CODE "file(REMOVE_RECURSE \"${CMAKE_INSTALL_PREFIX}\")") +install(TARGETS testdeploy DESTINATION .) +include(../../Modules/DeployQt4.cmake) +if(APPLE) + install_qt4_executable(testdeploy.app "qsqlite") +elseif(WIN32) + install_qt4_executable(testdeploy.exe "qsqlite") +else() + install_qt4_executable(testdeploy "qsqlite") +endif() + + +# test depends on standard qsqlite plugin +if(QT_QSQLITE_PLUGIN_DEBUG OR QT_QSQLITE_PLUGIN_RELEASE) + + # test the deployed Qt application + if(APPLE) + install(CODE " + message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\") + execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy.app/Contents/MacOS/testdeploy\" + RESULT_VARIABLE result) + if(NOT result STREQUAL \"0\") + message(FATAL_ERROR \"error running testdeploy app\") + endif() + ") + else() + install(CODE " + message(STATUS \"executing: ${CMAKE_INSTALL_PREFIX}/testdeploy\") + execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/testdeploy\" + RESULT_VARIABLE result) + if(NOT result STREQUAL \"0\") + message(FATAL_ERROR \"error running testdeploy app\") + endif() + ") + endif() + + # custom target to install and test the installation at build time + if(CMAKE_CONFIGURATION_TYPES) + set(install_config "-DCMAKE_INSTALL_CONFIG_NAME=${CMAKE_CFG_INTDIR}") + endif() + + add_custom_target(testdeploy_test ALL + COMMAND ${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake + COMMENT "${CMAKE_COMMAND} ${install_config} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake" + DEPENDS testdeploy) + +endif() diff --git a/Tests/Qt4Deploy/testdeploy.cpp b/Tests/Qt4Deploy/testdeploy.cpp new file mode 100644 index 000000000..8b9c8d6fa --- /dev/null +++ b/Tests/Qt4Deploy/testdeploy.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + qDebug() << "App path:" << app.applicationDirPath(); + qDebug() << "Plugin path:" << QLibraryInfo::location(QLibraryInfo::PluginsPath); + + bool foundSqlite = false; + + qDebug() << "Supported Database Drivers:"; + foreach(const QString &sqlDriver, QSqlDatabase::drivers()) + { + qDebug() << " " << sqlDriver; + if(sqlDriver == "QSQLITE") + foundSqlite = true; + } + + if(foundSqlite) + qDebug() << "Found sqlite support from plugin."; + else + qDebug() << "Could not find sqlite support from plugin."; + return foundSqlite ? 0 : 1; +} diff --git a/Tests/QtAutomoc/CMakeLists.txt b/Tests/QtAutomoc/CMakeLists.txt index d255a5a7d..5e3686dbc 100644 --- a/Tests/QtAutomoc/CMakeLists.txt +++ b/Tests/QtAutomoc/CMakeLists.txt @@ -8,7 +8,7 @@ include(UseQt4) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_definitions(-DFOO) +add_definitions(-DFOO -DSomeDefine="Barx") # enable relaxed mode so automoc can handle all the special cases: set(CMAKE_AUTOMOC_RELAXED_MODE TRUE) diff --git a/Tests/README b/Tests/README new file mode 100644 index 000000000..8b2fda845 --- /dev/null +++ b/Tests/README @@ -0,0 +1,39 @@ +If you think about adding a new testcase then here is a small checklist you +can run through to find a proper place for it. Go through the list from the +beginning and stop once you find something that matches your tests needs, +i.e. if you will test a module and only need the configure mode use the +instructions from section 2, not 3. + +1. Your testcase can run in CMake script mode, i.e. "cmake -P something" + +Put your test in Tests/CMakeTests/ directory as a .cmake.in file. It will be +put into the test binary directory by configure_file(... @ONLY) and run from +there. Use the AddCMakeTest() macro in Tests/CMakeTests/CMakeLists.txt to add +your test to the test runs. + +2. Your test needs CMake to run in configure mode, but will not build anything + +This includes tests that will build something using try_compile() and friends, +but nothing that expects add_executable(), add_library(), or add_test() to run. + +If the test configures the project only once and it must succeed then put it +into the Tests/CMakeOnly/ directory. Create a subdirectory named like your +test and write the CMakeLists.txt you need into that subdirectory. Use the +add_CMakeOnly_test() macro from Tests/CMakeOnly/CMakeLists.txt to add your +test to the test runs. + +If the test configures the project with multiple variations and verifies +success or failure each time then put it into the Tests/RunCMake/ directory. +Read the instructions in Tests/RunCMake/CMakeLists.txt to add a test. + +3. If you are testing something from the Modules directory + +Put your test in the Tests/Modules/ directory. Create a subdirectory there +named after your test. Use the ADD_TEST_MACRO macro from Tests/CMakeLists.txt +to add your test to the test run. If you have put your stuff in +Tests/Modules/Foo then you call it using ADD_TEST_MACRO(Module.Foo Foo). + +4. You are doing other stuff. + +Find a good place ;) In doubt mail to cmake-developers@cmake.org and ask for +advise. diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt new file mode 100644 index 000000000..0b79efa6a --- /dev/null +++ b/Tests/RunCMake/CMakeLists.txt @@ -0,0 +1,46 @@ +# This directory contains tests that run CMake to configure a project +# but do not actually build anything. To add a test: +# +# 1.) Add a subdirectory named for the test. +# +# 2.) Call add_RunCMake_test and pass the test directory name. +# +# 3.) Create a RunCMakeTest.cmake script in the directory containing +# include(RunCMake) +# run_cmake(SubTest1) +# ... +# run_cmake(SubTestN) +# where SubTest1..SubTestN are sub-test names each corresponding to +# an independent CMake run and project configuration. +# +# 3.) Create a CMakeLists.txt file in the directory containing +# cmake_minimum_required(...) +# project(${RunCMake_TEST} NONE) # or languages needed +# include(${RunCMake_TEST}.cmake) +# where "${RunCMake_TEST}" is literal. A value for RunCMake_TEST +# will be passed to CMake by the run_cmake macro when running each +# sub-test. +# +# 4.) Create a .cmake file for each sub-test named above +# containing the actual test code. Optionally create files +# containing expected test results: +# -result.txt = Process result expected if not "0" +# -stdout.txt = Regex matching expected stdout content +# -stderr.txt = Regex matching expected stderr content +# Note that trailing newlines will be stripped from actual test +# output before matching against the stdout and stderr expressions. + +macro(add_RunCMake_test test) + add_test(RunCMake.${test} ${CMAKE_CMAKE_COMMAND} + -DCMAKE_MODULE_PATH=${CMAKE_CURRENT_SOURCE_DIR} + -DRunCMake_GENERATOR=${CMAKE_TEST_GENERATOR} + -DRunCMake_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/${test} + -DRunCMake_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/${test} + -P "${CMAKE_CURRENT_SOURCE_DIR}/${test}/RunCMakeTest.cmake" + ) +endmacro() + +add_RunCMake_test(ObjectLibrary) + +add_RunCMake_test(build_command) +add_RunCMake_test(find_package) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt new file mode 100644 index 000000000..b31225b48 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at BadObjSource1.cmake:1 \(add_library\): + OBJECT library "A" contains: + + bad.def + + but may contain only headers and sources that compile. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake new file mode 100644 index 000000000..aa3514d90 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource1.cmake @@ -0,0 +1 @@ +add_library(A OBJECT a.c bad.def) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt new file mode 100644 index 000000000..906cf0b64 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at BadObjSource2.cmake:1 \(add_library\): + OBJECT library "A" contains: + + bad.obj + + but may contain only headers and sources that compile. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake new file mode 100644 index 000000000..7957c99f2 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadObjSource2.cmake @@ -0,0 +1 @@ +add_library(A OBJECT a.c bad.obj) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt new file mode 100644 index 000000000..a1cac36fa --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at BadSourceExpression1.cmake:1 \(add_library\): + Unrecognized generator expression: + + \$ +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake new file mode 100644 index 000000000..020c9a00f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression1.cmake @@ -0,0 +1 @@ +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt new file mode 100644 index 000000000..f1fcbe85f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at BadSourceExpression2.cmake:1 \(add_library\): + Objects of target "DoesNotExist" referenced but no such target exists. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake new file mode 100644 index 000000000..ed5dc4335 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression2.cmake @@ -0,0 +1 @@ +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt new file mode 100644 index 000000000..ad14a3513 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at BadSourceExpression3.cmake:2 \(add_library\): + Objects of target "NotObjLib" referenced but is not an OBJECT library. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake new file mode 100644 index 000000000..c3d9a622d --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/BadSourceExpression3.cmake @@ -0,0 +1,2 @@ +add_library(NotObjLib STATIC a.c) +add_library(A STATIC a.c $) diff --git a/Tests/RunCMake/ObjectLibrary/CMakeLists.txt b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt new file mode 100644 index 000000000..a7f077912 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} C) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/ObjectLibrary/Export-result.txt b/Tests/RunCMake/ObjectLibrary/Export-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Export-stderr.txt b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt new file mode 100644 index 000000000..bdadca488 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at Export.cmake:2 \(export\): + export given OBJECT library "A" which may not be exported. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/Export.cmake b/Tests/RunCMake/ObjectLibrary/Export.cmake new file mode 100644 index 000000000..a3f104e29 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Export.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +export(TARGETS A FILE AExport.cmake) diff --git a/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake b/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake new file mode 100644 index 000000000..0796c21ba --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ExportLanguages.cmake @@ -0,0 +1,15 @@ +enable_language(CXX) +add_library(A OBJECT a.cxx) +add_library(B STATIC a.c $) + +# Verify that object library languages are propagated. +export(TARGETS B NAMESPACE Exp FILE BExport.cmake) +include(${CMAKE_CURRENT_BINARY_DIR}/BExport.cmake) +get_property(configs TARGET ExpB PROPERTY IMPORTED_CONFIGURATIONS) +foreach(c ${configs}) + get_property(langs TARGET ExpB PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES_${c}) + list(FIND langs CXX pos) + if(${pos} LESS 0) + message(FATAL_ERROR "Target export does not list object library languages.") + endif() +endforeach() diff --git a/Tests/RunCMake/ObjectLibrary/Import-result.txt b/Tests/RunCMake/ObjectLibrary/Import-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Import-stderr.txt b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt new file mode 100644 index 000000000..74b496ab8 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at Import.cmake:1 \(add_library\): + The OBJECT library type may not be used for IMPORTED libraries. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/Import.cmake b/Tests/RunCMake/ObjectLibrary/Import.cmake new file mode 100644 index 000000000..806b44a25 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Import.cmake @@ -0,0 +1 @@ +add_library(A OBJECT IMPORTED) diff --git a/Tests/RunCMake/ObjectLibrary/Install-result.txt b/Tests/RunCMake/ObjectLibrary/Install-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/Install-stderr.txt b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt new file mode 100644 index 000000000..d2f9f4a37 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at Install.cmake:2 \(install\): + install TARGETS given OBJECT library "A" which may not be installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/Install.cmake b/Tests/RunCMake/ObjectLibrary/Install.cmake new file mode 100644 index 000000000..c1d214bd4 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/Install.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +install(TARGETS A DESTINATION lib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt new file mode 100644 index 000000000..90e828bdb --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at LinkObjLHS.cmake:2 \(target_link_libraries\): + Object library target "AnObjLib" may not link to anything. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake new file mode 100644 index 000000000..5d7831a23 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHS.cmake @@ -0,0 +1,2 @@ +add_library(AnObjLib OBJECT a.c) +target_link_libraries(AnObjLib OtherLib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt new file mode 100644 index 000000000..8809f8933 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at LinkObjRHS1.cmake:3 \(target_link_libraries\): + Target "AnObjLib" of type OBJECT_LIBRARY may not be linked into another + target. One may link only to STATIC or SHARED libraries, or to executables + with the ENABLE_EXPORTS property set. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake new file mode 100644 index 000000000..113d6a841 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS1.cmake @@ -0,0 +1,3 @@ +add_library(A STATIC a.c) +add_library(AnObjLib OBJECT a.c) +target_link_libraries(A AnObjLib) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt new file mode 100644 index 000000000..3295fcac3 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at LinkObjRHS2.cmake:1 \(add_library\): + Target "A" links to OBJECT library "AnObjLib" but this is not allowed. One + may link only to STATIC or SHARED libraries, or to executables with the + ENABLE_EXPORTS property set. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake new file mode 100644 index 000000000..616372949 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/LinkObjRHS2.cmake @@ -0,0 +1,3 @@ +add_library(A SHARED a.c) +target_link_libraries(A AnObjLib) +add_library(AnObjLib OBJECT a.c) diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt new file mode 100644 index 000000000..d67b4ae32 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at ObjWithObj.cmake:2 \(add_library\): + Only executables and non-OBJECT libraries may reference target objects. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake new file mode 100644 index 000000000..d0ef34bfe --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/ObjWithObj.cmake @@ -0,0 +1,2 @@ +add_library(A OBJECT a.c) +add_library(B OBJECT $) diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt new file mode 100644 index 000000000..4b067bbc3 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at PostBuild.cmake:2 \(add_custom_command\): + Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or + POST_BUILD commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/PostBuild.cmake b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake new file mode 100644 index 000000000..dea9a099e --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PostBuild.cmake @@ -0,0 +1,4 @@ +add_library(A OBJECT a.c) +add_custom_command(TARGET A POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "A post-build" + ) diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt new file mode 100644 index 000000000..3b27a6da5 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at PreBuild.cmake:2 \(add_custom_command\): + Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or + POST_BUILD commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/PreBuild.cmake b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake new file mode 100644 index 000000000..e4424c100 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreBuild.cmake @@ -0,0 +1,4 @@ +add_library(A OBJECT a.c) +add_custom_command(TARGET A PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "A pre-build" + ) diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-result.txt b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt new file mode 100644 index 000000000..947b9f177 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at PreLink.cmake:2 \(add_custom_command\): + Target "A" is an OBJECT library that may not have PRE_BUILD, PRE_LINK, or + POST_BUILD commands. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/PreLink.cmake b/Tests/RunCMake/ObjectLibrary/PreLink.cmake new file mode 100644 index 000000000..b88905511 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/PreLink.cmake @@ -0,0 +1,4 @@ +add_library(A OBJECT a.c) +add_custom_command(TARGET A PRE_LINK + COMMAND ${CMAKE_COMMAND} -E echo "A pre-link" + ) diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake new file mode 100644 index 000000000..55db14dfd --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -0,0 +1,18 @@ +include(RunCMake) + +run_cmake(BadSourceExpression1) +run_cmake(BadSourceExpression2) +run_cmake(BadSourceExpression3) +run_cmake(BadObjSource1) +run_cmake(BadObjSource2) +run_cmake(Export) +run_cmake(ExportLanguages) +run_cmake(Import) +run_cmake(Install) +run_cmake(LinkObjLHS) +run_cmake(LinkObjRHS1) +run_cmake(LinkObjRHS2) +run_cmake(ObjWithObj) +run_cmake(PostBuild) +run_cmake(PreBuild) +run_cmake(PreLink) diff --git a/Tests/RunCMake/ObjectLibrary/a.c b/Tests/RunCMake/ObjectLibrary/a.c new file mode 100644 index 000000000..af20d3ff6 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.c @@ -0,0 +1 @@ +int a(void) { return 0; } diff --git a/Tests/RunCMake/ObjectLibrary/a.cxx b/Tests/RunCMake/ObjectLibrary/a.cxx new file mode 100644 index 000000000..ae9c87c49 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/a.cxx @@ -0,0 +1 @@ +extern "C" int acxx(void) { return 0; } diff --git a/Tests/ComplexRelativePaths/Library/dummy b/Tests/RunCMake/ObjectLibrary/bad.def similarity index 100% rename from Tests/ComplexRelativePaths/Library/dummy rename to Tests/RunCMake/ObjectLibrary/bad.def diff --git a/Tests/ComplexRelativePaths/Library/empty.h b/Tests/RunCMake/ObjectLibrary/bad.obj similarity index 100% rename from Tests/ComplexRelativePaths/Library/empty.h rename to Tests/RunCMake/ObjectLibrary/bad.obj diff --git a/Tests/RunCMake/RunCMake.cmake b/Tests/RunCMake/RunCMake.cmake new file mode 100644 index 000000000..26394639f --- /dev/null +++ b/Tests/RunCMake/RunCMake.cmake @@ -0,0 +1,69 @@ +foreach(arg + RunCMake_GENERATOR + RunCMake_SOURCE_DIR + RunCMake_BINARY_DIR + ) + if(NOT DEFINED ${arg}) + message(FATAL_ERROR "${arg} not given!") + endif() +endforeach() + +function(run_cmake test) + set(top_src "${RunCMake_SOURCE_DIR}") + set(top_bin "${RunCMake_BINARY_DIR}") + if(EXISTS ${top_src}/${test}-result.txt) + file(READ ${top_src}/${test}-result.txt expect_result) + string(REGEX REPLACE "\n+$" "" expect_result "${expect_result}") + else() + set(expect_result 0) + endif() + foreach(o out err) + if(EXISTS ${top_src}/${test}-std${o}.txt) + file(READ ${top_src}/${test}-std${o}.txt expect_std${o}) + string(REGEX REPLACE "\n+$" "" expect_std${o} "${expect_std${o}}") + else() + unset(expect_std${o}) + endif() + endforeach() + set(source_dir "${top_src}") + set(binary_dir "${top_bin}/${test}-build") + file(REMOVE_RECURSE "${binary_dir}") + file(MAKE_DIRECTORY "${binary_dir}") + execute_process( + COMMAND ${CMAKE_COMMAND} "${source_dir}" + -G "${RunCMake_GENERATOR}" -DRunCMake_TEST=${test} + WORKING_DIRECTORY "${binary_dir}" + OUTPUT_VARIABLE actual_stdout + ERROR_VARIABLE actual_stderr + RESULT_VARIABLE actual_result + ) + set(msg "") + if(NOT "${actual_result}" STREQUAL "${expect_result}") + set(msg "${msg}Result is [${actual_result}], not [${expect_result}].\n") + endif() + foreach(o out err) + string(REGEX REPLACE "\n+$" "" actual_std${o} "${actual_std${o}}") + set(expect_${o} "") + if(DEFINED expect_std${o}) + if(NOT "${actual_std${o}}" MATCHES "${expect_std${o}}") + string(REGEX REPLACE "\n" "\n expect-${o}> " expect_${o} + " expect-${o}> ${expect_std${o}}") + set(expect_${o} "Expected std${o} to match:\n${expect_${o}}\n") + set(msg "${msg}std${o} does not match that expected.\n") + endif() + endif() + endforeach() + if(msg) + string(REGEX REPLACE "\n" "\n actual-out> " actual_out " actual-out> ${actual_stdout}") + string(REGEX REPLACE "\n" "\n actual-err> " actual_err " actual-err> ${actual_stderr}") + message(SEND_ERROR "${test} - FAILED:\n" + "${msg}" + "${expect_out}" + "Actual stdout:\n${actual_out}\n" + "${expect_err}" + "Actual stderr:\n${actual_err}\n" + ) + else() + message(STATUS "${test} - PASSED") + endif() +endfunction() diff --git a/Tests/CMakeCommands/build_command/CMakeLists.txt b/Tests/RunCMake/build_command/CMakeLists.txt similarity index 96% rename from Tests/CMakeCommands/build_command/CMakeLists.txt rename to Tests/RunCMake/build_command/CMakeLists.txt index 990ac90ce..0fbb94803 100644 --- a/Tests/CMakeCommands/build_command/CMakeLists.txt +++ b/Tests/RunCMake/build_command/CMakeLists.txt @@ -1,3 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) + # This CMakeLists file is *sometimes expected* to result in a configure error. # # expect this to succeed: @@ -12,12 +16,9 @@ # ...even purposefully calling it with known-bad argument lists to cover # error handling code. # -cmake_minimum_required(VERSION 2.8) -project(test_build_command) set(cmd "initial") -message("CTEST_FULL_OUTPUT") message("0. begin") if(TEST_ERROR_CONDITIONS) diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt new file mode 100644 index 000000000..331885b94 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF-stderr.txt @@ -0,0 +1 @@ +skipping cases 1, 2 and 3 because TEST_ERROR_CONDITIONS is OFF diff --git a/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt new file mode 100644 index 000000000..cf66a9d7a --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF-stdout.txt @@ -0,0 +1 @@ +Build files have been written to: diff --git a/Tests/RunCMake/build_command/ErrorsOFF.cmake b/Tests/RunCMake/build_command/ErrorsOFF.cmake new file mode 100644 index 000000000..a243fab01 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsOFF.cmake @@ -0,0 +1 @@ +set(TEST_ERROR_CONDITIONS OFF) diff --git a/Tests/RunCMake/build_command/ErrorsON-result.txt b/Tests/RunCMake/build_command/ErrorsON-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/build_command/ErrorsON-stderr.txt b/Tests/RunCMake/build_command/ErrorsON-stderr.txt new file mode 100644 index 000000000..0be7475d7 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-stderr.txt @@ -0,0 +1,12 @@ +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command requires at least one argument naming a CMake variable + ++ +1. cmd='initial' +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command unknown argument "BOGUS" + ++ +2. cmd='initial' +CMake Error at CMakeLists.txt:[0-9]+ \(build_command\): + build_command unknown argument "STUFF" diff --git a/Tests/RunCMake/build_command/ErrorsON-stdout.txt b/Tests/RunCMake/build_command/ErrorsON-stdout.txt new file mode 100644 index 000000000..841dd0d88 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON-stdout.txt @@ -0,0 +1 @@ +Configuring incomplete, errors occurred! diff --git a/Tests/RunCMake/build_command/ErrorsON.cmake b/Tests/RunCMake/build_command/ErrorsON.cmake new file mode 100644 index 000000000..27814bf64 --- /dev/null +++ b/Tests/RunCMake/build_command/ErrorsON.cmake @@ -0,0 +1 @@ +set(TEST_ERROR_CONDITIONS ON) diff --git a/Tests/RunCMake/build_command/RunCMakeTest.cmake b/Tests/RunCMake/build_command/RunCMakeTest.cmake new file mode 100644 index 000000000..4525c5725 --- /dev/null +++ b/Tests/RunCMake/build_command/RunCMakeTest.cmake @@ -0,0 +1,4 @@ +include(RunCMake) + +run_cmake(ErrorsOFF) +run_cmake(ErrorsON) diff --git a/Tests/RunCMake/find_package/CMakeLists.txt b/Tests/RunCMake/find_package/CMakeLists.txt new file mode 100644 index 000000000..e8db6b05b --- /dev/null +++ b/Tests/RunCMake/find_package/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt new file mode 100644 index 000000000..db8f51222 --- /dev/null +++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at ComponentRequiredAndOptional.cmake:1 \(find_package\): + find_package called with components that are both required and optional: + + CompA + CompB + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake b/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake new file mode 100644 index 000000000..0355f5af3 --- /dev/null +++ b/Tests/RunCMake/find_package/ComponentRequiredAndOptional.cmake @@ -0,0 +1 @@ +find_package(NotHere REQUIRED CompA CompB CompC OPTIONAL_COMPONENTS CompA CompB CompD) diff --git a/Tests/RunCMake/find_package/MissingConfig-stderr.txt b/Tests/RunCMake/find_package/MissingConfig-stderr.txt new file mode 100644 index 000000000..1eae0bb0b --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfig-stderr.txt @@ -0,0 +1,19 @@ +CMake Warning at MissingConfig.cmake:1 \(find_package\): + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Warning at MissingConfig.cmake:2 \(message\): + This warning must be reachable. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/find_package/MissingConfig.cmake b/Tests/RunCMake/find_package/MissingConfig.cmake new file mode 100644 index 000000000..238e7e498 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfig.cmake @@ -0,0 +1,2 @@ +find_package(NotHere CONFIG) +message(WARNING "This warning must be reachable.") diff --git a/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt b/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt new file mode 100644 index 000000000..10e71faa3 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigOneName-stderr.txt @@ -0,0 +1,10 @@ +CMake Warning at MissingConfigOneName.cmake:1 \(find_package\): + Could not find a package configuration file named "NotHereConfig.cmake" + provided by package "NotHere". + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingConfigOneName.cmake b/Tests/RunCMake/find_package/MissingConfigOneName.cmake new file mode 100644 index 000000000..11676a9ab --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigOneName.cmake @@ -0,0 +1 @@ +find_package(NotHere CONFIGS NotHereConfig.cmake) diff --git a/Tests/RunCMake/find_package/MissingConfigRequired-result.txt b/Tests/RunCMake/find_package/MissingConfigRequired-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigRequired-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt b/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt new file mode 100644 index 000000000..2ba774aa2 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigRequired-stderr.txt @@ -0,0 +1,13 @@ +CMake Error at MissingConfigRequired.cmake:1 \(find_package\): + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/find_package/MissingConfigRequired.cmake b/Tests/RunCMake/find_package/MissingConfigRequired.cmake new file mode 100644 index 000000000..0ae67023a --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigRequired.cmake @@ -0,0 +1,2 @@ +find_package(NotHere CONFIG REQUIRED) +message(FATAL_ERROR "This error must not be reachable.") diff --git a/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt b/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt new file mode 100644 index 000000000..2f5086ea8 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigVersion-stderr.txt @@ -0,0 +1,13 @@ +CMake Warning at MissingConfigVersion.cmake:1 \(find_package\): + Could not find a package configuration file provided by "NotHere" + \(requested version 1\.2\) with any of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingConfigVersion.cmake b/Tests/RunCMake/find_package/MissingConfigVersion.cmake new file mode 100644 index 000000000..ac35a79e4 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingConfigVersion.cmake @@ -0,0 +1 @@ +find_package(NotHere 1.2 CONFIG) diff --git a/Tests/RunCMake/find_package/MissingModule-stderr.txt b/Tests/RunCMake/find_package/MissingModule-stderr.txt new file mode 100644 index 000000000..2ad460f58 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingModule-stderr.txt @@ -0,0 +1,26 @@ +CMake Warning at MissingModule.cmake:1 \(find_package\): + No "FindNotHere.cmake" found in CMAKE_MODULE_PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Warning \(dev\) at MissingModule.cmake:1 \(find_package\): + FindNotHere.cmake must either be part of this project itself, in this case + adjust CMAKE_MODULE_PATH so that it points to the correct location inside + its source tree. + + Or it must be installed by a package which has already been found via + find_package\(\). In this case make sure that package has indeed been found + and adjust CMAKE_MODULE_PATH to contain the location where that package has + installed FindNotHere.cmake. This must be a location provided by that + package. This error in general means that the buildsystem of this project + is relying on a Find-module without ensuring that it is actually available. + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning at MissingModule.cmake:2 \(message\): + This warning must be reachable. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/find_package/MissingModule.cmake b/Tests/RunCMake/find_package/MissingModule.cmake new file mode 100644 index 000000000..76bcef293 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingModule.cmake @@ -0,0 +1,2 @@ +find_package(NotHere MODULE) +message(WARNING "This warning must be reachable.") diff --git a/Tests/RunCMake/find_package/MissingModuleRequired-result.txt b/Tests/RunCMake/find_package/MissingModuleRequired-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingModuleRequired-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt b/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt new file mode 100644 index 000000000..fec05f183 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingModuleRequired-stderr.txt @@ -0,0 +1,21 @@ +CMake Error at MissingModuleRequired.cmake:1 \(find_package\): + No "FindNotHere.cmake" found in CMAKE_MODULE_PATH. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Warning \(dev\) at MissingModuleRequired.cmake:1 \(find_package\): + FindNotHere.cmake must either be part of this project itself, in this case + adjust CMAKE_MODULE_PATH so that it points to the correct location inside + its source tree. + + Or it must be installed by a package which has already been found via + find_package\(\). In this case make sure that package has indeed been found + and adjust CMAKE_MODULE_PATH to contain the location where that package has + installed FindNotHere.cmake. This must be a location provided by that + package. This error in general means that the buildsystem of this project + is relying on a Find-module without ensuring that it is actually available. + +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/find_package/MissingModuleRequired.cmake b/Tests/RunCMake/find_package/MissingModuleRequired.cmake new file mode 100644 index 000000000..897eda688 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingModuleRequired.cmake @@ -0,0 +1,2 @@ +find_package(NotHere MODULE REQUIRED) +message(FATAL_ERROR "This error must not be reachable.") diff --git a/Tests/RunCMake/find_package/MissingNormal-stderr.txt b/Tests/RunCMake/find_package/MissingNormal-stderr.txt new file mode 100644 index 000000000..f4c6fbafd --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormal-stderr.txt @@ -0,0 +1,23 @@ +CMake Warning at MissingNormal.cmake:1 \(find_package\): + By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NotHere", but + CMake did not find one. + + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) + + +CMake Warning at MissingNormal.cmake:2 \(message\): + This warning must be reachable. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/find_package/MissingNormal.cmake b/Tests/RunCMake/find_package/MissingNormal.cmake new file mode 100644 index 000000000..fb90e0128 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormal.cmake @@ -0,0 +1,2 @@ +find_package(NotHere) +message(WARNING "This warning must be reachable.") diff --git a/Tests/RunCMake/find_package/MissingNormalRequired-result.txt b/Tests/RunCMake/find_package/MissingNormalRequired-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalRequired-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt b/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt new file mode 100644 index 000000000..7bb7902b6 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalRequired-stderr.txt @@ -0,0 +1,17 @@ +CMake Error at MissingNormalRequired.cmake:1 \(find_package\): + By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NotHere", but + CMake did not find one. + + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/find_package/MissingNormalRequired.cmake b/Tests/RunCMake/find_package/MissingNormalRequired.cmake new file mode 100644 index 000000000..33353d8cd --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalRequired.cmake @@ -0,0 +1,2 @@ +find_package(NotHere REQUIRED) +message(FATAL_ERROR "This error must not be reachable.") diff --git a/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt b/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt new file mode 100644 index 000000000..36de8009e --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalVersion-stderr.txt @@ -0,0 +1,17 @@ +CMake Warning at MissingNormalVersion.cmake:1 \(find_package\): + By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NotHere", but + CMake did not find one. + + Could not find a package configuration file provided by "NotHere" + \(requested version 1\.2\) with any of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingNormalVersion.cmake b/Tests/RunCMake/find_package/MissingNormalVersion.cmake new file mode 100644 index 000000000..2d9ce4ea5 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalVersion.cmake @@ -0,0 +1 @@ +find_package(NotHere 1.2) diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt new file mode 100644 index 000000000..d34f23c8f --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew-stderr.txt @@ -0,0 +1,30 @@ +CMake Warning \(dev\) at MissingNormalWarnNoModuleNew.cmake:3 \(find_package\): + find_package called without either MODULE or CONFIG option and no + FindNotHere.cmake module is in CMAKE_MODULE_PATH. Add MODULE to + exclusively request Module mode and fail if FindNotHere.cmake is missing. + Add CONFIG to exclusively request Config mode and search for a package + configuration file provided by NotHere \(NotHereConfig.cmake or + nothere-config.cmake\). + + \(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.\) +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning at MissingNormalWarnNoModuleNew.cmake:3 \(find_package\): + By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NotHere", but + CMake did not find one. + + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake new file mode 100644 index 000000000..0211249c6 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleNew.cmake @@ -0,0 +1,3 @@ +set(CMAKE_FIND_PACKAGE_WARN_NO_MODULE 1) +set(CMAKE_MINIMUM_REQUIRED_VERSION 2.8.8) +find_package(NotHere) diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt new file mode 100644 index 000000000..b336b5621 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld-stderr.txt @@ -0,0 +1,29 @@ +CMake Warning \(dev\) at MissingNormalWarnNoModuleOld.cmake:2 \(find_package\): + find_package called without NO_MODULE option and no FindNotHere.cmake + module is in CMAKE_MODULE_PATH. Add NO_MODULE to exclusively request + Config mode and search for a package configuration file provided by NotHere + \(NotHereConfig.cmake or nothere-config.cmake\). Otherwise make + FindNotHere.cmake available in CMAKE_MODULE_PATH. + + \(Variable CMAKE_FIND_PACKAGE_WARN_NO_MODULE enabled this warning.\) +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning at MissingNormalWarnNoModuleOld.cmake:2 \(find_package\): + By not providing "FindNotHere.cmake" in CMAKE_MODULE_PATH this project has + asked CMake to find a package configuration file provided by "NotHere", but + CMake did not find one. + + Could not find a package configuration file provided by "NotHere" with any + of the following names: + + NotHereConfig.cmake + nothere-config.cmake + + Add the installation prefix of "NotHere" to CMAKE_PREFIX_PATH or set + "NotHere_DIR" to a directory containing one of the above files. If + "NotHere" provides a separate development package or SDK, be sure it has + been installed. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake new file mode 100644 index 000000000..1c4a77599 --- /dev/null +++ b/Tests/RunCMake/find_package/MissingNormalWarnNoModuleOld.cmake @@ -0,0 +1,2 @@ +set(CMAKE_FIND_PACKAGE_WARN_NO_MODULE 1) +find_package(NotHere) diff --git a/Tests/RunCMake/find_package/MixedModeOptions-result.txt b/Tests/RunCMake/find_package/MixedModeOptions-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/find_package/MixedModeOptions-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt b/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt new file mode 100644 index 000000000..b8670221b --- /dev/null +++ b/Tests/RunCMake/find_package/MixedModeOptions-stderr.txt @@ -0,0 +1,14 @@ +CMake Error at MixedModeOptions.cmake:1 \(find_package\): + find_package given options exclusive to Module mode: + + MODULE + + and options exclusive to Config mode: + + CONFIG + CONFIGS + NO_DEFAULT_PATH + + The options are incompatible. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/MixedModeOptions.cmake b/Tests/RunCMake/find_package/MixedModeOptions.cmake new file mode 100644 index 000000000..7f78ee05f --- /dev/null +++ b/Tests/RunCMake/find_package/MixedModeOptions.cmake @@ -0,0 +1 @@ +find_package(NotHere MODULE CONFIG CONFIGS NotHereConfig.cmake NO_DEFAULT_PATH) diff --git a/Tests/RunCMake/find_package/RunCMakeTest.cmake b/Tests/RunCMake/find_package/RunCMakeTest.cmake new file mode 100644 index 000000000..42705b77a --- /dev/null +++ b/Tests/RunCMake/find_package/RunCMakeTest.cmake @@ -0,0 +1,16 @@ +include(RunCMake) + +run_cmake(ComponentRequiredAndOptional) +run_cmake(MissingNormal) +run_cmake(MissingNormalRequired) +run_cmake(MissingNormalVersion) +run_cmake(MissingNormalWarnNoModuleOld) +run_cmake(MissingNormalWarnNoModuleNew) +run_cmake(MissingModule) +run_cmake(MissingModuleRequired) +run_cmake(MissingConfig) +run_cmake(MissingConfigOneName) +run_cmake(MissingConfigRequired) +run_cmake(MissingConfigVersion) +run_cmake(MixedModeOptions) +run_cmake(SetFoundFALSE) diff --git a/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt b/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt new file mode 100644 index 000000000..695f6450d --- /dev/null +++ b/Tests/RunCMake/find_package/SetFoundFALSE-stderr.txt @@ -0,0 +1,9 @@ +CMake Warning at SetFoundFALSE.cmake:2 \(find_package\): + Found package configuration file: + + .*/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake + + but it set SetFoundFALSE_FOUND to FALSE so package "SetFoundFALSE" is + considered to be NOT FOUND. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/find_package/SetFoundFALSE.cmake b/Tests/RunCMake/find_package/SetFoundFALSE.cmake new file mode 100644 index 000000000..fbcec3c56 --- /dev/null +++ b/Tests/RunCMake/find_package/SetFoundFALSE.cmake @@ -0,0 +1,2 @@ +set(SetFoundFALSE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +find_package(SetFoundFALSE CONFIG) diff --git a/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake b/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake new file mode 100644 index 000000000..ae6bd1454 --- /dev/null +++ b/Tests/RunCMake/find_package/SetFoundFALSEConfig.cmake @@ -0,0 +1 @@ +set(SetFoundFALSE_FOUND FALSE) diff --git a/Tests/SBCS/CMakeLists.txt b/Tests/SBCS/CMakeLists.txt new file mode 100644 index 000000000..b3c3c2cfc --- /dev/null +++ b/Tests/SBCS/CMakeLists.txt @@ -0,0 +1,6 @@ +# a SBCS test case +project (SBCS) + +add_definitions(-D_SBCS) + +add_executable (SBCS SBCS.cxx) diff --git a/Tests/SBCS/SBCS.cxx b/Tests/SBCS/SBCS.cxx new file mode 100644 index 000000000..6ce2c9f25 --- /dev/null +++ b/Tests/SBCS/SBCS.cxx @@ -0,0 +1,22 @@ +// Test to verify that _SBCS being defined causes CharacterSet to be set to 0 (Single Byte Character Set) + +int main () +{ +#ifdef _UNICODE + bool UnicodeSet=true; +#else + bool UnicodeSet=false; +#endif + +#ifdef _MBCS + bool MBCSSet=true; +#else + bool MBCSSet=false; +#endif + + // if neither _UNICODE nor _MBCS is set, CharacterSet must be set to SBCS. + bool SBCSSet=(!UnicodeSet && !MBCSSet); + + // Reverse boolean to indicate error case correctly + return !SBCSSet; +} diff --git a/Tests/SystemInformation/SystemInformation.in b/Tests/SystemInformation/SystemInformation.in index 1055d07dd..90ae20a60 100644 --- a/Tests/SystemInformation/SystemInformation.in +++ b/Tests/SystemInformation/SystemInformation.in @@ -17,6 +17,10 @@ CMAKE_CXX_COMPILER == "${CMAKE_CXX_COMPILER}" CMAKE_C_COMPILER == "${CMAKE_C_COMPILER}" CMAKE_COMPILER_IS_GNUCC == "${CMAKE_COMPILER_IS_GNUCC}" CMAKE_COMPILER_IS_GNUCXX == "${CMAKE_COMPILER_IS_GNUCXX}" +CMAKE_C_COMPILER_ID == "${CMAKE_C_COMPILER_ID}" +CMAKE_C_COMPILER_VERSION == "${CMAKE_C_COMPILER_VERSION}" +CMAKE_CXX_COMPILER_ID == "${CMAKE_CXX_COMPILER_ID}" +CMAKE_CXX_COMPILER_VERSION == "${CMAKE_CXX_COMPILER_VERSION}" // C shared library flag CMAKE_SHARED_LIBRARY_C_FLAGS == "${CMAKE_SHARED_LIBRARY_C_FLAGS}" diff --git a/Tests/VSGNUFortran/CMakeLists.txt b/Tests/VSGNUFortran/CMakeLists.txt new file mode 100644 index 000000000..229c3156c --- /dev/null +++ b/Tests/VSGNUFortran/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 2.8) +project(VSGNUFortran) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") + +# force the executable to be put out of Debug/Release dir +# because gmake build of fortran will not be in a config +# directory, and for easier testing we want the exe and .dll +# to be in the same directory. +if(CMAKE_CONFIGURATION_TYPES) + foreach(config ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER "${config}" config) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) + endforeach() +endif() + +add_subdirectory(subdir) +include_directories(${VSGNUFortran_BINARY_DIR}/subdir/fortran) +add_subdirectory(c_code) +# use a cmake script to run the executable so that PATH +# can be set with the MinGW/bin in it, and the fortran +# runtime libraries can be found. +configure_file(runtest.cmake.in runtest.cmake @ONLY) diff --git a/Tests/VSGNUFortran/c_code/CMakeLists.txt b/Tests/VSGNUFortran/c_code/CMakeLists.txt new file mode 100644 index 000000000..27d22fd35 --- /dev/null +++ b/Tests/VSGNUFortran/c_code/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(c_using_fortran main.c) +target_link_libraries(c_using_fortran hello) diff --git a/Tests/VSGNUFortran/c_code/main.c b/Tests/VSGNUFortran/c_code/main.c new file mode 100644 index 000000000..391bf26fd --- /dev/null +++ b/Tests/VSGNUFortran/c_code/main.c @@ -0,0 +1,7 @@ +#include // created by FortranCInterface +extern void FC_hello(void); +int main() +{ + FC_hello(); + return 0; +} diff --git a/Tests/VSGNUFortran/runtest.cmake.in b/Tests/VSGNUFortran/runtest.cmake.in new file mode 100644 index 000000000..987207bc4 --- /dev/null +++ b/Tests/VSGNUFortran/runtest.cmake.in @@ -0,0 +1,23 @@ +get_filename_component(MINGW_PATH "@MINGW_GFORTRAN@" PATH) +if(NOT EXISTS "${MINGW_PATH}") + set(test_exe + "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran@CMAKE_EXECUTABLE_SUFFIX@") + message("run: ${test_exe}") + execute_process(COMMAND "${test_exe}" + RESULT_VARIABLE res) + if(NOT "${res}" EQUAL 0) + message(FATAL_ERROR "${test_exe} returned a non 0 value") + endif() + return() +endif() +file(TO_NATIVE_PATH "${MINGW_PATH}" MINGW_PATH) +string(REPLACE "\\" "\\\\" MINGW_PATH "${MINGW_PATH}") +message("${MINGW_PATH}") +set(test_exe "@VSGNUFortran_BINARY_DIR@/bin/c_using_fortran.exe") +set(ENV{PATH} "${MINGW_PATH}";$ENV{PATH}) +message("run ${test_exe}") +execute_process(COMMAND "${test_exe}" + RESULT_VARIABLE res) +if(NOT "${res}" EQUAL 0) + message(FATAL_ERROR "${test_exe} returned a non 0 value") +endif() diff --git a/Tests/VSGNUFortran/subdir/CMakeLists.txt b/Tests/VSGNUFortran/subdir/CMakeLists.txt new file mode 100644 index 000000000..0b9919953 --- /dev/null +++ b/Tests/VSGNUFortran/subdir/CMakeLists.txt @@ -0,0 +1,16 @@ +include(CMakeAddFortranSubdirectory) +# add the fortran subdirectory as a fortran project +# the subdir is fortran, the project is FortranHello +cmake_add_fortran_subdirectory(fortran + PROJECT FortranHello # project name in toplevel CMakeLists.txt + ARCHIVE_DIR ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} + RUNTIME_DIR bin # ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + LIBRARIES hello world # target libraries created + CMAKE_COMMAND_LINE + -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} + -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + LINK_LIBRARIES # link interface libraries + LINK_LIBS hello world # hello needs world to link + NO_EXTERNAL_INSTALL + ) diff --git a/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt new file mode 100644 index 000000000..3ee1855c3 --- /dev/null +++ b/Tests/VSGNUFortran/subdir/fortran/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 2.8) +project(FortranHello Fortran C) + +# add a function to test for -lsunquad on sunpro sun systems. +function(test_sunquad result) + set( TEST_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/sunq") + file(WRITE "${TEST_DIR}/testsunq.f" " + PROGRAM TEST + END + ") + file(WRITE ${TEST_DIR}/CMakeLists.txt " +project(sunq Fortran) +add_library(sunq SHARED testsunq.f) +target_link_libraries(sunq sunquad) +") + message(STATUS "looking for -lsunquad") + try_compile(RESULT "${TEST_DIR}" "${TEST_DIR}" sunq OUTPUT_VARIABLE OUT) + if("${RESULT}") + message(STATUS "-lsunquad found") + else() + message(STATUS "-lsunquad not found") + endif() + message(STATUS + "looking for sunquad:\nRESULT=[${RESULT}]\nOUTPUT=[\n${OUT}\n]") + set(${result} "${RESULT}" PARENT_SCOPE) +endfunction() + +# check for the fortran c interface mangling +include(FortranCInterface) +FortranCInterface_HEADER(HelloWorldFCMangle.h + MACRO_NAMESPACE "FC_" + SYMBOL_NAMESPACE "FC_" + SYMBOLS hello world) +add_library(hello SHARED hello.f) +add_library(world SHARED world.f) +target_link_libraries(hello world) +if(CMAKE_Fortran_COMPILER_ID MATCHES SunPro) + target_link_libraries(hello fsu) + if(CMAKE_Fortran_PLATFORM_ID MATCHES SunOS) + target_link_libraries(hello sunmath m) + test_sunquad(CMAKE_HAS_SUNQUAD) + if(CMAKE_HAS_SUNQUAD) + target_link_libraries(hello sunquad) + endif() + endif() +endif() diff --git a/Tests/VSGNUFortran/subdir/fortran/hello.f b/Tests/VSGNUFortran/subdir/fortran/hello.f new file mode 100644 index 000000000..e52119add --- /dev/null +++ b/Tests/VSGNUFortran/subdir/fortran/hello.f @@ -0,0 +1,7 @@ +!DEC$ ATTRIBUTES DLLEXPORT :: HELLO + SUBROUTINE HELLO + + PRINT *, 'Hello' + CALL WORLD + + END diff --git a/Tests/VSGNUFortran/subdir/fortran/world.f b/Tests/VSGNUFortran/subdir/fortran/world.f new file mode 100644 index 000000000..0598eeea6 --- /dev/null +++ b/Tests/VSGNUFortran/subdir/fortran/world.f @@ -0,0 +1,6 @@ +!DEC$ ATTRIBUTES DLLEXPORT :: WORLD + SUBROUTINE WORLD + + PRINT *, 'World!' + + END diff --git a/Utilities/KWIML/ABI.h.in b/Utilities/KWIML/ABI.h.in index e95a4ffe6..e85a1c588 100644 --- a/Utilities/KWIML/ABI.h.in +++ b/Utilities/KWIML/ABI.h.in @@ -380,7 +380,15 @@ suppression macro @KWIML@_ABI_NO_VERIFY was defined. #elif defined(__m68k__) || defined(M68000) # define @KWIML@_ABI_ENDIAN_ID @KWIML@_ABI_ENDIAN_ID_BIG -/* MIPS */ +/* MIPSel (MIPS little endian) */ +#elif defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) +# define @KWIML@_ABI_ENDIAN_ID @KWIML@_ABI_ENDIAN_ID_LITTLE + +/* MIPSeb (MIPS big endian) */ +#elif defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) +# define @KWIML@_ABI_ENDIAN_ID @KWIML@_ABI_ENDIAN_ID_BIG + +/* MIPS (fallback, big endian) */ #elif defined(__mips) || defined(__mips__) || defined(__MIPS__) # define @KWIML@_ABI_ENDIAN_ID @KWIML@_ABI_ENDIAN_ID_BIG diff --git a/Utilities/KWIML/test/test_INT_format.h.in b/Utilities/KWIML/test/test_INT_format.h.in index 72a62f259..71b443d6e 100644 --- a/Utilities/KWIML/test/test_INT_format.h.in +++ b/Utilities/KWIML/test/test_INT_format.h.in @@ -18,17 +18,15 @@ # define LANG "C " #endif -#define VALUE(T, U) \ - (@KWIML@_INT_##T)((@KWIML@_INT_##U)0xab << \ - ((sizeof(@KWIML@_INT_##T)-1)<<3)) \ +#define VALUE(T, U) (T)((U)0xab << ((sizeof(T)-1)<<3)) -#define TEST_C(C, V, PRI, T, U) \ +#define TEST_C_(C, V, PRI, T, U) \ { \ - @KWIML@_INT_##T const x = VALUE(T, U); \ - @KWIML@_INT_##T y = @KWIML@_INT_##C(V); \ - printf(LANG "@KWIML@_INT_" #C ":" \ - " expression [%"@KWIML@_INT_PRI##PRI"]," \ - " literal [%"@KWIML@_INT_PRI##PRI"]", x, y); \ + T const x = VALUE(T, U); \ + T y = C(V); \ + printf(LANG #C ":" \ + " expression [%" @KWIML@_INT_PRI##PRI "]," \ + " literal [%" @KWIML@_INT_PRI##PRI "]", x, y); \ if(x == y) \ { \ printf(", PASSED\n"); \ @@ -40,11 +38,11 @@ } \ } -#define TEST_PRI(PRI, T, U, STR) \ +#define TEST_PRI_(PRI, T, U, STR) \ { \ - @KWIML@_INT_##T const x = VALUE(T, U); \ + T const x = VALUE(T, U); \ char const* str = STR; \ - sprintf(buf, "%"@KWIML@_INT_PRI##PRI, x); \ + sprintf(buf, "%" @KWIML@_INT_PRI##PRI, x); \ printf(LANG "@KWIML@_INT_PRI" #PRI ":" \ " expected [%s], got [%s]", str, buf); \ if(strcmp(str, buf) == 0) \ @@ -58,19 +56,19 @@ } \ } -#define TEST_SCN(SCN, T, U, STR) TEST_SCN2(SCN, SCN, T, U, STR) -#define TEST_SCN2(PRI, SCN, T, U, STR) \ +#define TEST_SCN_(SCN, T, U, STR) TEST_SCN2_(SCN, SCN, T, U, STR) +#define TEST_SCN2_(PRI, SCN, T, U, STR) \ { \ - @KWIML@_INT_##T const x = VALUE(T, U); \ - @KWIML@_INT_##T y; \ + T const x = VALUE(T, U); \ + T y; \ char const* str = STR; \ - if(sscanf(str, "%"@KWIML@_INT_SCN##SCN, &y) != 1) \ + if(sscanf(str, "%" @KWIML@_INT_SCN##SCN, &y) != 1) \ { \ y = 0; \ } \ printf(LANG "@KWIML@_INT_SCN" #SCN ":" \ - " expected [%"@KWIML@_INT_PRI##PRI"]," \ - " got [%"@KWIML@_INT_PRI##PRI"]", x, y); \ + " expected [%" @KWIML@_INT_PRI##PRI "]," \ + " got [%" @KWIML@_INT_PRI##PRI "]", x, y); \ if(x == y) \ { \ printf(", PASSED\n"); \ @@ -82,10 +80,24 @@ } \ } -#define TEST(FMT, T, U, STR) TEST2(FMT, FMT, T, U, STR) -#define TEST2(PRI, SCN, T, U, STR) \ - TEST_PRI(PRI, T, U, STR) \ - TEST_SCN2(PRI, SCN, T, U, STR) +#define TEST_(FMT, T, U, STR) TEST2_(FMT, FMT, T, U, STR) +#define TEST2_(PRI, SCN, T, U, STR) \ + TEST_PRI_(PRI, T, U, STR) \ + TEST_SCN2_(PRI, SCN, T, U, STR) + +/* Concatenate T and U now to avoid expanding them. */ +#define TEST(FMT, T, U, STR) \ + TEST_(FMT, @KWIML@_INT_##T, @KWIML@_INT_##U, STR) +#define TEST2(PRI, SCN, T, U, STR) \ + TEST2_(PRI, SCN, @KWIML@_INT_##T, @KWIML@_INT_##U, STR) +#define TEST_C(C, V, PRI, T, U) \ + TEST_C_(@KWIML@_INT_##C, V, PRI, @KWIML@_INT_##T, @KWIML@_INT_##U) +#define TEST_PRI(PRI, T, U, STR) \ + TEST_PRI_(PRI, @KWIML@_INT_##T, @KWIML@_INT_##U, STR) +#define TEST_SCN(SCN, T, U, STR) \ + TEST_SCN_(SCN, @KWIML@_INT_##T, @KWIML@_INT_##U, STR) +#define TEST_SCN2(PRI, SCN, T, U, STR) \ + TEST_SCN2_(PRI, SCN, @KWIML@_INT_##T, @KWIML@_INT_##U, STR) static int test_INT_format(void) { diff --git a/Utilities/Release/Cygwin/cygwin-setup.hint.in b/Utilities/Release/Cygwin/cygwin-setup.hint.in index 9706c0d8d..a2532fc68 100644 --- a/Utilities/Release/Cygwin/cygwin-setup.hint.in +++ b/Utilities/Release/Cygwin/cygwin-setup.hint.in @@ -1,5 +1,5 @@ # CMake setup.hint file for cygwin setup.exe program -category: Devel -requires: @CMAKE_NCURSES_VERSION@ cygwin -sdesc: "A cross platform build manager" -ldesc: "CMake is a cross platform build manager. It allows you to specify build parameters for C and C++ programs in a cross platform manner. For cygwin Makefiles will be generated. CMake is also capable of generating microsoft project files, nmake, and borland makefiles. CMake can also perform system inspection operations like finding installed libraries and header files." +category: Devel +requires: libgcc1 libidn11 @CMAKE_NCURSES_VERSION@ libstdc++6 +sdesc: "A cross platform build manager" +ldesc: "CMake is a cross platform build manager. It allows you to specify build parameters for C and C++ programs in a cross platform manner. For cygwin Makefiles will be generated. CMake is also capable of generating microsoft project files, nmake, and borland makefiles. CMake can also perform system inspection operations like finding installed libraries and header files." diff --git a/Utilities/Release/dash2win64_cygwin.cmake b/Utilities/Release/dash2win64_cygwin.cmake index 74d501243..78e8df0af 100644 --- a/Utilities/Release/dash2win64_cygwin.cmake +++ b/Utilities/Release/dash2win64_cygwin.cmake @@ -8,6 +8,7 @@ set(CPACK_SOURCE_GENERATORS "CygwinSource") set(MAKE_PROGRAM "make") set(INITIAL_CACHE "CMAKE_BUILD_TYPE:STRING=Release CMAKE_Fortran_COMPILER_FULLPATH:FILEPATH=FALSE +CTEST_TEST_TIMEOUT:STRING=7200 DART_TESTING_TIMEOUT:STRING=7200 ") set(CXX g++) diff --git a/Utilities/Release/dashmacmini2_release.cmake b/Utilities/Release/dashmacmini2_release.cmake index 115181de2..3e6b04973 100644 --- a/Utilities/Release/dashmacmini2_release.cmake +++ b/Utilities/Release/dashmacmini2_release.cmake @@ -5,14 +5,14 @@ set(INSTALL_PREFIX /) set(HOST dashmacmini2) set(MAKE_PROGRAM "make") set(MAKE "${MAKE_PROGRAM} -j2") -set(CPACK_BINARY_GENERATORS "PackageMaker TGZ TZ") +set(CPACK_BINARY_GENERATORS "PackageMaker TGZ TZ") set(INITIAL_CACHE " CMAKE_BUILD_TYPE:STRING=Release CMAKE_OSX_ARCHITECTURES:STRING=ppc;i386 CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE CPACK_SYSTEM_NAME:STRING=Darwin-universal BUILD_QtDialog:BOOL=TRUE -QT_QMAKE_EXECUTABLE:FILEPATH=/Users/kitware/Software/QtBinUniversal/bin/qmake +QT_QMAKE_EXECUTABLE:FILEPATH=/Users/kitware/Support/qt-4.8.0/install/bin/qmake ") get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH) include(${path}/release_cmake.cmake) diff --git a/Utilities/Release/dashmacmini5_release.cmake b/Utilities/Release/dashmacmini5_release.cmake index 9bb3a98a0..bd93a8733 100644 --- a/Utilities/Release/dashmacmini5_release.cmake +++ b/Utilities/Release/dashmacmini5_release.cmake @@ -14,7 +14,7 @@ CMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.5 CMAKE_SKIP_BOOTSTRAP_TEST:STRING=TRUE CPACK_SYSTEM_NAME:STRING=Darwin64-universal BUILD_QtDialog:BOOL=TRUE -QT_QMAKE_EXECUTABLE:FILEPATH=/Users/kitware/Support/qt-4.7.4/install/bin/qmake +QT_QMAKE_EXECUTABLE:FILEPATH=/Users/kitware/Support/qt-4.8.0/install/bin/qmake ") get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH) include(${path}/release_cmake.cmake) diff --git a/Utilities/Release/magrathea_release.cmake b/Utilities/Release/magrathea_release.cmake index 549460ecd..1b2ae02c7 100644 --- a/Utilities/Release/magrathea_release.cmake +++ b/Utilities/Release/magrathea_release.cmake @@ -10,7 +10,7 @@ CURSES_INCLUDE_PATH:PATH=/usr/i686-gcc-332s/include/ncurses FORM_LIBRARY:FILEPATH=/usr/i686-gcc-332s/lib/libform.a CPACK_SYSTEM_NAME:STRING=Linux-i386 BUILD_QtDialog:BOOL:=TRUE -QT_QMAKE_EXECUTABLE:FILEPATH=/home/kitware/qt-x11-opensource-src-4.3.3-install/bin/qmake +QT_QMAKE_EXECUTABLE:FILEPATH=/home/kitware/qt-4.43-install/bin/qmake ") get_filename_component(path "${CMAKE_CURRENT_LIST_FILE}" PATH) include(${path}/release_cmake.cmake) diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in index daf811412..c8240850e 100644 --- a/Utilities/cmThirdParty.h.in +++ b/Utilities/cmThirdParty.h.in @@ -16,6 +16,7 @@ #cmakedefine CMAKE_USE_SYSTEM_CURL #cmakedefine CMAKE_USE_SYSTEM_EXPAT #cmakedefine CMAKE_USE_SYSTEM_ZLIB +#cmakedefine CMAKE_USE_SYSTEM_BZIP2 #cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE #cmakedefine CTEST_USE_XMLRPC diff --git a/Utilities/cm_bzlib.h b/Utilities/cm_bzlib.h new file mode 100644 index 000000000..d1fffa1aa --- /dev/null +++ b/Utilities/cm_bzlib.h @@ -0,0 +1,23 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2000-2012 Kitware, Inc., Insight Software Consortium + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef __cm_bzlib_h +#define __cm_bzlib_h + +/* Use the bzip2 library configured for CMake. */ +#include "cmThirdParty.h" +#ifdef CMAKE_USE_SYSTEM_BZIP2 +# include +#else +# include +#endif + +#endif diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt index 7030b2eb2..caa44f1d6 100644 --- a/Utilities/cmcurl/CMakeLists.txt +++ b/Utilities/cmcurl/CMakeLists.txt @@ -33,12 +33,7 @@ INCLUDE (CheckIncludeFile) INCLUDE (CheckIncludeFiles) INCLUDE (CheckLibraryExists) INCLUDE (CheckSymbolExists) -IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.4 - AND CMake_SOURCE_DIR) - INCLUDE (${CMake_SOURCE_DIR}/Modules/CheckTypeSize.cmake) -ELSE() - INCLUDE (CheckTypeSize) -ENDIF() +INCLUDE (CheckTypeSize) SET(libCurl_SRCS # amigaos.c - does not build on AmigaOS @@ -131,15 +126,15 @@ IF(CURL_MALLOC_DEBUG) ENDIF(CURL_MALLOC_DEBUG) # On windows preload settings -IF(WIN32) +IF(WIN32 AND NOT MINGW) INCLUDE(${LIBCURL_SOURCE_DIR}/Platforms/WindowsCache.cmake) -ENDIF(WIN32) +ENDIF() # This macro checks if the symbol exists in the library and if it # does, it appends library to the list. SET(CURL_LIBS "") MACRO(CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE) - CHECK_LIBRARY_EXISTS("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "" + CHECK_LIBRARY_EXISTS("${LIBRARY};${CURL_LIBS}" ${SYMBOL} "" ${VARIABLE}) IF(${VARIABLE}) SET(CURL_LIBS ${CURL_LIBS} ${LIBRARY}) @@ -180,7 +175,7 @@ IF(CMAKE_USE_OPENSSL) SET(USE_SSLEAY TRUE) SET(USE_OPENSSL TRUE) IF(WIN32) - FIND_PATH(SSLINCLUDE openssl/crypto.h + FIND_PATH(SSLINCLUDE openssl/crypto.h PATHS c:/hoffman/Tools/openssl_w32vc6-0.9.8g/inc32) INCLUDE_DIRECTORIES(${SSLINCLUDE}) FIND_LIBRARY(LIBEAY NAMES libeay32) @@ -190,6 +185,11 @@ IF(CMAKE_USE_OPENSSL) CHECK_LIBRARY_EXISTS_CONCAT("crypto" CRYPTO_lock HAVE_LIBCRYPTO) CHECK_LIBRARY_EXISTS_CONCAT("ssl" SSL_connect HAVE_LIBSSL) ENDIF(WIN32) + SET(CURL_CA_BUNDLE "" CACHE FILEPATH "Path to SSL CA Certificate Bundle") + MARK_AS_ADVANCED(CURL_CA_BUNDLE) + IF(CURL_CA_BUNDLE) + ADD_DEFINITIONS(-DCURL_CA_BUNDLE="${CURL_CA_BUNDLE}") + ENDIF(CURL_CA_BUNDLE) ENDIF(CMAKE_USE_OPENSSL) # Check for idn @@ -221,7 +221,7 @@ IF(HAVE_FEATURES_H) getenv.c hash.c http.c - if2ip.c + if2ip.c mprintf.c multi.c sendf.c @@ -287,9 +287,9 @@ ENDIF(NOT CURL_SPECIAL_LIBZ) CHECK_INCLUDE_FILE_CONCAT("sys/socket.h" HAVE_SYS_SOCKET_H) CHECK_INCLUDE_FILE_CONCAT("netinet/in.h" HAVE_NETINET_IN_H) CHECK_INCLUDE_FILE_CONCAT("net/if.h" HAVE_NET_IF_H) -CHECK_INCLUDE_FILE_CONCAT("netinet/if_ether.h" +CHECK_INCLUDE_FILE_CONCAT("netinet/if_ether.h" HAVE_NETINET_IF_ETHER_H) -CHECK_INCLUDE_FILE_CONCAT("netinet/tcp.h" +CHECK_INCLUDE_FILE_CONCAT("netinet/tcp.h" HAVE_NETINET_TCP_H) CHECK_INCLUDE_FILE_CONCAT("sys/select.h" HAVE_SYS_SELECT_H) CHECK_INCLUDE_FILE_CONCAT("utime.h" HAVE_UTIME_H) @@ -421,7 +421,7 @@ IF(CMAKE_USE_OPENSSL) CHECK_SYMBOL_EXISTS(RAND_status "${CURL_INCLUDES}" HAVE_RAND_STATUS) CHECK_SYMBOL_EXISTS(RAND_screen "${CURL_INCLUDES}" HAVE_RAND_SCREEN) CHECK_SYMBOL_EXISTS(RAND_egd "${CURL_INCLUDES}" HAVE_RAND_EGD) - CHECK_SYMBOL_EXISTS(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}" + CHECK_SYMBOL_EXISTS(CRYPTO_cleanup_all_ex_data "${CURL_INCLUDES}" HAVE_CRYPTO_CLEANUP_ALL_EX_DATA) ENDIF(CMAKE_USE_OPENSSL) CHECK_SYMBOL_EXISTS(gmtime_r "${CURL_INCLUDES}" HAVE_GMTIME_R) @@ -485,7 +485,7 @@ ENDIF(NOT HAVE_SIGSETJMP) # For other curl specific tests, use this macro. MACRO(CURL_INTERNAL_TEST CURL_TEST) IF("${CURL_TEST}" MATCHES "^${CURL_TEST}$") - SET(MACRO_CHECK_FUNCTION_DEFINITIONS + SET(MACRO_CHECK_FUNCTION_DEFINITIONS "-D${CURL_TEST} ${CMAKE_REQUIRED_FLAGS}") IF(CMAKE_REQUIRED_LIBRARIES) SET(CURL_TEST_ADD_LIBRARIES @@ -502,18 +502,18 @@ MACRO(CURL_INTERNAL_TEST CURL_TEST) IF(${CURL_TEST}) SET(${CURL_TEST} 1 CACHE INTERNAL "Curl test ${FUNCTION}") MESSAGE(STATUS "Performing Curl Test ${CURL_TEST} - Success") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log "Performing Curl Test ${CURL_TEST} passed with the following output:\n" "${OUTPUT}\n") ELSE(${CURL_TEST}) MESSAGE(STATUS "Performing Curl Test ${CURL_TEST} - Failed") SET(${CURL_TEST} "" CACHE INTERNAL "Curl test ${FUNCTION}") - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "Performing Curl Test ${CURL_TEST} failed with the following output:\n" "${OUTPUT}\n") ENDIF(${CURL_TEST}) ENDIF("${CURL_TEST}" MATCHES "^${CURL_TEST}$") -ENDMACRO(CURL_INTERNAL_TEST) +ENDMACRO(CURL_INTERNAL_TEST) # Do curl specific tests #OPTION(CURL_HAVE_DISABLED_NONBLOCKING "Disable non-blocking socket detection" OFF) @@ -527,7 +527,7 @@ IF(NOT CURL_HAVE_DISABLED_NONBLOCKING) HAVE_SO_NONBLOCK ) ENDIF(NOT CURL_HAVE_DISABLED_NONBLOCKING) -FOREACH(CURL_TEST +FOREACH(CURL_TEST ${CURL_NONBLOCKING_TESTS} TIME_WITH_SYS_TIME HAVE_O_NONBLOCKHAVE_GETHOSTBYADDR_R_5 @@ -627,12 +627,12 @@ SET(CMAKE_REQUIRED_FLAGS) # Check for nonblocking SET(HAVE_DISABLED_NONBLOCKING 1) -IF(HAVE_FIONBIO OR +IF(HAVE_FIONBIO OR HAVE_IOCTLSOCKET OR HAVE_IOCTLSOCKET_CASE OR HAVE_O_NONBLOCK) SET(HAVE_DISABLED_NONBLOCKING) -ENDIF(HAVE_FIONBIO OR +ENDIF(HAVE_FIONBIO OR HAVE_IOCTLSOCKET OR HAVE_IOCTLSOCKET_CASE OR HAVE_O_NONBLOCK) diff --git a/Utilities/cmlibarchive/.gitattributes b/Utilities/cmlibarchive/.gitattributes new file mode 100644 index 000000000..be7062b6e --- /dev/null +++ b/Utilities/cmlibarchive/.gitattributes @@ -0,0 +1,2 @@ +*.h whitespace=indent-with-non-tab,-blank-at-eol +*.c whitespace=indent-with-non-tab,-blank-at-eol diff --git a/Utilities/cmlibarchive/CMakeLists.txt b/Utilities/cmlibarchive/CMakeLists.txt index 3a6b5c4ae..7f7a69f04 100644 --- a/Utilities/cmlibarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/CMakeLists.txt @@ -1,20 +1,21 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) # # PROJECT(libarchive C) # -SET(CMAKE_MODULE_PATH "${libarchive_SOURCE_DIR}/build/cmake") +CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) +SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake") +if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${libarchive_BINARY_DIR}/bin) +endif() -# We use CHECK_TYPE_SIZE for existence tests, so use only one arch. -LIST(LENGTH CMAKE_OSX_ARCHITECTURES NUM_ARCHS) -IF(${NUM_ARCHS} GREATER 1) - LIST(GET CMAKE_OSX_ARCHITECTURES 0 CMAKE_TRY_COMPILE_OSX_ARCHITECTURES) -ENDIF() +# On MacOS, prefer MacPorts libraries to system libraries. +# I haven't come up with a compelling argument for this to be conditional. +list(APPEND CMAKE_PREFIX_PATH /opt/local) # # Version - read from 'version' file. # -FILE(STRINGS ${libarchive_SOURCE_DIR}/build/version _version) +FILE(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/build/version _version) STRING(REGEX REPLACE "^([0-9])[0-9][0-9][0-9][0-9][0-9][0-9][a-z]?$" "\\1" _major ${_version}) STRING(REGEX REPLACE @@ -24,40 +25,61 @@ STRING(REGEX REPLACE STRING(REGEX REPLACE "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]([a-z]?)$" "\\1" _quality ${_version}) SET(_version_number ${_major}${_minor}${_revision}) -STRING(REGEX REPLACE "[0]*([^0][0-9]*)$" "\\1" _minor ${_minor}) -STRING(REGEX REPLACE "[0]*([^0][0-9]*)$" "\\1" _revision ${_revision}) +STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_minor ${_minor}) +STRING(REGEX REPLACE "[0]*([^0]*[0-9])$" "\\1" _trimmed_revision ${_revision}) # -SET(VERSION "${_major}.${_minor}.${_revision}${_quality}") +SET(VERSION "${_major}.${_trimmed_minor}.${_trimmed_revision}${_quality}") SET(BSDCPIO_VERSION_STRING "${VERSION}") SET(BSDTAR_VERSION_STRING "${VERSION}") SET(LIBARCHIVE_VERSION_NUMBER "${_version_number}") SET(LIBARCHIVE_VERSION_STRING "${VERSION}") -# Shared library number -SET(SOVERSION 8) -OPTION(ENABLE_TAR "Enable tar building" ON) -OPTION(ENABLE_TAR_SHARED "Enable dynamic build of tar" OFF) -OPTION(ENABLE_CPIO "Enable cpio building" ON) -OPTION(ENABLE_CPIO_SHARED "Enable dynamic build of cpio" OFF) -OPTION(ENABLE_XATTR "Enable extended attribute support" ON) -OPTION(ENABLE_ACL "Enable ACL support" OFF) -OPTION(ENABLE_TEST "Enable unit and regression tests" OFF) +# INTERFACE_VERSION increments with every release +# libarchive 2.7 == interface version 9 = 2 + 7 +# libarchive 2.8 == interface version 10 = 2 + 8 +# libarchive 2.9 == interface version 11 = 2 + 9 +# libarchive 3.0 == interface version 12 +# libarchive 3.x == interface version 12 + x +math(EXPR INTERFACE_VERSION "12 + ${_minor}") -IF(ENABLE_TEST) - ENABLE_TESTING() -ENDIF(ENABLE_TEST) -IF(WIN32 AND NOT CYGWIN) - # Currently, dynamic build only. - SET(ENABLE_TAR_SHARED ON) - SET(ENABLE_CPIO_SHARED ON) -ENDIF(WIN32 AND NOT CYGWIN) +# Set SOVERSION == Interface version +# ?? Should there be more here ?? +SET(SOVERSION "${INTERFACE_VERSION}") + +# Disable warnings to avoid changing 3rd party code. +IF("${CMAKE_C_COMPILER_ID}" MATCHES + "^(GNU|Clang|XL|VisualAge|SunPro|MIPSpro|HP|Intel)$") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w") +ELSEIF("${CMAKE_C_COMPILER_ID}" MATCHES "^(PathScale)$") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -woffall") +ELSEIF(BORLAND) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-") +ENDIF() + +# Enable CTest/CDash support +include(CTest) + +OPTION(ENABLE_NETTLE "Enable use of Nettle" ON) +OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON) +OPTION(ENABLE_XATTR "Enable extended attribute support" ON) +OPTION(ENABLE_ACL "Enable ACL support" ON) +OPTION(ENABLE_ICONV "Enable iconv support" ON) IF(WIN32) - SET(_WIN32_WINNT 0x0500 CACHE INTERNAL "Setting _WIN32_WINNT to 0x0500 for Windows 2000 APIs") - SET(WINVER 0x0500 CACHE INTERNAL "Setting WINVER to 0x0500 for Windows 2000 APIs") + IF(MSVC60) + SET(WINVER 0x0400) + ELSE() + SET(WINVER 0x0500) + ENDIF() + SET(_WIN32_WINNT ${WINVER}) ENDIF(WIN32) +IF("${CMAKE_C_PLATFORM_ID}" MATCHES "^(HP-UX)$") + ADD_DEFINITIONS(-D_XOPEN_SOURCE=500) # Ask wchar.h for mbstate_t +ENDIF() + # +INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceRuns) INCLUDE(CheckFileOffsetBits) INCLUDE(CheckFuncs) @@ -126,8 +148,8 @@ IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") # cmake -DCMAKE_PREFIX_PATH= # # If compiling error occured in zconf.h, You may need patch to zconf.h. - #--- zconf.h.orig 2005-07-21 00:40:26.000000000 - #+++ zconf.h 2009-01-19 11:39:10.093750000 + #--- zconf.h.orig 2005-07-21 00:40:26.000000000 + #+++ zconf.h 2009-01-19 11:39:10.093750000 #@@ -286,7 +286,7 @@ # # #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */ @@ -140,7 +162,6 @@ IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}") SET(ADDITIONAL_LIBS "") - # # Find ZLIB # @@ -149,14 +170,19 @@ IF(ZLIB_FOUND) SET(HAVE_LIBZ 1) SET(HAVE_ZLIB_H 1) INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) - # if building inside cmake do not add this lib - # as it will not exist at try compile time - IF(NOT "${ZLIB_LIBRARIES}" MATCHES cmzlib) - LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES}) - ENDIF(NOT "${ZLIB_LIBRARIES}" MATCHES cmzlib) + LIST(APPEND ADDITIONAL_LIBS ${ZLIB_LIBRARIES}) + IF(WIN32 AND NOT CYGWIN) + SET(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR}) + SET(CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES}) + CHECK_C_SOURCE_Runs( + "#ifndef ZLIB_WINAPI\n#define ZLIB_WINAPI\n#endif\n#include \nint main() {uLong f = zlibCompileFlags(); return (f&(1U<<10))?0:-1; }" + ZLIB_WINAPI) + SET(CMAKE_REQUIRED_INCLUDES) + SET(CMAKE_REQUIRED_LIBRARIES) + ENDIF(WIN32 AND NOT CYGWIN) +ELSE(ZLIB_FOUND) + MESSAGE(FATAL_ERROR "CMake requires zlib to be available to libarchive") ENDIF(ZLIB_FOUND) -MARK_AS_ADVANCED(CLEAR ZLIB_INCLUDE_DIR) -MARK_AS_ADVANCED(CLEAR ZLIB_LIBRARY) # # Find BZip2 # @@ -165,43 +191,28 @@ IF(BZIP2_FOUND) SET(HAVE_LIBBZ2 1) SET(HAVE_BZLIB_H 1) INCLUDE_DIRECTORIES(${BZIP2_INCLUDE_DIR}) - # if building inside cmake do not add this lib - # as it will not exist at try compile time - IF(NOT "${BZIP2_LIBRARIES}" MATCHES cmbzip2) - LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES}) - ENDIF() + LIST(APPEND ADDITIONAL_LIBS ${BZIP2_LIBRARIES}) ENDIF(BZIP2_FOUND) MARK_AS_ADVANCED(CLEAR BZIP2_INCLUDE_DIR) -MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARIES) +MARK_AS_ADVANCED(CLEAR BZIP2_LIBRARY) + +IF(0) # CMake does not need LZMA support in libarchive # # Find LZMA # -IF(BUILD_ARCHIVE_WITHIN_CMAKE) - # do not depend on external library - # for internal CMake build - SET(LZMA_FOUND FALSE) -ELSE(BUILD_ARCHIVE_WITHIN_CMAKE) - FIND_PACKAGE(LZMA) -ENDIF(BUILD_ARCHIVE_WITHIN_CMAKE) - +FIND_PACKAGE(LZMA) IF(LZMA_FOUND) SET(HAVE_LIBLZMA 1) SET(HAVE_LZMA_H 1) INCLUDE_DIRECTORIES(${LZMA_INCLUDE_DIR}) LIST(APPEND ADDITIONAL_LIBS ${LZMA_LIBRARIES}) - MARK_AS_ADVANCED(CLEAR LZMA_INCLUDE_DIR) - MARK_AS_ADVANCED(CLEAR LZMA_LIBRARY) ELSEIF(LZMADEC_FOUND) SET(HAVE_LIBLZMADEC 1) SET(HAVE_LZMADEC_H 1) INCLUDE_DIRECTORIES(${LZMADEC_INCLUDE_DIR}) LIST(APPEND ADDITIONAL_LIBS ${LZMADEC_LIBRARIES}) - MARK_AS_ADVANCED(CLEAR LZMADEC_INCLUDE_DIR) - MARK_AS_ADVANCED(CLEAR LZMADEC_LIBRARY) -ELSE(LZMA_FOUND) - MARK_AS_ADVANCED(CLEAR LZMA_INCLUDE_DIR) - MARK_AS_ADVANCED(CLEAR LZMA_LIBRARY) ENDIF(LZMA_FOUND) +ENDIF() # # Check headers @@ -212,29 +223,36 @@ SET(INCLUDES "") MACRO (LA_CHECK_INCLUDE_FILE header var) CHECK_INCLUDE_FILES("${INCLUDES};${header}" ${var}) IF (${var}) - SET(INCLUDES ${INCLUDES} ${header}) + SET(INCLUDES ${INCLUDES} ${header}) ENDIF (${var}) ENDMACRO (LA_CHECK_INCLUDE_FILE) -# Few headers that must precede other headers -# Must precede sys/extattr.h on FreeBSD +# Some FreeBSD headers assume sys/types.h was already included. LA_CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) # Alphabetize the rest unless there's a compelling reason LA_CHECK_INCLUDE_FILE("acl/libacl.h" HAVE_ACL_LIBACL_H) -LA_CHECK_INCLUDE_FILE("attr/xattr.h" HAVE_ATTR_XATTR_H) LA_CHECK_INCLUDE_FILE("ctype.h" HAVE_CTYPE_H) +LA_CHECK_INCLUDE_FILE("copyfile.h" HAVE_COPYFILE_H) LA_CHECK_INCLUDE_FILE("direct.h" HAVE_DIRECT_H) LA_CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H) LA_CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H) LA_CHECK_INCLUDE_FILE("ext2fs/ext2_fs.h" HAVE_EXT2FS_EXT2_FS_H) + +CHECK_C_SOURCE_COMPILES("#include +#include +int main(void) { return EXT2_IOC_GETFLAGS; }" HAVE_WORKING_EXT2_IOC_GETFLAGS) + LA_CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H) LA_CHECK_INCLUDE_FILE("grp.h" HAVE_GRP_H) LA_CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) LA_CHECK_INCLUDE_FILE("io.h" HAVE_IO_H) LA_CHECK_INCLUDE_FILE("langinfo.h" HAVE_LANGINFO_H) LA_CHECK_INCLUDE_FILE("limits.h" HAVE_LIMITS_H) +LA_CHECK_INCLUDE_FILE("linux/types.h" HAVE_LINUX_TYPES_H) +LA_CHECK_INCLUDE_FILE("linux/fiemap.h" HAVE_LINUX_FIEMAP_H) LA_CHECK_INCLUDE_FILE("linux/fs.h" HAVE_LINUX_FS_H) +LA_CHECK_INCLUDE_FILE("linux/magic.h" HAVE_LINUX_MAGIC_H) LA_CHECK_INCLUDE_FILE("locale.h" HAVE_LOCALE_H) LA_CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) LA_CHECK_INCLUDE_FILE("paths.h" HAVE_PATHS_H) @@ -249,15 +267,20 @@ LA_CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) LA_CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) LA_CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) LA_CHECK_INCLUDE_FILE("sys/acl.h" HAVE_SYS_ACL_H) -LA_CHECK_INCLUDE_FILE("sys/extattr.h" HAVE_SYS_EXTATTR_H) +LA_CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) LA_CHECK_INCLUDE_FILE("sys/ioctl.h" HAVE_SYS_IOCTL_H) LA_CHECK_INCLUDE_FILE("sys/mkdev.h" HAVE_SYS_MKDEV_H) +LA_CHECK_INCLUDE_FILE("sys/mount.h" HAVE_SYS_MOUNT_H) LA_CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H) LA_CHECK_INCLUDE_FILE("sys/poll.h" HAVE_SYS_POLL_H) LA_CHECK_INCLUDE_FILE("sys/select.h" HAVE_SYS_SELECT_H) LA_CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) +LA_CHECK_INCLUDE_FILE("sys/statfs.h" HAVE_SYS_STATFS_H) +LA_CHECK_INCLUDE_FILE("sys/statvfs.h" HAVE_SYS_STATVFS_H) LA_CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H) LA_CHECK_INCLUDE_FILE("sys/utime.h" HAVE_SYS_UTIME_H) +LA_CHECK_INCLUDE_FILE("sys/utsname.h" HAVE_SYS_UTSNAME_H) +LA_CHECK_INCLUDE_FILE("sys/vfs.h" HAVE_SYS_VFS_H) LA_CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H) LA_CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H) LA_CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) @@ -265,139 +288,398 @@ LA_CHECK_INCLUDE_FILE("utime.h" HAVE_UTIME_H) LA_CHECK_INCLUDE_FILE("wchar.h" HAVE_WCHAR_H) LA_CHECK_INCLUDE_FILE("wctype.h" HAVE_WCTYPE_H) LA_CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H) +# Following files need windwos.h, so we should test it after windows.h test. +LA_CHECK_INCLUDE_FILE("wincrypt.h" HAVE_WINCRYPT_H) +LA_CHECK_INCLUDE_FILE("winioctl.h" HAVE_WINIOCTL_H) - # -# Some headers require extra includes when they're available. +# Check whether use of __EXTENSIONS__ is safe. +# We need some macro such as _GNU_SOURCE to use extension functions. +# +SET(_INCLUDE_FILES) +FOREACH (it ${_HEADER}) + SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n") +ENDFOREACH (it) + +CHECK_C_SOURCE_COMPILES( + "#define __EXTENSIONS__ 1 + ${_INCLUDE_FILES} + int main() { return 0;}" + SAFE_TO_DEFINE_EXTENSIONS) + # +# Find Nettle +# +IF(ENABLE_NETTLE) + CHECK_LIBRARY_EXISTS(nettle "nettle_sha1_digest" "" NETTLE_FOUND) + IF(NETTLE_FOUND) + SET(CMAKE_REQUIRED_LIBRARIES "nettle") + FIND_LIBRARY(NETTLE_LIBRARY NAMES nettle) + LIST(APPEND ADDITIONAL_LIBS ${NETTLE_LIBRARY}) + ELSE(NETTLE_FOUND) + SET(ENABLE_NETTLE OFF) + ENDIF(NETTLE_FOUND) +ENDIF(ENABLE_NETTLE) # # Find OpenSSL +# (Except on Mac, where OpenSSL is deprecated.) # -IF(CMAKE_USE_OPENSSL) +IF(ENABLE_OPENSSL AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") FIND_PACKAGE(OpenSSL) ELSE() - SET(OPENSSL_FOUND 0) + SET(OPENSSL_FOUND FALSE) # Override cached value ENDIF() -IF(OPENSSL_FOUND) - INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES}) -ENDIF(OPENSSL_FOUND) + +# FreeBSD libmd +CHECK_LIBRARY_EXISTS(md "MD5Init" "" LIBMD_FOUND) +IF(LIBMD_FOUND) + SET(CMAKE_REQUIRED_LIBRARIES "md") + FIND_LIBRARY(LIBMD_LIBRARY NAMES md) + LIST(APPEND ADDITIONAL_LIBS ${LIBMD_LIBRARY}) +ENDIF(LIBMD_FOUND) + # -# Check MD5/RMD160/SHA headers +# How to prove that CRYPTO functions, which have several names on various +# platforms, just see if archive_crypto.c can compile and link against +# required libraries. # -LA_CHECK_INCLUDE_FILE("md5.h" HAVE_MD5_H) -LA_CHECK_INCLUDE_FILE("openssl/md5.h" HAVE_OPENSSL_MD5_H) -LA_CHECK_INCLUDE_FILE("openssl/ripemd.h" HAVE_OPENSSL_RIPEMD_H) -LA_CHECK_INCLUDE_FILE("openssl/sha.h" HAVE_OPENSSL_SHA_H) -LA_CHECK_INCLUDE_FILE("ripemd.h" HAVE_RIPEMD_H) -LA_CHECK_INCLUDE_FILE("rmd160.h" HAVE_RMD160_H) -LA_CHECK_INCLUDE_FILE("sha.h" HAVE_SHA_H) -LA_CHECK_INCLUDE_FILE("sha1.h" HAVE_SHA1_H) -LA_CHECK_INCLUDE_FILE("sha2.h" HAVE_SHA2_H) -LA_CHECK_INCLUDE_FILE("sha256.h" HAVE_SHA256_H) +MACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION) + IF(HAVE_SYS_TYPES_H) + SET(CRYPTO_HEADER_CONFIG "#define HAVE_SYS_TYPES_H 1\n") + ELSE(HAVE_SYS_TYPES_H) + SET(CRYPTO_HEADER_CONFIG "") + ENDIF(HAVE_SYS_TYPES_H) + + FOREACH(ALGORITHM ${ALGORITHMS}) + STRING(TOLOWER "${ALGORITHM}" lower_algorithm) + STRING(TOUPPER "${ALGORITHM}" algorithm) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND) + SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE) + ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NOT NETTLE_FOUND) + SET(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} FALSE) + ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND NOT OPENSSL_FOUND) + + IF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + # Probe the local implementation for whether this + # crypto implementation is available on this platform. + SET(TRY_CRYPTO_REQUIRED_INCLUDES + "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_CURRENT_SOURCE_DIR}/libarchive;${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp") + SET(TRY_CRYPTO_REQUIRED_LIBS) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + SET(TRY_CRYPTO_REQUIRED_INCLUDES + "${TRY_CRYPTO_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}") + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${OPENSSL_LIBRARIES}") + ELSEIF("${IMPLEMENTATION}" MATCHES "^NETTLE$" AND NETTLE_FOUND) + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${NETTLE_LIBRARY}") + ELSEIF("${IMPLEMENTATION}" MATCHES "^LIBMD$" AND LIBMD_FOUND) + SET(TRY_CRYPTO_REQUIRED_LIBS + "-DLINK_LIBRARIES:STRING=${LIBMD_LIBRARY}") + ENDIF("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + + FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/libarchive/archive_crypto.c" + ARCHIVE_CRYPTO_C) + + SET(SOURCE " +#define ARCHIVE_${algorithm}_COMPILE_TEST +#define ARCHIVE_CRYPTO_${algorithm}_${IMPLEMENTATION} +#define PLATFORM_CONFIG_H \"check_crypto_md.h\" + +${ARCHIVE_CRYPTO_C} + +int +main(int argc, char **argv) +{ + archive_${lower_crypto}_ctx ctx; + archive_${lower_crypto}_init(&ctx); + archive_${lower_crypto}_update(&ctx, *argv, argc); + archive_${lower_crypto}_final(&ctx, NULL); + return 0; +} +") + + FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.h" "") + FILE(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c" "${SOURCE}") + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}") + + TRY_COMPILE(ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_md.c + CMAKE_FLAGS + "${TRY_CRYPTO_REQUIRED_LIBS}" + "${TRY_CRYPTO_REQUIRED_INCLUDES}" + OUTPUT_VARIABLE OUTPUT) + + # Inform user whether or not we found it; if not, log why we didn't. + IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- found") + ELSE (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} -- not found") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Checking support for ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION} failed with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${SOURCE}\n") + ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + + # Add appropriate libs/includes depending on whether the implementation + # was found on this platform. + IF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + IF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${OPENSSL_LIBRARIES}) + LIST(REMOVE_DUPLICATES ADDITIONAL_LIBS) + ENDIF ("${IMPLEMENTATION}" MATCHES "^OPENSSL$" AND OPENSSL_FOUND) + ENDIF (ARCHIVE_CRYPTO_${ALGORITHM}_${IMPLEMENTATION}) + ENDFOREACH(ALGORITHM ${ALGORITHMS}) +ENDMACRO(CHECK_CRYPTO ALGORITHMS IMPLEMENTATION) # -# Find MD5/RMD160/SHA library +# CRYPTO functions on Windows is defined at archive_windows.c, thus we do not +# need the test what the functions can be mapped to archive_{crypto name}_init, +# archive_{crypto name}_update and archive_{crypto name}_final. +# The functions on Windows use CALG_{crypto name} macro to create a crypt object +# and then we need to know what CALG_{crypto name} macros is available to show +# ARCHIVE_CRYPTO_{crypto name}_WIN macros because Windows 2000 and earlier version +# of Windows XP do not support SHA256, SHA384 and SHA512. +# +MACRO(CHECK_CRYPTO_WIN CRYPTO_LIST) + IF(WIN32 AND NOT CYGWIN) + FOREACH(CRYPTO ${CRYPTO_LIST}) + IF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN) + STRING(TOUPPER "${CRYPTO}" crypto) + SET(ALGID "") + IF ("${CRYPTO}" MATCHES "^MD5$") + SET(ALGID "CALG_MD5") + ENDIF ("${CRYPTO}" MATCHES "^MD5$") + IF ("${CRYPTO}" MATCHES "^SHA1$") + SET(ALGID "CALG_SHA1") + ENDIF ("${CRYPTO}" MATCHES "^SHA1$") + IF ("${CRYPTO}" MATCHES "^SHA256$") + SET(ALGID "CALG_SHA_256") + ENDIF ("${CRYPTO}" MATCHES "^SHA256$") + IF ("${CRYPTO}" MATCHES "^SHA384$") + SET(ALGID "CALG_SHA_384") + ENDIF ("${CRYPTO}" MATCHES "^SHA384$") + IF ("${CRYPTO}" MATCHES "^SHA512$") + SET(ALGID "CALG_SHA_512") + ENDIF ("${CRYPTO}" MATCHES "^SHA512$") + + SET(SOURCE "#define ${crypto}_COMPILE_TEST +#define _WIN32_WINNT ${_WIN32_WINNT} +#define WINVER ${WINVER} +#include +#include + +int +main(int argc, char **argv) +{ + return ${ALGID}; +} +") + SET(SOURCE_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_crypto_win.c") + + FILE(WRITE "${SOURCE_FILE}" "${SOURCE}") + MESSAGE(STATUS "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN") + + TRY_COMPILE(ARCHIVE_CRYPTO_${CRYPTO}_WIN + ${CMAKE_BINARY_DIR} + ${SOURCE_FILE} + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_CURRENT_SOURCE_DIR}/libarchive" + OUTPUT_VARIABLE OUTPUT) + + IF (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + MESSAGE(STATUS + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- found") + ELSE (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + MESSAGE(STATUS + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN -- not found") + FILE(APPEND + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Checking support for ARCHIVE_CRYPTO_${CRYPTO}_WIN failed with the following output:\n" + "${OUTPUT}\n" + "Source file was:\n${SOURCE}\n") + ENDIF (ARCHIVE_CRYPTO_${CRYPTO}_WIN) + + ENDIF(NOT DEFINED ARCHIVE_CRYPTO_${CRYPTO}_WIN) + ENDFOREACH(CRYPTO) + ENDIF(WIN32 AND NOT CYGWIN) +ENDMACRO(CHECK_CRYPTO_WIN CRYPTO_LIST) + # -IF(CMAKE_USE_OPENSSL) - FIND_LIBRARY(CRYPTO_LIBRARY NAMES crypto) -ELSE() - SET(CRYPTO_LIBRARY "") +# Find iconv +# POSIX defines the second arg as const char ** +# and requires it to be in libc. But we can accept +# a non-const argument here and can support iconv() +# being in libiconv. +# +MACRO(CHECK_ICONV LIB TRY_ICONV_CONST) + IF(NOT HAVE_ICONV) + CHECK_C_SOURCE_COMPILES( + "#include + #include + int main() { + ${TRY_ICONV_CONST} char *ccp; + iconv_t cd = iconv_open(\"\", \"\"); + iconv(cd, &ccp, (size_t *)0, (char **)0, (size_t *)0); + iconv_close(cd); + return 0; + }" + HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + IF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + SET(HAVE_ICONV true) + SET(ICONV_CONST ${TRY_ICONV_CONST}) + ENDIF(HAVE_ICONV_${LIB}_${TRY_ICONV_CONST}) + ENDIF(NOT HAVE_ICONV) +ENDMACRO(CHECK_ICONV TRY_ICONV_CONST) + +IF(ENABLE_ICONV) + FIND_PATH(ICONV_INCLUDE_DIR iconv.h) + MARK_AS_ADVANCED(ICONV_INCLUDE_DIR) + IF(ICONV_INCLUDE_DIR) + #SET(INCLUDES ${INCLUDES} "iconv.h") + SET(HAVE_ICONV_H 1) + INCLUDE_DIRECTORIES(${ICONV_INCLUDE_DIR}) + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) + CHECK_ICONV("libc" "const") + CHECK_ICONV("libc" "") + + # If iconv isn't in libc and we have a libiconv, try that. + FIND_LIBRARY(LIBICONV_PATH iconv) + IF(NOT HAVE_ICONV AND LIBICONV_PATH) + LIST(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBICONV_PATH}) + CHECK_ICONV("libiconv" "const") + CHECK_ICONV("libiconv" "") + IF (HAVE_ICONV) + LIST(APPEND ADDITIONAL_LIBS ${LIBICONV_PATH}) + ENDIF(HAVE_ICONV) + ENDIF(NOT HAVE_ICONV AND LIBICONV_PATH) + ENDIF(ICONV_INCLUDE_DIR) + # + # Find locale_charset() for libiconv. + # + IF(LIBICONV_PATH) + CHECK_INCLUDE_FILES("localcharset.h" HAVE_LOCALCHARSET_H) + CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET) + IF(NOT HAVE_LOCALE_CHARSET) + FIND_LIBRARY(LIBCHARSET_PATH charset) + IF(LIBCHARSET_PATH) + SET(CMAKE_REQUIRED_LIBRARIES ${LIBCHARSET_PATH}) + CHECK_FUNCTION_EXISTS_GLIBC(locale_charset HAVE_LOCALE_CHARSET) + IF(HAVE_LOCALE_CHARSET) + LIST(APPEND ADDITIONAL_LIBS ${LIBCHARSET_PATH}) + ENDIF(HAVE_LOCALE_CHARSET) + ENDIF(LIBCHARSET_PATH) + ENDIF(NOT HAVE_LOCALE_CHARSET) + ENDIF(LIBICONV_PATH) +ELSE(ENABLE_ICONV) + # Make sure ICONV variables are not in CACHE after ENABLE_ICONV disabled + # (once enabled). + UNSET(HAVE_LOCALE_CHARSET CACHE) + UNSET(HAVE_ICONV CACHE) + UNSET(HAVE_ICONV_libc_ CACHE) + UNSET(HAVE_ICONV_libc_const CACHE) + UNSET(HAVE_ICONV_libiconv_ CACHE) + UNSET(HAVE_ICONV_libiconv_const CACHE) + UNSET(ICONV_INCLUDE_DIR CACHE) + UNSET(LIBICONV_PATH CACHE) +ENDIF(ENABLE_ICONV) + +IF(0) # CMake does not need XML support in libarchive +# +# Find Libxml2 +# +FIND_PACKAGE(LibXml2) +IF(LIBXML2_FOUND) + INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${LIBXML2_LIBRARIES}) + SET(HAVE_LIBXML2 1) + # libxml2's include files use iconv.h + SET(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}) + CHECK_INCLUDE_FILES("libxml/xmlreader.h" HAVE_LIBXML_XMLREADER_H) + CHECK_INCLUDE_FILES("libxml/xmlwriter.h" HAVE_LIBXML_XMLWRITER_H) + SET(CMAKE_REQUIRED_INCLUDES "") +ELSE(LIBXML2_FOUND) + # + # Find Expat + # + FIND_PACKAGE(EXPAT) + IF(EXPAT_FOUND) + INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR}) + LIST(APPEND ADDITIONAL_LIBS ${EXPAT_LIBRARIES}) + SET(HAVE_LIBEXPAT 1) + LA_CHECK_INCLUDE_FILE("expat.h" HAVE_EXPAT_H) + ENDIF(EXPAT_FOUND) +ENDIF(LIBXML2_FOUND) ENDIF() -IF(CRYPTO_LIBRARY) - LIST(APPEND ADDITIONAL_LIBS ${CRYPTO_LIBRARY}) -ELSE(CRYPTO_LIBRARY) - IF(NOT OPENSSL_FOUND) - FIND_LIBRARY(MD_LIBRARY NAMES md) - IF(MD_LIBRARY) - LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY}) - ENDIF(MD_LIBRARY) - ENDIF(NOT OPENSSL_FOUND) -ENDIF(CRYPTO_LIBRARY) -# -# Check MD5/RMD160/SHA functions -# -SET(CMAKE_REQUIRED_LIBRARIES ${ADDITIONAL_LIBS}) -CHECK_FUNCTION_EXISTS(MD5_Init HAVE_MD5_Init) -IF(NOT HAVE_MD5_Init) - CHECK_FUNCTION_EXISTS(MD5Init HAVE_MD5Init) - IF(HAVE_MD5Init) - SET(MD5_Init, "MD5Init") - SET(MD5_Update, "MD5Update") - SET(MD5_Final, "MD5Final") - ENDIF(HAVE_MD5Init) -ENDIF(NOT HAVE_MD5_Init) -IF(HAVE_MD5_Init OR HAVE_MD5Init) - SET(HAVE_MD5 1) -ENDIF(HAVE_MD5_Init OR HAVE_MD5Init) -# -CHECK_FUNCTION_EXISTS(RIPEMD160_Init HAVE_RIPEMD160_Init) -IF(NOT HAVE_RIPEMD160_Init) - CHECK_FUNCTION_EXISTS(RMD160Init HAVE_RMD160Init) - IF(HAVE_RMD160Init) - SET(RIPEMD160_Init, "RMD160Init") - SET(RIPEMD160_Update, "RMD160Update") - SET(RIPEMD160_Final, "RMD160Final") - ENDIF(HAVE_RMD160Init) -ENDIF(NOT HAVE_RIPEMD160_Init) -IF(HAVE_RIPEMD160_Init OR HAVE_RMD160Init) - SET(HAVE_RMD160 1) -ENDIF(HAVE_RIPEMD160_Init OR HAVE_RMD160Init) -# -CHECK_FUNCTION_EXISTS(SHA1_Init HAVE_SHA1_Init) -IF(NOT HAVE_SHA1_Init) - CHECK_FUNCTION_EXISTS(SHA1Init HAVE_SHA1Init) - IF(HAVE_SHA1Init) - SET(SHA1_Init, "SHA1Init") - SET(SHA1_Update, "SHA1Update") - SET(SHA1_Final, "SHA1Final") - ENDIF(HAVE_SHA1Init) -ENDIF(NOT HAVE_SHA1_Init) -IF(HAVE_SHA1_Init OR HAVE_SHA1Init) - SET(HAVE_SHA1 1) -ENDIF(HAVE_SHA1_Init OR HAVE_SHA1Init) -# -CHECK_FUNCTION_EXISTS(SHA256_Init HAVE_SHA256) -CHECK_FUNCTION_EXISTS(SHA384_Init HAVE_SHA384) -CHECK_FUNCTION_EXISTS(SHA512_Init HAVE_SHA512) # # Check functions # -CHECK_SYMBOL_EXISTS(CreateHardLinkA "windows.h" HAVE_CREATEHARDLINKA) -CHECK_SYMBOL_EXISTS(CreateHardLinkW "windows.h" HAVE_CREATEHARDLINKW) +IF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") + # + # During checking functions, we should use -fno-builtin to avoid the + # failure of function detection which failure is an error "conflicting + # types for built-in function" caused by using -Werror option. + # + SET(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-builtin") +ENDIF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") +CHECK_SYMBOL_EXISTS(_CrtSetReportMode "crtdbg.h" HAVE__CrtSetReportMode) CHECK_FUNCTION_EXISTS_GLIBC(chflags HAVE_CHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(chown HAVE_CHOWN) CHECK_FUNCTION_EXISTS_GLIBC(chroot HAVE_CHROOT) +CHECK_FUNCTION_EXISTS_GLIBC(ctime_r HAVE_CTIME_R) CHECK_FUNCTION_EXISTS_GLIBC(fchdir HAVE_FCHDIR) CHECK_FUNCTION_EXISTS_GLIBC(fchflags HAVE_FCHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(fchmod HAVE_FCHMOD) CHECK_FUNCTION_EXISTS_GLIBC(fchown HAVE_FCHOWN) CHECK_FUNCTION_EXISTS_GLIBC(fcntl HAVE_FCNTL) +CHECK_FUNCTION_EXISTS_GLIBC(fdopendir HAVE_FDOPENDIR) CHECK_FUNCTION_EXISTS_GLIBC(fork HAVE_FORK) CHECK_FUNCTION_EXISTS_GLIBC(fstat HAVE_FSTAT) +CHECK_FUNCTION_EXISTS_GLIBC(fstatat HAVE_FSTATAT) +CHECK_FUNCTION_EXISTS_GLIBC(fstatfs HAVE_FSTATFS) +CHECK_FUNCTION_EXISTS_GLIBC(fstatvfs HAVE_FSTATVFS) CHECK_FUNCTION_EXISTS_GLIBC(ftruncate HAVE_FTRUNCATE) +CHECK_FUNCTION_EXISTS_GLIBC(futimens HAVE_FUTIMENS) CHECK_FUNCTION_EXISTS_GLIBC(futimes HAVE_FUTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(futimesat HAVE_FUTIMESAT) CHECK_FUNCTION_EXISTS_GLIBC(geteuid HAVE_GETEUID) +CHECK_FUNCTION_EXISTS_GLIBC(getgrgid_r HAVE_GETGRGID_R) +CHECK_FUNCTION_EXISTS_GLIBC(getgrnam_r HAVE_GETGRNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwnam_r HAVE_GETPWNAM_R) +CHECK_FUNCTION_EXISTS_GLIBC(getpwuid_r HAVE_GETPWUID_R) CHECK_FUNCTION_EXISTS_GLIBC(getpid HAVE_GETPID) +CHECK_FUNCTION_EXISTS_GLIBC(getvfsbyname HAVE_GETVFSBYNAME) +CHECK_FUNCTION_EXISTS_GLIBC(gmtime_r HAVE_GMTIME_R) CHECK_FUNCTION_EXISTS_GLIBC(lchflags HAVE_LCHFLAGS) CHECK_FUNCTION_EXISTS_GLIBC(lchmod HAVE_LCHMOD) CHECK_FUNCTION_EXISTS_GLIBC(lchown HAVE_LCHOWN) CHECK_FUNCTION_EXISTS_GLIBC(link HAVE_LINK) +CHECK_FUNCTION_EXISTS_GLIBC(localtime_r HAVE_LOCALTIME_R) CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT) CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(mbrtowc HAVE_MBRTOWC) +CHECK_FUNCTION_EXISTS_GLIBC(mbsnrtowcs HAVE_MBSNRTOWCS) CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE) CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR) CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO) CHECK_FUNCTION_EXISTS_GLIBC(mknod HAVE_MKNOD) +CHECK_FUNCTION_EXISTS_GLIBC(mkstemp HAVE_MKSTEMP) CHECK_FUNCTION_EXISTS_GLIBC(nl_langinfo HAVE_NL_LANGINFO) +CHECK_FUNCTION_EXISTS_GLIBC(openat HAVE_OPENAT) CHECK_FUNCTION_EXISTS_GLIBC(pipe HAVE_PIPE) CHECK_FUNCTION_EXISTS_GLIBC(poll HAVE_POLL) CHECK_FUNCTION_EXISTS_GLIBC(readlink HAVE_READLINK) CHECK_FUNCTION_EXISTS_GLIBC(select HAVE_SELECT) CHECK_FUNCTION_EXISTS_GLIBC(setenv HAVE_SETENV) CHECK_FUNCTION_EXISTS_GLIBC(setlocale HAVE_SETLOCALE) +CHECK_FUNCTION_EXISTS_GLIBC(sigaction HAVE_SIGACTION) +CHECK_FUNCTION_EXISTS_GLIBC(statfs HAVE_STATFS) +CHECK_FUNCTION_EXISTS_GLIBC(statvfs HAVE_STATVFS) CHECK_FUNCTION_EXISTS_GLIBC(strchr HAVE_STRCHR) CHECK_FUNCTION_EXISTS_GLIBC(strdup HAVE_STRDUP) CHECK_FUNCTION_EXISTS_GLIBC(strerror HAVE_STRERROR) @@ -409,20 +691,52 @@ CHECK_FUNCTION_EXISTS_GLIBC(tzset HAVE_TZSET) CHECK_FUNCTION_EXISTS_GLIBC(unsetenv HAVE_UNSETENV) CHECK_FUNCTION_EXISTS_GLIBC(utime HAVE_UTIME) CHECK_FUNCTION_EXISTS_GLIBC(utimes HAVE_UTIMES) +CHECK_FUNCTION_EXISTS_GLIBC(utimensat HAVE_UTIMENSAT) CHECK_FUNCTION_EXISTS_GLIBC(vfork HAVE_VFORK) CHECK_FUNCTION_EXISTS_GLIBC(wcrtomb HAVE_WCRTOMB) +CHECK_FUNCTION_EXISTS_GLIBC(wcscmp HAVE_WCSCMP) CHECK_FUNCTION_EXISTS_GLIBC(wcscpy HAVE_WCSCPY) CHECK_FUNCTION_EXISTS_GLIBC(wcslen HAVE_WCSLEN) +CHECK_FUNCTION_EXISTS_GLIBC(wcsnrtombs HAVE_WCSNRTOMBS) CHECK_FUNCTION_EXISTS_GLIBC(wctomb HAVE_WCTOMB) -CHECK_SYMBOL_EXISTS(wmemcmp "wchar.h" HAVE_WMEMCMP) -CHECK_SYMBOL_EXISTS(wmemcpy "wchar.h" HAVE_WMEMCPY) +CHECK_FUNCTION_EXISTS_GLIBC(_ctime64_s HAVE__CTIME64_S) +CHECK_FUNCTION_EXISTS_GLIBC(_fseeki64 HAVE__FSEEKI64) +CHECK_FUNCTION_EXISTS_GLIBC(_get_timezone HAVE__GET_TIMEZONE) +CHECK_FUNCTION_EXISTS_GLIBC(_localtime64_s HAVE__LOCALTIME64_S) +CHECK_FUNCTION_EXISTS_GLIBC(_mkgmtime64 HAVE__MKGMTIME64) SET(CMAKE_REQUIRED_LIBRARIES "") -CHECK_SYMBOL_EXISTS(fseeko "stdio.h" HAVE_FSEEKO) -CHECK_SYMBOL_EXISTS(strerror_r "string.h" HAVE_STRERROR_R) -CHECK_SYMBOL_EXISTS(strftime "time.h" HAVE_STRFTIME) -CHECK_SYMBOL_EXISTS(vprintf "stdio.h" HAVE_VPRINTF) +CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH) +CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO) +CHECK_FUNCTION_EXISTS(strerror_r HAVE_STRERROR_R) +CHECK_FUNCTION_EXISTS(strftime HAVE_STRFTIME) +CHECK_FUNCTION_EXISTS(vprintf HAVE_VPRINTF) +CHECK_FUNCTION_EXISTS(wmemcmp HAVE_WMEMCMP) +CHECK_FUNCTION_EXISTS(wmemcpy HAVE_WMEMCPY) + +# Restore CMAKE_REQUIRED_FLAGS +IF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") + SET(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS}) +ENDIF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") + +# Make sure we have the POSIX version of readdir_r, not the +# older 2-argument version. +CHECK_C_SOURCE_COMPILES( + "#include \nint main() {DIR *d = opendir(\".\"); struct dirent e,*r; return readdir_r(d,&e,&r);}" + HAVE_READDIR_R) + +# Only detect readlinkat() if we also have AT_FDCWD in unistd.h. +# NOTE: linux requires fcntl.h for AT_FDCWD. +CHECK_C_SOURCE_COMPILES( + "#include \n#include \nint main() {char buf[10]; return readlinkat(AT_FDCWD, \"\", buf, 0);}" + HAVE_READLINKAT) + + +# To verify major(), we need to both include the header +# of interest and verify that the result can be linked. +# CHECK_FUNCTION_EXISTS doesn't accept a header argument, +# CHECK_SYMBOL_EXISTS doesn't test linkage. CHECK_C_SOURCE_COMPILES( "#include \nint main() { return major(256); }" MAJOR_IN_MKDEV) @@ -447,8 +761,6 @@ ENDIF(HAVE_INTTYPES_H) CHECK_SYMBOL_EXISTS(EFTYPE "errno.h" HAVE_EFTYPE) CHECK_SYMBOL_EXISTS(EILSEQ "errno.h" HAVE_EILSEQ) CHECK_SYMBOL_EXISTS(D_MD_ORDER "langinfo.h" HAVE_D_MD_ORDER) -CHECK_SYMBOL_EXISTS(optarg "unistd.h" HAVE_DECL_OPTARG) -CHECK_SYMBOL_EXISTS(optind "unistd.h" HAVE_DECL_OPTIND) CHECK_SYMBOL_EXISTS(INT64_MAX "${headers}" HAVE_DECL_INT64_MAX) CHECK_SYMBOL_EXISTS(INT64_MIN "${headers}" HAVE_DECL_INT64_MIN) CHECK_SYMBOL_EXISTS(UINT32_MAX "${headers}" HAVE_DECL_UINT32_MAX) @@ -459,6 +771,16 @@ CHECK_SYMBOL_EXISTS(SSIZE_MAX "limits.h" HAVE_DECL_SSIZE_MAX) # # Check struct members # +# Check for tm_gmtoff in struct tm +CHECK_STRUCT_MEMBER("struct tm" tm_gmtoff + "time.h" HAVE_STRUCT_TM_TM_GMTOFF) +CHECK_STRUCT_MEMBER("struct tm" __tm_gmtoff + "time.h" HAVE_STRUCT_TM___TM_GMTOFF) + +# Check for f_namemax in struct statfs +CHECK_STRUCT_MEMBER("struct statfs" f_namemax + "sys/param.h;sys/mount.h" HAVE_STRUCT_STATFS_F_NAMEMAX) + # Check for birthtime in struct stat CHECK_STRUCT_MEMBER("struct stat" st_birthtime "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_BIRTHTIME) @@ -482,6 +804,12 @@ CHECK_STRUCT_MEMBER("struct stat" st_blksize # Check for st_flags in struct stat (BSD fflags) CHECK_STRUCT_MEMBER("struct stat" st_flags "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_FLAGS) + +IF(HAVE_SYS_STATVFS_H) + CHECK_STRUCT_MEMBER("struct statvfs" f_iosize + "sys/types.h;sys/statvfs.h" HAVE_STRUCT_STATVFS_F_IOSIZE) +ENDIF() + # # CHECK_STRUCT_MEMBER("struct tm" tm_sec @@ -490,16 +818,35 @@ CHECK_STRUCT_MEMBER("struct tm" tm_sec # # Check for integer types # -# XXX There must be a way to make this simpler XXXX # -CHECK_TYPE_SIZE("long long int" LONG_LONG_INT) -CHECK_TYPE_SIZE("unsigned long long" UNSIGNED_LONG_LONG) -CHECK_TYPE_SIZE("unsigned long long int" UNSIGNED_LONG_LONG_INT) +CHECK_TYPE_SIZE("short" SIZE_OF_SHORT) +CHECK_TYPE_SIZE("int" SIZE_OF_INT) +CHECK_TYPE_SIZE("long" SIZE_OF_LONG) +CHECK_TYPE_SIZE("long long" SIZE_OF_LONG_LONG) + +CHECK_TYPE_SIZE("unsigned short" SIZE_OF_UNSIGNED_SHORT) +CHECK_TYPE_SIZE("unsigned" SIZE_OF_UNSIGNED) +CHECK_TYPE_SIZE("unsigned long" SIZE_OF_UNSIGNED_LONG) +CHECK_TYPE_SIZE("unsigned long long" SIZE_OF_UNSIGNED_LONG_LONG) + +CHECK_TYPE_SIZE("__int64" __INT64) +CHECK_TYPE_SIZE("unsigned __int64" UNSIGNED___INT64) + +CHECK_TYPE_SIZE(int16_t INT16_T) +CHECK_TYPE_SIZE(int32_t INT32_T) +CHECK_TYPE_SIZE(int64_t INT64_T) +CHECK_TYPE_SIZE(intmax_t INTMAX_T) +CHECK_TYPE_SIZE(uint8_t UINT8_T) +CHECK_TYPE_SIZE(uint16_t UINT16_T) +CHECK_TYPE_SIZE(uint32_t UINT32_T) +CHECK_TYPE_SIZE(uint64_t UINT64_T) +CHECK_TYPE_SIZE(uintmax_t UINTMAX_T) -# CHECK_TYPE_SIZE(dev_t DEV_T) IF(NOT HAVE_DEV_T) - SET(dev_t "unsigned int") + IF(MSVC) + SET(dev_t "unsigned int") + ENDIF(MSVC) ENDIF(NOT HAVE_DEV_T) # CHECK_TYPE_SIZE(gid_t GID_T) @@ -520,20 +867,6 @@ IF(NOT HAVE_ID_T) ENDIF(WIN32) ENDIF(NOT HAVE_ID_T) # -CHECK_TYPE_SIZE(int64_t INT64_T) -IF(NOT HAVE_INT64_T) - IF(WIN32) - SET(int64_t "__int64") - ELSE(WIN32) - SET(int64_t "long long") - ENDIF(WIN32) -ENDIF(NOT HAVE_INT64_T) -# -CHECK_TYPE_SIZE(intmax_t INTMAX_T) -IF(NOT HAVE_INTMAX_T) - SET(intmax_t "int64_t") -ENDIF(NOT HAVE_INTMAX_T) -# CHECK_TYPE_SIZE(mode_t MODE_T) IF(NOT HAVE_MODE_T) IF(WIN32) @@ -575,33 +908,14 @@ IF(NOT HAVE_UID_T) ENDIF(WIN32) ENDIF(NOT HAVE_UID_T) # -CHECK_TYPE_SIZE(uint16_t UINT16_T) -IF(NOT HAVE_UINT16_T) - SET(uint16_t "unsigned short") -ENDIF(NOT HAVE_UINT16_T) -# -CHECK_TYPE_SIZE(uint32_t UINT32_T) -IF(NOT HAVE_UINT32_T) - SET(uint32_t "unsigned int") -ENDIF(NOT HAVE_UINT32_T) -CHECK_TYPE_SIZE(int32_t INT32_T) -IF(NOT HAVE_INT32_T) - SET(int32_t "int") -ENDIF(NOT HAVE_INT32_T) -# -CHECK_TYPE_SIZE(uint64_t UINT64_T) -IF(NOT HAVE_UINT64_T) +CHECK_TYPE_SIZE(pid_t PID_T) +IF(NOT HAVE_PID_T) IF(WIN32) - SET(uint64_t "unsigned __int64") + SET(pid_t "int") ELSE(WIN32) - SET(uint64_t "unsigned long long") + MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?") ENDIF(WIN32) -ENDIF(NOT HAVE_UINT64_T) -# -CHECK_TYPE_SIZE(uintmax_t UINTMAX_T) -IF(NOT HAVE_UINTMAX_T) - SET(uintmax_t "uint64_t") -ENDIF(NOT HAVE_UINTMAX_T) +ENDIF(NOT HAVE_PID_T) # CHECK_TYPE_SIZE(intptr_t INTPTR_T) IF(NOT HAVE_INTPTR_T) @@ -630,28 +944,64 @@ ENDIF(HAVE_SIZEOF_WCHAR_T) # CHECK_FILE_OFFSET_BITS() - - # # Check for Extended Attribute libraries, headers, and functions # IF(ENABLE_XATTR) LA_CHECK_INCLUDE_FILE(attr/xattr.h HAVE_ATTR_XATTR_H) LA_CHECK_INCLUDE_FILE(sys/xattr.h HAVE_SYS_XATTR_H) - CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_ATTR_LIB) - IF(HAVE_ATTR_LIB) + LA_CHECK_INCLUDE_FILE(sys/extattr.h HAVE_SYS_EXTATTR_H) + CHECK_LIBRARY_EXISTS(attr "setxattr" "" HAVE_LIBATTR) + IF(HAVE_LIBATTR) SET(CMAKE_REQUIRED_LIBRARIES "attr") - ENDIF(HAVE_ATTR_LIB) + ENDIF(HAVE_LIBATTR) + CHECK_SYMBOL_EXISTS(EXTATTR_NAMESPACE_USER "sys/types.h;sys/extattr.h" HAVE_DECL_EXTATTR_NAMESPACE_USER) CHECK_FUNCTION_EXISTS_GLIBC(extattr_get_file HAVE_EXTATTR_GET_FILE) CHECK_FUNCTION_EXISTS_GLIBC(extattr_list_file HAVE_EXTATTR_LIST_FILE) CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_fd HAVE_EXTATTR_SET_FD) CHECK_FUNCTION_EXISTS_GLIBC(extattr_set_file HAVE_EXTATTR_SET_FILE) + CHECK_FUNCTION_EXISTS_GLIBC(fgetxattr HAVE_FGETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(flistxattr HAVE_FLISTXATTR) CHECK_FUNCTION_EXISTS_GLIBC(fsetxattr HAVE_FSETXATTR) CHECK_FUNCTION_EXISTS_GLIBC(getxattr HAVE_GETXATTR) CHECK_FUNCTION_EXISTS_GLIBC(lgetxattr HAVE_LGETXATTR) CHECK_FUNCTION_EXISTS_GLIBC(listxattr HAVE_LISTXATTR) CHECK_FUNCTION_EXISTS_GLIBC(llistxattr HAVE_LLISTXATTR) CHECK_FUNCTION_EXISTS_GLIBC(lsetxattr HAVE_LSETXATTR) + CHECK_FUNCTION_EXISTS_GLIBC(fgetea HAVE_FGETEA) + CHECK_FUNCTION_EXISTS_GLIBC(flistea HAVE_FLISTEA) + CHECK_FUNCTION_EXISTS_GLIBC(fsetea HAVE_FSETEA) + CHECK_FUNCTION_EXISTS_GLIBC(getea HAVE_GETEA) + CHECK_FUNCTION_EXISTS_GLIBC(lgetea HAVE_LGETEA) + CHECK_FUNCTION_EXISTS_GLIBC(listea HAVE_LISTEA) + CHECK_FUNCTION_EXISTS_GLIBC(llistea HAVE_LLISTEA) + CHECK_FUNCTION_EXISTS_GLIBC(lsetea HAVE_LSETEA) +ELSE(ENABLE_XATTR) + SET(HAVE_ATTR_LIB FALSE) + SET(HAVE_ATTR_XATTR_H FALSE) + SET(HAVE_DECL_EXTATTR_NAMESPACE_USER FALSE) + SET(HAVE_EXTATTR_GET_FILE FALSE) + SET(HAVE_EXTATTR_LIST_FILE FALSE) + SET(HAVE_EXTATTR_SET_FD FALSE) + SET(HAVE_EXTATTR_SET_FILE FALSE) + SET(HAVE_FGETEA FALSE) + SET(HAVE_FGETXATTR FALSE) + SET(HAVE_FLISTEA FALSE) + SET(HAVE_FLISTXATTR FALSE) + SET(HAVE_FSETEA FALSE) + SET(HAVE_FSETXATTR FALSE) + SET(HAVE_GETEA FALSE) + SET(HAVE_GETXATTR FALSE) + SET(HAVE_LGETEA FALSE) + SET(HAVE_LGETXATTR FALSE) + SET(HAVE_LISTEA FALSE) + SET(HAVE_LISTXATTR FALSE) + SET(HAVE_LLISTEA FALSE) + SET(HAVE_LLISTXATTR FALSE) + SET(HAVE_LSETEA FALSE) + SET(HAVE_LSETXATTR FALSE) + SET(HAVE_SYS_EXTATTR_H FALSE) + SET(HAVE_SYS_XATTR_H FALSE) ENDIF(ENABLE_XATTR) # @@ -663,12 +1013,12 @@ ENDIF(ENABLE_XATTR) # which makes the following checks rather more complex than I would like. # IF(ENABLE_ACL) - CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_ACL_LIB) - IF(HAVE_ACL_LIB) + CHECK_LIBRARY_EXISTS(acl "acl_get_file" "" HAVE_LIBACL) + IF(HAVE_LIBACL) SET(CMAKE_REQUIRED_LIBRARIES "acl") FIND_LIBRARY(ACL_LIBRARY NAMES acl) LIST(APPEND ADDITIONAL_LIBS ${ACL_LIBRARY}) - ENDIF(HAVE_ACL_LIB) + ENDIF(HAVE_LIBACL) # CHECK_FUNCTION_EXISTS_GLIBC(acl_create_entry HAVE_ACL_CREATE_ENTRY) CHECK_FUNCTION_EXISTS_GLIBC(acl_init HAVE_ACL_INIT) @@ -682,19 +1032,50 @@ IF(ENABLE_ACL) # test for specific permissions in a permset.) Linux uses the obvious # name, FreeBSD adds _np to mark it as "non-Posix extension." # Test for both as a double-check that we really have POSIX-style ACL support. - CHECK_SYMBOL_EXISTS(acl_get_perm "${INCLUDES}" HAVE_ACL_GET_PERM) - CHECK_SYMBOL_EXISTS(acl_get_perm_np "${INCLUDES}" HAVE_ACL_GET_PERM_NP) - CHECK_SYMBOL_EXISTS(acl_get_link "${INCLUDES}" HAVE_ACL_GET_LINK) - CHECK_SYMBOL_EXISTS(acl_get_link_np "${INCLUDES}" HAVE_ACL_GET_LINK_NP) + CHECK_FUNCTION_EXISTS(acl_get_perm HAVE_ACL_GET_PERM) + CHECK_FUNCTION_EXISTS(acl_get_perm_np HAVE_ACL_GET_PERM_NP) + CHECK_FUNCTION_EXISTS(acl_get_link HAVE_ACL_GET_LINK) + CHECK_FUNCTION_EXISTS(acl_get_link_np HAVE_ACL_GET_LINK_NP) # MacOS has an acl.h that isn't POSIX. It can be detected by # checking for ACL_USER CHECK_SYMBOL_EXISTS(ACL_USER "${INCLUDES}" HAVE_ACL_USER) +ELSE(ENABLE_ACL) + # If someone runs cmake, then disables ACL support, we need + # to forcibly override the cached values for these. + SET(HAVE_ACL_CREATE_ENTRY FALSE) + SET(HAVE_ACL_GET_LINK FALSE) + SET(HAVE_ACL_GET_LINK_NP FALSE) + SET(HAVE_ACL_GET_PERM FALSE) + SET(HAVE_ACL_GET_PERM_NP FALSE) + SET(HAVE_ACL_INIT FALSE) + SET(HAVE_ACL_LIB FALSE) + SET(HAVE_ACL_PERMSET_T FALSE) + SET(HAVE_ACL_SET_FD FALSE) + SET(HAVE_ACL_SET_FD_NP FALSE) + SET(HAVE_ACL_SET_FILE FALSE) + SET(HAVE_ACL_USER FALSE) ENDIF(ENABLE_ACL) +# +# Check MD5/RMD160/SHA support +# NOTE: Crypto checks must be run last before generating config.h +# +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" LIBC) +CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC2) +CHECK_CRYPTO("SHA256;SHA384;SHA512" LIBC3) +CHECK_CRYPTO("MD5;SHA1;SHA256;SHA384;SHA512" LIBSYSTEM) +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" NETTLE) +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA384;SHA512" OPENSSL) + +# Libmd has to be probed after OpenSSL. +CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD) + +CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512") + # Generate "config.h" from "build/cmake/config.h.in" CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/config.h) + ${CMAKE_CURRENT_BINARY_DIR}/config.h) INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR}) ADD_DEFINITIONS(-DHAVE_CONFIG_H) @@ -717,24 +1098,17 @@ ENDIF(WIN32 AND NOT CYGWIN) # # # -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/libarchive) +INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libarchive) # IF(MSVC) ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE) ENDIF(MSVC) -# Especially for early development, we want to be a little -# aggressive about diagnosing build problems; this can get -# relaxed somewhat in final shipping versions. -#IF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") -# ADD_DEFINITIONS(-Wall -Werror) -#ENDIF ("CMAKE_C_COMPILER_ID" MATCHES "^GNU$") -IF(ENABLE_TEST) -ADD_CUSTOM_TARGET(run_all_tests) -ENDIF(ENABLE_TEST) +# We need CoreServices on Mac OS. +IF(APPLE) + LIST(APPEND ADDITIONAL_LIBS "-framework CoreServices") +ENDIF(APPLE) add_subdirectory(libarchive) -#add_subdirectory(tar) -#add_subdirectory(cpio) install(FILES COPYING DESTINATION ${CMake_DOC_DEST}/cmlibarchive) diff --git a/Utilities/cmlibarchive/COPYING b/Utilities/cmlibarchive/COPYING index 9dbf49dbf..b25880600 100644 --- a/Utilities/cmlibarchive/COPYING +++ b/Utilities/cmlibarchive/COPYING @@ -16,8 +16,8 @@ the actual statements in the files are controlling. a 3-clause UC Regents copyright; please read the individual source files for details: libarchive/archive_entry.c - libarchive/archive_read_support_compression_compress.c - libarchive/archive_write_set_compression_compress.c + libarchive/archive_read_support_filter_compress.c + libarchive/archive_write_set_filter_compress.c libarchive/mtree.5 tar/matching.c diff --git a/Utilities/cmlibarchive/CTestConfig.cmake b/Utilities/cmlibarchive/CTestConfig.cmake new file mode 100644 index 000000000..7a09742db --- /dev/null +++ b/Utilities/cmlibarchive/CTestConfig.cmake @@ -0,0 +1,11 @@ +# TODO: This file should be moved into the build/cmake directory... + +# The libarchive CDash page appears at +# http://my.cdash.org/index.php?project=libarchive +set(CTEST_PROJECT_NAME "libarchive") +set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") + +set(CTEST_DROP_METHOD "http") +set(CTEST_DROP_SITE "my.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=libarchive") +set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/Utilities/cmlibarchive/INSTALL b/Utilities/cmlibarchive/INSTALL deleted file mode 100644 index d91cc0691..000000000 --- a/Utilities/cmlibarchive/INSTALL +++ /dev/null @@ -1,30 +0,0 @@ -More complete build documentation is available on the libarchive -Wiki: http://libarchive.googlecode.com/ - -On most Unix-like systems, you should be able to install libarchive, -bsdtar, and bsdcpio using the following common steps: - ./configure - make - make install - -If you need to customize the target directories or otherwise adjust -the build setting, use - ./configure --help -to list the configure options. - -If you are developing libarchive and need to update the -configure script and other build files: - /bin/sh build/autogen.sh - -To create a distribution, please use the 'distcheck' target: - /bin/sh build/autogen.sh && ./configure && make distcheck - -On non-Unix-like systems, use the "cmake" utility (available from -http://cmake.org/) to generate suitable build files for your platform. -Cmake requires the name of the directory containing CmakeLists.txt and -the "generator" to use for your build environment. For example, to -build with Xcode on Mac OS, you can use the following command: - cmake -G "Xcode" ~/libarchive-download-dir/ -The result will be appropriate makefiles, solution files, or project -files that can be used with the corresponding development tool. -See the libarchive Wiki or the cmake site for further documentation. \ No newline at end of file diff --git a/Utilities/cmlibarchive/Makefile.am b/Utilities/cmlibarchive/Makefile.am deleted file mode 100644 index 73f992c24..000000000 --- a/Utilities/cmlibarchive/Makefile.am +++ /dev/null @@ -1,595 +0,0 @@ -## Process this file with automake to produce Makefile.in - -AUTOMAKE_OPTIONS= foreign subdir-objects -ACLOCAL_AMFLAGS = -I build/autoconf - -# -# What to build and install -# -lib_LTLIBRARIES= libarchive.la -noinst_LTLIBRARIES= libarchive_fe.la -bin_PROGRAMS= $(bsdtar_programs) $(bsdcpio_programs) -man_MANS= $(libarchive_man_MANS) $(bsdtar_man_MANS) $(bsdcpio_man_MANS) -BUILT_SOURCES= libarchive/test/list.h tar/test/list.h cpio/test/list.h - -# -# What to test: We always test libarchive, test bsdtar and bsdcpio only -# if we built them. -# -check_PROGRAMS= libarchive_test $(bsdtar_test_programs) $(bsdcpio_test_programs) -TESTS= libarchive_test $(bsdtar_test_programs) $(bsdcpio_test_programs) -TESTS_ENVIRONMENT= $(libarchive_TESTS_ENVIRONMENT) $(bsdtar_TESTS_ENVIRONMENT) $(bsdcpio_TESTS_ENVIRONMENT) -# Always build and test both bsdtar and bsdcpio as part of 'distcheck' -DISTCHECK_CONFIGURE_FLAGS = --enable-bsdtar --enable-bsdcpio -# Especially for early development, we want to be a little -# aggressive about diagnosing build problems; this can get -# relaxed somewhat in final shipping versions. -AM_CFLAGS=-Wall -Werror -PLATFORMCPPFLAGS = @PLATFORMCPPFLAGS@ -AM_CPPFLAGS=$(PLATFORMCPPFLAGS) - -# -# What to include in the distribution -# -EXTRA_DIST= \ - CMakeLists.txt \ - build/autogen.sh \ - build/release.sh \ - build/cmake \ - build/version \ - build/windows \ - contrib \ - doc \ - examples \ - $(libarchive_EXTRA_DIST) \ - $(libarchive_test_EXTRA_DIST) \ - $(bsdtar_EXTRA_DIST) \ - $(bsdtar_test_EXTRA_DIST) \ - $(bsdcpio_EXTRA_DIST) \ - $(bsdcpio_test_EXTRA_DIST) - -# a) Clean out some unneeded files and directories -# b) Collect all documentation and format it for distribution. -dist-hook: - rm -rf `find $(distdir) -name CVS -type d` - rm -rf `find $(distdir) -name .svn -type d` - rm -f `find $(distdir) -name '*~'` - rm -f `find $(distdir) -name '*.out'` - rm -f `find $(distdir) -name '*.core'` - -rm -f $(distdir)/*/Makefile $(distdir)/*/*/Makefile - cd $(distdir)/doc && /bin/sh update.sh - -# Verify cmake builds as part of the acceptance -distcheck-hook: - mkdir $(distdir)/_build/cmtest - cd $(distdir)/_build/cmtest && cmake ../.. && make && make test - rm -rf $(distdir)/_build/cmtest - -# -# Extra rules for cleanup -# -DISTCLEANFILES= \ - libarchive/test/list.h \ - tar/test/list.h \ - cpio/test/list.h - -distclean-local: - -rm -rf .ref - -rm -rf autom4te.cache/ - -rm -f *~ - -[ -f libarchive/Makefile ] && cd libarchive && make clean - -[ -f libarchive/test/Makefile ] && cd libarchive/test && make clean - -[ -f tar/Makefile ] && cd tar && make clean - -[ -f tar/test/Makefile ] && cd tar/test && make clean - -[ -f cpio/Makefile ] && cd cpio && make clean - -[ -f cpio/test/Makefile ] && cd cpio/test && make clean - -# -# Libarchive headers, source, etc. -# -# - -include_HEADERS= libarchive/archive.h libarchive/archive_entry.h - -libarchive_la_SOURCES= \ - libarchive/archive_check_magic.c \ - libarchive/archive_endian.h \ - libarchive/archive_entry.c \ - libarchive/archive_entry.h \ - libarchive/archive_entry_copy_stat.c \ - libarchive/archive_entry_link_resolver.c \ - libarchive/archive_entry_private.h \ - libarchive/archive_entry_stat.c \ - libarchive/archive_entry_strmode.c \ - libarchive/archive_entry_xattr.c \ - libarchive/archive_hash.h \ - libarchive/archive_platform.h \ - libarchive/archive_private.h \ - libarchive/archive_read.c \ - libarchive/archive_read_data_into_fd.c \ - libarchive/archive_read_disk.c \ - libarchive/archive_read_disk_entry_from_file.c \ - libarchive/archive_read_disk_private.h \ - libarchive/archive_read_disk_set_standard_lookup.c \ - libarchive/archive_read_extract.c \ - libarchive/archive_read_open_fd.c \ - libarchive/archive_read_open_file.c \ - libarchive/archive_read_open_filename.c \ - libarchive/archive_read_open_memory.c \ - libarchive/archive_read_private.h \ - libarchive/archive_read_support_compression_all.c \ - libarchive/archive_read_support_compression_bzip2.c \ - libarchive/archive_read_support_compression_compress.c \ - libarchive/archive_read_support_compression_gzip.c \ - libarchive/archive_read_support_compression_none.c \ - libarchive/archive_read_support_compression_program.c \ - libarchive/archive_read_support_compression_xz.c \ - libarchive/archive_read_support_format_all.c \ - libarchive/archive_read_support_format_ar.c \ - libarchive/archive_read_support_format_cpio.c \ - libarchive/archive_read_support_format_empty.c \ - libarchive/archive_read_support_format_iso9660.c \ - libarchive/archive_read_support_format_mtree.c \ - libarchive/archive_read_support_format_raw.c \ - libarchive/archive_read_support_format_tar.c \ - libarchive/archive_read_support_format_zip.c \ - libarchive/archive_string.c \ - libarchive/archive_string.h \ - libarchive/archive_string_sprintf.c \ - libarchive/archive_util.c \ - libarchive/archive_virtual.c \ - libarchive/archive_write.c \ - libarchive/archive_write_disk.c \ - libarchive/archive_write_disk_private.h \ - libarchive/archive_write_disk_set_standard_lookup.c \ - libarchive/archive_write_open_fd.c \ - libarchive/archive_write_open_file.c \ - libarchive/archive_write_open_filename.c \ - libarchive/archive_write_open_memory.c \ - libarchive/archive_write_private.h \ - libarchive/archive_write_set_compression_bzip2.c \ - libarchive/archive_write_set_compression_compress.c \ - libarchive/archive_write_set_compression_gzip.c \ - libarchive/archive_write_set_compression_none.c \ - libarchive/archive_write_set_compression_program.c \ - libarchive/archive_write_set_compression_xz.c \ - libarchive/archive_write_set_format.c \ - libarchive/archive_write_set_format_ar.c \ - libarchive/archive_write_set_format_by_name.c \ - libarchive/archive_write_set_format_cpio.c \ - libarchive/archive_write_set_format_cpio_newc.c \ - libarchive/archive_write_set_format_mtree.c \ - libarchive/archive_write_set_format_pax.c \ - libarchive/archive_write_set_format_shar.c \ - libarchive/archive_write_set_format_ustar.c \ - libarchive/archive_write_set_format_zip.c \ - libarchive/config_freebsd.h \ - libarchive/config_windows.h \ - libarchive/filter_fork.c \ - libarchive/filter_fork.h - -if INC_WINDOWS_FILES -libarchive_la_SOURCES+= \ - libarchive/archive_entry_copy_bhfi.c \ - libarchive/archive_windows.h \ - libarchive/archive_windows.c \ - libarchive/filter_fork_windows.c -endif - -# -no-undefined marks that libarchive doesn't rely on symbols -# defined in the application. This is mandatory for cygwin. -libarchive_la_LDFLAGS= -no-undefined -version-info $(ARCHIVE_LIBTOOL_VERSION) - -# Manpages to install -libarchive_man_MANS= \ - libarchive/archive_entry.3 \ - libarchive/archive_read.3 \ - libarchive/archive_read_disk.3 \ - libarchive/archive_util.3 \ - libarchive/archive_write.3 \ - libarchive/archive_write_disk.3 \ - libarchive/cpio.5 \ - libarchive/libarchive.3 \ - libarchive/libarchive_internals.3 \ - libarchive/libarchive-formats.5 \ - libarchive/mtree.5 \ - libarchive/tar.5 - -# Additional libarchive files to include in the distribution -libarchive_EXTRA_DIST= \ - libarchive/test/list.h \ - libarchive/archive_windows.c \ - libarchive/archive_windows.h \ - libarchive/filter_fork_windows.c \ - libarchive/CMakeLists.txt \ - $(libarchive_man_MANS) - -# -# -# libarchive_test program -# -# -libarchive_test_SOURCES= \ - $(libarchive_la_SOURCES) \ - libarchive/test/main.c \ - libarchive/test/read_open_memory.c \ - libarchive/test/test.h \ - libarchive/test/test_acl_basic.c \ - libarchive/test/test_acl_freebsd.c \ - libarchive/test/test_acl_pax.c \ - libarchive/test/test_archive_api_feature.c \ - libarchive/test/test_bad_fd.c \ - libarchive/test/test_compat_bzip2.c \ - libarchive/test/test_compat_gtar.c \ - libarchive/test/test_compat_gzip.c \ - libarchive/test/test_compat_solaris_tar_acl.c \ - libarchive/test/test_compat_tar_hardlink.c \ - libarchive/test/test_compat_xz.c \ - libarchive/test/test_compat_zip.c \ - libarchive/test/test_empty_write.c \ - libarchive/test/test_entry.c \ - libarchive/test/test_extattr_freebsd.c \ - libarchive/test/test_fuzz.c \ - libarchive/test/test_entry_strmode.c \ - libarchive/test/test_link_resolver.c \ - libarchive/test/test_open_fd.c \ - libarchive/test/test_open_file.c \ - libarchive/test/test_open_filename.c \ - libarchive/test/test_pax_filename_encoding.c \ - libarchive/test/test_read_compress_program.c \ - libarchive/test/test_read_data_large.c \ - libarchive/test/test_read_disk.c \ - libarchive/test/test_read_disk_entry_from_file.c \ - libarchive/test/test_read_extract.c \ - libarchive/test/test_read_file_nonexistent.c \ - libarchive/test/test_read_format_ar.c \ - libarchive/test/test_read_format_cpio_bin.c \ - libarchive/test/test_read_format_cpio_bin_Z.c \ - libarchive/test/test_read_format_cpio_bin_be.c \ - libarchive/test/test_read_format_cpio_bin_bz2.c \ - libarchive/test/test_read_format_cpio_bin_gz.c \ - libarchive/test/test_read_format_cpio_bin_xz.c \ - libarchive/test/test_read_format_cpio_odc.c \ - libarchive/test/test_read_format_cpio_svr4_gzip.c \ - libarchive/test/test_read_format_cpio_svr4c_Z.c \ - libarchive/test/test_read_format_empty.c \ - libarchive/test/test_read_format_gtar_gz.c \ - libarchive/test/test_read_format_gtar_lzma.c \ - libarchive/test/test_read_format_gtar_sparse.c \ - libarchive/test/test_read_format_iso_gz.c \ - libarchive/test/test_read_format_isojoliet_bz2.c \ - libarchive/test/test_read_format_isojoliet_long.c \ - libarchive/test/test_read_format_isojoliet_rr.c \ - libarchive/test/test_read_format_isorr_bz2.c \ - libarchive/test/test_read_format_isorr_new_bz2.c \ - libarchive/test/test_read_format_isozisofs_bz2.c \ - libarchive/test/test_read_format_mtree.c \ - libarchive/test/test_read_format_pax_bz2.c \ - libarchive/test/test_read_format_raw.c \ - libarchive/test/test_read_format_tar.c \ - libarchive/test/test_read_format_tar_empty_filename.c \ - libarchive/test/test_read_format_tbz.c \ - libarchive/test/test_read_format_tgz.c \ - libarchive/test/test_read_format_txz.c \ - libarchive/test/test_read_format_tz.c \ - libarchive/test/test_read_format_zip.c \ - libarchive/test/test_read_large.c \ - libarchive/test/test_read_pax_truncated.c \ - libarchive/test/test_read_position.c \ - libarchive/test/test_read_truncated.c \ - libarchive/test/test_tar_filenames.c \ - libarchive/test/test_tar_large.c \ - libarchive/test/test_ustar_filenames.c \ - libarchive/test/test_write_compress.c \ - libarchive/test/test_write_compress_bzip2.c \ - libarchive/test/test_write_compress_gzip.c \ - libarchive/test/test_write_compress_lzma.c \ - libarchive/test/test_write_compress_program.c \ - libarchive/test/test_write_compress_xz.c \ - libarchive/test/test_write_disk.c \ - libarchive/test/test_write_disk_failures.c \ - libarchive/test/test_write_disk_hardlink.c \ - libarchive/test/test_write_disk_perms.c \ - libarchive/test/test_write_disk_secure.c \ - libarchive/test/test_write_disk_sparse.c \ - libarchive/test/test_write_disk_symlink.c \ - libarchive/test/test_write_disk_times.c \ - libarchive/test/test_write_format_ar.c \ - libarchive/test/test_write_format_cpio.c \ - libarchive/test/test_write_format_cpio_empty.c \ - libarchive/test/test_write_format_cpio_odc.c \ - libarchive/test/test_write_format_cpio_newc.c \ - libarchive/test/test_write_format_mtree.c \ - libarchive/test/test_write_format_pax.c \ - libarchive/test/test_write_format_shar_empty.c \ - libarchive/test/test_write_format_tar.c \ - libarchive/test/test_write_format_tar_empty.c \ - libarchive/test/test_write_format_tar_ustar.c \ - libarchive/test/test_write_format_zip.c \ - libarchive/test/test_write_format_zip_empty.c \ - libarchive/test/test_write_format_zip_no_compression.c \ - libarchive/test/test_write_open_memory.c - -libarchive_test_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_builddir)/libarchive/test -DLIBARCHIVE_STATIC $(PLATFORMCPPFLAGS) - -# The "list.h" file just lists all of the tests defined in all of the sources. -# Building it automatically provides a sanity-check on libarchive_test_SOURCES -# above. -libarchive/test/list.h: Makefile - cat $(top_srcdir)/libarchive/test/test_*.c | grep DEFINE_TEST > libarchive/test/list.h - -libarchive_TESTS_ENVIRONMENT= LIBARCHIVE_TEST_FILES=`cd $(top_srcdir);/bin/pwd`/libarchive/test - -libarchive_test_EXTRA_DIST=\ - libarchive/test/test_compat_bzip2_1.tbz.uu \ - libarchive/test/test_compat_bzip2_2.tbz.uu \ - libarchive/test/test_compat_gtar_1.tar.uu \ - libarchive/test/test_compat_gzip_1.tgz.uu \ - libarchive/test/test_compat_gzip_2.tgz.uu \ - libarchive/test/test_compat_solaris_tar_acl.tar.uu \ - libarchive/test/test_compat_tar_hardlink_1.tar.uu \ - libarchive/test/test_compat_xz_1.txz.uu \ - libarchive/test/test_compat_zip_1.zip.uu \ - libarchive/test/test_fuzz_1.iso.uu \ - libarchive/test/test_pax_filename_encoding.tar.uu \ - libarchive/test/test_read_format_cpio_bin_be.cpio.uu \ - libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu \ - libarchive/test/test_read_format_gtar_sparse_1_17.tar.uu \ - libarchive/test/test_read_format_gtar_sparse_1_17_posix00.tar.uu \ - libarchive/test/test_read_format_gtar_sparse_1_17_posix01.tar.uu \ - libarchive/test/test_read_format_gtar_sparse_1_17_posix10.tar.uu \ - libarchive/test/test_read_format_gtar_sparse_1_17_posix10_modified.tar.uu \ - libarchive/test/test_read_format_iso_gz.iso.gz.uu \ - libarchive/test/test_read_format_isojoliet_bz2.iso.bz2.uu \ - libarchive/test/test_read_format_isojoliet_long.iso.bz2.uu \ - libarchive/test/test_read_format_isojoliet_rr.iso.bz2.uu \ - libarchive/test/test_read_format_isorr_bz2.iso.bz2.uu \ - libarchive/test/test_read_format_isorr_new_bz2.iso.bz2.uu \ - libarchive/test/test_read_format_isozisofs_bz2.iso.bz2.uu \ - libarchive/test/test_read_format_raw.data.Z.uu \ - libarchive/test/test_read_format_raw.data.uu \ - libarchive/test/test_read_format_iso_gz.iso.gz.uu \ - libarchive/test/test_read_format_tar_empty_filename.tar.uu \ - libarchive/test/test_read_format_zip.zip.uu \ - libarchive/test/CMakeLists.txt \ - libarchive/test/README - -# -# Common code for libarchive frontends (cpio, tar) -# -libarchive_fe_la_SOURCES= \ - libarchive_fe/err.c \ - libarchive_fe/err.h \ - libarchive_fe/lafe_platform.h \ - libarchive_fe/line_reader.c \ - libarchive_fe/line_reader.h \ - libarchive_fe/matching.c \ - libarchive_fe/matching.h \ - libarchive_fe/pathmatch.c \ - libarchive_fe/pathmatch.h - -# -# -# bsdtar source, docs, etc. -# -# - -bsdtar_SOURCES= \ - tar/bsdtar.c \ - tar/bsdtar.h \ - tar/bsdtar_platform.h \ - tar/cmdline.c \ - tar/getdate.c \ - tar/read.c \ - tar/subst.c \ - tar/tree.c \ - tar/tree.h \ - tar/util.c \ - tar/write.c - -if INC_WINDOWS_FILES -bsdtar_SOURCES+= \ - tar/bsdtar_windows.h \ - tar/bsdtar_windows.c -endif - -bsdtar_DEPENDENCIES= libarchive.la libarchive_fe.la - -if STATIC_BSDTAR -bsdtar_ldstatic= -static -bsdtar_ccstatic= -DLIBARCHIVE_STATIC -else -bsdtar_ldstatic= -bsdtar_ccstatic= -endif - -bsdtar_LDADD= libarchive.la libarchive_fe.la -bsdtar_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe $(bsdtar_ccstatic) $(PLATFORMCPPFLAGS) -bsdtar_LDFLAGS= $(bsdtar_ldstatic) - -bsdtar_EXTRA_DIST= \ - tar/bsdtar.1 \ - tar/bsdtar_windows.h \ - tar/bsdtar_windows.c \ - tar/CMakeLists.txt \ - tar/config_freebsd.h \ - tar/test/list.h - - -if BUILD_BSDTAR -bsdtar_man_MANS= tar/bsdtar.1 -bsdtar_programs= bsdtar -else -bsdtar_man_MANS= -bsdtar_programs= -endif - -# -# bsdtar_test -# - -bsdtar_test_SOURCES= \ - tar/getdate.c \ - tar/test/main.c \ - tar/test/test.h \ - tar/test/test_0.c \ - tar/test/test_basic.c \ - tar/test/test_copy.c \ - tar/test/test_getdate.c \ - tar/test/test_help.c \ - tar/test/test_option_T_upper.c \ - tar/test/test_option_q.c \ - tar/test/test_option_r.c \ - tar/test/test_option_s.c \ - tar/test/test_patterns.c \ - tar/test/test_stdio.c \ - tar/test/test_strip_components.c \ - tar/test/test_symlink_dir.c \ - tar/test/test_version.c \ - tar/test/test_windows.c - -# For now, bsdtar_test uses Windows shims from tar/bsdtar_windows.* -if INC_WINDOWS_FILES -bsdtar_test_SOURCES+= \ - tar/bsdtar_windows.h \ - tar/bsdtar_windows.c -endif - -bsdtar_test_CPPFLAGS=\ - -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe \ - -I$(top_srcdir)/tar -I$(top_builddir)/tar/test \ - $(PLATFORMCPPFLAGS) - -tar/test/list.h: Makefile - cat $(top_srcdir)/tar/test/test_*.c | grep DEFINE_TEST > tar/test/list.h - -if BUILD_BSDTAR -bsdtar_test_programs= bsdtar_test -bsdtar_TESTS_ENVIRONMENT= BSDTAR=`cd $(top_builddir);/bin/pwd`/bsdtar$(EXEEXT) BSDTAR_TEST_FILES=`cd $(top_srcdir);/bin/pwd`/tar/test -else -bsdtar_test_programs= -bsdtar_TESTS_ENVIRONMENT= -endif - -bsdtar_test_EXTRA_DIST= \ - tar/test/test_patterns_2.tar.uu \ - tar/test/test_patterns_3.tar.uu \ - tar/test/test_patterns_4.tar.uu \ - tar/test/CMakeLists.txt - - -# -# -# bsdcpio source, docs, etc. -# -# - -bsdcpio_SOURCES= \ - cpio/cmdline.c \ - cpio/cpio.c \ - cpio/cpio.h \ - cpio/cpio_platform.h - -if INC_WINDOWS_FILES -bsdcpio_SOURCES+= \ - cpio/cpio_windows.h \ - cpio/cpio_windows.c -endif - -bsdcpio_DEPENDENCIES = libarchive.la libarchive_fe.la - - -if STATIC_BSDCPIO -bsdcpio_ldstatic= -static -bsdcpio_ccstatic= -DLIBARCHIVE_STATIC -else -bsdcpio_ldstatic= -bsdcpio_ccstatic= -endif - -bsdcpio_LDADD= libarchive_fe.la libarchive.la -bsdcpio_CPPFLAGS= -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe $(bsdcpio_ccstatic) $(PLATFORMCPPFLAGS) -bsdcpio_LDFLAGS= $(bsdcpio_ldstatic) - -bsdcpio_EXTRA_DIST= \ - cpio/test/list.h \ - cpio/bsdcpio.1 \ - cpio/cpio_windows.h \ - cpio/cpio_windows.c \ - cpio/CMakeLists.txt \ - cpio/config_freebsd.h - - -if BUILD_BSDCPIO -# Manpages to install -bsdcpio_man_MANS= cpio/bsdcpio.1 -bsdcpio_programs= bsdcpio -else -bsdcpio_man_MANS= -bsdcpio_programs= -endif - -# -# bsdcpio_test -# - -bsdcpio_test_SOURCES= \ - cpio/cmdline.c \ - cpio/test/main.c \ - cpio/test/test.h \ - cpio/test/test_0.c \ - cpio/test/test_basic.c \ - cpio/test/test_cmdline.c \ - cpio/test/test_format_newc.c \ - cpio/test/test_gcpio_compat.c \ - cpio/test/test_option_B_upper.c \ - cpio/test/test_option_C_upper.c \ - cpio/test/test_option_J_upper.c \ - cpio/test/test_option_L_upper.c \ - cpio/test/test_option_Z_upper.c \ - cpio/test/test_option_a.c \ - cpio/test/test_option_c.c \ - cpio/test/test_option_d.c \ - cpio/test/test_option_f.c \ - cpio/test/test_option_help.c \ - cpio/test/test_option_l.c \ - cpio/test/test_option_lzma.c \ - cpio/test/test_option_m.c \ - cpio/test/test_option_t.c \ - cpio/test/test_option_u.c \ - cpio/test/test_option_version.c \ - cpio/test/test_option_y.c \ - cpio/test/test_option_z.c \ - cpio/test/test_owner_parse.c \ - cpio/test/test_passthrough_dotdot.c \ - cpio/test/test_passthrough_reverse.c \ - cpio/test/test_pathmatch.c - -bsdcpio_test_CPPFLAGS= \ - -I$(top_srcdir)/libarchive -I$(top_srcdir)/libarchive_fe \ - -I$(top_srcdir)/cpio -I$(top_builddir)/cpio/test \ - $(PLATFORMCPPFLAGS) -bsdcpio_test_LDADD=libarchive_fe.la - -cpio/test/list.h: Makefile - cat $(top_srcdir)/cpio/test/test_*.c | grep DEFINE_TEST > cpio/test/list.h - -if BUILD_BSDCPIO -bsdcpio_test_programs= bsdcpio_test -bsdcpio_TESTS_ENVIRONMENT= BSDCPIO=`cd $(top_builddir);/bin/pwd`/bsdcpio$(EXEEXT) BSDCPIO_TEST_FILES=`cd $(top_srcdir);/bin/pwd`/cpio/test -else -bsdcpio_test_programs= -bsdcpio_TESTS_ENVIRONMENT= -endif - -bsdcpio_test_EXTRA_DIST= \ - cpio/test/test_gcpio_compat_ref.bin.uu \ - cpio/test/test_gcpio_compat_ref.crc.uu \ - cpio/test/test_gcpio_compat_ref.newc.uu \ - cpio/test/test_gcpio_compat_ref.ustar.uu \ - cpio/test/test_option_f.cpio.uu \ - cpio/test/test_option_m.cpio.uu \ - cpio/test/test_option_t.cpio.uu \ - cpio/test/test_option_t.stdout.uu \ - cpio/test/test_option_tv.stdout.uu \ - cpio/test/CMakeLists.txt diff --git a/Utilities/cmlibarchive/NEWS b/Utilities/cmlibarchive/NEWS deleted file mode 100644 index 9c8f46d48..000000000 --- a/Utilities/cmlibarchive/NEWS +++ /dev/null @@ -1,499 +0,0 @@ - -Apr 01, 2009: libarchive 2.6.990a released -Apr 01, 2009: Use command-line gunzip, bunzip2, unxz, unlzma for - decompression if the library is built without suitable - libraries. The setup functions return ARCHIVE_WARN - in this case so clients can adapt if necessary. -Apr 01, 2009: Use getpw*_r and getgr*_r functions for thread-safety. -Mar 24, 2009: Add archive_read_next_header2(), which is up to 25% - more efficient for some clients; from Brian Harring. -Mar 22, 2009: PDF versions of manpages are now included in the distribution. -Mar, 2009: Major work to improve Cygwin build by Charles Wilson. -Feb/Mar, 2009: Major work on cmake build support, mostly by Michihiro NAKAJIMA. -Feb/Mar, 2009: Major work on Visual Studio support by Michihiro NAKAJIMA. - All tests now pass. -Feb 25, 2009: Fix Debian Bug #516577 -Feb 21, 2009: Yacc is no longer needed to build; date parser rewritten in C. -Jan/Feb, 2009: Mtree work by Michihiro. -Feb, 2009: Joliet support by Andreas Henriksson. -Jan/Feb, 2009: New options framework by Michihiro. -Feb, 2009: High-res timestamps on Tru64, AIX, and GNU Hurd, by Björn Jacke. -Jan 18, 2009: Extended attributes work on FreeBSD and Linux now with pax format. -Jan 07, 2009: New archive_read_disk_entry_from_file() knows about ACLs, - extended attributes, etc so that bsdtar and bsdcpio don't require - such system-specific knowledge. -Jan 03, 2009: Read filter system extensively refactored. In particular, - read filter pipelines are now built out automatically and individual - filters should be much easier to implement. Documentation on the - Googlecode Wiki explains how to implement new filters. -Dec 28, 2008: Many Windows/Visual Studio fixes from Michihiro NAKAJIMA. - -Dec 28, 2008: Main libarchive development moved from FreeBSD Perforce - server to Google Code. This should make it easier for more - people to participate in libarchive development. - -Dec 28, 2008: libarchive 2.6.0 released -Dec 25, 2008: libarchive 2.5.905a released -Dec 10, 2008: libarchive 2.5.904a released -Dec 04, 2008: libarchive 2.5.903a released -Nov 09, 2008: libarchive 2.5.902a released -Nov 08, 2008: libarchive 2.5.901a released -Nov 08, 2008: Start of pre-release testing for libarchive 2.6 - -Nov 07, 2008: Read filter refactor: The decompression routines just - consume and produce arbitrarily-sized blocks. The reblocking - from read_support_compression_none() has been pulled into the - read core. Also, the decompression bid now makes multiple - passes and stacks read filters. -Oct 21, 2008: bsdcpio: New command-line parser. -Oct 19, 2008: Internal read_ahead change: short reads are now an error -Oct 06, 2008: bsdtar: option parser no longer uses getopt_long(), - gives consistent option parsing on all platforms. -Sep 19, 2008: Jaakko Heinonen: shar utility built on libarchive -Sep 17, 2008: Pedro Giffuni: birthtime support -Sep 17, 2008: Miklos Vajna: lzma reader and test. Note: I still have - some concerns about the auto-detection (LZMA file format - doesn't support auto-detection well), so this is not yet - enabled under archive_read_support_compression_all(). For - now, you must call archive_read_support_compression_lzma() if - you want LZMA read support. -Sep 11, 2008: Ivailo Petrov: Many fixes to Windows build, new solution files -Jul 26, 2008: archive_entry now tracks which values have not been set. - This helps zip extraction (file size is often "unknown") and - time restores (tar usually doesn't know atime). -Jul 26, 2008: Joerg Sonnenberger: Performance improvements to shar writer -Jul 25, 2008: Joerg Sonnenberger: mtree write support - -Jul 02, 2008: libarchive 2.5.5 released - -Jul 02, 2008: libarchive 2.5.5b released -Jul 01, 2008: bsdcpio is being used by enough people, we can call it 1.0.0 now -Jun 20, 2008: bsdcpio: If a -l link fails with EXDEV, copy the file instead -Jun 19, 2008: bsdcpio: additional long options for better GNU cpio compat -Jun 15, 2008: Many small portability and bugfixes since 2.5.4b. - -May 25, 2008: libarchive 2.5.4b released -May 21, 2008: Joerg Sonnenberger: fix bsdtar hardlink handling for newc format - -May 21, 2008: More progress on Windows building. Thanks to "Scott" - for the Windows makefiles, thanks to Kees Zeelenberg for - code contributions. - -May 21, 2008: Fix a number of non-exploitable integer and buffer overflows, - thanks to David Remahl at Apple for pointing these out. - -May 21, 2008: Colin Percival: SIGINFO or SIGUSR1 to bsdtar prints progress info - -May 16, 2008: bsdtar's test harness no longer depends on file ordering. - This was causing spurious test failures on a lot of systems. - Thanks to Bernhard R. Link for the diagnosis. - -May 14, 2008: Joerg Sonnenberger: -s substitution support for bsdtar - -May 13, 2008: Joerg Sonnenberger: Many mtree improvements - -May 11, 2008: Joerg Sonnenberger: fix hardlink extraction when - hardlinks have different permissions from original file - -April 30, 2008: Primary libarchive work has been moved into the FreeBSD - project's Perforce repository: http://perforce.freebsd.org/ - The libarchive project can be browsed at - //depot/user/kientzle/libarchive-portable - Direct link: http://preview.tinyurl.com/46mdgr - -May 04, 2008: libarchive 2.5.3b released - * libarchive: Several fixes to link resolver to address bsdcpio crashes - * bsdcpio: -p hardlink handling fixes - * tar/pax: Ensure ustar dirnames end in '/'; be more careful about - measuring filenames when deciding what pathname fields to use - * libarchive: Mark which entry strings are set; be accurate about - distinguishing empty strings ("") from unset ones (NULL) - * tar: Don't crash reading entries with empty filenames - * libarchive_test, bsdtar_test, bsdcpio_test: Better detaults: - run all tests, delete temp dirs, summarize repeated failures - * -no-undefined to libtool for Cygwin - * libarchive_test: Skip large file tests on systems with 32-bit off_t - * iso9660: Don't bother trying to find the body of an empty file; - this works around strange behavior from some ISO9660 writers - * tar: allow -r -T to be used together - * tar: allow --format with -r or -u - * libarchive: Don't build archive.h - -May 04, 2008: Simplified building: archive.h is no longer constructed - This may require additional #if conditionals on some platforms. - -Mar 30, 2008: libarchive 2.5.1b released - -Mar 15, 2008: libarchive 2.5.0b released -Mar 15, 2008: bsdcpio now seems to correctly write hardlinks into newc, - ustar, and old cpio archives. Just a little more testing before - bsdcpio 1.0 becomes a reality. -Mar 15, 2008: I think the new linkify() interface is finally handling - all known hardlink strategies. -Mar 15, 2008: Mtree read fixes from Joerg Sonnenberger. -Mar 15, 2008: Many new bsdtar and bsdcpio options from Joerg Sonnenberger. -Mar 15, 2008: test harnesses no longer require uudecode; they - now have built-in decoding logic that decodes the reference - files as they are needed. - -Mar 14, 2008: libarchive 2.4.14 released; identical to 2.4.13 except for - a point fix for gname/uname mixup in pax format that was introduced - with the UTF-8 fixes. - -Feb 26, 2008: libarchive 2.4.13 released -Feb 25, 2008: Handle path, linkname, gname, or uname that can't be converted - to/from UTF-8. Implement "hdrcharset" attribute from SUS-2008. -Feb 25, 2008: Fix name clash on NetBSD. -Feb 18, 2008: Fix writing empty 'ar' archives, per Kai Wang -Feb 18, 2008: [bsdtar] Permit appending on block devices. -Feb 09, 2008: New "linkify" resolver to help with newc hardlink writing; - bsdcpio still needs to be converted to use this. -Feb 02, 2008: Windows compatibility fixes from Ivailo Petrov, Kees Zeelenberg -Jan 30, 2008: Ignore hardlink size for non-POSIX tar archives. - -Jan 22, 2008: libarchive 2.4.12 released -Jan 22, 2008: Fix bad padding when writing symlinks to newc cpio archives. -Jan 22, 2008: Verify bsdcpio_test by getting it to work against GNU cpio 2.9. - bsdcpio_test complains about missing options (-y and -z), format - of informational messages (--version, --help), and a minor formatting - issue in odc format output. After this update, bsdcpio_test uncovered - several more cosmetic issues in bsdcpio, all now fixed. -Jan 22, 2008: Experimental support for self-extracting Zip archives. -Jan 22, 2008: Extend hardlink restore strategy to work correctly with - hardlinks extracted from newc cpio files. (Which store the body - only with the last occurrence of a link.) - -Dec 30, 2007: libarchive 2.4.11 released -Dec 30, 2007: Fixed a compile error in bsdcpio on some systems. - -Dec 29, 2007: libarchive 2.4.10 released -Dec 29, 2007: bsdcpio 0.9.0 is ready for wider use. -Dec 29, 2007: Completed initial test harness for bsdcpio. - -Dec 22, 2007: libarchive 2.4.9 released -Dec 22, 2007: Implement the remaining options for bsdcpio: -a, -q, -L, -f, - pattern selection for -i and -it. - -Dec 13, 2007: libarchive 2.4.8 released -Dec 13, 2007: gzip and bzip2 compression now handle zero-byte writes correctly, - Thanks to Damien Golding for bringing this to my attention. - -Dec 12, 2007: libarchive 2.4.7 released - -Dec 10, 2007: libarchive 2.4.6 released -Dec 09, 2007: tar/test/test_copy.c verifies "tar -c | tar -x" copy pipeline -Dec 07, 2007: Fix a couple of minor memory leaks. - -Dec 04, 2007: libarchive 2.4.5 released -Dec 04, 2007: Fix cpio/test/test_write_odc by setting the umask first. - -Dec 03, 2007: libarchive 2.4.4 released -Dec 03, 2007: New configure options --disable-xattr and --disable-acl, - thanks to Samuli Suominen. - -Dec 03, 2007: libarchive 2.4.3 released -Dec 03, 2007: Thanks to Lapo Luchini for sending me a ZIP file that - libarchive couldn't handle. Fixed a bug in handling of - "length at end" flags in ZIP files. -Dec 03, 2007: Fixed bsdcpio -help, bsdtar -help tests. -Dec 02, 2007: First cut at real bsdtar test harness. - -Dec 02, 2007: libarchive 2.4.2 released - -Dec 02, 2007: libarchive 2.4.1 released -Dec 02, 2007: Minor fixes, rough cut of mdoc-to-man conversion for - man pages. - -Oct 30, 2007: libarchive 2.4.0 released -Oct 30, 2007: Minor compile fix thanks to Joerg Schilling. -Oct 30, 2007: Only run the format auction once at the beginning of the - archive. This is simpler and supports better error recovery. -Oct 29, 2007: Test support for very large entries in tar archives: - libarchive_test now exercises entries from 2GB up to 1TB. - -Oct 27, 2007: libarchive 2.3.5 released -Oct 27, 2007: Correct some unnecessary internal data copying in the - "compression none" reader and writer; this reduces user time - by up to 2/3 in some tests. (Thanks to Jan Psota for - publishing his performance test results to GNU tar's bug-tar - mailing list; those results pointed me towards this problem.) -Oct 27, 2007: Fix for skipping archive entries that are exactly - a multiple of 4G on 32-bit platforms. -Oct 25, 2007: Fix for reading very large (>8G) tar archives; this was - broken when I put in support for new GNU tar sparse formats. -Oct 20, 2007: Initial work on new pattern-matching code for cpio; I - hope this eventually replaces the code currently in bsdtar. - -Oct 08, 2007: libarchive 2.3.4 released -Oct 05, 2007: Continuing work on bsdcpio test suite. -Oct 05, 2007: New cpio.5 manpage, updates to "History" of bsdcpio.1 and - bsdtar.1 manpages. -Oct 05, 2007: Fix zip reader to immediately return EOF if you try - to read body of non-regular file. In particular, this fixes - bsdtar extraction of zip archives. - -Sep 30, 2007: libarchive 2.3.3 released -Sep 26, 2007: Rework Makefile.am so that the enable/disable options - actually do the right things. -Sep 26, 2007: cpio-odc and cpio-newc archives no longer write bodies - for non-regular files. -Sep 26, 2007: Test harness for bsdcpio is in place, needs more tests written. - This is much nicer than the ragtag collection of test scripts - that bsdtar has. - -Sep 20, 2007: libarchive 2.3.2 released -Sep 20, 2007: libarchive 2.3.1 broke bsdtar because the archive_write_data() - fix was implemented incorrectly. - -Sep 16, 2007: libarchive 2.3.1 released -Sep 16, 2007: Many fixes to bsdcpio 0.3: handle hardlinks with -p, recognize - block size on writing, fix a couple of segfaults. -Sep 16, 2007: Fixed return value from archive_write_data() when used - with archive_write_disk() to match the documentation and other - instances of this same function. -Sep 15, 2007: Add archive_entry_link_resolver, archive_entry_strmode - -Sep 11, 2007: libarchive 2.2.8 released -Sep 09, 2007: bsdcpio 0.2 supports most (not yet all) of the old POSIX spec. - -Sep 01, 2007: libarchive 2.2.7 released -Aug 31, 2007: Support for reading mtree files, including an mtree.5 manpage - (A little experimental still.) -Aug 18, 2007: Read gtar 1.17 --posix --sparse entries. -Aug 13, 2007: Refined suid/sgid restore handling; it is no longer - an error if suid/sgid bits are dropped when you request - perm restore but don't request owner restore. -Aug 06, 2007: Use --enable-bsdcpio if you want to try bsdcpio - -Aug 05, 2007: libarchive 2.2.6 released -Aug 05, 2007: New configure option --disable-bsdtar, thanks to Joerg - Sonnenberger. -Aug 05, 2007: Several bug fixes from FreeBSD CVS repo. - -Jul 13, 2007: libarchive 2.2.5 released - -Jul 12, 2007: libarchive 2.2.4 released -Jul 12, 2007: Thanks to Colin Percival's help in diagnosing and - fixing several critical security bugs. Details available at - http://security.freebsd.org/advisories/FreeBSD-SA-07:05.libarchive.asc - -May 26, 2007: libarchive 2.2.3 released -May 26, 2007: Fix memory leaks in ZIP reader and shar writer, add some - missing system headers to archive_entry.h, dead code cleanup - from Colin Percival, more tests for gzip/bzip2, fix an - EOF anomaly in bzip2 decompression. - -May 12, 2007: libarchive 2.2.2 released -May 12, 2007: Fix archive_write_disk permission restore by cloning - entry passed into write_header so that permission info is - still available at finish_entry time. (archive_read_extract() - worked okay because it held onto the passed-in entry, but - direct consumers of archive_write_disk would break). This - required fixing archive_entry_clone(), which now works and has - a reasonably complete test case. -May 10, 2007: Skeletal cpio implementation. - -May 06, 2007: libarchive 2.2.1 released -May 06, 2007: Flesh out a lot more of test_entry.c so as to catch - problems such as the device node breakage before releasing . -May 05, 2007: Fix a bad bug introduced in 2.1.9 that broke device - node entries in tar archives. -May 03, 2007: Move 'struct stat' out of archive_entry core as well. - This removes some portability headaches and fixes a bunch - of corner cases that arise when manipulating archives on - dissimilar systems. - -Apr 30, 2007: libarchive 2.1.10 released -Apr 31, 2007: Minor code cleanup. - -Apr 24, 2007: libarchive 2.1.9 released -Apr 24, 2007: Fix some recently-introduced problems with libraries - (Just let automake handle it and it all works much better.) - Finish isolating major()/minor()/makedev() in archive_entry.c. - -Apr 23, 2007: libarchive 2.1.8 released -Apr 23, 2007: Minor fixes found from building on MacOS X - -Apr 22, 2007: libarchive 2.1.7 released -Apr 22, 2007: Eliminated all uses of 'struct stat' from the - format readers/writers. This should improve portability; - 'struct stat' is now only used in archive_entry and in - code that actually touches the disk. - -Apr 17, 2007: libarchive 2.1.6 released - Libarchive now compiles and passes all tests on Interix. - -Apr 16, 2007: libarchive 2.1.5 released - -Apr 15, 2007: libarchive 2.1b2 released -Apr 15, 2007: New libarchive_internals.3 documentation of internal APIs. - Not complete, but should prove helpful. -Apr 15, 2007: Experimental "read_compress_program" and "write_compress_program" - for using libarchive with external compression. Not yet - well tested, and likely has portability issues. Feedback - appreciated. - -Apr 14, 2007: libarchive 2.0.31 released -Apr 14, 2007: More fixes for Interix, more 'ar' work - -Apr 14, 2007: libarchive 2.0.30 released -Apr 13, 2007: libarchive now enforces trailing '/' on dirs - written to tar archives - -Apr 11, 2007: libarchive 2.0.29 released -Apr 11, 2007: Make it easier to statically configure for different platforms. -Apr 11, 2007: Updated config.guess, config.sub, libtool - -Apr 06, 2007: libarchive 2.0.28 released -Apr 06, 2007: 'ar' format read/write support thanks to Kai Wang. - -Apr 01, 2007: libarchive 2.0.27 released -Mar 31, 2007: Several minor fixes from Colin Percival and Joerg Sonnenberger. - -Mar 12, 2007: libarchive 2.0.25 released -Mar 12, 2007: Fix broken --unlink flag. - -Mar 11, 2007: libarchive 2.0.24 released -Mar 10, 2007: Correct an ACL blunder that causes any ACL with an entry - that refers to a non-existent user or group to not be restored correctly. - The fix both makes the parser more tolerant (so that archives created - with the buggy ACLs can be read now) and corrects the ACL formatter. -Mar 10, 2007: More work on test portability to Linux. - -Mar 10, 2007: libarchive 2.0.22 released -Mar 10, 2007: Header cleanups; added linux/fs.h, removed - some unnecessary headers, added #include guards in bsdtar. - If you see any obvious compile failures from this, let me know. -Mar 10, 2007: Work on bsdtar test scripts: not yet robust enough - to enable as part of "make check", but getting better. -Mar 10, 2007: libarchive now returns ARCHIVE_FAILED when - a header write fails in a way that only affects this item. - Less bad than ARCHIVE_FATAL, but worse than ARCHIVE_WARN. - -Mar 07, 2007: libarchive 2.0.21 released -Mar 07, 2007: Add some ACL tests (only for the system-independent - portion of the ACL support for now). -Mar 07, 2007: tar's ability to read ACLs off disk got - turned off for FreeBSD; re-enable it. (ACL restores and - libarchive support for storing/reading ACLs from pax - archives was unaffected.) - -Mar 02, 2007: libarchive 2.0.20 released -Mar 2, 2007: It's not perfect, but it's pretty good. - Libarchive 2.0 is officially out of beta. - -Feb 28, 2007: libarchive 2.0b17 released -Feb 27, 2007: Make the GID restore checks more robust by checking - whether the current user has too few or too many privileges. - -Feb 26, 2007: libarchive 2.0b15 released -Feb 26, 2007: Don't lose symlinks when extracting from ISOs. - Thanks to Diego "Flameeyes" Pettenò for telling me about the - broken testcase on Gentoo that (finally!) led me to the cause - of this long-standing bug. - -Feb 26, 2007: libarchive 2.0b14 released -Feb 26, 2007: Fix a broken test on platforms that lack lchmod(). - -Feb 25, 2007: libarchive 2.0b13 released -Feb 25, 2007: Empty archives were being written as empty files, - without a proper end-of-archive marker. Fixed. - -Feb 23, 2007: libarchive 2.0b12 released -Feb 22, 2007: Basic security checks added: _EXTRACT_SECURE_NODOTDOT - and _EXTRACT_SECURE_SYMLINK. These checks used to be in bsdtar, - but they belong down in libarchive where they can be used by - other tools and where they can be better optimized. - -Feb 11, 2007: libarchive 2.0b11 released -Feb 10, 2007: Fixed a bunch of errors in libarchive's handling - of EXTRACT_PERM and EXTRACT_OWNER, especially relating - to SUID and SGID bits. - -Jan 31, 2007: libarchive 2.0b9 released -Jan 31, 2007: Added read support for "empty" archives as a - distinct archive format. Bsdtar uses this to handle, e.g., - "touch foo.tar; tar -rf foo.tar" - -Jan 22, 2007: libarchive 2.0b6 released -Jan 22, 2007: archive_write_disk API is now in place. It provides - a finer-grained interface than archive_read_extract. In particular, - you can use it to create objects on disk without having an archive - around (just feed it archive_entry objects describing what you - want to create), you can override the uname/gname-to-uid/gid lookups - (minitar uses this to avoid getpwXXX() and getgrXXX() bloat). - -Jan 09, 2007: libarchive 2.0a3 released -Jan 9, 2007: archive_extract is now much better; it handles the - most common cases with a minimal number of system calls. - Some features still need a lot of testing, especially corner - cases involving objects that already exist on disk. I expect - the next round of API overhaul will simplify building test cases. -Jan 9, 2007: a number of fixes thanks to Colin Percival, especially - corrections to the skip() framework and handling of large files. -Jan 9, 2007: Fixes for large ISOs. The code should correctly handle - very large ISOs with entries up to 4G. Thanks to Robert Sciuk - for pointing out these issues. - -Sep 05, 2006: libarchive 1.3.1 released -Sep 5, 2006: Bump version to 1.3 for new I/O wrappers. -Sep 4, 2006: New memory and FILE read/write wrappers. -Sep 4, 2006: libarchive test harness is now minimally functional; - it's located a few minor bugs in error-handling logic - -Aug 17, 2006: libarchive 1.2.54 released -Aug 17, 2006: Outline ABI changes for libarchive 2.0; these - are protected behind #ifdef's until I think I've found everything - that needs to change. -Aug 17, 2006: Fix error-handling in archive_read/write_close() - They weren't returning any errors before. -Aug 17, 2006: Fix recursive-add logic to not trigger if it's not set - Fixes a bug adding files when writing archive to pipe or when - using archive_write_open() directly. -Jul 2006: New "skip" handling improves performance extracting - single files from large uncompressed archives. - -Mar 21, 2006: 1.2.52 released -Mar 21, 2006: Fix -p on platforms that don't have platform-specific - extended attribute code. -Mar 20, 2006: Add NEWS file; fill in some older history from other - files. I'll try to keep this file up-to-date from now on. - -OLDER NEWS SUMMARIES - -Mar 19, 2006: libarchive 1.2.51 released -Mar 18, 2006: Many fixes to extended attribute support, including a redesign - of the storage format to simplify debugging. -Mar 12, 2006: Remove 'tp' support; it was a fun idea, but not worth - spending much time on. -Mar 11, 2006: Incorporated Jaakko Heinonen's still-experimental support - for extended attributes (Currently Linux-only.). -Mar 11, 2006: Reorganized distribution package: There is now one tar.gz - file that builds both libarchive and bsdtar. -Feb 13, 2006: Minor bug fixes: correctly read cpio device entries, write - Pax attribute entry names. -Nov 7, 2005: Experimental 'tp' format support in libarchive. Feedback - appreciated; this is not enabled by archive_read_support_format_all() - yet as I'm not quite content with the format detection heuristics. -Nov 7, 2005: Some more portability improvements thanks to Darin Broady, - minor bugfixes. -Oct 12, 2005: Use GNU libtool to build shared libraries on many systems. -Aug 9, 2005: Correctly detect that MacOS X does not have POSIX ACLs. -Apr 17, 2005: Kees Zeelenberg has ported libarchive and bsdtar to Windows: - http://gnuwin32.sourceforge.net/ -Apr 11, 2005: Extended Zip/Zip64 support thanks to Dan Nelson. -L/-h - fix from Jaakko Heinonen. -Mar 12, 2005: archive_read_extract can now handle very long - pathnames (I've tested with pathnames up to 1MB). -Mar 12, 2005: Marcus Geiger has written an article about libarchive - http://xsnil.antbear.org/2005/02/05/archive-mit-libarchive-verarbeiten/ - including examples of using it from Objective-C. His MoinX - http://moinx.antbear.org/ desktop Wiki uses - libarchive for archiving and restoring Wiki pages. -Jan 22, 2005: Preliminary ZIP extraction support, - new directory-walking code for bsdtar. -Jan 16, 2005: ISO9660 extraction code added; manpage corrections. -May 22, 2004: Many gtar-compatible long options have been added; almost - all FreeBSD ports extract correctly with bsdtar. -May 18, 2004: bsdtar can read Solaris, HP-UX, Unixware, star, gtar, - and pdtar archives. diff --git a/Utilities/cmlibarchive/README b/Utilities/cmlibarchive/README deleted file mode 100644 index cfbb7657e..000000000 --- a/Utilities/cmlibarchive/README +++ /dev/null @@ -1,137 +0,0 @@ -README for libarchive bundle. - -Questions? Issues? - * http://libarchive.googlecode.com/ is the home for ongoing - libarchive development, including issue tracker, additional - documentation, and links to the libarchive mailing lists. - -This distribution bundle includes the following components: - * libarchive: a library for reading and writing streaming archives - * tar: the 'bsdtar' program is a full-featured 'tar' - replacement built on libarchive - * cpio: the 'bsdcpio' program is a different interface to - essentially the same functionality - * examples: Some small example programs that you may find useful. - * examples/minitar: a compact sample demonstrating use of libarchive. - I use this for testing link pollution; it should produce a very - small executable file on most systems. - * contrib: Various items sent to me by third parties; - please contact the authors with any questions. - -The top-level directory contains the following information files: - * NEWS - highlights of recent changes - * COPYING - what you can do with this - * INSTALL - installation instructions - * README - this file - * configure - configuration script, see INSTALL for details. - * CMakeLists.txt - input for "cmake" build tool, see INSTALL - -The following files in the top-level directory are used by the -'configure' script: - * Makefile.am, aclocal.m4, configure.ac - - used to build this distribution, only needed by maintainers - * Makefile.in, config.h.in - - templates used by configure script - -Guide to Documentation installed by this system: - * bsdtar.1 explains the use of the bsdtar program - * bsdcpio.1 explains the use of the bsdcpio program - * libarchive.3 gives an overview of the library as a whole - * archive_read.3, archive_write.3, archive_write_disk.3, and - archive_read_disk.3 provide detailed calling sequences for the read - and write APIs - * archive_entry.3 details the "struct archive_entry" utility class - * archive_internals.3 provides some insight into libarchive's - internal structure and operation. - * libarchive-formats.5 documents the file formats supported by the library - * cpio.5, mtree.5, and tar.5 provide detailed information about these - popular archive formats, including hard-to-find details about - modern cpio and tar variants. -The manual pages above are provided in the 'doc' directory in -a number of different formats. - -You should also read the copious comments in "archive.h" and the -source code for the sample programs for more details. Please let me -know about any errors or omissions you find. - -Currently, the library automatically detects and reads the following: - * gzip compression - * bzip2 compression - * compress/LZW compression - * lzma and xz compression - * GNU tar format (including GNU long filenames, long link names, and - sparse files) - * Solaris 9 extended tar format (including ACLs) - * Old V7 tar archives - * POSIX ustar - * POSIX pax interchange format - * POSIX octet-oriented cpio - * SVR4 ASCII cpio - * POSIX octet-oriented cpio - * Binary cpio (big-endian or little-endian) - * ISO9660 CD-ROM images (with optional Rockridge or Joliet extensions) - * ZIP archives (with uncompressed or "deflate" compressed entries) - * GNU and BSD 'ar' archives - * 'mtree' format - -The library can write: - * gzip compression - * bzip2 compression - * compress/LZW compression - * lzma and xz compression - * POSIX ustar - * POSIX pax interchange format - * "restricted" pax format, which will create ustar archives except for - entries that require pax extensions (for long filenames, ACLs, etc). - * POSIX octet-oriented cpio - * SVR4 "newc" cpio - * shar archives - * ZIP archives (with uncompressed or "deflate" compressed entries) - * GNU and BSD 'ar' archives - * 'mtree' format - -Notes about the library architecture: - - * This is a heavily stream-oriented system. There is no direct - support for in-place modification or random access. - - * The library is designed to be extended with new compression and - archive formats. The only requirement is that the format be - readable or writable as a stream and that each archive entry be - independent. There are articles on the libarchive Wiki explaining - how to extend libarchive. - - * On read, compression and format are always detected automatically. - - * I've attempted to minimize static link pollution. If you don't - explicitly invoke a particular feature (such as support for a - particular compression or format), it won't get pulled in. - In particular, if you don't explicitly enable a particular - compression or decompression support, you won't need to link - against the corresponding compression or decompression libraries. - This also reduces the size of statically-linked binaries in - environments where that matters. - - * On read, the library accepts whatever blocks you hand it. - Your read callback is free to pass the library a byte at a time - or mmap the entire archive and give it to the library at once. - On write, the library always produces correctly-blocked output. - - * The object-style approach allows you to have multiple archive streams - open at once. bsdtar uses this in its "@archive" extension. - - * The archive itself is read/written using callback functions. - You can read an archive directly from an in-memory buffer or - write it to a socket, if you wish. There are some utility - functions to provide easy-to-use "open file," etc, capabilities. - - * The read/write APIs are designed to allow individual entries - to be read or written to any data source: You can create - a block of data in memory and add it to a tar archive without - first writing a temporary file. You can also read an entry from - an archive and write the data directly to a socket. If you want - to read/write entries to disk, there are convenience functions to - make this especially easy. - - * Note: "pax interchange format" is really an extended tar format, - despite what the name says. diff --git a/Utilities/cmlibarchive/README-CMake.txt b/Utilities/cmlibarchive/README-CMake.txt new file mode 100644 index 000000000..45cb0939e --- /dev/null +++ b/Utilities/cmlibarchive/README-CMake.txt @@ -0,0 +1,66 @@ +The Utilities/cmlibarchive directory contains a reduced distribution +of the libarchive source tree with only the library source code and +CMake build system. It is not a submodule; the actual content is part +of our source tree and changes can be made and committed directly. + +We update from upstream using Git's "subtree" merge strategy. A +special branch contains commits of upstream libarchive snapshots and +nothing else. No Git ref points explicitly to the head of this +branch, but it is merged into our history. + +Update libarchive from upstream as follows. Create a local branch to +explicitly reference the upstream snapshot branch head: + + git branch libarchive-upstream 4f4fe6e5 + +Use a temporary directory to checkout the branch: + + mkdir libarchive-tmp + cd libarchive-tmp + git init + git pull .. libarchive-upstream + rm -rf * + +Now place the (reduced) libarchive content in this directory. See +instructions shown by + + git log 4f4fe6e5 + +for help extracting the content from the upstream svn repo. Then run +the following commands to commit the new version. Substitute the +appropriate date and version number: + + git add --all + + GIT_AUTHOR_NAME='LibArchive Upstream' \ + GIT_AUTHOR_EMAIL='libarchive-discuss@googlegroups.com' \ + GIT_AUTHOR_DATE='2011-12-31 13:54:34 -0500' \ + git commit -m 'libarchive 3.0.2-r4051 (reduced)' && + git commit --amend + +Edit the commit message to describe the procedure used to obtain the +content. Then push the changes back up to the main local repository: + + git push .. HEAD:libarchive-upstream + cd .. + rm -rf libarchive-tmp + +Create a topic in the main repository on which to perform the update: + + git checkout -b update-libarchive master + +Merge the libarchive-upstream branch as a subtree: + + git merge -s recursive -X subtree=Utilities/cmlibarchive \ + libarchive-upstream + +If there are conflicts, resolve them and commit. Build and test the +tree. Commit any additional changes needed to succeed. + +Finally, run + + git rev-parse --short=8 libarchive-upstream + +to get the commit from which the libarchive-upstream branch must be started +on the next update. Edit the "git branch libarchive-upstream" line above to +record it, and commit this file. diff --git a/Utilities/cmlibarchive/build/autoconf/check_stdcall_func.m4 b/Utilities/cmlibarchive/build/autoconf/check_stdcall_func.m4 deleted file mode 100644 index 926b046c5..000000000 --- a/Utilities/cmlibarchive/build/autoconf/check_stdcall_func.m4 +++ /dev/null @@ -1,51 +0,0 @@ -# AC_LANG_STDCALL_FUNC_LINK_TRY(FUNCTION, SIGNATURE) -# ------------------------------- -# Produce a source which links correctly iff the FUNCTION exists. -AC_DEFUN([AC_LANG_STDCALL_FUNC_LINK_TRY], -[_AC_LANG_DISPATCH([$0], _AC_LANG, $@)]) - -# AC_CHECK_STDCALL_FUNC(FUNCTION, SIGNATURE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -# ----------------------------------------------------------------- -AC_DEFUN([AC_CHECK_STDCALL_FUNC], -[AS_VAR_PUSHDEF([ac_var], [ac_cv_func_$1])dnl -AC_CACHE_CHECK([for $1], ac_var, -[AC_LINK_IFELSE([AC_LANG_STDCALL_FUNC_LINK_TRY([$1],[$2])], - [AS_VAR_SET(ac_var, yes)], - [AS_VAR_SET(ac_var, no)])]) -AS_IF([test AS_VAR_GET(ac_var) = yes], [$3], [$4])dnl -AS_VAR_POPDEF([ac_var])dnl -])# AC_CHECK_FUNC - -# AC_LANG_STDCALL_FUNC_LINK_TRY(C)(FUNCTION, SIGNATURE) -# ---------------------------------- -# Don't include because on OSF/1 3.0 it includes -# which includes which contains a -# prototype for select. Similarly for bzero. -m4_define([AC_LANG_STDCALL_FUNC_LINK_TRY(C)], -[AC_LANG_PROGRAM( -[/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char __stdcall $1 ( $2 ) below. */ -#include -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char __stdcall $1 ( $2 ); -char (*f) ( $2 ); -], -[/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$1) || defined (__stub___$1) -choke me -#else -f = $1; -#endif -])]) - -# AC_LANG_STDCALL_FUNC_LINK_TRY(C++)(FUNCTION) -# ------------------------------------ -m4_copy([AC_LANG_STDCALL_FUNC_LINK_TRY(C)], [AC_LANG_STDCALL_FUNC_LINK_TRY(C++)]) - diff --git a/Utilities/cmlibarchive/build/autoconf/la_uid_t.m4 b/Utilities/cmlibarchive/build/autoconf/la_uid_t.m4 deleted file mode 100644 index 107a2fd77..000000000 --- a/Utilities/cmlibarchive/build/autoconf/la_uid_t.m4 +++ /dev/null @@ -1,20 +0,0 @@ -# la_TYPE_UID_T -# ------------- -AC_DEFUN([la_TYPE_UID_T], -[AC_REQUIRE([AC_CANONICAL_HOST])dnl -AC_CACHE_CHECK(for uid_t in sys/types.h, la_cv_type_uid_t, -[AC_EGREP_HEADER(uid_t, sys/types.h, - la_cv_type_uid_t=yes, la_cv_type_uid_t=no)]) -if test $la_cv_type_uid_t = no; then - case $host in - *mingw*) def_uid_t=short ;; - *) def_uid_t=int ;; - esac - AC_DEFINE_UNQUOTED(uid_t, [$def_uid_t], - [Define to match typeof st_uid field of struct stat if doesn't define.]) - AC_DEFINE_UNQUOTED(gid_t, [$def_uid_t], - [Define to match typeof st_gid field of struct stat if doesn't define.]) -fi -]) -AU_ALIAS([AC_TYPE_UID_T], [la_TYPE_UID_T]) - diff --git a/Utilities/cmlibarchive/build/autogen.sh b/Utilities/cmlibarchive/build/autogen.sh deleted file mode 100755 index 03cd65737..000000000 --- a/Utilities/cmlibarchive/build/autogen.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - - -# Start from one level above the build directory -if [ -f version ]; then - cd .. -fi - -if [ \! -f build/version ]; then - echo "Can't find source directory" - exit 1 -fi - -set -xe -aclocal -I build/autoconf - -# Note: --automake flag needed only for libtoolize from -# libtool 1.5.x; in libtool 2.2.x it is a synonym for --quiet -case `uname` in -Darwin) glibtoolize --automake -c;; -*) libtoolize --automake -c;; -esac -autoconf -autoheader -automake -a -c diff --git a/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake index 472b80d0d..b347c9366 100644 --- a/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake +++ b/Utilities/cmlibarchive/build/cmake/CheckFileOffsetBits.cmake @@ -12,21 +12,22 @@ # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. - #INCLUDE(CheckCXXSourceCompiles) -MACRO (CHECK_FILE_OFFSET_BITS) +GET_FILENAME_COMPONENT(_selfdir_CheckFileOffsetBits + "${CMAKE_CURRENT_LIST_FILE}" PATH) +MACRO (CHECK_FILE_OFFSET_BITS) IF(NOT DEFINED _FILE_OFFSET_BITS) MESSAGE(STATUS "Checking _FILE_OFFSET_BITS for large files") TRY_COMPILE(__WITHOUT_FILE_OFFSET_BITS_64 - ${CMAKE_BINARY_DIR} - ${libarchive_SOURCE_DIR}/build/cmake/CheckFileOffsetBits.c + ${CMAKE_CURRENT_BINARY_DIR} + ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}) IF(NOT __WITHOUT_FILE_OFFSET_BITS_64) TRY_COMPILE(__WITH_FILE_OFFSET_BITS_64 - ${CMAKE_BINARY_DIR} - ${libarchive_SOURCE_DIR}/build/cmake/CheckFileOffsetBits.c + ${CMAKE_CURRENT_BINARY_DIR} + ${_selfdir_CheckFileOffsetBits}/CheckFileOffsetBits.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=64) ENDIF(NOT __WITHOUT_FILE_OFFSET_BITS_64) diff --git a/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake b/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake index 923c693a9..0670df97f 100644 --- a/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake +++ b/Utilities/cmlibarchive/build/cmake/CheckFuncs.cmake @@ -23,25 +23,27 @@ # For details see the accompanying COPYING-CMAKE-SCRIPTS file. INCLUDE(CheckFunctionExists) +GET_FILENAME_COMPONENT(_selfdir_CheckFunctionExistsGlibc + "${CMAKE_CURRENT_LIST_FILE}" PATH) MACRO (CHECK_FUNCTION_EXISTS_GLIBC _FUNC _FUNCVAR) - IF(NOT DEFINED ${_FUNCVAR}) - SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}") - SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}") - CONFIGURE_FILE( ${libarchive_SOURCE_DIR}/build/cmake/CheckFuncs_stub.c.in - ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c IMMEDIATE) - TRY_COMPILE(__stub - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c - COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} - CMAKE_FLAGS - -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} - "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}") - IF (__stub) - SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}") - ELSE (__stub) - CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}") - ENDIF (__stub) - ENDIF(NOT DEFINED ${_FUNCVAR}) + IF(NOT DEFINED ${_FUNCVAR}) + SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}") + SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}") + CONFIGURE_FILE( ${_selfdir_CheckFunctionExistsGlibc}/CheckFuncs_stub.c.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c IMMEDIATE) + TRY_COMPILE(__stub + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + CMAKE_FLAGS + -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} + "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}") + IF (__stub) + SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}") + ELSE (__stub) + CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}") + ENDIF (__stub) + ENDIF(NOT DEFINED ${_FUNCVAR}) ENDMACRO (CHECK_FUNCTION_EXISTS_GLIBC) diff --git a/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake b/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake index 1d065c4ab..0b46b2cdd 100644 --- a/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake +++ b/Utilities/cmlibarchive/build/cmake/FindLZMA.cmake @@ -14,7 +14,7 @@ IF (LZMA_INCLUDE_DIR) ENDIF (LZMA_INCLUDE_DIR) FIND_PATH(LZMA_INCLUDE_DIR lzma.h) -FIND_LIBRARY(LZMA_LIBRARY NAMES lzma ) +FIND_LIBRARY(LZMA_LIBRARY NAMES lzma liblzma) # handle the QUIETLY and REQUIRED arguments and set LZMA_FOUND to TRUE if # all listed variables are TRUE @@ -46,7 +46,3 @@ ELSE(LZMA_FOUND) SET( LZMADEC_LIBRARIES ) ENDIF(LZMADEC_FOUND) ENDIF(LZMA_FOUND) - - -MARK_AS_ADVANCED( LZMA_LIBRARY LZMA_INCLUDE_DIR - LZMADEC_LIBRARY LZMADEC_INCLUDE_DIR ) diff --git a/Utilities/cmlibarchive/build/cmake/config.h.in b/Utilities/cmlibarchive/build/cmake/config.h.in index 34dbce3c2..ff97cbd98 100644 --- a/Utilities/cmlibarchive/build/cmake/config.h.in +++ b/Utilities/cmlibarchive/build/cmake/config.h.in @@ -1,8 +1,291 @@ -/* config.h. Generated from config.h.cmake by cmake configure */ +/* config.h. Generated from build/cmake/config.h.in by cmake configure */ #if defined(__osf__) # define _OSF_SOURCE #endif +/* + * Ensure we have C99-style int64_t, etc, all defined. + */ + +/* First, we need to know if the system has already defined them. */ +#cmakedefine HAVE_INT16_T +#cmakedefine HAVE_INT32_T +#cmakedefine HAVE_INT64_T +#cmakedefine HAVE_INTMAX_T + +#cmakedefine HAVE_UINT8_T +#cmakedefine HAVE_UINT16_T +#cmakedefine HAVE_UINT32_T +#cmakedefine HAVE_UINT64_T +#cmakedefine HAVE_UINTMAX_T + +/* We might have the types we want under other spellings. */ +#cmakedefine HAVE___INT64 +#cmakedefine HAVE_U_INT64_T +#cmakedefine HAVE_UNSIGNED___INT64 + +/* The sizes of various standard integer types. */ +@SIZE_OF_SHORT_CODE@ +@SIZE_OF_INT_CODE@ +@SIZE_OF_LONG_CODE@ +@SIZE_OF_LONG_LONG_CODE@ +@SIZE_OF_UNSIGNED_SHORT_CODE@ +@SIZE_OF_UNSIGNED_CODE@ +@SIZE_OF_UNSIGNED_LONG_CODE@ +@SIZE_OF_UNSIGNED_LONG_LONG_CODE@ + +/* + * If we lack int64_t, define it to the first of __int64, int, long, and long long + * that exists and is the right size. + */ +#if !defined(HAVE_INT64_T) && defined(HAVE___INT64) +typedef __int64 int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_INT == 8 +typedef int int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_LONG == 8 +typedef long int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) && SIZE_OF_LONG_LONG == 8 +typedef long long int64_t; +#define HAVE_INT64_T +#endif + +#if !defined(HAVE_INT64_T) +#error No 64-bit integer type was found. +#endif + +/* + * Similarly for int32_t + */ +#if !defined(HAVE_INT32_T) && SIZE_OF_INT == 4 +typedef long int32_t; +#define HAVE_INT32_T +#endif + +#if !defined(HAVE_INT32_T) && SIZE_OF_LONG == 4 +typedef long int32_t; +#define HAVE_INT32_T +#endif + +#if !defined(HAVE_INT32_T) +#error No 32-bit integer type was found. +#endif + +/* + * Similarly for int16_t + */ +#if !defined(HAVE_INT16_T) && SIZE_OF_INT == 2 +typedef int int16_t; +#define HAVE_INT16_T +#endif + +#if !defined(HAVE_INT16_T) && SIZE_OF_SHORT == 2 +typedef short int16_t; +#define HAVE_INT16_T +#endif + +#if !defined(HAVE_INT16_T) +#error No 16-bit integer type was found. +#endif + +/* + * Similarly for uint64_t + */ +#if !defined(HAVE_UINT64_T) && defined(HAVE_UNSIGNED___INT64) +typedef unsigned __int64 uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED == 8 +typedef unsigned uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG == 8 +typedef unsigned long uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) && SIZE_OF_UNSIGNED_LONG_LONG == 8 +typedef unsigned long long uint64_t; +#define HAVE_UINT64_T +#endif + +#if !defined(HAVE_UINT64_T) +#error No 64-bit unsigned integer type was found. +#endif + + +/* + * Similarly for uint32_t + */ +#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED == 4 +typedef unsigned uint32_t; +#define HAVE_UINT32_T +#endif + +#if !defined(HAVE_UINT32_T) && SIZE_OF_UNSIGNED_LONG == 4 +typedef unsigned long uint32_t; +#define HAVE_UINT32_T +#endif + +#if !defined(HAVE_UINT32_T) +#error No 32-bit unsigned integer type was found. +#endif + +/* + * Similarly for uint16_t + */ +#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED == 2 +typedef unsigned uint16_t; +#define HAVE_UINT16_T +#endif + +#if !defined(HAVE_UINT16_T) && SIZE_OF_UNSIGNED_SHORT == 2 +typedef unsigned short uint16_t; +#define HAVE_UINT16_T +#endif + +#if !defined(HAVE_UINT16_T) +#error No 16-bit unsigned integer type was found. +#endif + +/* + * Similarly for uint8_t + */ +#if !defined(HAVE_UINT8_T) +typedef unsigned char uint8_t; +#define HAVE_UINT8_T +#endif + +#if !defined(HAVE_UINT16_T) +#error No 8-bit unsigned integer type was found. +#endif + +/* Define intmax_t and uintmax_t if they are not already defined. */ +#if !defined(HAVE_INTMAX_T) +typedef int64_t intmax_t; +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#endif + +#if !defined(HAVE_UINTMAX_T) +typedef uint64_t uintmax_t; +#endif + +/* Define ZLIB_WINAPI if zlib was built on Visual Studio. */ +#cmakedefine ZLIB_WINAPI 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_LIBC 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_LIBSYSTEM 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_NETTLE 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_OPENSSL 1 + +/* MD5 via ARCHIVE_CRYPTO_MD5_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_MD5_WIN 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_LIBC 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_NETTLE 1 + +/* RMD160 via ARCHIVE_CRYPTO_RMD160_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_RMD160_OPENSSL 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBC 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_LIBSYSTEM 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_NETTLE 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_OPENSSL 1 + +/* SHA1 via ARCHIVE_CRYPTO_SHA1_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA1_WIN 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC2 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBC3 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_LIBSYSTEM 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_NETTLE 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_OPENSSL 1 + +/* SHA256 via ARCHIVE_CRYPTO_SHA256_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA256_WIN 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC2 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBC3 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_LIBSYSTEM 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_NETTLE 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_OPENSSL 1 + +/* SHA384 via ARCHIVE_CRYPTO_SHA384_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA384_WIN 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC2 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC2 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBC3 supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBC3 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_LIBSYSTEM supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_LIBSYSTEM 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_NETTLE supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_NETTLE 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_OPENSSL supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_OPENSSL 1 + +/* SHA512 via ARCHIVE_CRYPTO_SHA512_WIN supported. */ +#cmakedefine ARCHIVE_CRYPTO_SHA512_WIN 1 + /* Version number of bsdcpio */ #cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}" @@ -48,6 +331,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ATTR_XATTR_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_BSDXML_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_BZLIB_H 1 @@ -60,15 +346,18 @@ /* Define to 1 if you have the `chroot' function. */ #cmakedefine HAVE_CHROOT 1 -/* Define to 1 if you have the `CreateHardLinkA' function. */ -#cmakedefine HAVE_CREATEHARDLINKA 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_COPYFILE_H 1 -/* Define to 1 if you have the `CreateHardLinkW' function. */ -#cmakedefine HAVE_CREATEHARDLINKW 1 +/* Define to 1 if you have the `ctime_r' function. */ +#cmakedefine HAVE_CTIME_R 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_CTYPE_H 1 +/* Define to 1 if you have the `cygwin_conv_path' function. */ +#cmakedefine HAVE_CYGWIN_CONV_PATH 1 + /* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you don't. */ #cmakedefine HAVE_DECL_INT64_MAX 1 @@ -77,14 +366,6 @@ don't. */ #cmakedefine HAVE_DECL_INT64_MIN 1 -/* Define to 1 if you have the declaration of `optarg', and to 0 if you don't. - */ -#cmakedefine HAVE_DECL_OPTARG 1 - -/* Define to 1 if you have the declaration of `optind', and to 0 if you don't. - */ -#cmakedefine HAVE_DECL_OPTIND 1 - /* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you don't. */ #cmakedefine HAVE_DECL_SIZE_MAX 1 @@ -130,6 +411,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ERRNO_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_EXPAT_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_EXT2FS_EXT2_FS_H 1 @@ -145,6 +429,9 @@ /* Define to 1 if you have the `extattr_set_file' function. */ #cmakedefine HAVE_EXTATTR_SET_FILE 1 +/* Define to 1 if EXTATTR_NAMESPACE_USER is defined in sys/extattr.h. */ +#cmakedefine HAVE_DECL_EXTATTR_NAMESPACE_USER 1 + /* Define to 1 if you have the `fchdir' function. */ #cmakedefine HAVE_FCHDIR 1 @@ -163,38 +450,95 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_FCNTL_H 1 +/* Define to 1 if you have the `fdopendir' function. */ +#cmakedefine HAVE_FDOPENDIR 1 + +/* Define to 1 if you have the `fgetea' function. */ +#cmakedefine HAVE_FGETEA 1 + +/* Define to 1 if you have the `fgetxattr' function. */ +#cmakedefine HAVE_FGETXATTR 1 + +/* Define to 1 if you have the `flistea' function. */ +#cmakedefine HAVE_FLISTEA 1 + +/* Define to 1 if you have the `flistxattr' function. */ +#cmakedefine HAVE_FLISTXATTR 1 + /* Define to 1 if you have the `fork' function. */ #cmakedefine HAVE_FORK 1 /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ #cmakedefine HAVE_FSEEKO 1 +/* Define to 1 if you have the `fsetea' function. */ +#cmakedefine HAVE_FSETEA 1 + /* Define to 1 if you have the `fsetxattr' function. */ #cmakedefine HAVE_FSETXATTR 1 /* Define to 1 if you have the `fstat' function. */ #cmakedefine HAVE_FSTAT 1 +/* Define to 1 if you have the `fstatat' function. */ +#cmakedefine HAVE_FSTATAT 1 + +/* Define to 1 if you have the `fstatfs' function. */ +#cmakedefine HAVE_FSTATFS 1 + +/* Define to 1 if you have the `fstatvfs' function. */ +#cmakedefine HAVE_FSTATVFS 1 + /* Define to 1 if you have the `ftruncate' function. */ #cmakedefine HAVE_FTRUNCATE 1 +/* Define to 1 if you have the `futimens' function. */ +#cmakedefine HAVE_FUTIMENS 1 + /* Define to 1 if you have the `futimes' function. */ #cmakedefine HAVE_FUTIMES 1 +/* Define to 1 if you have the `futimesat' function. */ +#cmakedefine HAVE_FUTIMESAT 1 + +/* Define to 1 if you have the `getea' function. */ +#cmakedefine HAVE_GETEA 1 + /* Define to 1 if you have the `geteuid' function. */ #cmakedefine HAVE_GETEUID 1 +/* Define to 1 if you have the `getgrgid_r' function. */ +#cmakedefine HAVE_GETGRGID_R 1 + +/* Define to 1 if you have the `getgrnam_r' function. */ +#cmakedefine HAVE_GETGRNAM_R 1 + /* Define to 1 if you have the `getpid' function. */ #cmakedefine HAVE_GETPID 1 +/* Define to 1 if you have the `getpwnam_r' function. */ +#cmakedefine HAVE_GETPWNAM_R 1 + +/* Define to 1 if you have the `getpwuid_r' function. */ +#cmakedefine HAVE_GETPWUID_R 1 + +/* Define to 1 if you have the `getvfsbyname' function. */ +#cmakedefine HAVE_GETVFSBYNAME 1 + /* Define to 1 if you have the `getxattr' function. */ #cmakedefine HAVE_GETXATTR 1 +/* Define to 1 if you have the `gmtime_r' function. */ +#cmakedefine HAVE_GMTIME_R 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_GRP_H 1 -/* Define to 1 if the system has the type `intmax_t'. */ -#cmakedefine HAVE_INTMAX_T 1 +/* Define to 1 if you have the `iconv' function. */ +#cmakedefine HAVE_ICONV 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ICONV_H 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_INTTYPES_H 1 @@ -214,6 +558,9 @@ /* Define to 1 if you have the `lchown' function. */ #cmakedefine HAVE_LCHOWN 1 +/* Define to 1 if you have the `lgetea' function. */ +#cmakedefine HAVE_LGETEA 1 + /* Define to 1 if you have the `lgetxattr' function. */ #cmakedefine HAVE_LGETXATTR 1 @@ -223,39 +570,81 @@ /* Define to 1 if you have the `attr' library (-lattr). */ #cmakedefine HAVE_LIBATTR 1 +/* Define to 1 if you have the `bsdxml' library (-lbsdxml). */ +#cmakedefine HAVE_LIBBSDXML 1 + /* Define to 1 if you have the `bz2' library (-lbz2). */ #cmakedefine HAVE_LIBBZ2 1 +/* Define to 1 if you have the `expat' library (-lexpat). */ +#cmakedefine HAVE_LIBEXPAT 1 + /* Define to 1 if you have the `lzma' library (-llzma). */ #cmakedefine HAVE_LIBLZMA 1 /* Define to 1 if you have the `lzmadec' library (-llzmadec). */ #cmakedefine HAVE_LIBLZMADEC 1 +/* Define to 1 if you have the `xml2' library (-lxml2). */ +#cmakedefine HAVE_LIBXML2 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBXML_XMLREADER_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LIBXML_XMLWRITER_H 1 + /* Define to 1 if you have the `z' library (-lz). */ #cmakedefine HAVE_LIBZ 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LIMITS_H 1 -/* Define to 1 if you have the link() function. */ +/* Define to 1 if you have the `link' function. */ #cmakedefine HAVE_LINK 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_FIEMAP_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LINUX_FS_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LINUX_MAGIC_H 1 + +/* Define to 1 if you have the `listea' function. */ +#cmakedefine HAVE_LISTEA 1 + /* Define to 1 if you have the `listxattr' function. */ #cmakedefine HAVE_LISTXATTR 1 +/* Define to 1 if you have the `llistea' function. */ +#cmakedefine HAVE_LLISTEA 1 + /* Define to 1 if you have the `llistxattr' function. */ #cmakedefine HAVE_LLISTXATTR 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_LOCALCHARSET_H 1 + +/* Define to 1 if you have the `locale_charset' function. */ +#cmakedefine HAVE_LOCALE_CHARSET 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LOCALE_H 1 +/* Define to 1 if you have the `localtime_r' function. */ +#cmakedefine HAVE_LOCALTIME_R 1 + /* Define to 1 if the system has the type `long long int'. */ #cmakedefine HAVE_LONG_LONG_INT 1 +/* Define to 1 if you have the `lsetea' function. */ +#cmakedefine HAVE_LSETEA 1 + /* Define to 1 if you have the `lsetxattr' function. */ #cmakedefine HAVE_LSETXATTR 1 @@ -275,11 +664,11 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LZMA_H 1 -/* Define to 1 if you have the `MD5' functions. */ -#cmakedefine HAVE_MD5 1 +/* Define to 1 if you have the `mbrtowc' function. */ +#cmakedefine HAVE_MBRTOWC 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MD5_H 1 +/* Define to 1 if you have the `mbsnrtowcs' function. */ +#cmakedefine HAVE_MBSNRTOWCS 1 /* Define to 1 if you have the `memmove' function. */ #cmakedefine HAVE_MEMMOVE 1 @@ -296,20 +685,17 @@ /* Define to 1 if you have the `mknod' function. */ #cmakedefine HAVE_MKNOD 1 +/* Define to 1 if you have the `mkstemp' function. */ +#cmakedefine HAVE_MKSTEMP 1 + /* Define to 1 if you have the header file, and it defines `DIR'. */ #cmakedefine HAVE_NDIR_H 1 /* Define to 1 if you have the `nl_langinfo' function. */ #cmakedefine HAVE_NL_LANGINFO 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_OPENSSL_MD5_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_OPENSSL_RIPEMD_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_OPENSSL_SHA_H 1 +/* Define to 1 if you have the `openat' function. */ +#cmakedefine HAVE_OPENAT 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_PATHS_H 1 @@ -329,21 +715,18 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_PWD_H 1 +/* Define to 1 if you have the `readdir_r' function. */ +#cmakedefine HAVE_READDIR_R 1 + /* Define to 1 if you have the `readlink' function. */ #cmakedefine HAVE_READLINK 1 +/* Define to 1 if you have the `readlinkat' function. */ +#cmakedefine HAVE_READLINKAT 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_REGEX_H 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_RIPEMD_H 1 - -/* Define to 1 if you have the `RIPEMD160' functions. */ -#cmakedefine HAVE_RMD160 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_RMD160_H 1 - /* Define to 1 if you have the `select' function. */ #cmakedefine HAVE_SELECT 1 @@ -353,33 +736,18 @@ /* Define to 1 if you have the `setlocale' function. */ #cmakedefine HAVE_SETLOCALE 1 -/* Define to 1 if you have the `SHA1' functions. */ -#cmakedefine HAVE_SHA1 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SHA1_H 1 - -/* Define to 1 if you have the `SHA256' functions. */ -#cmakedefine HAVE_SHA256 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SHA256_H 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SHA2_H 1 - -/* Define to 1 if you have the `SHA384' functions. */ -#cmakedefine HAVE_SHA384 1 - -/* Define to 1 if you have the `SHA512' functions. */ -#cmakedefine HAVE_SHA512 1 - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SHA_H 1 +/* Define to 1 if you have the `sigaction' function. */ +#cmakedefine HAVE_SIGACTION 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SIGNAL_H 1 +/* Define to 1 if you have the `statfs' function. */ +#cmakedefine HAVE_STATFS 1 + +/* Define to 1 if you have the `statvfs' function. */ +#cmakedefine HAVE_STATVFS 1 + /* Define to 1 if `stat' has the bug that it succeeds when given the zero-length file name argument. */ #cmakedefine HAVE_STAT_EMPTY_STRING_BUG 1 @@ -417,43 +785,61 @@ /* Define to 1 if you have the `strrchr' function. */ #cmakedefine HAVE_STRRCHR 1 -/* Define to 1 if `st_birthtime' is member of `struct stat'. */ +/* Define to 1 if `f_namemax' is a member of `struct statfs'. */ +#cmakedefine HAVE_STRUCT_STATFS_F_NAMEMAX 1 + +/* Define to 1 if `f_iosize' is a member of `struct statvfs'. */ +#cmakedefine HAVE_STRUCT_STATVFS_F_IOSIZE 1 + +/* Define to 1 if `st_birthtime' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIME 1 -/* Define to 1 if `st_birthtimespec.tv_nsec' is member of `struct stat'. */ +/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 -/* Define to 1 if `st_blksize' is member of `struct stat'. */ +/* Define to 1 if `st_blksize' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_BLKSIZE 1 -/* Define to 1 if `st_flags' is member of `struct stat'. */ +/* Define to 1 if `st_flags' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_FLAGS 1 -/* Define to 1 if `st_mtimespec.tv_nsec' is member of `struct stat'. */ +/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 -/* Define to 1 if `st_mtime_n' is member of `struct stat'. */ +/* Define to 1 if `st_mtime_n' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_MTIME_N 1 -/* Define to 1 if `st_mtime_usec' is member of `struct stat'. */ +/* Define to 1 if `st_mtime_usec' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_MTIME_USEC 1 -/* Define to 1 if `st_mtim.tv_nsec' is member of `struct stat'. */ +/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC 1 -/* Define to 1 if `st_umtime' is member of `struct stat'. */ +/* Define to 1 if `st_umtime' is a member of `struct stat'. */ #cmakedefine HAVE_STRUCT_STAT_ST_UMTIME 1 -/* Define to 1 if you have the symlink() function. */ +/* Define to 1 if `tm_gmtoff' is a member of `struct tm'. */ +#cmakedefine HAVE_STRUCT_TM_TM_GMTOFF 1 + +/* Define to 1 if `__tm_gmtoff' is a member of `struct tm'. */ +#cmakedefine HAVE_STRUCT_TM___TM_GMTOFF 1 + +/* Define to 1 if you have the `symlink' function. */ #cmakedefine HAVE_SYMLINK 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_ACL_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_CDEFS_H 1 + /* Define to 1 if you have the header file, and it defines `DIR'. */ #cmakedefine HAVE_SYS_DIR_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_EA_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_EXTATTR_H 1 @@ -463,6 +849,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_MKDEV_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_MOUNT_H 1 + /* Define to 1 if you have the header file, and it defines `DIR'. */ #cmakedefine HAVE_SYS_NDIR_H 1 @@ -476,6 +865,12 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_SELECT_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STATFS_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STATVFS_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_STAT_H 1 @@ -488,6 +883,12 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_UTIME_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_UTSNAME_H 1 + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_VFS_H 1 + /* Define to 1 if you have that is POSIX.1 compatible. */ #cmakedefine HAVE_SYS_WAIT_H 1 @@ -503,9 +904,6 @@ /* Define to 1 if you have the `tzset' function. */ #cmakedefine HAVE_TZSET 1 -/* Define to 1 if the system has the type `uintmax_t'. */ -#cmakedefine HAVE_UINTMAX_T 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_UNISTD_H 1 @@ -521,6 +919,9 @@ /* Define to 1 if you have the `utime' function. */ #cmakedefine HAVE_UTIME 1 +/* Define to 1 if you have the `utimensat' function. */ +#cmakedefine HAVE_UTIMENSAT 1 + /* Define to 1 if you have the `utimes' function. */ #cmakedefine HAVE_UTIMES 1 @@ -542,30 +943,66 @@ /* Define to 1 if you have the `wcrtomb' function. */ #cmakedefine HAVE_WCRTOMB 1 +/* Define to 1 if you have the `wcscmp' function. */ +#cmakedefine HAVE_WCSCMP 1 + /* Define to 1 if you have the `wcscpy' function. */ #cmakedefine HAVE_WCSCPY 1 /* Define to 1 if you have the `wcslen' function. */ #cmakedefine HAVE_WCSLEN 1 +/* Define to 1 if you have the `wcsnrtombs' function. */ +#cmakedefine HAVE_WCSNRTOMBS 1 + /* Define to 1 if you have the `wctomb' function. */ #cmakedefine HAVE_WCTOMB 1 /* Define to 1 if you have the header file. */ #cmakedefine HAVE_WCTYPE_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINCRYPT_H 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_WINDOWS_H 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_WINIOCTL_H 1 + +/* Define to 1 if you have _CrtSetReportMode in */ +#cmakedefine HAVE__CrtSetReportMode 1 + /* Define to 1 if you have the `wmemcmp' function. */ #cmakedefine HAVE_WMEMCMP 1 /* Define to 1 if you have the `wmemcpy' function. */ #cmakedefine HAVE_WMEMCPY 1 +/* Define to 1 if you have a working EXT2_IOC_GETFLAGS */ +#cmakedefine HAVE_WORKING_EXT2_IOC_GETFLAGS 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_ZLIB_H 1 +/* Define to 1 if you have the `_ctime64_s' function. */ +#cmakedefine HAVE__CTIME64_S 1 + +/* Define to 1 if you have the `_fseeki64' function. */ +#cmakedefine HAVE__FSEEKI64 1 + +/* Define to 1 if you have the `_get_timezone' function. */ +#cmakedefine HAVE__GET_TIMEZONE 1 + +/* Define to 1 if you have the `_localtime64_s' function. */ +#cmakedefine HAVE__LOCALTIME64_S 1 + +/* Define to 1 if you have the `_mkgmtime64' function. */ +#cmakedefine HAVE__MKGMTIME64 1 + +/* Define as const if the declaration of iconv() needs const. */ +#define ICONV_CONST ${ICONV_CONST} + /* Version number of libarchive as a single integer */ #cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}" @@ -584,36 +1021,9 @@ . */ #cmakedefine MAJOR_IN_SYSMACROS 1 -/* Define to the generates final MD5 hash function. */ -#cmakedefine MD5_Final ${MD5_Final} - -/* Define to the initializes MD5 context function. */ -#cmakedefine MD5_Init ${MD5_Init} - -/* Define to the updates MD5 context function. */ -#cmakedefine MD5_Update ${MD5_Update} - /* Define to 1 if your C compiler doesn't accept -c and -o together. */ #cmakedefine NO_MINUS_C_MINUS_O 1 -/* Define to the generates final RIPEMD160 hash function. */ -#cmakedefine RIPEMD160_Final ${RIPEMD160_Final} - -/* Define to the initializes RIPEMD160 context function. */ -#cmakedefine RIPEMD160_Init ${RIPEMD160_Init} - -/* Define to the updates RIPEMD160 context function. */ -#cmakedefine RIPEMD160_Update ${RIPEMD160_Update} - -/* Define to the generates final SHA1 hash function. */ -#cmakedefine SHA1_Final ${SHA1_Final} - -/* Define to the initializes SHA1 context function. */ -#cmakedefine SHA1_Init ${SHA1_Init} - -/* Define to the updates SHA1 context function. */ -#cmakedefine SHA1_Update ${SHA1_Update} - /* The size of `wchar_t', as computed by sizeof. */ #cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T} @@ -623,6 +1033,33 @@ /* Define to 1 if you can safely include both and . */ #cmakedefine TIME_WITH_SYS_TIME 1 +/* + * Some platform requires a macro to use extension functions. + */ +#cmakedefine SAFE_TO_DEFINE_EXTENSIONS 1 +#ifdef SAFE_TO_DEFINE_EXTENSIONS +/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif +#endif /* SAFE_TO_DEFINE_EXTENSIONS */ + /* Version number of package */ #cmakedefine VERSION "${VERSION}" @@ -635,10 +1072,9 @@ /* Define for large files, on AIX-style hosts. */ #cmakedefine _LARGE_FILES ${_LARGE_FILES} -/* Define for Solaris 2.5.1 so the uint64_t typedef from , - , or is not used. If the typedef were allowed, the - #define below would cause a syntax error. */ -#cmakedefine _UINT64_T +/* Define for Windows to use Windows 2000+ APIs. */ +#cmakedefine _WIN32_WINNT ${_WIN32_WINNT} +#cmakedefine WINVER ${WINVER} /* Define to empty if `const' does not conform to ANSI C. */ #cmakedefine const ${const} @@ -649,23 +1085,15 @@ /* Define to `unsigned long' if does not define. */ #cmakedefine id_t ${id_t} -/* Define to the type of a signed integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -#cmakedefine int64_t ${int64_t} - -/* Define to the widest signed integer type if and do - not define. */ -#cmakedefine intmax_t ${intmax_t} - /* Define to `int' if does not define. */ #cmakedefine mode_t ${mode_t} -/* Define to `unsigned int' if does not define. */ -#cmakedefine dev_t ${dev_t} - /* Define to `long long' if does not define. */ #cmakedefine off_t ${off_t} +/* Define to `int' if doesn't define. */ +#cmakedefine pid_t ${pid_t} + /* Define to `unsigned int' if does not define. */ #cmakedefine size_t ${size_t} @@ -675,23 +1103,6 @@ /* Define to `int' if doesn't define. */ #cmakedefine uid_t ${uid_t} -/* Define to `unsigned short' if doesn't define. */ -#cmakedefine uint16_t ${uint16_t} - -/* Define to `unsigned int' if doesn't define. */ -#cmakedefine uint32_t ${uint32_t} - -/* Define to `int' if doesn't define. */ -#cmakedefine int32_t ${int32_t} - -/* Define to the type of an unsigned integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -#cmakedefine uint64_t ${uint64_t} - -/* Define to the widest unsigned integer type if and - do not define. */ -#cmakedefine uintmax_t ${uintmax_t} - /* Define to `int' if does not define. */ #cmakedefine intptr_t ${intptr_t} diff --git a/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in new file mode 100644 index 000000000..95d715951 --- /dev/null +++ b/Utilities/cmlibarchive/build/pkgconfig/libarchive.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libarchive +Description: library that can create and read several streaming archive formats +Version: @VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -larchive +Libs.private: @LIBS@ diff --git a/Utilities/cmlibarchive/build/release.sh b/Utilities/cmlibarchive/build/release.sh deleted file mode 100755 index c45acf83f..000000000 --- a/Utilities/cmlibarchive/build/release.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh +v - -PATH=/usr/local/gnu-autotools/bin/:$PATH -export PATH - -# BSD make's "OBJDIR" support freaks out the automake-generated -# Makefile. Effectively disable it. -export MAKEOBJDIRPREFIX=/junk - -# Start from the build directory, where the version file is located -if [ -f build/version ]; then - cd build -fi - -if [ \! -f version ]; then - echo "Can't find version file" - exit 1 -fi - -# Update the build number in the 'version' file. -# Separate number from additional alpha/beta/etc marker -MARKER=`cat version | sed 's/[0-9.]//g'` -# Bump the number -VN=`cat version | sed 's/[^0-9.]//g'` -# Reassemble and write back out -VN=$(($VN + 1)) -rm -f version.old -mv version version.old -chmod +w version.old -echo $VN$MARKER > version -# Build out the string. -VS="$(($VN/1000000)).$(( ($VN/1000)%1000 )).$(( $VN%1000 ))$MARKER" - -cd .. - -# Substitute the integer version into Libarchive's archive.h -perl -p -i -e "s/^(#define\tARCHIVE_VERSION_NUMBER).*/\$1 $VN/" libarchive/archive.h -perl -p -i -e "s/^(#define\tARCHIVE_VERSION_STRING).*/\$1 \"libarchive $VS\"/" libarchive/archive.h -# Substitute the string version into tar and cpio Makefiles -perl -p -i -e "s/^(BSDTAR_VERSION_STRING)=.*/\$1=$VS/" tar/Makefile -perl -p -i -e "s/^(BSDCPIO_VERSION_STRING)=.*/\$1=$VS/" cpio/Makefile -# Substitute versions into configure.ac as well -perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_S\]),.*\)/$1,['"$VS"'])/' configure.ac -perl -p -i -e 's/(m4_define\(\[LIBARCHIVE_VERSION_N\]),.*\)/$1,['"$VN"'])/' configure.ac - -# Add a version notice to NEWS -mv NEWS NEWS.bak -chmod +w NEWS.bak -echo > NEWS -echo `date +"%b %d, %Y:"` libarchive $VS released >> NEWS -cat NEWS.bak >> NEWS - -# Clean up first -rm -rf /usr/obj`pwd` -(cd examples/minitar && make cleandir && make clean) -(cd libarchive && make cleandir && make clean) -(cd libarchive/test && make cleandir && make clean && make list.h) -(cd tar && make cleandir && make clean) - -# Build the libarchive distfile -/bin/sh build/autogen.sh -./configure -make distcheck diff --git a/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh b/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh new file mode 100644 index 000000000..95dbe167d --- /dev/null +++ b/Utilities/cmlibarchive/build/utils/gen_archive_string_composition_h.sh @@ -0,0 +1,418 @@ +#!/bin/sh +# +# This needs http://unicode.org/Public/UNIDATA/UnicodeData.txt +# +inputfile="$1" # Expect UnicodeData.txt +outfile=archive_string_composition.h +pickout=/tmp/mk_unicode_composition_tbl$$.awk +################################################################################# +# +# Append the file header of "archive_string_composition.h" +# +################################################################################# +append_copyright() +{ +cat > ${outfile} < ${pickout} <>8) <= 0x%X && u_decomposable_blocks[(uc)>>8])\\n", highnum + printf "static const char u_decomposable_blocks[0x%X+1] = {\\n\\t", highnum + # + # Output blockmap + for (i = 0; i <= highnum; i++) { + if (i != 0 && i % 32 == 0) + printf "\\n\\t" + # Additionally Hangul[11XX(17), AC00(172) - D7FF(215)] is decomposable. + if (blockmap[i] || i == 17 || (i >= 172 && i <= 215)) + printf "1," + else + printf "0," + } + printf "\\n};\\n\\n" + # + # Output a macro to get a canonical combining class. + # + print "/* Get Canonical Combining Class(CCC). */" + printf "#define CCC(uc)\\t\\\\\n" + printf "\\t(((uc) > 0x%s)?0:\\\\\\n", max + printf "\\tccc_val[ccc_val_index[ccc_index[(uc)>>8]][((uc)>>4)&0x0F]][(uc)&0x0F])\\n" + print "" + # + # Output a canonical combining class value table. + # + midcnt = 0 + printf "/* The table of the value of Canonical Cimbining Class */\\n" + print "static const unsigned char ccc_val[][16] = {" + print " /* idx=0: XXXX0 - XXXXF */" + print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }," + for (h = 0; h <= highnum; h++) { + if (!blockmap[h]) + continue; + for (m = 0; m < 16; m++) { + if (!xx_blockmap[h, m]) + continue; + midcnt++ + printf " /* idx=%d: %03X%1X0 - %03X%1XF */\\n {", midcnt, h, m, h, m + for (l = 0; l < 15; l++) { + printf "%d, ", xxx_blockmap[h, m, l] + } + printf "%d },\n", xxx_blockmap[h, m, 15] + } + } + printf "};\n" + # + # Output the index table of the canonical combining class value table. + # + cnt = 0 + midcnt = 0 + printf "\\n/* The index table to ccc_val[*][16] */\\n" + print "static const unsigned char ccc_val_index[][16] = {" + print " /* idx=0: XXX00 - XXXFF */" + print " { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }," + for (h = 0; h <= highnum; h++) { + if (!blockmap[h]) + continue; + cnt++ + printf " /* idx=%d: %03X00 - %03XFF */\\n {", cnt, h, h + for (m = 0; m < 16; m++) { + if (m != 0) + printf "," + if (xx_blockmap[h, m]) { + midcnt++ + printf "%2d", midcnt + } else + printf " 0" + } + printf " },\\n" + } + printf "};\\n" + # + # Output the index table to the index table of the canonical combining + # class value table. + # + printf "\\n/* The index table to ccc_val_index[*][16] */\\n" + printf "static const unsigned char ccc_index[] = {\\n ", h + cnt = 0 + for (h = 0; h <= highnum; h++) { + if (h != 0 && h % 24 == 0) + printf "\\n " + if (blockmap[h]) { + cnt++; + printf "%2d,", cnt + } else + printf " 0," + } + print "};" + print "" + print "#endif /* ARCHIVE_STRING_COMPOSITION_H_INCLUDED */" +} +# +# +function hextoi(hex) +{ + dec = 0 + for (i=0; i < length(hex); i++) { + x = substr(hex, i+1, 1) + if (x ~/[0-9]/) + dec = dec * 16 + x; + else if (x == "A") + dec = dec * 16 + 10; + else if (x == "B") + dec = dec * 16 + 11; + else if (x == "C") + dec = dec * 16 + 12; + else if (x == "D") + dec = dec * 16 + 13; + else if (x == "E") + dec = dec * 16 + 14; + else if (x == "F") + dec = dec * 16 + 15; + } + return dec +} +# +# Collect Canonical Combining Class values. +# +\$4 ~/^[0-9A-F]+$/ { + if (\$4 !~/^0$/) { + if (min == "") { + min = \$1 + } + max = \$1 + high = substr(\$1, 1, length(\$1) -2) + highnum = hextoi(high) + mid = substr(\$1, length(\$1) -1, 1) + midnum = hextoi(mid) + low = substr(\$1, length(\$1), 1) + lownum = hextoi(low) + blockmap[highnum] = 1 + xx_blockmap[highnum, midnum] = 1 + xxx_blockmap[highnum, midnum, lownum] = \$4 + } +} +# +# Following code points are not decomposed in MAC OS. +# U+2000 - U+2FFF +# U+F900 - U+FAFF +# U+2F800 - U+2FAFF +# +#\$1 ~/^2[0-9A-F][0-9A-F][0-9A-F]\$/ { +# next +#} +#\$1 ~/^F[9A][0-9A-F][0-9A-F]\$/ { +# next +#} +#\$1 ~/^2F[89A][0-9A-F][0-9A-F]\$/ { +# next +#} +# +# Exclusion code points specified by +# http://unicode.org/Public/UNIDATA/CompositionExclusions.txt +## +# 1. Script Specifices +## +\$1 ~/^095[89ABCDEF]\$/ { + next +} +\$1 ~/^09D[CDF]\$/ { + next +} +\$1 ~/^0A3[36]\$/ { + next +} +\$1 ~/^0A5[9ABE]\$/ { + next +} +\$1 ~/^0B5[CD]\$/ { + next +} +\$1 ~/^0F4[3D]\$/ { + next +} +\$1 ~/^0F5[27C]\$/ { + next +} +\$1 ~/^0F69\$/ { + next +} +\$1 ~/^0F7[68]\$/ { + next +} +\$1 ~/^0F9[3D]\$/ { + next +} +\$1 ~/^0FA[27C]\$/ { + next +} +\$1 ~/^0FB9\$/ { + next +} +\$1 ~/^FB1[DF]\$/ { + next +} +\$1 ~/^FB2[ABCDEF]\$/ { + next +} +\$1 ~/^FB3[012345689ABCE]\$/ { + next +} +\$1 ~/^FB4[01346789ABCDE]\$/ { + next +} +## +# 2. Post Composition Version precomposed characters +## +\$1 ~/^2ADC\$/ { + next +} +\$1 ~/^1D15[EF]\$/ { + next +} +\$1 ~/^1D16[01234]\$/ { + next +} +\$1 ~/^1D1B[BCDEF]\$/ { + next +} +\$1 ~/^1D1C0\$/ { + next +} +## +# 3. Singleton Decompositions +## +\$1 ~/^034[01]\$/ { + next +} +\$1 ~/^037[4E]\$/ { + next +} +\$1 ~/^0387\$/ { + next +} +\$1 ~/^1F7[13579BD]\$/ { + next +} +\$1 ~/^1FB[BE]\$/ { + next +} +\$1 ~/^1FC[9B]\$/ { + next +} +\$1 ~/^1FD[3B]\$/ { + next +} +\$1 ~/^1FE[3BEF]\$/ { + next +} +\$1 ~/^1FF[9BD]\$/ { + next +} +\$1 ~/^200[01]\$/ { + next +} +\$1 ~/^212[6AB]\$/ { + next +} +\$1 ~/^232[9A]\$/ { + next +} +\$1 ~/^F9[0-9A-F][0-9A-F]\$/ { + next +} +\$1 ~/^FA0[0-9A-D]\$/ { + next +} +\$1 ~/^FA1[025-9A-E]\$/ { + next +} +\$1 ~/^FA2[0256A-D]\$/ { + next +} +\$1 ~/^FA[3-5][0-9A-F]\$/ { + next +} +\$1 ~/^FA6[0-9A-D]\$/ { + next +} +\$1 ~/^FA[7-9A-C][0-9A-F]\$/ { + next +} +\$1 ~/^FAD[0-9]\$/ { + next +} +\$1 ~/^2F[89][0-9A-F][0-9A-F]\$/ { + next +} +\$1 ~/^2FA0[0-9A-F]\$/ { + next +} +\$1 ~/^2FA1[0-9A-D]\$/ { + next +} +## +# 4. Non-Starter Decompositions +## +\$1 ~/^0344\$/ { + next +} +\$1 ~/^0F7[35]\$/ { + next +} +\$1 ~/^0F81\$/ { + next +} +# +# Output combinations for NFD ==> NFC. +# +\$6 ~/^[0-9A-F]+ [0-9A-F]+\$/ { + split(\$6, cp, " ") + if (length(\$1) == 4) + print "0"cp[1], "0"cp[2], "0"\$1 | cmd + else + print cp[1], cp[2], \$1 | cmd +} +AWK_END +################################################################################# +# +# Run awk a script. +# +################################################################################# +append_copyright +awk -f ${pickout} ${inputfile} >> ${outfile} +# +# Remove awk the script. +rm ${pickout} diff --git a/Utilities/cmlibarchive/build/version b/Utilities/cmlibarchive/build/version index 16a4591a2..ee575c8f5 100644 --- a/Utilities/cmlibarchive/build/version +++ b/Utilities/cmlibarchive/build/version @@ -1 +1 @@ -2007900a +3000002 diff --git a/Utilities/cmlibarchive/configure.ac b/Utilities/cmlibarchive/configure.ac deleted file mode 100644 index 510025b11..000000000 --- a/Utilities/cmlibarchive/configure.ac +++ /dev/null @@ -1,448 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. - -dnl First, define all of the version numbers up front. -dnl In particular, this allows the version macro to be used in AC_INIT - -dnl These first two version numbers are updated automatically on each release. -m4_define([LIBARCHIVE_VERSION_S],[2.7.900a]) -m4_define([LIBARCHIVE_VERSION_N],[2007900]) - -dnl bsdtar and bsdcpio versioning tracks libarchive -m4_define([BSDTAR_VERSION_S],LIBARCHIVE_VERSION_S()) -m4_define([BSDCPIO_VERSION_S],LIBARCHIVE_VERSION_S()) - -# -# Now starts the "real" configure script. -# - -AC_INIT([libarchive],LIBARCHIVE_VERSION_S(),[kientzle@freebsd.org]) -# Make sure the srcdir contains "libarchive" directory -AC_CONFIG_SRCDIR([libarchive]) -# Use auxiliary subscripts from this subdirectory (cleans up root) -AC_CONFIG_AUX_DIR([build/autoconf]) -# M4 scripts -AC_CONFIG_MACRO_DIR([build/autoconf]) -# Must follow AC_CONFIG macros above... -AM_INIT_AUTOMAKE() - -# Libtool versioning uses different conventions on different -# platforms. At least on FreeBSD, libtool uses an overly complex -# convention that attempts to solve problems that most people just -# don't have and which just causes confusion for most end users. -ARCHIVE_MAJOR=$(( LIBARCHIVE_VERSION_N() / 1000000 )) -ARCHIVE_MINOR=$(( (LIBARCHIVE_VERSION_N() / 1000) % 1000 )) -ARCHIVE_REVISION=$(( LIBARCHIVE_VERSION_N() % 1000 )) -ARCHIVE_LIBTOOL_MAJOR=`echo $((${ARCHIVE_MAJOR} + ${ARCHIVE_MINOR}))` -ARCHIVE_LIBTOOL_VERSION=$ARCHIVE_LIBTOOL_MAJOR:$ARCHIVE_REVISION:$ARCHIVE_MINOR - -# Stick the version numbers into config.h -AC_DEFINE([LIBARCHIVE_VERSION_STRING],"LIBARCHIVE_VERSION_S()", - [Version number of libarchive]) -AC_DEFINE_UNQUOTED([LIBARCHIVE_VERSION_NUMBER],"LIBARCHIVE_VERSION_N()", - [Version number of libarchive as a single integer]) -AC_DEFINE([BSDCPIO_VERSION_STRING],"BSDCPIO_VERSION_S()", - [Version number of bsdcpio]) -AC_DEFINE([BSDTAR_VERSION_STRING],"BSDTAR_VERSION_S()", - [Version number of bsdtar]) - -# The shell variables here must be the same as the AC_SUBST() variables -# below, but the shell variable names apparently cannot be the same as -# the m4 macro names above. Why? Ask autoconf. -BSDCPIO_VERSION_STRING=BSDCPIO_VERSION_S() -BSDTAR_VERSION_STRING=BSDTAR_VERSION_S() -LIBARCHIVE_VERSION_STRING=LIBARCHIVE_VERSION_S() -LIBARCHIVE_VERSION_NUMBER=LIBARCHIVE_VERSION_N() - -# Substitute the above version numbers into the various files below. -# Yes, I believe this is the fourth time we define what are essentially -# the same symbols. Why? Ask autoconf. -AC_SUBST(ARCHIVE_LIBTOOL_VERSION) -AC_SUBST(BSDCPIO_VERSION_STRING) -AC_SUBST(BSDTAR_VERSION_STRING) -AC_SUBST(LIBARCHIVE_VERSION_STRING) -AC_SUBST(LIBARCHIVE_VERSION_NUMBER) - -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([Makefile]) - -# Check for host type -AC_CANONICAL_HOST - -dnl Compilation on mingw and Cygwin needs special Makefile rules -inc_windows_files=no -inc_cygwin_files=no -case "$host_os" in - *mingw* ) inc_windows_files=yes ;; - *cygwin*) inc_cygwin_files=yes ;; -esac -AM_CONDITIONAL([INC_WINDOWS_FILES], [test $inc_windows_files = yes]) -AM_CONDITIONAL([INC_CYGWIN_FILES], [test $inc_cygwin_files = yes]) - -dnl Defines that are required for specific platforms (e.g. -D_POSIX_SOURCE, etc) -PLATFORMCPPFLAGS= -case "$host_os" in - *mingw* ) PLATFORMCPPFLAGS=-D__USE_MINGW_ANSI_STDIO ;; -esac -AC_SUBST(PLATFORMCPPFLAGS) - -# Checks for programs. -AC_PROG_CC -AM_PROG_CC_C_O -AC_LIBTOOL_WIN32_DLL -AC_PROG_LIBTOOL -AC_CHECK_TOOL([STRIP],[strip]) - -# -# Options for building bsdtar. -# -# Default is to build bsdtar, but allow people to override that. -# -AC_ARG_ENABLE([bsdtar], - [AS_HELP_STRING([--enable-bsdtar], [enable build of bsdtar (default)]) - AS_HELP_STRING([--enable-bsdtar=static], [force static build of bsdtar]) - AS_HELP_STRING([--enable-bsdtar=shared], [force dynamic build of bsdtar]) -AS_HELP_STRING([--disable-bsdtar], [disable build of bsdtar])], - [], [enable_bsdtar=yes]) - -case "$enable_bsdtar" in -yes) - if test "$enable_static" = "no"; then - static_bsdtar=no - else - static_bsdtar=yes - fi - build_bsdtar=yes - ;; -dynamic|shared) - if test "$enable_shared" = "no"; then - AC_MSG_FAILURE([Shared linking of bsdtar requires shared libarchive]) - fi - build_bsdtar=yes - static_bsdtar=no - ;; -static) - build_bsdtar=yes - static_bsdtar=yes - ;; -no) - build_bsdtar=no - static_bsdtar=no - ;; -*) - AC_MSG_FAILURE([Unsupported value for --enable-bsdtar]) - ;; -esac - -AM_CONDITIONAL([BUILD_BSDTAR], [ test "$build_bsdtar" = yes ]) -AM_CONDITIONAL([STATIC_BSDTAR], [ test "$static_bsdtar" = yes ]) - -# -# Options for building bsdcpio. -# -# Default is not to build bsdcpio, but that can be overridden. -# -AC_ARG_ENABLE([bsdcpio], - [AS_HELP_STRING([--enable-bsdcpio], [enable build of bsdcpio (default)]) - AS_HELP_STRING([--enable-bsdcpio=static], [static build of bsdcpio]) - AS_HELP_STRING([--enable-bsdcpio=shared], [dynamic build of bsdcpio]) -AS_HELP_STRING([--disable-bsdcpio], [disable build of bsdcpio])], - [], [enable_bsdcpio=yes]) - -case "$enable_bsdcpio" in -yes) - if test "$enable_static" = "no"; then - static_bsdcpio=no - else - static_bsdcpio=yes - fi - build_bsdcpio=yes - ;; -dynamic|shared) - if test "$enabled_shared" = "no"; then - AC_MSG_FAILURE([Shared linking of bsdcpio requires shared libarchive]) - fi - build_bsdcpio=yes - ;; -static) - build_bsdcpio=yes - static_bsdcpio=yes - ;; -no) - build_bsdcpio=no - static_bsdcpio=no - ;; -*) - AC_MSG_FAILURE([Unsupported value for --enable-bsdcpio]) - ;; -esac - -AM_CONDITIONAL([BUILD_BSDCPIO], [ test "$build_bsdcpio" = yes ]) -AM_CONDITIONAL([STATIC_BSDCPIO], [ test "$static_bsdcpio" = yes ]) - -# Set up defines needed before including any headers -case $host in - *mingw* | *cygwin* ) - AC_DEFINE([_WIN32_WINNT], 0x0500, [Define to '0x0500' for Windows 2000 APIs.]) - AC_DEFINE([WINVER], 0x0500, [Define to '0x0500' for Windows 2000 APIs.]) - ;; -esac - -# Checks for header files. -AC_HEADER_STDC -AC_HEADER_DIRENT -AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS([acl/libacl.h attr/xattr.h ctype.h errno.h]) -AC_CHECK_HEADERS([ext2fs/ext2_fs.h fcntl.h grp.h]) -AC_CHECK_HEADERS([inttypes.h io.h langinfo.h limits.h linux/fs.h]) -AC_CHECK_HEADERS([locale.h paths.h poll.h pwd.h regex.h signal.h stdarg.h]) -AC_CHECK_HEADERS([stdint.h stdlib.h string.h]) -AC_CHECK_HEADERS([sys/acl.h sys/extattr.h sys/ioctl.h sys/mkdev.h]) -AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/select.h sys/time.h sys/utime.h]) -AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h windows.h]) - -# Checks for libraries. -AC_ARG_WITH([zlib], - AS_HELP_STRING([--without-zlib], [Don't build support for gzip through zlib])) - -if test "x$with_zlib" != "xno"; then - AC_CHECK_HEADERS([zlib.h]) - AC_CHECK_LIB(z,inflate) -fi - -AC_ARG_WITH([bz2lib], - AS_HELP_STRING([--without-bz2lib], [Don't build support for bzip2 through bz2lib])) - -if test "x$with_bz2lib" != "xno"; then - AC_CHECK_HEADERS([bzlib.h]) - AC_CHECK_LIB(bz2,BZ2_bzDecompressInit) -fi - -AC_ARG_WITH([lzmadec], - AS_HELP_STRING([--without-lzmadec], [Don't build support for lzma through lzmadec])) - -if test "x$with_lzmadec" != "xno"; then - AC_CHECK_HEADERS([lzmadec.h]) - AC_CHECK_LIB(lzmadec,lzmadec_decode) -fi - -AC_ARG_WITH([lzma], - AS_HELP_STRING([--without-lzma], [Don't build support for xz through lzma])) - -if test "x$with_lzma" != "xno"; then - AC_CHECK_HEADERS([lzma.h]) - AC_CHECK_LIB(lzma,lzma_stream_decoder) -fi - -AC_ARG_WITH([openssl], - AS_HELP_STRING([--without-openssl], [Don't build support for mtree hashes through openssl])) - -AC_CHECK_HEADERS([md5.h ripemd.h rmd160.h sha.h sha1.h sha2.h sha256.h]) -# Common names for libc implementation on NetBSD and OpenBSD -AC_CHECK_FUNCS(MD5Init RMD160Init SHA1Init) -# SHA2 on NetBSD and older OpenBSD -AC_CHECK_FUNCS(SHA256_Init SHA384_Init SHA512_Init) -# SHA2 on newer OpenBSD -AC_CHECK_FUNCS(SHA256Init SHA384Init SHA512Init) - -if test "x$with_openssl" != "xno"; then - if test "$ac_cv_func_MD5Init" != "yes"; then - AC_CHECK_HEADERS([openssl/md5.h]) - AC_SEARCH_LIBS([MD5_Init], [crypto]) - fi - if test "$ac_cv_func_RMD160Init" != "yes"; then - AC_CHECK_HEADERS([openssl/ripemd.h]) - AC_SEARCH_LIBS([RIMEMD160_Init], [crypto]) - fi - if test "$ac_cv_func_SHA1Init" != "yes"; then - AC_CHECK_HEADERS([openssl/sha.h]) - AC_SEARCH_LIBS([SHA1_Init], [crypto]) - fi - if test "$ac_cv_func_SHA256Init" != "yes" || - test "$ac_cv_func_SHA384Init" != "yes" || - test "$ac_cv_func_SHA512Init" != "yes"; then - if test "$ac_cv_func_SHA256_Init" != "yes" || - test "$ac_cv_func_SHA384_Init" != "yes" || - test "$ac_cv_func_SHA512_Init" != "yes"; then - AC_CHECK_HEADERS([openssl/sha.h]) - AC_SEARCH_LIBS([SHA256_Init SHA384_Init SHA512_Init], [crypto]) - fi - fi -fi - -# TODO: Give the user the option of using a pre-existing system -# libarchive. This will define HAVE_LIBARCHIVE which will cause -# bsdtar_platform.h to use #include <...> for the libarchive headers. -# Need to include Makefile.am magic to link against system -# -larchive in that case. -#AC_CHECK_LIB(archive,archive_version) - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -# AC_TYPE_UID_T defaults to "int", which is incorrect for MinGW -# and MSVC. Use a customized version. -la_TYPE_UID_T -AC_TYPE_MODE_T -# AC_TYPE_OFF_T defaults to "long", which limits us to 4GB files on -# most systems... default to "long long" instead. -AC_CHECK_TYPE(off_t, [long long]) -AC_TYPE_SIZE_T -AC_CHECK_TYPE(id_t, [unsigned long]) -AC_CHECK_TYPE(uintptr_t, [unsigned int]) - -# Check for birthtime in struct stat -AC_CHECK_MEMBERS([struct stat.st_birthtime]) - -# Check for high-resolution timestamps in struct stat -AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec]) -AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec]) -AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec]) -AC_CHECK_MEMBERS([struct stat.st_mtime_n]) # AIX -AC_CHECK_MEMBERS([struct stat.st_umtime]) # Tru64 -AC_CHECK_MEMBERS([struct stat.st_mtime_usec]) # Hurd -# Check for block size support in struct stat -AC_CHECK_MEMBERS([struct stat.st_blksize]) -# Check for st_flags in struct stat (BSD fflags) -AC_CHECK_MEMBERS([struct stat.st_flags]) - -# If you have uintmax_t, we assume printf supports %ju -# If you have unsigned long long, we assume printf supports %llu -# TODO: Check for %ju and %llu support directly. -AC_CHECK_TYPES([uintmax_t, unsigned long long]) - -# We need int64_t, uint64_t, intmax_t, and uintmax_t -AC_TYPE_INTMAX_T -AC_TYPE_INT64_T -AC_TYPE_UINTMAX_T -AC_TYPE_UINT64_T - -# TODO: If any of these are missing, define them right here. -AC_CHECK_DECLS([SIZE_MAX, SSIZE_MAX, INT64_MAX, INT64_MIN, UINT64_MAX, UINT32_MAX]) - -AC_CHECK_DECL([EFTYPE], - [AC_DEFINE(HAVE_EFTYPE, 1, [A possible errno value for invalid file format errors])], - [], - [#include ]) -AC_CHECK_DECL([EILSEQ], - [AC_DEFINE(HAVE_EILSEQ, 1, [A possible errno value for invalid file format errors])], - [], - [#include ]) -AC_CHECK_TYPE([wchar_t], - [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]wchar_t), 1, [Define to 1 if the system has the type `wchar_t'.])dnl - AC_CHECK_SIZEOF([wchar_t])], - []) - -AC_HEADER_TIME - -# Checks for library functions. -AC_PROG_GCC_TRADITIONAL -AC_HEADER_MAJOR -AC_FUNC_FSEEKO -AC_FUNC_MEMCMP -AC_FUNC_LSTAT -AC_FUNC_STAT -AC_FUNC_STRERROR_R -AC_FUNC_STRFTIME -AC_FUNC_VPRINTF -# check for: -# CreateHardLinkA(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES) -# To avoid necessity for including windows.h or special forward declaration -# workarounds, we use 'void *' for 'struct SECURITY_ATTRIBUTES *' -AC_CHECK_STDCALL_FUNC([CreateHardLinkA],[const char *, const char *, void *]) -AC_CHECK_FUNCS([chflags chown chroot]) -AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fork]) -AC_CHECK_FUNCS([fstat ftruncate futimes geteuid getpid]) -AC_CHECK_FUNCS([lchflags lchmod lchown link lstat]) -AC_CHECK_FUNCS([lutimes memmove memset mkdir mkfifo mknod]) -AC_CHECK_FUNCS([nl_langinfo pipe poll readlink select setenv setlocale]) -AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm]) -AC_CHECK_FUNCS([tzset unsetenv utime utimes vfork]) -AC_CHECK_FUNCS([wcrtomb wcscpy wcslen wctomb wmemcmp wmemcpy]) -# detects cygwin-1.7, as opposed to older versions -AC_CHECK_FUNCS([cygwin_conv_path]) - -# FreeBSD's nl_langinfo supports an option to specify whether the -# current locale uses month/day or day/month ordering. It makes the -# output a little prettier... -AC_CHECK_DECL([D_MD_ORDER], -[AC_DEFINE(HAVE_D_MD_ORDER, 1, [Define to 1 if nl_langinfo supports D_MD_ORDER])], -[], -[#if HAVE_LANGINFO_H -#include -#endif -]) - -# Check for dirent.d_namlen field explicitly -# (This is a bit more straightforward than, if not quite as portable as, -# the recipe given by the autoconf maintainers.) -AC_CHECK_MEMBER(struct dirent.d_namlen,,, -[#if HAVE_DIRENT_H -#include -#endif -]) - -# Check for Extended Attributes support -AC_ARG_ENABLE([xattr], - AS_HELP_STRING([--disable-xattr], - [Enable Extended Attributes support (default: check)])) - -if test "x$enable_xattr" != "xno"; then - AC_CHECK_HEADERS([attr/xattr.h]) - AC_CHECK_HEADERS([sys/xattr.h]) - AC_CHECK_LIB(attr,setxattr) - AC_CHECK_FUNCS([extattr_get_file extattr_list_file]) - AC_CHECK_FUNCS([extattr_set_fd extattr_set_file]) - AC_CHECK_FUNCS([fsetxattr getxattr]) - AC_CHECK_FUNCS([lgetxattr listxattr llistxattr lsetxattr]) -fi - -# Check for ACL support -# -# The ACL support in libarchive is written against the POSIX1e draft, -# which was never officially approved and varies quite a bit across -# platforms. Worse, some systems have completely non-POSIX acl functions, -# which makes the following checks rather more complex than I would like. -# -AC_ARG_ENABLE([acl], - AS_HELP_STRING([--disable-acl], - [Enable ACL support (default: check)])) - -if test "x$enable_acl" != "xno"; then - AC_CHECK_HEADERS([sys/acl.h]) - AC_CHECK_LIB([acl],[acl_get_file]) - AC_CHECK_FUNCS([acl_create_entry acl_init acl_set_fd acl_set_fd_np acl_set_file]) - - AC_CHECK_TYPES(acl_permset_t,,, - [#if HAVE_SYS_TYPES_H - #include - #endif - #if HAVE_SYS_ACL_H - #include - #endif - ]) - - # The "acl_get_perm()" function was omitted from the POSIX draft. - # (It's a pretty obvious oversight; otherwise, there's no way to - # test for specific permissions in a permset.) Linux uses the obvious - # name, FreeBSD adds _np to mark it as "non-Posix extension." - # Test for both as a double-check that we really have POSIX-style ACL support. - AC_CHECK_FUNCS(acl_get_perm_np acl_get_perm acl_get_link acl_get_link_np,,, - [#if HAVE_SYS_TYPES_H - #include - #endif - #if HAVE_SYS_ACL_H - #include - #endif - ]) - - # MacOS has an acl.h that isn't POSIX. It can be detected by - # checking for ACL_USER - AC_CHECK_DECL([ACL_USER], - [AC_DEFINE(HAVE_ACL_USER, 1, [True for systems with POSIX ACL support])], - [], - [#include ]) -fi - -# Additional requirements -AC_SYS_LARGEFILE - -AC_OUTPUT diff --git a/Utilities/cmlibarchive/contrib/README b/Utilities/cmlibarchive/contrib/README deleted file mode 100644 index 2eb0114ff..000000000 --- a/Utilities/cmlibarchive/contrib/README +++ /dev/null @@ -1,32 +0,0 @@ -Many people have graciously sent me configuration -files and other useful tidbits for use with libarchive. - -I do not support or use any of these; but if you can use them, enjoy! - -====================================================================== - -From: Andre Stechert - -libarchive_autodetect-st_lib_archive.m4 - -M4 macros for use with autoconf to detect whether a suitable -version of libarchive is installed on this system. - - -====================================================================== - -libarchive.spec - -An RPM ".spec" file for building libarchive on most systems. -This apparently was originally developed by a group at pld-linux.org. -Several people have sent me different versions of this file. - -====================================================================== - -From: Robert Meier - -libarchive.1aix53.spec - -As above, for use on AIX5.3. - -====================================================================== diff --git a/Utilities/cmlibarchive/contrib/libarchive.1aix53.spec b/Utilities/cmlibarchive/contrib/libarchive.1aix53.spec deleted file mode 100644 index 028c0421b..000000000 --- a/Utilities/cmlibarchive/contrib/libarchive.1aix53.spec +++ /dev/null @@ -1,160 +0,0 @@ -# $LastChangedRevision: 8 $, $LastChangedDate: 2008-04-30 18:11:33 -0400 (Wed, 30 Apr 2008) $ -Summary: Library to create and read several different archive formats -Summary(pl): Biblioteka do tworzenia i odczytu ró¿nych formatów archiwów -Name: libarchive -Version: 2.0a3 -Release: 1aix53 -License: BSD -Group: Libraries -Source0: http://people.freebsd.org/~kientzle/libarchive/src/%{name}-%{version}.tar.gz -Patch: %{name}-0123457890.patch -URL: http://people.freebsd.org/~kientzle/libarchive/ -Requires: glibc -Requires: zlib -Requires: bzip2 -BuildRequires: gcc -BuildRequires: gcc-c++ -BuildRequires: gawk -BuildRequires: zlib-devel -BuildRequires: bzip2 -BuildRoot: %{_tmppath}/%{name}-%{version}-build - -%description -Libarchive is a programming library that can create and read several -different streaming archive formats, including most popular TAR -variants and several CPIO formats. It can also write SHAR archives. - -%description -l pl -Libarchive jest bibliotek± s³u¿ac± to tworzenia i odczytu wielu -ró¿nych strumieniowych formatów archiwów, w³±czaj±c w to popularne -odmiany TAR oraz wiele formatów CPIO. Biblioteka ta potrafi tak¿e -zapisywaæ archiwa SHAR. - -%package devel -Summary: Header files for libarchive library -Summary(pl): Pliki nag³ówkowe biblioteki libarchive -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -Header files for libarchive library. - -%description devel -l pl -Pliki nag³ówkowe biblioteki libarchive. - -%package static -Summary: Static libarchive library -Summary(pl): Statyczna biblioteka libarchive -Group: Development/Libraries -Requires: %{name}-devel = %{version}-%{release} - -%description static -Static libarchive library. - -%description static -l pl -Statyczna biblioteka libarchive. - -%package -n bsdtar -Summary: bsdtar - tar(1) implementation based on libarchive -Summary(pl): bsdtar - implementacja programu tar(1) oparta na libarchive -Group: Applications/Archiving -Requires: %{name} = %{version}-%{release} - -%description -n bsdtar -bsdtar - tar(1) implementation based on libarchive. - -%description -n bsdtar -l pl -bsdtar - implementacja programu tar(1), oparta na libarchive. - -%prep -%setup -q -%patch0 -p1 - -%build -# Specify paths to avoid use of vacpp -# -maix64 - required to use large files with aix-5.3 -# -static - required for interoperability without copying libraries -# -D_BSD - required to include definition of makedev -# -X64 - required to assemble 64-bit COFF files -mkdir -p %{buildroot} -PATH=/opt/freeware/libexec:/opt/freeware/bin:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:. \ -CPATH=/opt/freeware/include:/usr/local/include \ -LIBPATH=/opt/freeware/lib:/usr/local/lib:/usr/share/lib \ -LD_LIBRARY_PATH=/opt/freeware/lib:/usr/local/lib:/usr/share/lib \ -CFLAGS="$RPM_OPT_FLAGS -maix64 -static -D_BSD" \ -CXXFLAGS="$RPM_OPT_FLAGS -maix64 -static -D_BSD" \ -AR="ar -X64" \ -./configure \ ---prefix=%{_prefix} \ ---libexecdir=%{_libexecdir} \ ---mandir=%{_mandir} \ ---infodir=%{_infodir} \ ---enable-shared=yes \ ---enable-static=yes \ -| tee %{buildroot}/config.log -make | tee %{buildroot}/make.log - -%install -[ "%buildroot" != "/" ] && [ -d %buildroot ] && rm -rf %buildroot; -make DESTDIR=%buildroot install -# original install builds, but does install bsdtar -cp .libs/%{name}.a %{buildroot}%{_libdir} -cp bsdtar %{buildroot}%{_bindir} -cp tar/bsdtar.1 %{buildroot}%{_mandir}/man1 - -%clean -rm -fr %buildroot - -%files -%defattr(644,root,root,755) -%{_libdir}/libarchive.a - -%files devel -%defattr(644,root,root,755) -%{_libdir}/libarchive.la -%{_includedir}/*.h -%doc %{_mandir}/man3/* -%doc %{_mandir}/man5/* - -%files -n bsdtar -%defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/bsdtar -%doc %{_mandir}/man1/bsdtar.1* - -%define date %(echo `LC_ALL="C" date +"%a %b %d %Y"`) -%changelog -* %{date} PLD Team -All persons listed below can be reached at @pld-linux.org - -$Log: libarchive.spec,v $ -Release 1aix53 2006/12/12 rm1023@dcx.com -- tweak for aix-5.3 -- added libarchive-0123457890.patch for "0123457890" error -- replaced libarchive-1.3.1.tar.gz with libarchive-2.0a3.tar.gz -- removed obsolete -CVE-2006-5680.patch and -man_progname.patch - -Revision 1.6 2006/11/15 10:41:28 qboosh -- BR: acl-devel,attr-devel -- devel deps - -Revision 1.5 2006/11/08 22:22:25 twittner -- up to 1.3.1 -- added BR: e2fsprogs-devel -- added -CVE-2006-5680.patch agains entering in infinite -loop in corrupt archives -- added bsdtar package (bsdtar is included now in libarchive -sources) -- rel. 0.1 for testing - -Revision 1.4 2005/12/15 18:26:36 twittner -- up to 1.2.37 -- removed -shared.patch (no longer needed) - -Revision 1.3 2005/10/05 17:00:12 arekm -- up to 1.02.034 - -Revision 1.2 2005/07/27 20:17:21 qboosh -- typo - -Revision 1.1 2005/07/27 08:36:03 adamg -- new diff --git a/Utilities/cmlibarchive/contrib/libarchive.spec b/Utilities/cmlibarchive/contrib/libarchive.spec deleted file mode 100644 index 56545f972..000000000 --- a/Utilities/cmlibarchive/contrib/libarchive.spec +++ /dev/null @@ -1,147 +0,0 @@ -# $LastChangedRevision: 8 $, $LastChangedDate: 2008-04-30 18:11:33 -0400 (Wed, 30 Apr 2008) $ -Summary: Library to create and read several different archive formats -Summary(pl): Biblioteka do tworzenia i odczytu ró¿nych formatów archiwów -Name: libarchive -Version: 2.0a3 -Release: 1 -License: BSD -Group: Libraries -Source0: http://people.freebsd.org/~kientzle/libarchive/src/%{name}-%{version}.tar.gz -Patch: %{name}-0123457890.patch -URL: http://people.freebsd.org/~kientzle/libarchive/ -Requires: glibc -Requires: zlib -Requires: bzip2 -BuildRequires: gcc -BuildRequires: gcc-c++ -BuildRequires: gawk -BuildRequires: zlib-devel -BuildRequires: bzip2 -BuildRoot: %{_tmppath}/%{name}-%{version}-build - -%description -Libarchive is a programming library that can create and read several -different streaming archive formats, including most popular TAR -variants and several CPIO formats. It can also write SHAR archives. - -%description -l pl -Libarchive jest bibliotek± s³u¿ac± to tworzenia i odczytu wielu -ró¿nych strumieniowych formatów archiwów, w³±czaj±c w to popularne -odmiany TAR oraz wiele formatów CPIO. Biblioteka ta potrafi tak¿e -zapisywaæ archiwa SHAR. - -%package devel -Summary: Header files for libarchive library -Summary(pl): Pliki nag³ówkowe biblioteki libarchive -Group: Development/Libraries -Requires: %{name} = %{version}-%{release} - -%description devel -Header files for libarchive library. - -%description devel -l pl -Pliki nag³ówkowe biblioteki libarchive. - -%package static -Summary: Static libarchive library -Summary(pl): Statyczna biblioteka libarchive -Group: Development/Libraries -Requires: %{name}-devel = %{version}-%{release} - -%description static -Static libarchive library. - -%description static -l pl -Statyczna biblioteka libarchive. - -%package -n bsdtar -Summary: bsdtar - tar(1) implementation based on libarchive -Summary(pl): bsdtar - implementacja programu tar(1) oparta na libarchive -Group: Applications/Archiving -Requires: %{name} = %{version}-%{release} - -%description -n bsdtar -bsdtar - tar(1) implementation based on libarchive. - -%description -n bsdtar -l pl -bsdtar - implementacja programu tar(1), oparta na libarchive. - -%prep -%setup -q -%patch0 -p1 - -%build -mkdir -p %{buildroot} -./configure \ ---prefix=%{_prefix} \ ---libexecdir=%{_libexecdir} \ ---mandir=%{_mandir} \ ---infodir=%{_infodir} \ ---enable-shared=yes \ ---enable-static=yes \ -| tee %{buildroot}/config.log -make | tee %{buildroot}/make.log - -%install -[ "%buildroot" != "/" ] && [ -d %buildroot ] && rm -rf %buildroot; -make DESTDIR=%buildroot install -# original install builds, but does install bsdtar -cp .libs/%{name}.a %{buildroot}%{_libdir} -cp bsdtar %{buildroot}%{_bindir} -cp tar/bsdtar.1 %{buildroot}%{_mandir}/man1 - -%clean -rm -fr %buildroot - -%files -%defattr(644,root,root,755) -%{_libdir}/libarchive.a - -%files devel -%defattr(644,root,root,755) -%{_libdir}/libarchive.la -%{_includedir}/*.h -%doc %{_mandir}/man3/* -%doc %{_mandir}/man5/* - -%files -n bsdtar -%defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/bsdtar -%doc %{_mandir}/man1/bsdtar.1* - -%define date %(echo `LC_ALL="C" date +"%a %b %d %Y"`) -%changelog -* %{date} PLD Team -All persons listed below can be reached at @pld-linux.org - -$Log: libarchive.spec,v $ -Release 1 2006/12/12 rm1023@dcx.com -- added libarchive-0123457890.patch for "0123457890" error -- replaced libarchive-1.3.1.tar.gz with libarchive-2.0a3.tar.gz -- removed obsolete -CVE-2006-5680.patch and -man_progname.patch - -Revision 1.6 2006/11/15 10:41:28 qboosh -- BR: acl-devel,attr-devel -- devel deps - -Revision 1.5 2006/11/08 22:22:25 twittner -- up to 1.3.1 -- added BR: e2fsprogs-devel -- added -CVE-2006-5680.patch agains entering in infinite -loop in corrupt archives -- added bsdtar package (bsdtar is included now in libarchive -sources) -- rel. 0.1 for testing - -Revision 1.4 2005/12/15 18:26:36 twittner -- up to 1.2.37 -- removed -shared.patch (no longer needed) - -Revision 1.3 2005/10/05 17:00:12 arekm -- up to 1.02.034 - -Revision 1.2 2005/07/27 20:17:21 qboosh -- typo - -Revision 1.1 2005/07/27 08:36:03 adamg -- new diff --git a/Utilities/cmlibarchive/contrib/libarchive_autodetect-st_lib_archive.m4 b/Utilities/cmlibarchive/contrib/libarchive_autodetect-st_lib_archive.m4 deleted file mode 100644 index 98eb533c3..000000000 --- a/Utilities/cmlibarchive/contrib/libarchive_autodetect-st_lib_archive.m4 +++ /dev/null @@ -1,154 +0,0 @@ -dnl -dnl @synopsis ST_LIB_ARCHIVE([ENABLED-DEFAULT]) -dnl -dnl This macro figures out what's necessary to link a program against an -dnl instance of the BSD libarchive package by Tim Kientzle. -dnl -dnl See http://people.freebsd.org/~kientzle/libarchive/ for more info. -dnl -dnl It exports and substitutes the variables LIBARCHIVE_LIBS, LIBARCHIVE_LDFLAGS, -dnl and LIBARCHIVE_CPPFLAGS to appropriate values for the identified instance of -dnl libarchive. The values are AC_SUBST'd, so a user could, for example, simply -dnl include @LIBARCHIVE_CPPFLAGS@ in the definition of AM_CPPFLAGS in a Makefile.am. -dnl -dnl ENABLED-DEFAULT is either "yes" or "no" and determines whether the default value -dnl is --with-libarchive or --without-libarchive. It is not possible to specify a -dnl default directory. More simply, any reasonable choice for a default should just -dnl go into the auto-detect list. -dnl -dnl The macro defines the symbol HAVE_LIBARCHIVE if the library is found. You -dnl should use autoheader to include a definition for this symbol in a config.h -dnl file. Sample usage in a C/C++ source is as follows: -dnl -dnl #ifdef HAVE_LIBARCHIVE -dnl #include -dnl #endif /* HAVE_LIBARCHIVE */ -dnl -dnl @category InstalledPackages -dnl @author Andre Stechert -dnl @version 2006-04-20 -dnl @license GPLWithACException - -AC_DEFUN([ST_LIB_ARCHIVE], -[ -# -# Handle input from the configurer and blend with the requirements from the maintainer. -# We go through the trouble of creating a second set of variables other than the with_foo -# variables in order to be sure that error/corner cases have been cleaned up. -# -# After this statement, three trusted variable are defined. -# -# st_lib_archive_ENABLED will be either "yes" or "no". its value determines whether -# or not we bother with the rest of the checks and whether or not we export a -# bunch of variables. -# -# st_lib_archive_LOCATION will be either "auto" or "defined". if it is "auto", then -# we try a bunch of standard locations. if it is "defined", then we just try the value -# provided in st_lib_archive_DIR. -# -# st_lib_archive_DIR will contain the string provided by the user, provided that it's -# actually a directory. -# -AC_MSG_CHECKING([if libarchive is wanted]) -AC_ARG_WITH([libarchive], - AS_HELP_STRING([--with-libarchive=DIR], [libarchive installation directory]), - [if test "x$with_libarchive" = "xno" ; then - st_lib_archive_ENABLED=no - elif test "x$with_libarchive" = "xyes" ; then - st_lib_archive_ENABLED=yes - st_lib_archive_LOCATION=auto - else - st_lib_archive_ENABLED=yes - st_lib_archive_LOCATION=defined - if test -d "$with_libarchive" ; then - st_lib_archive_DIR="$with_libarchive" - else - AC_MSG_ERROR([$with_libarchive is not a directory]) - fi - fi], - [if test "x$1" = "xno" ; then - st_lib_archive_ENABLED=no - elif test "x$1" = "xyes" ; then - st_lib_archive_ENABLED=yes - else - st_lib_archive_ENABLED=yes - fi]) - -if test "$st_lib_archive_ENABLED" = "yes" ; then - AC_MSG_RESULT([yes]) -# -# After this statement, one trusted variable is defined. -# -# st_lib_archive_LIB will be either "lib" or "lib64", depending on whether the configurer -# specified 32, 64. The default is "lib". -# - AC_MSG_CHECKING([whether to use lib or lib64]) - AC_ARG_WITH([libarchive-bits], - AS_HELP_STRING([--with-libarchive-bits=32/64], [if 64, look in /lib64 on hybrid systems]), - [if test "x$with_libarchive_bits" = "x32" ; then - st_lib_archive_LIB=lib - elif test "x$with_libarchive_bits" = "x64" ; then - st_lib_archive_LIB=lib64 - else - AC_MSG_ERROR([the argument must be either 32 or 64]) - fi], - [st_lib_archive_LIB=lib]) - AC_MSG_RESULT($st_lib_archive_LIB) -# -# Save the environment before verifying libarchive availability -# - st_lib_archive_SAVECPPFLAGS="$CPPFLAGS" - st_lib_archive_SAVELDFLAGS="$LDFLAGS" - AC_LANG_SAVE - AC_LANG_C - - if test "x$st_lib_archive_LOCATION" = "xdefined" ; then - CPPFLAGS="-I$st_lib_archive_DIR/include $st_lib_archive_SAVECPPFLAGS" - LDFLAGS="-L$st_lib_archive_DIR/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS" - AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no]) - AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no]) - if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then - LIBARCHIVE_CPPFLAGS="-I$dir/include" - LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB" - else - AC_MSG_ERROR([could not find libarchive in the requested location]) - fi - else - # - # These are the common install directories for Linux, FreeBSD, Solaris, and Mac. - # - for dir in /usr /usr/local /usr/sfw /opt/csw /opt/local /sw - do - if test -d "$dir" ; then - CPPFLAGS="-I$dir/include $st_lib_archive_SAVECPPFLAGS" - LDFLAGS="-L$dir/$st_lib_archive_LIB $st_lib_archive_SAVELDFLAGS" - AC_CHECK_LIB(archive, archive_read_new, [st_lib_archive_found_lib=yes], [st_lib_archive_found_lib=no]) - AC_CHECK_HEADER(archive.h, [st_lib_archive_found_hdr=yes], [st_lib_archive_found_hdr=no]) - if test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes"; then - LIBARCHIVE_CPPFLAGS="-I$dir/include" - LIBARCHIVE_LDFLAGS="-L$dir/$st_lib_archive_LIB" - break - fi - fi - done - fi - - if test "x$st_lib_archive_found_hdr" = "xyes" && test "x$st_lib_archive_found_lib" = "xyes" ; then - LIBARCHIVE_LIBS="-larchive" - AC_DEFINE([HAVE_LIBARCHIVE], [1], [Defined to 1 if libarchive is available for use.]) - AC_SUBST(LIBARCHIVE_LIBS) - AC_SUBST(LIBARCHIVE_CPPFLAGS) - AC_SUBST(LIBARCHIVE_LDFLAGS) - fi - -# -# Restore the environment now that we're done. -# - AC_LANG_RESTORE - CPPFLAGS="$st_lib_archive_SAVECPPFLAGS" - LDFLAGS="$st_lib_archive_SAVELDFLAGS" -else - AC_MSG_RESULT([no]) -fi -AM_CONDITIONAL(LIBARCHIVE, test "x$st_lib_archive_found_lib" = "xyes" && test "x$st_lib_archive_found_hdr" = "xyes") -]) diff --git a/Utilities/cmlibarchive/contrib/psota-benchmark/results.txt b/Utilities/cmlibarchive/contrib/psota-benchmark/results.txt deleted file mode 100644 index 8197b28f7..000000000 --- a/Utilities/cmlibarchive/contrib/psota-benchmark/results.txt +++ /dev/null @@ -1,122 +0,0 @@ -ODP: [Bug-tar] GNU tar, star and BSD tar speed comparision +new script - -Jan Psota -Thu, 25 Oct 2007 06:51:13 -0700 - -Latest TCP script at the bottom (3180 bytes). -4 tests: 64bit dual core Athlon tmpfs / disk (reiserfs) - 60MB/s, - 32bit Athlon tmpfs / disk (reiserfs) - 55MB/s -Both machines were idle -- used for testing only. -Tarball and extracted files were on different physical devices. -Test data: linux 2.6.22/3 kernel sources for memory operations, -for the other data average file size should bring enough info. - -2 x [...] processor means 1 processor with 2 cores (2 entries in cpuinfo). -Archive format is set to pax (Joerg). -Let's end with it. I only wanted to send You a new version of TCP script :-). - --- -Jan Psota - -TCP, version 2007-10-25 -Linux 2.6.22-suspend2-r2 / Gentoo Base System release 2.0.0_rc5 -2012MB of memory, 2 x AMD Athlon(tm) 64 X2 Dual Core Processor 4200+ 2211.348 -512 KB 4426.24 bmips -gcc (GCC) 4.2.2 (Gentoo 4.2.2 p1.0) -CFLAGS="-O2 -march=k8 -pipe" - -bsdtar: bsdtar 2.3.4 - libarchive 2.3.4 -gnutar: tar (GNU tar) 1.19 -star: star: star 1.5a85 (x86_64-unknown-linux-gnu) - -best time of 5 repetitions, - src=linux-2.6.23, 291M in 23867 files, avg 13KB/file, - archive=/tmp/tcp.tar, extract to /tmp/tcptmp -program operation real user system %CPU speed -bsdtar create 0.764 0.232 0.532 99.96 370308 KB/s -gnutar create 0.743 0.200 0.512 95.87 380775 KB/s -star create 0.587 0.040 0.820 100.00 441247 KB/s - -bsdtar list 0.164 0.096 0.068 99.84 1579341 KB/s -gnutar list 0.218 0.064 0.152 98.92 1188128 KB/s -star list 0.359 0.044 0.240 79.09 721481 KB/s - -bsdtar extract 0.733 0.200 0.504 96.02 353358 KB/s -gnutar extract 0.625 0.092 0.508 96.02 414419 KB/s -star extract 0.875 0.096 0.980 100.00 296013 KB/s - -bsdtar compare 0.001 0.000 0.000 0.00 259012000 KB/s -gnutar compare 0.719 0.288 0.400 95.66 360239 KB/s -star compare 0.695 0.224 0.636 100.00 372679 KB/s - -[...] -best time of 3 repetitions, - src=/home, 3.2G in 7447 files, avg 554KB/file, - archive=/var/tcp.tar, extract to /mnt/a/tcptmp -program operation real user system %CPU speed -bsdtar create 184.680 0.552 13.365 7.53 17958 KB/s -gnutar create 159.240 0.256 12.417 7.95 20827 KB/s -star create 181.779 0.140 14.789 8.21 18203 KB/s - -bsdtar list 0.053 0.032 0.016 91.41 62435471 KB/s -gnutar list 56.535 0.136 3.764 6.89 58531 KB/s -star list 56.652 0.080 5.236 9.38 58410 KB/s - -bsdtar extract 78.914 0.820 15.149 20.23 41932 KB/s -gnutar extract 78.480 0.196 14.197 18.33 42164 KB/s -star extract 79.439 0.132 12.973 16.49 41655 KB/s - -bsdtar compare 0.001 0.000 0.000 0.00 3309080000 KB/s -gnutar compare 61.771 3.464 8.905 20.02 53570 KB/s -star compare 57.561 1.728 9.897 20.19 57488 KB/s - - -Linux 2.6.22-suspend2-smp / Gentoo Base System release 2.0.0_rc5 -504MB of memory, 1 x AMD Athlon(tm) Processor 1500.033 256 KB 3002.55 bmips -gcc (GCC) 4.2.2 (Gentoo 4.2.2 p1.0) -CFLAGS="-O2 -march=athlon-xp -mfpmath=sse -frename-registers -pipe" - -bsdtar: bsdtar 2.3.4 - libarchive 2.3.4 -gnutar: tar (GNU tar) 1.19 -star: star: star 1.5a85 (i686-pc-linux-gnu) - -best time of 3 repetitions, - src=/usr/src/linux-2.6.22-suspend2/drivers, 119M in 5900 files, - avg 21KB/file, archive=/tmp/tcp.tar, extract to /tmp/tcptmp -program operation real user system %CPU speed -bsdtar create 1.329 0.192 1.132 99.63 89784 KB/s -gnutar create 1.223 0.124 1.092 99.46 97566 KB/s -star create 1.848 0.036 1.708 94.36 61372 KB/s - -bsdtar list 0.167 0.060 0.108 100.00 679137 KB/s -gnutar list 0.161 0.040 0.124 100.00 704447 KB/s -star list 0.859 0.044 0.716 88.51 132032 KB/s - -bsdtar extract 1.186 0.172 1.012 99.87 95629 KB/s -gnutar extract 1.064 0.056 1.004 99.63 106593 KB/s -star extract 1.920 0.088 1.724 94.40 59070 KB/s - -bsdtar compare 0.002 0.000 0.000 0.00 56708000 KB/s -gnutar compare 0.925 0.232 0.692 99.90 122611 KB/s -star compare 1.569 0.376 1.096 93.79 72285 KB/s - -[...] -best time of 3 repetitions, - src=/home/jasiu, 2.1G in 8416 files, avg 277KB/file, - archive=/home/j2/tcp.tar, extract to /mnt/a/tar/tcptmp -program operation real user system %CPU speed -bsdtar create 182.171 1.692 29.130 16.91 11584 KB/s -gnutar create 174.999 0.632 27.450 16.04 12059 KB/s -star create 180.004 0.360 41.795 23.41 11677 KB/s - -bsdtar list 0.214 0.076 0.136 99.04 9822294 KB/s -gnutar list 0.210 0.076 0.136 100.00 10009385 KB/s -star list 43.462 0.148 18.109 42.00 48363 KB/s - -bsdtar extract 94.912 4.476 31.574 37.98 22146 KB/s -gnutar extract 94.657 0.396 29.462 31.54 22206 KB/s -star extract 100.814 0.400 39.906 39.98 20849 KB/s - -bsdtar compare 0.003 0.000 0.004 100.00 700657000 KB/s -gnutar compare 80.174 3.932 20.365 30.30 26217 KB/s -star compare 73.911 8.341 27.670 48.72 28439 KB/s diff --git a/Utilities/cmlibarchive/contrib/psota-benchmark/tcp.sh b/Utilities/cmlibarchive/contrib/psota-benchmark/tcp.sh deleted file mode 100755 index 6c0e4b5e9..000000000 --- a/Utilities/cmlibarchive/contrib/psota-benchmark/tcp.sh +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/sh -# tar comparision program -# 2007-10-25 Jan Psota - -n=3 # number of repetitions -TAR=(bsdtar gnutar star) # TApeArchivers to compare -OPT=("" "--seek" "-no-fsync") -pax="--format=pax" # comment out for defaults -OPN=(create list extract compare) # operations -version="2007-10-25" -TIMEFORMAT=$'%R\t%U\t%S\t%P' -LC_ALL=C - -test $# -ge 2 || { - echo -e "usage:\t$0 source_dir where_to_place_archive -[where_to_extract_it] - -TCP, version $version -TCP stands for Tar Comparision Program here. -It currently compares: BSD tar (bsdtar), GNU tar (gnutar) and star in archive -creation, listing, extraction and archive-to-extracted comparision. -Tcp prints out best time of n=$n repetitions. - -Tcp creates temporary archive named tcp.tar with $pax and some native -(--seek/-no-fsync) options and extracts it to [\$3]/tcptmp/. -If unset, third argument defaults to [\$2]. -After normal exit tcp removes tarball and extracted files. -Tcp does not check filesystems destination directories are on for free space, -so make sure there is enough space (a bit more than source_dir uses) for both: -archive and extracted files. -Do not use white space in arguments. - Jan Psota, $version" - exit 0 -} -src=$1 -dst=$2/tcp.tar -dst_path=${3:-$2}/tcptmp -test -e $dst -o -e /tmp/tcp \ - && { echo "$dst or /tmp/tcp exists, exiting"; exit 1; } -mkdir $dst_path || exit 2 - -use_times () -{ - awk -F"\t" -vN=$n -vL="`du -k $dst`" -vOFS="\t" -vORS="" ' - { if (NF==4) { printf "\t%s\t%10.1d KB/s\n", $0, ($1+0>0 ? -(L+0)/($1+0) : 0) } }' \ - /tmp/tcp | sort | head -1 - > /tmp/tcp -} - -test -d $src || { echo "'$src' is not a directory"; exit 3; } - -# system information: type, release, memory, cpu(s), compiler and flags -echo -e "TCP, version $version\n"`uname -sr`" / "`head -1 /etc/*-release` -free -m | awk '/^Mem/ { printf "%dMB of memory, ", $2 }' -test -e /proc/cpuinfo \ - && awk -F: '/name|cache size|MHz|mips/ { if (!a) b=b $2 } - /^$/ { a++ } END { print a" x"b" bmips" }' /proc/cpuinfo -test -e /etc/gentoo-release \ - && gcc --version | head -1 && grep ^CFLAGS /etc/make.conf - -# tar versions -echo -for tar in [EMAIL PROTECTED]; do echo -ne "$tar:\t"; $tar --version | head -1; -done - -echo -e "\nbest time of $n repetitions,\n"\ -" src=$src, "\ -`du -sh $src | awk '{print $1}'`" in "`find $src | wc -l`" files, "\ -"avg "$((`du -sk $src | awk '{print $1}'`/`find $src -type f | wc --l`))"KB/file,\n"\ -" archive=$dst, extract to $dst_path" - -echo -e "program\toperation\treal\tuser\tsystem\t%CPU\t speed" -> /tmp/tcp -let op_num=0 -for op in "cf $dst $pax -C $src ." "tf $dst" "xf $dst -C $dst_path" \ - "f $dst -C $dst_path --diff"; do - let tar_num=0 - for tar in [EMAIL PROTECTED]; do - echo -en "$tar\t${OPN[op_num]}\t" - for ((i=1; i<=$n; i++)); do - echo $op | grep -q ^cf && rm -f $dst - echo $op | grep -q ^xf && - { chmod -R u+w $dst_path - rm -rf $dst_path; mkdir $dst_path; } - sync - if echo $op | grep -q ^f; then # op == compare - time $tar $op ${OPT[$tar_num]} > /dev/null - else # op in (create | list | extract) - time $tar $op ${OPT[$tar_num]} > /dev/null \ - || break 3 - fi 2>> /tmp/tcp - done - use_times - let tar_num++ - done - let op_num++ - echo -done -rm -rf $dst_path $dst -echo -cat /tmp/tcp -rm -f /tmp/tcp diff --git a/Utilities/cmlibarchive/contrib/shar/shar.1 b/Utilities/cmlibarchive/contrib/shar/shar.1 deleted file mode 100644 index 151590dfb..000000000 --- a/Utilities/cmlibarchive/contrib/shar/shar.1 +++ /dev/null @@ -1,128 +0,0 @@ -.\" Copyright (c) 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)shar.1 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD$ -.\" -.Dd April 17, 2008 -.Dt SHAR 1 -.Os -.Sh NAME -.Nm shar -.Nd create a shell archive of files -.Sh SYNOPSIS -.Nm -.Op Fl br -.Op Fl o Ar archive-file -.Ar -.Sh DESCRIPTION -The -.Nm -command writes a -.Xr sh 1 -shell script which will recreate the file hierarchy specified by the command -line operands. -.Pp -The -.Nm -command is normally used for distributing files by -.Xr ftp 1 -or -.Xr mail 1 . -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl b -Use an alternative binary format. Content of files will be uuencoded. -This option should be used to archive binary files correctly. -In this mode also file permissions will be stored to the archive. -uudecode(1) is needed to extract archives created with this option. -.It Fl o Ar archive-file -Redirect output to -.Ar archive-file . -.It Fl r -If -.Ar file -given on command line is a directory the entire subtree will be archived. -Symbolic links given on command line are followed. Other symbolic links will -be archived as such. -.El -.Sh EXAMPLES -To create a shell archive of the program -.Xr ls 1 -and mail it to Rick: -.Bd -literal -offset indent -cd ls -shar -r . \&| mail -s "ls source" rick -.Ed -.Pp -To recreate the program directory: -.Bd -literal -offset indent -mkdir ls -cd ls -\&... - -\&... -sh archive -.Ed -.Sh SEE ALSO -.Xr compress 1 , -.Xr mail 1 , -.Xr tar 1 , -.Xr uuencode 1 , -.Xr uuencode 5 -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.4 . -This is a re-implementation based on the libarchive(3) library. -.Sh BUGS -The -.Nm -command makes no provisions for hard links. -.Pp -Files containing magic characters or files without a newline ('\\n') as the -last character are not handled correctly with the default format. Use the -b -option for binary files. -.Pp -It is easy to insert trojan horses into -.Nm -files. -It is strongly recommended that all shell archive files be examined -before running them through -.Xr sh 1 . -Archives produced using this implementation of -.Nm -may be easily examined with the command: -.Bd -literal -offset indent -egrep -v '^[X#]' shar.file -.Ed diff --git a/Utilities/cmlibarchive/contrib/shar/shar.c b/Utilities/cmlibarchive/contrib/shar/shar.c deleted file mode 100644 index 91ab2b5f0..000000000 --- a/Utilities/cmlibarchive/contrib/shar/shar.c +++ /dev/null @@ -1,314 +0,0 @@ -/*- - * Copyright (c) 2008 Jaakko Heinonen - * 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 - * in this position and unchanged. - * 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 -#ifdef __FBSDID -__FBSDID("$FreeBSD$"); -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "tree.h" - -/* command line options */ -static int b_opt; /* use alternative shar binary format */ -static int r_opt; /* recurse into subdirectories */ -static char *o_arg; /* output file name */ - -static void -usage(void) -{ - fprintf(stderr, "Usage: shar [-br] [-o filename] file ...\n"); - exit(EX_USAGE); -} - -/* - * Initialize archive structure and create a shar archive. - */ -static struct archive * -shar_create(void) -{ - struct archive *a; - - if ((a = archive_write_new()) == NULL) - errx(EXIT_FAILURE, "%s", archive_error_string(a)); - - if (b_opt) - archive_write_set_format_shar_dump(a); - else - archive_write_set_format_shar(a); - archive_write_set_compression_none(a); - - if (archive_write_open_filename(a, o_arg) != ARCHIVE_OK) - errx(EX_CANTCREAT, "%s", archive_error_string(a)); - - return (a); -} - -/* buffer for file data */ -static char buffer[32768]; - -/* - * Write file data to an archive entry. - */ -static int -shar_write_entry_data(struct archive *a, const int fd) -{ - ssize_t bytes_read, bytes_written; - - assert(a != NULL); - assert(fd >= 0); - - bytes_read = read(fd, buffer, sizeof(buffer)); - while (bytes_read != 0) { - if (bytes_read < 0) { - archive_set_error(a, errno, "Read failed"); - return (ARCHIVE_WARN); - } - bytes_written = archive_write_data(a, buffer, bytes_read); - if (bytes_written < 0) - return (ARCHIVE_WARN); - bytes_read = read(fd, buffer, sizeof(buffer)); - } - - return (ARCHIVE_OK); -} - -/* - * Write a file to the archive. We have special handling for symbolic links. - */ -static int -shar_write_entry(struct archive *a, const char *pathname, const char *accpath, - const struct stat *st) -{ - struct archive_entry *entry; - int fd = -1; - int ret = ARCHIVE_OK; - - assert(a != NULL); - assert(pathname != NULL); - assert(accpath != NULL); - assert(st != NULL); - - entry = archive_entry_new(); - - if (S_ISREG(st->st_mode) && st->st_size > 0) { - /* regular file */ - if ((fd = open(accpath, O_RDONLY)) == -1) { - warn("%s", accpath); - ret = ARCHIVE_WARN; - goto out; - } - } else if (S_ISLNK(st->st_mode)) { - /* symbolic link */ - char lnkbuff[PATH_MAX + 1]; - int lnklen; - if ((lnklen = readlink(accpath, lnkbuff, PATH_MAX)) == -1) { - warn("%s", accpath); - ret = ARCHIVE_WARN; - goto out; - } - lnkbuff[lnklen] = '\0'; - archive_entry_set_symlink(entry, lnkbuff); - } - archive_entry_copy_stat(entry, st); - archive_entry_set_pathname(entry, pathname); - if (!S_ISREG(st->st_mode) || st->st_size == 0) - archive_entry_set_size(entry, 0); - if (archive_write_header(a, entry) != ARCHIVE_OK) { - warnx("%s: %s", pathname, archive_error_string(a)); - ret = ARCHIVE_WARN; - goto out; - } - if (fd >= 0) { - if ((ret = shar_write_entry_data(a, fd)) != ARCHIVE_OK) - warnx("%s: %s", accpath, archive_error_string(a)); - } -out: - archive_entry_free(entry); - if (fd >= 0) - close(fd); - - return (ret); -} - -/* - * Write singe path to the archive. The path can be a regular file, directory - * or device. Symbolic links are followed. - */ -static int -shar_write_path(struct archive *a, const char *pathname) -{ - struct stat st; - - assert(a != NULL); - assert(pathname != NULL); - - if ((stat(pathname, &st)) == -1) { - warn("%s", pathname); - return (ARCHIVE_WARN); - } - - return (shar_write_entry(a, pathname, pathname, &st)); -} - -/* - * Write tree to the archive. If pathname is a symbolic link it will be - * followed. Other symbolic links are stored as such to the archive. - */ -static int -shar_write_tree(struct archive *a, const char *pathname) -{ - struct tree *t; - const struct stat *lst, *st; - int error = 0; - int tree_ret; - int first; - - assert(a != NULL); - assert(pathname != NULL); - - t = tree_open(pathname); - for (first = 1; (tree_ret = tree_next(t)); first = 0) { - if (tree_ret == TREE_ERROR_DIR) { - warnx("%s: %s", tree_current_path(t), - strerror(tree_errno(t))); - error = 1; - continue; - } else if (tree_ret != TREE_REGULAR) - continue; - if ((lst = tree_current_lstat(t)) == NULL) { - warn("%s", tree_current_path(t)); - error = 1; - continue; - } - /* - * If the symlink was given on command line then - * follow it rather than write it as symlink. - */ - if (first && S_ISLNK(lst->st_mode)) { - if ((st = tree_current_stat(t)) == NULL) { - warn("%s", tree_current_path(t)); - error = 1; - continue; - } - } else - st = lst; - - if (shar_write_entry(a, tree_current_path(t), - tree_current_access_path(t), st) != ARCHIVE_OK) - error = 1; - - tree_descend(t); - } - - tree_close(t); - - return ((error != 0) ? ARCHIVE_WARN : ARCHIVE_OK); -} - -/* - * Create a shar archive and write files/trees into it. - */ -static int -shar_write(char **fn, size_t nfn) -{ - struct archive *a; - size_t i; - int error = 0; - - assert(fn != NULL); - assert(nfn > 0); - - a = shar_create(); - - for (i = 0; i < nfn; i++) { - if (r_opt) { - if (shar_write_tree(a, fn[i]) != ARCHIVE_OK) - error = 1; - } else { - if (shar_write_path(a, fn[i]) != ARCHIVE_OK) - error = 1; - } - } - - if (archive_write_finish(a) != ARCHIVE_OK) - errx(EXIT_FAILURE, "%s", archive_error_string(a)); - - if (error != 0) - warnx("Error exit delayed from previous errors."); - - return (error); -} - -int -main(int argc, char **argv) -{ - int opt; - - while ((opt = getopt(argc, argv, "bro:")) != -1) { - switch (opt) { - case 'b': - b_opt = 1; - break; - case 'o': - o_arg = optarg; - break; - case 'r': - r_opt = 1; - break; - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if(argc < 1) - usage(); - - if (shar_write(argv, argc) != 0) - exit(EXIT_FAILURE); - else - exit(EXIT_SUCCESS); - /* NOTREACHED */ -} - diff --git a/Utilities/cmlibarchive/contrib/shar/tree.c b/Utilities/cmlibarchive/contrib/shar/tree.c deleted file mode 100644 index 594afd492..000000000 --- a/Utilities/cmlibarchive/contrib/shar/tree.c +++ /dev/null @@ -1,542 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - */ - -/*- - * This is a new directory-walking system that addresses a number - * of problems I've had with fts(3). In particular, it has no - * pathname-length limits (other than the size of 'int'), handles - * deep logical traversals, uses considerably less memory, and has - * an opaque interface (easier to modify in the future). - * - * Internally, it keeps a single list of "tree_entry" items that - * represent filesystem objects that require further attention. - * Non-directories are not kept in memory: they are pulled from - * readdir(), returned to the client, then freed as soon as possible. - * Any directory entry to be traversed gets pushed onto the stack. - * - * There is surprisingly little information that needs to be kept for - * each item on the stack. Just the name, depth (represented here as the - * string length of the parent directory's pathname), and some markers - * indicating how to get back to the parent (via chdir("..") for a - * regular dir or via fchdir(2) for a symlink). - */ -#include "tree_config.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_DIRENT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "tree.h" - -/* - * TODO: - * 1) Loop checking. - * 3) Arbitrary logical traversals by closing/reopening intermediate fds. - */ - -struct tree_entry { - struct tree_entry *next; - struct tree_entry *parent; - char *name; - size_t dirname_length; - dev_t dev; - ino_t ino; - int fd; - int flags; -}; - -/* Definitions for tree_entry.flags bitmap. */ -#define isDir 1 /* This entry is a regular directory. */ -#define isDirLink 2 /* This entry is a symbolic link to a directory. */ -#define needsPreVisit 4 /* This entry needs to be previsited. */ -#define needsPostVisit 8 /* This entry needs to be postvisited. */ - -/* - * Local data for this package. - */ -struct tree { - struct tree_entry *stack; - struct tree_entry *current; - DIR *d; - int initialDirFd; - int flags; - int visit_type; - int tree_errno; /* Error code from last failed operation. */ - - char *buff; - const char *basename; - size_t buff_length; - size_t path_length; - size_t dirname_length; - - int depth; - int openCount; - int maxOpenCount; - - struct stat lst; - struct stat st; -}; - -/* Definitions for tree.flags bitmap. */ -#define needsReturn 8 /* Marks first entry as not having been returned yet. */ -#define hasStat 16 /* The st entry is set. */ -#define hasLstat 32 /* The lst entry is set. */ - - -#ifdef HAVE_DIRENT_D_NAMLEN -/* BSD extension; avoids need for a strlen() call. */ -#define D_NAMELEN(dp) (dp)->d_namlen -#else -#define D_NAMELEN(dp) (strlen((dp)->d_name)) -#endif - -#if 0 -#include -void -tree_dump(struct tree *t, FILE *out) -{ - struct tree_entry *te; - - fprintf(out, "\tdepth: %d\n", t->depth); - fprintf(out, "\tbuff: %s\n", t->buff); - fprintf(out, "\tpwd: "); fflush(stdout); system("pwd"); - fprintf(out, "\taccess: %s\n", t->basename); - fprintf(out, "\tstack:\n"); - for (te = t->stack; te != NULL; te = te->next) { - fprintf(out, "\t\tte->name: %s%s%s\n", te->name, - te->flags & needsPreVisit ? "" : " *", - t->current == te ? " (current)" : ""); - } -} -#endif - -/* - * Add a directory path to the current stack. - */ -static void -tree_push(struct tree *t, const char *path) -{ - struct tree_entry *te; - - te = malloc(sizeof(*te)); - memset(te, 0, sizeof(*te)); - te->next = t->stack; - t->stack = te; - te->fd = -1; - te->name = strdup(path); - te->flags = needsPreVisit | needsPostVisit; - te->dirname_length = t->dirname_length; -} - -/* - * Append a name to the current path. - */ -static void -tree_append(struct tree *t, const char *name, size_t name_length) -{ - char *p; - - if (t->buff != NULL) - t->buff[t->dirname_length] = '\0'; - /* Strip trailing '/' from name, unless entire name is "/". */ - while (name_length > 1 && name[name_length - 1] == '/') - name_length--; - - /* Resize pathname buffer as needed. */ - while (name_length + 1 + t->dirname_length >= t->buff_length) { - t->buff_length *= 2; - if (t->buff_length < 1024) - t->buff_length = 1024; - t->buff = realloc(t->buff, t->buff_length); - } - p = t->buff + t->dirname_length; - t->path_length = t->dirname_length + name_length; - /* Add a separating '/' if it's needed. */ - if (t->dirname_length > 0 && p[-1] != '/') { - *p++ = '/'; - t->path_length ++; - } - strncpy(p, name, name_length); - p[name_length] = '\0'; - t->basename = p; -} - -/* - * Open a directory tree for traversal. - */ -struct tree * -tree_open(const char *path) -{ - struct tree *t; - - t = malloc(sizeof(*t)); - memset(t, 0, sizeof(*t)); - tree_append(t, path, strlen(path)); - t->initialDirFd = open(".", O_RDONLY); - /* - * During most of the traversal, items are set up and then - * returned immediately from tree_next(). That doesn't work - * for the very first entry, so we set a flag for this special - * case. - */ - t->flags = needsReturn; - return (t); -} - -/* - * We've finished a directory; ascend back to the parent. - */ -static void -tree_ascend(struct tree *t) -{ - struct tree_entry *te; - - te = t->stack; - t->depth--; - if (te->flags & isDirLink) { - fchdir(te->fd); - close(te->fd); - t->openCount--; - } else { - chdir(".."); - } -} - -/* - * Pop the working stack. - */ -static void -tree_pop(struct tree *t) -{ - struct tree_entry *te; - - t->buff[t->dirname_length] = '\0'; - if (t->stack == t->current && t->current != NULL) - t->current = t->current->parent; - te = t->stack; - t->stack = te->next; - t->dirname_length = te->dirname_length; - t->basename = t->buff + t->dirname_length; - /* Special case: starting dir doesn't skip leading '/'. */ - if (t->dirname_length > 0) - t->basename++; - free(te->name); - free(te); -} - -/* - * Get the next item in the tree traversal. - */ -int -tree_next(struct tree *t) -{ - struct dirent *de = NULL; - - /* Handle the startup case by returning the initial entry. */ - if (t->flags & needsReturn) { - t->flags &= ~needsReturn; - return (t->visit_type = TREE_REGULAR); - } - - while (t->stack != NULL) { - /* If there's an open dir, get the next entry from there. */ - while (t->d != NULL) { - de = readdir(t->d); - if (de == NULL) { - closedir(t->d); - t->d = NULL; - } else if (de->d_name[0] == '.' - && de->d_name[1] == '\0') { - /* Skip '.' */ - } else if (de->d_name[0] == '.' - && de->d_name[1] == '.' - && de->d_name[2] == '\0') { - /* Skip '..' */ - } else { - /* - * Append the path to the current path - * and return it. - */ - tree_append(t, de->d_name, D_NAMELEN(de)); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - return (t->visit_type = TREE_REGULAR); - } - } - - /* If the current dir needs to be visited, set it up. */ - if (t->stack->flags & needsPreVisit) { - t->current = t->stack; - tree_append(t, t->stack->name, strlen(t->stack->name)); - t->stack->flags &= ~needsPreVisit; - /* If it is a link, set up fd for the ascent. */ - if (t->stack->flags & isDirLink) { - t->stack->fd = open(".", O_RDONLY); - t->openCount++; - if (t->openCount > t->maxOpenCount) - t->maxOpenCount = t->openCount; - } - t->dirname_length = t->path_length; - if (chdir(t->stack->name) != 0) { - /* chdir() failed; return error */ - tree_pop(t); - t->tree_errno = errno; - return (t->visit_type = TREE_ERROR_DIR); - } - t->depth++; - t->d = opendir("."); - if (t->d == NULL) { - tree_ascend(t); /* Undo "chdir" */ - tree_pop(t); - t->tree_errno = errno; - return (t->visit_type = TREE_ERROR_DIR); - } - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - t->basename = "."; - return (t->visit_type = TREE_POSTDESCENT); - } - - /* We've done everything necessary for the top stack entry. */ - if (t->stack->flags & needsPostVisit) { - tree_ascend(t); - tree_pop(t); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - return (t->visit_type = TREE_POSTASCENT); - } - } - return (t->visit_type = 0); -} - -/* - * Return error code. - */ -int -tree_errno(struct tree *t) -{ - return (t->tree_errno); -} - -/* - * Called by the client to mark the directory just returned from - * tree_next() as needing to be visited. - */ -void -tree_descend(struct tree *t) -{ - if (t->visit_type != TREE_REGULAR) - return; - - if (tree_current_is_physical_dir(t)) { - tree_push(t, t->basename); - t->stack->flags |= isDir; - } else if (tree_current_is_dir(t)) { - tree_push(t, t->basename); - t->stack->flags |= isDirLink; - } -} - -/* - * Get the stat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_stat(struct tree *t) -{ - if (!(t->flags & hasStat)) { - if (stat(t->basename, &t->st) != 0) - return NULL; - t->flags |= hasStat; - } - return (&t->st); -} - -/* - * Get the lstat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_lstat(struct tree *t) -{ - if (!(t->flags & hasLstat)) { - if (lstat(t->basename, &t->lst) != 0) - return NULL; - t->flags |= hasLstat; - } - return (&t->lst); -} - -/* - * Test whether current entry is a dir or link to a dir. - */ -int -tree_current_is_dir(struct tree *t) -{ - const struct stat *st; - - /* - * If we already have lstat() info, then try some - * cheap tests to determine if this is a dir. - */ - if (t->flags & hasLstat) { - /* If lstat() says it's a dir, it must be a dir. */ - if (S_ISDIR(tree_current_lstat(t)->st_mode)) - return 1; - /* Not a dir; might be a link to a dir. */ - /* If it's not a link, then it's not a link to a dir. */ - if (!S_ISLNK(tree_current_lstat(t)->st_mode)) - return 0; - /* - * It's a link, but we don't know what it's a link to, - * so we'll have to use stat(). - */ - } - - st = tree_current_stat(t); - /* If we can't stat it, it's not a dir. */ - if (st == NULL) - return 0; - /* Use the definitive test. Hopefully this is cached. */ - return (S_ISDIR(st->st_mode)); -} - -/* - * Test whether current entry is a physical directory. Usually, we - * already have at least one of stat() or lstat() in memory, so we - * use tricks to try to avoid an extra trip to the disk. - */ -int -tree_current_is_physical_dir(struct tree *t) -{ - const struct stat *st; - - /* - * If stat() says it isn't a dir, then it's not a dir. - * If stat() data is cached, this check is free, so do it first. - */ - if ((t->flags & hasStat) - && (!S_ISDIR(tree_current_stat(t)->st_mode))) - return 0; - - /* - * Either stat() said it was a dir (in which case, we have - * to determine whether it's really a link to a dir) or - * stat() info wasn't available. So we use lstat(), which - * hopefully is already cached. - */ - - st = tree_current_lstat(t); - /* If we can't stat it, it's not a dir. */ - if (st == NULL) - return 0; - /* Use the definitive test. Hopefully this is cached. */ - return (S_ISDIR(st->st_mode)); -} - -/* - * Test whether current entry is a symbolic link. - */ -int -tree_current_is_physical_link(struct tree *t) -{ - const struct stat *st = tree_current_lstat(t); - if (st == NULL) - return 0; - return (S_ISLNK(st->st_mode)); -} - -/* - * Return the access path for the entry just returned from tree_next(). - */ -const char * -tree_current_access_path(struct tree *t) -{ - return (t->basename); -} - -/* - * Return the full path for the entry just returned from tree_next(). - */ -const char * -tree_current_path(struct tree *t) -{ - return (t->buff); -} - -/* - * Return the length of the path for the entry just returned from tree_next(). - */ -size_t -tree_current_pathlen(struct tree *t) -{ - return (t->path_length); -} - -/* - * Return the nesting depth of the entry just returned from tree_next(). - */ -int -tree_current_depth(struct tree *t) -{ - return (t->depth); -} - -/* - * Terminate the traversal and release any resources. - */ -void -tree_close(struct tree *t) -{ - /* Release anything remaining in the stack. */ - while (t->stack != NULL) - tree_pop(t); - if (t->buff) - free(t->buff); - /* chdir() back to where we started. */ - if (t->initialDirFd >= 0) { - fchdir(t->initialDirFd); - close(t->initialDirFd); - t->initialDirFd = -1; - } - free(t); -} diff --git a/Utilities/cmlibarchive/contrib/shar/tree.h b/Utilities/cmlibarchive/contrib/shar/tree.h deleted file mode 100644 index f99e918cc..000000000 --- a/Utilities/cmlibarchive/contrib/shar/tree.h +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD$ - */ - -/*- - * A set of routines for traversing directory trees. - * Similar in concept to the fts library, but with a few - * important differences: - * * Uses less memory. In particular, fts stores an entire directory - * in memory at a time. This package only keeps enough subdirectory - * information in memory to track the traversal. Information - * about non-directories is discarded as soon as possible. - * * Supports very deep logical traversals. The fts package - * uses "non-chdir" approach for logical traversals. This - * package does use a chdir approach for logical traversals - * and can therefore handle pathnames much longer than - * PATH_MAX. - * * Supports deep physical traversals "out of the box." - * Due to the memory optimizations above, there's no need to - * limit dir names to 32k. - */ - -#include -#include - -struct tree; - -/* Initiate/terminate a tree traversal. */ -struct tree *tree_open(const char * /* pathname */); -void tree_close(struct tree *); - -/* - * tree_next() returns Zero if there is no next entry, non-zero if there is. - * Note that directories are potentially visited three times. The first - * time as "regular" file. If tree_descend() is invoked at that time, - * the directory is added to a work list and will be visited two more - * times: once just after descending into the directory and again - * just after ascending back to the parent. - * - * TREE_ERROR is returned if the descent failed (because the - * directory couldn't be opened, for instance). This is returned - * instead of TREE_PREVISIT/TREE_POSTVISIT. - */ -#define TREE_REGULAR 1 -#define TREE_POSTDESCENT 2 -#define TREE_POSTASCENT 3 -#define TREE_ERROR_DIR -1 -int tree_next(struct tree *); - -int tree_errno(struct tree *); - -/* - * Request that current entry be visited. If you invoke it on every - * directory, you'll get a physical traversal. This is ignored if the - * current entry isn't a directory or a link to a directory. So, if - * you invoke this on every returned path, you'll get a full logical - * traversal. - */ -void tree_descend(struct tree *); - -/* - * Return information about the current entry. - */ - -int tree_current_depth(struct tree *); -/* - * The current full pathname, length of the full pathname, - * and a name that can be used to access the file. - * Because tree does use chdir extensively, the access path is - * almost never the same as the full current path. - */ -const char *tree_current_path(struct tree *); -size_t tree_current_pathlen(struct tree *); -const char *tree_current_access_path(struct tree *); -/* - * Request the lstat() or stat() data for the current path. Since the - * tree package needs to do some of this anyway, and caches the - * results, you should take advantage of it here if you need it rather - * than make a redundant stat() or lstat() call of your own. - */ -const struct stat *tree_current_stat(struct tree *); -const struct stat *tree_current_lstat(struct tree *); -/* The following tests may use mechanisms much faster than stat()/lstat(). */ -/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */ -int tree_current_is_physical_dir(struct tree *); -/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */ -int tree_current_is_physical_link(struct tree *); -/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */ -int tree_current_is_dir(struct tree *); - -/* For testing/debugging: Dump the internal status to the given filehandle. */ -void tree_dump(struct tree *, FILE *); diff --git a/Utilities/cmlibarchive/contrib/shar/tree_config.h b/Utilities/cmlibarchive/contrib/shar/tree_config.h deleted file mode 100644 index 6e2cd7ccd..000000000 --- a/Utilities/cmlibarchive/contrib/shar/tree_config.h +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD$ - */ -#ifndef TREE_CONFIG_H_INCLUDED -#define TREE_CONFIG_H_INCLUDED - -#if defined(PLATFORM_CONFIG_H) -/* - * Use hand-built config.h in environments that need it. - */ -#include PLATFORM_CONFIG_H -#elif defined(HAVE_CONFIG_H) -/* - * Most POSIX platforms use the 'configure' script to build config.h - */ -#include "../config.h" -#elif defined(__FreeBSD__) -/* - * Built-in definitions for FreeBSD. - */ -#define HAVE_DIRENT_D_NAMLEN 1 -#define HAVE_DIRENT_H 1 -#define HAVE_ERRNO_H 1 -#define HAVE_FCNTL_H 1 -#define HAVE_LIBARCHIVE 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRING_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_UNISTD_H 1 -#else -/* - * Warn if there's no platform configuration. - */ -#error Oops: No config.h and no built-in configuration in bsdtar_platform.h. -#endif /* !HAVE_CONFIG_H */ - -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ -#define __FBSDID(a) struct _undefined_hack -#endif - -#ifdef HAVE_LIBARCHIVE -/* If we're using the platform libarchive, include system headers. */ -#include -#include -#else -/* Otherwise, include user headers. */ -#include "archive.h" -#include "archive_entry.h" -#endif - -#endif /* !TREE_CONFIG_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/contrib/untar.c b/Utilities/cmlibarchive/contrib/untar.c deleted file mode 100644 index 0ea645541..000000000 --- a/Utilities/cmlibarchive/contrib/untar.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * "untar" is an extremely simple tar extractor: - * * A single C source file, so it should be easy to compile - * and run on any system with a C compiler. - * * Extremely portable standard C. The only non-ANSI function - * used is mkdir(). - * * Reads basic ustar tar archives. - * * Does not require libarchive or any other special library. - * - * To compile: cc -o untar untar.c - * - * Usage: untar - * - * In particular, this program should be sufficient to extract the - * distribution for libarchive, allowing people to bootstrap - * libarchive on systems that do not already have a tar program. - * - * To unpack libarchive-x.y.z.tar.gz: - * * gunzip libarchive-x.y.z.tar.gz - * * untar libarchive-x.y.z.tar - * - * Written by Tim Kientzle, March 2009. - * - * Released into the public domain. - */ - -/* These are all highly standard and portable headers. */ -#include -#include -#include - -/* This is for mkdir(); this may need to be changed for some platforms. */ -#include /* For mkdir() */ - -/* Parse an octal number, ignoring leading and trailing nonsense. */ -static int -parseoct(const char *p, size_t n) -{ - int i = 0; - - while (*p < '0' || *p > '7') { - ++p; - --n; - } - while (*p >= '0' && *p <= '7' && n > 0) { - i *= 8; - i += *p - '0'; - ++p; - --n; - } - return (i); -} - -/* Returns true if this is 512 zero bytes. */ -static int -is_end_of_archive(const char *p) -{ - int n; - for (n = 511; n >= 0; --n) - if (p[n] != '\0') - return (0); - return (1); -} - -/* Create a directory, including parent directories as necessary. */ -static void -create_dir(char *pathname, int mode) -{ - char *p; - int r; - - /* Strip trailing '/' */ - if (pathname[strlen(pathname) - 1] == '/') - pathname[strlen(pathname) - 1] = '\0'; - - /* Try creating the directory. */ - r = mkdir(pathname, mode); - - if (r != 0) { - /* On failure, try creating parent directory. */ - p = strrchr(pathname, '/'); - if (p != NULL) { - *p = '\0'; - create_dir(pathname, 0755); - *p = '/'; - r = mkdir(pathname, mode); - } - } - if (r != 0) - fprintf(stderr, "Could not create directory %s\n", pathname); -} - -/* Create a file, including parent directory as necessary. */ -static FILE * -create_file(char *pathname, int mode) -{ - FILE *f; - f = fopen(pathname, "w+"); - if (f == NULL) { - /* Try creating parent dir and then creating file. */ - char *p = strrchr(pathname, '/'); - if (p != NULL) { - *p = '\0'; - create_dir(pathname, 0755); - *p = '/'; - f = fopen(pathname, "w+"); - } - } - return (f); -} - -/* Verify the tar checksum. */ -static int -verify_checksum(const char *p) -{ - int n, u = 0; - for (n = 0; n < 512; ++n) { - if (n < 148 || n > 155) - /* Standard tar checksum adds unsigned bytes. */ - u += ((unsigned char *)p)[n]; - else - u += 0x20; - - } - return (u == parseoct(p + 148, 8)); -} - -/* Extract a tar archive. */ -static void -untar(FILE *a, const char *path) -{ - char buff[512]; - FILE *f = NULL; - size_t bytes_read; - int filesize; - - printf("Extracting from %s\n", path); - for (;;) { - bytes_read = fread(buff, 1, 512, a); - if (bytes_read < 512) { - fprintf(stderr, - "Short read on %s: expected 512, got %d\n", - path, bytes_read); - return; - } - if (is_end_of_archive(buff)) { - printf("End of %s\n", path); - return; - } - if (!verify_checksum(buff)) { - fprintf(stderr, "Checksum failure\n"); - return; - } - filesize = parseoct(buff + 124, 12); - switch (buff[156]) { - case '1': - printf(" Ignoring hardlink %s\n", buff); - break; - case '2': - printf(" Ignoring symlink %s\n", buff); - break; - case '3': - printf(" Ignoring character device %s\n", buff); - break; - case '4': - printf(" Ignoring block device %s\n", buff); - break; - case '5': - printf(" Extracting dir %s\n", buff); - create_dir(buff, parseoct(buff + 100, 8)); - filesize = 0; - break; - case '6': - printf(" Ignoring FIFO %s\n", buff); - break; - default: - printf(" Extracting file %s\n", buff); - f = create_file(buff, parseoct(buff + 100, 8)); - break; - } - while (filesize > 0) { - bytes_read = fread(buff, 1, 512, a); - if (bytes_read < 512) { - fprintf(stderr, - "Short read on %s: Expected 512, got %d\n", - path, bytes_read); - return; - } - if (filesize < 512) - bytes_read = filesize; - if (f != NULL) { - if (fwrite(buff, 1, bytes_read, f) - != bytes_read) - { - fprintf(stderr, "Failed write\n"); - fclose(f); - f = NULL; - } - } - filesize -= bytes_read; - } - if (f != NULL) { - fclose(f); - f = NULL; - } - } -} - -int -main(int argc, char **argv) -{ - FILE *a; - - ++argv; /* Skip program name */ - for ( ;*argv != NULL; ++argv) { - a = fopen(*argv, "r"); - if (a == NULL) - fprintf(stderr, "Unable to open %s\n", *argv); - else { - untar(a, *argv); - fclose(a); - } - } - return (0); -} diff --git a/Utilities/cmlibarchive/cpio/CMakeLists.txt b/Utilities/cmlibarchive/cpio/CMakeLists.txt deleted file mode 100644 index 84934ad0c..000000000 --- a/Utilities/cmlibarchive/cpio/CMakeLists.txt +++ /dev/null @@ -1,54 +0,0 @@ -############################################ -# -# How to build bsdcpio -# -############################################ -IF(ENABLE_CPIO) - - SET(bsdcpio_SOURCES - cmdline.c - cpio.c - cpio.h - cpio_platform.h - ../libarchive_fe/err.c - ../libarchive_fe/err.h - ../libarchive_fe/lafe_platform.h - ../libarchive_fe/line_reader.c - ../libarchive_fe/line_reader.h - ../libarchive_fe/matching.c - ../libarchive_fe/matching.h - ../libarchive_fe/pathmatch.c - ../libarchive_fe/pathmatch.h - ) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe) - IF(WIN32 AND NOT CYGWIN) - LIST(APPEND bsdcpio_SOURCES cpio_windows.c) - LIST(APPEND bsdcpio_SOURCES cpio_windows.h) - ENDIF(WIN32 AND NOT CYGWIN) - - # bsdcpio documentation - SET(bsdcpio_MANS bsdcpio.1) - - # How to build bsdcpio - ADD_EXECUTABLE(bsdcpio ${bsdcpio_SOURCES}) - IF(ENABLE_CPIO_SHARED) - TARGET_LINK_LIBRARIES(bsdcpio archive ${ADDITIONAL_LIBS}) - ELSE(ENABLE_CPIO_SHARED) - TARGET_LINK_LIBRARIES(bsdcpio archive_static ${ADDITIONAL_LIBS}) - ENDIF(ENABLE_CPIO_SHARED) - # On Windows, DLL must end up in same dir with EXEs - IF(WIN32 AND NOT CYGWIN) - SET_TARGET_PROPERTIES(bsdcpio PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - ENDIF(WIN32 AND NOT CYGWIN) - # Full path to the compiled executable (used by test suite) - GET_TARGET_PROPERTY(BSDCPIO bsdcpio LOCATION) - - # Installation rules - INSTALL(TARGETS bsdcpio RUNTIME DESTINATION bin) - INSTALL_MAN(${bsdcpio_MANS}) - -ENDIF(ENABLE_CPIO) - -# Test suite -add_subdirectory(test) diff --git a/Utilities/cmlibarchive/cpio/bsdcpio.1 b/Utilities/cmlibarchive/cpio/bsdcpio.1 deleted file mode 100644 index 79b6997ef..000000000 --- a/Utilities/cmlibarchive/cpio/bsdcpio.1 +++ /dev/null @@ -1,405 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" 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 AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 21, 2007 -.Dt BSDCPIO 1 -.Os -.Sh NAME -.Nm cpio -.Nd copy files to and from archives -.Sh SYNOPSIS -.Nm -.Brq Fl i -.Op Ar options -.Op Ar pattern ... -.Op Ar < archive -.Nm -.Brq Fl o -.Op Ar options -.Ar < name-list -.Op Ar > archive -.Nm -.Brq Fl p -.Op Ar options -.Ar dest-dir -.Ar < name-list -.Sh DESCRIPTION -.Nm -copies files between archives and directories. -This implementation can extract from tar, pax, cpio, zip, jar, ar, -and ISO 9660 cdrom images and can create tar, pax, cpio, ar, -and shar archives. -.Pp -The first option to -.Nm -is a mode indicator from the following list: -.Bl -tag -compact -width indent -.It Fl i -Input. -Read an archive from standard input (unless overriden) and extract the -contents to disk or (if the -.Fl t -option is specified) -list the contents to standard output. -If one or more file patterns are specified, only files matching -one of the patterns will be extracted. -.It Fl o -Output. -Read a list of filenames from standard input and produce a new archive -on standard output (unless overriden) containing the specified items. -.It Fl p -Pass-through. -Read a list of filenames from standard input and copy the files to the -specified directory. -.El -.Pp -.Sh OPTIONS -Unless specifically stated otherwise, options are applicable in -all operating modes. -.Bl -tag -width indent -.It Fl 0 -Read filenames separated by NUL characters instead of newlines. -This is necessary if any of the filenames being read might contain newlines. -.It Fl A -(o mode only) -Append to the specified archive. -(Not yet implemented.) -.It Fl a -(o and p modes) -Reset access times on files after they are read. -.It Fl B -(o mode only) -Block output to records of 5120 bytes. -.It Fl C Ar size -(o mode only) -Block output to records of -.Ar size -bytes. -.It Fl c -(o mode only) -Use the old POSIX portable character format. -Equivalent to -.Fl -format Ar odc . -.It Fl d -(i and p modes) -Create directories as necessary. -.It Fl E Ar file -(i mode only) -Read list of file name patterns from -.Ar file -to list and extract. -.It Fl F Ar file -Read archive from or write archive to -.Ar file . -.It Fl f Ar pattern -(i mode only) -Ignore files that match -.Ar pattern . -.It Fl -format Ar format -(o mode only) -Produce the output archive in the specified format. -Supported formats include: -.Pp -.Bl -tag -width "iso9660" -compact -.It Ar cpio -Synonym for -.Ar odc . -.It Ar newc -The SVR4 portable cpio format. -.It Ar odc -The old POSIX.1 portable octet-oriented cpio format. -.It Ar pax -The POSIX.1 pax format, an extension of the ustar format. -.It Ar ustar -The POSIX.1 tar format. -.El -.Pp -The default format is -.Ar odc . -See -.Xr libarchive_formats 5 -for more complete information about the -formats currently supported by the underlying -.Xr libarchive 3 -library. -.It Fl H Ar format -Synonym for -.Fl -format . -.It Fl h , Fl -help -Print usage information. -.It Fl I Ar file -Read archive from -.Ar file . -.It Fl i -Input mode. -See above for description. -.It Fl -insecure -(i and p mode only) -Disable security checks during extraction or copying. -This allows extraction via symbolic links and path names containing -.Sq .. -in the name. -.It Fl J -(o mode only) -Compress the file with xz-compatible compression before writing it. -In input mode, this option is ignored; xz compression is recognized -automatically on input. -.It Fl j -Synonym for -.Fl y . -.It Fl L -(o and p modes) -All symbolic links will be followed. -Normally, symbolic links are archived and copied as symbolic links. -With this option, the target of the link will be archived or copied instead. -.It Fl l -(p mode only) -Create links from the target directory to the original files, -instead of copying. -.It Fl lzma -(o mode only) -Compress the file with lzma-compatible compression before writing it. -In input mode, this option is ignored; lzma compression is recognized -automatically on input. -.It Fl m -(i and p modes) -Set file modification time on created files to match -those in the source. -.It Fl n -(i mode, only with -.Fl t ) -Display numeric uid and gid. -By default, -.Nm -displays the user and group names when they are provided in the -archive, or looks up the user and group names in the system -password database. -.It Fl no-preserve-owner -(i mode only) -Do not attempt to restore file ownership. -This is the default when run by non-root users. -.It Fl O Ar file -Write archive to -.Ar file . -.It Fl o -Output mode. -See above for description. -.It Fl p -Pass-through mode. -See above for description. -.It Fl preserve-owner -(i mode only) -Restore file ownership. -This is the default when run by the root user. -.It Fl -quiet -Suppress unnecessary messages. -.It Fl R Oo user Oc Ns Oo : Oc Ns Oo group Oc -Set the owner and/or group on files in the output. -If group is specified with no user -(for example, -.Fl R Ar :wheel ) -then the group will be set but not the user. -If the user is specified with a trailing colon and no group -(for example, -.Fl R Ar root: ) -then the group will be set to the user's default group. -If the user is specified with no trailing colon, then -the user will be set but not the group. -In -.Fl i -and -.Fl p -modes, this option can only be used by the super-user. -(For compatibility, a period can be used in place of the colon.) -.It Fl r -(All modes.) -Rename files interactively. -For each file, a prompt is written to -.Pa /dev/tty -containing the name of the file and a line is read from -.Pa /dev/tty . -If the line read is blank, the file is skipped. -If the line contains a single period, the file is processed normally. -Otherwise, the line is taken to be the new name of the file. -.It Fl t -(i mode only) -List the contents of the archive to stdout; -do not restore the contents to disk. -.It Fl u -(i and p modes) -Unconditionally overwrite existing files. -Ordinarily, an older file will not overwrite a newer file on disk. -.It Fl v -Print the name of each file to stderr as it is processed. -With -.Fl t , -provide a detailed listing of each file. -.It Fl -version -Print the program version information and exit. -.It Fl y -(o mode only) -Compress the archive with bzip2-compatible compression before writing it. -In input mode, this option is ignored; -bzip2 compression is recognized automatically on input. -.It Fl Z -(o mode only) -Compress the archive with compress-compatible compression before writing it. -In input mode, this option is ignored; -compression is recognized automatically on input. -.It Fl z -(o mode only) -Compress the archive with gzip-compatible compression before writing it. -In input mode, this option is ignored; -gzip compression is recognized automatically on input. -.El -.Sh ENVIRONMENT -The following environment variables affect the execution of -.Nm : -.Bl -tag -width ".Ev BLOCKSIZE" -.It Ev LANG -The locale to use. -See -.Xr environ 7 -for more information. -.It Ev TZ -The timezone to use when displaying dates. -See -.Xr environ 7 -for more information. -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -The -.Nm -command is traditionally used to copy file heirarchies in conjunction -with the -.Xr find 1 -command. -The first example here simply copies all files from -.Pa src -to -.Pa dest : -.Dl Nm find Pa src | Nm Fl pmud Pa dest -.Pp -By carefully selecting options to the -.Xr find 1 -command and combining it with other standard utilities, -it is possible to exercise very fine control over which files are copied. -This next example copies files from -.Pa src -to -.Pa dest -that are more than 2 days old and whose names match a particular pattern: -.Dl Nm find Pa src Fl mtime Ar +2 | Nm grep foo[bar] | Nm Fl pdmu Pa dest -.Pp -This example copies files from -.Pa src -to -.Pa dest -that are more than 2 days old and which contain the word -.Do foobar Dc : -.Dl Nm find Pa src Fl mtime Ar +2 | Nm xargs Nm grep -l foobar | Nm Fl pdmu Pa dest -.Sh COMPATIBILITY -The mode options i, o, and p and the options -a, B, c, d, f, l, m, r, t, u, and v comply with SUSv2. -.Pp -The old POSIX.1 standard specified that only -.Fl i , -.Fl o , -and -.Fl p -were interpreted as command-line options. -Each took a single argument of a list of modifier -characters. -For example, the standard syntax allows -.Fl imu -but does not support -.Fl miu -or -.Fl i Fl m Fl u , -since -.Ar m -and -.Ar u -are only modifiers to -.Fl i , -they are not command-line options in their own right. -The syntax supported by this implementation is backwards-compatible -with the standard. -For best compatibility, scripts should limit themselves to the -standard syntax. -.Sh SEE ALSO -.Xr bzip2 1 , -.Xr tar 1 , -.Xr gzip 1 , -.Xr mt 1 , -.Xr pax 1 , -.Xr libarchive 3 , -.Xr cpio 5 , -.Xr libarchive-formats 5 , -.Xr tar 5 -.Sh STANDARDS -There is no current POSIX standard for the cpio command; it appeared -in -.St -p1003.1-96 -but was dropped from -.St -p1003.1-2001 . -.Pp -The cpio, ustar, and pax interchange file formats are defined by -.St -p1003.1-2001 -for the pax command. -.Sh HISTORY -The original -.Nm cpio -and -.Nm find -utilities were written by Dick Haight -while working in AT&T's Unix Support Group. -They first appeared in 1977 in PWB/UNIX 1.0, the -.Dq Programmer's Work Bench -system developed for use within AT&T. -They were first released outside of AT&T as part of System III Unix in 1981. -As a result, -.Nm cpio -actually predates -.Nm tar , -even though it was not well-known outside of AT&T until some time later. -.Pp -This is a complete re-implementation based on the -.Xr libarchive 3 -library. -.Sh BUGS -The cpio archive format has several basic limitations: -It does not store user and group names, only numbers. -As a result, it cannot be reliably used to transfer -files between systems with dissimilar user and group numbering. -Older cpio formats limit the user and group numbers to -16 or 18 bits, which is insufficient for modern systems. -The cpio archive formats cannot support files over 4 gigabytes, -except for the -.Dq odc -variant, which can support files up to 8 gigabytes. diff --git a/Utilities/cmlibarchive/cpio/cmdline.c b/Utilities/cmlibarchive/cpio/cmdline.c deleted file mode 100644 index b6ffb2ec5..000000000 --- a/Utilities/cmlibarchive/cpio/cmdline.c +++ /dev/null @@ -1,369 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "cpio_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/cmdline.c,v 1.5 2008/12/06 07:30:40 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "cpio.h" -#include "err.h" - -/* - * Short options for cpio. Please keep this sorted. - */ -static const char *short_options = "0AaBC:cdE:F:f:H:hI:iJjLlmnO:opR:rtuvW:yZz"; - -/* - * Long options for cpio. Please keep this sorted. - */ -static const struct option { - const char *name; - int required; /* 1 if this option requires an argument */ - int equivalent; /* Equivalent short option. */ -} cpio_longopts[] = { - { "create", 0, 'o' }, - { "extract", 0, 'i' }, - { "file", 1, 'F' }, - { "format", 1, 'H' }, - { "help", 0, 'h' }, - { "insecure", 0, OPTION_INSECURE }, - { "link", 0, 'l' }, - { "list", 0, 't' }, - { "lzma", 0, OPTION_LZMA }, - { "make-directories", 0, 'd' }, - { "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER }, - { "null", 0, '0' }, - { "numeric-uid-gid", 0, 'n' }, - { "owner", 1, 'R' }, - { "pass-through", 0, 'p' }, - { "preserve-modification-time", 0, 'm' }, - { "preserve-owner", 0, OPTION_PRESERVE_OWNER }, - { "quiet", 0, OPTION_QUIET }, - { "unconditional", 0, 'u' }, - { "verbose", 0, 'v' }, - { "version", 0, OPTION_VERSION }, - { "xz", 0, 'J' }, - { NULL, 0, 0 } -}; - -/* - * I used to try to select platform-provided getopt() or - * getopt_long(), but that caused a lot of headaches. In particular, - * I couldn't consistently use long options in the test harness - * because not all platforms have getopt_long(). That in turn led to - * overuse of the -W hack in the test harness, which made it rough to - * run the test harness against GNU cpio. (I periodically run the - * test harness here against GNU cpio as a sanity-check. Yes, - * I've found a couple of bugs in GNU cpio that way.) - */ -int -cpio_getopt(struct cpio *cpio) -{ - enum { state_start = 0, state_next_word, state_short, state_long }; - static int state = state_start; - static char *opt_word; - - const struct option *popt, *match = NULL, *match2 = NULL; - const char *p, *long_prefix = "--"; - size_t optlength; - int opt = '?'; - int required = 0; - - cpio->optarg = NULL; - - /* First time through, initialize everything. */ - if (state == state_start) { - /* Skip program name. */ - ++cpio->argv; - --cpio->argc; - state = state_next_word; - } - - /* - * We're ready to look at the next word in argv. - */ - if (state == state_next_word) { - /* No more arguments, so no more options. */ - if (cpio->argv[0] == NULL) - return (-1); - /* Doesn't start with '-', so no more options. */ - if (cpio->argv[0][0] != '-') - return (-1); - /* "--" marks end of options; consume it and return. */ - if (strcmp(cpio->argv[0], "--") == 0) { - ++cpio->argv; - --cpio->argc; - return (-1); - } - /* Get next word for parsing. */ - opt_word = *cpio->argv++; - --cpio->argc; - if (opt_word[1] == '-') { - /* Set up long option parser. */ - state = state_long; - opt_word += 2; /* Skip leading '--' */ - } else { - /* Set up short option parser. */ - state = state_short; - ++opt_word; /* Skip leading '-' */ - } - } - - /* - * We're parsing a group of POSIX-style single-character options. - */ - if (state == state_short) { - /* Peel next option off of a group of short options. */ - opt = *opt_word++; - if (opt == '\0') { - /* End of this group; recurse to get next option. */ - state = state_next_word; - return cpio_getopt(cpio); - } - - /* Does this option take an argument? */ - p = strchr(short_options, opt); - if (p == NULL) - return ('?'); - if (p[1] == ':') - required = 1; - - /* If it takes an argument, parse that. */ - if (required) { - /* If arg is run-in, opt_word already points to it. */ - if (opt_word[0] == '\0') { - /* Otherwise, pick up the next word. */ - opt_word = *cpio->argv; - if (opt_word == NULL) { - lafe_warnc(0, - "Option -%c requires an argument", - opt); - return ('?'); - } - ++cpio->argv; - --cpio->argc; - } - if (opt == 'W') { - state = state_long; - long_prefix = "-W "; /* For clearer errors. */ - } else { - state = state_next_word; - cpio->optarg = opt_word; - } - } - } - - /* We're reading a long option, including -W long=arg convention. */ - if (state == state_long) { - /* After this long option, we'll be starting a new word. */ - state = state_next_word; - - /* Option name ends at '=' if there is one. */ - p = strchr(opt_word, '='); - if (p != NULL) { - optlength = (size_t)(p - opt_word); - cpio->optarg = (char *)(uintptr_t)(p + 1); - } else { - optlength = strlen(opt_word); - } - - /* Search the table for an unambiguous match. */ - for (popt = cpio_longopts; popt->name != NULL; popt++) { - /* Short-circuit if first chars don't match. */ - if (popt->name[0] != opt_word[0]) - continue; - /* If option is a prefix of name in table, record it.*/ - if (strncmp(opt_word, popt->name, optlength) == 0) { - match2 = match; /* Record up to two matches. */ - match = popt; - /* If it's an exact match, we're done. */ - if (strlen(popt->name) == optlength) { - match2 = NULL; /* Forget the others. */ - break; - } - } - } - - /* Fail if there wasn't a unique match. */ - if (match == NULL) { - lafe_warnc(0, - "Option %s%s is not supported", - long_prefix, opt_word); - return ('?'); - } - if (match2 != NULL) { - lafe_warnc(0, - "Ambiguous option %s%s (matches --%s and --%s)", - long_prefix, opt_word, match->name, match2->name); - return ('?'); - } - - /* We've found a unique match; does it need an argument? */ - if (match->required) { - /* Argument required: get next word if necessary. */ - if (cpio->optarg == NULL) { - cpio->optarg = *cpio->argv; - if (cpio->optarg == NULL) { - lafe_warnc(0, - "Option %s%s requires an argument", - long_prefix, match->name); - return ('?'); - } - ++cpio->argv; - --cpio->argc; - } - } else { - /* Argument forbidden: fail if there is one. */ - if (cpio->optarg != NULL) { - lafe_warnc(0, - "Option %s%s does not allow an argument", - long_prefix, match->name); - return ('?'); - } - } - return (match->equivalent); - } - - return (opt); -} - - -/* - * Parse the argument to the -R or --owner flag. - * - * The format is one of the following: - * - Override user but not group - * : - Override both, group is user's default group - * : - Override user but not group - * : - Override both - * : - Override group but not user - * - * Where uid/gid are decimal representations and groupname/username - * are names to be looked up in system database. Note that we try - * to look up an argument as a name first, then try numeric parsing. - * - * A period can be used instead of the colon. - * - * Sets uid/gid return as appropriate, -1 indicates uid/gid not specified. - * - * Returns NULL if no error, otherwise returns error string for display. - * - */ -const char * -owner_parse(const char *spec, int *uid, int *gid) -{ - static char errbuff[128]; - const char *u, *ue, *g; - - *uid = -1; - *gid = -1; - - if (spec[0] == '\0') - return ("Invalid empty user/group spec"); - - /* - * Split spec into [user][:.][group] - * u -> first char of username, NULL if no username - * ue -> first char after username (colon, period, or \0) - * g -> first char of group name - */ - if (*spec == ':' || *spec == '.') { - /* If spec starts with ':' or '.', then just group. */ - ue = u = NULL; - g = spec + 1; - } else { - /* Otherwise, [user] or [user][:] or [user][:][group] */ - ue = u = spec; - while (*ue != ':' && *ue != '.' && *ue != '\0') - ++ue; - g = ue; - if (*g != '\0') /* Skip : or . to find first char of group. */ - ++g; - } - - if (u != NULL) { - /* Look up user: ue is first char after end of user. */ - char *user; - struct passwd *pwent; - - user = (char *)malloc(ue - u + 1); - if (user == NULL) - return ("Couldn't allocate memory"); - memcpy(user, u, ue - u); - user[ue - u] = '\0'; - if ((pwent = getpwnam(user)) != NULL) { - *uid = pwent->pw_uid; - if (*ue != '\0') - *gid = pwent->pw_gid; - } else { - char *end; - errno = 0; - *uid = strtoul(user, &end, 10); - if (errno || *end != '\0') { - snprintf(errbuff, sizeof(errbuff), - "Couldn't lookup user ``%s''", user); - errbuff[sizeof(errbuff) - 1] = '\0'; - return (errbuff); - } - } - free(user); - } - - if (*g != '\0') { - struct group *grp; - if ((grp = getgrnam(g)) != NULL) { - *gid = grp->gr_gid; - } else { - char *end; - errno = 0; - *gid = strtoul(g, &end, 10); - if (errno || *end != '\0') { - snprintf(errbuff, sizeof(errbuff), - "Couldn't lookup group ``%s''", g); - errbuff[sizeof(errbuff) - 1] = '\0'; - return (errbuff); - } - } - } - return (NULL); -} diff --git a/Utilities/cmlibarchive/cpio/config_freebsd.h b/Utilities/cmlibarchive/cpio/config_freebsd.h deleted file mode 100644 index b2971afb8..000000000 --- a/Utilities/cmlibarchive/cpio/config_freebsd.h +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/cpio/config_freebsd.h,v 1.3 2008/12/06 07:30:40 kientzle Exp $ - */ - -/* A hand-tooled configuration for FreeBSD. */ - -#include /* __FreeBSD_version */ - -#define HAVE_DIRENT_H 1 -#define HAVE_ERRNO_H 1 -#define HAVE_FCNTL_H 1 -#define HAVE_FUTIMES 1 -#define HAVE_GRP_H 1 -#define HAVE_LIBARCHIVE 1 -#define HAVE_LINK 1 -#define HAVE_LSTAT 1 -#define HAVE_LUTIMES 1 -#define HAVE_PWD_H 1 -#define HAVE_READLINK 1 -#define HAVE_STDARG_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRING_H 1 -#define HAVE_SYMLINK 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TIME_H 1 -#define HAVE_TIME_H 1 -#define HAVE_UINTMAX_T 1 -#define HAVE_UNISTD_H 1 -#define HAVE_UNSIGNED_LONG_LONG 1 -#define HAVE_UTIMES 1 - diff --git a/Utilities/cmlibarchive/cpio/cpio.c b/Utilities/cmlibarchive/cpio/cpio.c deleted file mode 100644 index a12ca80ad..000000000 --- a/Utilities/cmlibarchive/cpio/cpio.c +++ /dev/null @@ -1,1233 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "cpio_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle Exp $"); - -#include -#include -#include - -#ifdef HAVE_SYS_MKDEV_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#ifdef HAVE_STDARG_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_TIME_H -#include -#endif - -#include "cpio.h" -#include "err.h" -#include "line_reader.h" -#include "matching.h" - -/* Fixed size of uname/gname caches. */ -#define name_cache_size 101 - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -struct name_cache { - int probes; - int hits; - size_t size; - struct { - id_t id; - char *name; - } cache[name_cache_size]; -}; - -static int copy_data(struct archive *, struct archive *); -static const char *cpio_rename(const char *name); -static int entry_to_archive(struct cpio *, struct archive_entry *); -static int file_to_archive(struct cpio *, const char *); -static void free_cache(struct name_cache *cache); -static void list_item_verbose(struct cpio *, struct archive_entry *); -static void long_help(void); -static const char *lookup_gname(struct cpio *, gid_t gid); -static int lookup_gname_helper(struct cpio *, - const char **name, id_t gid); -static const char *lookup_uname(struct cpio *, uid_t uid); -static int lookup_uname_helper(struct cpio *, - const char **name, id_t uid); -static void mode_in(struct cpio *); -static void mode_list(struct cpio *); -static void mode_out(struct cpio *); -static void mode_pass(struct cpio *, const char *); -static int restore_time(struct cpio *, struct archive_entry *, - const char *, int fd); -static void usage(void); -static void version(void); - -int -main(int argc, char *argv[]) -{ - static char buff[16384]; - struct cpio _cpio; /* Allocated on stack. */ - struct cpio *cpio; - const char *errmsg; - int uid, gid; - int opt; - - cpio = &_cpio; - memset(cpio, 0, sizeof(*cpio)); - cpio->buff = buff; - cpio->buff_size = sizeof(buff); - - /* Need lafe_progname before calling lafe_warnc. */ - if (*argv == NULL) - lafe_progname = "bsdcpio"; - else { -#if defined(_WIN32) && !defined(__CYGWIN__) - lafe_progname = strrchr(*argv, '\\'); -#else - lafe_progname = strrchr(*argv, '/'); -#endif - if (lafe_progname != NULL) - lafe_progname++; - else - lafe_progname = *argv; - } - - cpio->uid_override = -1; - cpio->gid_override = -1; - cpio->argv = argv; - cpio->argc = argc; - cpio->mode = '\0'; - cpio->verbose = 0; - cpio->compress = '\0'; - cpio->extract_flags = ARCHIVE_EXTRACT_NO_AUTODIR; - cpio->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; - cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_SYMLINKS; - cpio->extract_flags |= ARCHIVE_EXTRACT_SECURE_NODOTDOT; - cpio->extract_flags |= ARCHIVE_EXTRACT_PERM; - cpio->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; - cpio->extract_flags |= ARCHIVE_EXTRACT_ACL; -#if !defined(_WIN32) && !defined(__CYGWIN__) - if (geteuid() == 0) - cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; -#endif - cpio->bytes_per_block = 512; - cpio->filename = NULL; - - while ((opt = cpio_getopt(cpio)) != -1) { - switch (opt) { - case '0': /* GNU convention: --null, -0 */ - cpio->option_null = 1; - break; - case 'A': /* NetBSD/OpenBSD */ - cpio->option_append = 1; - break; - case 'a': /* POSIX 1997 */ - cpio->option_atime_restore = 1; - break; - case 'B': /* POSIX 1997 */ - cpio->bytes_per_block = 5120; - break; - case 'C': /* NetBSD/OpenBSD */ - cpio->bytes_per_block = atoi(cpio->optarg); - if (cpio->bytes_per_block <= 0) - lafe_errc(1, 0, "Invalid blocksize %s", cpio->optarg); - break; - case 'c': /* POSIX 1997 */ - cpio->format = "odc"; - break; - case 'd': /* POSIX 1997 */ - cpio->extract_flags &= ~ARCHIVE_EXTRACT_NO_AUTODIR; - break; - case 'E': /* NetBSD/OpenBSD */ - lafe_include_from_file(&cpio->matching, - cpio->optarg, cpio->option_null); - break; - case 'F': /* NetBSD/OpenBSD/GNU cpio */ - cpio->filename = cpio->optarg; - break; - case 'f': /* POSIX 1997 */ - lafe_exclude(&cpio->matching, cpio->optarg); - break; - case 'H': /* GNU cpio (also --format) */ - cpio->format = cpio->optarg; - break; - case 'h': - long_help(); - break; - case 'I': /* NetBSD/OpenBSD */ - cpio->filename = cpio->optarg; - break; - case 'i': /* POSIX 1997 */ - if (cpio->mode != '\0') - lafe_errc(1, 0, - "Cannot use both -i and -%c", cpio->mode); - cpio->mode = opt; - break; - case 'J': /* GNU tar, others */ - cpio->compress = opt; - break; - case 'j': /* GNU tar, others */ - cpio->compress = opt; - break; - case OPTION_INSECURE: - cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_SYMLINKS; - cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; - break; - case 'L': /* GNU cpio */ - cpio->option_follow_links = 1; - break; - case 'l': /* POSIX 1997 */ - cpio->option_link = 1; - break; - case OPTION_LZMA: /* GNU tar, others */ - cpio->compress = opt; - break; - case 'm': /* POSIX 1997 */ - cpio->extract_flags |= ARCHIVE_EXTRACT_TIME; - break; - case 'n': /* GNU cpio */ - cpio->option_numeric_uid_gid = 1; - break; - case OPTION_NO_PRESERVE_OWNER: /* GNU cpio */ - cpio->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; - break; - case 'O': /* GNU cpio */ - cpio->filename = cpio->optarg; - break; - case 'o': /* POSIX 1997 */ - if (cpio->mode != '\0') - lafe_errc(1, 0, - "Cannot use both -o and -%c", cpio->mode); - cpio->mode = opt; - break; - case 'p': /* POSIX 1997 */ - if (cpio->mode != '\0') - lafe_errc(1, 0, - "Cannot use both -p and -%c", cpio->mode); - cpio->mode = opt; - cpio->extract_flags &= ~ARCHIVE_EXTRACT_SECURE_NODOTDOT; - break; - case OPTION_PRESERVE_OWNER: - cpio->extract_flags |= ARCHIVE_EXTRACT_OWNER; - break; - case OPTION_QUIET: /* GNU cpio */ - cpio->quiet = 1; - break; - case 'R': /* GNU cpio, also --owner */ - errmsg = owner_parse(cpio->optarg, &uid, &gid); - if (errmsg) { - lafe_warnc(-1, "%s", errmsg); - usage(); - } - if (uid != -1) - cpio->uid_override = uid; - if (gid != -1) - cpio->gid_override = gid; - break; - case 'r': /* POSIX 1997 */ - cpio->option_rename = 1; - break; - case 't': /* POSIX 1997 */ - cpio->option_list = 1; - break; - case 'u': /* POSIX 1997 */ - cpio->extract_flags - &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; - break; - case 'v': /* POSIX 1997 */ - cpio->verbose++; - break; - case OPTION_VERSION: /* GNU convention */ - version(); - break; -#if 0 - /* - * cpio_getopt() handles -W specially, so it's not - * available here. - */ - case 'W': /* Obscure, but useful GNU convention. */ - break; -#endif - case 'y': /* tar convention */ - cpio->compress = opt; - break; - case 'Z': /* tar convention */ - cpio->compress = opt; - break; - case 'z': /* tar convention */ - cpio->compress = opt; - break; - default: - usage(); - } - } - - /* - * Sanity-check args, error out on nonsensical combinations. - */ - /* -t implies -i if no mode was specified. */ - if (cpio->option_list && cpio->mode == '\0') - cpio->mode = 'i'; - /* -t requires -i */ - if (cpio->option_list && cpio->mode != 'i') - lafe_errc(1, 0, "Option -t requires -i", cpio->mode); - /* -n requires -it */ - if (cpio->option_numeric_uid_gid && !cpio->option_list) - lafe_errc(1, 0, "Option -n requires -it"); - /* Can only specify format when writing */ - if (cpio->format != NULL && cpio->mode != 'o') - lafe_errc(1, 0, "Option --format requires -o"); - /* -l requires -p */ - if (cpio->option_link && cpio->mode != 'p') - lafe_errc(1, 0, "Option -l requires -p"); - /* TODO: Flag other nonsensical combinations. */ - - switch (cpio->mode) { - case 'o': - /* TODO: Implement old binary format in libarchive, - use that here. */ - if (cpio->format == NULL) - cpio->format = "odc"; /* Default format */ - - mode_out(cpio); - break; - case 'i': - while (*cpio->argv != NULL) { - lafe_include(&cpio->matching, *cpio->argv); - --cpio->argc; - ++cpio->argv; - } - if (cpio->option_list) - mode_list(cpio); - else - mode_in(cpio); - break; - case 'p': - if (*cpio->argv == NULL || **cpio->argv == '\0') - lafe_errc(1, 0, - "-p mode requires a target directory"); - mode_pass(cpio, *cpio->argv); - break; - default: - lafe_errc(1, 0, - "Must specify at least one of -i, -o, or -p"); - } - - free_cache(cpio->gname_cache); - free_cache(cpio->uname_cache); - return (0); -} - -void -usage(void) -{ - const char *p; - - p = lafe_progname; - - fprintf(stderr, "Brief Usage:\n"); - fprintf(stderr, " List: %s -it < archive\n", p); - fprintf(stderr, " Extract: %s -i < archive\n", p); - fprintf(stderr, " Create: %s -o < filenames > archive\n", p); - fprintf(stderr, " Help: %s --help\n", p); - exit(1); -} - -static const char *long_help_msg = - "First option must be a mode specifier:\n" - " -i Input -o Output -p Pass\n" - "Common Options:\n" - " -v Verbose\n" - "Create: %p -o [options] < [list of files] > [archive]\n" - " -J,-y,-z,--lzma Compress archive with xz/bzip2/gzip/lzma\n" - " --format {odc|newc|ustar} Select archive format\n" - "List: %p -it < [archive]\n" - "Extract: %p -i [options] < [archive]\n"; - - -/* - * Note that the word 'bsdcpio' will always appear in the first line - * of output. - * - * In particular, /bin/sh scripts that need to test for the presence - * of bsdcpio can use the following template: - * - * if (cpio --help 2>&1 | grep bsdcpio >/dev/null 2>&1 ) then \ - * echo bsdcpio; else echo not bsdcpio; fi - */ -static void -long_help(void) -{ - const char *prog; - const char *p; - - prog = lafe_progname; - - fflush(stderr); - - p = (strcmp(prog,"bsdcpio") != 0) ? "(bsdcpio)" : ""; - printf("%s%s: manipulate archive files\n", prog, p); - - for (p = long_help_msg; *p != '\0'; p++) { - if (*p == '%') { - if (p[1] == 'p') { - fputs(prog, stdout); - p++; - } else - putchar('%'); - } else - putchar(*p); - } - version(); -} - -static void -version(void) -{ - fprintf(stdout,"bsdcpio %s -- %s\n", - BSDCPIO_VERSION_STRING, - archive_version()); - exit(0); -} - -static void -mode_out(struct cpio *cpio) -{ - struct archive_entry *entry, *spare; - struct lafe_line_reader *lr; - const char *p; - int r; - - if (cpio->option_append) - lafe_errc(1, 0, "Append mode not yet supported."); - - cpio->archive_read_disk = archive_read_disk_new(); - if (cpio->archive_read_disk == NULL) - lafe_errc(1, 0, "Failed to allocate archive object"); - if (cpio->option_follow_links) - archive_read_disk_set_symlink_logical(cpio->archive_read_disk); - else - archive_read_disk_set_symlink_physical(cpio->archive_read_disk); - archive_read_disk_set_standard_lookup(cpio->archive_read_disk); - - cpio->archive = archive_write_new(); - if (cpio->archive == NULL) - lafe_errc(1, 0, "Failed to allocate archive object"); - switch (cpio->compress) { - case 'J': - r = archive_write_set_compression_xz(cpio->archive); - break; - case OPTION_LZMA: - r = archive_write_set_compression_lzma(cpio->archive); - break; - case 'j': case 'y': - r = archive_write_set_compression_bzip2(cpio->archive); - break; - case 'z': - r = archive_write_set_compression_gzip(cpio->archive); - break; - case 'Z': - r = archive_write_set_compression_compress(cpio->archive); - break; - default: - r = archive_write_set_compression_none(cpio->archive); - break; - } - if (r < ARCHIVE_WARN) - lafe_errc(1, 0, "Requested compression not available"); - r = archive_write_set_format_by_name(cpio->archive, cpio->format); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - archive_write_set_bytes_per_block(cpio->archive, cpio->bytes_per_block); - cpio->linkresolver = archive_entry_linkresolver_new(); - archive_entry_linkresolver_set_strategy(cpio->linkresolver, - archive_format(cpio->archive)); - - /* - * The main loop: Copy each file into the output archive. - */ - r = archive_write_open_file(cpio->archive, cpio->filename); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - lr = lafe_line_reader("-", cpio->option_null); - while ((p = lafe_line_reader_next(lr)) != NULL) - file_to_archive(cpio, p); - lafe_line_reader_free(lr); - - /* - * The hardlink detection may have queued up a couple of entries - * that can now be flushed. - */ - entry = NULL; - archive_entry_linkify(cpio->linkresolver, &entry, &spare); - while (entry != NULL) { - entry_to_archive(cpio, entry); - archive_entry_free(entry); - entry = NULL; - archive_entry_linkify(cpio->linkresolver, &entry, &spare); - } - - r = archive_write_close(cpio->archive); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - - if (!cpio->quiet) { - int64_t blocks = - (archive_position_uncompressed(cpio->archive) + 511) - / 512; - fprintf(stderr, "%lu %s\n", (unsigned long)blocks, - blocks == 1 ? "block" : "blocks"); - } - archive_write_finish(cpio->archive); -} - -/* - * This is used by both out mode (to copy objects from disk into - * an archive) and pass mode (to copy objects from disk to - * an archive_write_disk "archive"). - */ -static int -file_to_archive(struct cpio *cpio, const char *srcpath) -{ - const char *destpath; - struct archive_entry *entry, *spare; - size_t len; - const char *p; - int r; - - /* - * Create an archive_entry describing the source file. - * - */ - entry = archive_entry_new(); - if (entry == NULL) - lafe_errc(1, 0, "Couldn't allocate entry"); - archive_entry_copy_sourcepath(entry, srcpath); - r = archive_read_disk_entry_from_file(cpio->archive_read_disk, - entry, -1, NULL); - if (r < ARCHIVE_WARN) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - if (r < ARCHIVE_OK) - lafe_warnc(0, archive_error_string(cpio->archive)); - - if (cpio->uid_override >= 0) - archive_entry_set_uid(entry, cpio->uid_override); - if (cpio->gid_override >= 0) - archive_entry_set_gid(entry, cpio->gid_override); - - /* - * Generate a destination path for this entry. - * "destination path" is the name to which it will be copied in - * pass mode or the name that will go into the archive in - * output mode. - */ - destpath = srcpath; - if (cpio->destdir) { - len = strlen(cpio->destdir) + strlen(srcpath) + 8; - if (len >= cpio->pass_destpath_alloc) { - while (len >= cpio->pass_destpath_alloc) { - cpio->pass_destpath_alloc += 512; - cpio->pass_destpath_alloc *= 2; - } - free(cpio->pass_destpath); - cpio->pass_destpath = malloc(cpio->pass_destpath_alloc); - if (cpio->pass_destpath == NULL) - lafe_errc(1, ENOMEM, - "Can't allocate path buffer"); - } - strcpy(cpio->pass_destpath, cpio->destdir); - p = srcpath; - while (p[0] == '/') - ++p; - strcat(cpio->pass_destpath, p); - destpath = cpio->pass_destpath; - } - if (cpio->option_rename) - destpath = cpio_rename(destpath); - if (destpath == NULL) - return (0); - archive_entry_copy_pathname(entry, destpath); - - /* - * If we're trying to preserve hardlinks, match them here. - */ - spare = NULL; - if (cpio->linkresolver != NULL - && archive_entry_filetype(entry) != AE_IFDIR) { - archive_entry_linkify(cpio->linkresolver, &entry, &spare); - } - - if (entry != NULL) { - r = entry_to_archive(cpio, entry); - archive_entry_free(entry); - if (spare != NULL) { - if (r == 0) - r = entry_to_archive(cpio, spare); - archive_entry_free(spare); - } - } - return (r); -} - -static int -entry_to_archive(struct cpio *cpio, struct archive_entry *entry) -{ - const char *destpath = archive_entry_pathname(entry); - const char *srcpath = archive_entry_sourcepath(entry); - int fd = -1; - ssize_t bytes_read; - int r; - - /* Print out the destination name to the user. */ - if (cpio->verbose) - fprintf(stderr,"%s", destpath); - - /* - * Option_link only makes sense in pass mode and for - * regular files. Also note: if a link operation fails - * because of cross-device restrictions, we'll fall back - * to copy mode for that entry. - * - * TODO: Test other cpio implementations to see if they - * hard-link anything other than regular files here. - */ - if (cpio->option_link - && archive_entry_filetype(entry) == AE_IFREG) - { - struct archive_entry *t; - /* Save the original entry in case we need it later. */ - t = archive_entry_clone(entry); - if (t == NULL) - lafe_errc(1, ENOMEM, "Can't create link"); - /* Note: link(2) doesn't create parent directories, - * so we use archive_write_header() instead as a - * convenience. */ - archive_entry_set_hardlink(t, srcpath); - /* This is a straight link that carries no data. */ - archive_entry_set_size(t, 0); - r = archive_write_header(cpio->archive, t); - archive_entry_free(t); - if (r != ARCHIVE_OK) - lafe_warnc(archive_errno(cpio->archive), - archive_error_string(cpio->archive)); - if (r == ARCHIVE_FATAL) - exit(1); -#ifdef EXDEV - if (r != ARCHIVE_OK && archive_errno(cpio->archive) == EXDEV) { - /* Cross-device link: Just fall through and use - * the original entry to copy the file over. */ - lafe_warnc(0, "Copying file instead"); - } else -#endif - return (0); - } - - /* - * Make sure we can open the file (if necessary) before - * trying to write the header. - */ - if (archive_entry_filetype(entry) == AE_IFREG) { - if (archive_entry_size(entry) > 0) { - fd = open(srcpath, O_RDONLY | O_BINARY); - if (fd < 0) { - lafe_warnc(errno, - "%s: could not open file", srcpath); - goto cleanup; - } - } - } else { - archive_entry_set_size(entry, 0); - } - - r = archive_write_header(cpio->archive, entry); - - if (r != ARCHIVE_OK) - lafe_warnc(archive_errno(cpio->archive), - "%s: %s", - srcpath, - archive_error_string(cpio->archive)); - - if (r == ARCHIVE_FATAL) - exit(1); - - if (r >= ARCHIVE_WARN && fd >= 0) { - bytes_read = read(fd, cpio->buff, cpio->buff_size); - while (bytes_read > 0) { - r = archive_write_data(cpio->archive, - cpio->buff, bytes_read); - if (r < 0) - lafe_errc(1, archive_errno(cpio->archive), - archive_error_string(cpio->archive)); - if (r < bytes_read) { - lafe_warnc(0, - "Truncated write; file may have grown while being archived."); - } - bytes_read = read(fd, cpio->buff, cpio->buff_size); - } - } - - fd = restore_time(cpio, entry, srcpath, fd); - -cleanup: - if (cpio->verbose) - fprintf(stderr,"\n"); - if (fd >= 0) - close(fd); - return (0); -} - -static int -restore_time(struct cpio *cpio, struct archive_entry *entry, - const char *name, int fd) -{ -#ifndef HAVE_UTIMES - static int warned = 0; - - (void)cpio; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)name; /* UNUSED */ - - if (!warned) - lafe_warnc(0, "Can't restore access times on this platform"); - warned = 1; - return (fd); -#else -#if defined(_WIN32) && !defined(__CYGWIN__) - struct __timeval times[2]; -#else - struct timeval times[2]; -#endif - - if (!cpio->option_atime_restore) - return (fd); - - times[1].tv_sec = archive_entry_mtime(entry); - times[1].tv_usec = archive_entry_mtime_nsec(entry) / 1000; - - times[0].tv_sec = archive_entry_atime(entry); - times[0].tv_usec = archive_entry_atime_nsec(entry) / 1000; - -#ifdef HAVE_FUTIMES - if (fd >= 0 && futimes(fd, times) == 0) - return (fd); -#endif - /* - * Some platform cannot restore access times if the file descriptor - * is still opened. - */ - if (fd >= 0) { - close(fd); - fd = -1; - } - -#ifdef HAVE_LUTIMES - if (lutimes(name, times) != 0) -#else - if ((AE_IFLNK != archive_entry_filetype(entry)) - && utimes(name, times) != 0) -#endif - lafe_warnc(errno, "Can't update time for %s", name); -#endif - return (fd); -} - - -static void -mode_in(struct cpio *cpio) -{ - struct archive *a; - struct archive_entry *entry; - struct archive *ext; - const char *destpath; - int r; - - ext = archive_write_disk_new(); - if (ext == NULL) - lafe_errc(1, 0, "Couldn't allocate restore object"); - r = archive_write_disk_set_options(ext, cpio->extract_flags); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(ext)); - a = archive_read_new(); - if (a == NULL) - lafe_errc(1, 0, "Couldn't allocate archive object"); - archive_read_support_compression_all(a); - archive_read_support_format_all(a); - - if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) - lafe_errc(1, archive_errno(a), - archive_error_string(a)); - for (;;) { - r = archive_read_next_header(a, &entry); - if (r == ARCHIVE_EOF) - break; - if (r != ARCHIVE_OK) { - lafe_errc(1, archive_errno(a), - archive_error_string(a)); - } - if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) - continue; - if (cpio->option_rename) { - destpath = cpio_rename(archive_entry_pathname(entry)); - archive_entry_set_pathname(entry, destpath); - } else - destpath = archive_entry_pathname(entry); - if (destpath == NULL) - continue; - if (cpio->verbose) - fprintf(stdout, "%s\n", destpath); - if (cpio->uid_override >= 0) - archive_entry_set_uid(entry, cpio->uid_override); - if (cpio->gid_override >= 0) - archive_entry_set_gid(entry, cpio->gid_override); - r = archive_write_header(ext, entry); - if (r != ARCHIVE_OK) { - fprintf(stderr, "%s: %s\n", - archive_entry_pathname(entry), - archive_error_string(ext)); - } else if (archive_entry_size(entry) > 0) { - r = copy_data(a, ext); - } - } - r = archive_read_close(a); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(a)); - r = archive_write_close(ext); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(ext)); - if (!cpio->quiet) { - int64_t blocks = (archive_position_uncompressed(a) + 511) - / 512; - fprintf(stderr, "%lu %s\n", (unsigned long)blocks, - blocks == 1 ? "block" : "blocks"); - } - archive_read_finish(a); - archive_write_finish(ext); - exit(0); -} - -static int -copy_data(struct archive *ar, struct archive *aw) -{ - int r; - size_t size; - const void *block; - off_t offset; - - for (;;) { - r = archive_read_data_block(ar, &block, &size, &offset); - if (r == ARCHIVE_EOF) - return (ARCHIVE_OK); - if (r != ARCHIVE_OK) { - lafe_warnc(archive_errno(ar), - "%s", archive_error_string(ar)); - return (r); - } - r = archive_write_data_block(aw, block, size, offset); - if (r != ARCHIVE_OK) { - lafe_warnc(archive_errno(aw), - archive_error_string(aw)); - return (r); - } - } -} - -static void -mode_list(struct cpio *cpio) -{ - struct archive *a; - struct archive_entry *entry; - int r; - - a = archive_read_new(); - if (a == NULL) - lafe_errc(1, 0, "Couldn't allocate archive object"); - archive_read_support_compression_all(a); - archive_read_support_format_all(a); - - if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block)) - lafe_errc(1, archive_errno(a), - archive_error_string(a)); - for (;;) { - r = archive_read_next_header(a, &entry); - if (r == ARCHIVE_EOF) - break; - if (r != ARCHIVE_OK) { - lafe_errc(1, archive_errno(a), - archive_error_string(a)); - } - if (lafe_excluded(cpio->matching, archive_entry_pathname(entry))) - continue; - if (cpio->verbose) - list_item_verbose(cpio, entry); - else - fprintf(stdout, "%s\n", archive_entry_pathname(entry)); - } - r = archive_read_close(a); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(a)); - if (!cpio->quiet) { - int64_t blocks = (archive_position_uncompressed(a) + 511) - / 512; - fprintf(stderr, "%lu %s\n", (unsigned long)blocks, - blocks == 1 ? "block" : "blocks"); - } - archive_read_finish(a); - exit(0); -} - -/* - * Display information about the current file. - * - * The format here roughly duplicates the output of 'ls -l'. - * This is based on SUSv2, where 'tar tv' is documented as - * listing additional information in an "unspecified format," - * and 'pax -l' is documented as using the same format as 'ls -l'. - */ -static void -list_item_verbose(struct cpio *cpio, struct archive_entry *entry) -{ - char size[32]; - char date[32]; - char uids[16], gids[16]; - const char *uname, *gname; - FILE *out = stdout; - const struct stat *st; - const char *fmt; - time_t tim; - static time_t now; - - st = archive_entry_stat(entry); - - if (!now) - time(&now); - - if (cpio->option_numeric_uid_gid) { - /* Format numeric uid/gid for display. */ - snprintf(uids, sizeof(uids), CPIO_FILESIZE_PRINTF, - (CPIO_FILESIZE_TYPE)archive_entry_uid(entry)); - uname = uids; - snprintf(gids, sizeof(gids), CPIO_FILESIZE_PRINTF, - (CPIO_FILESIZE_TYPE)archive_entry_gid(entry)); - gname = gids; - } else { - /* Use uname if it's present, else lookup name from uid. */ - uname = archive_entry_uname(entry); - if (uname == NULL) - uname = lookup_uname(cpio, archive_entry_uid(entry)); - /* Use gname if it's present, else lookup name from gid. */ - gname = archive_entry_gname(entry); - if (gname == NULL) - gname = lookup_gname(cpio, archive_entry_gid(entry)); - } - - /* Print device number or file size. */ - if (archive_entry_filetype(entry) == AE_IFCHR - || archive_entry_filetype(entry) == AE_IFBLK) { - snprintf(size, sizeof(size), "%lu,%lu", - (unsigned long)archive_entry_rdevmajor(entry), - (unsigned long)archive_entry_rdevminor(entry)); - } else { - snprintf(size, sizeof(size), CPIO_FILESIZE_PRINTF, - (CPIO_FILESIZE_TYPE)st->st_size); - } - - /* Format the time using 'ls -l' conventions. */ - tim = (time_t)st->st_mtime; -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Windows' strftime function does not support %e format. */ - if (tim - now > 365*86400/2 - || tim - now < -365*86400/2) - fmt = cpio->day_first ? "%d %b %Y" : "%b %d %Y"; - else - fmt = cpio->day_first ? "%d %b %H:%M" : "%b %d %H:%M"; -#else - if (abs(tim - now) > (365/2)*86400) - fmt = cpio->day_first ? "%e %b %Y" : "%b %e %Y"; - else - fmt = cpio->day_first ? "%e %b %H:%M" : "%b %e %H:%M"; -#endif - strftime(date, sizeof(date), fmt, localtime(&tim)); - - fprintf(out, "%s%3d %-8s %-8s %8s %12s %s", - archive_entry_strmode(entry), - archive_entry_nlink(entry), - uname, gname, size, date, - archive_entry_pathname(entry)); - - /* Extra information for links. */ - if (archive_entry_hardlink(entry)) /* Hard link */ - fprintf(out, " link to %s", archive_entry_hardlink(entry)); - else if (archive_entry_symlink(entry)) /* Symbolic link */ - fprintf(out, " -> %s", archive_entry_symlink(entry)); - fprintf(out, "\n"); -} - -static void -mode_pass(struct cpio *cpio, const char *destdir) -{ - struct lafe_line_reader *lr; - const char *p; - int r; - - /* Ensure target dir has a trailing '/' to simplify path surgery. */ - cpio->destdir = malloc(strlen(destdir) + 8); - strcpy(cpio->destdir, destdir); - if (destdir[strlen(destdir) - 1] != '/') - strcat(cpio->destdir, "/"); - - cpio->archive = archive_write_disk_new(); - if (cpio->archive == NULL) - lafe_errc(1, 0, "Failed to allocate archive object"); - r = archive_write_disk_set_options(cpio->archive, cpio->extract_flags); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - cpio->linkresolver = archive_entry_linkresolver_new(); - archive_write_disk_set_standard_lookup(cpio->archive); - - cpio->archive_read_disk = archive_read_disk_new(); - if (cpio->archive_read_disk == NULL) - lafe_errc(1, 0, "Failed to allocate archive object"); - if (cpio->option_follow_links) - archive_read_disk_set_symlink_logical(cpio->archive_read_disk); - else - archive_read_disk_set_symlink_physical(cpio->archive_read_disk); - archive_read_disk_set_standard_lookup(cpio->archive_read_disk); - - lr = lafe_line_reader("-", cpio->option_null); - while ((p = lafe_line_reader_next(lr)) != NULL) - file_to_archive(cpio, p); - lafe_line_reader_free(lr); - - archive_entry_linkresolver_free(cpio->linkresolver); - r = archive_write_close(cpio->archive); - if (r != ARCHIVE_OK) - lafe_errc(1, 0, archive_error_string(cpio->archive)); - - if (!cpio->quiet) { - int64_t blocks = - (archive_position_uncompressed(cpio->archive) + 511) - / 512; - fprintf(stderr, "%lu %s\n", (unsigned long)blocks, - blocks == 1 ? "block" : "blocks"); - } - - archive_write_finish(cpio->archive); -} - -/* - * Prompt for a new name for this entry. Returns a pointer to the - * new name or NULL if the entry should not be copied. This - * implements the semantics defined in POSIX.1-1996, which specifies - * that an input of '.' means the name should be unchanged. GNU cpio - * treats '.' as a literal new name. - */ -static const char * -cpio_rename(const char *name) -{ - static char buff[1024]; - FILE *t; - char *p, *ret; - - t = fopen("/dev/tty", "r+"); - if (t == NULL) - return (name); - fprintf(t, "%s (Enter/./(new name))? ", name); - fflush(t); - - p = fgets(buff, sizeof(buff), t); - fclose(t); - if (p == NULL) - /* End-of-file is a blank line. */ - return (NULL); - - while (*p == ' ' || *p == '\t') - ++p; - if (*p == '\n' || *p == '\0') - /* Empty line. */ - return (NULL); - if (*p == '.' && p[1] == '\n') - /* Single period preserves original name. */ - return (name); - ret = p; - /* Trim the final newline. */ - while (*p != '\0' && *p != '\n') - ++p; - /* Overwrite the final \n with a null character. */ - *p = '\0'; - return (ret); -} - -static void -free_cache(struct name_cache *cache) -{ - size_t i; - - if (cache != NULL) { - for (i = 0; i < cache->size; i++) - free(cache->cache[i].name); - free(cache); - } -} - -/* - * Lookup uname/gname from uid/gid, return NULL if no match. - */ -static const char * -lookup_name(struct cpio *cpio, struct name_cache **name_cache_variable, - int (*lookup_fn)(struct cpio *, const char **, id_t), id_t id) -{ - char asnum[16]; - struct name_cache *cache; - const char *name; - int slot; - - - if (*name_cache_variable == NULL) { - *name_cache_variable = malloc(sizeof(struct name_cache)); - if (*name_cache_variable == NULL) - lafe_errc(1, ENOMEM, "No more memory"); - memset(*name_cache_variable, 0, sizeof(struct name_cache)); - (*name_cache_variable)->size = name_cache_size; - } - - cache = *name_cache_variable; - cache->probes++; - - slot = id % cache->size; - if (cache->cache[slot].name != NULL) { - if (cache->cache[slot].id == id) { - cache->hits++; - return (cache->cache[slot].name); - } - free(cache->cache[slot].name); - cache->cache[slot].name = NULL; - } - - if (lookup_fn(cpio, &name, id) == 0) { - if (name == NULL || name[0] == '\0') { - /* If lookup failed, format it as a number. */ - snprintf(asnum, sizeof(asnum), "%u", (unsigned)id); - name = asnum; - } - cache->cache[slot].name = strdup(name); - if (cache->cache[slot].name != NULL) { - cache->cache[slot].id = id; - return (cache->cache[slot].name); - } - /* - * Conveniently, NULL marks an empty slot, so - * if the strdup() fails, we've just failed to - * cache it. No recovery necessary. - */ - } - return (NULL); -} - -static const char * -lookup_uname(struct cpio *cpio, uid_t uid) -{ - return (lookup_name(cpio, &cpio->uname_cache, - &lookup_uname_helper, (id_t)uid)); -} - -static int -lookup_uname_helper(struct cpio *cpio, const char **name, id_t id) -{ - struct passwd *pwent; - - (void)cpio; /* UNUSED */ - - errno = 0; - pwent = getpwuid((uid_t)id); - if (pwent == NULL) { - *name = NULL; - if (errno != 0) - lafe_warnc(errno, "getpwuid(%d) failed", id); - return (errno); - } - - *name = pwent->pw_name; - return (0); -} - -static const char * -lookup_gname(struct cpio *cpio, gid_t gid) -{ - return (lookup_name(cpio, &cpio->gname_cache, - &lookup_gname_helper, (id_t)gid)); -} - -static int -lookup_gname_helper(struct cpio *cpio, const char **name, id_t id) -{ - struct group *grent; - - (void)cpio; /* UNUSED */ - - errno = 0; - grent = getgrgid((gid_t)id); - if (grent == NULL) { - *name = NULL; - if (errno != 0) - lafe_warnc(errno, "getgrgid(%d) failed", id); - return (errno); - } - - *name = grent->gr_name; - return (0); -} diff --git a/Utilities/cmlibarchive/cpio/cpio.h b/Utilities/cmlibarchive/cpio/cpio.h deleted file mode 100644 index 511bef6b6..000000000 --- a/Utilities/cmlibarchive/cpio/cpio.h +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/cpio/cpio.h,v 1.7 2008/12/06 07:30:40 kientzle Exp $ - */ - -#ifndef CPIO_H_INCLUDED -#define CPIO_H_INCLUDED - -#include "cpio_platform.h" -#include - -#include "matching.h" - -/* - * The internal state for the "cpio" program. - * - * Keeping all of the state in a structure like this simplifies memory - * leak testing (at exit, anything left on the heap is suspect). A - * pointer to this structure is passed to most cpio internal - * functions. - */ -struct cpio { - /* Option parsing */ - const char *optarg; - - /* Options */ - const char *filename; - char mode; /* -i -o -p */ - char compress; /* -j, -y, or -z */ - const char *format; /* -H format */ - int bytes_per_block; /* -b block_size */ - int verbose; /* -v */ - int quiet; /* --quiet */ - int extract_flags; /* Flags for extract operation */ - char symlink_mode; /* H or L, per BSD conventions */ - const char *compress_program; - int option_append; /* -A, only relevant for -o */ - int option_atime_restore; /* -a */ - int option_follow_links; /* -L */ - int option_link; /* -l */ - int option_list; /* -t */ - char option_null; /* --null */ - int option_numeric_uid_gid; /* -n */ - int option_rename; /* -r */ - char *destdir; - size_t pass_destpath_alloc; - char *pass_destpath; - int uid_override; - int gid_override; - int day_first; /* true if locale prefers day/mon */ - - /* If >= 0, then close this when done. */ - int fd; - - /* Miscellaneous state information */ - struct archive *archive; - struct archive *archive_read_disk; - int argc; - char **argv; - int return_value; /* Value returned by main() */ - struct archive_entry_linkresolver *linkresolver; - - struct name_cache *uname_cache; - struct name_cache *gname_cache; - - /* Work data. */ - struct lafe_matching *matching; - char *buff; - size_t buff_size; -}; - -const char *owner_parse(const char *, int *, int *); - - -/* Fake short equivalents for long options that otherwise lack them. */ -enum { - OPTION_INSECURE = 1, - OPTION_LZMA, - OPTION_NO_PRESERVE_OWNER, - OPTION_PRESERVE_OWNER, - OPTION_QUIET, - OPTION_VERSION -}; - -int cpio_getopt(struct cpio *cpio); - -#endif diff --git a/Utilities/cmlibarchive/cpio/cpio_platform.h b/Utilities/cmlibarchive/cpio/cpio_platform.h deleted file mode 100644 index 253b8a832..000000000 --- a/Utilities/cmlibarchive/cpio/cpio_platform.h +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/cpio/cpio_platform.h,v 1.2 2008/12/06 07:15:42 kientzle Exp $ - */ - -/* - * This header is the first thing included in any of the cpio - * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. - */ - -#ifndef CPIO_PLATFORM_H_INCLUDED -#define CPIO_PLATFORM_H_INCLUDED - -#if defined(PLATFORM_CONFIG_H) -/* Use hand-built config.h in environments that need it. */ -#include PLATFORM_CONFIG_H -#else -/* Read config.h or die trying. */ -#include "config.h" -#endif - -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#elif !defined(__FBSDID) -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ -#define __FBSDID(a) struct _undefined_hack -#endif - -#ifdef HAVE_LIBARCHIVE -/* If we're using the platform libarchive, include system headers. */ -#include -#include -#else -/* Otherwise, include user headers. */ -#include "archive.h" -#include "archive_entry.h" -#endif - -/* - * We need to be able to display a filesize using printf(). The type - * and format string here must be compatible with one another and - * large enough for any file. - */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#define CPIO_FILESIZE_TYPE __int64 -#define CPIO_FILESIZE_PRINTF "%I64u" -#elif HAVE_UINTMAX_T -#define CPIO_FILESIZE_TYPE uintmax_t -#define CPIO_FILESIZE_PRINTF "%ju" -#elif HAVE_UNSIGNED_LONG_LONG -#define CPIO_FILESIZE_TYPE unsigned long long -#define CPIO_FILESIZE_PRINTF "%llu" -#else -#define CPIO_FILESIZE_TYPE unsigned long -#define CPIO_FILESIZE_PRINTF "%lu" -#endif - - -/* How to mark functions that don't return. */ -#if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -#include "cpio_windows.h" -#endif - -#endif /* !CPIO_PLATFORM_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/cpio/cpio_windows.c b/Utilities/cmlibarchive/cpio/cpio_windows.c deleted file mode 100644 index 37d358fd0..000000000 --- a/Utilities/cmlibarchive/cpio/cpio_windows.c +++ /dev/null @@ -1,336 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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. - * - * $FreeBSD$ - */ - -#if defined(_WIN32) && !defined(__CYGWIN__) - -#include "cpio_platform.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cpio.h" -#include "err.h" - -#define EPOC_TIME (116444736000000000ULL) - -static void cpio_dosmaperr(unsigned long); - -/* - * Prepend "\\?\" to the path name and convert it to unicode to permit - * an extended-length path for a maximum total path length of 32767 - * characters. - * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx - */ -static wchar_t * -permissive_name(const char *name) -{ - wchar_t *wn, *wnp; - wchar_t *ws, *wsp; - size_t l, len, slen, alloclen; - int unc; - - len = strlen(name); - wn = malloc((len + 1) * sizeof(wchar_t)); - if (wn == NULL) - return (NULL); - l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); - if (l == 0) { - free(wn); - return (NULL); - } - wn[l] = L'\0'; - - /* Get a full path names */ - l = GetFullPathNameW(wn, 0, NULL, NULL); - if (l == 0) { - free(wn); - return (NULL); - } - wnp = malloc(l * sizeof(wchar_t)); - if (wnp == NULL) { - free(wn); - return (NULL); - } - len = GetFullPathNameW(wn, l, wnp, NULL); - free(wn); - wn = wnp; - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'?' && wnp[3] == L'\\') - /* We have already permissive names. */ - return (wn); - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'.' && wnp[3] == L'\\') { - /* Device names */ - if (((wnp[4] >= L'a' && wnp[4] <= L'z') || - (wnp[4] >= L'A' && wnp[4] <= L'Z')) && - wnp[5] == L':' && wnp[6] == L'\\') - wnp[2] = L'?';/* Not device names. */ - return (wn); - } - - unc = 0; - if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { - wchar_t *p = &wnp[2]; - - /* Skip server-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\') { - wchar_t *rp = ++p; - /* Skip share-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\' && p != rp) { - /* Now, match patterns such as - * "\\server-name\share-name\" */ - wnp += 2; - len -= 2; - unc = 1; - } - } - } - - alloclen = slen = 4 + (unc * 4) + len + 1; - ws = wsp = malloc(slen * sizeof(wchar_t)); - if (ws == NULL) { - free(wn); - return (NULL); - } - /* prepend "\\?\" */ - wcsncpy(wsp, L"\\\\?\\", 4); - wsp += 4; - slen -= 4; - if (unc) { - /* append "UNC\" ---> "\\?\UNC\" */ - wcsncpy(wsp, L"UNC\\", 4); - wsp += 4; - slen -= 4; - } - wcsncpy(wsp, wnp, slen); - free(wn); - ws[alloclen - 1] = L'\0'; - return (ws); -} - -static HANDLE -cpio_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, - LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -{ - wchar_t *wpath; - HANDLE handle; - - handle = CreateFileA(path, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); - if (handle != INVALID_HANDLE_VALUE) - return (handle); - if (GetLastError() != ERROR_PATH_NOT_FOUND) - return (handle); - wpath = permissive_name(path); - if (wpath == NULL) - return (handle); - handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); - free(wpath); - return (handle); -} - -#define WINTIME(sec, usec) ((Int32x32To64(sec, 10000000) + EPOC_TIME) + (usec * 10)) -static int -__hutimes(HANDLE handle, const struct __timeval *times) -{ - ULARGE_INTEGER wintm; - FILETIME fatime, fmtime; - - wintm.QuadPart = WINTIME(times[0].tv_sec, times[0].tv_usec); - fatime.dwLowDateTime = wintm.LowPart; - fatime.dwHighDateTime = wintm.HighPart; - wintm.QuadPart = WINTIME(times[1].tv_sec, times[1].tv_usec); - fmtime.dwLowDateTime = wintm.LowPart; - fmtime.dwHighDateTime = wintm.HighPart; - if (SetFileTime(handle, NULL, &fatime, &fmtime) == 0) { - errno = EINVAL; - return (-1); - } - return (0); -} - -int -futimes(int fd, const struct __timeval *times) -{ - - return (__hutimes((HANDLE)_get_osfhandle(fd), times)); -} - -int -utimes(const char *name, const struct __timeval *times) -{ - int ret; - HANDLE handle; - - handle = cpio_CreateFile(name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (handle == INVALID_HANDLE_VALUE) { - cpio_dosmaperr(GetLastError()); - return (-1); - } - ret = __hutimes(handle, times); - CloseHandle(handle); - return (ret); -} - -/* - * The following function was modified from PostgreSQL sources and is - * subject to the copyright below. - */ -/*------------------------------------------------------------------------- - * - * win32error.c - * Map win32 error codes to errno values - * - * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group - * - * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -/* -PostgreSQL Database Management System -(formerly known as Postgres, then as Postgres95) - -Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group - -Portions Copyright (c) 1994, The Regents of the University of California - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose, without fee, and without a written agreement -is hereby granted, provided that the above copyright notice and this -paragraph and the following two paragraphs appear in all copies. - -IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR -DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO -PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -*/ - -static const struct { - DWORD winerr; - int doserr; -} doserrors[] = -{ - { ERROR_INVALID_FUNCTION, EINVAL }, - { ERROR_FILE_NOT_FOUND, ENOENT }, - { ERROR_PATH_NOT_FOUND, ENOENT }, - { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, - { ERROR_ACCESS_DENIED, EACCES }, - { ERROR_INVALID_HANDLE, EBADF }, - { ERROR_ARENA_TRASHED, ENOMEM }, - { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, - { ERROR_INVALID_BLOCK, ENOMEM }, - { ERROR_BAD_ENVIRONMENT, E2BIG }, - { ERROR_BAD_FORMAT, ENOEXEC }, - { ERROR_INVALID_ACCESS, EINVAL }, - { ERROR_INVALID_DATA, EINVAL }, - { ERROR_INVALID_DRIVE, ENOENT }, - { ERROR_CURRENT_DIRECTORY, EACCES }, - { ERROR_NOT_SAME_DEVICE, EXDEV }, - { ERROR_NO_MORE_FILES, ENOENT }, - { ERROR_LOCK_VIOLATION, EACCES }, - { ERROR_SHARING_VIOLATION, EACCES }, - { ERROR_BAD_NETPATH, ENOENT }, - { ERROR_NETWORK_ACCESS_DENIED, EACCES }, - { ERROR_BAD_NET_NAME, ENOENT }, - { ERROR_FILE_EXISTS, EEXIST }, - { ERROR_CANNOT_MAKE, EACCES }, - { ERROR_FAIL_I24, EACCES }, - { ERROR_INVALID_PARAMETER, EINVAL }, - { ERROR_NO_PROC_SLOTS, EAGAIN }, - { ERROR_DRIVE_LOCKED, EACCES }, - { ERROR_BROKEN_PIPE, EPIPE }, - { ERROR_DISK_FULL, ENOSPC }, - { ERROR_INVALID_TARGET_HANDLE, EBADF }, - { ERROR_INVALID_HANDLE, EINVAL }, - { ERROR_WAIT_NO_CHILDREN, ECHILD }, - { ERROR_CHILD_NOT_COMPLETE, ECHILD }, - { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, - { ERROR_NEGATIVE_SEEK, EINVAL }, - { ERROR_SEEK_ON_DEVICE, EACCES }, - { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, - { ERROR_NOT_LOCKED, EACCES }, - { ERROR_BAD_PATHNAME, ENOENT }, - { ERROR_MAX_THRDS_REACHED, EAGAIN }, - { ERROR_LOCK_FAILED, EACCES }, - { ERROR_ALREADY_EXISTS, EEXIST }, - { ERROR_FILENAME_EXCED_RANGE, ENOENT }, - { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, - { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } -}; - -static void -cpio_dosmaperr(unsigned long e) -{ - int i; - - if (e == 0) { - errno = 0; - return; - } - - for (i = 0; i < sizeof(doserrors); i++) { - if (doserrors[i].winerr == e) { - errno = doserrors[i].doserr; - return; - } - } - - /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ - errno = EINVAL; - return; -} -#endif diff --git a/Utilities/cmlibarchive/cpio/cpio_windows.h b/Utilities/cmlibarchive/cpio/cpio_windows.h deleted file mode 100644 index 5c14c8ad8..000000000 --- a/Utilities/cmlibarchive/cpio/cpio_windows.h +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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. - * - * $FreeBSD$ - */ -#ifndef CPIO_WINDOWS_H -#define CPIO_WINDOWS_H 1 - -#include -#include - -#define getgrgid(id) NULL -#define getgrnam(name) NULL -#define getpwnam(name) NULL -#define getpwuid(id) NULL - -#ifdef _MSC_VER -#define snprintf sprintf_s -#define strdup _strdup -#define open _open -#define read _read -#define close _close -#endif - -struct passwd { - char *pw_name; - uid_t pw_uid; - gid_t pw_gid; -}; - -struct group { - char *gr_name; - gid_t gr_gid; -}; - -struct _timeval64i32 { - time_t tv_sec; - long tv_usec; -}; -#define __timeval _timeval64i32 - -extern int futimes(int fd, const struct __timeval *times); -#ifndef HAVE_FUTIMES -#define HAVE_FUTIMES 1 -#endif -extern int utimes(const char *name, const struct __timeval *times); -#ifndef HAVE_UTIMES -#define HAVE_UTIMES 1 -#endif - -#endif /* CPIO_WINDOWS_H */ diff --git a/Utilities/cmlibarchive/cpio/test/CMakeLists.txt b/Utilities/cmlibarchive/cpio/test/CMakeLists.txt deleted file mode 100644 index 4e1c98f53..000000000 --- a/Utilities/cmlibarchive/cpio/test/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -############################################ -# -# How to build bsdcpio_test -# -############################################ -IF(ENABLE_CPIO AND ENABLE_TEST) - SET(bsdcpio_test_SOURCES - ../cmdline.c - ../../libarchive_fe/err.c - ../../libarchive_fe/pathmatch.c - main.c - test.h - test_0.c - test_basic.c - test_cmdline.c - test_format_newc.c - test_gcpio_compat.c - test_option_B_upper.c - test_option_C_upper.c - test_option_J_upper.c - test_option_L_upper.c - test_option_Z_upper.c - test_option_a.c - test_option_c.c - test_option_d.c - test_option_f.c - test_option_help.c - test_option_l.c - test_option_lzma.c - test_option_m.c - test_option_t.c - test_option_u.c - test_option_version.c - test_option_y.c - test_option_z.c - test_owner_parse.c - test_passthrough_dotdot.c - test_passthrough_reverse.c - test_pathmatch.c - ) - IF(WIN32 AND NOT CYGWIN) - LIST(APPEND bsdcpio_test_SOURCES ../cpio_windows.h) - ENDIF(WIN32 AND NOT CYGWIN) - - # - # Generate the list.h - # - GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h - ${CMAKE_CURRENT_LIST_FILE} ${bsdcpio_test_SOURCES}) - SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_BINARY_DIR}) - # - # Register target - # - ADD_EXECUTABLE(bsdcpio_test ${bsdcpio_test_SOURCES}) - SET_PROPERTY(TARGET bsdcpio_test PROPERTY COMPILE_DEFINITIONS LIST_H) - - # ADD_TEST() for each separate test - SET(num 0) - FOREACH(test ${bsdcpio_test_SOURCES}) - IF(test MATCHES "^test_[^/]+[.]c$") - STRING(REGEX REPLACE "^(test_[^/]+)[.]c$" "\\1" testname ${test}) - ADD_TEST("bsdcpio_${testname}" bsdcpio_test - -v -p ${BSDCPIO} -r ${CMAKE_CURRENT_SOURCE_DIR} ${num}) - MATH(EXPR num "${num} + 1") - ENDIF(test MATCHES "^test_[^/]+[.]c$") - ENDFOREACH(test) - - # Experimental new test handling - ADD_CUSTOM_TARGET(run_bsdcpio_test - COMMAND bsdcpio_test -p ${BSDCPIO} -r ${CMAKE_CURRENT_SOURCE_DIR}) - ADD_DEPENDENCIES(run_bsdcpio_test bsdcpio) - ADD_DEPENDENCIES(run_all_tests run_bsdcpio_test) -ENDIF(ENABLE_CPIO AND ENABLE_TEST) - diff --git a/Utilities/cmlibarchive/cpio/test/main.c b/Utilities/cmlibarchive/cpio/test/main.c deleted file mode 100644 index 2740134ce..000000000 --- a/Utilities/cmlibarchive/cpio/test/main.c +++ /dev/null @@ -1,2059 +0,0 @@ -/* - * Copyright (c) 2003-2009 Tim Kientzle - * 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 -#include -#include -#include -#include "test.h" - -/* - * This same file is used pretty much verbatim for all test harnesses. - * - * The next few lines are the only differences. - * TODO: Move this into a separate configuration header, have all test - * suites share one copy of this file. - */ -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/main.c,v 1.3 2008/08/24 04:58:22 kientzle Exp $"); -#define KNOWNREF "test_option_f.cpio.uu" -#define ENVBASE "BSDCPIO" /* Prefix for environment variables. */ -#define PROGRAM "bsdcpio" /* Name of program being tested. */ -#undef LIBRARY /* Not testing a library. */ -#undef EXTRA_DUMP /* How to dump extra data */ -/* How to generate extra version info. */ -#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") - -/* - * - * Windows support routines - * - * Note: Configuration is a tricky issue. Using HAVE_* feature macros - * in the test harness is dangerous because they cover up - * configuration errors. The classic example of this is omitting a - * configure check. If libarchive and libarchive_test both look for - * the same feature macro, such errors are hard to detect. Platform - * macros (e.g., _WIN32 or __GNUC__) are a little better, but can - * easily lead to very messy code. It's best to limit yourself - * to only the most generic programming techniques in the test harness - * and thus avoid conditionals altogether. Where that's not possible, - * try to minimize conditionals by grouping platform-specific tests in - * one place (e.g., test_acl_freebsd) or by adding new assert() - * functions (e.g., assertMakeHardlink()) to cover up platform - * differences. Platform-specific coding in libarchive_test is often - * a symptom that some capability is missing from libarchive itself. - */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#if !defined(__GNUC__) -#include -#endif -#include -#include -#ifndef F_OK -#define F_OK (0) -#endif -#ifndef S_ISDIR -#define S_ISDIR(m) ((m) & _S_IFDIR) -#endif -#ifndef S_ISREG -#define S_ISREG(m) ((m) & _S_IFREG) -#endif -#define access _access -#define chdir _chdir -#ifndef fileno -#define fileno _fileno -#endif -/*#define fstat _fstat64*/ -#define getcwd _getcwd -#define lstat stat -/*#define lstat _stat64*/ -/*#define stat _stat64*/ -#define rmdir _rmdir -#define strdup _strdup -#define umask _umask -#define int64_t __int64 -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -void *GetFunctionKernel32(const char *name) -{ - static HINSTANCE lib; - static int set; - if (!set) { - set = 1; - lib = LoadLibrary("kernel32.dll"); - } - if (lib == NULL) { - fprintf(stderr, "Can't load kernel32.dll?!\n"); - exit(1); - } - return (void *)GetProcAddress(lib, name); -} - -static int -my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateSymbolicLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, flags); -} - -static int -my_CreateHardLinkA(const char *linkname, const char *target) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, NULL); -} - -int -my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) -{ - HANDLE h; - int r; - - memset(bhfi, 0, sizeof(*bhfi)); - h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) - return (0); - r = GetFileInformationByHandle(h, bhfi); - CloseHandle(h); - return (r); -} -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) -static void -invalid_parameter_handler(const wchar_t * expression, - const wchar_t * function, const wchar_t * file, - unsigned int line, uintptr_t pReserved) -{ - /* nop */ -} -#endif - -/* - * - * OPTIONS FLAGS - * - */ - -/* Enable core dump on failure. */ -static int dump_on_failure = 0; -/* Default is to remove temp dirs and log data for successful tests. */ -static int keep_temp_files = 0; -/* Default is to just report pass/fail for each test. */ -static int verbosity = 0; -#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ -#define VERBOSITY_PASSFAIL 0 /* Default */ -#define VERBOSITY_LIGHT_REPORT 1 /* -v */ -#define VERBOSITY_FULL 2 /* -vv */ -/* A few places generate even more output for verbosity > VERBOSITY_FULL, - * mostly for debugging the test harness itself. */ -/* Cumulative count of assertion failures. */ -static int failures = 0; -/* Cumulative count of reported skips. */ -static int skips = 0; -/* Cumulative count of assertions checked. */ -static int assertions = 0; - -/* Directory where uuencoded reference files can be found. */ -static const char *refdir; - -/* - * Report log information selectively to console and/or disk log. - */ -static int log_console = 0; -static FILE *logfile; -static void -vlogprintf(const char *fmt, va_list ap) -{ - if (log_console) - vfprintf(stdout, fmt, ap); - if (logfile != NULL) - vfprintf(logfile, fmt, ap); -} - -static void -logprintf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vlogprintf(fmt, ap); - va_end(ap); -} - -/* Set up a message to display only if next assertion fails. */ -static char msgbuff[4096]; -static const char *msg, *nextmsg; -void -failure(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); - va_end(ap); - nextmsg = msgbuff; -} - -/* - * Copy arguments into file-local variables. - * This was added to permit vararg assert() functions without needing - * variadic wrapper macros. Turns out that the vararg capability is almost - * never used, so almost all of the vararg assertions can be simplified - * by removing the vararg capability and reworking the wrapper macro to - * pass __FILE__, __LINE__ directly into the function instead of using - * this hook. I suspect this machinery is used so rarely that we - * would be better off just removing it entirely. That would simplify - * the code here noticably. - */ -static const char *test_filename; -static int test_line; -static void *test_extra; -void assertion_setup(const char *filename, int line) -{ - test_filename = filename; - test_line = line; -} - -/* Called at the beginning of each assert() function. */ -static void -assertion_count(const char *file, int line) -{ - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - ++assertions; - /* Proper handling of "failure()" message. */ - msg = nextmsg; - nextmsg = NULL; - /* Uncomment to print file:line after every assertion. - * Verbose, but occasionally useful in tracking down crashes. */ - /* printf("Checked %s:%d\n", file, line); */ -} - -/* - * For each test source file, we remember how many times each - * assertion was reported. Cleared before each new test, - * used by test_summarize(). - */ -static struct line { - int count; - int skip; -} failed_lines[10000]; - -/* Count this failure, setup up log destination and handle initial report. */ -static void -failure_start(const char *filename, int line, const char *fmt, ...) -{ - va_list ap; - - /* Record another failure for this line. */ - ++failures; - test_filename = filename; - failed_lines[line].count++; - - /* Determine whether to log header to console. */ - switch (verbosity) { - case VERBOSITY_FULL: - log_console = 1; - break; - case VERBOSITY_LIGHT_REPORT: - log_console = (failed_lines[line].count < 2); - break; - default: - log_console = 0; - } - - /* Log file:line header for this failure */ - va_start(ap, fmt); -#if _MSC_VER - logprintf("%s(%d): ", filename, line); -#else - logprintf("%s:%d: ", filename, line); -#endif - vlogprintf(fmt, ap); - va_end(ap); - logprintf("\n"); - - if (msg != NULL && msg[0] != '\0') { - logprintf(" Description: %s\n", msg); - msg = NULL; - } - - /* Determine whether to log details to console. */ - if (verbosity == VERBOSITY_LIGHT_REPORT) - log_console = 0; -} - -/* Complete reporting of failed tests. */ -/* - * The 'extra' hook here is used by libarchive to include libarchive - * error messages with assertion failures. It could also be used - * to add strerror() output, for example. Just define the EXTRA_DUMP() - * macro appropriately. - */ -static void -failure_finish(void *extra) -{ - (void)extra; /* UNUSED (maybe) */ -#ifdef EXTRA_DUMP - if (extra != NULL) - logprintf(" detail: %s\n", EXTRA_DUMP(extra)); -#endif - - if (dump_on_failure) { - fprintf(stderr, - " *** forcing core dump so failure can be debugged ***\n"); - *(char *)(NULL) = 0; - exit(1); - } -} - -/* Inform user that we're skipping some checks. */ -void -test_skipping(const char *fmt, ...) -{ - char buff[1024]; - va_list ap; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - va_end(ap); - /* failure_start() isn't quite right, but is awfully convenient. */ - failure_start(test_filename, test_line, "SKIPPING: %s", buff); - --failures; /* Undo failures++ in failure_start() */ - /* Don't failure_finish() here. */ - /* Mark as skip, so doesn't count as failed test. */ - failed_lines[test_line].skip = 1; - ++skips; -} - -/* - * - * ASSERTIONS - * - */ - -/* Generic assert() just displays the failed condition. */ -int -assertion_assert(const char *file, int line, int value, - const char *condition, void *extra) -{ - assertion_count(file, line); - if (!value) { - failure_start(file, line, "Assertion failed: %s", condition); - failure_finish(extra); - } - return (value); -} - -/* chdir() and report any errors */ -int -assertion_chdir(const char *file, int line, const char *pathname) -{ - assertion_count(file, line); - if (chdir(pathname) == 0) - return (1); - failure_start(file, line, "chdir(\"%s\")", pathname); - failure_finish(NULL); - return (0); - -} - -/* Verify two integers are equal. */ -int -assertion_equal_int(const char *file, int line, - long long v1, const char *e1, long long v2, const char *e2, void *extra) -{ - assertion_count(file, line); - if (v1 == v2) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); - failure_finish(extra); - return (0); -} - -static void strdump(const char *e, const char *p) -{ - logprintf(" %s = ", e); - if (p == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*p != '\0') { - unsigned int c = 0xff & *p++; - switch (c) { - case '\a': printf("\a"); break; - case '\b': printf("\b"); break; - case '\n': printf("\n"); break; - case '\r': printf("\r"); break; - default: - if (c >= 32 && c < 127) - logprintf("%c", c); - else - logprintf("\\x%02X", c); - } - } - logprintf("\""); - logprintf(" (length %d)\n", p == NULL ? 0 : (int)strlen(p)); -} - -/* Verify two strings are equal, dump them if not. */ -int -assertion_equal_string(const char *file, int line, - const char *v1, const char *e1, - const char *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || strcmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - strdump(e1, v1); - strdump(e2, v2); - failure_finish(extra); - return (0); -} - -static void -wcsdump(const char *e, const wchar_t *w) -{ - logprintf(" %s = ", e); - if (w == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*w != L'\0') { - unsigned int c = *w++; - if (c >= 32 && c < 127) - logprintf("%c", c); - else if (c < 256) - logprintf("\\x%02X", c); - else if (c < 0x10000) - logprintf("\\u%04X", c); - else - logprintf("\\U%08X", c); - } - logprintf("\"\n"); -} - -/* Verify that two wide strings are equal, dump them if not. */ -int -assertion_equal_wstring(const char *file, int line, - const wchar_t *v1, const char *e1, - const wchar_t *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - wcsdump(e1, v1); - wcsdump(e2, v2); - failure_finish(extra); - return (0); -} - -/* - * Pretty standard hexdump routine. As a bonus, if ref != NULL, then - * any bytes in p that differ from ref will be highlighted with '_' - * before and after the hex value. - */ -static void -hexdump(const char *p, const char *ref, size_t l, size_t offset) -{ - size_t i, j; - char sep; - - for(i=0; i < l; i+=16) { - logprintf("%04x", (unsigned)(i + offset)); - sep = ' '; - for (j = 0; j < 16 && i + j < l; j++) { - if (ref != NULL && p[i + j] != ref[i + j]) - sep = '_'; - logprintf("%c%02x", sep, 0xff & (int)p[i+j]); - if (ref != NULL && p[i + j] == ref[i + j]) - sep = ' '; - } - for (; j < 16; j++) { - logprintf("%c ", sep); - sep = ' '; - } - logprintf("%c", sep); - for (j=0; j < 16 && i + j < l; j++) { - int c = p[i + j]; - if (c >= ' ' && c <= 126) - logprintf("%c", c); - else - logprintf("."); - } - logprintf("\n"); - } -} - -/* Verify that two blocks of memory are the same, display the first - * block of differences if they're not. */ -int -assertion_equal_mem(const char *file, int line, - const void *_v1, const char *e1, - const void *_v2, const char *e2, - size_t l, const char *ld, void *extra) -{ - const char *v1 = (const char *)_v1; - const char *v2 = (const char *)_v2; - size_t offset; - - assertion_count(file, line); - if (v1 == v2 || memcmp(v1, v2, l) == 0) - return (1); - - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" size %s = %d\n", ld, (int)l); - /* Dump 48 bytes (3 lines) so that the first difference is - * in the second line. */ - offset = 0; - while (l > 64 && memcmp(v1, v2, 32) == 0) { - /* Two lines agree, so step forward one line. */ - v1 += 16; - v2 += 16; - l -= 16; - offset += 16; - } - logprintf(" Dump of %s\n", e1); - hexdump(v1, v2, l < 64 ? l : 64, offset); - logprintf(" Dump of %s\n", e2); - hexdump(v2, v1, l < 64 ? l : 64, offset); - logprintf("\n"); - failure_finish(extra); - return (0); -} - -/* Verify that the named file exists and is empty. */ -int -assertion_empty_file(const char *f1fmt, ...) -{ - char buff[1024]; - char f1[1024]; - struct stat st; - va_list ap; - ssize_t s; - FILE *f; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) - return (1); - - failure_start(test_filename, test_line, "File should be empty: %s", f1); - logprintf(" File size: %d\n", (int)st.st_size); - logprintf(" Contents:\n"); - f = fopen(f1, "rb"); - if (f == NULL) { - logprintf(" Unable to open %s\n", f1); - } else { - s = ((off_t)sizeof(buff) < st.st_size) ? - (ssize_t)sizeof(buff) : (ssize_t)st.st_size; - s = fread(buff, 1, s, f); - hexdump(buff, NULL, s, 0); - fclose(f); - } - failure_finish(NULL); - return (0); -} - -/* Verify that the named file exists and is not empty. */ -int -assertion_non_empty_file(const char *f1fmt, ...) -{ - char f1[1024]; - struct stat st; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) { - failure_start(test_filename, test_line, "File empty: %s", f1); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify that two files have the same contents. */ -/* TODO: hexdump the first bytes that actually differ. */ -int -assertion_equal_file(const char *fn1, const char *f2pattern, ...) -{ - char fn2[1024]; - va_list ap; - char buff1[1024]; - char buff2[1024]; - FILE *f1, *f2; - int n1, n2; - - assertion_count(test_filename, test_line); - va_start(ap, f2pattern); - vsprintf(fn2, f2pattern, ap); - va_end(ap); - - f1 = fopen(fn1, "rb"); - f2 = fopen(fn2, "rb"); - for (;;) { - n1 = fread(buff1, 1, sizeof(buff1), f1); - n2 = fread(buff2, 1, sizeof(buff2), f2); - if (n1 != n2) - break; - if (n1 == 0 && n2 == 0) { - fclose(f1); - fclose(f2); - return (1); - } - if (memcmp(buff1, buff2, n1) != 0) - break; - } - fclose(f1); - fclose(f2); - failure_start(test_filename, test_line, "Files not identical"); - logprintf(" file1=\"%s\"\n", fn1); - logprintf(" file2=\"%s\"\n", fn2); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file does exist. */ -int -assertion_file_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (!_access(f, 0)) - return (1); -#else - if (!access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file doesn't exist. */ -int -assertion_file_not_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (_access(f, 0)) - return (1); -#else - if (access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should not exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Compare the contents of a file to a block of memory. */ -int -assertion_file_contents(const void *buff, int s, const char *fpattern, ...) -{ - char fn[1024]; - va_list ap; - char *contents; - FILE *f; - int n; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(fn, fpattern, ap); - va_end(ap); - - f = fopen(fn, "rb"); - if (f == NULL) { - failure_start(test_filename, test_line, - "File should exist: %s", fn); - failure_finish(test_extra); - return (0); - } - contents = malloc(s * 2); - n = fread(contents, 1, s * 2, f); - fclose(f); - if (n == s && memcmp(buff, contents, s) == 0) { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "File contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n > 512 ? 512 : 0, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s > 512 ? 512 : 0, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Check the contents of a text file, being tolerant of line endings. */ -int -assertion_text_file_contents(const char *buff, const char *fn) -{ - char *contents; - const char *btxt, *ftxt; - FILE *f; - int n, s; - - assertion_count(test_filename, test_line); - f = fopen(fn, "r"); - s = strlen(buff); - contents = malloc(s * 2 + 128); - n = fread(contents, 1, s * 2 + 128 - 1, f); - if (n >= 0) - contents[n] = '\0'; - fclose(f); - /* Compare texts. */ - btxt = buff; - ftxt = (const char *)contents; - while (*btxt != '\0' && *ftxt != '\0') { - if (*btxt == *ftxt) { - ++btxt; - ++ftxt; - continue; - } - if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { - /* Pass over different new line characters. */ - ++btxt; - ftxt += 2; - continue; - } - break; - } - if (*btxt == '\0' && *ftxt == '\0') { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "Contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Test that two paths point to the same file. */ -/* As a side-effect, asserts that both files exist. */ -static int -is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(path1, &bhfi1); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path1); - failure_finish(NULL); - return (0); - } - r = my_GetFileInformationByName(path2, &bhfi2); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path2); - failure_finish(NULL); - return (0); - } - return (bhfi1.dwVolumeSerialNumber == bhfi2.dwVolumeSerialNumber - && bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh - && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); -#else - struct stat st1, st2; - int r; - - assertion_count(file, line); - r = lstat(path1, &st1); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path1); - failure_finish(NULL); - return (0); - } - r = lstat(path2, &st2); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path2); - failure_finish(NULL); - return (0); - } - return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); -#endif -} - -int -assertion_is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s are not hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -int -assertion_is_not_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (!is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s should not be hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -/* Verify a/b/mtime of 'pathname'. */ -/* If 'recent', verify that it's within last 10 seconds. */ -static int -assertion_file_time(const char *file, int line, - const char *pathname, long t, long nsec, char type, int recent) -{ - long long filet, filet_nsec; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define EPOC_TIME (116444736000000000ULL) - FILETIME ftime, fbirthtime, fatime, fmtime; - ULARGE_INTEGER wintm; - HANDLE h; - ftime.dwLowDateTime = 0; - ftime.dwHighDateTime = 0; - - assertion_count(file, line); - h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - failure_start(file, line, "Can't access %s\n", pathname); - failure_finish(NULL); - return (0); - } - r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); - switch (type) { - case 'a': ftime = fatime; break; - case 'b': ftime = fbirthtime; break; - case 'm': ftime = fmtime; break; - } - CloseHandle(h); - if (r == 0) { - failure_start(file, line, "Can't GetFileTime %s\n", pathname); - failure_finish(NULL); - return (0); - } - wintm.LowPart = ftime.dwLowDateTime; - wintm.HighPart = ftime.dwHighDateTime; - filet = (wintm.QuadPart - EPOC_TIME) / 10000000; - filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; - nsec = (nsec / 100) * 100; /* Round the request */ -#else - struct stat st; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Can't stat %s\n", pathname); - failure_finish(NULL); - return (0); - } - switch (type) { - case 'a': filet = st.st_atime; break; - case 'm': filet = st.st_mtime; break; - case 'b': filet = 0; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } -#if defined(__FreeBSD__) - switch (type) { - case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; - case 'b': filet = st.st_birthtime; - filet_nsec = st.st_birthtimespec.tv_nsec; break; - case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } - /* FreeBSD generally only stores to microsecond res, so round. */ - filet_nsec = (filet_nsec / 1000) * 1000; - nsec = (nsec / 1000) * 1000; -#else - filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ - if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ -#endif -#endif - if (recent) { - /* Check that requested time is up-to-date. */ - time_t now = time(NULL); - if (filet < now - 10 || filet > now + 1) { - failure_start(file, line, - "File %s has %ctime %ld, %ld seconds ago\n", - pathname, type, filet, now - filet); - failure_finish(NULL); - return (0); - } - } else if (filet != t || filet_nsec != nsec) { - failure_start(file, line, - "File %s has %ctime %ld.%09ld, expected %ld.%09ld", - pathname, type, filet, filet_nsec, t, nsec); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify atime of 'pathname'. */ -int -assertion_file_atime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); -} - -/* Verify atime of 'pathname' is up-to-date. */ -int -assertion_file_atime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); -} - -/* Verify birthtime of 'pathname'. */ -int -assertion_file_birthtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); -} - -/* Verify birthtime of 'pathname' is up-to-date. */ -int -assertion_file_birthtime_recent(const char *file, int line, - const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); -} - -/* Verify mtime of 'pathname'. */ -int -assertion_file_mtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); -} - -/* Verify mtime of 'pathname' is up-to-date. */ -int -assertion_file_mtime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); -} - -/* Verify number of links to 'pathname'. */ -int -assertion_file_nlinks(const char *file, int line, - const char *pathname, int nlinks) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(pathname, &bhfi); - if (r != 0 && bhfi.nNumberOfLinks == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, bhfi.nNumberOfLinks, nlinks); - failure_finish(NULL); - return (0); -#else - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_nlink == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, st.st_nlink, nlinks); - failure_finish(NULL); - return (0); -#endif -} - -/* Verify size of 'pathname'. */ -int -assertion_file_size(const char *file, int line, const char *pathname, long size) -{ - int64_t filesize; - int r; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - { - BY_HANDLE_FILE_INFORMATION bhfi; - r = !my_GetFileInformationByName(pathname, &bhfi); - filesize = ((int64_t)bhfi.nFileSizeHigh << 32) + bhfi.nFileSizeLow; - } -#else - { - struct stat st; - r = lstat(pathname, &st); - filesize = st.st_size; - } -#endif - if (r == 0 && filesize == size) - return (1); - failure_start(file, line, "File %s has size %ld, expected %ld", - pathname, (long)filesize, (long)size); - failure_finish(NULL); - return (0); -} - -/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ -int -assertion_is_dir(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Dir should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISDIR(st.st_mode)) { - failure_start(file, line, "%s is not a dir", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "Dir %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, - * verify that too. */ -int -assertion_is_reg(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0 || !S_ISREG(st.st_mode)) { - failure_start(file, line, "File should exist: %s", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "File %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Check whether 'pathname' is a symbolic link. If 'contents' is - * non-NULL, verify that the symlink has those contents. */ -static int -is_symlink(const char *file, int line, - const char *pathname, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - assertion_count(file, line); - return (0); -#else - char buff[300]; - struct stat st; - ssize_t linklen; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, - "Symlink should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISLNK(st.st_mode)) - return (0); - if (contents == NULL) - return (1); - linklen = readlink(pathname, buff, sizeof(buff)); - if (linklen < 0) { - failure_start(file, line, "Can't read symlink %s", pathname); - failure_finish(NULL); - return (0); - } - buff[linklen] = '\0'; - if (strcmp(buff, contents) != 0) - return (0); - return (1); -#endif -} - -/* Assert that path is a symlink that (optionally) contains contents. */ -int -assertion_is_symlink(const char *file, int line, - const char *path, const char *contents) -{ - if (is_symlink(file, line, path, contents)) - return (1); - if (contents) - failure_start(file, line, "File %s is not a symlink to %s", - path, contents); - else - failure_start(file, line, "File %s is not a symlink", path); - failure_finish(NULL); - return (0); -} - - -/* Create a directory and report any errors. */ -int -assertion_make_dir(const char *file, int line, const char *dirname, int mode) -{ - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - if (0 == _mkdir(dirname)) - return (1); -#else - if (0 == mkdir(dirname, mode)) - return (1); -#endif - failure_start(file, line, "Could not create directory %s", dirname); - failure_finish(NULL); - return(0); -} - -/* Create a file with the specified contents and report any failures. */ -int -assertion_make_file(const char *file, int line, - const char *path, int mode, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: Rework this to set file mode as well. */ - FILE *f; - assertion_count(file, line); - f = fopen(path, "wb"); - if (f == NULL) { - failure_start(file, line, "Could not create file %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if (strlen(contents) - != fwrite(contents, 1, strlen(contents), f)) { - fclose(f); - failure_start(file, line, - "Could not write file %s", path); - failure_finish(NULL); - return (0); - } - } - fclose(f); - return (1); -#else - int fd; - assertion_count(file, line); - fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); - if (fd < 0) { - failure_start(file, line, "Could not create %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if ((ssize_t)strlen(contents) - != write(fd, contents, strlen(contents))) { - close(fd); - failure_start(file, line, "Could not write to %s", path); - failure_finish(NULL); - return (0); - } - } - close(fd); - return (1); -#endif -} - -/* Create a hardlink and report any failures. */ -int -assertion_make_hardlink(const char *file, int line, - const char *newpath, const char *linkto) -{ - int succeeded; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = my_CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK - succeeded = !link(linkto, newpath); -#else - succeeded = 0; -#endif - if (succeeded) - return (1); - failure_start(file, line, "Could not create hardlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Create a symlink and report any failures. */ -int -assertion_make_symlink(const char *file, int line, - const char *newpath, const char *linkto) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - int targetIsDir = 0; /* TODO: Fix this */ - assertion_count(file, line); - if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) - return (1); -#elif HAVE_SYMLINK - assertion_count(file, line); - if (0 == symlink(linkto, newpath)) - return (1); -#endif - failure_start(file, line, "Could not create symlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Set umask, report failures. */ -int -assertion_umask(const char *file, int line, int mask) -{ - assertion_count(file, line); - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - umask(mask); - return (1); -} - -/* - * - * UTILITIES for use by tests. - * - */ - -/* - * Check whether platform supports symlinks. This is intended - * for tests to use in deciding whether to bother testing symlink - * support; if the platform doesn't support symlinks, there's no point - * in checking whether the program being tested can create them. - */ -int -canSymlink(void) -{ - /* Remember the test result */ - static int value = 0, tested = 0; - if (tested) - return (value); - - ++tested; - assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); -#if defined(_WIN32) && !defined(__CYGWIN__) - value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) - && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); -#elif HAVE_SYMLINK - value = (0 == symlink("canSymlink.0", "canSymlink.1")) - && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); -#endif - return (value); -} - -/* - * Can this platform run the gzip program? - */ -/* Platform-dependent options for hiding the output of a subcommand. */ -#if defined(_WIN32) && !defined(__CYGWIN__) -static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ -#else -static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ -#endif -int -canGzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Can this platform run the gunzip program? - */ -int -canGunzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gunzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Sleep as needed; useful for verifying disk timestamp changes by - * ensuring that the wall-clock time has actually changed before we - * go back to re-read something from disk. - */ -void -sleepUntilAfter(time_t t) -{ - while (t >= time(NULL)) -#if defined(_WIN32) && !defined(__CYGWIN__) - Sleep(500); -#else - sleep(1); -#endif -} - -/* - * Call standard system() call, but build up the command line using - * sprintf() conventions. - */ -int -systemf(const char *fmt, ...) -{ - char buff[8192]; - va_list ap; - int r; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - if (verbosity > VERBOSITY_FULL) - logprintf("Cmd: %s\n", buff); - r = system(buff); - va_end(ap); - return (r); -} - -/* - * Slurp a file into memory for ease of comparison and testing. - * Returns size of file in 'sizep' if non-NULL, null-terminates - * data in memory for ease of use. - */ -char * -slurpfile(size_t * sizep, const char *fmt, ...) -{ - char filename[8192]; - struct stat st; - va_list ap; - char *p; - ssize_t bytes_read; - FILE *f; - int r; - - va_start(ap, fmt); - vsprintf(filename, fmt, ap); - va_end(ap); - - f = fopen(filename, "rb"); - if (f == NULL) { - /* Note: No error; non-existent file is okay here. */ - return (NULL); - } - r = fstat(fileno(f), &st); - if (r != 0) { - logprintf("Can't stat file %s\n", filename); - fclose(f); - return (NULL); - } - p = malloc((size_t)st.st_size + 1); - if (p == NULL) { - logprintf("Can't allocate %ld bytes of memory to read file %s\n", - (long int)st.st_size, filename); - fclose(f); - return (NULL); - } - bytes_read = fread(p, 1, (size_t)st.st_size, f); - if (bytes_read < st.st_size) { - logprintf("Can't read file %s\n", filename); - fclose(f); - free(p); - return (NULL); - } - p[st.st_size] = '\0'; - if (sizep != NULL) - *sizep = (size_t)st.st_size; - fclose(f); - return (p); -} - -/* Read a uuencoded file from the reference directory, decode, and - * write the result into the current directory. */ -#define UUDECODE(c) (((c) - 0x20) & 0x3f) -void -extract_reference_file(const char *name) -{ - char buff[1024]; - FILE *in, *out; - - sprintf(buff, "%s/%s.uu", refdir, name); - in = fopen(buff, "r"); - failure("Couldn't open reference file %s", buff); - assert(in != NULL); - if (in == NULL) - return; - /* Read up to and including the 'begin' line. */ - for (;;) { - if (fgets(buff, sizeof(buff), in) == NULL) { - /* TODO: This is a failure. */ - return; - } - if (memcmp(buff, "begin ", 6) == 0) - break; - } - /* Now, decode the rest and write it. */ - /* Not a lot of error checking here; the input better be right. */ - out = fopen(name, "wb"); - while (fgets(buff, sizeof(buff), in) != NULL) { - char *p = buff; - int bytes; - - if (memcmp(buff, "end", 3) == 0) - break; - - bytes = UUDECODE(*p++); - while (bytes > 0) { - int n = 0; - /* Write out 1-3 bytes from that. */ - if (bytes > 0) { - n = UUDECODE(*p++) << 18; - n |= UUDECODE(*p++) << 12; - fputc(n >> 16, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++) << 6; - fputc((n >> 8) & 0xFF, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++); - fputc(n & 0xFF, out); - --bytes; - } - } - } - fclose(out); - fclose(in); -} - -/* - * - * TEST management - * - */ - -/* - * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has - * a line like - * DEFINE_TEST(test_function) - * for each test. - */ - -/* Use "list.h" to declare all of the test functions. */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); -#include "list.h" - -/* Use "list.h" to create a list of all tests (functions and names). */ -#undef DEFINE_TEST -#define DEFINE_TEST(n) { n, #n, 0 }, -struct { void (*func)(void); const char *name; int failures; } tests[] = { - #include "list.h" -}; - -/* - * Summarize repeated failures in the just-completed test. - */ -static void -test_summarize(const char *filename, int failed) -{ - unsigned int i; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: - printf(failed ? "E" : "."); - fflush(stdout); - break; - case VERBOSITY_PASSFAIL: - printf(failed ? "FAIL\n" : "ok\n"); - break; - } - - log_console = (verbosity == VERBOSITY_LIGHT_REPORT); - - for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { - if (failed_lines[i].count > 1 && !failed_lines[i].skip) - logprintf("%s:%d: Summary: Failed %d times\n", - filename, i, failed_lines[i].count); - } - /* Clear the failure history for the next file. */ - memset(failed_lines, 0, sizeof(failed_lines)); -} - -/* - * Actually run a single test, with appropriate setup and cleanup. - */ -static int -test_run(int i, const char *tmpdir) -{ - char logfilename[64]; - int failures_before = failures; - int oldumask; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ - break; - case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ - printf("%3d: %-50s", i, tests[i].name); - fflush(stdout); - break; - default: /* Title of test, details will follow */ - printf("%3d: %s\n", i, tests[i].name); - } - - /* Chdir to the top-level work directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, - "ERROR: Can't chdir to top work dir %s\n", tmpdir); - exit(1); - } - /* Create a log file for this test. */ - sprintf(logfilename, "%s.log", tests[i].name); - logfile = fopen(logfilename, "w"); - fprintf(logfile, "%s\n\n", tests[i].name); - /* Chdir() to a work dir for this specific test. */ - if (!assertMakeDir(tests[i].name, 0755) - || !assertChdir(tests[i].name)) { - fprintf(stderr, - "ERROR: Can't chdir to work dir %s/%s\n", - tmpdir, tests[i].name); - exit(1); - } - /* Explicitly reset the locale before each test. */ - setlocale(LC_ALL, "C"); - /* Record the umask before we run the test. */ - umask(oldumask = umask(0)); - /* - * Run the actual test. - */ - (*tests[i].func)(); - /* - * Clean up and report afterwards. - */ - /* Restore umask */ - umask(oldumask); - /* Reset locale. */ - setlocale(LC_ALL, "C"); - /* Reset directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", - tmpdir); - exit(1); - } - /* Report per-test summaries. */ - tests[i].failures = failures - failures_before; - test_summarize(test_filename, tests[i].failures); - /* Close the per-test log file. */ - fclose(logfile); - logfile = NULL; - /* If there were no failures, we can remove the work dir and logfile. */ - if (tests[i].failures == 0) { - if (!keep_temp_files && assertChdir(tmpdir)) { -#if defined(_WIN32) && !defined(__CYGWIN__) - systemf("rmdir /S /Q %s", tests[i].name); - systemf("del %s", logfilename); -#else - systemf("rm -rf %s", tests[i].name); - systemf("rm %s", logfilename); -#endif - } - } - /* Return appropriate status. */ - return (tests[i].failures); -} - -/* - * - * - * MAIN and support routines. - * - * - */ - -static void -usage(const char *program) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i; - - printf("Usage: %s [options] ...\n", program); - printf("Default is to run all tests.\n"); - printf("Otherwise, specify the numbers of the tests you wish to run.\n"); - printf("Options:\n"); - printf(" -d Dump core after any failure, for debugging.\n"); - printf(" -k Keep all temp files.\n"); - printf(" Default: temp files for successful tests deleted.\n"); -#ifdef PROGRAM - printf(" -p Path to executable to be tested.\n"); - printf(" Default: path taken from " ENVBASE " environment variable.\n"); -#endif - printf(" -q Quiet.\n"); - printf(" -r Path to dir containing reference files.\n"); - printf(" Default: Current directory.\n"); - printf(" -v Verbose.\n"); - printf("Available tests:\n"); - for (i = 0; i < limit; i++) - printf(" %d: %s\n", i, tests[i].name); - exit(1); -} - -static char * -get_refdir(const char *d) -{ - char tried[512] = { '\0' }; - char buff[128]; - char *pwd, *p; - - /* If a dir was specified, try that */ - if (d != NULL) { - pwd = NULL; - snprintf(buff, sizeof(buff), "%s", d); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - goto failure; - } - - /* Get the current dir. */ - pwd = getcwd(NULL, 0); - while (pwd[strlen(pwd) - 1] == '\n') - pwd[strlen(pwd) - 1] = '\0'; - - /* Look for a known file. */ - snprintf(buff, sizeof(buff), "%s", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - -#if defined(LIBRARY) - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); -#else - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); -#endif - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - if (memcmp(pwd, "/usr/obj", 8) == 0) { - snprintf(buff, sizeof(buff), "%s", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - } - -failure: - printf("Unable to locate known reference file %s\n", KNOWNREF); - printf(" Checked following directories:\n%s\n", tried); -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - DebugBreak(); -#endif - exit(1); - -success: - free(p); - free(pwd); - return strdup(buff); -} - -int -main(int argc, char **argv) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i, tests_run = 0, tests_failed = 0, option; - time_t now; - char *refdir_alloc = NULL; - const char *progname; - const char *tmp, *option_arg, *p; - char tmpdir[256]; - char tmpdir_timestamp[256]; - - (void)argc; /* UNUSED */ - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) - /* To stop to run the default invalid parameter handler. */ - _set_invalid_parameter_handler(invalid_parameter_handler); - /* Disable annoying assertion message box. */ - _CrtSetReportMode(_CRT_ASSERT, 0); -#endif - - /* - * Name of this program, used to build root of our temp directory - * tree. - */ - progname = p = argv[0]; - while (*p != '\0') { - /* Support \ or / dir separators for Windows compat. */ - if (*p == '/' || *p == '\\') - progname = p + 1; - ++p; - } - -#ifdef PROGRAM - /* Get the target program from environment, if available. */ - testprogfile = getenv(ENVBASE); -#endif - - if (getenv("TMPDIR") != NULL) - tmp = getenv("TMPDIR"); - else if (getenv("TMP") != NULL) - tmp = getenv("TMP"); - else if (getenv("TEMP") != NULL) - tmp = getenv("TEMP"); - else if (getenv("TEMPDIR") != NULL) - tmp = getenv("TEMPDIR"); - else - tmp = "/tmp"; - - /* Allow -d to be controlled through the environment. */ - if (getenv(ENVBASE "_DEBUG") != NULL) - dump_on_failure = 1; - - /* Get the directory holding test files from environment. */ - refdir = getenv(ENVBASE "_TEST_FILES"); - - /* - * Parse options, without using getopt(), which isn't available - * on all platforms. - */ - ++argv; /* Skip program name */ - while (*argv != NULL) { - if (**argv != '-') - break; - p = *argv++; - ++p; /* Skip '-' */ - while (*p != '\0') { - option = *p++; - option_arg = NULL; - /* If 'opt' takes an argument, parse that. */ - if (option == 'p' || option == 'r') { - if (*p != '\0') - option_arg = p; - else if (*argv == NULL) { - fprintf(stderr, - "Option -%c requires argument.\n", - option); - usage(progname); - } else - option_arg = *argv++; - p = ""; /* End of this option word. */ - } - - /* Now, handle the option. */ - switch (option) { - case 'd': - dump_on_failure = 1; - break; - case 'k': - keep_temp_files = 1; - break; - case 'p': -#ifdef PROGRAM - testprogfile = option_arg; -#else - usage(progname); -#endif - break; - case 'q': - verbosity--; - break; - case 'r': - refdir = option_arg; - break; - case 'v': - verbosity++; - break; - default: - usage(progname); - } - } - } - - /* - * Sanity-check that our options make sense. - */ -#ifdef PROGRAM - if (testprogfile == NULL) - usage(progname); - { - char *testprg; -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Command.com sometimes rejects '/' separators. */ - testprg = strdup(testprogfile); - for (i = 0; testprg[i] != '\0'; i++) { - if (testprg[i] == '/') - testprg[i] = '\\'; - } - testprogfile = testprg; -#endif - /* Quote the name that gets put into shell command lines. */ - testprg = malloc(strlen(testprogfile) + 3); - strcpy(testprg, "\""); - strcat(testprg, testprogfile); - strcat(testprg, "\""); - testprog = testprg; - } -#endif - - /* - * Create a temp directory for the following tests. - * Include the time the tests started as part of the name, - * to make it easier to track the results of multiple tests. - */ - now = time(NULL); - for (i = 0; ; i++) { - strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), - "%Y-%m-%dT%H.%M.%S", - localtime(&now)); - sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, - tmpdir_timestamp, i); - if (assertMakeDir(tmpdir,0755)) - break; - if (i >= 999) { - fprintf(stderr, - "ERROR: Unable to create temp directory %s\n", - tmpdir); - exit(1); - } - } - - /* - * If the user didn't specify a directory for locating - * reference files, try to find the reference files in - * the "usual places." - */ - refdir = refdir_alloc = get_refdir(refdir); - - /* - * Banner with basic information. - */ - printf("\n"); - printf("If tests fail or crash, details will be in:\n"); - printf(" %s\n", tmpdir); - printf("\n"); - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("Reference files will be read from: %s\n", refdir); -#ifdef PROGRAM - printf("Running tests on: %s\n", testprog); -#endif - printf("Exercising: "); - fflush(stdout); - printf("%s\n", EXTRA_VERSION); - } else { - printf("Running "); - fflush(stdout); - } - - /* - * Run some or all of the individual tests. - */ - if (*argv == NULL) { - /* Default: Run all tests. */ - for (i = 0; i < limit; i++) { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - } - } else { - while (*(argv) != NULL) { - if (**argv >= '0' && **argv <= '9') { - i = atoi(*argv); - if (i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } else { - for (i = 0; i < limit; ++i) { - if (strcmp(*argv, tests[i].name) == 0) - break; - } - if (i >= limit) { - printf("*** INVALID Test ``%s''\n", - *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - argv++; - } - } - - /* - * Report summary statistics. - */ - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("\n"); - printf("Totals:\n"); - printf(" Tests run: %8d\n", tests_run); - printf(" Tests failed: %8d\n", tests_failed); - printf(" Assertions checked:%8d\n", assertions); - printf(" Assertions failed: %8d\n", failures); - printf(" Skips reported: %8d\n", skips); - } - if (failures) { - printf("\n"); - printf("Failing tests:\n"); - for (i = 0; i < limit; ++i) { - if (tests[i].failures) - printf(" %d: %s (%d failures)\n", i, - tests[i].name, tests[i].failures); - } - printf("\n"); - printf("Details for failing tests: %s\n", tmpdir); - printf("\n"); - } else { - if (verbosity == VERBOSITY_SUMMARY_ONLY) - printf("\n"); - printf("%d tests passed, no failures\n", tests_run); - } - - free(refdir_alloc); - - /* If the final tmpdir is empty, we can remove it. */ - /* This should be the usual case when all tests succeed. */ - assertChdir(".."); - rmdir(tmpdir); - - return (tests_failed ? 1 : 0); -} diff --git a/Utilities/cmlibarchive/cpio/test/test.h b/Utilities/cmlibarchive/cpio/test/test.h deleted file mode 100644 index 99010c89f..000000000 --- a/Utilities/cmlibarchive/cpio/test/test.h +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2003-2006 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/cpio/test/test.h,v 1.2 2008/06/21 02:17:18 kientzle Exp $ - */ - -/* Every test program should #include "test.h" as the first thing. */ - -/* - * The goal of this file (and the matching test.c) is to - * simplify the very repetitive test-*.c test programs. - */ -#if defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "config.h" -#elif defined(__FreeBSD__) -/* Building as part of FreeBSD system requires a pre-built config.h. */ -#include "config_freebsd.h" -#elif defined(_WIN32) && !defined(__CYGWIN__) -/* Win32 can't run the 'configure' script. */ -#include "config_windows.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in test.h. -#endif - -#include /* Windows requires this before sys/stat.h */ -#include - -#ifdef USE_DMALLOC -#include -#endif -#if HAVE_DIRENT_H -#include -#else -#include -#define dirent direct -#endif -#include -#include -#ifdef HAVE_IO_H -#include -#endif -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_WINDOWS_H -#include -#endif - -/* - * System-specific tweaks. We really want to minimize these - * as much as possible, since they make it harder to understand - * the mainline code. - */ - -/* Windows (including Visual Studio and MinGW but not Cygwin) */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#include "../cpio_windows.h" -#define strdup _strdup -#define LOCALE_DE "deu" -#else -#define LOCALE_DE "de_DE.UTF-8" -#endif - -/* Visual Studio */ -#ifdef _MSC_VER -#define snprintf sprintf_s -#endif - -/* Cygwin */ -#if defined(__CYGWIN__) -/* Cygwin-1.7.x is lazy about populating nlinks, so don't - * expect it to be accurate. */ -# define NLINKS_INACCURATE_FOR_DIRS -#endif - -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Redefine DEFINE_TEST for use in defining the test functions. - */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); void name(void) - -/* An implementation of the standard assert() macro */ -#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) -/* chdir() and error if it fails */ -#define assertChdir(path) \ - assertion_chdir(__FILE__, __LINE__, path) -/* Assert two integers are the same. Reports value of each one if not. */ -#define assertEqualInt(v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* Assert two strings are the same. Reports value of each one if not. */ -#define assertEqualString(v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but v1 and v2 are wchar_t * */ -#define assertEqualWString(v1,v2) \ - assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but raw blocks of bytes. */ -#define assertEqualMem(v1, v2, l) \ - assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) -/* Assert two files are the same; allow printf-style expansion of second name. - * See below for comments about variable arguments here... - */ -#define assertEqualFile \ - assertion_setup(__FILE__, __LINE__);assertion_equal_file -/* Assert that a file is empty; supports printf-style arguments. */ -#define assertEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_empty_file -/* Assert that a file is not empty; supports printf-style arguments. */ -#define assertNonEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_non_empty_file -#define assertFileAtime(pathname, sec, nsec) \ - assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileAtimeRecent(pathname) \ - assertion_file_atime_recent(__FILE__, __LINE__, pathname) -#define assertFileBirthtime(pathname, sec, nsec) \ - assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileBirthtimeRecent(pathname) \ - assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_exists -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileNotExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_not_exists -/* Assert that file contents match a string; supports printf-style arguments. */ -#define assertFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_file_contents -#define assertFileMtime(pathname, sec, nsec) \ - assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileMtimeRecent(pathname) \ - assertion_file_mtime_recent(__FILE__, __LINE__, pathname) -#define assertFileNLinks(pathname, nlinks) \ - assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) -#define assertFileSize(pathname, size) \ - assertion_file_size(__FILE__, __LINE__, pathname, size) -#define assertTextFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_text_file_contents -#define assertIsDir(pathname, mode) \ - assertion_is_dir(__FILE__, __LINE__, pathname, mode) -#define assertIsHardlink(path1, path2) \ - assertion_is_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsNotHardlink(path1, path2) \ - assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsReg(pathname, mode) \ - assertion_is_reg(__FILE__, __LINE__, pathname, mode) -#define assertIsSymlink(pathname, contents) \ - assertion_is_symlink(__FILE__, __LINE__, pathname, contents) -/* Create a directory, report error if it fails. */ -#define assertMakeDir(dirname, mode) \ - assertion_make_dir(__FILE__, __LINE__, dirname, mode) -#define assertMakeFile(path, mode, contents) \ - assertion_make_file(__FILE__, __LINE__, path, mode, contents) -#define assertMakeHardlink(newfile, oldfile) \ - assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) -#define assertMakeSymlink(newfile, linkto) \ - assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) -#define assertUmask(mask) \ - assertion_umask(__FILE__, __LINE__, mask) - -/* - * This would be simple with C99 variadic macros, but I don't want to - * require that. Instead, I insert a function call before each - * skipping() call to pass the file and line information down. Crude, - * but effective. - */ -#define skipping \ - assertion_setup(__FILE__, __LINE__);test_skipping - -/* Function declarations. These are defined in test_utility.c. */ -void failure(const char *fmt, ...); -int assertion_assert(const char *, int, int, const char *, void *); -int assertion_chdir(const char *, int, const char *); -int assertion_empty_file(const char *, ...); -int assertion_equal_file(const char *, const char *, ...); -int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); -int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); -int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); -int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); -int assertion_file_atime(const char *, int, const char *, long, long); -int assertion_file_atime_recent(const char *, int, const char *); -int assertion_file_birthtime(const char *, int, const char *, long, long); -int assertion_file_birthtime_recent(const char *, int, const char *); -int assertion_file_contents(const void *, int, const char *, ...); -int assertion_file_exists(const char *, ...); -int assertion_file_mtime(const char *, int, const char *, long, long); -int assertion_file_mtime_recent(const char *, int, const char *); -int assertion_file_nlinks(const char *, int, const char *, int); -int assertion_file_not_exists(const char *, ...); -int assertion_file_size(const char *, int, const char *, long); -int assertion_is_dir(const char *, int, const char *, int); -int assertion_is_hardlink(const char *, int, const char *, const char *); -int assertion_is_not_hardlink(const char *, int, const char *, const char *); -int assertion_is_reg(const char *, int, const char *, int); -int assertion_is_symlink(const char *, int, const char *, const char *); -int assertion_make_dir(const char *, int, const char *, int); -int assertion_make_file(const char *, int, const char *, int, const char *); -int assertion_make_hardlink(const char *, int, const char *newpath, const char *); -int assertion_make_symlink(const char *, int, const char *newpath, const char *); -int assertion_non_empty_file(const char *, ...); -int assertion_text_file_contents(const char *buff, const char *f); -int assertion_umask(const char *, int, int); -void assertion_setup(const char *, int); - -void test_skipping(const char *fmt, ...); - -/* Like sprintf, then system() */ -int systemf(const char * fmt, ...); - -/* Delay until time() returns a value after this. */ -void sleepUntilAfter(time_t); - -/* Return true if this platform can create symlinks. */ -int canSymlink(void); - -/* Return true if this platform can run the "gzip" program. */ -int canGzip(void); - -/* Return true if this platform can run the "gunzip" program. */ -int canGunzip(void); - -/* Suck file into string allocated via malloc(). Call free() when done. */ -/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ -char *slurpfile(size_t *, const char *fmt, ...); - -/* Extracts named reference file to the current directory. */ -void extract_reference_file(const char *); - -/* - * Special interfaces for program test harness. - */ - -/* Pathname of exe to be tested. */ -const char *testprogfile; -/* Name of exe to use in printf-formatted command strings. */ -/* On Windows, this includes leading/trailing quotes. */ -const char *testprog; diff --git a/Utilities/cmlibarchive/cpio/test/test_0.c b/Utilities/cmlibarchive/cpio/test/test_0.c deleted file mode 100644 index e5d3bd23f..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_0.c +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * This first test does basic sanity checks on the environment. For - * most of these, we just exit on failure. - */ -#if !defined(_WIN32) || defined(__CYGWIN__) -#define DEV_NULL "/dev/null" -#else -#define DEV_NULL "NUL" -#endif - -DEFINE_TEST(test_0) -{ - struct stat st; - - failure("File %s does not exist?!", testprogfile); - if (!assertEqualInt(0, stat(testprogfile, &st))) - exit(1); - - failure("%s is not executable?!", testprogfile); - if (!assert((st.st_mode & 0111) != 0)) - exit(1); - - /* - * Try to succesfully run the program; this requires that - * we know some option that will succeed. - */ - if (0 == systemf("%s --version >" DEV_NULL, testprog)) { - /* This worked. */ - } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { - /* This worked. */ - } else { - failure("Unable to successfully run any of the following:\n" - " * %s --version\n" - " * %s -W version\n", - testprog, testprog); - assert(0); - } - - /* TODO: Ensure that our reference files are available. */ -} diff --git a/Utilities/cmlibarchive/cpio/test/test_basic.c b/Utilities/cmlibarchive/cpio/test/test_basic.c deleted file mode 100644 index a2c0b70fa..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_basic.c +++ /dev/null @@ -1,173 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_basic.c,v 1.4 2008/08/25 06:39:29 kientzle Exp $"); - -static void -verify_files(const char *msg) -{ - /* - * Verify unpacked files. - */ - - /* Regular file with 2 links. */ - assertIsReg("file", 0644); - failure(msg); - assertFileSize("file", 10); - assertFileNLinks("file", 2); - - /* Another name for the same file. */ - assertIsHardlink("linkfile", "file"); - - /* Symlink */ - if (canSymlink()) - assertIsSymlink("symlink", "file"); - - /* Another file with 1 link and different permissions. */ - assertIsReg("file2", 0777); - assertFileSize("file2", 10); - assertFileNLinks("file2", 1); - - /* dir */ - assertIsDir("dir", 0775); -} - -static void -basic_cpio(const char *target, - const char *pack_options, - const char *unpack_options, - const char *se) -{ - int r; - - if (!assertMakeDir(target, 0775)) - return; - - /* Use the cpio program to create an archive. */ - r = systemf("%s -o %s < filelist >%s/archive 2>%s/pack.err", - testprog, pack_options, target, target); - failure("Error invoking %s -o %s", testprog, pack_options); - assertEqualInt(r, 0); - - assertChdir(target); - - /* Verify stderr. */ - failure("Expected: %s, options=%s", se, pack_options); - assertTextFileContents(se, "pack.err"); - - /* - * Use cpio to unpack the archive into another directory. - */ - r = systemf("%s -i %s< archive >unpack.out 2>unpack.err", - testprog, unpack_options); - failure("Error invoking %s -i %s", testprog, unpack_options); - assertEqualInt(r, 0); - - /* Verify stderr. */ - failure("Error invoking %s -i %s in dir %s", testprog, unpack_options, target); - assertTextFileContents(se, "unpack.err"); - - verify_files(pack_options); - - assertChdir(".."); -} - -static void -passthrough(const char *target) -{ - int r; - - if (!assertMakeDir(target, 0775)) - return; - - /* - * Use cpio passthrough mode to copy files to another directory. - */ - r = systemf("%s -p %s %s/stdout 2>%s/stderr", - testprog, target, target, target); - failure("Error invoking %s -p", testprog); - assertEqualInt(r, 0); - - assertChdir(target); - - /* Verify stderr. */ - failure("Error invoking %s -p in dir %s", - testprog, target); - assertTextFileContents("1 block\n", "stderr"); - - verify_files("passthrough"); - assertChdir(".."); -} - -DEFINE_TEST(test_basic) -{ - FILE *filelist; - const char *msg; - - assertUmask(0); - - /* - * Create an assortment of files on disk. - */ - filelist = fopen("filelist", "w"); - - /* File with 10 bytes content. */ - assertMakeFile("file", 0644, "1234567890"); - fprintf(filelist, "file\n"); - - /* hardlink to above file. */ - assertMakeHardlink("linkfile", "file"); - fprintf(filelist, "linkfile\n"); - - /* Symlink to above file. */ - if (canSymlink()) { - assertMakeSymlink("symlink", "file"); - fprintf(filelist, "symlink\n"); - } - - /* Another file with different permissions. */ - assertMakeFile("file2", 0777, "1234567890"); - fprintf(filelist, "file2\n"); - - /* Directory. */ - assertMakeDir("dir", 0775); - fprintf(filelist, "dir\n"); - /* All done. */ - fclose(filelist); - - assertUmask(022); - - /* Archive/dearchive with a variety of options. */ - msg = canSymlink() ? "2 blocks\n" : "1 block\n"; - basic_cpio("copy", "", "", msg); - basic_cpio("copy_odc", "--format=odc", "", msg); - basic_cpio("copy_newc", "-H newc", "", "2 blocks\n"); - basic_cpio("copy_cpio", "-H odc", "", msg); - msg = canSymlink() ? "9 blocks\n" : "8 blocks\n"; - basic_cpio("copy_ustar", "-H ustar", "", msg); - - /* Copy in one step using -p */ - passthrough("passthrough"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_cmdline.c b/Utilities/cmlibarchive/cpio/test/test_cmdline.c deleted file mode 100644 index c8cd84e1e..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_cmdline.c +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Test the command-line parsing. - */ - -DEFINE_TEST(test_cmdline) -{ - FILE *f; - - /* Create an empty file. */ - f = fopen("empty", "wb"); - assert(f != NULL); - fclose(f); - - failure("-Q is an invalid option on every cpio program I know of"); - assert(0 != systemf("%s -i -Q 1.out 2>1.err", testprog)); - assertEmptyFile("1.out"); - - failure("-f requires an argument"); - assert(0 != systemf("%s -if 2.out 2>2.err", testprog)); - assertEmptyFile("2.out"); - - failure("-f requires an argument"); - assert(0 != systemf("%s -i -f 3.out 2>3.err", testprog)); - assertEmptyFile("3.out"); - - failure("--format requires an argument"); - assert(0 != systemf("%s -i --format 4.out 2>4.err", testprog)); - assertEmptyFile("4.out"); - - failure("--badopt is an invalid option"); - assert(0 != systemf("%s -i --badop 5.out 2>5.err", testprog)); - assertEmptyFile("5.out"); - - failure("--badopt is an invalid option"); - assert(0 != systemf("%s -i --badopt 6.out 2>6.err", testprog)); - assertEmptyFile("6.out"); - - failure("--n is ambiguous"); - assert(0 != systemf("%s -i --n 7.out 2>7.err", testprog)); - assertEmptyFile("7.out"); - - failure("--create forbids an argument"); - assert(0 != systemf("%s --create=arg 8.out 2>8.err", testprog)); - assertEmptyFile("8.out"); - - failure("-i with empty input should succeed"); - assert(0 == systemf("%s -i 9.out 2>9.err", testprog)); - assertEmptyFile("9.out"); - - failure("-o with empty input should succeed"); - assert(0 == systemf("%s -o 10.out 2>10.err", testprog)); - - failure("-i -p is nonsense"); - assert(0 != systemf("%s -i -p 11.out 2>11.err", testprog)); - assertEmptyFile("11.out"); - - failure("-p -i is nonsense"); - assert(0 != systemf("%s -p -i 12.out 2>12.err", testprog)); - assertEmptyFile("12.out"); - - failure("-i -o is nonsense"); - assert(0 != systemf("%s -i -o 13.out 2>13.err", testprog)); - assertEmptyFile("13.out"); - - failure("-o -i is nonsense"); - assert(0 != systemf("%s -o -i 14.out 2>14.err", testprog)); - assertEmptyFile("14.out"); - - failure("-o -p is nonsense"); - assert(0 != systemf("%s -o -p 15.out 2>15.err", testprog)); - assertEmptyFile("15.out"); - - failure("-p -o is nonsense"); - assert(0 != systemf("%s -p -o 16.out 2>16.err", testprog)); - assertEmptyFile("16.out"); - - failure("-p with empty input should fail"); - assert(0 != systemf("%s -p 17.out 2>17.err", testprog)); - assertEmptyFile("17.out"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_format_newc.c b/Utilities/cmlibarchive/cpio/test/test_format_newc.c deleted file mode 100644 index 133f753b8..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_format_newc.c +++ /dev/null @@ -1,294 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_format_newc.c,v 1.2 2008/08/22 02:09:10 kientzle Exp $"); - -/* Number of bytes needed to pad 'n' to multiple of 'block', assuming - * that 'block' is a power of two. This trick can be more easily - * remembered as -n & (block - 1), but many compilers quite reasonably - * warn about "-n" when n is an unsigned value. (~(n) + 1) is the - * same thing, but written in a way that won't offend anyone. */ -#define PAD(n, block) ((~(n) + 1) & ((block) - 1)) - -static int -is_hex(const char *p, size_t l) -{ - while (l > 0) { - if ((*p >= '0' && *p <= '9') - || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F')) - { - --l; - ++p; - } else - return (0); - - } - return (1); -} - -static int -from_hex(const char *p, size_t l) -{ - int r = 0; - - while (l > 0) { - r *= 16; - if (*p >= 'a' && *p <= 'f') - r += *p + 10 - 'a'; - else if (*p >= 'A' && *p <= 'F') - r += *p + 10 - 'A'; - else - r += *p - '0'; - --l; - ++p; - } - return (r); -} - -DEFINE_TEST(test_format_newc) -{ - FILE *list; - int r; - int devmajor, devminor, ino, gid; - int uid = -1; - time_t t, t2, now; - char *p, *e; - size_t s, fs, ns; - - assertUmask(0); - -#if !defined(_WIN32) - uid = getuid(); -#endif - - /* - * Create an assortment of files. - * TODO: Extend this to cover more filetypes. - */ - list = fopen("list", "w"); - - /* "file1" */ - assertMakeFile("file1", 0644, "1234567890"); - fprintf(list, "file1\n"); - - /* "hardlink" */ - assertMakeHardlink("hardlink", "file1"); - fprintf(list, "hardlink\n"); - - /* Another hardlink, but this one won't be archived. */ - assertMakeHardlink("hardlink2", "file1"); - - /* "symlink" */ - if (canSymlink()) { - assertMakeSymlink("symlink", "file1"); - fprintf(list, "symlink\n"); - } - - /* "dir" */ - assertMakeDir("dir", 0775); - fprintf(list, "dir\n"); - - /* Record some facts about what we just created: */ - now = time(NULL); /* They were all created w/in last two seconds. */ - - /* Use the cpio program to create an archive. */ - fclose(list); - r = systemf("%s -o --format=newc newc.out 2>newc.err", - testprog); - if (!assertEqualInt(r, 0)) - return; - - /* Verify that nothing went to stderr. */ - if (canSymlink()) { - assertTextFileContents("2 blocks\n", "newc.err"); - } else { - assertTextFileContents("1 block\n", "newc.err"); - } - - /* Verify that stdout is a well-formed cpio file in "newc" format. */ - p = slurpfile(&s, "newc.out"); - assertEqualInt(s, canSymlink() ? 1024 : 512); - e = p; - - /* - * Some of these assertions could be stronger, but it's - * a little tricky because they depend on the local environment. - */ - - /* First entry is "file1" */ - assert(is_hex(e, 110)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070701", 6); /* Magic */ - ino = from_hex(e + 6, 8); /* ino */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Group members bits and others bits do not work. */ - assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */ -#else - assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */ -#endif - if (uid < 0) - uid = from_hex(e + 22, 8); - assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ - gid = from_hex(e + 30, 8); /* gid */ - assertEqualMem(e + 38, "00000003", 8); /* nlink */ - t = from_hex(e + 46, 8); /* mtime */ - failure("t=0x%08x now=0x%08x=%d", t, now, now); - assert(t <= now); /* File wasn't created in future. */ - failure("t=0x%08x now - 2=0x%08x = %d", t, now - 2, now - 2); - assert(t >= now - 2); /* File was created w/in last 2 secs. */ - failure("newc format stores body only with last appearance of a link\n" - " first appearance should be empty, so this file size\n" - " field should be zero"); - assertEqualInt(0, from_hex(e + 54, 8)); /* File size */ - fs = from_hex(e + 54, 8); - fs += PAD(fs, 4); - devmajor = from_hex(e + 62, 8); /* devmajor */ - devminor = from_hex(e + 70, 8); /* devminor */ - assert(is_hex(e + 78, 8)); /* rdevmajor */ - assert(is_hex(e + 86, 8)); /* rdevminor */ - assertEqualMem(e + 94, "00000006", 8); /* Name size */ - ns = from_hex(e + 94, 8); - ns += PAD(ns + 2, 4); - assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ - assertEqualMem(e + 110, "file1\0", 6); /* Name contents */ - /* Since there's another link, no file contents here. */ - /* But add in file size so that an error here doesn't cascade. */ - e += 110 + fs + ns; - - if (canSymlink()) { - /* "symlink" pointing to "file1" */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assert(is_hex(e + 6, 8)); /* ino */ - assertEqualInt(0xa1ff, from_hex(e + 14, 8)); /* Mode */ - assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ - assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); - assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ - assertEqualMem(e + 54, "00000005", 8); /* File size */ - fs = from_hex(e + 54, 8); - fs += PAD(fs, 4); - assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ - assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ - assert(is_hex(e + 78, 8)); /* rdevmajor */ - assert(is_hex(e + 86, 8)); /* rdevminor */ - assertEqualMem(e + 94, "00000008", 8); /* Name size */ - ns = from_hex(e + 94, 8); - ns += PAD(ns + 2, 4); - assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ - assertEqualMem(e + 110, "symlink\0\0\0", 10); /* Name contents */ - assertEqualMem(e + 110 + ns, "file1\0\0\0", 8); /* symlink target */ - e += 110 + fs + ns; - } - - /* "dir" */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assert(is_hex(e + 6, 8)); /* ino */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Group members bits and others bits do not work. */ - assertEqualInt(0x41c0, from_hex(e + 14, 8) & 0xffc0); /* Mode */ -#else - /* Mode: sgid bit sometimes propagates from parent dirs, ignore it. */ - assertEqualInt(040775, from_hex(e + 14, 8) & ~02000); -#endif - assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ - assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ -#ifndef NLINKS_INACCURATE_FOR_DIRS - assertEqualMem(e + 38, "00000002", 8); /* nlink */ -#endif - t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); - assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ - assertEqualMem(e + 54, "00000000", 8); /* File size */ - fs = from_hex(e + 54, 8); - fs += PAD(fs, 4); - assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ - assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ - assert(is_hex(e + 78, 8)); /* rdevmajor */ - assert(is_hex(e + 86, 8)); /* rdevminor */ - assertEqualMem(e + 94, "00000004", 8); /* Name size */ - ns = from_hex(e + 94, 8); - ns += PAD(ns + 2, 4); - assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ - assertEqualMem(e + 110, "dir\0\0\0", 6); /* Name contents */ - e += 110 + fs + ns; - - /* Hardlink identical to "file1" */ - /* Since we only wrote two of the three links to this - * file, this link should get deferred by the hardlink logic. */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - failure("If these aren't the same, then the hardlink detection failed to match them."); - assertEqualInt(ino, from_hex(e + 6, 8)); /* ino */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Group members bits and others bits do not work. */ - assertEqualInt(0x8180, from_hex(e + 14, 8) & 0xffc0); /* Mode */ -#else - assertEqualInt(0x81a4, from_hex(e + 14, 8)); /* Mode */ -#endif - assertEqualInt(from_hex(e + 22, 8), uid); /* uid */ - assertEqualInt(gid, from_hex(e + 30, 8)); /* gid */ - assertEqualMem(e + 38, "00000003", 8); /* nlink */ - t2 = from_hex(e + 46, 8); /* mtime */ - failure("First entry created at t=0x%08x this entry created at t2=0x%08x", t, t2); - assert(t2 == t || t2 == t + 1); /* Almost same as first entry. */ - assertEqualInt(10, from_hex(e + 54, 8)); /* File size */ - fs = from_hex(e + 54, 8); - fs += PAD(fs, 4); - assertEqualInt(devmajor, from_hex(e + 62, 8)); /* devmajor */ - assertEqualInt(devminor, from_hex(e + 70, 8)); /* devminor */ - assert(is_hex(e + 78, 8)); /* rdevmajor */ - assert(is_hex(e + 86, 8)); /* rdevminor */ - assertEqualMem(e + 94, "00000009", 8); /* Name size */ - ns = from_hex(e + 94, 8); - ns += PAD(ns + 2, 4); - assertEqualInt(0, from_hex(e + 102, 8)); /* check field */ - assertEqualMem(e + 110, "hardlink\0\0", 10); /* Name contents */ - assertEqualMem(e + 110 + ns, "1234567890\0\0", 12); /* File contents */ - e += 110 + ns + fs; - - /* Last entry is end-of-archive marker. */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 8, "00000000", 8); /* ino */ - assertEqualMem(e + 14, "00000000", 8); /* mode */ - assertEqualMem(e + 22, "00000000", 8); /* uid */ - assertEqualMem(e + 30, "00000000", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000000", 8); /* mtime */ - assertEqualMem(e + 54, "00000000", 8); /* size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "00000000", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualInt(11, from_hex(e + 94, 8)); /* name size */ - assertEqualMem(e + 102, "00000000", 8); /* check field */ - assertEqualMem(e + 110, "TRAILER!!!\0\0", 12); /* Name */ - - free(p); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_gcpio_compat.c b/Utilities/cmlibarchive/cpio/test/test_gcpio_compat.c deleted file mode 100644 index 2d49523f9..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_gcpio_compat.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_gcpio_compat.c,v 1.2 2008/08/22 02:27:06 kientzle Exp $"); - -static void -unpack_test(const char *from, const char *options, const char *se) -{ - int r; - - /* Create a work dir named after the file we're unpacking. */ - assertMakeDir(from, 0775); - assertChdir(from); - - /* - * Use cpio to unpack the sample archive - */ - extract_reference_file(from); - r = systemf("%s -i %s < %s >unpack.out 2>unpack.err", - testprog, options, from); - failure("Error invoking %s -i %s < %s", - testprog, options, from); - assertEqualInt(r, 0); - - /* Verify that nothing went to stderr. */ - if (canSymlink()) { - failure("Error invoking %s -i %s < %s", - testprog, options, from); - assertTextFileContents(se, "unpack.err"); - } - - /* - * Verify unpacked files. - */ - - /* Regular file with 2 links. */ - assertIsReg("file", 0644); - failure("%s", from); - assertFileSize("file", 10); - assertFileSize("linkfile", 10); - failure("%s", from); - assertFileNLinks("file", 2); - - /* Another name for the same file. */ - failure("%s", from); - assertIsHardlink("linkfile", "file"); - assertFileSize("file", 10); - assertFileSize("linkfile", 10); - - /* Symlink */ - if (canSymlink()) - assertIsSymlink("symlink", "file"); - - /* dir */ - assertIsDir("dir", 0775); - - assertChdir(".."); -} - -DEFINE_TEST(test_gcpio_compat) -{ - assertUmask(0); - - /* Dearchive sample files with a variety of options. */ - if (canSymlink()) { - unpack_test("test_gcpio_compat_ref.bin", - "--no-preserve-owner", "1 block\n"); - unpack_test("test_gcpio_compat_ref.crc", - "--no-preserve-owner", "2 blocks\n"); - unpack_test("test_gcpio_compat_ref.newc", - "--no-preserve-owner", "2 blocks\n"); - /* gcpio-2.9 only reads 6 blocks here */ - unpack_test("test_gcpio_compat_ref.ustar", - "--no-preserve-owner", "7 blocks\n"); - } else { - unpack_test("test_gcpio_compat_ref_nosym.bin", - "--no-preserve-owner", "1 block\n"); - unpack_test("test_gcpio_compat_ref_nosym.crc", - "--no-preserve-owner", "2 blocks\n"); - unpack_test("test_gcpio_compat_ref_nosym.newc", - "--no-preserve-owner", "2 blocks\n"); - /* gcpio-2.9 only reads 6 blocks here */ - unpack_test("test_gcpio_compat_ref_nosym.ustar", - "--no-preserve-owner", "7 blocks\n"); - } -} diff --git a/Utilities/cmlibarchive/cpio/test/test_gcpio_compat_ref.bin.uu b/Utilities/cmlibarchive/cpio/test/test_gcpio_compat_ref.bin.uu deleted file mode 100644 index 745d8ab78..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_gcpio_compat_ref.bin.uu +++ /dev/null @@ -1,16 +0,0 @@ -$FreeBSD$ -begin 644 test_gcpio_compat_ref.bin -MQW%9`*IWI('H`^@#`@````U'=YD%````"@!F:6QE```Q,C,T-38W.#D*QW%9 -M`*IWI('H`^@#`@````U'=YD)````"@!L:6YK9FEL90``,3(S-#4V-S@Y"L=Q -M60"K=^VAZ`/H`P$````-1X29"`````0` small.cpio 2>small.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "small.err"); - assertEqualInt(0, stat("small.cpio", &st)); - assertEqualInt(512, st.st_size); - - /* Create an archive with -B; this should be 5120 bytes. */ - r = systemf("echo file | %s -oB > large.cpio 2>large.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "large.err"); - assertEqualInt(0, stat("large.cpio", &st)); - assertEqualInt(5120, st.st_size); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_J_upper.c b/Utilities/cmlibarchive/cpio/test/test_option_J_upper.c deleted file mode 100644 index 554f64a8c..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_J_upper.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_option_J_upper) -{ - char *p; - int r; - size_t s; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Archive it with xz compression. */ - r = systemf("echo f | %s -o -J >archive.out 2>archive.err", - testprog); - p = slurpfile(&s, "archive.err"); - p[s] = '\0'; - if (r != 0) { - if (strstr(p, "compression not available") != NULL) { - skipping("This version of bsdcpio was compiled " - "without xz support"); - return; - } - failure("-J option is broken"); - assertEqualInt(r, 0); - return; - } - /* Check that the archive file has an xz signature. */ - p = slurpfile(&s, "archive.out"); - assert(s > 2); - assertEqualMem(p, "\3757zXZ", 5); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_L_upper.c b/Utilities/cmlibarchive/cpio/test/test_option_L_upper.c deleted file mode 100644 index 396752f79..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_L_upper.c +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); - -/* This is a little pointless, as Windows doesn't support symlinks - * (except for the seriously crippled CreateSymbolicLink API) so these - * tests won't run on Windows. */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#define CAT "type" -#else -#define CAT "cat" -#endif - -DEFINE_TEST(test_option_L_upper) -{ - FILE *filelist; - int r; - - if (!canSymlink()) { - skipping("Symlink tests"); - return; - } - - filelist = fopen("filelist", "w"); - - /* Create a file and a symlink to the file. */ - assertMakeFile("file", 0644, "1234567890"); - fprintf(filelist, "file\n"); - - /* Symlink to above file. */ - assertMakeSymlink("symlink", "file"); - fprintf(filelist, "symlink\n"); - - fclose(filelist); - - r = systemf(CAT " filelist | %s -pd copy >copy.out 2>copy.err", testprog); - assertEqualInt(r, 0); - - failure("Regular -p without -L should preserve symlinks."); - assertIsSymlink("copy/symlink", NULL); - - r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("copy-L.out"); - assertTextFileContents("1 block\n", "copy-L.err"); - failure("-pdL should dereference symlinks and turn them into files."); - assertIsReg("copy-L/symlink", -1); - - r = systemf(CAT " filelist | %s -o >archive.out 2>archive.err", testprog); - failure("Error invoking %s -o ", testprog); - assertEqualInt(r, 0); - - assertMakeDir("unpack", 0755); - assertChdir("unpack"); - r = systemf(CAT " ../archive.out | %s -i >unpack.out 2>unpack.err", testprog); - assertChdir(".."); - failure("Error invoking %s -i", testprog); - assertEqualInt(r, 0); - - assertIsSymlink("unpack/symlink", NULL); - - r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog); - failure("Error invoking %s -oL", testprog); - assertEqualInt(r, 0); - - assertMakeDir("unpack-L", 0755); - assertChdir("unpack-L"); - r = systemf(CAT " ../archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); - assertChdir(".."); - failure("Error invoking %s -i < archive-L.out", testprog); - assertEqualInt(r, 0); - assertIsReg("unpack-L/symlink", -1); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_Z_upper.c b/Utilities/cmlibarchive/cpio/test/test_option_Z_upper.c deleted file mode 100644 index 6810ec631..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_Z_upper.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_option_Z_upper) -{ - char *p; - int r; - size_t s; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Archive it with compress compression. */ - r = systemf("echo f | %s -oZ >archive.out 2>archive.err", - testprog); - p = slurpfile(&s, "archive.err"); - p[s] = '\0'; - if (r != 0) { - if (strstr(p, "compression not available") != NULL) { - skipping("This version of bsdcpio was compiled " - "without compress support"); - return; - } - failure("-Z option is broken"); - assertEqualInt(r, 0); - return; - } - /* Check that the archive file has a compress signature. */ - p = slurpfile(&s, "archive.out"); - assert(s > 2); - assertEqualMem(p, "\x1f\x9d", 2); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_a.c b/Utilities/cmlibarchive/cpio/test/test_option_a.c deleted file mode 100644 index c39e553c2..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_a.c +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -#if defined(_WIN32) && !defined(__CYGWIN__) -#include -#else -#include -#endif -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_a.c,v 1.3 2008/08/24 06:21:00 kientzle Exp $"); - -static struct { - const char *name; - time_t atime_sec; -} files[] = { - { "f0", 0 }, - { "f1", 0 }, - { "f2", 0 }, - { "f3", 0 }, - { "f4", 0 }, - { "f5", 0 } -}; - -/* - * Create a bunch of test files and record their atimes. - * For the atime preserve/change tests, the files must have - * atimes in the past. We can accomplish this by explicitly invoking - * utime() on platforms that support it or by simply sleeping - * for a second after creating the files. (Creating all of the files - * at once means we only need to sleep once.) - */ -static void -test_create(void) -{ - struct stat st; - struct utimbuf times; - static const int numfiles = sizeof(files) / sizeof(files[0]); - int i; - - for (i = 0; i < numfiles; ++i) { - /* - * Note: Have to write at least one byte to the file. - * cpio doesn't bother reading the file if it's zero length, - * so the atime never gets changed in that case, which - * makes the tests below rather pointless. - */ - assertMakeFile(files[i].name, 0644, "a"); - - /* If utime() isn't supported on your platform, just - * #ifdef this section out. Most of the test below is - * still valid. */ - memset(×, 0, sizeof(times)); - times.actime = 1; - times.modtime = 3; - assertEqualInt(0, utime(files[i].name, ×)); - - /* Record whatever atime the file ended up with. */ - /* If utime() is available, this should be 1, but there's - * no harm in being careful. */ - assertEqualInt(0, stat(files[i].name, &st)); - files[i].atime_sec = st.st_atime; - } - - /* Wait until the atime on the last file is actually in the past. */ - sleepUntilAfter(files[numfiles - 1].atime_sec); -} - -DEFINE_TEST(test_option_a) -{ - struct stat st; - int r; - char *p; - - /* Create all of the test files. */ - test_create(); - - /* Sanity check; verify that atimes really do get modified. */ - assert((p = slurpfile(NULL, "f0")) != NULL); - free(p); - assertEqualInt(0, stat("f0", &st)); - if (st.st_atime == files[0].atime_sec) { - skipping("Cannot verify -a option\n" - " Your system appears to not support atime."); - } - else - { - /* - * If this disk is mounted noatime, then we can't - * verify correct operation without -a. - */ - - /* Copy the file without -a; should change the atime. */ - r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "copy-no-a.err"); - assertEmptyFile("copy-no-a.out"); - assertEqualInt(0, stat(files[1].name, &st)); - failure("Copying file without -a should have changed atime."); - assert(st.st_atime != files[1].atime_sec); - - /* Archive the file without -a; should change the atime. */ - r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "copy-no-a.err"); - assertEqualInt(0, stat(files[2].name, &st)); - failure("Archiving file without -a should have changed atime."); - assert(st.st_atime != files[2].atime_sec); - } - - /* - * We can, of course, still verify that the atime is unchanged - * when using the -a option. - */ - - /* Copy the file with -a; should not change the atime. */ - r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err", - files[3].name, testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "copy-a.err"); - assertEmptyFile("copy-a.out"); - assertEqualInt(0, stat(files[3].name, &st)); - failure("Copying file with -a should not have changed atime."); - assertEqualInt(st.st_atime, files[3].atime_sec); - - /* Archive the file with -a; should not change the atime. */ - r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err", - files[4].name, testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "copy-a.err"); - assertEqualInt(0, stat(files[4].name, &st)); - failure("Archiving file with -a should not have changed atime."); - assertEqualInt(st.st_atime, files[4].atime_sec); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_c.c b/Utilities/cmlibarchive/cpio/test/test_option_c.c deleted file mode 100644 index a28a2ff83..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_c.c +++ /dev/null @@ -1,221 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -static int -is_octal(const char *p, size_t l) -{ - while (l > 0) { - if (*p < '0' || *p > '7') - return (0); - --l; - ++p; - } - return (1); -} - -static int -from_octal(const char *p, size_t l) -{ - int r = 0; - - while (l > 0) { - r *= 8; - r += *p - '0'; - --l; - ++p; - } - return (r); -} - -DEFINE_TEST(test_option_c) -{ - FILE *filelist; - int r; - int uid = -1; - int dev, ino, gid; - time_t t, now; - char *p, *e; - size_t s; - - assertUmask(0); - -#if !defined(_WIN32) - uid = getuid(); -#endif - - /* - * Create an assortment of files. - * TODO: Extend this to cover more filetypes. - */ - filelist = fopen("filelist", "w"); - - /* "file" */ - assertMakeFile("file", 0644, "1234567890"); - fprintf(filelist, "file\n"); - - /* "symlink" */ - if (canSymlink()) { - assertMakeSymlink("symlink", "file"); - fprintf(filelist, "symlink\n"); - } - - /* "dir" */ - assertMakeDir("dir", 0775); - /* Record some facts about what we just created: */ - now = time(NULL); /* They were all created w/in last two seconds. */ - fprintf(filelist, "dir\n"); - - /* Use the cpio program to create an archive. */ - fclose(filelist); - r = systemf("%s -oc basic.out 2>basic.err", testprog); - /* Verify that nothing went to stderr. */ - assertTextFileContents("1 block\n", "basic.err"); - - /* Assert that the program finished. */ - failure("%s -oc crashed", testprog); - if (!assertEqualInt(r, 0)) - return; - - /* Verify that stdout is a well-formed cpio file in "odc" format. */ - p = slurpfile(&s, "basic.out"); - assertEqualInt(s, 512); - e = p; - - /* - * Some of these assertions could be stronger, but it's - * a little tricky because they depend on the local environment. - */ - - /* First entry is "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assert(is_octal(e + 6, 6)); /* dev */ - dev = from_octal(e + 6, 6); - assert(is_octal(e + 12, 6)); /* ino */ - ino = from_octal(e + 12, 6); -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Group members bits and others bits do not work. */ - assertEqualMem(e + 18, "100666", 6); /* Mode */ -#else - assertEqualMem(e + 18, "100644", 6); /* Mode */ -#endif - if (uid < 0) - uid = from_octal(e + 24, 6); - assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ - assert(is_octal(e + 30, 6)); /* gid */ - gid = from_octal(e + 30, 6); - assertEqualMem(e + 36, "000001", 6); /* nlink */ - failure("file entries should not have rdev set (dev field was 0%o)", - dev); - assertEqualMem(e + 42, "000000", 6); /* rdev */ - t = from_octal(e + 48, 11); /* mtime */ - assert(t <= now); /* File wasn't created in future. */ - assert(t >= now - 2); /* File was created w/in last 2 secs. */ - assertEqualMem(e + 59, "000005", 6); /* Name size */ - assertEqualMem(e + 65, "00000000012", 11); /* File size */ - assertEqualMem(e + 76, "file\0", 5); /* Name contents */ - assertEqualMem(e + 81, "1234567890", 10); /* File contents */ - e += 91; - - /* "symlink" pointing to "file" */ - if (canSymlink()) { - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualInt(dev, from_octal(e + 6, 6)); /* dev */ - assert(dev != from_octal(e + 12, 6)); /* ino */ -#if !defined(_WIN32) || defined(__CYGWIN__) - /* On Windows, symbolic link and group members bits and - * others bits do not work. */ - assertEqualMem(e + 18, "120777", 6); /* Mode */ -#endif - assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ - assertEqualInt(gid, from_octal(e + 30, 6)); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* nlink */ - failure("file entries should have rdev == 0 (dev was 0%o)", - from_octal(e + 6, 6)); - assertEqualMem(e + 42, "000000", 6); /* rdev */ - t = from_octal(e + 48, 11); /* mtime */ - assert(t <= now); /* File wasn't created in future. */ - assert(t >= now - 2); /* File was created w/in last 2 secs. */ - assertEqualMem(e + 59, "000010", 6); /* Name size */ - assertEqualMem(e + 65, "00000000004", 11); /* File size */ - assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */ - assertEqualMem(e + 84, "file", 4); /* Symlink target. */ - e += 88; - } - - /* "dir" */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - /* Dev should be same as first entry. */ - assert(is_octal(e + 6, 6)); /* dev */ - assertEqualInt(dev, from_octal(e + 6, 6)); - /* Ino must be different from first entry. */ - assert(is_octal(e + 12, 6)); /* ino */ - assert(dev != from_octal(e + 12, 6)); -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Group members bits and others bits do not work. */ - assertEqualMem(e + 18, "040777", 6); /* Mode */ -#else - /* Accept 042775 to accomodate systems where sgid bit propagates. */ - if (memcmp(e + 18, "042775", 6) != 0) - assertEqualMem(e + 18, "040775", 6); /* Mode */ -#endif - assertEqualInt(from_octal(e + 24, 6), uid); /* uid */ - /* Gid should be same as first entry. */ - assert(is_octal(e + 30, 6)); /* gid */ - assertEqualInt(gid, from_octal(e + 30, 6)); -#ifndef NLINKS_INACCURATE_FOR_DIRS - assertEqualMem(e + 36, "000002", 6); /* Nlink */ -#endif - t = from_octal(e + 48, 11); /* mtime */ - assert(t <= now); /* File wasn't created in future. */ - assert(t >= now - 2); /* File was created w/in last 2 secs. */ - assertEqualMem(e + 59, "000004", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "dir\0", 4); /* name */ - e += 80; - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000000", 6); /* dev */ - assertEqualMem(e + 12, "000000", 6); /* ino */ - assertEqualMem(e + 18, "000000", 6); /* Mode */ - assertEqualMem(e + 24, "000000", 6); /* uid */ - assertEqualMem(e + 30, "000000", 6); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* Nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000000", 11); /* mtime */ - assertEqualMem(e + 59, "000013", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */ - - free(p); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_d.c b/Utilities/cmlibarchive/cpio/test/test_option_d.c deleted file mode 100644 index 48e708596..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_d.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - - -DEFINE_TEST(test_option_d) -{ - int r; - - /* - * Create a file in a directory. - */ - assertMakeDir("dir", 0755); - assertMakeFile("dir/file", 0644, NULL); - - /* Create an archive. */ - r = systemf("echo dir/file | %s -o > archive.cpio 2>archive.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "archive.err"); - assertFileSize("archive.cpio", 512); - - /* Dearchive without -d, this should fail. */ - assertMakeDir("without-d", 0755); - assertChdir("without-d"); - r = systemf("%s -i < ../archive.cpio >out 2>err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("out"); - /* And the file should not be restored. */ - assertFileNotExists("dir/file"); - - /* Dearchive with -d, this should succeed. */ - assertChdir(".."); - assertMakeDir("with-d", 0755); - assertChdir("with-d"); - r = systemf("%s -id < ../archive.cpio >out 2>err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("out"); - assertTextFileContents("1 block\n", "err"); - /* And the file should be restored. */ - assertFileExists("dir/file"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_f.c b/Utilities/cmlibarchive/cpio/test/test_option_f.c deleted file mode 100644 index fa09e8523..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_f.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Unpack the archive in a new dir. - */ -static void -unpack(const char *dirname, const char *option) -{ - int r; - - assertMakeDir(dirname, 0755); - assertChdir(dirname); - extract_reference_file("test_option_f.cpio"); - r = systemf("%s -i %s < test_option_f.cpio > copy-no-a.out 2>copy-no-a.err", testprog, option); - assertEqualInt(0, r); - assertChdir(".."); -} - -DEFINE_TEST(test_option_f) -{ - /* Calibrate: No -f option, so everything should be extracted. */ - unpack("t0", "--no-preserve-owner"); - assertFileExists("t0/a123"); - assertFileExists("t0/a234"); - assertFileExists("t0/b123"); - assertFileExists("t0/b234"); - - /* Don't extract 'a*' files. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Single quotes isn't used by command.exe. */ - unpack("t1", "--no-preserve-owner -f a*"); -#else - unpack("t1", "--no-preserve-owner -f 'a*'"); -#endif - assertFileNotExists("t1/a123"); - assertFileNotExists("t1/a234"); - assertFileExists("t1/b123"); - assertFileExists("t1/b234"); - - /* Don't extract 'b*' files. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Single quotes isn't used by command.exe. */ - unpack("t2", "--no-preserve-owner -f b*"); -#else - unpack("t2", "--no-preserve-owner -f 'b*'"); -#endif - assertFileExists("t2/a123"); - assertFileExists("t2/a234"); - assertFileNotExists("t2/b123"); - assertFileNotExists("t2/b234"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_f.cpio.uu b/Utilities/cmlibarchive/cpio/test/test_option_f.cpio.uu deleted file mode 100644 index 42c63c396..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_f.cpio.uu +++ /dev/null @@ -1,16 +0,0 @@ -$FreeBSD$ -begin 644 test_option_f.cpio -M,#help.stdout 2>help.stderr", testprog); - failure("--help should generate nothing to stderr."); - assertEmptyFile("help.stderr"); - /* Help message should start with name of program. */ - p = slurpfile(&plen, "help.stdout"); - failure("Help output should be long enough."); - assert(plen >= 7); - failure("First line of help output should contain string 'bsdcpio'"); - assert(in_first_line(p, "bsdcpio")); - /* - * TODO: Extend this check to further verify that --help output - * looks approximately right. - */ - free(p); - - /* -h option should generate the same output. */ - r = systemf("%s -h >h.stdout 2>h.stderr", testprog); - failure("-h should generate nothing to stderr."); - assertEmptyFile("h.stderr"); - failure("stdout should be same for -h and --help"); - assertEqualFile("h.stdout", "help.stdout"); - - /* -W help should be another synonym. */ - r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog); - failure("-W help should generate nothing to stderr."); - assertEmptyFile("Whelp.stderr"); - failure("stdout should be same for -W help and --help"); - assertEqualFile("Whelp.stdout", "help.stdout"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_lzma.c b/Utilities/cmlibarchive/cpio/test/test_option_lzma.c deleted file mode 100644 index dc780f10f..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_lzma.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_option_lzma) -{ - char *p; - int r; - size_t s; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Archive it with lzma compression. */ - r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err", - testprog); - p = slurpfile(&s, "archive.err"); - p[s] = '\0'; - if (r != 0) { - if (strstr(p, "compression not available") != NULL) { - skipping("This version of bsdcpio was compiled " - "without lzma support"); - return; - } - failure("--lzma option is broken"); - assertEqualInt(r, 0); - return; - } - /* Check that the archive file has an lzma signature. */ - p = slurpfile(&s, "archive.out"); - assert(s > 2); - assertEqualMem(p, "\x5d\00\00", 3); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_m.c b/Utilities/cmlibarchive/cpio/test/test_option_m.c deleted file mode 100644 index 870a89483..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_m.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - - -DEFINE_TEST(test_option_m) -{ - int r; - - /* - * The reference archive has one file with an mtime in 1970, 1 - * second after the start of the epoch. - */ - - /* Restored without -m, the result should have a current mtime. */ - assertMakeDir("without-m", 0755); - assertChdir("without-m"); - extract_reference_file("test_option_m.cpio"); - r = systemf("%s --no-preserve-owner -i < test_option_m.cpio >out 2>err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("out"); - assertTextFileContents("1 block\n", "err"); - /* Should have been created within the last few seconds. */ - assertFileMtimeRecent("file"); - - /* With -m, it should have an mtime in 1970. */ - assertChdir(".."); - assertMakeDir("with-m", 0755); - assertChdir("with-m"); - extract_reference_file("test_option_m.cpio"); - r = systemf("%s --no-preserve-owner -im < test_option_m.cpio >out 2>err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("out"); - assertTextFileContents("1 block\n", "err"); - /* - * mtime in reference archive is '1' == 1 second after - * midnight Jan 1, 1970 UTC. - */ - assertFileMtime("file", 1, 0); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_m.cpio.uu b/Utilities/cmlibarchive/cpio/test/test_option_m.cpio.uu deleted file mode 100644 index 3d2002355..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_m.cpio.uu +++ /dev/null @@ -1,16 +0,0 @@ -$FreeBSD$ -begin 644 test_option_m.cpio -M,#it.out 2>it.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "it.err"); - extract_reference_file("test_option_t.stdout"); - p = slurpfile(NULL, "test_option_t.stdout"); - assertTextFileContents(p, "it.out"); - free(p); - - /* We accept plain "-t" as a synonym for "-it" */ - r = systemf("%s -t < test_option_t.cpio >t.out 2>t.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "t.err"); - extract_reference_file("test_option_t.stdout"); - p = slurpfile(NULL, "test_option_t.stdout"); - assertTextFileContents(p, "t.out"); - free(p); - - /* But "-ot" is an error. */ - assert(0 != systemf("%s -ot < test_option_t.cpio >ot.out 2>ot.err", - testprog)); - assertEmptyFile("ot.out"); - - /* List reference archive verbosely, make sure the TOC is correct. */ - r = systemf("%s -itv < test_option_t.cpio >tv.out 2>tv.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "tv.err"); - extract_reference_file("test_option_tv.stdout"); - - /* This doesn't work because the usernames on different systems - * are different and cpio now looks up numeric UIDs on - * the local system. */ - /* assertEqualFile("tv.out", "test_option_tv.stdout"); */ - - /* List reference archive with numeric IDs, verify TOC is correct. */ - r = systemf("%s -itnv < test_option_t.cpio >itnv.out 2>itnv.err", - testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "itnv.err"); - p = slurpfile(NULL, "itnv.out"); - /* Since -n uses numeric UID/GID, this part should be the - * same on every system. */ - assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42); - /* Date varies depending on local timezone. */ - if (memcmp(p + 42, "Dec 31 1969", 12) == 0) { - /* East of Greenwich we get Dec 31, 1969. */ - } else { - /* West of Greenwich get Jan 1, 1970 */ - assertEqualMem(p + 42, "Jan ", 4); - /* Some systems format "Jan 01", some "Jan 1" */ - assert(p[46] == ' ' || p[46] == '0'); - assertEqualMem(p + 47, "1 1970 ", 8); - } - assertEqualMem(p + 54, " file", 5); - free(p); - - /* But "-n" without "-t" is an error. */ - assert(0 != systemf("%s -in < test_option_t.cpio >in.out 2>in.err", - testprog)); - assertEmptyFile("in.out"); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_t.cpio.uu b/Utilities/cmlibarchive/cpio/test/test_option_t.cpio.uu deleted file mode 100644 index 055fe747d..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_t.cpio.uu +++ /dev/null @@ -1,16 +0,0 @@ -$FreeBSD$ -begin 644 test_option_t.cpio -M,# -#else -#include -#endif -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_option_u) -{ - struct utimbuf times; - char *p; - size_t s; - int r; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", - testprog); - assertEqualInt(r, 0); - - /* Check that the file contains only a single "a" */ - p = slurpfile(&s, "copy/f"); - assertEqualInt(s, 1); - assertEqualMem(p, "a", 1); - - /* Recreate the file with a single "b" */ - assertMakeFile("f", 0644, "b"); - - /* Set the mtime to the distant past. */ - memset(×, 0, sizeof(times)); - times.actime = 1; - times.modtime = 3; - assertEqualInt(0, utime("f", ×)); - - /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", - testprog); - assertEqualInt(r, 0); - - /* Verify that the file hasn't changed (it wasn't overwritten) */ - p = slurpfile(&s, "copy/f"); - assertEqualInt(s, 1); - assertEqualMem(p, "a", 1); - - /* Copy the file to the "copy" dir with -u (force) */ - r = systemf("echo f | %s -pud copy >copy.out 2>copy.err", - testprog); - assertEqualInt(r, 0); - - /* Verify that the file has changed (it was overwritten) */ - p = slurpfile(&s, "copy/f"); - assertEqualInt(s, 1); - assertEqualMem(p, "b", 1); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_version.c b/Utilities/cmlibarchive/cpio/test/test_option_version.c deleted file mode 100644 index f0dc88a88..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_version.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Test that --version option works and generates reasonable output. - */ - -static void -verify(const char *p, size_t s) -{ - const char *q = p; - - /* Version message should start with name of program, then space. */ - failure("version message too short:", p); - if (!assert(s > 6)) - return; - failure("Version message should begin with 'bsdcpio': %s", p); - if (!assertEqualMem(q, "bsdcpio ", 8)) - /* If we're not testing bsdcpio, don't keep going. */ - return; - q += 8; s -= 8; - /* Version number is a series of digits and periods. */ - while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { - ++q; - --s; - } - /* Version number terminated by space. */ - failure("Version: %s", p); - assert(s > 1); - /* Skip a single trailing a,b,c, or d. */ - if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') - ++q; - failure("Version: %s", p); - assert(*q == ' '); - ++q; --s; - /* Separator. */ - failure("Version: %s", p); - assertEqualMem(q, "-- ", 3); - q += 3; s -= 3; - /* libarchive name and version number */ - assert(s > 11); - failure("Version: %s", p); - assertEqualMem(q, "libarchive ", 11); - q += 11; s -= 11; - /* Version number is a series of digits and periods. */ - while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { - ++q; - --s; - } - /* Skip a single trailing a,b,c, or d. */ - if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') - ++q; - /* All terminated by a newline. */ - assert(s >= 1); - failure("Version: %s", p); -#if defined(_WIN32) && !defined(__CYGWIN__) - assertEqualMem(q, "\r\n", 2); -#else - assertEqualMem(q, "\n", 1); -#endif -} - - -DEFINE_TEST(test_option_version) -{ - int r; - char *p; - size_t s; - - r = systemf("%s --version >version.stdout 2>version.stderr", testprog); - if (r != 0) - r = systemf("%s -W version >version.stdout 2>version.stderr", - testprog); - failure("Unable to run either %s --version or %s -W version", - testprog, testprog); - if (!assert(r == 0)) - return; - - /* --version should generate nothing to stderr. */ - assertEmptyFile("version.stderr"); - /* Verify format of version message. */ - p = slurpfile(&s, "version.stdout"); - verify(p, s); - free(p); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_y.c b/Utilities/cmlibarchive/cpio/test/test_option_y.c deleted file mode 100644 index 934cd9025..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_y.c +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_y.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); - -DEFINE_TEST(test_option_y) -{ - char *p; - int r; - size_t s; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Archive it with bzip2 compression. */ - r = systemf("echo f | %s -oy >archive.out 2>archive.err", - testprog); - p = slurpfile(&s, "archive.err"); - p[s] = '\0'; - if (r != 0) { - if (strstr(p, "compression not available") != NULL) { - skipping("This version of bsdcpio was compiled " - "without bzip2 support"); - return; - } - failure("-y option is broken"); - assertEqualInt(r, 0); - return; - } - assertTextFileContents("1 block\n", "archive.err"); - /* Check that the archive file has a bzip2 signature. */ - p = slurpfile(&s, "archive.out"); - assert(s > 2); - assertEqualMem(p, "BZh9", 4); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_option_z.c b/Utilities/cmlibarchive/cpio/test/test_option_z.c deleted file mode 100644 index 0d7c148f7..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_option_z.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_option_z) -{ - char *p; - int r; - size_t s; - - /* Create a file. */ - assertMakeFile("f", 0644, "a"); - - /* Archive it with gzip compression. */ - r = systemf("echo f | %s -oz >archive.out 2>archive.err", - testprog); - p = slurpfile(&s, "archive.err"); - p[s] = '\0'; - if (r != 0) { - if (strstr(p, "compression not available") != NULL) { - skipping("This version of bsdcpio was compiled " - "without gzip support"); - return; - } - failure("-z option is broken"); - assertEqualInt(r, 0); - return; - } - /* Check that the archive file has a gzip signature. */ - p = slurpfile(&s, "archive.out"); - assert(s > 4); - assertEqualMem(p, "\x1f\x8b\x08\x00", 4); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_owner_parse.c b/Utilities/cmlibarchive/cpio/test/test_owner_parse.c deleted file mode 100644 index 9bdb4d901..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_owner_parse.c +++ /dev/null @@ -1,121 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -#include "../cpio.h" -#include "err.h" - -#if !defined(_WIN32) -#define ROOT "root" -static int root_uids[] = { 0 }; -static int root_gids[] = { 0 }; -#elif defined(__CYGWIN__) -/* On cygwin, the Administrator user most likely exists (unless - * it has been renamed or is in a non-English localization), but - * its primary group membership depends on how the user set up - * their /etc/passwd. Likely values are 513 (None), 545 (Users), - * or 544 (Administrators). Just check for one of those... - * TODO: Handle non-English localizations...e.g. French 'Administrateur' - * Use CreateWellKnownSID() and LookupAccountName()? - */ -#define ROOT "Administrator" -static int root_uids[] = { 500 }; -static int root_gids[] = { 513, 545, 544 }; -#endif - -#if defined(ROOT) -static int -int_in_list(int i, int *l, size_t n) -{ - while (n-- > 0) - if (*l++ == i) - return (1); - failure("%d", i); - return (0); -} -#endif - -DEFINE_TEST(test_owner_parse) -{ -#if !defined(ROOT) - skipping("No uid/gid configuration for this OS"); -#else - int uid, gid; - - assert(NULL == owner_parse(ROOT, &uid, &gid)); - assert(int_in_list(uid, root_uids, - sizeof(root_uids)/sizeof(root_uids[0]))); - assertEqualInt(-1, gid); - - - assert(NULL == owner_parse(ROOT ":", &uid, &gid)); - assert(int_in_list(uid, root_uids, - sizeof(root_uids)/sizeof(root_uids[0]))); - assert(int_in_list(gid, root_gids, - sizeof(root_gids)/sizeof(root_gids[0]))); - - assert(NULL == owner_parse(ROOT ".", &uid, &gid)); - assert(int_in_list(uid, root_uids, - sizeof(root_uids)/sizeof(root_uids[0]))); - assert(int_in_list(gid, root_gids, - sizeof(root_gids)/sizeof(root_gids[0]))); - - assert(NULL == owner_parse("111", &uid, &gid)); - assertEqualInt(111, uid); - assertEqualInt(-1, gid); - - assert(NULL == owner_parse("112:", &uid, &gid)); - assertEqualInt(112, uid); - /* Can't assert gid, since we don't know gid for user #112. */ - - assert(NULL == owner_parse("113.", &uid, &gid)); - assertEqualInt(113, uid); - /* Can't assert gid, since we don't know gid for user #113. */ - - assert(NULL == owner_parse(":114", &uid, &gid)); - assertEqualInt(-1, uid); - assertEqualInt(114, gid); - - assert(NULL == owner_parse(".115", &uid, &gid)); - assertEqualInt(-1, uid); - assertEqualInt(115, gid); - - assert(NULL == owner_parse("116:117", &uid, &gid)); - assertEqualInt(116, uid); - assertEqualInt(117, gid); - - /* - * TODO: Lookup current user/group name, build strings and - * use those to verify username/groupname lookups for ordinary - * users. - */ - - assert(NULL != owner_parse(":nonexistentgroup", &uid, &gid)); - assert(NULL != owner_parse(ROOT ":nonexistentgroup", &uid, &gid)); - assert(NULL != - owner_parse("nonexistentuser:nonexistentgroup", &uid, &gid)); -#endif -} diff --git a/Utilities/cmlibarchive/cpio/test/test_passthrough_dotdot.c b/Utilities/cmlibarchive/cpio/test/test_passthrough_dotdot.c deleted file mode 100644 index a81e1482d..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_passthrough_dotdot.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_dotdot.c,v 1.4 2008/08/24 06:21:00 kientzle Exp $"); - -/* - * Verify that "cpio -p .." works. - */ - -DEFINE_TEST(test_passthrough_dotdot) -{ - int r; - FILE *filelist; - - assertUmask(0); - - /* - * Create an assortment of files on disk. - */ - filelist = fopen("filelist", "w"); - - /* Directory. */ - assertMakeDir("dir", 0755); - assertChdir("dir"); - - fprintf(filelist, ".\n"); - - /* File with 10 bytes content. */ - assertMakeFile("file", 0642, "1234567890"); - fprintf(filelist, "file\n"); - - /* All done. */ - fclose(filelist); - - - /* - * Use cpio passthrough mode to copy files to another directory. - */ - r = systemf("%s -pdvm .. <../filelist >../stdout 2>../stderr", - testprog); - failure("Error invoking %s -pd ..", testprog); - assertEqualInt(r, 0); - - assertChdir(".."); - - /* Verify stderr and stdout. */ - assertTextFileContents("../.\n../file\n1 block\n", "stderr"); - assertEmptyFile("stdout"); - - /* Regular file. */ - assertIsReg("file", 0642); - assertFileSize("file", 10); - assertFileNLinks("file", 1); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_passthrough_reverse.c b/Utilities/cmlibarchive/cpio/test/test_passthrough_reverse.c deleted file mode 100644 index 86d70a6a2..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_passthrough_reverse.c +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_passthrough_reverse.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $"); - -/* - * As reported by Bernd Walter: Some people are in the habit of - * using "find -d" to generate a list for cpio -p because that - * copies the top-level dir last, which preserves owner and mode - * information. That's not necessary for bsdcpio (libarchive defers - * restoring directory information), but bsdcpio should still generate - * the correct results with this usage. - */ - -DEFINE_TEST(test_passthrough_reverse) -{ - int r; - FILE *filelist; - - assertUmask(0); - - /* - * Create an assortment of files on disk. - */ - filelist = fopen("filelist", "w"); - - /* Directory. */ - assertMakeDir("dir", 0743); - - /* File with 10 bytes content. */ - assertMakeFile("dir/file", 0644, "1234567890"); - fprintf(filelist, "dir/file\n"); - - /* Write dir last. */ - fprintf(filelist, "dir\n"); - - /* All done. */ - fclose(filelist); - - - /* - * Use cpio passthrough mode to copy files to another directory. - */ - r = systemf("%s -pdvm out stdout 2>stderr", testprog); - failure("Error invoking %s -pd out", testprog); - assertEqualInt(r, 0); - - assertChdir("out"); - - /* Verify stderr and stdout. */ - assertTextFileContents("out/dir/file\nout/dir\n1 block\n", - "../stderr"); - assertEmptyFile("../stdout"); - - /* dir */ - assertIsDir("dir", 0743); - - - /* Regular file. */ - assertIsReg("dir/file", 0644); - assertFileSize("dir/file", 10); - assertFileNLinks("dir/file", 1); -} diff --git a/Utilities/cmlibarchive/cpio/test/test_pathmatch.c b/Utilities/cmlibarchive/cpio/test/test_pathmatch.c deleted file mode 100644 index 12b888670..000000000 --- a/Utilities/cmlibarchive/cpio/test/test_pathmatch.c +++ /dev/null @@ -1,243 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -#include "pathmatch.h" - -/* - * Verify that the pattern matcher implements the wildcard logic specified - * in SUSv2 for the cpio command. This is essentially the - * shell glob syntax: - * * - matches any sequence of chars, including '/' - * ? - matches any single char, including '/' - * [...] - matches any of a set of chars, '-' specifies a range, - * initial '!' is undefined - * - * The specification in SUSv2 is a bit incomplete, I assume the following: - * Trailing '-' in [...] is not special. - * - * TODO: Figure out if there's a good way to extend this to handle - * Windows paths that use '\' as a path separator. - */ - -DEFINE_TEST(test_pathmatch) -{ - assertEqualInt(1, lafe_pathmatch("a/b/c", "a/b/c", 0)); - assertEqualInt(0, lafe_pathmatch("a/b/", "a/b/c", 0)); - assertEqualInt(0, lafe_pathmatch("a/b", "a/b/c", 0)); - assertEqualInt(0, lafe_pathmatch("a/b/c", "a/b/", 0)); - assertEqualInt(0, lafe_pathmatch("a/b/c", "a/b", 0)); - - /* Empty pattern only matches empty string. */ - assertEqualInt(1, lafe_pathmatch("","", 0)); - assertEqualInt(0, lafe_pathmatch("","a", 0)); - assertEqualInt(1, lafe_pathmatch("*","", 0)); - assertEqualInt(1, lafe_pathmatch("*","a", 0)); - assertEqualInt(1, lafe_pathmatch("*","abcd", 0)); - /* SUSv2: * matches / */ - assertEqualInt(1, lafe_pathmatch("*","abcd/efgh/ijkl", 0)); - assertEqualInt(1, lafe_pathmatch("abcd*efgh/ijkl","abcd/efgh/ijkl", 0)); - assertEqualInt(1, lafe_pathmatch("abcd***efgh/ijkl","abcd/efgh/ijkl", 0)); - assertEqualInt(1, lafe_pathmatch("abcd***/efgh/ijkl","abcd/efgh/ijkl", 0)); - assertEqualInt(0, lafe_pathmatch("?", "", 0)); - assertEqualInt(0, lafe_pathmatch("?", "\0", 0)); - assertEqualInt(1, lafe_pathmatch("?", "a", 0)); - assertEqualInt(0, lafe_pathmatch("?", "ab", 0)); - assertEqualInt(1, lafe_pathmatch("?", ".", 0)); - assertEqualInt(1, lafe_pathmatch("?", "?", 0)); - assertEqualInt(1, lafe_pathmatch("a", "a", 0)); - assertEqualInt(0, lafe_pathmatch("a", "ab", 0)); - assertEqualInt(0, lafe_pathmatch("a", "ab", 0)); - assertEqualInt(1, lafe_pathmatch("a?c", "abc", 0)); - /* SUSv2: ? matches / */ - assertEqualInt(1, lafe_pathmatch("a?c", "a/c", 0)); - assertEqualInt(1, lafe_pathmatch("a?*c*", "a/c", 0)); - assertEqualInt(1, lafe_pathmatch("*a*", "a/c", 0)); - assertEqualInt(1, lafe_pathmatch("*a*", "/a/c", 0)); - assertEqualInt(1, lafe_pathmatch("*a*", "defaaaaaaa", 0)); - assertEqualInt(0, lafe_pathmatch("a*", "defghi", 0)); - assertEqualInt(0, lafe_pathmatch("*a*", "defghi", 0)); - - /* Character classes */ - assertEqualInt(1, lafe_pathmatch("abc[def", "abc[def", 0)); - assertEqualInt(0, lafe_pathmatch("abc[def]", "abc[def", 0)); - assertEqualInt(0, lafe_pathmatch("abc[def", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[def]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[def]", "abce", 0)); - assertEqualInt(1, lafe_pathmatch("abc[def]", "abcf", 0)); - assertEqualInt(0, lafe_pathmatch("abc[def]", "abcg", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d*f]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d*f]", "abc*", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d*f]", "abcdefghi", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d*", "abcdefghi", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d*", "abc[defghi", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abce", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-f]", "abcf", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d-f]", "abcg", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abca", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abce", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcf", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abcg", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abch", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abci", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abcj", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-k]", "abck", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abcl", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d-fh-k]", "abc-", 0)); - - /* [] matches nothing, [!] is the same as ? */ - assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcdefg", 0)); - assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcqefg", 0)); - assertEqualInt(0, lafe_pathmatch("abc[]efg", "abcefg", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!]efg", "abcdefg", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!]efg", "abcqefg", 0)); - assertEqualInt(0, lafe_pathmatch("abc[!]efg", "abcefg", 0)); - - /* I assume: Trailing '-' is non-special. */ - assertEqualInt(0, lafe_pathmatch("abc[d-fh-]", "abcl", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abch", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abc-", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-fh-]", "abc-", 0)); - - /* ']' can be backslash-quoted within a character class. */ - assertEqualInt(1, lafe_pathmatch("abc[\\]]", "abc]", 0)); - assertEqualInt(1, lafe_pathmatch("abc[\\]d]", "abc]", 0)); - assertEqualInt(1, lafe_pathmatch("abc[\\]d]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d\\]]", "abc]", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d\\]]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d]e]", "abcde]", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d\\]e]", "abc]", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d\\]e]", "abcd]e", 0)); - assertEqualInt(0, lafe_pathmatch("abc[d]e]", "abc]", 0)); - - /* backslash-quoted chars can appear as either end of a range. */ - assertEqualInt(1, lafe_pathmatch("abc[\\d-f]gh", "abcegh", 0)); - assertEqualInt(0, lafe_pathmatch("abc[\\d-f]gh", "abcggh", 0)); - assertEqualInt(0, lafe_pathmatch("abc[\\d-f]gh", "abc\\gh", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d-\\f]gh", "abcegh", 0)); - assertEqualInt(1, lafe_pathmatch("abc[\\d-\\f]gh", "abcegh", 0)); - assertEqualInt(1, lafe_pathmatch("abc[\\d-\\f]gh", "abcegh", 0)); - /* backslash-quoted '-' isn't special. */ - assertEqualInt(0, lafe_pathmatch("abc[d\\-f]gh", "abcegh", 0)); - assertEqualInt(1, lafe_pathmatch("abc[d\\-f]gh", "abc-gh", 0)); - - /* Leading '!' negates a character class. */ - assertEqualInt(0, lafe_pathmatch("abc[!d]", "abcd", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!d]", "abce", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!d]", "abcc", 0)); - assertEqualInt(0, lafe_pathmatch("abc[!d-z]", "abcq", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!d-gi-z]", "abch", 0)); - assertEqualInt(1, lafe_pathmatch("abc[!fgijkl]", "abch", 0)); - assertEqualInt(0, lafe_pathmatch("abc[!fghijkl]", "abch", 0)); - - /* Backslash quotes next character. */ - assertEqualInt(0, lafe_pathmatch("abc\\[def]", "abc\\d", 0)); - assertEqualInt(1, lafe_pathmatch("abc\\[def]", "abc[def]", 0)); - assertEqualInt(0, lafe_pathmatch("abc\\\\[def]", "abc[def]", 0)); - assertEqualInt(0, lafe_pathmatch("abc\\\\[def]", "abc\\[def]", 0)); - assertEqualInt(1, lafe_pathmatch("abc\\\\[def]", "abc\\d", 0)); - assertEqualInt(1, lafe_pathmatch("abcd\\", "abcd\\", 0)); - assertEqualInt(0, lafe_pathmatch("abcd\\", "abcd\\[", 0)); - assertEqualInt(0, lafe_pathmatch("abcd\\", "abcde", 0)); - assertEqualInt(0, lafe_pathmatch("abcd\\[", "abcd\\", 0)); - - /* - * Because '.' and '/' have special meanings, we can - * identify many equivalent paths even if they're expressed - * differently. (But quoting a character with '\\' suppresses - * special meanings!) - */ - assertEqualInt(0, lafe_pathmatch("a/b/", "a/bc", 0)); - assertEqualInt(1, lafe_pathmatch("a/./b", "a/b", 0)); - assertEqualInt(0, lafe_pathmatch("a\\/./b", "a/b", 0)); - assertEqualInt(0, lafe_pathmatch("a/\\./b", "a/b", 0)); - assertEqualInt(0, lafe_pathmatch("a/.\\/b", "a/b", 0)); - assertEqualInt(0, lafe_pathmatch("a\\/\\.\\/b", "a/b", 0)); - assertEqualInt(1, lafe_pathmatch("./abc/./def/", "abc/def/", 0)); - assertEqualInt(1, lafe_pathmatch("abc/def", "./././abc/./def", 0)); - assertEqualInt(1, lafe_pathmatch("abc/def/././//", "./././abc/./def/", 0)); - assertEqualInt(1, lafe_pathmatch(".////abc/.//def", "./././abc/./def", 0)); - assertEqualInt(1, lafe_pathmatch("./abc?def/", "abc/def/", 0)); - failure("\"?./\" is not the same as \"/./\""); - assertEqualInt(0, lafe_pathmatch("./abc?./def/", "abc/def/", 0)); - failure("Trailing '/' should match no trailing '/'"); - assertEqualInt(1, lafe_pathmatch("./abc/./def/", "abc/def", 0)); - failure("Trailing '/./' is still the same directory."); - assertEqualInt(1, lafe_pathmatch("./abc/./def/./", "abc/def", 0)); - failure("Trailing '/.' is still the same directory."); - assertEqualInt(1, lafe_pathmatch("./abc/./def/.", "abc/def", 0)); - assertEqualInt(1, lafe_pathmatch("./abc/./def", "abc/def/", 0)); - failure("Trailing '/./' is still the same directory."); - assertEqualInt(1, lafe_pathmatch("./abc/./def", "abc/def/./", 0)); - failure("Trailing '/.' is still the same directory."); - assertEqualInt(1, lafe_pathmatch("./abc*/./def", "abc/def/.", 0)); - - /* Matches not anchored at beginning. */ - assertEqualInt(0, - lafe_pathmatch("bcd", "abcd", PATHMATCH_NO_ANCHOR_START)); - assertEqualInt(1, - lafe_pathmatch("abcd", "abcd", PATHMATCH_NO_ANCHOR_START)); - assertEqualInt(0, - lafe_pathmatch("^bcd", "abcd", PATHMATCH_NO_ANCHOR_START)); - assertEqualInt(1, - lafe_pathmatch("b/c/d", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); - assertEqualInt(0, - lafe_pathmatch("b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); - assertEqualInt(0, - lafe_pathmatch("^b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_START)); - - /* Matches not anchored at end. */ - assertEqualInt(0, - lafe_pathmatch("bcd", "abcd", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("abcd", "abcd", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("abcd", "abcd/", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("abcd", "abcd/.", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(0, - lafe_pathmatch("abc", "abcd", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(0, - lafe_pathmatch("a/b/c$", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c$", "a/b/c", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c$", "a/b/c/", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c/", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(0, - lafe_pathmatch("a/b/c/$", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c/$", "a/b/c/", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(1, - lafe_pathmatch("a/b/c/$", "a/b/c", PATHMATCH_NO_ANCHOR_END)); - assertEqualInt(0, - lafe_pathmatch("b/c", "a/b/c/d", PATHMATCH_NO_ANCHOR_END)); -} diff --git a/Utilities/cmlibarchive/doc/mdoc2man.awk b/Utilities/cmlibarchive/doc/mdoc2man.awk deleted file mode 100755 index 2d67c35d7..000000000 --- a/Utilities/cmlibarchive/doc/mdoc2man.awk +++ /dev/null @@ -1,391 +0,0 @@ -#!/usr/bin/awk -# -# Copyright (c) 2003 Peter Stuge -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# Dramatically overhauled by Tim Kientzle. This version almost -# handles library-style pages with Fn, Ft, etc commands. Still -# a lot of problems... - -BEGIN { - displaylines = 0 - trailer = "" - out = "" - sep = "" - nextsep = " " -} - -# Add a word with appropriate preceding whitespace -# Maintain a short queue of the expected upcoming word separators. -function add(str) { - out=out sep str - sep = nextsep - nextsep = " " -} - -# Add a word with no following whitespace -# Use for opening punctuation such as '(' -function addopen(str) { - add(str) - sep = "" -} - -# Add a word with no preceding whitespace -# Use for closing punctuation such as ')' or '.' -function addclose(str) { - sep = "" - add(str) -} - -# Add a word with no space before or after -# Use for separating punctuation such as '=' -function addpunct(str) { - sep = "" - add(str) - sep = "" -} - -# Emit the current line so far -function endline() { - addclose(trailer) - trailer = "" - if(length(out) > 0) { - print out - out="" - } - if(displaylines > 0) { - displaylines = displaylines - 1 - if (displaylines == 0) - dispend() - } - # First word on next line has no preceding whitespace - sep = "" -} - -function linecmd(cmd) { - endline() - add(cmd) - endline() -} - -function breakline() { - linecmd(".br") -} - -# Start an indented display -function dispstart() { - linecmd(".RS 4") -} - -# End an indented display -function dispend() { - linecmd(".RE") -} - -# Collect rest of input line -function wtail() { - retval="" - while(w 0) { - sub("^[ \t]*", "", l) - if (match(l, "^\"")) { - l = substr(l, 2) - o = index(l, "\"") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } else { - o = match(l, "[ \t]") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } - } - return n-1 -} - -! /^\./ { - out = $0 - endline() - next -} - -/^\.\\"/ { next } - -{ - sub("^\\.","") - nwords=splitwords($0, words) - # TODO: Instead of iterating 'w' over the array, have a separate - # function that returns 'next word' and use that. This will allow - # proper handling of double-quoted arguments as well. - for(w=1;w<=nwords;w++) { - if(match(words[w],"^Li$")) { # Literal; rest of line is unformatted - dispstart() - displaylines = 1 - } else if(match(words[w],"^Dl$")) { # Display literal - dispstart() - displaylines = 1 - } else if(match(words[w],"^Bd$")) { # Begin display - if(match(words[w+1],"-literal")) { - dispstart() - linecmd(".nf") - displaylines=10000 - w=nwords - } - } else if(match(words[w],"^Ed$")) { # End display - displaylines = 0 - dispend() - } else if(match(words[w],"^Ns$")) { # Suppress space after next word - nextsep = "" - } else if(match(words[w],"^No$")) { # Normal text - add(words[++w]) - } else if(match(words[w],"^Dq$")) { # Quote - addopen("``") - add(words[++w]) - while(w") - } else if(match(words[w],"^Dd$")) { - date=wtail() - next - } else if(match(words[w],"^Dt$")) { - id=wtail() - next - } else if(match(words[w],"^Ox$")) { - add("OpenBSD") - } else if(match(words[w],"^Fx$")) { - add("FreeBSD") - } else if(match(words[w],"^Nx$")) { - add("NetBSD") - } else if(match(words[w],"^St$")) { - if (match(words[w+1], "^-p1003.1$")) { - w++ - add("IEEE Std 1003.1 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-96$")) { - w++ - add("ISO/IEC 9945-1:1996 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-88$")) { - w++ - add("IEEE Std 1003.1-1988 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-2001$")) { - w++ - add("IEEE Std 1003.1-2001 (``POSIX.1'')") - } else if(match(words[w+1], "^-susv2$")) { - w++ - add("Version 2 of the Single UNIX Specification (``SUSv2'')") - } - } else if(match(words[w],"^Ex$")) { - if (match(words[w+1], "^-std$")) { - w++ - add("The \\fB" name "\\fP utility exits 0 on success, and >0 if an error occurs.") - } - } else if(match(words[w],"^Os$")) { - add(".TH " id " \"" date "\" \"" wtail() "\"") - } else if(match(words[w],"^Sh$")) { - section=wtail() - add(".SH " section) - linecmd(".ad l") - } else if(match(words[w],"^Xr$")) { - add("\\fB" words[++w] "\\fP(" words[++w] ")" words[++w]) - } else if(match(words[w],"^Nm$")) { - if(match(section,"SYNOPSIS")) - breakline() - if(w >= nwords) - n=name - else if (match(words[w+1], "^[A-Z][a-z]$")) - n=name - else if (match(words[w+1], "^[.,;:]$")) - n=name - else { - n=words[++w] - if(!length(name)) - name=n - } - if(!length(n)) - n=name - add("\\fB\\%" n "\\fP") - } else if(match(words[w],"^Nd$")) { - add("\\- " wtail()) - } else if(match(words[w],"^Fl$")) { - add("\\fB\\-" words[++w] "\\fP") - } else if(match(words[w],"^Ar$")) { - addopen("\\fI") - if(w==nwords) - add("file ...\\fP") - else - add(words[++w] "\\fP") - } else if(match(words[w],"^Cm$")) { - add("\\fB" words[++w] "\\fP") - } else if(match(words[w],"^Op$")) { - addopen("[") - option=1 - trailer="]" trailer - } else if(match(words[w],"^Pp$")) { - linecmd(".PP") - } else if(match(words[w],"^An$")) { - endline() - } else if(match(words[w],"^Ss$")) { - add(".SS") - } else if(match(words[w],"^Ft$")) { - if (match(section, "SYNOPSIS")) { - breakline() - } - add("\\fI" wtail() "\\fP") - if (match(section, "SYNOPSIS")) { - breakline() - } - } else if(match(words[w],"^Fn$")) { - ++w - F = "\\fB\\%" words[w] "\\fP(" - Fsep = "" - while(w\\fP") - } else if(match(words[w],"^Pa$")) { - addopen("\\fI") - w++ - if(match(words[w],"^\\.")) - add("\\&") - add(words[w] "\\fP") - } else if(match(words[w],"^Dv$")) { - add(".BR") - } else if(match(words[w],"^Em|Ev$")) { - add(".IR") - } else if(match(words[w],"^Pq$")) { - addopen("(") - trailer=")" trailer - } else if(match(words[w],"^Aq$")) { - addopen("\\%<") - trailer=">" trailer - } else if(match(words[w],"^Brq$")) { - addopen("{") - trailer="}" trailer - } else if(match(words[w],"^S[xy]$")) { - add(".B " wtail()) - } else if(match(words[w],"^Ic$")) { - add("\\fB") - trailer="\\fP" trailer - } else if(match(words[w],"^Bl$")) { - oldoptlist=optlist - linecmd(".RS 5") - if(match(words[w+1],"-bullet")) - optlist=1 - else if(match(words[w+1],"-enum")) { - optlist=2 - enum=0 - } else if(match(words[w+1],"-tag")) - optlist=3 - else if(match(words[w+1],"-item")) - optlist=4 - else if(match(words[w+1],"-bullet")) - optlist=1 - w=nwords - } else if(match(words[w],"^El$")) { - linecmd(".RE") - optlist=oldoptlist - } else if(match(words[w],"^It$")&&optlist) { - if(optlist==1) - add(".IP \\(bu") - else if(optlist==2) - add(".IP " ++enum ".") - else if(optlist==3) { - add(".TP") - endline() - if(match(words[w+1],"^Pa$|^Ev$")) { - add(".B") - w++ - } - } else if(optlist==4) - add(".IP") - } else if(match(words[w],"^Xo$")) { - # TODO: Figure out how to handle this - } else if(match(words[w],"^Xc$")) { - # TODO: Figure out how to handle this - } else if(match(words[w],"^[=]$")) { - addpunct(words[w]) - } else if(match(words[w],"^[\[{(]$")) { - addopen(words[w]) - } else if(match(words[w],"^[\\\])}.,;:]$")) { - addclose(words[w]) - } else { - add(words[w]) - } - } - if(match(out,"^\\.[^a-zA-Z]")) - sub("^\\.","",out) - endline() -} diff --git a/Utilities/cmlibarchive/doc/mdoc2wiki.awk b/Utilities/cmlibarchive/doc/mdoc2wiki.awk deleted file mode 100755 index 5d063be3e..000000000 --- a/Utilities/cmlibarchive/doc/mdoc2wiki.awk +++ /dev/null @@ -1,448 +0,0 @@ -#!/usr/bin/awk -# -# Copyright (c) 2003 Peter Stuge -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -# Dramatically overhauled by Tim Kientzle. This version almost -# handles library-style pages with Fn, Ft, etc commands. Still -# a lot of problems... - -BEGIN { - displaylines = 0 - listdepth = 0 - trailer = "" - out = "" - sep = "" - nextsep = " " - spaces = " " -} - -# Add a word with appropriate preceding whitespace -# Maintain a short queue of the expected upcoming word separators. -function add(str) { - out=out sep str - sep = nextsep - nextsep = " " -} - -# Add a word with no following whitespace -# Use for opening punctuation such as '(' -function addopen(str) { - add(str) - sep = "" -} - -# Add a word with no preceding whitespace -# Use for closing punctuation such as ')' or '.' -function addclose(str) { - sep = "" - add(str) -} - -# Add a word with no space before or after -# Use for separating punctuation such as '=' -function addpunct(str) { - sep = "" - add(str) - sep = "" -} - -# Emit the current line so far -function endline() { - addclose(trailer) - trailer = "" - if(length(out) > 0) { - print out - out="" - } - if(displaylines > 0) { - displaylines = displaylines - 1 - if (displaylines == 0) - dispend() - } - # First word on next line has no preceding whitespace - sep = "" -} - -function linecmd(cmd) { - endline() - add(cmd) - endline() -} - -function breakline() { - linecmd("
") -} - -# Start an indented display -function dispstart() { - linecmd("{{{") -} - -# End an indented display -function dispend() { - linecmd("}}}") -} - -# Collect rest of input line -function wtail() { - retval="" - while(w 0) { - sub("^[ \t]*", "", l) - if (match(l, "^\"")) { - l = substr(l, 2) - o = index(l, "\"") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } else { - o = match(l, "[ \t]") - if (o > 0) { - w = substr(l, 1, o-1) - l = substr(l, o+1) - dest[n++] = w - } else { - dest[n++] = l - l = "" - } - } - } - return n-1 -} - -! /^\./ { - out = $0 - endline() - next -} - -/^\.\\"/ { next } - -{ - sub("^\\.","") - nwords=splitwords($0, words) - # TODO: Instead of iterating 'w' over the array, have a separate - # function that returns 'next word' and use that. This will allow - # proper handling of double-quoted arguments as well. - for(w=1;w<=nwords;w++) { - if(match(words[w],"^Li$")) { # Literal; rest of line is unformatted - dispstart() - displaylines = 1 - } else if(match(words[w],"^Dl$")) { # Display literal - dispstart() - displaylines = 1 - } else if(match(words[w],"^Bd$")) { # Begin display - if(match(words[w+1],"-literal")) { - dispstart() - displaylines=10000 - w=nwords - } - } else if(match(words[w],"^Ed$")) { # End display - displaylines = 0 - dispend() - } else if(match(words[w],"^Ns$")) { # Suppress space before next word - sep="" - } else if(match(words[w],"^No$")) { # Normal text - add(words[++w]) - } else if(match(words[w],"^Dq$")) { # Quote - addopen("\"") - add(words[++w]) - while(w`") - } else if(match(words[w],"^Dd$")) { - date=wtail() - next - } else if(match(words[w],"^Dt$")) { - id=wtail() - next - } else if(match(words[w],"^Ox$")) { - add("OpenBSD") - } else if(match(words[w],"^Fx$")) { - add("FreeBSD") - } else if(match(words[w],"^Bx$")) { - add("BSD") - } else if(match(words[w],"^Nx$")) { - add("NetBSD") - } else if(match(words[w],"^St$")) { - if (match(words[w+1], "^-p1003.1$")) { - w++ - add("IEEE Std 1003.1 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-96$")) { - w++ - add("ISO/IEC 9945-1:1996 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-88$")) { - w++ - add("IEEE Std 1003.1-1988 (``POSIX.1'')") - } else if(match(words[w+1], "^-p1003.1-2001$")) { - w++ - add("IEEE Std 1003.1-2001 (``POSIX.1'')") - } else if(match(words[w+1], "^-susv2$")) { - w++ - add("Version 2 of the Single UNIX Specification (``SUSv2'')") - } - } else if(match(words[w],"^Ex$")) { - if (match(words[w+1], "^-std$")) { - w++ - add("The *" name "* utility exits 0 on success, and >0 if an error occurs.") - } - } else if(match(words[w],"^Os$")) { - add("#summary " id " manual page") - } else if(match(words[w],"^Sh$")) { - section=wtail() - linecmd("== " section " ==") - } else if(match(words[w],"^Xr$")) { - add("*" words[++w] "*(" words[++w] ")" words[++w]) - } else if(match(words[w],"^Nm$")) { - if(match(section,"SYNOPSIS")) - breakline() - if(w >= nwords) - n=name - else if (match(words[w+1], "^[A-Z][a-z]$")) - n=name - else if (match(words[w+1], "^[.,;:]$")) - n=name - else { - n=words[++w] - if(!length(name)) - name=n - } - if(!length(n)) - n=name - if (displaylines == 0) - add("*" n "*") - else - add(n) - } else if(match(words[w],"^Nd$")) { - add("- " wtail()) - } else if(match(words[w],"^Fl$")) { - if (displaylines == 0) - add("*-" words[++w] "*") - else - add("-" words[++w]) - } else if(match(words[w],"^Ar$")) { - if(w==nwords) - add("_file ..._") - else { - ++w - gsub("<", "`<`", words[w]) - add("_" words[w] "_") - } - } else if(match(words[w],"^Cm$")) { - ++w - if (displaylines == 0) { - gsub("^_", "`_`", words[w]) - gsub("\\*$", "`*`", words[w]) - add("*" words[w] "*") - } else - add(words[w]) - } else if(match(words[w],"^Op$")) { - addopen("`[`") - option=1 - trailer="`]`" trailer - } else if(match(words[w],"^Pp$")) { - ++w - endline() - print "" - } else if(match(words[w],"^An$")) { - if (match(words[w+1],"-nosplit")) - ++w - endline() - } else if(match(words[w],"^Ss$")) { - add("===") - trailer="===" - } else if(match(words[w],"^Ft$")) { - if (match(section, "SYNOPSIS")) { - breakline() - } - l = wtail() - gsub("\\*", "`*`", l) - - add("*" l "*") - if (match(section, "SYNOPSIS")) { - breakline() - } - } else if(match(words[w],"^Fn$")) { - ++w - F = "*" words[w] "*(" - Fsep = "" - while(w*") - } else if(match(words[w],"^Pa$")) { - w++ -# if(match(words[w],"^\\.")) -# add("\\&") - if (displaylines == 0) - add("_" words[w] "_") - else - add(words[w]) - } else if(match(words[w],"^Dv$")) { - linecmd() - } else if(match(words[w],"^Em|Ev$")) { - add(".IR") - } else if(match(words[w],"^Pq$")) { - addopen("(") - trailer=")" trailer - } else if(match(words[w],"^Aq$")) { - addopen(" <") - trailer=">" trailer - } else if(match(words[w],"^Brq$")) { - addopen("{") - trailer="}" trailer - } else if(match(words[w],"^S[xy]$")) { - add(".B " wtail()) - } else if(match(words[w],"^Tn$")) { - n=wtail() - gsub("\\*$", "`*`", n) - add("*" n "*") - } else if(match(words[w],"^Ic$")) { - add("\\fB") - trailer="\\fP" trailer - } else if(match(words[w],"^Bl$")) { - ++listdepth - listnext[listdepth]="" - if(match(words[w+1],"-bullet")) { - optlist[listdepth]=1 - addopen("
    ") - listclose[listdepth]="
" - } else if(match(words[w+1],"-enum")) { - optlist[listdepth]=2 - enum=0 - addopen("
    ") - listclose[listdepth]="
" - } else if(match(words[w+1],"-tag")) { - optlist[listdepth]=3 - addopen("
") - listclose[listdepth]="
" - } else if(match(words[w+1],"-item")) { - optlist[listdepth]=4 - addopen("
    ") - listclose[listdepth]="
" - } - w=nwords - } else if(match(words[w],"^El$")) { - addclose(listnext[listdepth]) - addclose(listclose[listdepth]) - listclose[listdepth]="" - listdepth-- - } else if(match(words[w],"^It$")) { - addclose(listnext[listdepth]) - if(optlist[listdepth]==1) { - addpunct("
  • ") - listnext[listdepth] = "
  • " - } else if(optlist[listdepth]==2) { - addpunct("
  • ") - listnext[listdepth] = "
  • " - } else if(optlist[listdepth]==3) { - addpunct("
    ") - listnext[listdepth] = "
    " - if(match(words[w+1],"^Xo$")) { - # Suppress trailer - w++ - } else if(match(words[w+1],"^Pa$|^Ev$")) { - addopen("*") - w++ - add(words[++w] "*") - } else { - trailer = listnext[listdepth] "
    " trailer - listnext[listdepth] = "
    " - } - } else if(optlist[listdepth]==4) { - addpunct("
  • ") - listnext[listdepth] = "
  • " - } - } else if(match(words[w],"^Xo$")) { - # TODO: Figure out how to handle this - } else if(match(words[w],"^Xc$")) { - # TODO: Figure out how to handle this - if (optlist[listdepth] == 3) { - addclose(listnext[listdepth]) - addopen("
    ") - listnext[listdepth] = "
    " - } - } else if(match(words[w],"^[=]$")) { - addpunct(words[w]) - } else if(match(words[w],"^[\[{(]$")) { - addopen(words[w]) - } else if(match(words[w],"^[\\\])}.,;:]$")) { - addclose(words[w]) - } else { - sub("\\\\&", "", words[w]) - add(words[w]) - } - } - if(match(out,"^\\.[^a-zA-Z]")) - sub("^\\.","",out) - endline() -} diff --git a/Utilities/cmlibarchive/doc/update.sh b/Utilities/cmlibarchive/doc/update.sh deleted file mode 100755 index 87c8453d0..000000000 --- a/Utilities/cmlibarchive/doc/update.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/sh - -# -# Simple script to repopulate the 'doc' tree from -# the mdoc man pages stored in each project. -# - -# Build Makefile in 'man' directory -cd man -rm -f *.[135] -echo > Makefile -echo "default: all" >>Makefile -echo >>Makefile -all="all:" -for d in libarchive tar cpio; do - for f in ../../$d/*.[135]; do - outname="`basename $f`" - echo >> Makefile - echo $outname: ../mdoc2man.awk $f >> Makefile - echo " awk -f ../mdoc2man.awk < $f > $outname" >> Makefile - all="$all $outname" - done -done -echo $all >>Makefile -cd .. - -# Rebuild Makefile in 'text' directory -cd text -rm -f *.txt -echo > Makefile -echo "default: all" >>Makefile -echo >>Makefile -all="all:" -for d in libarchive tar cpio; do - for f in ../../$d/*.[135]; do - outname="`basename $f`.txt" - echo >> Makefile - echo $outname: $f >> Makefile - echo " nroff -mdoc $f | col -b > $outname" >> Makefile - all="$all $outname" - done -done -echo $all >>Makefile -cd .. - -# Rebuild Makefile in 'pdf' directory -cd pdf -rm -f *.pdf -echo > Makefile -echo "default: all" >>Makefile -echo >>Makefile -all="all:" -for d in libarchive tar cpio; do - for f in ../../$d/*.[135]; do - outname="`basename $f`.pdf" - echo >> Makefile - echo $outname: $f >> Makefile - echo " groff -mdoc -T ps $f | ps2pdf - - > $outname" >> Makefile - all="$all $outname" - done -done -echo $all >>Makefile -cd .. - -# Build Makefile in 'html' directory -cd html -rm -f *.html -echo > Makefile -echo "default: all" >>Makefile -echo >>Makefile -all="all:" -for d in libarchive tar cpio; do - for f in ../../$d/*.[135]; do - outname="`basename $f`.html" - echo >> Makefile - echo $outname: ../mdoc2man.awk $f >> Makefile - echo " groff -mdoc -T html $f > $outname" >> Makefile - all="$all $outname" - done -done -echo $all >>Makefile -cd .. - -# Build Makefile in 'wiki' directory -cd wiki -rm -f *.wiki -echo > Makefile -echo "default: all" >>Makefile -echo >>Makefile -all="all:" -for d in libarchive tar cpio; do - for f in ../../$d/*.[135]; do - outname="`basename $f | awk '{ac=split($0,a,"[_.-]");o="ManPage";for(w=0;w<=ac;++w){o=o toupper(substr(a[w],1,1)) substr(a[w],2)};print o}'`.wiki" - echo >> Makefile - echo $outname: ../mdoc2wiki.awk $f >> Makefile - echo " awk -f ../mdoc2wiki.awk < $f > $outname" >> Makefile - all="$all $outname" - done -done -echo $all >>Makefile -cd .. - -# Convert all of the manpages to -man format -(cd man && make) -# Format all of the manpages to text -(cd text && make) -# Format all of the manpages to PDF -(cd pdf && make) -# Format all of the manpages to HTML -(cd html && make) -# Format all of the manpages to Google Wiki syntax -(cd wiki && make) diff --git a/Utilities/cmlibarchive/examples/minitar/README b/Utilities/cmlibarchive/examples/minitar/README deleted file mode 100644 index 83f646cdb..000000000 --- a/Utilities/cmlibarchive/examples/minitar/README +++ /dev/null @@ -1,12 +0,0 @@ -"minitar" is a minimal example of a program that uses libarchive to -read/write various archive formats. It's a more ambitious version of -'untar.c' that includes compile-time options to enable/disable various -features, including non-tar formats, archive creation, and automatic -decompression support. - -I use this as a test bed to check for "link pollution," ensuring that -a program using libarchive does not pull in unnecessary code. - -The "minitar" program is also a good starting point for anyone who -wants to use libarchive for their own purposes, as it demonstrates -basic usage of the library. diff --git a/Utilities/cmlibarchive/examples/minitar/minitar.c b/Utilities/cmlibarchive/examples/minitar/minitar.c deleted file mode 100644 index 73b4baf44..000000000 --- a/Utilities/cmlibarchive/examples/minitar/minitar.c +++ /dev/null @@ -1,421 +0,0 @@ -/*- - * This file is in the public domain. - * Do with it as you will. - */ - -/*- - * This is a compact "tar" program whose primary goal is small size. - * Statically linked, it can be very small indeed. This serves a number - * of goals: - * o a testbed for libarchive (to check for link pollution), - * o a useful tool for space-constrained systems (boot floppies, etc), - * o a place to experiment with new implementation ideas for bsdtar, - * o a small program to demonstrate libarchive usage. - * - * Use the following macros to suppress features: - * NO_BZIP2 - Implies NO_BZIP2_CREATE and NO_BZIP2_EXTRACT - * NO_BZIP2_CREATE - Suppress bzip2 compression support. - * NO_BZIP2_EXTRACT - Suppress bzip2 auto-detection and decompression. - * NO_COMPRESS - Implies NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT - * NO_COMPRESS_CREATE - Suppress compress(1) compression support - * NO_COMPRESS_EXTRACT - Suppress compress(1) auto-detect and decompression. - * NO_CREATE - Suppress all archive creation support. - * NO_CPIO_EXTRACT - Suppress auto-detect and dearchiving of cpio archives. - * NO_GZIP - Implies NO_GZIP_CREATE and NO_GZIP_EXTRACT - * NO_GZIP_CREATE - Suppress gzip compression support. - * NO_GZIP_EXTRACT - Suppress gzip auto-detection and decompression. - * NO_LOOKUP - Try to avoid getpw/getgr routines, which can be very large - * NO_TAR_EXTRACT - Suppress tar extraction - * - * With all of the above macros defined (except NO_TAR_EXTRACT), you - * get a very small program that can recognize and extract essentially - * any uncompressed tar archive. On FreeBSD 5.1, this minimal program - * is under 64k, statically linked, which compares rather favorably to - * main(){printf("hello, world");} - * which is over 60k statically linked on the same operating system. - * Without any of the above macros, you get a static executable of - * about 180k with a lot of very sophisticated modern features. - * Obviously, it's trivial to add support for ISO, Zip, mtree, - * lzma/xz, etc. Just fill in the appropriate setup calls. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifndef NO_CREATE -#include "tree.h" -#endif - -/* - * NO_CREATE implies NO_BZIP2_CREATE and NO_GZIP_CREATE and NO_COMPRESS_CREATE. - */ -#ifdef NO_CREATE -#undef NO_BZIP2_CREATE -#define NO_BZIP2_CREATE -#undef NO_COMPRESS_CREATE -#define NO_COMPRESS_CREATE -#undef NO_GZIP_CREATE -#define NO_GZIP_CREATE -#endif - -/* - * The combination of NO_BZIP2_CREATE and NO_BZIP2_EXTRACT is - * equivalent to NO_BZIP2. - */ -#ifdef NO_BZIP2_CREATE -#ifdef NO_BZIP2_EXTRACT -#undef NO_BZIP2 -#define NO_BZIP2 -#endif -#endif - -#ifdef NO_BZIP2 -#undef NO_BZIP2_EXTRACT -#define NO_BZIP2_EXTRACT -#undef NO_BZIP2_CREATE -#define NO_BZIP2_CREATE -#endif - -/* - * The combination of NO_COMPRESS_CREATE and NO_COMPRESS_EXTRACT is - * equivalent to NO_COMPRESS. - */ -#ifdef NO_COMPRESS_CREATE -#ifdef NO_COMPRESS_EXTRACT -#undef NO_COMPRESS -#define NO_COMPRESS -#endif -#endif - -#ifdef NO_COMPRESS -#undef NO_COMPRESS_EXTRACT -#define NO_COMPRESS_EXTRACT -#undef NO_COMPRESS_CREATE -#define NO_COMPRESS_CREATE -#endif - -/* - * The combination of NO_GZIP_CREATE and NO_GZIP_EXTRACT is - * equivalent to NO_GZIP. - */ -#ifdef NO_GZIP_CREATE -#ifdef NO_GZIP_EXTRACT -#undef NO_GZIP -#define NO_GZIP -#endif -#endif - -#ifdef NO_GZIP -#undef NO_GZIP_EXTRACT -#define NO_GZIP_EXTRACT -#undef NO_GZIP_CREATE -#define NO_GZIP_CREATE -#endif - -#ifndef NO_CREATE -static void create(const char *filename, int compress, const char **argv); -#endif -static void errmsg(const char *); -static void extract(const char *filename, int do_extract, int flags); -static int copy_data(struct archive *, struct archive *); -static void msg(const char *); -static void usage(void); - -static int verbose = 0; - -int -main(int argc, const char **argv) -{ - const char *filename = NULL; - int compress, flags, mode, opt; - - (void)argc; - mode = 'x'; - verbose = 0; - compress = '\0'; - flags = ARCHIVE_EXTRACT_TIME; - - /* Among other sins, getopt(3) pulls in printf(3). */ - while (*++argv != NULL && **argv == '-') { - const char *p = *argv + 1; - - while ((opt = *p++) != '\0') { - switch (opt) { -#ifndef NO_CREATE - case 'c': - mode = opt; - break; -#endif - case 'f': - if (*p != '\0') - filename = p; - else - filename = *++argv; - p += strlen(p); - break; -#ifndef NO_BZIP2_CREATE - case 'j': - compress = opt; - break; -#endif - case 'p': - flags |= ARCHIVE_EXTRACT_PERM; - flags |= ARCHIVE_EXTRACT_ACL; - flags |= ARCHIVE_EXTRACT_FFLAGS; - break; - case 't': - mode = opt; - break; - case 'v': - verbose++; - break; - case 'x': - mode = opt; - break; -#ifndef NO_BZIP2_CREATE - case 'y': - compress = opt; - break; -#endif -#ifndef NO_COMPRESS_CREATE - case 'Z': - compress = opt; - break; -#endif -#ifndef NO_GZIP_CREATE - case 'z': - compress = opt; - break; -#endif - default: - usage(); - } - } - } - - switch (mode) { -#ifndef NO_CREATE - case 'c': - create(filename, compress, argv); - break; -#endif - case 't': - extract(filename, 0, flags); - break; - case 'x': - extract(filename, 1, flags); - break; - } - - return (0); -} - - -#ifndef NO_CREATE -static char buff[16384]; - -static void -create(const char *filename, int compress, const char **argv) -{ - struct archive *a; - struct archive *disk; - struct archive_entry *entry; - ssize_t len; - int fd; - - a = archive_write_new(); - switch (compress) { -#ifndef NO_BZIP2_CREATE - case 'j': case 'y': - archive_write_set_compression_bzip2(a); - break; -#endif -#ifndef NO_COMPRESS_CREATE - case 'Z': - archive_write_set_compression_compress(a); - break; -#endif -#ifndef NO_GZIP_CREATE - case 'z': - archive_write_set_compression_gzip(a); - break; -#endif - default: - archive_write_set_compression_none(a); - break; - } - archive_write_set_format_ustar(a); - if (strcmp(filename, "-") == 0) - filename = NULL; - archive_write_open_file(a, filename); - - disk = archive_read_disk_new(); -#ifndef NO_LOOKUP - archive_read_disk_set_standard_lookup(disk); -#endif - while (*argv != NULL) { - struct tree *t = tree_open(*argv); - while (tree_next(t)) { - entry = archive_entry_new(); - archive_entry_set_pathname(entry, tree_current_path(t)); - archive_read_disk_entry_from_file(disk, entry, -1, - tree_current_stat(t)); - if (verbose) { - msg("a "); - msg(tree_current_path(t)); - } - archive_write_header(a, entry); - fd = open(tree_current_access_path(t), O_RDONLY); - len = read(fd, buff, sizeof(buff)); - while (len > 0) { - archive_write_data(a, buff, len); - len = read(fd, buff, sizeof(buff)); - } - close(fd); - archive_entry_free(entry); - if (verbose) - msg("\n"); - } - argv++; - } - archive_write_close(a); - archive_write_finish(a); -} -#endif - -static void -extract(const char *filename, int do_extract, int flags) -{ - struct archive *a; - struct archive *ext; - struct archive_entry *entry; - int r; - - a = archive_read_new(); - ext = archive_write_disk_new(); - archive_write_disk_set_options(ext, flags); -#ifndef NO_BZIP2_EXTRACT - archive_read_support_compression_bzip2(a); -#endif -#ifndef NO_GZIP_EXTRACT - archive_read_support_compression_gzip(a); -#endif -#ifndef NO_COMPRESS_EXTRACT - archive_read_support_compression_compress(a); -#endif -#ifndef NO_TAR_EXTRACT - archive_read_support_format_tar(a); -#endif -#ifndef NO_CPIO_EXTRACT - archive_read_support_format_cpio(a); -#endif -#ifndef NO_LOOKUP - archive_write_disk_set_standard_lookup(ext); -#endif - if (filename != NULL && strcmp(filename, "-") == 0) - filename = NULL; - if ((r = archive_read_open_file(a, filename, 10240))) { - errmsg(archive_error_string(a)); - errmsg("\n"); - exit(r); - } - for (;;) { - r = archive_read_next_header(a, &entry); - if (r == ARCHIVE_EOF) - break; - if (r != ARCHIVE_OK) { - errmsg(archive_error_string(a)); - errmsg("\n"); - exit(1); - } - if (verbose && do_extract) - msg("x "); - if (verbose || !do_extract) - msg(archive_entry_pathname(entry)); - if (do_extract) { - r = archive_write_header(ext, entry); - if (r != ARCHIVE_OK) - errmsg(archive_error_string(a)); - else - copy_data(a, ext); - } - if (verbose || !do_extract) - msg("\n"); - } - archive_read_close(a); - archive_read_finish(a); - exit(0); -} - -static int -copy_data(struct archive *ar, struct archive *aw) -{ - int r; - const void *buff; - size_t size; - off_t offset; - - for (;;) { - r = archive_read_data_block(ar, &buff, &size, &offset); - if (r == ARCHIVE_EOF) { - errmsg(archive_error_string(ar)); - return (ARCHIVE_OK); - } - if (r != ARCHIVE_OK) - return (r); - r = archive_write_data_block(aw, buff, size, offset); - if (r != ARCHIVE_OK) { - errmsg(archive_error_string(ar)); - return (r); - } - } -} - -static void -msg(const char *m) -{ - write(1, m, strlen(m)); -} - -static void -errmsg(const char *m) -{ - write(2, m, strlen(m)); -} - -static void -usage(void) -{ -/* Many program options depend on compile options. */ - const char *m = "Usage: minitar [-" -#ifndef NO_CREATE - "c" -#endif -#ifndef NO_BZIP2 - "j" -#endif - "tvx" -#ifndef NO_BZIP2 - "y" -#endif -#ifndef NO_COMPRESS - "Z" -#endif -#ifndef NO_GZIP - "z" -#endif - "] [-f file] [file]\n"; - - errmsg(m); - exit(1); -} diff --git a/Utilities/cmlibarchive/examples/minitar/notes b/Utilities/cmlibarchive/examples/minitar/notes deleted file mode 100644 index 79728d4e5..000000000 --- a/Utilities/cmlibarchive/examples/minitar/notes +++ /dev/null @@ -1,50 +0,0 @@ -create(const char* filename) -{ - struct archive *a; - a = archive_write_new(); -// pick a compression type - archive_write_set_compression_bzip2(a); - archive_write_set_compression_compress(a); - archive_write_set_compression_gzip(a); - archive_write_set_compression_none(a); - -// what does this do??? - archive_write_set_format_ustar(a); // is this what we want? -// maybe this: - archive_write_set_format_pax(a); - - archive_write_open_file(a, filename); - - struct archive* disk = archive_read_disk_new(); - archive_read_disk_set_standard_lookup(disk); - while (*argv != NULL) - { - struct tree *t = tree_open(*argv); - while (tree_next(t)) - { - entry = archive_entry_new(); - archive_entry_set_pathname(entry, tree_current_path(t)); - archive_read_disk_entry_from_file(disk, entry, -1, - tree_current_stat(t)); - if (verbose) - { - msg("a "); - msg(tree_current_path(t)); - } - archive_write_header(a, entry); - int fd = open(tree_current_access_path(t), O_RDONLY); - char buff[16384]; - len = read(fd, buff, sizeof(buff)); - while (len > 0) - { - archive_write_data(a, buff, len); - len = read(fd, buff, sizeof(buff)); - } - close(fd); - archive_entry_free(entry); - if (verbose) - msg("\n"); - } - } - -} diff --git a/Utilities/cmlibarchive/examples/minitar/tree.c b/Utilities/cmlibarchive/examples/minitar/tree.c deleted file mode 100644 index ae92635f6..000000000 --- a/Utilities/cmlibarchive/examples/minitar/tree.c +++ /dev/null @@ -1,423 +0,0 @@ -/*- - * Copyright (c) 2003-2004 Tim Kientzle - * 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 - * in this position and unchanged. - * 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. - */ - -/*- - * There is a single list of "tree_entry" items that represent - * filesystem objects that require further attention. Non-directories - * are not kept in memory: they are pulled from readdir(), returned to - * the client, then freed as soon as possible. Any directory entry to - * be traversed gets pushed onto the stack. - * - * There is surprisingly little information that needs to be kept for - * each item on the stack. Just the name, depth (represented here as the - * string length of the parent directory's pathname), and some markers - * indicating how to get back to the parent (via chdir("..") for a - * regular dir or via fchdir(2) for a symlink). - */ - -#include -#include -#include -#include -#include -#include - -#include "tree.h" - -/* - * TODO: - * 1) Loop checking. - * 3) Arbitrary logical traversals by closing/reopening intermediate fds. - */ - -struct tree_entry { - struct tree_entry *next; - char *name; - size_t dirname_length; - int fd; - int flags; -}; - -/* Definitions for tree_entry.flags bitmap. */ -#define isDir 1 /* This entry is a regular directory. */ -#define isDirLink 2 /* This entry is a symbolic link to a directory. */ -#define needsTraversal 4 /* This entry hasn't yet been traversed. */ - -/* - * Local data for this package. - */ -struct tree { - struct tree_entry *stack; - DIR *d; - int initialDirFd; - int flags; - - char *buff; - char *basename; - size_t buff_length; - size_t path_length; - size_t dirname_length; - - int depth; - int openCount; - int maxOpenCount; - - struct stat lst; - struct stat st; -}; - -/* Definitions for tree.flags bitmap. */ -#define needsReturn 8 /* Marks first entry as not having been returned yet. */ -#define hasStat 16 /* The st entry is set. */ -#define hasLstat 32 /* The lst entry is set. */ - - -#define HAVE_DIRENT_D_NAMLEN 1 -#ifdef HAVE_DIRENT_D_NAMLEN -/* BSD extension; avoids need for a strlen() call. */ -#define D_NAMELEN(dp) (dp)->d_namlen -#else -#define D_NAMELEN(dp) (strlen((dp)->d_name)) -#endif - -#if 0 -static void -dumpStack(struct tree *t) -{ - struct tree_entry *te; - - printf("\tbuff: %s\n", t->buff); - printf("\tpwd: "); fflush(stdout); system("pwd"); - printf("\tstack:\n"); - for (te = t->stack; te != NULL; te = te->next) { - printf("\t\tte->name: %s %s\n", te->name, te->flags & needsTraversal ? "" : "*"); - } -} -#endif - -/* - * Add a directory path to the current stack. - */ -static void -tree_add(struct tree *t, const char *path) -{ - struct tree_entry *te; - - te = malloc(sizeof(*te)); - memset(te, 0, sizeof(*te)); - te->next = t->stack; - t->stack = te; - te->fd = -1; - te->name = strdup(path); - te->flags = needsTraversal; - te->dirname_length = t->dirname_length; -} - -/* - * Append a name to the current path. - */ -static void -tree_append(struct tree *t, const char *name, size_t name_length) -{ - if (t->buff != NULL) - t->buff[t->dirname_length] = '\0'; - - /* Resize pathname buffer as needed. */ - while (name_length + 1 + t->dirname_length >= t->buff_length) { - t->buff_length *= 2; - if (t->buff_length < 1024) - t->buff_length = 1024; - t->buff = realloc(t->buff, t->buff_length); - } - t->basename = t->buff + t->dirname_length; - t->path_length = t->dirname_length + name_length; - if (t->dirname_length > 0) { - *t->basename++ = '/'; - t->path_length ++; - } - strcpy(t->basename, name); -} - -/* - * Open a directory tree for traversal. - */ -struct tree * -tree_open(const char *path) -{ - struct tree *t; - - t = malloc(sizeof(*t)); - memset(t, 0, sizeof(*t)); - tree_append(t, path, strlen(path)); - t->initialDirFd = open(".", O_RDONLY); - /* - * During most of the traversal, items are set up and then - * returned immediately from tree_next(). That doesn't work - * for the very first entry, so we set a flag for this special - * case. - */ - t->flags = needsReturn; - return (t); -} - -/* - * We've finished a directory; ascend back to the parent. - */ -static void -tree_ascend(struct tree *t) -{ - struct tree_entry *te; - - te = t->stack; - t->depth--; - if (te->flags & isDirLink) { - fchdir(te->fd); - close(te->fd); - t->openCount--; - } else { - chdir(".."); - } -} - -/* - * Pop the working stack. - */ -static void -tree_pop(struct tree *t) -{ - struct tree_entry *te; - - te = t->stack; - t->stack = te->next; - t->dirname_length = te->dirname_length; - free(te->name); - free(te); -} - -/* - * Get the next item in the tree traversal. - */ -int -tree_next(struct tree *t) -{ - struct dirent *de = NULL; - - /* Handle the startup case by returning the initial entry. */ - if (t->flags & needsReturn) { - t->flags &= ~needsReturn; - return (1); - } - - while (t->stack != NULL) { - /* If there's an open dir, get the next entry from there. */ - while (t->d != NULL) { - de = readdir(t->d); - if (de == NULL) { - closedir(t->d); - t->d = NULL; - } else if (de->d_name[0] == '.' - && de->d_name[1] == '\0') { - /* Skip '.' */ - } else if (de->d_name[0] == '.' - && de->d_name[1] == '.' - && de->d_name[2] == '\0') { - /* Skip '..' */ - } else { - /* - * Append the path to the current path - * and return it. - */ - tree_append(t, de->d_name, D_NAMELEN(de)); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - return (1); - } - } - - /* If the current dir needs to be traversed, set it up. */ - if (t->stack->flags & needsTraversal) { - tree_append(t, t->stack->name, strlen(t->stack->name)); - t->stack->flags &= ~needsTraversal; - /* If it is a link, set up fd for the ascent. */ - if (t->stack->flags & isDirLink) { - t->stack->fd = open(".", O_RDONLY); - t->openCount++; - if (t->openCount > t->maxOpenCount) - t->maxOpenCount = t->openCount; - } - if (chdir(t->stack->name) == 0) { - t->depth++; - t->dirname_length = t->path_length; - t->d = opendir("."); - } else - tree_pop(t); - continue; - } - - /* We've done everything necessary for the top stack entry. */ - tree_ascend(t); - tree_pop(t); - } - return (0); -} - -/* - * Called by the client to mark the directory just returned from - * tree_next() as needing to be visited. - */ -void -tree_descend(struct tree *t) -{ - const struct stat *s = tree_current_lstat(t); - - if (S_ISDIR(s->st_mode)) { - tree_add(t, t->basename); - t->stack->flags |= isDir; - } - - if (S_ISLNK(s->st_mode) && S_ISDIR(tree_current_stat(t)->st_mode)) { - tree_add(t, t->basename); - t->stack->flags |= isDirLink; - } -} - -/* - * Get the stat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_stat(struct tree *t) -{ - if (!(t->flags & hasStat)) { - stat(t->basename, &t->st); - t->flags |= hasStat; - } - return (&t->st); -} - -/* - * Get the lstat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_lstat(struct tree *t) -{ - if (!(t->flags & hasLstat)) { - lstat(t->basename, &t->lst); - t->flags |= hasLstat; - } - return (&t->lst); -} - -/* - * Return the access path for the entry just returned from tree_next(). - */ -const char * -tree_current_access_path(struct tree *t) -{ - return (t->basename); -} - -/* - * Return the full path for the entry just returned from tree_next(). - */ -const char * -tree_current_path(struct tree *t) -{ - return (t->buff); -} - -/* - * Return the length of the path for the entry just returned from tree_next(). - */ -size_t -tree_current_pathlen(struct tree *t) -{ - return (t->path_length); -} - -/* - * Return the nesting depth of the entry just returned from tree_next(). - */ -int -tree_current_depth(struct tree *t) -{ - return (t->depth); -} - -/* - * Terminate the traversal and release any resources. - */ -void -tree_close(struct tree *t) -{ - /* Release anything remaining in the stack. */ - while (t->stack != NULL) - tree_pop(t); - if (t->buff) - free(t->buff); - /* chdir() back to where we started. */ - if (t->initialDirFd >= 0) { - fchdir(t->initialDirFd); - close(t->initialDirFd); - t->initialDirFd = -1; - } - free(t); -} - - -#if 0 -/* Main function for testing. */ -#include - -int main(int argc, char **argv) -{ - size_t max_path_len = 0; - int max_depth = 0; - - system("pwd"); - while (*++argv) { - struct tree *t = tree_open(*argv); - while (tree_next(t)) { - size_t path_len = tree_current_pathlen(t); - int depth = tree_current_depth(t); - if (path_len > max_path_len) - max_path_len = path_len; - if (depth > max_depth) - max_depth = depth; - printf("%s\n", tree_current_path(t)); - if (S_ISDIR(tree_current_lstat(t)->st_mode)) - tree_descend(t); /* Descend into every dir. */ - } - tree_close(t); - printf("Max path length: %d\n", max_path_len); - printf("Max depth: %d\n", max_depth); - printf("Final open count: %d\n", t->openCount); - printf("Max open count: %d\n", t->maxOpenCount); - fflush(stdout); - system("pwd"); - } - return (0); -} -#endif diff --git a/Utilities/cmlibarchive/examples/minitar/tree.h b/Utilities/cmlibarchive/examples/minitar/tree.h deleted file mode 100644 index 554e6c2da..000000000 --- a/Utilities/cmlibarchive/examples/minitar/tree.h +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 2003-2004 Tim Kientzle - * 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 - * in this position and unchanged. - * 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. - */ - -/*- - * A set of routines for traversing directory trees. - * Similar in concept to the fts library, but with a few - * important differences: - * * Uses less memory. In particular, fts stores an entire directory - * in memory at a time. This package only keeps enough subdirectory - * information in memory to track the traversal. Information - * about non-directories is discarded as soon as possible. - * * Supports very deep logical traversals. The fts package - * uses "non-chdir" approach for logical traversals. This - * package does use a chdir approach for logical traversals - * and can therefore handle pathnames much longer than - * PATH_MAX. - * * Supports deep physical traversals "out of the box." - * Due to the memory optimizations above, there's no need to - * limit dir names to 32k. - */ - -#include - -struct tree; - -struct tree *tree_open(const char *); -/* Returns TRUE if there is a next entry. Zero if there is no next entry. */ -int tree_next(struct tree *); -/* Return information about the current entry. */ -int tree_current_depth(struct tree *); -/* - * The current full pathname, length of the full pathname, - * and a name that can be used to access the file. - * Because tree does use chdir extensively, the access path is - * almost never the same as the full current path. - */ -const char *tree_current_path(struct tree *); -size_t tree_current_pathlen(struct tree *); -const char *tree_current_access_path(struct tree *); -/* - * Request the lstat() or stat() data for the current path. - * Since the tree package needs to do some of this anyway, - * you should take advantage of it here if you need it. - */ -const struct stat *tree_current_stat(struct tree *); -const struct stat *tree_current_lstat(struct tree *); -/* - * Request that current entry be visited. If you invoke it on every - * directory, you'll get a physical traversal. This is ignored if the - * current entry isn't a directory or a link to a directory. So, if - * you invoke this on every returned path, you'll get a full logical - * traversal. - */ -void tree_descend(struct tree *); -void tree_close(struct tree *); diff --git a/Utilities/cmlibarchive/examples/tarfilter.c b/Utilities/cmlibarchive/examples/tarfilter.c deleted file mode 100644 index 9097d1259..000000000 --- a/Utilities/cmlibarchive/examples/tarfilter.c +++ /dev/null @@ -1,113 +0,0 @@ -/* - * This file is in the public domain. - * - * Feel free to use it as you wish. - */ - -/* - * This example program reads an archive from stdin (which can be in - * any format recognized by libarchive) and writes certain entries to - * an uncompressed ustar archive on stdout. This is a template for - * many kinds of archive manipulation: converting formats, resetting - * ownership, inserting entries, removing entries, etc. - * - * To compile: - * gcc -Wall -o tarfilter tarfilter.c -larchive -lz -lbz2 - */ - -#include -#include -#include -#include -#include -#include - -static void -die(char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - exit(1); -} - -int -main(int argc, char **argv) -{ - char buff[8192]; - ssize_t len; - int r; - mode_t m; - struct archive *ina; - struct archive *outa; - struct archive_entry *entry; - - /* Read an archive from stdin, with automatic format detection. */ - ina = archive_read_new(); - if (ina == NULL) - die("Couldn't create archive reader."); - if (archive_read_support_compression_all(ina) != ARCHIVE_OK) - die("Couldn't enable decompression"); - if (archive_read_support_format_all(ina) != ARCHIVE_OK) - die("Couldn't enable read formats"); - if (archive_read_open_fd(ina, 0, 10240) != ARCHIVE_OK) - die("Couldn't open input archive"); - - /* Write an uncompressed ustar archive to stdout. */ - outa = archive_write_new(); - if (outa == NULL) - die("Couldn't create archive writer."); - if (archive_write_set_compression_none(outa) != ARCHIVE_OK) - die("Couldn't enable compression"); - if (archive_write_set_format_ustar(outa) != ARCHIVE_OK) - die("Couldn't set output format"); - if (archive_write_open_fd(outa, 1) != ARCHIVE_OK) - die("Couldn't open output archive"); - - /* Examine each entry in the input archive. */ - while ((r = archive_read_next_header(ina, &entry)) == ARCHIVE_OK) { - fprintf(stderr, "%s: ", archive_entry_pathname(entry)); - - /* Skip anything that isn't a regular file. */ - if (!S_ISREG(archive_entry_mode(entry))) { - fprintf(stderr, "skipped\n"); - continue; - } - - /* Make everything owned by root/wheel. */ - archive_entry_set_uid(entry, 0); - archive_entry_set_uname(entry, "root"); - archive_entry_set_gid(entry, 0); - archive_entry_set_gname(entry, "wheel"); - - /* Make everything permission 0744, strip SUID, etc. */ - m = archive_entry_mode(entry); - archive_entry_set_mode(entry, (m & ~07777) | 0744); - - /* Copy input entries to output archive. */ - if (archive_write_header(outa, entry) != ARCHIVE_OK) - die("Error writing output archive"); - if (archive_entry_size(entry) > 0) { - len = archive_read_data(ina, buff, sizeof(buff)); - while (len > 0) { - if (archive_write_data(outa, buff, len) != len) - die("Error writing output archive"); - len = archive_read_data(ina, buff, sizeof(buff)); - } - if (len < 0) - die("Error reading input archive"); - } - fprintf(stderr, "copied\n"); - } - if (r != ARCHIVE_EOF) - die("Error reading archive"); - /* Close the archives. */ - if (archive_read_finish(ina) != ARCHIVE_OK) - die("Error closing input archive"); - if (archive_write_finish(outa) != ARCHIVE_OK) - die("Error closing output archive"); - return (0); -} diff --git a/Utilities/cmlibarchive/examples/untar.c b/Utilities/cmlibarchive/examples/untar.c deleted file mode 100644 index f0d54c216..000000000 --- a/Utilities/cmlibarchive/examples/untar.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * This file is in the public domain. - * Use it as you wish. - */ - -/* - * This is a compact tar extraction program using libarchive whose - * primary goal is small executable size. Statically linked, it can - * be very small, depending in large part on how cleanly factored your - * system libraries are. Note that this uses the standard libarchive, - * without any special recompilation. The only functional concession - * is that this program uses the uid/gid from the archive instead of - * doing uname/gname lookups. (Add a call to - * archive_write_disk_set_standard_lookup() to enable uname/gname - * lookups, but be aware that this can add 500k or more to a static - * executable, depending on the system libraries, since user/group - * lookups frequently pull in password, YP/LDAP, networking, and DNS - * resolver libraries.) - * - * To build: - * $ gcc -static -Wall -o untar untar.c -larchive - * $ strip untar - * - * NOTE: On some systems, you may need to add additional flags - * to ensure that untar.c is compiled the same way as libarchive - * was compiled. In particular, Linux users will probably - * have to add -D_FILE_OFFSET_BITS=64 to the command line above. - * - * For fun, statically compile the following simple hello.c program - * using the same flags as for untar and compare the size: - * - * #include - * int main(int argc, char **argv) { - * printf("hello, world\n"); - * return(0); - * } - * - * You may be even more surprised by the compiled size of true.c listed here: - * - * int main(int argc, char **argv) { - * return (0); - * } - * - * On a slightly customized FreeBSD 5 system that I used around - * 2005, hello above compiled to 89k compared to untar of 69k. So at - * that time, libarchive's tar reader and extract-to-disk routines - * compiled to less code than printf(). - * - * On my FreeBSD development system today (August, 2009): - * hello: 195024 bytes - * true: 194912 bytes - * untar: 259924 bytes - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -#include -#include -#include -#include -#include -#include -#include - -static void errmsg(const char *); -static void extract(const char *filename, int do_extract, int flags); -static void fail(const char *, const char *, int); -static int copy_data(struct archive *, struct archive *); -static void msg(const char *); -static void usage(void); -static void warn(const char *, const char *); - -static int verbose = 0; - -int -main(int argc, const char **argv) -{ - const char *filename = NULL; - int compress, flags, mode, opt; - - (void)argc; - mode = 'x'; - verbose = 0; - compress = '\0'; - flags = ARCHIVE_EXTRACT_TIME; - - /* Among other sins, getopt(3) pulls in printf(3). */ - while (*++argv != NULL && **argv == '-') { - const char *p = *argv + 1; - - while ((opt = *p++) != '\0') { - switch (opt) { - case 'f': - if (*p != '\0') - filename = p; - else - filename = *++argv; - p += strlen(p); - break; - case 'p': - flags |= ARCHIVE_EXTRACT_PERM; - flags |= ARCHIVE_EXTRACT_ACL; - flags |= ARCHIVE_EXTRACT_FFLAGS; - break; - case 't': - mode = opt; - break; - case 'v': - verbose++; - break; - case 'x': - mode = opt; - break; - default: - usage(); - } - } - } - - switch (mode) { - case 't': - extract(filename, 0, flags); - break; - case 'x': - extract(filename, 1, flags); - break; - } - - return (0); -} - - -static void -extract(const char *filename, int do_extract, int flags) -{ - struct archive *a; - struct archive *ext; - struct archive_entry *entry; - int r; - - a = archive_read_new(); - ext = archive_write_disk_new(); - archive_write_disk_set_options(ext, flags); - /* - * Note: archive_write_disk_set_standard_lookup() is useful - * here, but it requires library routines that can add 500k or - * more to a static executable. - */ - archive_read_support_format_tar(a); - /* - * On my system, enabling other archive formats adds 20k-30k - * each. Enabling gzip decompression adds about 20k. - * Enabling bzip2 is more expensive because the libbz2 library - * isn't very well factored. - */ - if (filename != NULL && strcmp(filename, "-") == 0) - filename = NULL; - if ((r = archive_read_open_file(a, filename, 10240))) - fail("archive_read_open_file()", - archive_error_string(a), r); - for (;;) { - r = archive_read_next_header(a, &entry); - if (r == ARCHIVE_EOF) - break; - if (r != ARCHIVE_OK) - fail("archive_read_next_header()", - archive_error_string(a), 1); - if (verbose && do_extract) - msg("x "); - if (verbose || !do_extract) - msg(archive_entry_pathname(entry)); - if (do_extract) { - r = archive_write_header(ext, entry); - if (r != ARCHIVE_OK) - warn("archive_write_header()", - archive_error_string(ext)); - else { - copy_data(a, ext); - r = archive_write_finish_entry(ext); - if (r != ARCHIVE_OK) - fail("archive_write_finish_entry()", - archive_error_string(ext), 1); - } - - } - if (verbose || !do_extract) - msg("\n"); - } - archive_read_close(a); - archive_read_finish(a); - exit(0); -} - -static int -copy_data(struct archive *ar, struct archive *aw) -{ - int r; - const void *buff; - size_t size; - off_t offset; - - for (;;) { - r = archive_read_data_block(ar, &buff, &size, &offset); - if (r == ARCHIVE_EOF) - return (ARCHIVE_OK); - if (r != ARCHIVE_OK) - return (r); - r = archive_write_data_block(aw, buff, size, offset); - if (r != ARCHIVE_OK) { - warn("archive_write_data_block()", - archive_error_string(aw)); - return (r); - } - } -} - -/* - * These reporting functions use low-level I/O; on some systems, this - * is a significant code reduction. Of course, on many server and - * desktop operating systems, malloc() and even crt rely on printf(), - * which in turn pulls in most of the rest of stdio, so this is not an - * optimization at all there. (If you're going to pay 100k or more - * for printf() anyway, you may as well use it!) - */ -static void -msg(const char *m) -{ - write(1, m, strlen(m)); -} - -static void -errmsg(const char *m) -{ - write(2, m, strlen(m)); -} - -static void -warn(const char *f, const char *m) -{ - errmsg(f); - errmsg(" failed: "); - errmsg(m); - errmsg("\n"); -} - -static void -fail(const char *f, const char *m, int r) -{ - warn(f, m); - exit(r); -} - -static void -usage(void) -{ - const char *m = "Usage: untar [-tvx] [-f file] [file]\n"; - errmsg(m); - exit(1); -} diff --git a/Utilities/cmlibarchive/libarchive/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/CMakeLists.txt index 7bc8eadcb..738419597 100644 --- a/Utilities/cmlibarchive/libarchive/CMakeLists.txt +++ b/Utilities/cmlibarchive/libarchive/CMakeLists.txt @@ -13,23 +13,34 @@ SET(include_HEADERS # Sources and private headers SET(libarchive_SOURCES + archive_acl.c archive_check_magic.c + archive_crypto.c + archive_crypto_private.h archive_endian.h archive_entry.c archive_entry.h archive_entry_copy_stat.c -# archive_entry_copy_bhfi.c archive_entry_link_resolver.c + archive_entry_locale.h archive_entry_private.h + archive_entry_sparse.c archive_entry_stat.c archive_entry_strmode.c archive_entry_xattr.c + archive_options.c + archive_options_private.h archive_platform.h + archive_ppmd_private.h + archive_ppmd7.c + archive_ppmd7_private.h archive_private.h + archive_rb.c + archive_rb.h archive_read.c archive_read_data_into_fd.c - archive_read_disk.c archive_read_disk_entry_from_file.c + archive_read_disk_posix.c archive_read_disk_private.h archive_read_disk_set_standard_lookup.c archive_read_extract.c @@ -38,29 +49,39 @@ SET(libarchive_SOURCES archive_read_open_filename.c archive_read_open_memory.c archive_read_private.h - archive_read_support_compression_all.c - archive_read_support_compression_bzip2.c - archive_read_support_compression_compress.c - archive_read_support_compression_gzip.c - archive_read_support_compression_none.c - archive_read_support_compression_program.c - archive_read_support_compression_xz.c + archive_read_set_options.c + archive_read_support_filter_all.c + archive_read_support_filter_bzip2.c + archive_read_support_filter_compress.c + archive_read_support_filter_gzip.c + archive_read_support_filter_none.c + archive_read_support_filter_program.c + archive_read_support_filter_rpm.c + archive_read_support_filter_uu.c + archive_read_support_filter_xz.c + archive_read_support_format_7zip.c archive_read_support_format_all.c archive_read_support_format_ar.c + archive_read_support_format_by_code.c + archive_read_support_format_cab.c archive_read_support_format_cpio.c archive_read_support_format_empty.c archive_read_support_format_iso9660.c + archive_read_support_format_lha.c archive_read_support_format_mtree.c + archive_read_support_format_rar.c archive_read_support_format_raw.c archive_read_support_format_tar.c + archive_read_support_format_xar.c archive_read_support_format_zip.c archive_string.c archive_string.h + archive_string_composition.h archive_string_sprintf.c archive_util.c archive_virtual.c archive_write.c - archive_write_disk.c + archive_write_disk_posix.c archive_write_disk_private.h archive_write_disk_set_standard_lookup.c archive_write_private.h @@ -68,22 +89,27 @@ SET(libarchive_SOURCES archive_write_open_file.c archive_write_open_filename.c archive_write_open_memory.c - archive_write_set_compression_bzip2.c - archive_write_set_compression_compress.c - archive_write_set_compression_gzip.c - archive_write_set_compression_none.c - archive_write_set_compression_program.c - archive_write_set_compression_xz.c + archive_write_add_filter_bzip2.c + archive_write_add_filter_compress.c + archive_write_add_filter_gzip.c + archive_write_add_filter_none.c + archive_write_add_filter_program.c + archive_write_add_filter_xz.c archive_write_set_format.c + archive_write_set_format_7zip.c archive_write_set_format_ar.c archive_write_set_format_by_name.c archive_write_set_format_cpio.c archive_write_set_format_cpio_newc.c + archive_write_set_format_gnutar.c + archive_write_set_format_iso9660.c archive_write_set_format_mtree.c archive_write_set_format_pax.c archive_write_set_format_shar.c archive_write_set_format_ustar.c + archive_write_set_format_xar.c archive_write_set_format_zip.c + archive_write_set_options.c filter_fork.c filter_fork.h ) @@ -91,11 +117,19 @@ SET(libarchive_SOURCES # Man pages SET(libarchive_MANS archive_entry.3 + archive_entry_acl.3 + archive_entry_linkify.3 + archive_entry_paths.3 + archive_entry_perms.3 + archive_entry_stat.3 + archive_entry_time.3 archive_read.3 archive_read_disk.3 + archive_read_set_options.3 archive_util.3 archive_write.3 archive_write_disk.3 + archive_write_set_options.3 cpio.5 libarchive.3 libarchive_internals.3 @@ -106,41 +140,13 @@ SET(libarchive_MANS IF(WIN32 AND NOT CYGWIN) LIST(APPEND libarchive_SOURCES archive_entry_copy_bhfi.c) + LIST(APPEND libarchive_SOURCES archive_read_disk_windows.c) LIST(APPEND libarchive_SOURCES archive_windows.c) LIST(APPEND libarchive_SOURCES archive_windows.h) + LIST(APPEND libarchive_SOURCES archive_write_disk_windows.c) LIST(APPEND libarchive_SOURCES filter_fork_windows.c) ENDIF(WIN32 AND NOT CYGWIN) -IF(BUILD_ARCHIVE_WITHIN_CMAKE) - # when building inside the CMake tree only use static - # and call the library cmlibarchive - ADD_LIBRARY(cmlibarchive STATIC ${libarchive_SOURCES} ${include_HEADERS}) - TARGET_LINK_LIBRARIES(cmlibarchive ${ADDITIONAL_LIBS}) -ELSE() - # Libarchive is a shared library - ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS}) - TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS}) - SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION}) - SET_TARGET_PROPERTIES(archive PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - - # archive_static is a static library - ADD_LIBRARY(archive_static STATIC ${libarchive_SOURCES} ${include_HEADERS}) - SET_TARGET_PROPERTIES(archive_static PROPERTIES COMPILE_DEFINITIONS - LIBARCHIVE_STATIC) - SET_TARGET_PROPERTIES(archive_static PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - # On Posix systems, libarchive.so and libarchive.a can co-exist. - IF(NOT WIN32 OR CYGWIN) - SET_TARGET_PROPERTIES(archive_static PROPERTIES OUTPUT_NAME archive) - ENDIF(NOT WIN32 OR CYGWIN) - - # How to install the libraries - INSTALL(TARGETS archive archive_static - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - INSTALL_MAN(${libarchive_MANS}) - INSTALL(FILES ${include_HEADERS} DESTINATION include) - ADD_SUBDIRECTORY(test) -ENDIF() +# CMake needs just one static "cmlibarchive" library. +ADD_LIBRARY(cmlibarchive STATIC ${libarchive_SOURCES} ${include_HEADERS}) +TARGET_LINK_LIBRARIES(cmlibarchive ${ADDITIONAL_LIBS}) diff --git a/Utilities/cmlibarchive/libarchive/archive.h b/Utilities/cmlibarchive/libarchive/archive.h index 8bc612f4b..9b6b1b0c2 100644 --- a/Utilities/cmlibarchive/libarchive/archive.h +++ b/Utilities/cmlibarchive/libarchive/archive.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,11 @@ */ #ifndef ARCHIVE_H_INCLUDED -#define ARCHIVE_H_INCLUDED +#define ARCHIVE_H_INCLUDED + +#include +#include /* for wchar_t */ +#include /* For FILE * */ /* * Note: archive.h is for use outside of libarchive; the configuration @@ -36,46 +40,46 @@ * platform macros. */ #if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 -# define __LA_STDINT_H -#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(__osf__) -# define __LA_STDINT_H +# include +#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__) +# include #endif -#include -#include /* Linux requires this for off_t */ -#ifdef __LA_STDINT_H -# include __LA_STDINT_H /* int64_t, etc. */ +/* Borland symbols are case-insensitive. This workaround only works + within CMake because we do not mix compilers. */ +#if defined(__BORLANDC__) +# define archive_read_open_FILE archive_read_open_FILE_ +# define archive_write_open_FILE archive_write_open_FILE_ #endif -#include /* For FILE * */ /* Get appropriate definitions of standard POSIX-style types. */ /* These should match the types used in 'struct stat' */ #if defined(_WIN32) && !defined(__CYGWIN__) -#define __LA_INT64_T __int64 +# define __LA_INT64_T __int64 # if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) -# define __LA_SSIZE_T ssize_t +# define __LA_SSIZE_T ssize_t # elif defined(_WIN64) -# define __LA_SSIZE_T __int64 +# define __LA_SSIZE_T __int64 # else -# define __LA_SSIZE_T long +# define __LA_SSIZE_T long # endif # if defined(__BORLANDC__) -# define __LA_UID_T uid_t -# define __LA_GID_T gid_t +# define __LA_UID_T uid_t +# define __LA_GID_T gid_t # else -# define __LA_UID_T short -# define __LA_GID_T short +# define __LA_UID_T short +# define __LA_GID_T short # endif #else -#include /* ssize_t, uid_t, and gid_t */ -#if defined(__osf__) -# define __LA_INT64_T long long -#else -# define __LA_INT64_T int64_t -#endif -#define __LA_SSIZE_T ssize_t -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t +# include /* ssize_t, uid_t, and gid_t */ +# if defined(_SCO_DS) || defined(__osf__) +# define __LA_INT64_T long long +# else +# define __LA_INT64_T int64_t +# endif +# define __LA_SSIZE_T ssize_t +# define __LA_UID_T uid_t +# define __LA_GID_T gid_t #endif /* @@ -86,15 +90,15 @@ #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) # ifdef __LIBARCHIVE_BUILD # ifdef __GNUC__ -# define __LA_DECL __attribute__((dllexport)) extern +# define __LA_DECL __attribute__((dllexport)) extern # else -# define __LA_DECL __declspec(dllexport) +# define __LA_DECL __declspec(dllexport) # endif # else # ifdef __GNUC__ -# define __LA_DECL __attribute__((dllimport)) extern +# define __LA_DECL # else -# define __LA_DECL __declspec(dllimport) +# define __LA_DECL __declspec(dllimport) # endif # endif #else @@ -102,6 +106,13 @@ # define __LA_DECL #endif +#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__) +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + #ifdef __cplusplus extern "C" { #endif @@ -120,49 +131,17 @@ extern "C" { * easy to compare versions at build time: for version a.b.c, the * version number is printf("%d%03d%03d",a,b,c). For example, if you * know your application requires version 2.12.108 or later, you can - * assert that ARCHIVE_VERSION >= 2012108. - * - * This single-number format was introduced with libarchive 1.9.0 in - * the libarchive 1.x family and libarchive 2.2.4 in the libarchive - * 2.x family. The following may be useful if you really want to do - * feature detection for earlier libarchive versions (which defined - * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead): - * - * #ifndef ARCHIVE_VERSION_NUMBER - * #define ARCHIVE_VERSION_NUMBER \ - * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) - * #endif + * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ -#define ARCHIVE_VERSION_NUMBER 2007900 -__LA_DECL int archive_version_number(void); +/* Note: Compiler will complain if this does not match archive_entry.h! */ +#define ARCHIVE_VERSION_NUMBER 3000002 +__LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.7.900a" -__LA_DECL const char * archive_version_string(void); - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* - * Deprecated; these are older names that will be removed in favor of - * the simpler definitions above. - */ -#define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER -__LA_DECL int archive_version_stamp(void); -#define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING -__LA_DECL const char * archive_version(void); -#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000) -__LA_DECL int archive_api_version(void); -#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000) -__LA_DECL int archive_api_feature(void); -#endif - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* This should never have been here in the first place. */ -/* Legacy of old tar assumptions, will be removed in libarchive 3.0. */ -#define ARCHIVE_BYTES_PER_RECORD 512 -#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240 -#endif +#define ARCHIVE_VERSION_STRING "libarchive 3.0.2" +__LA_DECL const char * archive_version_string(void); /* Declare our basic types. */ struct archive; @@ -173,14 +152,14 @@ struct archive_entry; * to retrieve details. Unless specified otherwise, all functions * that return 'int' use these codes. */ -#define ARCHIVE_EOF 1 /* Found end of archive. */ -#define ARCHIVE_OK 0 /* Operation was successful. */ -#define ARCHIVE_RETRY (-10) /* Retry might succeed. */ -#define ARCHIVE_WARN (-20) /* Partial success. */ +#define ARCHIVE_EOF 1 /* Found end of archive. */ +#define ARCHIVE_OK 0 /* Operation was successful. */ +#define ARCHIVE_RETRY (-10) /* Retry might succeed. */ +#define ARCHIVE_WARN (-20) /* Partial success. */ /* For example, if write_header "fails", then you can't push data. */ -#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ +#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ /* But if write_header is "fatal," then this archive is dead and useless. */ -#define ARCHIVE_FATAL (-30) /* No more operations are possible. */ +#define ARCHIVE_FATAL (-30) /* No more operations are possible. */ /* * As far as possible, archive_errno returns standard platform errno codes. @@ -190,11 +169,11 @@ struct archive_entry; * platform-dependent error code. */ /* Unrecognized or invalid file format. */ -/* #define ARCHIVE_ERRNO_FILE_FORMAT */ +/* #define ARCHIVE_ERRNO_FILE_FORMAT */ /* Illegal usage of the library. */ -/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ +/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ /* Unknown or unclassified error. */ -/* #define ARCHIVE_ERRNO_MISC */ +/* #define ARCHIVE_ERRNO_MISC */ /* * Callbacks are invoked to automatically read/skip/write/open/close the @@ -204,49 +183,59 @@ struct archive_entry; */ /* Returns pointer and size of next block of data from archive. */ -typedef __LA_SSIZE_T archive_read_callback(struct archive *, - void *_client_data, const void **_buffer); - -/* Skips at most request bytes from archive and returns the skipped amount */ -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* Libarchive 1.0 used ssize_t for the return, which is only 32 bits - * on most 32-bit platforms; not large enough. */ -typedef __LA_SSIZE_T archive_skip_callback(struct archive *, - void *_client_data, size_t request); -#elif ARCHIVE_VERSION_NUMBER < 3000000 -/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a - * few other platforms where off_t varies with build settings. */ -typedef off_t archive_skip_callback(struct archive *, - void *_client_data, off_t request); -#else -/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be - * 64 bits on every platform. */ -typedef __LA_INT64_T archive_skip_callback(struct archive *, - void *_client_data, __LA_INT64_T request); -#endif +typedef __LA_SSIZE_T archive_read_callback(struct archive *, + void *_client_data, const void **_buffer); + +/* Skips at most request bytes from archive and returns the skipped amount. + * This may skip fewer bytes than requested; it may even skip zero bytes. + * If you do skip fewer bytes than requested, libarchive will invoke your + * read callback and discard data as necessary to make up the full skip. + */ +typedef __LA_INT64_T archive_skip_callback(struct archive *, + void *_client_data, __LA_INT64_T request); + +/* Seeks to specified location in the file and returns the position. + * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h. + * Return ARCHIVE_FATAL if the seek fails for any reason. + */ +typedef __LA_INT64_T archive_seek_callback(struct archive *, + void *_client_data, __LA_INT64_T offset, int whence); /* Returns size actually written, zero on EOF, -1 on error. */ -typedef __LA_SSIZE_T archive_write_callback(struct archive *, - void *_client_data, - const void *_buffer, size_t _length); +typedef __LA_SSIZE_T archive_write_callback(struct archive *, + void *_client_data, + const void *_buffer, size_t _length); -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* Open callback is actually never needed; remove it in libarchive 3.0. */ -typedef int archive_open_callback(struct archive *, void *_client_data); -#endif +typedef int archive_open_callback(struct archive *, void *_client_data); -typedef int archive_close_callback(struct archive *, void *_client_data); +typedef int archive_close_callback(struct archive *, void *_client_data); /* - * Codes for archive_compression. + * Codes to identify various stream filters. */ -#define ARCHIVE_COMPRESSION_NONE 0 -#define ARCHIVE_COMPRESSION_GZIP 1 -#define ARCHIVE_COMPRESSION_BZIP2 2 -#define ARCHIVE_COMPRESSION_COMPRESS 3 -#define ARCHIVE_COMPRESSION_PROGRAM 4 -#define ARCHIVE_COMPRESSION_LZMA 5 -#define ARCHIVE_COMPRESSION_XZ 6 +#define ARCHIVE_FILTER_NONE 0 +#define ARCHIVE_FILTER_GZIP 1 +#define ARCHIVE_FILTER_BZIP2 2 +#define ARCHIVE_FILTER_COMPRESS 3 +#define ARCHIVE_FILTER_PROGRAM 4 +#define ARCHIVE_FILTER_LZMA 5 +#define ARCHIVE_FILTER_XZ 6 +#define ARCHIVE_FILTER_UU 7 +#define ARCHIVE_FILTER_RPM 8 +#define ARCHIVE_FILTER_LZIP 9 + +#if ARCHIVE_VERSION_NUMBER < 4000000 +#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE +#define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP +#define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2 +#define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS +#define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM +#define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA +#define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ +#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU +#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM +#define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP +#endif /* * Codes returned by archive_format. @@ -260,34 +249,40 @@ typedef int archive_close_callback(struct archive *, void *_client_data); * will change the format code to indicate the extended format that * was used). In other cases, it's because different tools have * modified the archive and so different parts of the archive - * actually have slightly different formts. (Both tar and cpio store + * actually have slightly different formats. (Both tar and cpio store * format codes in each entry, so it is quite possible for each * entry to be in a different format.) */ -#define ARCHIVE_FORMAT_BASE_MASK 0xff0000 -#define ARCHIVE_FORMAT_CPIO 0x10000 -#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) -#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) -#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) -#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) -#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) -#define ARCHIVE_FORMAT_SHAR 0x20000 -#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) -#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) -#define ARCHIVE_FORMAT_TAR 0x30000 -#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) -#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) -#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) -#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) -#define ARCHIVE_FORMAT_ISO9660 0x40000 -#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) -#define ARCHIVE_FORMAT_ZIP 0x50000 -#define ARCHIVE_FORMAT_EMPTY 0x60000 -#define ARCHIVE_FORMAT_AR 0x70000 -#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) -#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) -#define ARCHIVE_FORMAT_MTREE 0x80000 -#define ARCHIVE_FORMAT_RAW 0x90000 +#define ARCHIVE_FORMAT_BASE_MASK 0xff0000 +#define ARCHIVE_FORMAT_CPIO 0x10000 +#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) +#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) +#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) +#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) +#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) +#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6) +#define ARCHIVE_FORMAT_SHAR 0x20000 +#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) +#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) +#define ARCHIVE_FORMAT_TAR 0x30000 +#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) +#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) +#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) +#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) +#define ARCHIVE_FORMAT_ISO9660 0x40000 +#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) +#define ARCHIVE_FORMAT_ZIP 0x50000 +#define ARCHIVE_FORMAT_EMPTY 0x60000 +#define ARCHIVE_FORMAT_AR 0x70000 +#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) +#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) +#define ARCHIVE_FORMAT_MTREE 0x80000 +#define ARCHIVE_FORMAT_RAW 0x90000 +#define ARCHIVE_FORMAT_XAR 0xA0000 +#define ARCHIVE_FORMAT_LHA 0xB0000 +#define ARCHIVE_FORMAT_CAB 0xC0000 +#define ARCHIVE_FORMAT_RAR 0xD0000 +#define ARCHIVE_FORMAT_7ZIP 0xE0000 /*- * Basic outline for reading an archive: @@ -301,7 +296,7 @@ typedef int archive_close_callback(struct archive *, void *_client_data); * data for entries of interest. * 5) Call archive_read_finish to end processing. */ -__LA_DECL struct archive *archive_read_new(void); +__LA_DECL struct archive *archive_read_new(void); /* * The archive_read_support_XXX calls enable auto-detect for this @@ -310,39 +305,83 @@ __LA_DECL struct archive *archive_read_new(void); * support_compression_bzip2(). The "all" functions provide the * obvious shorthand. */ -__LA_DECL int archive_read_support_compression_all(struct archive *); -__LA_DECL int archive_read_support_compression_bzip2(struct archive *); -__LA_DECL int archive_read_support_compression_compress(struct archive *); -__LA_DECL int archive_read_support_compression_gzip(struct archive *); -__LA_DECL int archive_read_support_compression_lzma(struct archive *); -__LA_DECL int archive_read_support_compression_none(struct archive *); -__LA_DECL int archive_read_support_compression_program(struct archive *, - const char *command); -__LA_DECL int archive_read_support_compression_program_signature - (struct archive *, const char *, - const void * /* match */, size_t); - -__LA_DECL int archive_read_support_compression_xz(struct archive *); - -__LA_DECL int archive_read_support_format_all(struct archive *); -__LA_DECL int archive_read_support_format_ar(struct archive *); -__LA_DECL int archive_read_support_format_cpio(struct archive *); -__LA_DECL int archive_read_support_format_empty(struct archive *); -__LA_DECL int archive_read_support_format_gnutar(struct archive *); -__LA_DECL int archive_read_support_format_iso9660(struct archive *); -__LA_DECL int archive_read_support_format_mtree(struct archive *); -__LA_DECL int archive_read_support_format_raw(struct archive *); -__LA_DECL int archive_read_support_format_tar(struct archive *); -__LA_DECL int archive_read_support_format_zip(struct archive *); - - -/* Open the archive using callbacks for archive I/O. */ -__LA_DECL int archive_read_open(struct archive *, void *_client_data, - archive_open_callback *, archive_read_callback *, - archive_close_callback *); -__LA_DECL int archive_read_open2(struct archive *, void *_client_data, - archive_open_callback *, archive_read_callback *, - archive_skip_callback *, archive_close_callback *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +__LA_DECL int archive_read_support_compression_all(struct archive *); +__LA_DECL int archive_read_support_compression_bzip2(struct archive *); +__LA_DECL int archive_read_support_compression_compress(struct archive *); +__LA_DECL int archive_read_support_compression_gzip(struct archive *); +__LA_DECL int archive_read_support_compression_lzip(struct archive *); +__LA_DECL int archive_read_support_compression_lzma(struct archive *); +__LA_DECL int archive_read_support_compression_none(struct archive *); +__LA_DECL int archive_read_support_compression_program(struct archive *, + const char *command); +__LA_DECL int archive_read_support_compression_program_signature + (struct archive *, const char *, + const void * /* match */, size_t); + +__LA_DECL int archive_read_support_compression_rpm(struct archive *); +__LA_DECL int archive_read_support_compression_uu(struct archive *); +__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_bzip2(struct archive *); +__LA_DECL int archive_read_support_filter_compress(struct archive *); +__LA_DECL int archive_read_support_filter_gzip(struct archive *); +__LA_DECL int archive_read_support_filter_lzip(struct archive *); +__LA_DECL int archive_read_support_filter_lzma(struct archive *); +__LA_DECL int archive_read_support_filter_none(struct archive *); +__LA_DECL int archive_read_support_filter_program(struct archive *, + const char *command); +__LA_DECL int archive_read_support_filter_program_signature + (struct archive *, const char *, + const void * /* match */, size_t); + +__LA_DECL int archive_read_support_filter_rpm(struct archive *); +__LA_DECL int archive_read_support_filter_uu(struct archive *); +__LA_DECL int archive_read_support_filter_xz(struct archive *); + +__LA_DECL int archive_read_support_format_7zip(struct archive *); +__LA_DECL int archive_read_support_format_all(struct archive *); +__LA_DECL int archive_read_support_format_ar(struct archive *); +__LA_DECL int archive_read_support_format_by_code(struct archive *, int); +__LA_DECL int archive_read_support_format_cab(struct archive *); +__LA_DECL int archive_read_support_format_cpio(struct archive *); +__LA_DECL int archive_read_support_format_empty(struct archive *); +__LA_DECL int archive_read_support_format_gnutar(struct archive *); +__LA_DECL int archive_read_support_format_iso9660(struct archive *); +__LA_DECL int archive_read_support_format_lha(struct archive *); +__LA_DECL int archive_read_support_format_mtree(struct archive *); +__LA_DECL int archive_read_support_format_rar(struct archive *); +__LA_DECL int archive_read_support_format_raw(struct archive *); +__LA_DECL int archive_read_support_format_tar(struct archive *); +__LA_DECL int archive_read_support_format_xar(struct archive *); +__LA_DECL int archive_read_support_format_zip(struct archive *); + +/* Set various callbacks. */ +__LA_DECL int archive_read_set_open_callback(struct archive *, + archive_open_callback *); +__LA_DECL int archive_read_set_read_callback(struct archive *, + archive_read_callback *); +__LA_DECL int archive_read_set_seek_callback(struct archive *, + archive_seek_callback *); +__LA_DECL int archive_read_set_skip_callback(struct archive *, + archive_skip_callback *); +__LA_DECL int archive_read_set_close_callback(struct archive *, + archive_close_callback *); +/* The callback data is provided to all of the callbacks above. */ +__LA_DECL int archive_read_set_callback_data(struct archive *, void *); +/* Opening freezes the callbacks. */ +__LA_DECL int archive_read_open1(struct archive *); + +/* Convenience wrappers around the above. */ +__LA_DECL int archive_read_open(struct archive *, void *_client_data, + archive_open_callback *, archive_read_callback *, + archive_close_callback *); +__LA_DECL int archive_read_open2(struct archive *, void *_client_data, + archive_open_callback *, archive_read_callback *, + archive_skip_callback *, archive_close_callback *); /* * A variety of shortcuts that invoke archive_read_open() with @@ -350,41 +389,43 @@ __LA_DECL int archive_read_open2(struct archive *, void *_client_data, * accept a block size handle tape blocking correctly. */ /* Use this if you know the filename. Note: NULL indicates stdin. */ -__LA_DECL int archive_read_open_filename(struct archive *, - const char *_filename, size_t _block_size); +__LA_DECL int archive_read_open_filename(struct archive *, + const char *_filename, size_t _block_size); +__LA_DECL int archive_read_open_filename_w(struct archive *, + const wchar_t *_filename, size_t _block_size); /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ -__LA_DECL int archive_read_open_file(struct archive *, - const char *_filename, size_t _block_size); +__LA_DECL int archive_read_open_file(struct archive *, + const char *_filename, size_t _block_size); /* Read an archive that's stored in memory. */ -__LA_DECL int archive_read_open_memory(struct archive *, - void * buff, size_t size); +__LA_DECL int archive_read_open_memory(struct archive *, + void * buff, size_t size); /* A more involved version that is only used for internal testing. */ -__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff, - size_t size, size_t read_size); +__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff, + size_t size, size_t read_size); /* Read an archive that's already open, using the file descriptor. */ -__LA_DECL int archive_read_open_fd(struct archive *, int _fd, - size_t _block_size); +__LA_DECL int archive_read_open_fd(struct archive *, int _fd, + size_t _block_size); /* Read an archive that's already open, using a FILE *. */ /* Note: DO NOT use this with tape drives. */ -__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); +__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); /* Parses and returns next entry header. */ -__LA_DECL int archive_read_next_header(struct archive *, - struct archive_entry **); +__LA_DECL int archive_read_next_header(struct archive *, + struct archive_entry **); /* Parses and returns next entry header using the archive_entry passed in */ -__LA_DECL int archive_read_next_header2(struct archive *, - struct archive_entry *); +__LA_DECL int archive_read_next_header2(struct archive *, + struct archive_entry *); /* * Retrieve the byte offset in UNCOMPRESSED data where last-read * header started. */ -__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); +__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); /* Read data from the body of an entry. Similar to read(2). */ -__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, - void *, size_t); +__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, + void *, size_t); /* * A zero-copy version of archive_read_data that also exposes the file offset @@ -392,14 +433,8 @@ __LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, * the desired size of the block. The API does guarantee that offsets will * be strictly increasing and that returned blocks will not overlap. */ -#if ARCHIVE_VERSION_NUMBER < 3000000 -__LA_DECL int archive_read_data_block(struct archive *a, - const void **buff, size_t *size, off_t *offset); -#else -__LA_DECL int archive_read_data_block(struct archive *a, - const void **buff, size_t *size, - __LA_INT64_T *offset); -#endif +__LA_DECL int archive_read_data_block(struct archive *a, + const void **buff, size_t *size, __LA_INT64_T *offset); /*- * Some convenience functions that are built on archive_read_data: @@ -407,23 +442,27 @@ __LA_DECL int archive_read_data_block(struct archive *a, * 'into_buffer': writes data into memory buffer that you provide * 'into_fd': writes data to specified filedes */ -__LA_DECL int archive_read_data_skip(struct archive *); -__LA_DECL int archive_read_data_into_buffer(struct archive *, - void *buffer, __LA_SSIZE_T len); -__LA_DECL int archive_read_data_into_fd(struct archive *, int fd); +__LA_DECL int archive_read_data_skip(struct archive *); +__LA_DECL int archive_read_data_into_fd(struct archive *, int fd); /* * Set read options. */ -/* Apply option string to the format only. */ -__LA_DECL int archive_read_set_format_options(struct archive *_a, - const char *s); -/* Apply option string to the filter only. */ -__LA_DECL int archive_read_set_filter_options(struct archive *_a, - const char *s); +/* Apply option to the format only. */ +__LA_DECL int archive_read_set_format_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to the filter only. */ +__LA_DECL int archive_read_set_filter_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to both the format and the filter. */ +__LA_DECL int archive_read_set_option(struct archive *_a, + const char *m, const char *o, + const char *v); /* Apply option string to both the format and the filter. */ -__LA_DECL int archive_read_set_options(struct archive *_a, - const char *s); +__LA_DECL int archive_read_set_options(struct archive *_a, + const char *opts); /*- * Convenience function to recreate the current entry (whose header @@ -442,59 +481,61 @@ __LA_DECL int archive_read_set_options(struct archive *_a, /* The "flags" argument selects optional behavior, 'OR' the flags you want. */ /* Default: Do not try to set owner/group. */ -#define ARCHIVE_EXTRACT_OWNER (0x0001) +#define ARCHIVE_EXTRACT_OWNER (0x0001) /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ -#define ARCHIVE_EXTRACT_PERM (0x0002) +#define ARCHIVE_EXTRACT_PERM (0x0002) /* Default: Do not restore mtime/atime. */ -#define ARCHIVE_EXTRACT_TIME (0x0004) +#define ARCHIVE_EXTRACT_TIME (0x0004) /* Default: Replace existing files. */ -#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) +#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) /* Default: Try create first, unlink only if create fails with EEXIST. */ -#define ARCHIVE_EXTRACT_UNLINK (0x0010) +#define ARCHIVE_EXTRACT_UNLINK (0x0010) /* Default: Do not restore ACLs. */ -#define ARCHIVE_EXTRACT_ACL (0x0020) +#define ARCHIVE_EXTRACT_ACL (0x0020) /* Default: Do not restore fflags. */ -#define ARCHIVE_EXTRACT_FFLAGS (0x0040) +#define ARCHIVE_EXTRACT_FFLAGS (0x0040) /* Default: Do not restore xattrs. */ -#define ARCHIVE_EXTRACT_XATTR (0x0080) +#define ARCHIVE_EXTRACT_XATTR (0x0080) /* Default: Do not try to guard against extracts redirected by symlinks. */ /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ -#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) +#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) /* Default: Do not reject entries with '..' as path elements. */ -#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) +#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) /* Default: Create parent directories as needed. */ -#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) +#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) /* Default: Overwrite files, even if one on disk is newer. */ -#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) +#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) /* Detect blocks of 0 and write holes instead. */ -#define ARCHIVE_EXTRACT_SPARSE (0x1000) - -__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, - int flags); -__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, - struct archive * /* dest */); -__LA_DECL void archive_read_extract_set_progress_callback(struct archive *, - void (*_progress_func)(void *), void *_user_data); +#define ARCHIVE_EXTRACT_SPARSE (0x1000) +/* Default: Do not restore Mac extended metadata. */ +/* This has no effect except on Mac OS. */ +#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000) + +__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, + int flags); +__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, + struct archive * /* dest */); +__LA_DECL void archive_read_extract_set_progress_callback(struct archive *, + void (*_progress_func)(void *), void *_user_data); /* Record the dev/ino of a file that will not be written. This is * generally set to the dev/ino of the archive being read. */ -__LA_DECL void archive_read_extract_set_skip_file(struct archive *, - dev_t, ino_t); +__LA_DECL void archive_read_extract_set_skip_file(struct archive *, + __LA_INT64_T, __LA_INT64_T); /* Close the file and release most resources. */ -__LA_DECL int archive_read_close(struct archive *); +__LA_DECL int archive_read_close(struct archive *); /* Release all resources and destroy the object. */ -/* Note that archive_read_finish will call archive_read_close for you. */ -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* Erroneously declared to return void in libarchive 1.x */ -__LA_DECL void archive_read_finish(struct archive *); -#else -__LA_DECL int archive_read_finish(struct archive *); +/* Note that archive_read_free will call archive_read_close for you. */ +__LA_DECL int archive_read_free(struct archive *); +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Synonym for archive_read_free() for backwards compatibility. */ +__LA_DECL int archive_read_finish(struct archive *); #endif /*- * To create an archive: - * 1) Ask archive_write_new for a archive writer object. + * 1) Ask archive_write_new for an archive writer object. * 2) Set any global properties. In particular, you should set * the compression and format to use. * 3) Call archive_write_open to open the file (most people @@ -505,110 +546,122 @@ __LA_DECL int archive_read_finish(struct archive *); * - archive_write_header to write the header * - archive_write_data to write the entry data * 5) archive_write_close to close the output - * 6) archive_write_finish to cleanup the writer and release resources + * 6) archive_write_free to cleanup the writer and release resources */ -__LA_DECL struct archive *archive_write_new(void); -__LA_DECL int archive_write_set_bytes_per_block(struct archive *, - int bytes_per_block); -__LA_DECL int archive_write_get_bytes_per_block(struct archive *); +__LA_DECL struct archive *archive_write_new(void); +__LA_DECL int archive_write_set_bytes_per_block(struct archive *, + int bytes_per_block); +__LA_DECL int archive_write_get_bytes_per_block(struct archive *); /* XXX This is badly misnamed; suggestions appreciated. XXX */ -__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, - int bytes_in_last_block); -__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); +__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, + int bytes_in_last_block); +__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); /* The dev/ino of a file that won't be archived. This is used * to avoid recursively adding an archive to itself. */ -__LA_DECL int archive_write_set_skip_file(struct archive *, dev_t, ino_t); - -__LA_DECL int archive_write_set_compression_bzip2(struct archive *); -__LA_DECL int archive_write_set_compression_compress(struct archive *); -__LA_DECL int archive_write_set_compression_gzip(struct archive *); -__LA_DECL int archive_write_set_compression_lzma(struct archive *); -__LA_DECL int archive_write_set_compression_none(struct archive *); -__LA_DECL int archive_write_set_compression_program(struct archive *, - const char *cmd); -__LA_DECL int archive_write_set_compression_xz(struct archive *); +__LA_DECL int archive_write_set_skip_file(struct archive *, + __LA_INT64_T, __LA_INT64_T); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +__LA_DECL int archive_write_set_compression_bzip2(struct archive *); +__LA_DECL int archive_write_set_compression_compress(struct archive *); +__LA_DECL int archive_write_set_compression_gzip(struct archive *); +__LA_DECL int archive_write_set_compression_lzip(struct archive *); +__LA_DECL int archive_write_set_compression_lzma(struct archive *); +__LA_DECL int archive_write_set_compression_none(struct archive *); +__LA_DECL int archive_write_set_compression_program(struct archive *, + const char *cmd); +__LA_DECL int archive_write_set_compression_xz(struct archive *); +#endif + +__LA_DECL int archive_write_add_filter_bzip2(struct archive *); +__LA_DECL int archive_write_add_filter_compress(struct archive *); +__LA_DECL int archive_write_add_filter_gzip(struct archive *); +__LA_DECL int archive_write_add_filter_lzip(struct archive *); +__LA_DECL int archive_write_add_filter_lzma(struct archive *); +__LA_DECL int archive_write_add_filter_none(struct archive *); +__LA_DECL int archive_write_add_filter_program(struct archive *, + const char *cmd); +__LA_DECL int archive_write_add_filter_xz(struct archive *); + + /* A convenience function to set the format based on the code or name. */ -__LA_DECL int archive_write_set_format(struct archive *, int format_code); -__LA_DECL int archive_write_set_format_by_name(struct archive *, - const char *name); +__LA_DECL int archive_write_set_format(struct archive *, int format_code); +__LA_DECL int archive_write_set_format_by_name(struct archive *, + const char *name); /* To minimize link pollution, use one or more of the following. */ -__LA_DECL int archive_write_set_format_ar_bsd(struct archive *); -__LA_DECL int archive_write_set_format_ar_svr4(struct archive *); -__LA_DECL int archive_write_set_format_cpio(struct archive *); -__LA_DECL int archive_write_set_format_cpio_newc(struct archive *); -__LA_DECL int archive_write_set_format_mtree(struct archive *); +__LA_DECL int archive_write_set_format_7zip(struct archive *); +__LA_DECL int archive_write_set_format_ar_bsd(struct archive *); +__LA_DECL int archive_write_set_format_ar_svr4(struct archive *); +__LA_DECL int archive_write_set_format_cpio(struct archive *); +__LA_DECL int archive_write_set_format_cpio_newc(struct archive *); +__LA_DECL int archive_write_set_format_gnutar(struct archive *); +__LA_DECL int archive_write_set_format_iso9660(struct archive *); +__LA_DECL int archive_write_set_format_mtree(struct archive *); /* TODO: int archive_write_set_format_old_tar(struct archive *); */ -__LA_DECL int archive_write_set_format_pax(struct archive *); -__LA_DECL int archive_write_set_format_pax_restricted(struct archive *); -__LA_DECL int archive_write_set_format_shar(struct archive *); -__LA_DECL int archive_write_set_format_shar_dump(struct archive *); -__LA_DECL int archive_write_set_format_ustar(struct archive *); -__LA_DECL int archive_write_set_format_zip(struct archive *); -__LA_DECL int archive_write_open(struct archive *, void *, - archive_open_callback *, archive_write_callback *, - archive_close_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_set_format_pax(struct archive *); +__LA_DECL int archive_write_set_format_pax_restricted(struct archive *); +__LA_DECL int archive_write_set_format_shar(struct archive *); +__LA_DECL int archive_write_set_format_shar_dump(struct archive *); +__LA_DECL int archive_write_set_format_ustar(struct archive *); +__LA_DECL int archive_write_set_format_xar(struct archive *); +__LA_DECL int archive_write_set_format_zip(struct archive *); +__LA_DECL int archive_write_open(struct archive *, void *, + archive_open_callback *, archive_write_callback *, + archive_close_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 *, + const wchar_t *_file); /* A deprecated synonym for archive_write_open_filename() */ -__LA_DECL int archive_write_open_file(struct archive *, const char *_file); -__LA_DECL int archive_write_open_FILE(struct archive *, FILE *); +__LA_DECL int archive_write_open_file(struct archive *, const char *_file); +__LA_DECL int archive_write_open_FILE(struct archive *, FILE *); /* _buffSize is the size of the buffer, _used refers to a variable that * will be updated after each write into the buffer. */ -__LA_DECL int archive_write_open_memory(struct archive *, - void *_buffer, size_t _buffSize, size_t *_used); +__LA_DECL int archive_write_open_memory(struct archive *, + void *_buffer, size_t _buffSize, size_t *_used); /* * Note that the library will truncate writes beyond the size provided * to archive_write_header or pad if the provided data is short. */ -__LA_DECL int archive_write_header(struct archive *, - struct archive_entry *); -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* This was erroneously declared to return "int" in libarchive 1.x. */ -__LA_DECL int archive_write_data(struct archive *, - const void *, size_t); -#else -/* Libarchive 2.0 and later return ssize_t here. */ -__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, - const void *, size_t); -#endif - -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* Libarchive 1.x and 2.x use off_t for the argument, but that's not - * stable on Linux. */ -__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, - const void *, size_t, off_t); -#else -/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */ -__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, - const void *, size_t, __LA_INT64_T); -#endif -__LA_DECL int archive_write_finish_entry(struct archive *); -__LA_DECL int archive_write_close(struct archive *); -#if ARCHIVE_VERSION_NUMBER < 2000000 -/* Return value was incorrect in libarchive 1.x. */ -__LA_DECL void archive_write_finish(struct archive *); -#else -/* Libarchive 2.x and later returns an error if this fails. */ -/* It can fail if the archive wasn't already closed, in which case - * archive_write_finish() will implicitly call archive_write_close(). */ -__LA_DECL int archive_write_finish(struct archive *); +__LA_DECL int archive_write_header(struct archive *, + struct archive_entry *); +__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, + const void *, size_t); + +/* This interface is currently only available for archive_write_disk handles. */ +__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, + const void *, size_t, __LA_INT64_T); + +__LA_DECL int archive_write_finish_entry(struct archive *); +__LA_DECL int archive_write_close(struct archive *); +/* This can fail if the archive wasn't already closed, in which case + * archive_write_free() will implicitly call archive_write_close(). */ +__LA_DECL int archive_write_free(struct archive *); +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Synonym for archive_write_free() for backwards compatibility. */ +__LA_DECL int archive_write_finish(struct archive *); #endif /* * Set write options. */ -/* Apply option string to the format only. */ -__LA_DECL int archive_write_set_format_options(struct archive *_a, - const char *s); -/* Apply option string to the compressor only. */ -__LA_DECL int archive_write_set_compressor_options(struct archive *_a, - const char *s); -/* Apply option string to both the format and the compressor. */ -__LA_DECL int archive_write_set_options(struct archive *_a, - const char *s); - +/* Apply option to the format only. */ +__LA_DECL int archive_write_set_format_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to the filter only. */ +__LA_DECL int archive_write_set_filter_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option to both the format and the filter. */ +__LA_DECL int archive_write_set_option(struct archive *_a, + const char *m, const char *o, + const char *v); +/* Apply option string to both the format and the filter. */ +__LA_DECL int archive_write_set_options(struct archive *_a, + const char *opts); /*- * ARCHIVE_WRITE_DISK API @@ -621,19 +674,19 @@ __LA_DECL int archive_write_set_options(struct archive *_a, * - construct an appropriate struct archive_entry structure * - archive_write_header to create the file/dir/etc on disk * - archive_write_data to write the entry data - * 4) archive_write_finish to cleanup the writer and release resources + * 4) archive_write_free to cleanup the writer and release resources * * In particular, you can use this in conjunction with archive_read() * to pull entries out of an archive and create them on disk. */ -__LA_DECL struct archive *archive_write_disk_new(void); +__LA_DECL struct archive *archive_write_disk_new(void); /* This file will not be overwritten. */ -__LA_DECL int archive_write_disk_set_skip_file(struct archive *, - dev_t, ino_t); +__LA_DECL int archive_write_disk_set_skip_file(struct archive *, + __LA_INT64_T, __LA_INT64_T); /* Set flags to control how the next item gets created. * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */ -__LA_DECL int archive_write_disk_set_options(struct archive *, - int flags); +__LA_DECL int archive_write_disk_set_options(struct archive *, + int flags); /* * The lookup functions are given uname/uid (or gname/gid) pairs and * return a uid (gid) suitable for this system. These are used for @@ -651,20 +704,22 @@ __LA_DECL int archive_write_disk_set_options(struct archive *, * particular, these match the specifications of POSIX "pax" and old * POSIX "tar". */ -__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); +__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); /* * If neither the default (naive) nor the standard (big) functions suit * your needs, you can write your own and register them. Be sure to * include a cleanup function if you have allocated private data. */ -__LA_DECL int archive_write_disk_set_group_lookup(struct archive *, - void * /* private_data */, - __LA_GID_T (*)(void *, const char *, __LA_GID_T), - void (* /* cleanup */)(void *)); -__LA_DECL int archive_write_disk_set_user_lookup(struct archive *, - void * /* private_data */, - __LA_UID_T (*)(void *, const char *, __LA_UID_T), - void (* /* cleanup */)(void *)); +__LA_DECL int archive_write_disk_set_group_lookup(struct archive *, + void * /* private_data */, + __LA_INT64_T (*)(void *, const char *, __LA_INT64_T), + void (* /* cleanup */)(void *)); +__LA_DECL int archive_write_disk_set_user_lookup(struct archive *, + void * /* private_data */, + __LA_INT64_T (*)(void *, const char *, __LA_INT64_T), + void (* /* cleanup */)(void *)); +__LA_DECL __LA_INT64_T archive_write_disk_gid(struct archive *, const char *, __LA_INT64_T); +__LA_DECL __LA_INT64_T archive_write_disk_uid(struct archive *, const char *, __LA_INT64_T); /* * ARCHIVE_READ_DISK API @@ -685,42 +740,74 @@ __LA_DECL int archive_read_disk_entry_from_file(struct archive *, struct archive_entry *, int /* fd */, const struct stat *); /* Look up gname for gid or uname for uid. */ /* Default implementations are very, very stupid. */ -__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_GID_T); -__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_UID_T); +__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T); +__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T); /* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the * results for performance. */ -__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); +__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); /* You can install your own lookups if you like. */ -__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, +__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, void * /* private_data */, - const char *(* /* lookup_fn */)(void *, __LA_GID_T), + const char *(* /* lookup_fn */)(void *, __LA_INT64_T), void (* /* cleanup_fn */)(void *)); -__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, +__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, void * /* private_data */, - const char *(* /* lookup_fn */)(void *, __LA_UID_T), + const char *(* /* lookup_fn */)(void *, __LA_INT64_T), void (* /* cleanup_fn */)(void *)); +/* Start traversal. */ +__LA_DECL int archive_read_disk_open(struct archive *, const char *); +__LA_DECL int archive_read_disk_open_w(struct archive *, const wchar_t *); +/* + * Request that current entry be visited. If you invoke it on every + * directory, you'll get a physical traversal. This is ignored if the + * current entry isn't a directory or a link to a directory. So, if + * you invoke this on every returned path, you'll get a full logical + * traversal. + */ +__LA_DECL int archive_read_disk_descend(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *); +__LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *); +/* Request that the access time of the entry visited by travesal be restored. */ +__LA_DECL int archive_read_disk_set_atime_restored(struct archive *); /* * Accessor functions to read/set various information in * the struct archive object: */ -/* Bytes written after compression or read before decompression. */ -__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); -/* Bytes written to compressor or read from decompressor. */ -__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); - -__LA_DECL const char *archive_compression_name(struct archive *); -__LA_DECL int archive_compression(struct archive *); -__LA_DECL int archive_errno(struct archive *); -__LA_DECL const char *archive_error_string(struct archive *); -__LA_DECL const char *archive_format_name(struct archive *); -__LA_DECL int archive_format(struct archive *); -__LA_DECL void archive_clear_error(struct archive *); -__LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); -__LA_DECL void archive_copy_error(struct archive *dest, - struct archive *src); -__LA_DECL int archive_file_count(struct archive *); + +/* Number of filters in the current filter pipeline. */ +/* Filter #0 is the one closest to the format, -1 is a synonym for the + * last filter, which is always the pseudo-filter that wraps the + * client callbacks. */ +__LA_DECL int archive_filter_count(struct archive *); +__LA_DECL __LA_INT64_T archive_filter_bytes(struct archive *, int); +__LA_DECL int archive_filter_code(struct archive *, int); +__LA_DECL const char * archive_filter_name(struct archive *, int); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* These don't properly handle multiple filters, so are deprecated and + * will eventually be removed. */ +/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */ +__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); +/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */ +__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); +/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */ +__LA_DECL const char *archive_compression_name(struct archive *); +/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */ +__LA_DECL int archive_compression(struct archive *); +#endif + +__LA_DECL int archive_errno(struct archive *); +__LA_DECL const char *archive_error_string(struct archive *); +__LA_DECL const char *archive_format_name(struct archive *); +__LA_DECL int archive_format(struct archive *); +__LA_DECL void archive_clear_error(struct archive *); +__LA_DECL void archive_set_error(struct archive *, int _err, + const char *fmt, ...) __LA_PRINTF(3, 4); +__LA_DECL void archive_copy_error(struct archive *dest, + struct archive *src); +__LA_DECL int archive_file_count(struct archive *); #ifdef __cplusplus } diff --git a/Utilities/cmlibarchive/libarchive/archive_acl.c b/Utilities/cmlibarchive/libarchive/archive_acl.c new file mode 100644 index 000000000..4747a4c5a --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_acl.c @@ -0,0 +1,1264 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_WCHAR_H +#include +#endif + +#include "archive_acl_private.h" +#include "archive_entry.h" +#include "archive_private.h" + +#undef max +#define max(a, b) ((a)>(b)?(a):(b)) + +#ifndef HAVE_WMEMCMP +/* Good enough for simple equality testing, but not for sorting. */ +#define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t)) +#endif + +static int acl_special(struct archive_acl *acl, + int type, int permset, int tag); +static struct archive_acl_entry *acl_new_entry(struct archive_acl *acl, + int type, int permset, int tag, int id); +static int isint_w(const wchar_t *start, const wchar_t *end, int *result); +static int ismode_w(const wchar_t *start, const wchar_t *end, int *result); +static void next_field_w(const wchar_t **wp, const wchar_t **start, + const wchar_t **end, wchar_t *sep); +static int prefix_w(const wchar_t *start, const wchar_t *end, + const wchar_t *test); +static void append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, + const wchar_t *wname, int perm, int id); +static void append_id_w(wchar_t **wp, int id); +static int isint(const char *start, const char *end, int *result); +static int ismode(const char *start, const char *end, int *result); +static void next_field(const char **p, const char **start, + const char **end, char *sep); +static int prefix(const char *start, const char *end, + const char *test); +static void append_entry(char **p, const char *prefix, int tag, + const char *name, int perm, int id); +static void append_id(char **p, int id); + +void +archive_acl_clear(struct archive_acl *acl) +{ + struct archive_acl_entry *ap; + + while (acl->acl_head != NULL) { + ap = acl->acl_head->next; + archive_mstring_clean(&acl->acl_head->name); + free(acl->acl_head); + acl->acl_head = ap; + } + if (acl->acl_text_w != NULL) { + free(acl->acl_text_w); + acl->acl_text_w = NULL; + } + if (acl->acl_text != NULL) { + free(acl->acl_text); + acl->acl_text = NULL; + } + acl->acl_p = NULL; + acl->acl_state = 0; /* Not counting. */ +} + +void +archive_acl_copy(struct archive_acl *dest, struct archive_acl *src) +{ + struct archive_acl_entry *ap, *ap2; + + archive_acl_clear(dest); + + dest->mode = src->mode; + ap = src->acl_head; + while (ap != NULL) { + ap2 = acl_new_entry(dest, + ap->type, ap->permset, ap->tag, ap->id); + if (ap2 != NULL) + archive_mstring_copy(&ap2->name, &ap->name); + ap = ap->next; + } +} + +int +archive_acl_add_entry(struct archive_acl *acl, + int type, int permset, int tag, int id, const char *name) +{ + struct archive_acl_entry *ap; + + if (acl_special(acl, type, permset, tag) == 0) + return ARCHIVE_OK; + ap = acl_new_entry(acl, type, permset, tag, id); + if (ap == NULL) { + /* XXX Error XXX */ + return ARCHIVE_FAILED; + } + if (name != NULL && *name != '\0') + archive_mstring_copy_mbs(&ap->name, name); + else + archive_mstring_clean(&ap->name); + return ARCHIVE_OK; +} + +int +archive_acl_add_entry_w_len(struct archive_acl *acl, + int type, int permset, int tag, int id, const wchar_t *name, size_t len) +{ + struct archive_acl_entry *ap; + + if (acl_special(acl, type, permset, tag) == 0) + return ARCHIVE_OK; + ap = acl_new_entry(acl, type, permset, tag, id); + if (ap == NULL) { + /* XXX Error XXX */ + return ARCHIVE_FAILED; + } + if (name != NULL && *name != L'\0' && len > 0) + archive_mstring_copy_wcs_len(&ap->name, name, len); + else + archive_mstring_clean(&ap->name); + return ARCHIVE_OK; +} + +int +archive_acl_add_entry_len_l(struct archive_acl *acl, + int type, int permset, int tag, int id, const char *name, size_t len, + struct archive_string_conv *sc) +{ + struct archive_acl_entry *ap; + int r; + + if (acl_special(acl, type, permset, tag) == 0) + return ARCHIVE_OK; + ap = acl_new_entry(acl, type, permset, tag, id); + if (ap == NULL) { + /* XXX Error XXX */ + return ARCHIVE_FAILED; + } + if (name != NULL && *name != '\0' && len > 0) { + r = archive_mstring_copy_mbs_len_l(&ap->name, name, len, sc); + } else { + r = 0; + archive_mstring_clean(&ap->name); + } + if (r == 0) + return (ARCHIVE_OK); + else if (errno == ENOMEM) + return (ARCHIVE_FATAL); + else + return (ARCHIVE_WARN); +} + +/* + * If this ACL entry is part of the standard POSIX permissions set, + * store the permissions in the stat structure and return zero. + */ +static int +acl_special(struct archive_acl *acl, int type, int permset, int tag) +{ + if (type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS + && ((permset & ~007) == 0)) { + switch (tag) { + case ARCHIVE_ENTRY_ACL_USER_OBJ: + acl->mode &= ~0700; + acl->mode |= (permset & 7) << 6; + return (0); + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + acl->mode &= ~0070; + acl->mode |= (permset & 7) << 3; + return (0); + case ARCHIVE_ENTRY_ACL_OTHER: + acl->mode &= ~0007; + acl->mode |= permset & 7; + return (0); + } + } + return (1); +} + +/* + * Allocate and populate a new ACL entry with everything but the + * name. + */ +static struct archive_acl_entry * +acl_new_entry(struct archive_acl *acl, + int type, int permset, int tag, int id) +{ + struct archive_acl_entry *ap, *aq; + + /* Type argument must be a valid NFS4 or POSIX.1e type. + * The type must agree with anything already set and + * the permset must be compatible. */ + if (type & ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + return (NULL); + } + if (permset & + ~(ARCHIVE_ENTRY_ACL_PERMS_NFS4 + | ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4)) { + return (NULL); + } + } else if (type & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) { + if (acl->acl_types & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) { + return (NULL); + } + if (permset & ~ARCHIVE_ENTRY_ACL_PERMS_POSIX1E) { + return (NULL); + } + } else { + return (NULL); + } + + /* Verify the tag is valid and compatible with NFS4 or POSIX.1e. */ + switch (tag) { + case ARCHIVE_ENTRY_ACL_USER: + case ARCHIVE_ENTRY_ACL_USER_OBJ: + case ARCHIVE_ENTRY_ACL_GROUP: + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + /* Tags valid in both NFS4 and POSIX.1e */ + break; + case ARCHIVE_ENTRY_ACL_MASK: + case ARCHIVE_ENTRY_ACL_OTHER: + /* Tags valid only in POSIX.1e. */ + if (type & ~ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) { + return (NULL); + } + break; + case ARCHIVE_ENTRY_ACL_EVERYONE: + /* Tags valid only in NFS4. */ + if (type & ~ARCHIVE_ENTRY_ACL_TYPE_NFS4) { + return (NULL); + } + break; + default: + /* No other values are valid. */ + return (NULL); + } + + if (acl->acl_text_w != NULL) { + free(acl->acl_text_w); + acl->acl_text_w = NULL; + } + if (acl->acl_text != NULL) { + free(acl->acl_text); + acl->acl_text = NULL; + } + + /* If there's a matching entry already in the list, overwrite it. */ + ap = acl->acl_head; + aq = NULL; + while (ap != NULL) { + if (ap->type == type && ap->tag == tag && ap->id == id) { + ap->permset = permset; + return (ap); + } + aq = ap; + ap = ap->next; + } + + /* Add a new entry to the end of the list. */ + ap = (struct archive_acl_entry *)malloc(sizeof(*ap)); + if (ap == NULL) + return (NULL); + memset(ap, 0, sizeof(*ap)); + if (aq == NULL) + acl->acl_head = ap; + else + aq->next = ap; + ap->type = type; + ap->tag = tag; + ap->id = id; + ap->permset = permset; + acl->acl_types |= type; + return (ap); +} + +/* + * Return a count of entries matching "want_type". + */ +int +archive_acl_count(struct archive_acl *acl, int want_type) +{ + int count; + struct archive_acl_entry *ap; + + count = 0; + ap = acl->acl_head; + while (ap != NULL) { + if ((ap->type & want_type) != 0) + count++; + ap = ap->next; + } + + if (count > 0 && ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) + count += 3; + return (count); +} + +/* + * Prepare for reading entries from the ACL data. Returns a count + * of entries matching "want_type", or zero if there are no + * non-extended ACL entries of that type. + */ +int +archive_acl_reset(struct archive_acl *acl, int want_type) +{ + int count, cutoff; + + count = archive_acl_count(acl, want_type); + + /* + * If the only entries are the three standard ones, + * then don't return any ACL data. (In this case, + * client can just use chmod(2) to set permissions.) + */ + if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) + cutoff = 3; + else + cutoff = 0; + + if (count > cutoff) + acl->acl_state = ARCHIVE_ENTRY_ACL_USER_OBJ; + else + acl->acl_state = 0; + acl->acl_p = acl->acl_head; + return (count); +} + + +/* + * Return the next ACL entry in the list. Fake entries for the + * standard permissions and include them in the returned list. + */ +int +archive_acl_next(struct archive *a, struct archive_acl *acl, int want_type, int *type, + int *permset, int *tag, int *id, const char **name) +{ + *name = NULL; + *id = -1; + + /* + * The acl_state is either zero (no entries available), -1 + * (reading from list), or an entry type (retrieve that type + * from ae_stat.aest_mode). + */ + if (acl->acl_state == 0) + return (ARCHIVE_WARN); + + /* The first three access entries are special. */ + if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + switch (acl->acl_state) { + case ARCHIVE_ENTRY_ACL_USER_OBJ: + *permset = (acl->mode >> 6) & 7; + *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + *tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + acl->acl_state = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + return (ARCHIVE_OK); + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + *permset = (acl->mode >> 3) & 7; + *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + *tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + acl->acl_state = ARCHIVE_ENTRY_ACL_OTHER; + return (ARCHIVE_OK); + case ARCHIVE_ENTRY_ACL_OTHER: + *permset = acl->mode & 7; + *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; + *tag = ARCHIVE_ENTRY_ACL_OTHER; + acl->acl_state = -1; + acl->acl_p = acl->acl_head; + return (ARCHIVE_OK); + default: + break; + } + } + + while (acl->acl_p != NULL && (acl->acl_p->type & want_type) == 0) + acl->acl_p = acl->acl_p->next; + if (acl->acl_p == NULL) { + acl->acl_state = 0; + *type = 0; + *permset = 0; + *tag = 0; + *id = -1; + *name = NULL; + return (ARCHIVE_EOF); /* End of ACL entries. */ + } + *type = acl->acl_p->type; + *permset = acl->acl_p->permset; + *tag = acl->acl_p->tag; + *id = acl->acl_p->id; + if (archive_mstring_get_mbs(a, &acl->acl_p->name, name) != 0) + *name = NULL; + acl->acl_p = acl->acl_p->next; + return (ARCHIVE_OK); +} + +/* + * Generate a text version of the ACL. The flags parameter controls + * the style of the generated ACL. + */ +const wchar_t * +archive_acl_text_w(struct archive *a, struct archive_acl *acl, int flags) +{ + int count; + size_t length; + const wchar_t *wname; + const wchar_t *prefix; + wchar_t separator; + struct archive_acl_entry *ap; + int id; + wchar_t *wp; + + if (acl->acl_text_w != NULL) { + free (acl->acl_text_w); + acl->acl_text_w = NULL; + } + + separator = L','; + count = 0; + length = 0; + ap = acl->acl_head; + while (ap != NULL) { + if ((ap->type & flags) != 0) { + count++; + if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) && + (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)) + length += 8; /* "default:" */ + length += 5; /* tag name */ + length += 1; /* colon */ + if (archive_mstring_get_wcs(a, &ap->name, &wname) == 0 && + wname != NULL) + length += wcslen(wname); + else + length += sizeof(uid_t) * 3 + 1; + length ++; /* colon */ + length += 3; /* rwx */ + length += 1; /* colon */ + length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1; + length ++; /* newline */ + } + ap = ap->next; + } + + if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) { + length += 10; /* "user::rwx\n" */ + length += 11; /* "group::rwx\n" */ + length += 11; /* "other::rwx\n" */ + } + + if (count == 0) + return (NULL); + + /* Now, allocate the string and actually populate it. */ + wp = acl->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t)); + if (wp == NULL) + __archive_errx(1, "No memory to generate the text version of the ACL"); + count = 0; + if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, + acl->mode & 0700, -1); + *wp++ = ','; + append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL, + acl->mode & 0070, -1); + *wp++ = ','; + append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL, + acl->mode & 0007, -1); + count += 3; + + ap = acl->acl_head; + while (ap != NULL) { + if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0 && + archive_mstring_get_wcs(a, &ap->name, &wname) == 0) { + *wp++ = separator; + if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) + id = ap->id; + else + id = -1; + append_entry_w(&wp, NULL, ap->tag, wname, + ap->permset, id); + count++; + } + ap = ap->next; + } + } + + + if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { + if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) + prefix = L"default:"; + else + prefix = NULL; + ap = acl->acl_head; + count = 0; + while (ap != NULL) { + if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0 && + archive_mstring_get_wcs(a, &ap->name, &wname) == 0) { + if (count > 0) + *wp++ = separator; + if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) + id = ap->id; + else + id = -1; + append_entry_w(&wp, prefix, ap->tag, + wname, ap->permset, id); + count ++; + } + ap = ap->next; + } + } + + return (acl->acl_text_w); +} + + +static void +append_id_w(wchar_t **wp, int id) +{ + if (id < 0) + id = 0; + if (id > 9) + append_id_w(wp, id / 10); + *(*wp)++ = L"0123456789"[id % 10]; +} + +static void +append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, + const wchar_t *wname, int perm, int id) +{ + if (prefix != NULL) { + wcscpy(*wp, prefix); + *wp += wcslen(*wp); + } + switch (tag) { + case ARCHIVE_ENTRY_ACL_USER_OBJ: + wname = NULL; + id = -1; + /* FALLTHROUGH */ + case ARCHIVE_ENTRY_ACL_USER: + wcscpy(*wp, L"user"); + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + wname = NULL; + id = -1; + /* FALLTHROUGH */ + case ARCHIVE_ENTRY_ACL_GROUP: + wcscpy(*wp, L"group"); + break; + case ARCHIVE_ENTRY_ACL_MASK: + wcscpy(*wp, L"mask"); + wname = NULL; + id = -1; + break; + case ARCHIVE_ENTRY_ACL_OTHER: + wcscpy(*wp, L"other"); + wname = NULL; + id = -1; + break; + } + *wp += wcslen(*wp); + *(*wp)++ = L':'; + if (wname != NULL) { + wcscpy(*wp, wname); + *wp += wcslen(*wp); + } else if (tag == ARCHIVE_ENTRY_ACL_USER + || tag == ARCHIVE_ENTRY_ACL_GROUP) { + append_id_w(wp, id); + id = -1; + } + *(*wp)++ = L':'; + *(*wp)++ = (perm & 0444) ? L'r' : L'-'; + *(*wp)++ = (perm & 0222) ? L'w' : L'-'; + *(*wp)++ = (perm & 0111) ? L'x' : L'-'; + if (id != -1) { + *(*wp)++ = L':'; + append_id_w(wp, id); + } + **wp = L'\0'; +} + +int +archive_acl_text_l(struct archive_acl *acl, int flags, + const char **acl_text, size_t *acl_text_len, + struct archive_string_conv *sc) +{ + int count; + size_t length; + const char *name; + const char *prefix; + char separator; + struct archive_acl_entry *ap; + size_t len; + int id, r; + char *p; + + if (acl->acl_text != NULL) { + free (acl->acl_text); + acl->acl_text = NULL; + } + + *acl_text = NULL; + if (acl_text_len != NULL) + *acl_text_len = 0; + separator = ','; + count = 0; + length = 0; + ap = acl->acl_head; + while (ap != NULL) { + if ((ap->type & flags) != 0) { + count++; + if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) && + (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)) + length += 8; /* "default:" */ + length += 5; /* tag name */ + length += 1; /* colon */ + r = archive_mstring_get_mbs_l( + &ap->name, &name, &len, sc); + if (r != 0) + return (-1); + if (len > 0 && name != NULL) + length += len; + else + length += sizeof(uid_t) * 3 + 1; + length ++; /* colon */ + length += 3; /* rwx */ + length += 1; /* colon */ + length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1; + length ++; /* newline */ + } + ap = ap->next; + } + + if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) { + length += 10; /* "user::rwx\n" */ + length += 11; /* "group::rwx\n" */ + length += 11; /* "other::rwx\n" */ + } + + if (count == 0) + return (0); + + /* Now, allocate the string and actually populate it. */ + p = acl->acl_text = (char *)malloc(length); + if (p == NULL) + __archive_errx(1, "No memory to generate the text version of the ACL"); + count = 0; + if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { + append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, + acl->mode & 0700, -1); + *p++ = ','; + append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL, + acl->mode & 0070, -1); + *p++ = ','; + append_entry(&p, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL, + acl->mode & 0007, -1); + count += 3; + + for (ap = acl->acl_head; ap != NULL; ap = ap->next) { + if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) == 0) + continue; + r = archive_mstring_get_mbs_l( + &ap->name, &name, &len, sc); + if (r != 0) + return (-1); + *p++ = separator; + if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) + id = ap->id; + else + id = -1; + append_entry(&p, NULL, ap->tag, name, + ap->permset, id); + count++; + } + } + + + if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { + if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) + prefix = "default:"; + else + prefix = NULL; + count = 0; + for (ap = acl->acl_head; ap != NULL; ap = ap->next) { + if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) == 0) + continue; + r = archive_mstring_get_mbs_l( + &ap->name, &name, &len, sc); + if (r != 0) + return (-1); + if (count > 0) + *p++ = separator; + if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) + id = ap->id; + else + id = -1; + append_entry(&p, prefix, ap->tag, + name, ap->permset, id); + count ++; + } + } + + *acl_text = acl->acl_text; + if (acl_text_len != NULL) + *acl_text_len = strlen(acl->acl_text); + return (0); +} + +static void +append_id(char **p, int id) +{ + if (id < 0) + id = 0; + if (id > 9) + append_id(p, id / 10); + *(*p)++ = "0123456789"[id % 10]; +} + +static void +append_entry(char **p, const char *prefix, int tag, + const char *name, int perm, int id) +{ + if (prefix != NULL) { + strcpy(*p, prefix); + *p += strlen(*p); + } + switch (tag) { + case ARCHIVE_ENTRY_ACL_USER_OBJ: + name = NULL; + id = -1; + /* FALLTHROUGH */ + case ARCHIVE_ENTRY_ACL_USER: + strcpy(*p, "user"); + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + name = NULL; + id = -1; + /* FALLTHROUGH */ + case ARCHIVE_ENTRY_ACL_GROUP: + strcpy(*p, "group"); + break; + case ARCHIVE_ENTRY_ACL_MASK: + strcpy(*p, "mask"); + name = NULL; + id = -1; + break; + case ARCHIVE_ENTRY_ACL_OTHER: + strcpy(*p, "other"); + name = NULL; + id = -1; + break; + } + *p += strlen(*p); + *(*p)++ = ':'; + if (name != NULL) { + strcpy(*p, name); + *p += strlen(*p); + } else if (tag == ARCHIVE_ENTRY_ACL_USER + || tag == ARCHIVE_ENTRY_ACL_GROUP) { + append_id(p, id); + id = -1; + } + *(*p)++ = ':'; + *(*p)++ = (perm & 0444) ? 'r' : '-'; + *(*p)++ = (perm & 0222) ? 'w' : '-'; + *(*p)++ = (perm & 0111) ? 'x' : '-'; + if (id != -1) { + *(*p)++ = ':'; + append_id(p, id); + } + **p = '\0'; +} + +/* + * Parse a textual ACL. This automatically recognizes and supports + * extensions described above. The 'type' argument is used to + * indicate the type that should be used for any entries not + * explicitly marked as "default:". + */ +int +archive_acl_parse_w(struct archive_acl *acl, + const wchar_t *text, int default_type) +{ + struct { + const wchar_t *start; + const wchar_t *end; + } field[4], name; + + int fields, n; + int type, tag, permset, id; + wchar_t sep; + + while (text != NULL && *text != L'\0') { + /* + * Parse the fields out of the next entry, + * advance 'text' to start of next entry. + */ + fields = 0; + do { + const wchar_t *start, *end; + next_field_w(&text, &start, &end, &sep); + if (fields < 4) { + field[fields].start = start; + field[fields].end = end; + } + ++fields; + } while (sep == L':'); + + /* Set remaining fields to blank. */ + for (n = fields; n < 4; ++n) + field[n].start = field[n].end = NULL; + + /* Check for a numeric ID in field 1 or 3. */ + id = -1; + isint_w(field[1].start, field[1].end, &id); + /* Field 3 is optional. */ + if (id == -1 && fields > 3) + isint_w(field[3].start, field[3].end, &id); + + /* + * Solaris extension: "defaultuser::rwx" is the + * default ACL corresponding to "user::rwx", etc. + */ + if (field[0].end - field[0].start > 7 + && wmemcmp(field[0].start, L"default", 7) == 0) { + type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; + field[0].start += 7; + } else + type = default_type; + + name.start = name.end = NULL; + if (prefix_w(field[0].start, field[0].end, L"user")) { + if (!ismode_w(field[2].start, field[2].end, &permset)) + return (ARCHIVE_WARN); + if (id != -1 || field[1].start < field[1].end) { + tag = ARCHIVE_ENTRY_ACL_USER; + name = field[1]; + } else + tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + } else if (prefix_w(field[0].start, field[0].end, L"group")) { + if (!ismode_w(field[2].start, field[2].end, &permset)) + return (ARCHIVE_WARN); + if (id != -1 || field[1].start < field[1].end) { + tag = ARCHIVE_ENTRY_ACL_GROUP; + name = field[1]; + } else + tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + } else if (prefix_w(field[0].start, field[0].end, L"other")) { + if (fields == 2 + && field[1].start < field[1].end + && ismode_w(field[1].start, field[1].end, &permset)) { + /* This is Solaris-style "other:rwx" */ + } else if (fields == 3 + && field[1].start == field[1].end + && field[2].start < field[2].end + && ismode_w(field[2].start, field[2].end, &permset)) { + /* This is FreeBSD-style "other::rwx" */ + } else + return (ARCHIVE_WARN); + tag = ARCHIVE_ENTRY_ACL_OTHER; + } else if (prefix_w(field[0].start, field[0].end, L"mask")) { + if (fields == 2 + && field[1].start < field[1].end + && ismode_w(field[1].start, field[1].end, &permset)) { + /* This is Solaris-style "mask:rwx" */ + } else if (fields == 3 + && field[1].start == field[1].end + && field[2].start < field[2].end + && ismode_w(field[2].start, field[2].end, &permset)) { + /* This is FreeBSD-style "mask::rwx" */ + } else + return (ARCHIVE_WARN); + tag = ARCHIVE_ENTRY_ACL_MASK; + } else + return (ARCHIVE_WARN); + + /* Add entry to the internal list. */ + archive_acl_add_entry_w_len(acl, type, permset, + tag, id, name.start, name.end - name.start); + } + return (ARCHIVE_OK); +} + +/* + * Parse a string to a positive decimal integer. Returns true if + * the string is non-empty and consists only of decimal digits, + * false otherwise. + */ +static int +isint_w(const wchar_t *start, const wchar_t *end, int *result) +{ + int n = 0; + if (start >= end) + return (0); + while (start < end) { + if (*start < '0' || *start > '9') + return (0); + if (n > (INT_MAX / 10) || + (n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) { + n = INT_MAX; + } else { + n *= 10; + n += *start - '0'; + } + start++; + } + *result = n; + return (1); +} + +/* + * Parse a string as a mode field. Returns true if + * the string is non-empty and consists only of mode characters, + * false otherwise. + */ +static int +ismode_w(const wchar_t *start, const wchar_t *end, int *permset) +{ + const wchar_t *p; + + if (start >= end) + return (0); + p = start; + *permset = 0; + while (p < end) { + switch (*p++) { + case 'r': case 'R': + *permset |= ARCHIVE_ENTRY_ACL_READ; + break; + case 'w': case 'W': + *permset |= ARCHIVE_ENTRY_ACL_WRITE; + break; + case 'x': case 'X': + *permset |= ARCHIVE_ENTRY_ACL_EXECUTE; + break; + case '-': + break; + default: + return (0); + } + } + return (1); +} + +/* + * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated + * to point to just after the separator. *start points to the first + * character of the matched text and *end just after the last + * character of the matched identifier. In particular *end - *start + * is the length of the field body, not including leading or trailing + * whitespace. + */ +static void +next_field_w(const wchar_t **wp, const wchar_t **start, + const wchar_t **end, wchar_t *sep) +{ + /* Skip leading whitespace to find start of field. */ + while (**wp == L' ' || **wp == L'\t' || **wp == L'\n') { + (*wp)++; + } + *start = *wp; + + /* Scan for the separator. */ + while (**wp != L'\0' && **wp != L',' && **wp != L':' && + **wp != L'\n') { + (*wp)++; + } + *sep = **wp; + + /* Trim trailing whitespace to locate end of field. */ + *end = *wp - 1; + while (**end == L' ' || **end == L'\t' || **end == L'\n') { + (*end)--; + } + (*end)++; + + /* Adjust scanner location. */ + if (**wp != L'\0') + (*wp)++; +} + +/* + * Return true if the characters [start...end) are a prefix of 'test'. + * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc. + */ +static int +prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test) +{ + if (start == end) + return (0); + + if (*start++ != *test++) + return (0); + + while (start < end && *start++ == *test++) + ; + + if (start < end) + return (0); + + return (1); +} + +/* + * Parse a textual ACL. This automatically recognizes and supports + * extensions described above. The 'type' argument is used to + * indicate the type that should be used for any entries not + * explicitly marked as "default:". + */ +int +archive_acl_parse_l(struct archive_acl *acl, + const char *text, int default_type, struct archive_string_conv *sc) +{ + struct { + const char *start; + const char *end; + } field[4], name; + + int fields, n, r, ret = ARCHIVE_OK; + int type, tag, permset, id; + char sep; + + while (text != NULL && *text != '\0') { + /* + * Parse the fields out of the next entry, + * advance 'text' to start of next entry. + */ + fields = 0; + do { + const char *start, *end; + next_field(&text, &start, &end, &sep); + if (fields < 4) { + field[fields].start = start; + field[fields].end = end; + } + ++fields; + } while (sep == ':'); + + /* Set remaining fields to blank. */ + for (n = fields; n < 4; ++n) + field[n].start = field[n].end = NULL; + + /* Check for a numeric ID in field 1 or 3. */ + id = -1; + isint(field[1].start, field[1].end, &id); + /* Field 3 is optional. */ + if (id == -1 && fields > 3) + isint(field[3].start, field[3].end, &id); + + /* + * Solaris extension: "defaultuser::rwx" is the + * default ACL corresponding to "user::rwx", etc. + */ + if (field[0].end - field[0].start > 7 + && memcmp(field[0].start, "default", 7) == 0) { + type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; + field[0].start += 7; + } else + type = default_type; + + name.start = name.end = NULL; + if (prefix(field[0].start, field[0].end, "user")) { + if (!ismode(field[2].start, field[2].end, &permset)) + return (ARCHIVE_WARN); + if (id != -1 || field[1].start < field[1].end) { + tag = ARCHIVE_ENTRY_ACL_USER; + name = field[1]; + } else + tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + } else if (prefix(field[0].start, field[0].end, "group")) { + if (!ismode(field[2].start, field[2].end, &permset)) + return (ARCHIVE_WARN); + if (id != -1 || field[1].start < field[1].end) { + tag = ARCHIVE_ENTRY_ACL_GROUP; + name = field[1]; + } else + tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + } else if (prefix(field[0].start, field[0].end, "other")) { + if (fields == 2 + && field[1].start < field[1].end + && ismode(field[1].start, field[1].end, &permset)) { + /* This is Solaris-style "other:rwx" */ + } else if (fields == 3 + && field[1].start == field[1].end + && field[2].start < field[2].end + && ismode(field[2].start, field[2].end, &permset)) { + /* This is FreeBSD-style "other::rwx" */ + } else + return (ARCHIVE_WARN); + tag = ARCHIVE_ENTRY_ACL_OTHER; + } else if (prefix(field[0].start, field[0].end, "mask")) { + if (fields == 2 + && field[1].start < field[1].end + && ismode(field[1].start, field[1].end, &permset)) { + /* This is Solaris-style "mask:rwx" */ + } else if (fields == 3 + && field[1].start == field[1].end + && field[2].start < field[2].end + && ismode(field[2].start, field[2].end, &permset)) { + /* This is FreeBSD-style "mask::rwx" */ + } else + return (ARCHIVE_WARN); + tag = ARCHIVE_ENTRY_ACL_MASK; + } else + return (ARCHIVE_WARN); + + /* Add entry to the internal list. */ + r = archive_acl_add_entry_len_l(acl, type, permset, + tag, id, name.start, name.end - name.start, sc); + if (r < ARCHIVE_WARN) + return (r); + if (r != ARCHIVE_OK) + ret = ARCHIVE_WARN; + } + return (ret); +} + +/* + * Parse a string to a positive decimal integer. Returns true if + * the string is non-empty and consists only of decimal digits, + * false otherwise. + */ +static int +isint(const char *start, const char *end, int *result) +{ + int n = 0; + if (start >= end) + return (0); + while (start < end) { + if (*start < '0' || *start > '9') + return (0); + if (n > (INT_MAX / 10) || + (n == INT_MAX / 10 && (*start - '0') > INT_MAX % 10)) { + n = INT_MAX; + } else { + n *= 10; + n += *start - '0'; + } + start++; + } + *result = n; + return (1); +} + +/* + * Parse a string as a mode field. Returns true if + * the string is non-empty and consists only of mode characters, + * false otherwise. + */ +static int +ismode(const char *start, const char *end, int *permset) +{ + const char *p; + + if (start >= end) + return (0); + p = start; + *permset = 0; + while (p < end) { + switch (*p++) { + case 'r': case 'R': + *permset |= ARCHIVE_ENTRY_ACL_READ; + break; + case 'w': case 'W': + *permset |= ARCHIVE_ENTRY_ACL_WRITE; + break; + case 'x': case 'X': + *permset |= ARCHIVE_ENTRY_ACL_EXECUTE; + break; + case '-': + break; + default: + return (0); + } + } + return (1); +} + +/* + * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated + * to point to just after the separator. *start points to the first + * character of the matched text and *end just after the last + * character of the matched identifier. In particular *end - *start + * is the length of the field body, not including leading or trailing + * whitespace. + */ +static void +next_field(const char **p, const char **start, + const char **end, char *sep) +{ + /* Skip leading whitespace to find start of field. */ + while (**p == ' ' || **p == '\t' || **p == '\n') { + (*p)++; + } + *start = *p; + + /* Scan for the separator. */ + while (**p != '\0' && **p != ',' && **p != ':' && **p != '\n') { + (*p)++; + } + *sep = **p; + + /* Trim trailing whitespace to locate end of field. */ + *end = *p - 1; + while (**end == ' ' || **end == '\t' || **end == '\n') { + (*end)--; + } + (*end)++; + + /* Adjust scanner location. */ + if (**p != '\0') + (*p)++; +} + +/* + * Return true if the characters [start...end) are a prefix of 'test'. + * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc. + */ +static int +prefix(const char *start, const char *end, const char *test) +{ + if (start == end) + return (0); + + if (*start++ != *test++) + return (0); + + while (start < end && *start++ == *test++) + ; + + if (start < end) + return (0); + + return (1); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_acl_private.h b/Utilities/cmlibarchive/libarchive/archive_acl_private.h new file mode 100644 index 000000000..1421adbf8 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_acl_private.h @@ -0,0 +1,87 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * 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. + * + * $FreeBSD$ + */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_ACL_PRIVATE_H_INCLUDED +#define ARCHIVE_ACL_PRIVATE_H_INCLUDED + +#include "archive_string.h" + +struct archive_acl_entry { + struct archive_acl_entry *next; + int type; /* E.g., access or default */ + int tag; /* E.g., user/group/other/mask */ + int permset; /* r/w/x bits */ + int id; /* uid/gid for user/group */ + struct archive_mstring name; /* uname/gname */ +}; + +struct archive_acl { + mode_t mode; + struct archive_acl_entry *acl_head; + struct archive_acl_entry *acl_p; + int acl_state; /* See acl_next for details. */ + wchar_t *acl_text_w; + char *acl_text; + int acl_types; +}; + +void archive_acl_clear(struct archive_acl *); +void archive_acl_copy(struct archive_acl *, struct archive_acl *); +int archive_acl_count(struct archive_acl *, int); +int archive_acl_reset(struct archive_acl *, int); +int archive_acl_next(struct archive *, struct archive_acl *, int, + int *, int *, int *, int *, const char **); + +int archive_acl_add_entry(struct archive_acl *, int, int, int, int, const char *); +int archive_acl_add_entry_w_len(struct archive_acl *, + int, int, int, int, const wchar_t *, size_t); +int archive_acl_add_entry_len(struct archive_acl *, + int, int, int, int, const char *, size_t); + +const wchar_t *archive_acl_text_w(struct archive *, struct archive_acl *, int); +int archive_acl_text_l(struct archive_acl *, int, const char **, size_t *, + struct archive_string_conv *); + +/* + * Private ACL parser. This is private because it handles some + * very weird formats that clients should not be messing with. + * Clients should only deal with their platform-native formats. + * Because of the need to support many formats cleanly, new arguments + * are likely to get added on a regular basis. Clients who try to use + * this interface are likely to be surprised when it changes. + */ +int archive_acl_parse_w(struct archive_acl *, + const wchar_t *, int /* type */); +int archive_acl_parse_l(struct archive_acl *, + const char *, int /* type */, + struct archive_string_conv *); + +#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_check_magic.c b/Utilities/cmlibarchive/libarchive/archive_check_magic.c index e9dbe5148..91229557a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_check_magic.c +++ b/Utilities/cmlibarchive/libarchive/archive_check_magic.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_check_magic.c,v 1.9 2008/12/06 05:52:01 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_check_magic.c 201089 2009-12-28 02:20:23Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -50,86 +50,125 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_check_magic.c,v 1.9 2008/12/06 05 static void errmsg(const char *m) { - size_t s = strlen(m); - ssize_t written; - - while (s > 0) { - written = write(2, m, strlen(m)); - if (written <= 0) - return; - m += written; - s -= written; - } + size_t s = strlen(m); + ssize_t written; + + while (s > 0) { + written = write(2, m, strlen(m)); + if (written <= 0) + return; + m += written; + s -= written; + } } static void diediedie(void) { #if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - /* Cause a breakpoint exception */ - DebugBreak(); + /* Cause a breakpoint exception */ + DebugBreak(); #endif - *(char *)1 = 1; /* Deliberately segfault and force a coredump. */ - _exit(1); /* If that didn't work, just exit with an error. */ + abort(); /* Terminate the program abnormally. */ } static const char * state_name(unsigned s) { - switch (s) { - case ARCHIVE_STATE_NEW: return ("new"); - case ARCHIVE_STATE_HEADER: return ("header"); - case ARCHIVE_STATE_DATA: return ("data"); - case ARCHIVE_STATE_EOF: return ("eof"); - case ARCHIVE_STATE_CLOSED: return ("closed"); - case ARCHIVE_STATE_FATAL: return ("fatal"); - default: return ("??"); - } + switch (s) { + case ARCHIVE_STATE_NEW: return ("new"); + case ARCHIVE_STATE_HEADER: return ("header"); + case ARCHIVE_STATE_DATA: return ("data"); + case ARCHIVE_STATE_EOF: return ("eof"); + case ARCHIVE_STATE_CLOSED: return ("closed"); + case ARCHIVE_STATE_FATAL: return ("fatal"); + default: return ("??"); + } +} + +static const char * +archive_handle_type_name(unsigned m) +{ + switch (m) { + case ARCHIVE_WRITE_MAGIC: return ("archive_write"); + case ARCHIVE_READ_MAGIC: return ("archive_read"); + case ARCHIVE_WRITE_DISK_MAGIC: return ("archive_write_disk"); + case ARCHIVE_READ_DISK_MAGIC: return ("archive_read_disk"); + default: return NULL; + } } -static void -write_all_states(unsigned int states) +static char * +write_all_states(char *buff, unsigned int states) { - unsigned int lowbit; - - /* A trick for computing the lowest set bit. */ - while ((lowbit = states & (1 + ~states)) != 0) { - states &= ~lowbit; /* Clear the low bit. */ - errmsg(state_name(lowbit)); - if (states != 0) - errmsg("/"); - } + unsigned int lowbit; + + buff[0] = '\0'; + + /* A trick for computing the lowest set bit. */ + while ((lowbit = states & (1 + ~states)) != 0) { + states &= ~lowbit; /* Clear the low bit. */ + strcat(buff, state_name(lowbit)); + if (states != 0) + strcat(buff, "/"); + } + return buff; } /* - * Check magic value and current state; bail if it isn't valid. + * Check magic value and current state. + * Magic value mismatches are fatal and result in calls to abort(). + * State mismatches return ARCHIVE_FATAL. + * Otherwise, returns ARCHIVE_OK. * * This is designed to catch serious programming errors that violate * the libarchive API. */ -void +int __archive_check_magic(struct archive *a, unsigned int magic, unsigned int state, const char *function) { - if (a->magic != magic) { - errmsg("INTERNAL ERROR: Function "); - errmsg(function); - errmsg(" invoked with invalid struct archive structure.\n"); - diediedie(); - } - - if (state == ARCHIVE_STATE_ANY) - return; - - if ((a->state & state) == 0) { - errmsg("INTERNAL ERROR: Function '"); - errmsg(function); - errmsg("' invoked with archive structure in state '"); - write_all_states(a->state); - errmsg("', should be in state '"); - write_all_states(state); - errmsg("'\n"); - diediedie(); - } + char states1[64]; + char states2[64]; + const char *handle_type; + + /* + * If this isn't some form of archive handle, + * then the library user has screwed up so bad that + * we don't even have a reliable way to report an error. + */ + handle_type = archive_handle_type_name(a->magic); + + if (!handle_type) { + errmsg("PROGRAMMER ERROR: Function "); + errmsg(function); + errmsg(" invoked with invalid archive handle.\n"); + diediedie(); + } + + if (a->magic != magic) { + archive_set_error(a, -1, + "PROGRAMMER ERROR: Function '%s' invoked" + " on '%s' archive object, which is not supported.", + function, + handle_type); + a->state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + if ((a->state & state) == 0) { + /* If we're already FATAL, don't overwrite the error. */ + if (a->state != ARCHIVE_STATE_FATAL) + archive_set_error(a, -1, + "INTERNAL ERROR: Function '%s' invoked with" + " archive structure in state '%s'," + " should be in state '%s'", + function, + write_all_states(states1, a->state), + write_all_states(states2, state)); + a->state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + return ARCHIVE_OK; } diff --git a/Utilities/cmlibarchive/libarchive/archive_crc32.h b/Utilities/cmlibarchive/libarchive/archive_crc32.h index 108bc5494..cd633af89 100644 --- a/Utilities/cmlibarchive/libarchive/archive_crc32.h +++ b/Utilities/cmlibarchive/libarchive/archive_crc32.h @@ -21,6 +21,8 @@ * 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. + * + * $FreeBSD: head/lib/libarchive/archive_crc32.h 201102 2009-12-28 03:11:36Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -38,27 +40,39 @@ static unsigned long crc32(unsigned long crc, const void *_p, size_t len) { - unsigned long crc2, b, i; - const unsigned char *p = _p; - static volatile int crc_tbl_inited = 0; - static unsigned long crc_tbl[256]; + unsigned long crc2, b, i; + const unsigned char *p = _p; + static volatile int crc_tbl_inited = 0; + static unsigned long crc_tbl[256]; - if (!crc_tbl_inited) { - for (b = 0; b < 256; ++b) { - crc2 = b; - for (i = 8; i > 0; --i) { - if (crc2 & 1) - crc2 = (crc2 >> 1) ^ 0xedb88320UL; - else - crc2 = (crc2 >> 1); - } - crc_tbl[b] = crc2; - } - crc_tbl_inited = 1; - } + if (!crc_tbl_inited) { + for (b = 0; b < 256; ++b) { + crc2 = b; + for (i = 8; i > 0; --i) { + if (crc2 & 1) + crc2 = (crc2 >> 1) ^ 0xedb88320UL; + else + crc2 = (crc2 >> 1); + } + crc_tbl[b] = crc2; + } + crc_tbl_inited = 1; + } - crc = crc ^ 0xffffffffUL; - while (len--) - crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); - return (crc ^ 0xffffffffUL); + crc = crc ^ 0xffffffffUL; + /* A use of this loop is about 20% - 30% faster than + * no use version in any optimization option of gcc. */ + for (;len >= 8; len -= 8) { + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + } + while (len--) + crc = crc_tbl[(crc ^ *p++) & 0xff] ^ (crc >> 8); + return (crc ^ 0xffffffffUL); } diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto.c b/Utilities/cmlibarchive/libarchive/archive_crypto.c new file mode 100644 index 000000000..2caf57169 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_crypto.c @@ -0,0 +1,1427 @@ +/*- +* Copyright (c) 2003-2007 Tim Kientzle +* Copyright (c) 2011 Andres Mejia +* Copyright (c) 2011 Michihiro NAKAJIMA +* 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" + +#include "archive.h" +#include "archive_crypto_private.h" + +/* In particular, force the configure probe to break if it tries + * to test a combination of OpenSSL and libmd. */ +#if defined(ARCHIVE_CRYPTO_OPENSSL) && defined(ARCHIVE_CRYPTO_LIBMD) +#error Cannot use both OpenSSL and libmd. +#endif + +/* + * Message digest functions for Windows platform. + */ +#if defined(ARCHIVE_CRYPTO_MD5_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA1_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA512_WIN) + +/* + * Initialize a Message digest. + */ +static int +win_crypto_init(Digest_CTX *ctx, ALG_ID algId) +{ + + ctx->valid = 0; + if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + if (GetLastError() != (DWORD)NTE_BAD_KEYSET) + return (ARCHIVE_FAILED); + if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, + PROV_RSA_FULL, CRYPT_NEWKEYSET)) + return (ARCHIVE_FAILED); + } + + if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) { + CryptReleaseContext(ctx->cryptProv, 0); + return (ARCHIVE_FAILED); + } + + ctx->valid = 1; + return (ARCHIVE_OK); +} + +/* + * Update a Message digest. + */ +static int +win_crypto_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len) +{ + + if (!ctx->valid) + return (ARCHIVE_FAILED); + + CryptHashData(ctx->hash, + (unsigned char *)(uintptr_t)buf, + (DWORD)len, 0); + return (ARCHIVE_OK); +} + +static int +win_crypto_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx) +{ + DWORD siglen = bufsize; + + if (!ctx->valid) + return (ARCHIVE_FAILED); + + CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0); + CryptDestroyHash(ctx->hash); + CryptReleaseContext(ctx->cryptProv, 0); + ctx->valid = 0; + return (ARCHIVE_OK); +} + +#endif /* defined(ARCHIVE_CRYPTO_*_WIN) */ + + +/* MD5 implementations */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBC) + +static int +__archive_libc_md5init(archive_md5_ctx *ctx) +{ + MD5Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + MD5Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_md5final(archive_md5_ctx *ctx, void *md) +{ + MD5Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD) + +static int +__archive_libmd_md5init(archive_md5_ctx *ctx) +{ + MD5Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + MD5Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_md5final(archive_md5_ctx *ctx, void *md) +{ + MD5Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) + +static int +__archive_libsystem_md5init(archive_md5_ctx *ctx) +{ + CC_MD5_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + CC_MD5_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_md5final(archive_md5_ctx *ctx, void *md) +{ + CC_MD5_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE) + +static int +__archive_nettle_md5init(archive_md5_ctx *ctx) +{ + md5_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + md5_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_md5final(archive_md5_ctx *ctx, void *md) +{ + md5_digest(ctx, MD5_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL) + +static int +__archive_openssl_md5init(archive_md5_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_md5()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_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 + * archive_write_set_format_xar.c + */ + if (ctx->digest) + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_MD5_WIN) + +static int +__archive_windowsapi_md5init(archive_md5_ctx *ctx) +{ + return (win_crypto_init(ctx, CALG_MD5)); +} + +static int +__archive_windowsapi_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) +{ + return (win_crypto_Final(md, 16, ctx)); +} + +#else + +static int +__archive_stub_md5init(archive_md5_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_md5update(archive_md5_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_md5final(archive_md5_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* RIPEMD160 implementations */ +#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) + +static int +__archive_libc_ripemd160init(archive_rmd160_ctx *ctx) +{ + RMD160Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, + size_t insize) +{ + RMD160Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_ripemd160final(archive_rmd160_ctx *ctx, void *md) +{ + RMD160Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD) + +static int +__archive_libmd_ripemd160init(archive_rmd160_ctx *ctx) +{ + RIPEMD160_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, + size_t insize) +{ + RIPEMD160_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_ripemd160final(archive_rmd160_ctx *ctx, void *md) +{ + RIPEMD160_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE) + +static int +__archive_nettle_ripemd160init(archive_rmd160_ctx *ctx) +{ + ripemd160_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, + size_t insize) +{ + ripemd160_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_ripemd160final(archive_rmd160_ctx *ctx, void *md) +{ + ripemd160_digest(ctx, RIPEMD160_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) + +static int +__archive_openssl_ripemd160init(archive_rmd160_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_ripemd160()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_ripemd160final(archive_rmd160_ctx *ctx, void *md) +{ + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#else + +static int +__archive_stub_ripemd160init(archive_rmd160_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_ripemd160update(archive_rmd160_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_ripemd160final(archive_rmd160_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* SHA1 implementations */ +#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) + +static int +__archive_libc_sha1init(archive_sha1_ctx *ctx) +{ + SHA1Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + SHA1Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha1final(archive_sha1_ctx *ctx, void *md) +{ + SHA1Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD) + +static int +__archive_libmd_sha1init(archive_sha1_ctx *ctx) +{ + SHA1_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + SHA1_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha1final(archive_sha1_ctx *ctx, void *md) +{ + SHA1_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) + +static int +__archive_libsystem_sha1init(archive_sha1_ctx *ctx) +{ + CC_SHA1_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + CC_SHA1_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha1final(archive_sha1_ctx *ctx, void *md) +{ + CC_SHA1_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE) + +static int +__archive_nettle_sha1init(archive_sha1_ctx *ctx) +{ + sha1_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + sha1_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha1final(archive_sha1_ctx *ctx, void *md) +{ + sha1_digest(ctx, SHA1_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) + +static int +__archive_openssl_sha1init(archive_sha1_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_sha1()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_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 + * archive_write_set_format_xar.c + */ + if (ctx->digest) + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA1_WIN) + +static int +__archive_windowsapi_sha1init(archive_sha1_ctx *ctx) +{ + return (win_crypto_init(ctx, CALG_SHA1)); +} + +static int +__archive_windowsapi_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) +{ + return (win_crypto_Final(md, 20, ctx)); +} + +#else + +static int +__archive_stub_sha1init(archive_sha1_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha1update(archive_sha1_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha1final(archive_sha1_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* SHA256 implementations */ +#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) + +static int +__archive_libc_sha256init(archive_sha256_ctx *ctx) +{ + SHA256_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + SHA256_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha256final(archive_sha256_ctx *ctx, void *md) +{ + SHA256_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2) + +static int +__archive_libc2_sha256init(archive_sha256_ctx *ctx) +{ + SHA256Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + SHA256Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha256final(archive_sha256_ctx *ctx, void *md) +{ + SHA256Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3) + +static int +__archive_libc3_sha256init(archive_sha256_ctx *ctx) +{ + SHA256Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + SHA256Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha256final(archive_sha256_ctx *ctx, void *md) +{ + SHA256Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD) + +static int +__archive_libmd_sha256init(archive_sha256_ctx *ctx) +{ + SHA256_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + SHA256_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha256final(archive_sha256_ctx *ctx, void *md) +{ + SHA256_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) + +static int +__archive_libsystem_sha256init(archive_sha256_ctx *ctx) +{ + CC_SHA256_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + CC_SHA256_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha256final(archive_sha256_ctx *ctx, void *md) +{ + CC_SHA256_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE) + +static int +__archive_nettle_sha256init(archive_sha256_ctx *ctx) +{ + sha256_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + sha256_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha256final(archive_sha256_ctx *ctx, void *md) +{ + sha256_digest(ctx, SHA256_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) + +static int +__archive_openssl_sha256init(archive_sha256_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_sha256()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha256final(archive_sha256_ctx *ctx, void *md) +{ + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA256_WIN) + +static int +__archive_windowsapi_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, + size_t insize) +{ + return (win_crypto_Update(ctx, indata, insize)); +} + +static int +__archive_windowsapi_sha256final(archive_sha256_ctx *ctx, void *md) +{ + return (win_crypto_Final(md, 32, ctx)); +} + +#else + +static int +__archive_stub_sha256init(archive_sha256_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha256update(archive_sha256_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha256final(archive_sha256_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* SHA384 implementations */ +#if defined(ARCHIVE_CRYPTO_SHA384_LIBC) + +static int +__archive_libc_sha384init(archive_sha384_ctx *ctx) +{ + SHA384_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + SHA384_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha384final(archive_sha384_ctx *ctx, void *md) +{ + SHA384_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2) + +static int +__archive_libc2_sha384init(archive_sha384_ctx *ctx) +{ + SHA384Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + SHA384Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha384final(archive_sha384_ctx *ctx, void *md) +{ + SHA384Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3) + +static int +__archive_libc3_sha384init(archive_sha384_ctx *ctx) +{ + SHA384Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + SHA384Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha384final(archive_sha384_ctx *ctx, void *md) +{ + SHA384Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) + +static int +__archive_libsystem_sha384init(archive_sha384_ctx *ctx) +{ + CC_SHA384_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + CC_SHA384_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha384final(archive_sha384_ctx *ctx, void *md) +{ + CC_SHA384_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE) + +static int +__archive_nettle_sha384init(archive_sha384_ctx *ctx) +{ + sha384_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + sha384_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha384final(archive_sha384_ctx *ctx, void *md) +{ + sha384_digest(ctx, SHA384_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) + +static int +__archive_openssl_sha384init(archive_sha384_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_sha384()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha384final(archive_sha384_ctx *ctx, void *md) +{ + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA384_WIN) + +static int +__archive_windowsapi_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, + size_t insize) +{ + return (win_crypto_Update(ctx, indata, insize)); +} + +static int +__archive_windowsapi_sha384final(archive_sha384_ctx *ctx, void *md) +{ + return (win_crypto_Final(md, 48, ctx)); +} + +#else + +static int +__archive_stub_sha384init(archive_sha384_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha384update(archive_sha384_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha384final(archive_sha384_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* SHA512 implementations */ +#if defined(ARCHIVE_CRYPTO_SHA512_LIBC) + +static int +__archive_libc_sha512init(archive_sha512_ctx *ctx) +{ + SHA512_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + SHA512_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc_sha512final(archive_sha512_ctx *ctx, void *md) +{ + SHA512_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2) + +static int +__archive_libc2_sha512init(archive_sha512_ctx *ctx) +{ + SHA512Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + SHA512Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc2_sha512final(archive_sha512_ctx *ctx, void *md) +{ + SHA512Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3) + +static int +__archive_libc3_sha512init(archive_sha512_ctx *ctx) +{ + SHA512Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + SHA512Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libc3_sha512final(archive_sha512_ctx *ctx, void *md) +{ + SHA512Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD) + +static int +__archive_libmd_sha512init(archive_sha512_ctx *ctx) +{ + SHA512_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + SHA512_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libmd_sha512final(archive_sha512_ctx *ctx, void *md) +{ + SHA512_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) + +static int +__archive_libsystem_sha512init(archive_sha512_ctx *ctx) +{ + CC_SHA512_Init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + CC_SHA512_Update(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_libsystem_sha512final(archive_sha512_ctx *ctx, void *md) +{ + CC_SHA512_Final(md, ctx); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE) + +static int +__archive_nettle_sha512init(archive_sha512_ctx *ctx) +{ + sha512_init(ctx); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + sha512_update(ctx, insize, indata); + return (ARCHIVE_OK); +} + +static int +__archive_nettle_sha512final(archive_sha512_ctx *ctx, void *md) +{ + sha512_digest(ctx, SHA512_DIGEST_SIZE, md); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) + +static int +__archive_openssl_sha512init(archive_sha512_ctx *ctx) +{ + EVP_DigestInit(ctx, EVP_sha512()); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + EVP_DigestUpdate(ctx, indata, insize); + return (ARCHIVE_OK); +} + +static int +__archive_openssl_sha512final(archive_sha512_ctx *ctx, void *md) +{ + EVP_DigestFinal(ctx, md, NULL); + return (ARCHIVE_OK); +} + +#elif defined(ARCHIVE_CRYPTO_SHA512_WIN) + +static int +__archive_windowsapi_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, + size_t insize) +{ + return (win_crypto_Update(ctx, indata, insize)); +} + +static int +__archive_windowsapi_sha512final(archive_sha512_ctx *ctx, void *md) +{ + return (win_crypto_Final(md, 64, ctx)); +} + +#else + +static int +__archive_stub_sha512init(archive_sha512_ctx *ctx) +{ + (void)ctx; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha512update(archive_sha512_ctx *ctx, const void *indata, + size_t insize) +{ + (void)ctx; /* UNUSED */ + (void)indata; /* UNUSED */ + (void)insize; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +static int +__archive_stub_sha512final(archive_sha512_ctx *ctx, void *md) +{ + (void)ctx; /* UNUSED */ + (void)md; /* UNUSED */ + return (ARCHIVE_FAILED); +} + +#endif + +/* NOTE: Crypto functions are set based on availability and by the following + * order of preference. + * 1. libc + * 2. libc2 + * 3. libc3 + * 4. libSystem + * 5. OpenSSL + * 6. Windows API + */ +const struct archive_crypto __archive_crypto = +{ +/* 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_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 + +/* 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_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 + +/* 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_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 + +/* 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_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 + +/* 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_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 + +/* 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_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 +}; diff --git a/Utilities/cmlibarchive/libarchive/archive_crypto_private.h b/Utilities/cmlibarchive/libarchive/archive_crypto_private.h new file mode 100644 index 000000000..f8b1fb3c3 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_crypto_private.h @@ -0,0 +1,376 @@ +/*- +* Copyright (c) 2003-2007 Tim Kientzle +* Copyright (c) 2011 Andres Mejia +* 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. +*/ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_CRYPTO_PRIVATE_H_INCLUDED +#define ARCHIVE_CRYPTO_PRIVATE_H_INCLUDED + +/* + * Crypto support in various Operating Systems: + * + * NetBSD: + * - MD5 and SHA1 in libc: without _ after algorithm name + * - SHA2 in libc: with _ after algorithm name + * + * OpenBSD: + * - MD5, SHA1 and SHA2 in libc: without _ after algorithm name + * - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name + * + * DragonFly and FreeBSD: + * - MD5 libmd: without _ after algorithm name + * - SHA1, SHA256 and SHA512 in libmd: with _ after algorithm name + * + * Mac OS X (10.4 and later): + * - MD5, SHA1 and SHA2 in libSystem: with CC_ prefix and _ after algorithm name + * + * OpenSSL: + * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name + * + * Windows: + * - MD5, SHA1 and SHA2 in archive_crypto.c using Windows crypto API + */ + +/* libc crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBC) +#include +#endif +#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBC3) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBC3) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBC3) +#include +#endif + +/* libmd crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_RMD160_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_SHA1_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBMD) +#define ARCHIVE_CRYPTO_LIBMD 1 +#endif + +#if defined(ARCHIVE_CRYPTO_MD5_LIBMD) +#include +#endif +#if defined(ARCHIVE_CRYPTO_RMD160_LIBMD) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA1_LIBMD) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA256_LIBMD) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA512_LIBMD) +#include +#endif + +/* libSystem crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) +#include +#endif + +/* Nettle crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_NETTLE) +#include +#endif +#if defined(ARCHIVE_CRYPTO_RMD160_NETTLE) +#include +#endif +#if defined(ARCHIVE_CRYPTO_SHA1_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA256_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA384_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA512_NETTLE) +#include +#endif + +/* OpenSSL crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) +#define ARCHIVE_CRYPTO_OPENSSL 1 +#include +#endif + +/* Windows crypto headers */ +#if defined(ARCHIVE_CRYPTO_MD5_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA1_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\ + defined(ARCHIVE_CRYPTO_SHA512_WIN) +#include +typedef struct { + int valid; + HCRYPTPROV cryptProv; + HCRYPTHASH hash; +} Digest_CTX; +#endif + +/* typedefs */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBC) +typedef MD5_CTX archive_md5_ctx; +#elif defined(ARCHIVE_CRYPTO_MD5_LIBMD) +typedef MD5_CTX archive_md5_ctx; +#elif defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) +typedef CC_MD5_CTX archive_md5_ctx; +#elif defined(ARCHIVE_CRYPTO_MD5_NETTLE) +typedef struct md5_ctx archive_md5_ctx; +#elif defined(ARCHIVE_CRYPTO_MD5_OPENSSL) +typedef EVP_MD_CTX archive_md5_ctx; +#elif defined(ARCHIVE_CRYPTO_MD5_WIN) +typedef Digest_CTX archive_md5_ctx; +#else +typedef unsigned char archive_md5_ctx; +#endif + +#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) +typedef RMD160_CTX archive_rmd160_ctx; +#elif defined(ARCHIVE_CRYPTO_RMD160_LIBMD) +typedef RIPEMD160_CTX archive_rmd160_ctx; +#elif defined(ARCHIVE_CRYPTO_RMD160_NETTLE) +typedef struct ripemd160_ctx archive_rmd160_ctx; +#elif defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) +typedef EVP_MD_CTX archive_rmd160_ctx; +#else +typedef unsigned char archive_rmd160_ctx; +#endif + +#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) +typedef SHA1_CTX archive_sha1_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA1_LIBMD) +typedef SHA1_CTX archive_sha1_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) +typedef CC_SHA1_CTX archive_sha1_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA1_NETTLE) +typedef struct sha1_ctx archive_sha1_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) +typedef EVP_MD_CTX archive_sha1_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA1_WIN) +typedef Digest_CTX archive_sha1_ctx; +#else +typedef unsigned char archive_sha1_ctx; +#endif + +#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) +typedef SHA256_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC2) +typedef SHA256_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBC3) +typedef SHA2_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBMD) +typedef SHA256_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) +typedef CC_SHA256_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_NETTLE) +typedef struct sha256_ctx archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) +typedef EVP_MD_CTX archive_sha256_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA256_WIN) +typedef Digest_CTX archive_sha256_ctx; +#else +typedef unsigned char archive_sha256_ctx; +#endif + +#if defined(ARCHIVE_CRYPTO_SHA384_LIBC) +typedef SHA384_CTX archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC2) +typedef SHA384_CTX archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBC3) +typedef SHA2_CTX archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) +typedef CC_SHA512_CTX archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_NETTLE) +typedef struct sha384_ctx archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) +typedef EVP_MD_CTX archive_sha384_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA384_WIN) +typedef Digest_CTX archive_sha384_ctx; +#else +typedef unsigned char archive_sha384_ctx; +#endif + +#if defined(ARCHIVE_CRYPTO_SHA512_LIBC) +typedef SHA512_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC2) +typedef SHA512_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBC3) +typedef SHA2_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBMD) +typedef SHA512_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) +typedef CC_SHA512_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_NETTLE) +typedef struct sha512_ctx archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) +typedef EVP_MD_CTX archive_sha512_ctx; +#elif defined(ARCHIVE_CRYPTO_SHA512_WIN) +typedef Digest_CTX archive_sha512_ctx; +#else +typedef unsigned char archive_sha512_ctx; +#endif + +/* defines */ +#if defined(ARCHIVE_CRYPTO_MD5_LIBC) ||\ + defined(ARCHIVE_CRYPTO_MD5_LIBMD) || \ + defined(ARCHIVE_CRYPTO_MD5_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_MD5_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_MD5_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_MD5_WIN) +#define ARCHIVE_HAS_MD5 +#endif +#define archive_md5_init(ctx)\ + __archive_crypto.md5init(ctx) +#define archive_md5_final(ctx, md)\ + __archive_crypto.md5final(ctx, md) +#define archive_md5_update(ctx, buf, n)\ + __archive_crypto.md5update(ctx, buf, n) + +#if defined(ARCHIVE_CRYPTO_RMD160_LIBC) ||\ + defined(ARCHIVE_CRYPTO_RMD160_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_RMD160_OPENSSL) +#define ARCHIVE_HAS_RMD160 +#endif +#define archive_rmd160_init(ctx)\ + __archive_crypto.rmd160init(ctx) +#define archive_rmd160_final(ctx, md)\ + __archive_crypto.rmd160final(ctx, md) +#define archive_rmd160_update(ctx, buf, n)\ + __archive_crypto.rmd160update(ctx, buf, n) + +#if defined(ARCHIVE_CRYPTO_SHA1_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA1_LIBMD) || \ + defined(ARCHIVE_CRYPTO_SHA1_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA1_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA1_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA1_WIN) +#define ARCHIVE_HAS_SHA1 +#endif +#define archive_sha1_init(ctx)\ + __archive_crypto.sha1init(ctx) +#define archive_sha1_final(ctx, md)\ + __archive_crypto.sha1final(ctx, md) +#define archive_sha1_update(ctx, buf, n)\ + __archive_crypto.sha1update(ctx, buf, n) + +#if defined(ARCHIVE_CRYPTO_SHA256_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBC3) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_SHA256_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA256_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA256_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA256_WIN) +#define ARCHIVE_HAS_SHA256 +#endif +#define archive_sha256_init(ctx)\ + __archive_crypto.sha256init(ctx) +#define archive_sha256_final(ctx, md)\ + __archive_crypto.sha256final(ctx, md) +#define archive_sha256_update(ctx, buf, n)\ + __archive_crypto.sha256update(ctx, buf, n) + +#if defined(ARCHIVE_CRYPTO_SHA384_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBC3) ||\ + defined(ARCHIVE_CRYPTO_SHA384_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA384_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA384_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA384_WIN) +#define ARCHIVE_HAS_SHA384 +#endif +#define archive_sha384_init(ctx)\ + __archive_crypto.sha384init(ctx) +#define archive_sha384_final(ctx, md)\ + __archive_crypto.sha384final(ctx, md) +#define archive_sha384_update(ctx, buf, n)\ + __archive_crypto.sha384update(ctx, buf, n) + +#if defined(ARCHIVE_CRYPTO_SHA512_LIBC) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBC2) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBC3) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBMD) ||\ + defined(ARCHIVE_CRYPTO_SHA512_LIBSYSTEM) ||\ + defined(ARCHIVE_CRYPTO_SHA512_NETTLE) ||\ + defined(ARCHIVE_CRYPTO_SHA512_OPENSSL) ||\ + defined(ARCHIVE_CRYPTO_SHA512_WIN) +#define ARCHIVE_HAS_SHA512 +#endif +#define archive_sha512_init(ctx)\ + __archive_crypto.sha512init(ctx) +#define archive_sha512_final(ctx, md)\ + __archive_crypto.sha512final(ctx, md) +#define archive_sha512_update(ctx, buf, n)\ + __archive_crypto.sha512update(ctx, buf, n) + +/* Minimal interface to crypto functionality for internal use in libarchive */ +struct archive_crypto +{ + /* Message Digest */ + int (*md5init)(archive_md5_ctx *ctx); + int (*md5update)(archive_md5_ctx *, const void *, size_t); + int (*md5final)(archive_md5_ctx *, void *); + int (*rmd160init)(archive_rmd160_ctx *); + int (*rmd160update)(archive_rmd160_ctx *, const void *, size_t); + int (*rmd160final)(archive_rmd160_ctx *, void *); + int (*sha1init)(archive_sha1_ctx *); + int (*sha1update)(archive_sha1_ctx *, const void *, size_t); + int (*sha1final)(archive_sha1_ctx *, void *); + int (*sha256init)(archive_sha256_ctx *); + int (*sha256update)(archive_sha256_ctx *, const void *, size_t); + int (*sha256final)(archive_sha256_ctx *, void *); + int (*sha384init)(archive_sha384_ctx *); + int (*sha384update)(archive_sha384_ctx *, const void *, size_t); + int (*sha384final)(archive_sha384_ctx *, void *); + int (*sha512init)(archive_sha512_ctx *); + int (*sha512update)(archive_sha512_ctx *, const void *, size_t); + int (*sha512final)(archive_sha512_ctx *, void *); +}; + +extern const struct archive_crypto __archive_crypto; + +#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_endian.h b/Utilities/cmlibarchive/libarchive/archive_endian.h index 58abee6df..1dd8536c4 100644 --- a/Utilities/cmlibarchive/libarchive/archive_endian.h +++ b/Utilities/cmlibarchive/libarchive/archive_endian.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_endian.h,v 1.4 2008/12/06 06:12:24 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_endian.h 201085 2009-12-28 02:17:15Z kientzle $ * * Borrowed from FreeBSD's */ @@ -43,11 +43,10 @@ * Disabling inline keyword for compilers known to choke on it: * - Watcom C++ in C code. (For any version?) * - SGI MIPSpro - * - SunPro C * - Microsoft Visual C++ 6.0 (supposedly newer versions too) */ -#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) || defined(__SUNPRO_C) -#define inline +#if defined(__WATCOMC__) || defined(__sgi) || defined(__hpux) || defined(__BORLANDC__) +#define inline #elif defined(_MSC_VER) || defined(__osf__) #define inline __inline #endif @@ -57,107 +56,107 @@ static inline uint16_t archive_be16dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return ((p[0] << 8) | p[1]); + return ((p[0] << 8) | p[1]); } static inline uint32_t archive_be32dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); + return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } static inline uint64_t archive_be64dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4)); + return (((uint64_t)archive_be32dec(p) << 32) | archive_be32dec(p + 4)); } static inline uint16_t archive_le16dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return ((p[1] << 8) | p[0]); + return ((p[1] << 8) | p[0]); } static inline uint32_t archive_le32dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); + return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); } static inline uint64_t archive_le64dec(const void *pp) { - unsigned char const *p = (unsigned char const *)pp; + unsigned char const *p = (unsigned char const *)pp; - return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p)); + return (((uint64_t)archive_le32dec(p + 4) << 32) | archive_le32dec(p)); } static inline void archive_be16enc(void *pp, uint16_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - p[0] = (u >> 8) & 0xff; - p[1] = u & 0xff; + p[0] = (u >> 8) & 0xff; + p[1] = u & 0xff; } static inline void archive_be32enc(void *pp, uint32_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - p[0] = (u >> 24) & 0xff; - p[1] = (u >> 16) & 0xff; - p[2] = (u >> 8) & 0xff; - p[3] = u & 0xff; + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; } static inline void archive_be64enc(void *pp, uint64_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - archive_be32enc(p, u >> 32); - archive_be32enc(p + 4, u & 0xffffffff); + archive_be32enc(p, u >> 32); + archive_be32enc(p + 4, u & 0xffffffff); } static inline void archive_le16enc(void *pp, uint16_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - p[0] = u & 0xff; - p[1] = (u >> 8) & 0xff; + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; } static inline void archive_le32enc(void *pp, uint32_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - p[0] = u & 0xff; - p[1] = (u >> 8) & 0xff; - p[2] = (u >> 16) & 0xff; - p[3] = (u >> 24) & 0xff; + p[0] = u & 0xff; + p[1] = (u >> 8) & 0xff; + p[2] = (u >> 16) & 0xff; + p[3] = (u >> 24) & 0xff; } static inline void archive_le64enc(void *pp, uint64_t u) { - unsigned char *p = (unsigned char *)pp; + unsigned char *p = (unsigned char *)pp; - archive_le32enc(p, u & 0xffffffff); - archive_le32enc(p + 4, u >> 32); + archive_le32enc(p, u & 0xffffffff); + archive_le32enc(p + 4, u >> 32); } #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.3 b/Utilities/cmlibarchive/libarchive/archive_entry.3 index 9ceb18b7a..10e3c34cc 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.3 +++ b/Utilities/cmlibarchive/libarchive/archive_entry.3 @@ -1,4 +1,5 @@ .\" Copyright (c) 2003-2007 Tim Kientzle +.\" Copyright (c) 2010 Joerg Sonnenberger .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,267 +25,25 @@ .\" .\" $FreeBSD: src/lib/libarchive/archive_entry.3,v 1.18 2008/05/26 17:00:22 kientzle Exp $ .\" -.Dd May 12, 2008 -.Dt archive_entry 3 +.Dd Feburary 22, 2010 +.Dt ARCHIVE_ENTRY 3 .Os .Sh NAME -.Nm archive_entry_acl_add_entry , -.Nm archive_entry_acl_add_entry_w , -.Nm archive_entry_acl_clear , -.Nm archive_entry_acl_count , -.Nm archive_entry_acl_next , -.Nm archive_entry_acl_next_w , -.Nm archive_entry_acl_reset , -.Nm archive_entry_acl_text_w , -.Nm archive_entry_atime , -.Nm archive_entry_atime_nsec , .Nm archive_entry_clear , .Nm archive_entry_clone , -.Nm archive_entry_copy_fflags_text , -.Nm archive_entry_copy_fflags_text_w , -.Nm archive_entry_copy_gname , -.Nm archive_entry_copy_gname_w , -.Nm archive_entry_copy_hardlink , -.Nm archive_entry_copy_hardlink_w , -.Nm archive_entry_copy_link , -.Nm archive_entry_copy_link_w , -.Nm archive_entry_copy_pathname_w , -.Nm archive_entry_copy_sourcepath , -.Nm archive_entry_copy_stat , -.Nm archive_entry_copy_symlink , -.Nm archive_entry_copy_symlink_w , -.Nm archive_entry_copy_uname , -.Nm archive_entry_copy_uname_w , -.Nm archive_entry_dev , -.Nm archive_entry_devmajor , -.Nm archive_entry_devminor , -.Nm archive_entry_filetype , -.Nm archive_entry_fflags , -.Nm archive_entry_fflags_text , .Nm archive_entry_free , -.Nm archive_entry_gid , -.Nm archive_entry_gname , -.Nm archive_entry_hardlink , -.Nm archive_entry_ino , -.Nm archive_entry_mode , -.Nm archive_entry_mtime , -.Nm archive_entry_mtime_nsec , -.Nm archive_entry_nlink , .Nm archive_entry_new , -.Nm archive_entry_pathname , -.Nm archive_entry_pathname_w , -.Nm archive_entry_rdev , -.Nm archive_entry_rdevmajor , -.Nm archive_entry_rdevminor , -.Nm archive_entry_set_atime , -.Nm archive_entry_set_ctime , -.Nm archive_entry_set_dev , -.Nm archive_entry_set_devmajor , -.Nm archive_entry_set_devminor , -.Nm archive_entry_set_filetype , -.Nm archive_entry_set_fflags , -.Nm archive_entry_set_gid , -.Nm archive_entry_set_gname , -.Nm archive_entry_set_hardlink , -.Nm archive_entry_set_link , -.Nm archive_entry_set_mode , -.Nm archive_entry_set_mtime , -.Nm archive_entry_set_pathname , -.Nm archive_entry_set_rdevmajor , -.Nm archive_entry_set_rdevminor , -.Nm archive_entry_set_size , -.Nm archive_entry_set_symlink , -.Nm archive_entry_set_uid , -.Nm archive_entry_set_uname , -.Nm archive_entry_size , -.Nm archive_entry_sourcepath , -.Nm archive_entry_stat , -.Nm archive_entry_symlink , -.Nm archive_entry_uid , -.Nm archive_entry_uname -.Nd functions for manipulating archive entry descriptions +.Nd functions for managing archive entry descriptions .Sh SYNOPSIS .In archive_entry.h -.Ft void -.Fo archive_entry_acl_add_entry -.Fa "struct archive_entry *" -.Fa "int type" -.Fa "int permset" -.Fa "int tag" -.Fa "int qual" -.Fa "const char *name" -.Fc -.Ft void -.Fo archive_entry_acl_add_entry_w -.Fa "struct archive_entry *" -.Fa "int type" -.Fa "int permset" -.Fa "int tag" -.Fa "int qual" -.Fa "const wchar_t *name" -.Fc -.Ft void -.Fn archive_entry_acl_clear "struct archive_entry *" -.Ft int -.Fn archive_entry_acl_count "struct archive_entry *" "int type" -.Ft int -.Fo archive_entry_acl_next -.Fa "struct archive_entry *" -.Fa "int want_type" -.Fa "int *type" -.Fa "int *permset" -.Fa "int *tag" -.Fa "int *qual" -.Fa "const char **name" -.Fc -.Ft int -.Fo archive_entry_acl_next_w -.Fa "struct archive_entry *" -.Fa "int want_type" -.Fa "int *type" -.Fa "int *permset" -.Fa "int *tag" -.Fa "int *qual" -.Fa "const wchar_t **name" -.Fc -.Ft int -.Fn archive_entry_acl_reset "struct archive_entry *" "int want_type" -.Ft const wchar_t * -.Fn archive_entry_acl_text_w "struct archive_entry *" "int flags" -.Ft time_t -.Fn archive_entry_atime "struct archive_entry *" -.Ft long -.Fn archive_entry_atime_nsec "struct archive_entry *" .Ft "struct archive_entry *" .Fn archive_entry_clear "struct archive_entry *" .Ft struct archive_entry * .Fn archive_entry_clone "struct archive_entry *" -.Ft const char * * -.Fn archive_entry_copy_fflags_text_w "struct archive_entry *" "const char *" -.Ft const wchar_t * -.Fn archive_entry_copy_fflags_text_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_gname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_gname_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_hardlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_hardlink_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_sourcepath "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_pathname_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_stat "struct archive_entry *" "const struct stat *" -.Ft void -.Fn archive_entry_copy_symlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_symlink_w "struct archive_entry *" "const wchar_t *" -.Ft void -.Fn archive_entry_copy_uname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_copy_uname_w "struct archive_entry *" "const wchar_t *" -.Ft dev_t -.Fn archive_entry_dev "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_devmajor "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_devminor "struct archive_entry *" -.Ft mode_t -.Fn archive_entry_filetype "struct archive_entry *" -.Ft void -.Fo archive_entry_fflags -.Fa "struct archive_entry *" -.Fa "unsigned long *set" -.Fa "unsigned long *clear" -.Fc -.Ft const char * -.Fn archive_entry_fflags_text "struct archive_entry *" .Ft void .Fn archive_entry_free "struct archive_entry *" -.Ft const char * -.Fn archive_entry_gname "struct archive_entry *" -.Ft const char * -.Fn archive_entry_hardlink "struct archive_entry *" -.Ft ino_t -.Fn archive_entry_ino "struct archive_entry *" -.Ft mode_t -.Fn archive_entry_mode "struct archive_entry *" -.Ft time_t -.Fn archive_entry_mtime "struct archive_entry *" -.Ft long -.Fn archive_entry_mtime_nsec "struct archive_entry *" -.Ft unsigned int -.Fn archive_entry_nlink "struct archive_entry *" .Ft struct archive_entry * .Fn archive_entry_new "void" -.Ft const char * -.Fn archive_entry_pathname "struct archive_entry *" -.Ft const wchar_t * -.Fn archive_entry_pathname_w "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdev "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdevmajor "struct archive_entry *" -.Ft dev_t -.Fn archive_entry_rdevminor "struct archive_entry *" -.Ft void -.Fn archive_entry_set_dev "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_devmajor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_devminor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_filetype "struct archive_entry *" "unsigned int" -.Ft void -.Fo archive_entry_set_fflags -.Fa "struct archive_entry *" -.Fa "unsigned long set" -.Fa "unsigned long clear" -.Fc -.Ft void -.Fn archive_entry_set_gid "struct archive_entry *" "gid_t" -.Ft void -.Fn archive_entry_set_gname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_hardlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_ino "struct archive_entry *" "unsigned long" -.Ft void -.Fn archive_entry_set_link "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_mode "struct archive_entry *" "mode_t" -.Ft void -.Fn archive_entry_set_mtime "struct archive_entry *" "time_t" "long nanos" -.Ft void -.Fn archive_entry_set_nlink "struct archive_entry *" "unsigned int" -.Ft void -.Fn archive_entry_set_pathname "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_rdev "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_rdevmajor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_rdevminor "struct archive_entry *" "dev_t" -.Ft void -.Fn archive_entry_set_size "struct archive_entry *" "int64_t" -.Ft void -.Fn archive_entry_set_symlink "struct archive_entry *" "const char *" -.Ft void -.Fn archive_entry_set_uid "struct archive_entry *" "uid_t" -.Ft void -.Fn archive_entry_set_uname "struct archive_entry *" "const char *" -.Ft int64_t -.Fn archive_entry_size "struct archive_entry *" -.Ft const char * -.Fn archive_entry_sourcepath "struct archive_entry *" -.Ft const struct stat * -.Fn archive_entry_stat "struct archive_entry *" -.Ft const char * -.Fn archive_entry_symlink "struct archive_entry *" -.Ft const char * -.Fn archive_entry_uname "struct archive_entry *" .Sh DESCRIPTION These functions create and manipulate data objects that represent entries within an archive. @@ -320,8 +79,24 @@ Allocate and return a blank .Tn struct archive_entry object. .El -.Ss Set and Get Functions -Most of the functions here set or read entries in an object. +.Ss Function groups +Due to high number of functions, the accessor functions can be found in +man pages grouped by the purpose. +.Bl -tag -width ".Xr archive_entry_perms 3" +.It Xr archive_entry_acl 3 +Access Control List manipulation +.It Xr archive_entry_paths 3 +Path name manipulation +.It Xr archive_entry_perms 3 +User, group and mode manipulation +.It Xr archive_entry_stat 3 +Functions not in the other groups and copying to/from +.Vt struct stat . +.It Xr archive_entry_time 3 +Time field manipulation +.El +.Pp +Most of the functions set or read entries in an object. Such functions have one of the following forms: .Bl -tag -compact -width indent .It Fn archive_entry_set_XXXX @@ -350,75 +125,15 @@ Similarly, if you store a wide string and then store a narrow string for the same data, the previously-set wide string will be discarded in favor of the new data. .Pp -There are a few set/get functions that merit additional description: -.Bl -tag -compact -width indent -.It Fn archive_entry_set_link -This function sets the symlink field if it is already set. -Otherwise, it sets the hardlink field. -.El -.Ss File Flags -File flags are transparently converted between a bitmap -representation and a textual format. -For example, if you set the bitmap and ask for text, the library -will build a canonical text format. -However, if you set a text format and request a text format, -you will get back the same text, even if it is ill-formed. -If you need to canonicalize a textual flags string, you should first set the -text form, then request the bitmap form, then use that to set the bitmap form. -Setting the bitmap format will clear the internal text representation -and force it to be reconstructed when you next request the text form. -.Pp -The bitmap format consists of two integers, one containing bits -that should be set, the other specifying bits that should be -cleared. -Bits not mentioned in either bitmap will be ignored. -Usually, the bitmap of bits to be cleared will be set to zero. -In unusual circumstances, you can force a fully-specified set -of file flags by setting the bitmap of flags to clear to the complement -of the bitmap of flags to set. -(This differs from -.Xr fflagstostr 3 , -which only includes names for set bits.) -Converting a bitmap to a textual string is a platform-specific -operation; bits that are not meaningful on the current platform -will be ignored. -.Pp -The canonical text format is a comma-separated list of flag names. -The -.Fn archive_entry_copy_fflags_text -and -.Fn archive_entry_copy_fflags_text_w -functions parse the provided text and sets the internal bitmap values. -This is a platform-specific operation; names that are not meaningful -on the current platform will be ignored. -The function returns a pointer to the start of the first name that was not -recognized, or NULL if every name was recognized. -Note that every name--including names that follow an unrecognized name--will -be evaluated, and the bitmaps will be set to reflect every name that is -recognized. -(In particular, this differs from -.Xr strtofflags 3 , -which stops parsing at the first unrecognized name.) -.Ss ACL Handling -XXX This needs serious help. -XXX -.Pp -An -.Dq Access Control List -(ACL) is a list of permissions that grant access to particular users or -groups beyond what would normally be provided by standard POSIX mode bits. -The ACL handling here addresses some deficiencies in the POSIX.1e draft 17 ACL -specification. -In particular, POSIX.1e draft 17 specifies several different formats, but -none of those formats include both textual user/group names and numeric -UIDs/GIDs. -.Pp -XXX explain ACL stuff XXX .\" .Sh EXAMPLE .\" .Sh RETURN VALUES .\" .Sh ERRORS .Sh SEE ALSO -.Xr archive 3 +.Xr archive 3 , +.Xr archive_entry_acl 3 , +.Xr archive_entry_paths 3 , +.Xr archive_entry_perms 3 , +.Xr archive_entry_time 3 .Sh HISTORY The .Nm libarchive diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.c b/Utilities/cmlibarchive/libarchive/archive_entry.c index c30423115..cbdda8a44 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:43 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry.c 201096 2009-12-28 02:41:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -39,21 +39,24 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:4 #include #define HAVE_MAJOR #endif +#ifdef HAVE_ERRNO_H +#include +#endif #ifdef HAVE_LIMITS_H #include #endif #ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif /* * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. * As the include guards don't agree, the order of include is important. */ #ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif #include #include @@ -68,13 +71,12 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:4 #endif #include "archive.h" +#include "archive_acl_private.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_entry_private.h" -#undef max -#define max(a, b) ((a)>(b)?(a):(b)) - #if !defined(HAVE_MAJOR) && !defined(major) /* Replacement for major/minor/makedev. */ #define major(x) ((int)(0x00ff & ((x) >> 8))) @@ -98,270 +100,49 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:4 #define ae_makedev(maj, min) makedev((maj), (min)) #endif -static void aes_clean(struct aes *); -static void aes_copy(struct aes *dest, struct aes *src); -static const char * aes_get_mbs(struct aes *); -static const wchar_t * aes_get_wcs(struct aes *); -static int aes_set_mbs(struct aes *, const char *mbs); -static int aes_copy_mbs(struct aes *, const char *mbs); -/* static void aes_set_wcs(struct aes *, const wchar_t *wcs); */ -static int aes_copy_wcs(struct aes *, const wchar_t *wcs); -static int aes_copy_wcs_len(struct aes *, const wchar_t *wcs, size_t); - -static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear); -static const wchar_t *ae_wcstofflags(const wchar_t *stringp, - unsigned long *setp, unsigned long *clrp); -static const char *ae_strtofflags(const char *stringp, - unsigned long *setp, unsigned long *clrp); -static void append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, - const wchar_t *wname, int perm, int id); -static void append_id_w(wchar_t **wp, int id); - -static int acl_special(struct archive_entry *entry, - int type, int permset, int tag); -static struct ae_acl *acl_new_entry(struct archive_entry *entry, - int type, int permset, int tag, int id); -static int isint_w(const wchar_t *start, const wchar_t *end, int *result); -static int ismode_w(const wchar_t *start, const wchar_t *end, int *result); -static void next_field_w(const wchar_t **wp, const wchar_t **start, - const wchar_t **end, wchar_t *sep); -static int prefix_w(const wchar_t *start, const wchar_t *end, - const wchar_t *test); -static void -archive_entry_acl_add_entry_w_len(struct archive_entry *entry, int type, - int permset, int tag, int id, const wchar_t *name, size_t); - +/* + * This adjustment is needed to support the following idiom for adding + * 1000ns to the stored time: + * archive_entry_set_atime(archive_entry_atime(), + * archive_entry_atime_nsec() + 1000) + * The additional if() here compensates for ambiguity in the C standard, + * which permits two possible interpretations of a % b when a is negative. + */ +#define FIX_NS(t,ns) \ + do { \ + t += ns / 1000000000; \ + ns %= 1000000000; \ + if (ns < 0) { --t; ns += 1000000000; } \ + } while (0) + +static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear); +static const wchar_t *ae_wcstofflags(const wchar_t *stringp, + unsigned long *setp, unsigned long *clrp); +static const char *ae_strtofflags(const char *stringp, + unsigned long *setp, unsigned long *clrp); #ifndef HAVE_WCSCPY static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2) { - wchar_t *dest = s1; - while ((*s1 = *s2) != L'\0') - ++s1, ++s2; - return dest; + wchar_t *dest = s1; + while ((*s1 = *s2) != L'\0') + ++s1, ++s2; + return dest; } #endif #ifndef HAVE_WCSLEN static size_t wcslen(const wchar_t *s) { - const wchar_t *p = s; - while (*p != L'\0') - ++p; - return p - s; + const wchar_t *p = s; + while (*p != L'\0') + ++p; + return p - s; } #endif #ifndef HAVE_WMEMCMP /* Good enough for simple equality testing, but not for sorting. */ #define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t)) #endif -#ifndef HAVE_WMEMCPY -#define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t)) -#endif - -static void -aes_clean(struct aes *aes) -{ - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - archive_string_free(&(aes->aes_mbs)); - archive_string_free(&(aes->aes_utf8)); - aes->aes_set = 0; -} - -static void -aes_copy(struct aes *dest, struct aes *src) -{ - wchar_t *wp; - - dest->aes_set = src->aes_set; - archive_string_copy(&(dest->aes_mbs), &(src->aes_mbs)); - archive_string_copy(&(dest->aes_utf8), &(src->aes_utf8)); - - if (src->aes_wcs != NULL) { - wp = (wchar_t *)malloc((wcslen(src->aes_wcs) + 1) - * sizeof(wchar_t)); - if (wp == NULL) - __archive_errx(1, "No memory for aes_copy()"); - wcscpy(wp, src->aes_wcs); - dest->aes_wcs = wp; - } -} - -static const char * -aes_get_utf8(struct aes *aes) -{ - if (aes->aes_set & AES_SET_UTF8) - return (aes->aes_utf8.s); - if ((aes->aes_set & AES_SET_WCS) - && archive_strappend_w_utf8(&(aes->aes_utf8), aes->aes_wcs) != NULL) { - aes->aes_set |= AES_SET_UTF8; - return (aes->aes_utf8.s); - } - return (NULL); -} - -static const char * -aes_get_mbs(struct aes *aes) -{ - /* If we already have an MBS form, return that immediately. */ - if (aes->aes_set & AES_SET_MBS) - return (aes->aes_mbs.s); - /* If there's a WCS form, try converting with the native locale. */ - if ((aes->aes_set & AES_SET_WCS) - && archive_strappend_w_mbs(&(aes->aes_mbs), aes->aes_wcs) != NULL) { - aes->aes_set |= AES_SET_MBS; - return (aes->aes_mbs.s); - } - /* We'll use UTF-8 for MBS if all else fails. */ - return (aes_get_utf8(aes)); -} - -static const wchar_t * -aes_get_wcs(struct aes *aes) -{ - wchar_t *w; - int r; - - /* Return WCS form if we already have it. */ - if (aes->aes_set & AES_SET_WCS) - return (aes->aes_wcs); - - if (aes->aes_set & AES_SET_MBS) { - /* Try converting MBS to WCS using native locale. */ - /* - * No single byte will be more than one wide character, - * so this length estimate will always be big enough. - */ - size_t wcs_length = aes->aes_mbs.length; - - w = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t)); - if (w == NULL) - __archive_errx(1, "No memory for aes_get_wcs()"); - r = mbstowcs(w, aes->aes_mbs.s, wcs_length); - if (r > 0) { - w[r] = 0; - aes->aes_set |= AES_SET_WCS; - return (aes->aes_wcs = w); - } - free(w); - } - - if (aes->aes_set & AES_SET_UTF8) { - /* Try converting UTF8 to WCS. */ - aes->aes_wcs = __archive_string_utf8_w(&(aes->aes_utf8)); - if (aes->aes_wcs != NULL) - aes->aes_set |= AES_SET_WCS; - return (aes->aes_wcs); - } - return (NULL); -} - -static int -aes_set_mbs(struct aes *aes, const char *mbs) -{ - return (aes_copy_mbs(aes, mbs)); -} - -static int -aes_copy_mbs(struct aes *aes, const char *mbs) -{ - if (mbs == NULL) { - aes->aes_set = 0; - return (0); - } - aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */ - archive_strcpy(&(aes->aes_mbs), mbs); - archive_string_empty(&(aes->aes_utf8)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - return (0); -} - -/* - * The 'update' form tries to proactively update all forms of - * this string (WCS and MBS) and returns an error if any of - * them fail. This is used by the 'pax' handler, for instance, - * to detect and report character-conversion failures early while - * still allowing clients to get potentially useful values from - * the more tolerant lazy conversions. (get_mbs and get_wcs will - * strive to give the user something useful, so you can get hopefully - * usable values even if some of the character conversions are failing.) - */ -static int -aes_update_utf8(struct aes *aes, const char *utf8) -{ - if (utf8 == NULL) { - aes->aes_set = 0; - return (1); /* Succeeded in clearing everything. */ - } - - /* Save the UTF8 string. */ - archive_strcpy(&(aes->aes_utf8), utf8); - - /* Empty the mbs and wcs strings. */ - archive_string_empty(&(aes->aes_mbs)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - - aes->aes_set = AES_SET_UTF8; /* Only UTF8 is set now. */ - - /* TODO: We should just do a direct UTF-8 to MBS conversion - * here. That would be faster, use less space, and give the - * same information. (If a UTF-8 to MBS conversion succeeds, - * then UTF-8->WCS and Unicode->MBS conversions will both - * succeed.) */ - - /* Try converting UTF8 to WCS, return false on failure. */ - aes->aes_wcs = __archive_string_utf8_w(&(aes->aes_utf8)); - if (aes->aes_wcs == NULL) - return (0); - aes->aes_set = AES_SET_UTF8 | AES_SET_WCS; /* Both UTF8 and WCS set. */ - - /* Try converting WCS to MBS, return false on failure. */ - if (archive_strappend_w_mbs(&(aes->aes_mbs), aes->aes_wcs) == NULL) - return (0); - aes->aes_set = AES_SET_UTF8 | AES_SET_WCS | AES_SET_MBS; - - /* All conversions succeeded. */ - return (1); -} - -static int -aes_copy_wcs(struct aes *aes, const wchar_t *wcs) -{ - return aes_copy_wcs_len(aes, wcs, wcs == NULL ? 0 : wcslen(wcs)); -} - -static int -aes_copy_wcs_len(struct aes *aes, const wchar_t *wcs, size_t len) -{ - wchar_t *w; - - if (wcs == NULL) { - aes->aes_set = 0; - return (0); - } - aes->aes_set = AES_SET_WCS; /* Only WCS form set. */ - archive_string_empty(&(aes->aes_mbs)); - archive_string_empty(&(aes->aes_utf8)); - if (aes->aes_wcs) { - free((wchar_t *)(uintptr_t)aes->aes_wcs); - aes->aes_wcs = NULL; - } - w = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); - if (w == NULL) - __archive_errx(1, "No memory for aes_copy_wcs()"); - wmemcpy(w, wcs, len); - w[len] = L'\0'; - aes->aes_wcs = w; - return (0); -} /**************************************************************************** * @@ -372,85 +153,104 @@ aes_copy_wcs_len(struct aes *aes, const wchar_t *wcs, size_t len) struct archive_entry * archive_entry_clear(struct archive_entry *entry) { - if (entry == NULL) - return (NULL); - aes_clean(&entry->ae_fflags_text); - aes_clean(&entry->ae_gname); - aes_clean(&entry->ae_hardlink); - aes_clean(&entry->ae_pathname); - aes_clean(&entry->ae_sourcepath); - aes_clean(&entry->ae_symlink); - aes_clean(&entry->ae_uname); - archive_entry_acl_clear(entry); - archive_entry_xattr_clear(entry); - free(entry->stat); - memset(entry, 0, sizeof(*entry)); - return entry; + if (entry == NULL) + return (NULL); + archive_mstring_clean(&entry->ae_fflags_text); + archive_mstring_clean(&entry->ae_gname); + archive_mstring_clean(&entry->ae_hardlink); + archive_mstring_clean(&entry->ae_pathname); + archive_mstring_clean(&entry->ae_sourcepath); + archive_mstring_clean(&entry->ae_symlink); + archive_mstring_clean(&entry->ae_uname); + archive_entry_copy_mac_metadata(entry, NULL, 0); + archive_acl_clear(&entry->acl); + archive_entry_xattr_clear(entry); + archive_entry_sparse_clear(entry); + free(entry->stat); + memset(entry, 0, sizeof(*entry)); + return entry; } struct archive_entry * archive_entry_clone(struct archive_entry *entry) { - struct archive_entry *entry2; - struct ae_acl *ap, *ap2; - struct ae_xattr *xp; - - /* Allocate new structure and copy over all of the fields. */ - entry2 = (struct archive_entry *)malloc(sizeof(*entry2)); - if (entry2 == NULL) - return (NULL); - memset(entry2, 0, sizeof(*entry2)); - entry2->ae_stat = entry->ae_stat; - entry2->ae_fflags_set = entry->ae_fflags_set; - entry2->ae_fflags_clear = entry->ae_fflags_clear; - - aes_copy(&entry2->ae_fflags_text, &entry->ae_fflags_text); - aes_copy(&entry2->ae_gname, &entry->ae_gname); - aes_copy(&entry2->ae_hardlink, &entry->ae_hardlink); - aes_copy(&entry2->ae_pathname, &entry->ae_pathname); - aes_copy(&entry2->ae_sourcepath, &entry->ae_sourcepath); - aes_copy(&entry2->ae_symlink, &entry->ae_symlink); - entry2->ae_set = entry->ae_set; - aes_copy(&entry2->ae_uname, &entry->ae_uname); - - /* Copy ACL data over. */ - ap = entry->acl_head; - while (ap != NULL) { - ap2 = acl_new_entry(entry2, - ap->type, ap->permset, ap->tag, ap->id); - if (ap2 != NULL) - aes_copy(&ap2->name, &ap->name); - ap = ap->next; - } - - /* Copy xattr data over. */ - xp = entry->xattr_head; - while (xp != NULL) { - archive_entry_xattr_add_entry(entry2, - xp->name, xp->value, xp->size); - xp = xp->next; - } - - return (entry2); + struct archive_entry *entry2; + struct ae_xattr *xp; + struct ae_sparse *sp; + size_t s; + const void *p; + + /* Allocate new structure and copy over all of the fields. */ + /* TODO: Should we copy the archive over? Or require a new archive + * as an argument? */ + entry2 = archive_entry_new2(entry->archive); + if (entry2 == NULL) + return (NULL); + entry2->ae_stat = entry->ae_stat; + entry2->ae_fflags_set = entry->ae_fflags_set; + entry2->ae_fflags_clear = entry->ae_fflags_clear; + + /* TODO: XXX If clone can have a different archive, what do we do here if + * character sets are different? XXX */ + archive_mstring_copy(&entry2->ae_fflags_text, &entry->ae_fflags_text); + archive_mstring_copy(&entry2->ae_gname, &entry->ae_gname); + archive_mstring_copy(&entry2->ae_hardlink, &entry->ae_hardlink); + archive_mstring_copy(&entry2->ae_pathname, &entry->ae_pathname); + archive_mstring_copy(&entry2->ae_sourcepath, &entry->ae_sourcepath); + archive_mstring_copy(&entry2->ae_symlink, &entry->ae_symlink); + entry2->ae_set = entry->ae_set; + archive_mstring_copy(&entry2->ae_uname, &entry->ae_uname); + + /* Copy ACL data over. */ + archive_acl_copy(&entry2->acl, &entry->acl); + + /* Copy Mac OS metadata. */ + p = archive_entry_mac_metadata(entry, &s); + archive_entry_copy_mac_metadata(entry2, p, s); + + /* Copy xattr data over. */ + xp = entry->xattr_head; + while (xp != NULL) { + archive_entry_xattr_add_entry(entry2, + xp->name, xp->value, xp->size); + xp = xp->next; + } + + /* Copy sparse data over. */ + sp = entry->sparse_head; + while (sp != NULL) { + archive_entry_sparse_add_entry(entry2, + sp->offset, sp->length); + sp = sp->next; + } + + return (entry2); } void archive_entry_free(struct archive_entry *entry) { - archive_entry_clear(entry); - free(entry); + archive_entry_clear(entry); + free(entry); } struct archive_entry * archive_entry_new(void) { - struct archive_entry *entry; + return archive_entry_new2(NULL); +} + +struct archive_entry * +archive_entry_new2(struct archive *a) +{ + struct archive_entry *entry; - entry = (struct archive_entry *)malloc(sizeof(*entry)); - if (entry == NULL) - return (NULL); - memset(entry, 0, sizeof(*entry)); - return (entry); + entry = (struct archive_entry *)malloc(sizeof(*entry)); + if (entry == NULL) + return (NULL); + memset(entry, 0, sizeof(*entry)); + entry->archive = a; + return (entry); } /* @@ -460,97 +260,103 @@ archive_entry_new(void) time_t archive_entry_atime(struct archive_entry *entry) { - return (entry->ae_stat.aest_atime); + return (entry->ae_stat.aest_atime); } long archive_entry_atime_nsec(struct archive_entry *entry) { - return (entry->ae_stat.aest_atime_nsec); + return (entry->ae_stat.aest_atime_nsec); } int archive_entry_atime_is_set(struct archive_entry *entry) { - return (entry->ae_set & AE_SET_ATIME); + return (entry->ae_set & AE_SET_ATIME); } time_t archive_entry_birthtime(struct archive_entry *entry) { - return (entry->ae_stat.aest_birthtime); + return (entry->ae_stat.aest_birthtime); } long archive_entry_birthtime_nsec(struct archive_entry *entry) { - return (entry->ae_stat.aest_birthtime_nsec); + return (entry->ae_stat.aest_birthtime_nsec); } int archive_entry_birthtime_is_set(struct archive_entry *entry) { - return (entry->ae_set & AE_SET_BIRTHTIME); + return (entry->ae_set & AE_SET_BIRTHTIME); } time_t archive_entry_ctime(struct archive_entry *entry) { - return (entry->ae_stat.aest_ctime); + return (entry->ae_stat.aest_ctime); } int archive_entry_ctime_is_set(struct archive_entry *entry) { - return (entry->ae_set & AE_SET_CTIME); + return (entry->ae_set & AE_SET_CTIME); } long archive_entry_ctime_nsec(struct archive_entry *entry) { - return (entry->ae_stat.aest_ctime_nsec); + return (entry->ae_stat.aest_ctime_nsec); } dev_t archive_entry_dev(struct archive_entry *entry) { - if (entry->ae_stat.aest_dev_is_broken_down) - return ae_makedev(entry->ae_stat.aest_devmajor, - entry->ae_stat.aest_devminor); - else - return (entry->ae_stat.aest_dev); + if (entry->ae_stat.aest_dev_is_broken_down) + return ae_makedev(entry->ae_stat.aest_devmajor, + entry->ae_stat.aest_devminor); + else + return (entry->ae_stat.aest_dev); +} + +int +archive_entry_dev_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_DEV); } dev_t archive_entry_devmajor(struct archive_entry *entry) { - if (entry->ae_stat.aest_dev_is_broken_down) - return (entry->ae_stat.aest_devmajor); - else - return major(entry->ae_stat.aest_dev); + if (entry->ae_stat.aest_dev_is_broken_down) + return (entry->ae_stat.aest_devmajor); + else + return major(entry->ae_stat.aest_dev); } dev_t archive_entry_devminor(struct archive_entry *entry) { - if (entry->ae_stat.aest_dev_is_broken_down) - return (entry->ae_stat.aest_devminor); - else - return minor(entry->ae_stat.aest_dev); + if (entry->ae_stat.aest_dev_is_broken_down) + return (entry->ae_stat.aest_devminor); + else + return minor(entry->ae_stat.aest_dev); } mode_t archive_entry_filetype(struct archive_entry *entry) { - return (AE_IFMT & entry->ae_stat.aest_mode); + return (AE_IFMT & entry->acl.mode); } void archive_entry_fflags(struct archive_entry *entry, unsigned long *set, unsigned long *clear) { - *set = entry->ae_fflags_set; - *clear = entry->ae_fflags_clear; + *set = entry->ae_fflags_set; + *clear = entry->ae_fflags_clear; } /* @@ -565,192 +371,293 @@ archive_entry_fflags(struct archive_entry *entry, const char * archive_entry_fflags_text(struct archive_entry *entry) { - const char *f; - char *p; + const char *f; + char *p; - f = aes_get_mbs(&entry->ae_fflags_text); - if (f != NULL) - return (f); + if (archive_mstring_get_mbs(entry->archive, + &entry->ae_fflags_text, &f) == 0 && f != NULL) + return (f); - if (entry->ae_fflags_set == 0 && entry->ae_fflags_clear == 0) - return (NULL); + if (entry->ae_fflags_set == 0 && entry->ae_fflags_clear == 0) + return (NULL); - p = ae_fflagstostr(entry->ae_fflags_set, entry->ae_fflags_clear); - if (p == NULL) - return (NULL); + p = ae_fflagstostr(entry->ae_fflags_set, entry->ae_fflags_clear); + if (p == NULL) + return (NULL); - aes_copy_mbs(&entry->ae_fflags_text, p); - free(p); - f = aes_get_mbs(&entry->ae_fflags_text); - return (f); + archive_mstring_copy_mbs(&entry->ae_fflags_text, p); + free(p); + if (archive_mstring_get_mbs(entry->archive, + &entry->ae_fflags_text, &f) == 0) + return (f); + return (NULL); } -gid_t +int64_t archive_entry_gid(struct archive_entry *entry) { - return (entry->ae_stat.aest_gid); + return (entry->ae_stat.aest_gid); } const char * archive_entry_gname(struct archive_entry *entry) { - return (aes_get_mbs(&entry->ae_gname)); + const char *p; + if (archive_mstring_get_mbs(entry->archive, &entry->ae_gname, &p) == 0) + return (p); + return (NULL); } const wchar_t * archive_entry_gname_w(struct archive_entry *entry) { - return (aes_get_wcs(&entry->ae_gname)); + const wchar_t *p; + if (archive_mstring_get_wcs(entry->archive, &entry->ae_gname, &p) == 0) + return (p); + return (NULL); +} + +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)); } const char * archive_entry_hardlink(struct archive_entry *entry) { - if (entry->ae_set & AE_SET_HARDLINK) - return (aes_get_mbs(&entry->ae_hardlink)); - return (NULL); + const char *p; + if ((entry->ae_set & AE_SET_HARDLINK) && archive_mstring_get_mbs( + entry->archive, &entry->ae_hardlink, &p) == 0) + return (p); + return (NULL); } const wchar_t * archive_entry_hardlink_w(struct archive_entry *entry) { - if (entry->ae_set & AE_SET_HARDLINK) - return (aes_get_wcs(&entry->ae_hardlink)); - return (NULL); + const wchar_t *p; + if ((entry->ae_set & AE_SET_HARDLINK) && archive_mstring_get_wcs( + entry->archive, &entry->ae_hardlink, &p) == 0) + return (p); + return (NULL); } -ino_t +int +_archive_entry_hardlink_l(struct archive_entry *entry, + const char **p, size_t *len, struct archive_string_conv *sc) +{ + if ((entry->ae_set & AE_SET_HARDLINK) == 0) { + *p = NULL; + *len = 0; + return (0); + } + return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc)); +} + +int64_t archive_entry_ino(struct archive_entry *entry) { - return (entry->ae_stat.aest_ino); + return (entry->ae_stat.aest_ino); +} + +int +archive_entry_ino_is_set(struct archive_entry *entry) +{ + return (entry->ae_set & AE_SET_INO); } int64_t archive_entry_ino64(struct archive_entry *entry) { - return (entry->ae_stat.aest_ino); + return (entry->ae_stat.aest_ino); } mode_t archive_entry_mode(struct archive_entry *entry) { - return (entry->ae_stat.aest_mode); + return (entry->acl.mode); } time_t archive_entry_mtime(struct archive_entry *entry) { - return (entry->ae_stat.aest_mtime); + return (entry->ae_stat.aest_mtime); } long archive_entry_mtime_nsec(struct archive_entry *entry) { - return (entry->ae_stat.aest_mtime_nsec); + return (entry->ae_stat.aest_mtime_nsec); } int archive_entry_mtime_is_set(struct archive_entry *entry) { - return (entry->ae_set & AE_SET_MTIME); + return (entry->ae_set & AE_SET_MTIME); } unsigned int archive_entry_nlink(struct archive_entry *entry) { - return (entry->ae_stat.aest_nlink); + return (entry->ae_stat.aest_nlink); } const char * archive_entry_pathname(struct archive_entry *entry) { - return (aes_get_mbs(&entry->ae_pathname)); + const char *p; + if (archive_mstring_get_mbs( + entry->archive, &entry->ae_pathname, &p) == 0) + return (p); + return (NULL); } const wchar_t * archive_entry_pathname_w(struct archive_entry *entry) { - return (aes_get_wcs(&entry->ae_pathname)); + const wchar_t *p; + if (archive_mstring_get_wcs( + entry->archive, &entry->ae_pathname, &p) == 0) + return (p); + return (NULL); +} + +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)); +} + +mode_t +archive_entry_perm(struct archive_entry *entry) +{ + return (~AE_IFMT & entry->acl.mode); } dev_t archive_entry_rdev(struct archive_entry *entry) { - if (entry->ae_stat.aest_rdev_is_broken_down) - return ae_makedev(entry->ae_stat.aest_rdevmajor, - entry->ae_stat.aest_rdevminor); - else - return (entry->ae_stat.aest_rdev); + if (entry->ae_stat.aest_rdev_is_broken_down) + return ae_makedev(entry->ae_stat.aest_rdevmajor, + entry->ae_stat.aest_rdevminor); + else + return (entry->ae_stat.aest_rdev); } dev_t archive_entry_rdevmajor(struct archive_entry *entry) { - if (entry->ae_stat.aest_rdev_is_broken_down) - return (entry->ae_stat.aest_rdevmajor); - else - return major(entry->ae_stat.aest_rdev); + if (entry->ae_stat.aest_rdev_is_broken_down) + return (entry->ae_stat.aest_rdevmajor); + else + return major(entry->ae_stat.aest_rdev); } dev_t archive_entry_rdevminor(struct archive_entry *entry) { - if (entry->ae_stat.aest_rdev_is_broken_down) - return (entry->ae_stat.aest_rdevminor); - else - return minor(entry->ae_stat.aest_rdev); + if (entry->ae_stat.aest_rdev_is_broken_down) + return (entry->ae_stat.aest_rdevminor); + else + return minor(entry->ae_stat.aest_rdev); } int64_t archive_entry_size(struct archive_entry *entry) { - return (entry->ae_stat.aest_size); + return (entry->ae_stat.aest_size); } int archive_entry_size_is_set(struct archive_entry *entry) { - return (entry->ae_set & AE_SET_SIZE); + return (entry->ae_set & AE_SET_SIZE); } const char * archive_entry_sourcepath(struct archive_entry *entry) { - return (aes_get_mbs(&entry->ae_sourcepath)); + const char *p; + if (archive_mstring_get_mbs( + entry->archive, &entry->ae_sourcepath, &p) == 0) + return (p); + return (NULL); +} + +const wchar_t * +archive_entry_sourcepath_w(struct archive_entry *entry) +{ + const wchar_t *p; + if (archive_mstring_get_wcs( + entry->archive, &entry->ae_sourcepath, &p) == 0) + return (p); + return (NULL); } const char * archive_entry_symlink(struct archive_entry *entry) { - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_get_mbs(&entry->ae_symlink)); - return (NULL); + const char *p; + if ((entry->ae_set & AE_SET_SYMLINK) && archive_mstring_get_mbs( + entry->archive, &entry->ae_symlink, &p) == 0) + return (p); + return (NULL); } const wchar_t * archive_entry_symlink_w(struct archive_entry *entry) { - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_get_wcs(&entry->ae_symlink)); - return (NULL); + const wchar_t *p; + if ((entry->ae_set & AE_SET_SYMLINK) && archive_mstring_get_wcs( + entry->archive, &entry->ae_symlink, &p) == 0) + return (p); + return (NULL); +} + +int +_archive_entry_symlink_l(struct archive_entry *entry, + const char **p, size_t *len, struct archive_string_conv *sc) +{ + if ((entry->ae_set & AE_SET_SYMLINK) == 0) { + *p = NULL; + *len = 0; + return (0); + } + return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc)); } -uid_t +int64_t archive_entry_uid(struct archive_entry *entry) { - return (entry->ae_stat.aest_uid); + return (entry->ae_stat.aest_uid); } const char * archive_entry_uname(struct archive_entry *entry) { - return (aes_get_mbs(&entry->ae_uname)); + const char *p; + if (archive_mstring_get_mbs(entry->archive, &entry->ae_uname, &p) == 0) + return (p); + return (NULL); } const wchar_t * archive_entry_uname_w(struct archive_entry *entry) { - return (aes_get_wcs(&entry->ae_uname)); + const wchar_t *p; + if (archive_mstring_get_wcs(entry->archive, &entry->ae_uname, &p) == 0) + return (p); + return (NULL); +} + +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)); } /* @@ -760,390 +667,536 @@ archive_entry_uname_w(struct archive_entry *entry) void archive_entry_set_filetype(struct archive_entry *entry, unsigned int type) { - entry->stat_valid = 0; - entry->ae_stat.aest_mode &= ~AE_IFMT; - entry->ae_stat.aest_mode |= AE_IFMT & type; + entry->stat_valid = 0; + entry->acl.mode &= ~AE_IFMT; + entry->acl.mode |= AE_IFMT & type; } void archive_entry_set_fflags(struct archive_entry *entry, unsigned long set, unsigned long clear) { - aes_clean(&entry->ae_fflags_text); - entry->ae_fflags_set = set; - entry->ae_fflags_clear = clear; + archive_mstring_clean(&entry->ae_fflags_text); + entry->ae_fflags_set = set; + entry->ae_fflags_clear = clear; } const char * archive_entry_copy_fflags_text(struct archive_entry *entry, const char *flags) { - aes_copy_mbs(&entry->ae_fflags_text, flags); - return (ae_strtofflags(flags, - &entry->ae_fflags_set, &entry->ae_fflags_clear)); + archive_mstring_copy_mbs(&entry->ae_fflags_text, flags); + return (ae_strtofflags(flags, + &entry->ae_fflags_set, &entry->ae_fflags_clear)); } const wchar_t * archive_entry_copy_fflags_text_w(struct archive_entry *entry, const wchar_t *flags) { - aes_copy_wcs(&entry->ae_fflags_text, flags); - return (ae_wcstofflags(flags, - &entry->ae_fflags_set, &entry->ae_fflags_clear)); + archive_mstring_copy_wcs(&entry->ae_fflags_text, flags); + return (ae_wcstofflags(flags, + &entry->ae_fflags_set, &entry->ae_fflags_clear)); } void -archive_entry_set_gid(struct archive_entry *entry, gid_t g) +archive_entry_set_gid(struct archive_entry *entry, int64_t g) { - entry->stat_valid = 0; - entry->ae_stat.aest_gid = g; + entry->stat_valid = 0; + entry->ae_stat.aest_gid = g; } void archive_entry_set_gname(struct archive_entry *entry, const char *name) { - aes_set_mbs(&entry->ae_gname, name); + archive_mstring_copy_mbs(&entry->ae_gname, name); } void archive_entry_copy_gname(struct archive_entry *entry, const char *name) { - aes_copy_mbs(&entry->ae_gname, name); + archive_mstring_copy_mbs(&entry->ae_gname, name); } void archive_entry_copy_gname_w(struct archive_entry *entry, const wchar_t *name) { - aes_copy_wcs(&entry->ae_gname, name); + archive_mstring_copy_wcs(&entry->ae_gname, name); } int archive_entry_update_gname_utf8(struct archive_entry *entry, const char *name) { - return (aes_update_utf8(&entry->ae_gname, name)); + if (archive_mstring_update_utf8(entry->archive, + &entry->ae_gname, name) == 0) + return (1); + return (0); +} + +int +_archive_entry_copy_gname_l(struct archive_entry *entry, + const char *name, size_t len, struct archive_string_conv *sc) +{ + return (archive_mstring_copy_mbs_len_l(&entry->ae_gname, name, len, sc)); } void -archive_entry_set_ino(struct archive_entry *entry, unsigned long ino) +archive_entry_set_ino(struct archive_entry *entry, int64_t ino) { - entry->stat_valid = 0; - entry->ae_stat.aest_ino = ino; + entry->stat_valid = 0; + entry->ae_set |= AE_SET_INO; + entry->ae_stat.aest_ino = ino; } void archive_entry_set_ino64(struct archive_entry *entry, int64_t ino) { - entry->stat_valid = 0; - entry->ae_stat.aest_ino = ino; + entry->stat_valid = 0; + entry->ae_set |= AE_SET_INO; + entry->ae_stat.aest_ino = ino; } void archive_entry_set_hardlink(struct archive_entry *entry, const char *target) { - aes_set_mbs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; + archive_mstring_copy_mbs(&entry->ae_hardlink, target); + if (target != NULL) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; } void archive_entry_copy_hardlink(struct archive_entry *entry, const char *target) { - aes_copy_mbs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; + archive_mstring_copy_mbs(&entry->ae_hardlink, target); + if (target != NULL) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; } void archive_entry_copy_hardlink_w(struct archive_entry *entry, const wchar_t *target) { - aes_copy_wcs(&entry->ae_hardlink, target); - if (target != NULL) - entry->ae_set |= AE_SET_HARDLINK; - else - entry->ae_set &= ~AE_SET_HARDLINK; + archive_mstring_copy_wcs(&entry->ae_hardlink, target); + if (target != NULL) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; +} + +int +archive_entry_update_hardlink_utf8(struct archive_entry *entry, const char *target) +{ + if (target != NULL) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; + if (archive_mstring_update_utf8(entry->archive, + &entry->ae_hardlink, target) == 0) + return (1); + return (0); +} + +int +_archive_entry_copy_hardlink_l(struct archive_entry *entry, + const char *target, size_t len, struct archive_string_conv *sc) +{ + int r; + + r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink, + target, len, sc); + if (target != NULL && r == 0) + entry->ae_set |= AE_SET_HARDLINK; + else + entry->ae_set &= ~AE_SET_HARDLINK; + return (r); } void archive_entry_set_atime(struct archive_entry *entry, time_t t, long ns) { - entry->stat_valid = 0; - entry->ae_set |= AE_SET_ATIME; - entry->ae_stat.aest_atime = t; - entry->ae_stat.aest_atime_nsec = ns; + FIX_NS(t, ns); + entry->stat_valid = 0; + entry->ae_set |= AE_SET_ATIME; + entry->ae_stat.aest_atime = t; + entry->ae_stat.aest_atime_nsec = ns; } void archive_entry_unset_atime(struct archive_entry *entry) { - archive_entry_set_atime(entry, 0, 0); - entry->ae_set &= ~AE_SET_ATIME; + archive_entry_set_atime(entry, 0, 0); + entry->ae_set &= ~AE_SET_ATIME; } void -archive_entry_set_birthtime(struct archive_entry *entry, time_t m, long ns) +archive_entry_set_birthtime(struct archive_entry *entry, time_t t, long ns) { - entry->stat_valid = 0; - entry->ae_set |= AE_SET_BIRTHTIME; - entry->ae_stat.aest_birthtime = m; - entry->ae_stat.aest_birthtime_nsec = ns; + FIX_NS(t, ns); + entry->stat_valid = 0; + entry->ae_set |= AE_SET_BIRTHTIME; + entry->ae_stat.aest_birthtime = t; + entry->ae_stat.aest_birthtime_nsec = ns; } void archive_entry_unset_birthtime(struct archive_entry *entry) { - archive_entry_set_birthtime(entry, 0, 0); - entry->ae_set &= ~AE_SET_BIRTHTIME; + archive_entry_set_birthtime(entry, 0, 0); + entry->ae_set &= ~AE_SET_BIRTHTIME; } void archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns) { - entry->stat_valid = 0; - entry->ae_set |= AE_SET_CTIME; - entry->ae_stat.aest_ctime = t; - entry->ae_stat.aest_ctime_nsec = ns; + FIX_NS(t, ns); + entry->stat_valid = 0; + entry->ae_set |= AE_SET_CTIME; + entry->ae_stat.aest_ctime = t; + entry->ae_stat.aest_ctime_nsec = ns; } void archive_entry_unset_ctime(struct archive_entry *entry) { - archive_entry_set_ctime(entry, 0, 0); - entry->ae_set &= ~AE_SET_CTIME; + archive_entry_set_ctime(entry, 0, 0); + entry->ae_set &= ~AE_SET_CTIME; } void archive_entry_set_dev(struct archive_entry *entry, dev_t d) { - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 0; - entry->ae_stat.aest_dev = d; + entry->stat_valid = 0; + entry->ae_set |= AE_SET_DEV; + entry->ae_stat.aest_dev_is_broken_down = 0; + entry->ae_stat.aest_dev = d; } void archive_entry_set_devmajor(struct archive_entry *entry, dev_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 1; - entry->ae_stat.aest_devmajor = m; + entry->stat_valid = 0; + entry->ae_set |= AE_SET_DEV; + entry->ae_stat.aest_dev_is_broken_down = 1; + entry->ae_stat.aest_devmajor = m; } void archive_entry_set_devminor(struct archive_entry *entry, dev_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_dev_is_broken_down = 1; - entry->ae_stat.aest_devminor = m; + entry->stat_valid = 0; + entry->ae_set |= AE_SET_DEV; + entry->ae_stat.aest_dev_is_broken_down = 1; + entry->ae_stat.aest_devminor = m; } /* Set symlink if symlink is already set, else set hardlink. */ void archive_entry_set_link(struct archive_entry *entry, const char *target) { - if (entry->ae_set & AE_SET_SYMLINK) - aes_set_mbs(&entry->ae_symlink, target); - else - aes_set_mbs(&entry->ae_hardlink, target); + if (entry->ae_set & AE_SET_SYMLINK) + archive_mstring_copy_mbs(&entry->ae_symlink, target); + else + archive_mstring_copy_mbs(&entry->ae_hardlink, target); } /* Set symlink if symlink is already set, else set hardlink. */ void archive_entry_copy_link(struct archive_entry *entry, const char *target) { - if (entry->ae_set & AE_SET_SYMLINK) - aes_copy_mbs(&entry->ae_symlink, target); - else - aes_copy_mbs(&entry->ae_hardlink, target); + if (entry->ae_set & AE_SET_SYMLINK) + archive_mstring_copy_mbs(&entry->ae_symlink, target); + else + archive_mstring_copy_mbs(&entry->ae_hardlink, target); } /* Set symlink if symlink is already set, else set hardlink. */ void archive_entry_copy_link_w(struct archive_entry *entry, const wchar_t *target) { - if (entry->ae_set & AE_SET_SYMLINK) - aes_copy_wcs(&entry->ae_symlink, target); - else - aes_copy_wcs(&entry->ae_hardlink, target); + if (entry->ae_set & AE_SET_SYMLINK) + archive_mstring_copy_wcs(&entry->ae_symlink, target); + else + archive_mstring_copy_wcs(&entry->ae_hardlink, target); } int archive_entry_update_link_utf8(struct archive_entry *entry, const char *target) { - if (entry->ae_set & AE_SET_SYMLINK) - return (aes_update_utf8(&entry->ae_symlink, target)); - else - return (aes_update_utf8(&entry->ae_hardlink, target)); + int r; + if (entry->ae_set & AE_SET_SYMLINK) + r = archive_mstring_update_utf8(entry->archive, + &entry->ae_symlink, target); + else + r = archive_mstring_update_utf8(entry->archive, + &entry->ae_hardlink, target); + return ((r == 0)? 1: 0); +} + +int +_archive_entry_copy_link_l(struct archive_entry *entry, + const char *target, size_t len, struct archive_string_conv *sc) +{ + int r; + + if (entry->ae_set & AE_SET_SYMLINK) + r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink, + target, len, sc); + else + r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink, + target, len, sc); + return (r); } void archive_entry_set_mode(struct archive_entry *entry, mode_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_mode = m; + entry->stat_valid = 0; + entry->acl.mode = m; } void -archive_entry_set_mtime(struct archive_entry *entry, time_t m, long ns) +archive_entry_set_mtime(struct archive_entry *entry, time_t t, long ns) { - entry->stat_valid = 0; - entry->ae_set |= AE_SET_MTIME; - entry->ae_stat.aest_mtime = m; - entry->ae_stat.aest_mtime_nsec = ns; + FIX_NS(t, ns); + entry->stat_valid = 0; + entry->ae_set |= AE_SET_MTIME; + entry->ae_stat.aest_mtime = t; + entry->ae_stat.aest_mtime_nsec = ns; } void archive_entry_unset_mtime(struct archive_entry *entry) { - archive_entry_set_mtime(entry, 0, 0); - entry->ae_set &= ~AE_SET_MTIME; + archive_entry_set_mtime(entry, 0, 0); + entry->ae_set &= ~AE_SET_MTIME; } void archive_entry_set_nlink(struct archive_entry *entry, unsigned int nlink) { - entry->stat_valid = 0; - entry->ae_stat.aest_nlink = nlink; + entry->stat_valid = 0; + entry->ae_stat.aest_nlink = nlink; } void archive_entry_set_pathname(struct archive_entry *entry, const char *name) { - aes_set_mbs(&entry->ae_pathname, name); + archive_mstring_copy_mbs(&entry->ae_pathname, name); } void archive_entry_copy_pathname(struct archive_entry *entry, const char *name) { - aes_copy_mbs(&entry->ae_pathname, name); + archive_mstring_copy_mbs(&entry->ae_pathname, name); } void archive_entry_copy_pathname_w(struct archive_entry *entry, const wchar_t *name) { - aes_copy_wcs(&entry->ae_pathname, name); + archive_mstring_copy_wcs(&entry->ae_pathname, name); } int archive_entry_update_pathname_utf8(struct archive_entry *entry, const char *name) { - return (aes_update_utf8(&entry->ae_pathname, name)); + if (archive_mstring_update_utf8(entry->archive, + &entry->ae_pathname, name) == 0) + return (1); + return (0); +} + +int +_archive_entry_copy_pathname_l(struct archive_entry *entry, + const char *name, size_t len, struct archive_string_conv *sc) +{ + return (archive_mstring_copy_mbs_len_l(&entry->ae_pathname, + name, len, sc)); } void archive_entry_set_perm(struct archive_entry *entry, mode_t p) { - entry->stat_valid = 0; - entry->ae_stat.aest_mode &= AE_IFMT; - entry->ae_stat.aest_mode |= ~AE_IFMT & p; + entry->stat_valid = 0; + entry->acl.mode &= AE_IFMT; + entry->acl.mode |= ~AE_IFMT & p; } void archive_entry_set_rdev(struct archive_entry *entry, dev_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_rdev = m; - entry->ae_stat.aest_rdev_is_broken_down = 0; + entry->stat_valid = 0; + entry->ae_stat.aest_rdev = m; + entry->ae_stat.aest_rdev_is_broken_down = 0; } void archive_entry_set_rdevmajor(struct archive_entry *entry, dev_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_rdev_is_broken_down = 1; - entry->ae_stat.aest_rdevmajor = m; + entry->stat_valid = 0; + entry->ae_stat.aest_rdev_is_broken_down = 1; + entry->ae_stat.aest_rdevmajor = m; } void archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m) { - entry->stat_valid = 0; - entry->ae_stat.aest_rdev_is_broken_down = 1; - entry->ae_stat.aest_rdevminor = m; + entry->stat_valid = 0; + entry->ae_stat.aest_rdev_is_broken_down = 1; + entry->ae_stat.aest_rdevminor = m; } void archive_entry_set_size(struct archive_entry *entry, int64_t s) { - entry->stat_valid = 0; - entry->ae_stat.aest_size = s; - entry->ae_set |= AE_SET_SIZE; + entry->stat_valid = 0; + entry->ae_stat.aest_size = s; + entry->ae_set |= AE_SET_SIZE; } void archive_entry_unset_size(struct archive_entry *entry) { - archive_entry_set_size(entry, 0); - entry->ae_set &= ~AE_SET_SIZE; + archive_entry_set_size(entry, 0); + entry->ae_set &= ~AE_SET_SIZE; } void archive_entry_copy_sourcepath(struct archive_entry *entry, const char *path) { - aes_set_mbs(&entry->ae_sourcepath, path); + archive_mstring_copy_mbs(&entry->ae_sourcepath, path); +} + +void +archive_entry_copy_sourcepath_w(struct archive_entry *entry, const wchar_t *path) +{ + archive_mstring_copy_wcs(&entry->ae_sourcepath, path); } void archive_entry_set_symlink(struct archive_entry *entry, const char *linkname) { - aes_set_mbs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; + archive_mstring_copy_mbs(&entry->ae_symlink, linkname); + if (linkname != NULL) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; } void archive_entry_copy_symlink(struct archive_entry *entry, const char *linkname) { - aes_copy_mbs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; + archive_mstring_copy_mbs(&entry->ae_symlink, linkname); + if (linkname != NULL) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; } void archive_entry_copy_symlink_w(struct archive_entry *entry, const wchar_t *linkname) { - aes_copy_wcs(&entry->ae_symlink, linkname); - if (linkname != NULL) - entry->ae_set |= AE_SET_SYMLINK; - else - entry->ae_set &= ~AE_SET_SYMLINK; + archive_mstring_copy_wcs(&entry->ae_symlink, linkname); + if (linkname != NULL) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; +} + +int +archive_entry_update_symlink_utf8(struct archive_entry *entry, const char *linkname) +{ + if (linkname != NULL) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; + if (archive_mstring_update_utf8(entry->archive, + &entry->ae_symlink, linkname) == 0) + return (1); + return (0); +} + +int +_archive_entry_copy_symlink_l(struct archive_entry *entry, + const char *linkname, size_t len, struct archive_string_conv *sc) +{ + int r; + + r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink, + linkname, len, sc); + if (linkname != NULL && r == 0) + entry->ae_set |= AE_SET_SYMLINK; + else + entry->ae_set &= ~AE_SET_SYMLINK; + return (r); } void -archive_entry_set_uid(struct archive_entry *entry, uid_t u) +archive_entry_set_uid(struct archive_entry *entry, int64_t u) { - entry->stat_valid = 0; - entry->ae_stat.aest_uid = u; + entry->stat_valid = 0; + entry->ae_stat.aest_uid = u; } void archive_entry_set_uname(struct archive_entry *entry, const char *name) { - aes_set_mbs(&entry->ae_uname, name); + archive_mstring_copy_mbs(&entry->ae_uname, name); } void archive_entry_copy_uname(struct archive_entry *entry, const char *name) { - aes_copy_mbs(&entry->ae_uname, name); + archive_mstring_copy_mbs(&entry->ae_uname, name); } void archive_entry_copy_uname_w(struct archive_entry *entry, const wchar_t *name) { - aes_copy_wcs(&entry->ae_uname, name); + archive_mstring_copy_wcs(&entry->ae_uname, name); } int archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name) { - return (aes_update_utf8(&entry->ae_uname, name)); + if (archive_mstring_update_utf8(entry->archive, + &entry->ae_uname, name) == 0) + return (1); + return (0); +} + +int +_archive_entry_copy_uname_l(struct archive_entry *entry, + const char *name, size_t len, struct archive_string_conv *sc) +{ + return (archive_mstring_copy_mbs_len_l(&entry->ae_uname, + name, len, sc)); +} + +const void * +archive_entry_mac_metadata(struct archive_entry *entry, size_t *s) +{ + *s = entry->mac_metadata_size; + return entry->mac_metadata; +} + +void +archive_entry_copy_mac_metadata(struct archive_entry *entry, + const void *p, size_t s) +{ + free(entry->mac_metadata); + if (p == NULL || s == 0) { + entry->mac_metadata = NULL; + entry->mac_metadata_size = 0; + } else { + entry->mac_metadata_size = s; + entry->mac_metadata = malloc(s); + if (entry->mac_metadata == NULL) + abort(); + memcpy(entry->mac_metadata, p, s); + } } /* @@ -1155,148 +1208,37 @@ archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name) * uninitiated. */ +struct archive_acl * +archive_entry_acl(struct archive_entry *entry) +{ + return &entry->acl; +} + void archive_entry_acl_clear(struct archive_entry *entry) { - struct ae_acl *ap; - - while (entry->acl_head != NULL) { - ap = entry->acl_head->next; - aes_clean(&entry->acl_head->name); - free(entry->acl_head); - entry->acl_head = ap; - } - if (entry->acl_text_w != NULL) { - free(entry->acl_text_w); - entry->acl_text_w = NULL; - } - entry->acl_p = NULL; - entry->acl_state = 0; /* Not counting. */ + archive_acl_clear(&entry->acl); } /* * Add a single ACL entry to the internal list of ACL data. */ -void +int archive_entry_acl_add_entry(struct archive_entry *entry, int type, int permset, int tag, int id, const char *name) { - struct ae_acl *ap; - - if (acl_special(entry, type, permset, tag) == 0) - return; - ap = acl_new_entry(entry, type, permset, tag, id); - if (ap == NULL) { - /* XXX Error XXX */ - return; - } - if (name != NULL && *name != '\0') - aes_copy_mbs(&ap->name, name); - else - aes_clean(&ap->name); + return archive_acl_add_entry(&entry->acl, type, permset, tag, id, name); } /* * As above, but with a wide-character name. */ -void +int archive_entry_acl_add_entry_w(struct archive_entry *entry, int type, int permset, int tag, int id, const wchar_t *name) { - archive_entry_acl_add_entry_w_len(entry, type, permset, tag, id, name, wcslen(name)); -} - -static void -archive_entry_acl_add_entry_w_len(struct archive_entry *entry, - int type, int permset, int tag, int id, const wchar_t *name, size_t len) -{ - struct ae_acl *ap; - - if (acl_special(entry, type, permset, tag) == 0) - return; - ap = acl_new_entry(entry, type, permset, tag, id); - if (ap == NULL) { - /* XXX Error XXX */ - return; - } - if (name != NULL && *name != L'\0' && len > 0) - aes_copy_wcs_len(&ap->name, name, len); - else - aes_clean(&ap->name); -} - -/* - * If this ACL entry is part of the standard POSIX permissions set, - * store the permissions in the stat structure and return zero. - */ -static int -acl_special(struct archive_entry *entry, int type, int permset, int tag) -{ - if (type == ARCHIVE_ENTRY_ACL_TYPE_ACCESS) { - switch (tag) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - entry->ae_stat.aest_mode &= ~0700; - entry->ae_stat.aest_mode |= (permset & 7) << 6; - return (0); - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - entry->ae_stat.aest_mode &= ~0070; - entry->ae_stat.aest_mode |= (permset & 7) << 3; - return (0); - case ARCHIVE_ENTRY_ACL_OTHER: - entry->ae_stat.aest_mode &= ~0007; - entry->ae_stat.aest_mode |= permset & 7; - return (0); - } - } - return (1); -} - -/* - * Allocate and populate a new ACL entry with everything but the - * name. - */ -static struct ae_acl * -acl_new_entry(struct archive_entry *entry, - int type, int permset, int tag, int id) -{ - struct ae_acl *ap, *aq; - - if (type != ARCHIVE_ENTRY_ACL_TYPE_ACCESS && - type != ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) - return (NULL); - if (entry->acl_text_w != NULL) { - free(entry->acl_text_w); - entry->acl_text_w = NULL; - } - - /* XXX TODO: More sanity-checks on the arguments XXX */ - - /* If there's a matching entry already in the list, overwrite it. */ - ap = entry->acl_head; - aq = NULL; - while (ap != NULL) { - if (ap->type == type && ap->tag == tag && ap->id == id) { - ap->permset = permset; - return (ap); - } - aq = ap; - ap = ap->next; - } - - /* Add a new entry to the end of the list. */ - ap = (struct ae_acl *)malloc(sizeof(*ap)); - if (ap == NULL) - return (NULL); - memset(ap, 0, sizeof(*ap)); - if (aq == NULL) - entry->acl_head = ap; - else - aq->next = ap; - ap->type = type; - ap->tag = tag; - ap->id = id; - ap->permset = permset; - return (ap); + return archive_acl_add_entry_w_len(&entry->acl, + type, permset, tag, id, name, wcslen(name)); } /* @@ -1305,20 +1247,7 @@ acl_new_entry(struct archive_entry *entry, int archive_entry_acl_count(struct archive_entry *entry, int want_type) { - int count; - struct ae_acl *ap; - - count = 0; - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & want_type) != 0) - count++; - ap = ap->next; - } - - if (count > 0 && ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) - count += 3; - return (count); + return archive_acl_count(&entry->acl, want_type); } /* @@ -1329,93 +1258,18 @@ archive_entry_acl_count(struct archive_entry *entry, int want_type) int archive_entry_acl_reset(struct archive_entry *entry, int want_type) { - int count, cutoff; - - count = archive_entry_acl_count(entry, want_type); - - /* - * If the only entries are the three standard ones, - * then don't return any ACL data. (In this case, - * client can just use chmod(2) to set permissions.) - */ - if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) - cutoff = 3; - else - cutoff = 0; - - if (count > cutoff) - entry->acl_state = ARCHIVE_ENTRY_ACL_USER_OBJ; - else - entry->acl_state = 0; - entry->acl_p = entry->acl_head; - return (count); + return archive_acl_reset(&entry->acl, want_type); } /* * Return the next ACL entry in the list. Fake entries for the * standard permissions and include them in the returned list. */ - int archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, int *permset, int *tag, int *id, const char **name) { - *name = NULL; - *id = -1; - - /* - * The acl_state is either zero (no entries available), -1 - * (reading from list), or an entry type (retrieve that type - * from ae_stat.aest_mode). - */ - if (entry->acl_state == 0) - return (ARCHIVE_WARN); - - /* The first three access entries are special. */ - if ((want_type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - switch (entry->acl_state) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - *permset = (entry->ae_stat.aest_mode >> 6) & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - entry->acl_state = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - return (ARCHIVE_OK); - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - *permset = (entry->ae_stat.aest_mode >> 3) & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - entry->acl_state = ARCHIVE_ENTRY_ACL_OTHER; - return (ARCHIVE_OK); - case ARCHIVE_ENTRY_ACL_OTHER: - *permset = entry->ae_stat.aest_mode & 7; - *type = ARCHIVE_ENTRY_ACL_TYPE_ACCESS; - *tag = ARCHIVE_ENTRY_ACL_OTHER; - entry->acl_state = -1; - entry->acl_p = entry->acl_head; - return (ARCHIVE_OK); - default: - break; - } - } - - while (entry->acl_p != NULL && (entry->acl_p->type & want_type) == 0) - entry->acl_p = entry->acl_p->next; - if (entry->acl_p == NULL) { - entry->acl_state = 0; - *type = 0; - *permset = 0; - *tag = 0; - *id = -1; - *name = NULL; - return (ARCHIVE_EOF); /* End of ACL entries. */ - } - *type = entry->acl_p->type; - *permset = entry->acl_p->permset; - *tag = entry->acl_p->tag; - *id = entry->acl_p->id; - *name = aes_get_mbs(&entry->acl_p->name); - entry->acl_p = entry->acl_p->next; - return (ARCHIVE_OK); + return archive_acl_next(entry->archive, &entry->acl, want_type, type, permset, tag, id, name); } /* @@ -1425,405 +1279,26 @@ archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type, const wchar_t * archive_entry_acl_text_w(struct archive_entry *entry, int flags) { - int count; - size_t length; - const wchar_t *wname; - const wchar_t *prefix; - wchar_t separator; - struct ae_acl *ap; - int id; - wchar_t *wp; - - if (entry->acl_text_w != NULL) { - free (entry->acl_text_w); - entry->acl_text_w = NULL; - } - - separator = L','; - count = 0; - length = 0; - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & flags) != 0) { - count++; - if ((flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) && - (ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)) - length += 8; /* "default:" */ - length += 5; /* tag name */ - length += 1; /* colon */ - wname = aes_get_wcs(&ap->name); - if (wname != NULL) - length += wcslen(wname); - else - length += sizeof(uid_t) * 3 + 1; - length ++; /* colon */ - length += 3; /* rwx */ - length += 1; /* colon */ - length += max(sizeof(uid_t), sizeof(gid_t)) * 3 + 1; - length ++; /* newline */ - } - ap = ap->next; - } - - if (count > 0 && ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0)) { - length += 10; /* "user::rwx\n" */ - length += 11; /* "group::rwx\n" */ - length += 11; /* "other::rwx\n" */ - } - - if (count == 0) - return (NULL); - - /* Now, allocate the string and actually populate it. */ - wp = entry->acl_text_w = (wchar_t *)malloc(length * sizeof(wchar_t)); - if (wp == NULL) - __archive_errx(1, "No memory to generate the text version of the ACL"); - count = 0; - if ((flags & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_USER_OBJ, NULL, - entry->ae_stat.aest_mode & 0700, -1); - *wp++ = ','; - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_GROUP_OBJ, NULL, - entry->ae_stat.aest_mode & 0070, -1); - *wp++ = ','; - append_entry_w(&wp, NULL, ARCHIVE_ENTRY_ACL_OTHER, NULL, - entry->ae_stat.aest_mode & 0007, -1); - count += 3; - - ap = entry->acl_head; - while (ap != NULL) { - if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) { - wname = aes_get_wcs(&ap->name); - *wp++ = separator; - if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) - id = ap->id; - else - id = -1; - append_entry_w(&wp, NULL, ap->tag, wname, - ap->permset, id); - count++; - } - ap = ap->next; - } - } - - - if ((flags & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { - if (flags & ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT) - prefix = L"default:"; - else - prefix = NULL; - ap = entry->acl_head; - count = 0; - while (ap != NULL) { - if ((ap->type & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0) { - wname = aes_get_wcs(&ap->name); - if (count > 0) - *wp++ = separator; - if (flags & ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID) - id = ap->id; - else - id = -1; - append_entry_w(&wp, prefix, ap->tag, - wname, ap->permset, id); - count ++; - } - ap = ap->next; - } - } - - return (entry->acl_text_w); -} - -static void -append_id_w(wchar_t **wp, int id) -{ - if (id < 0) - id = 0; - if (id > 9) - append_id_w(wp, id / 10); - *(*wp)++ = L"0123456789"[id % 10]; -} - -static void -append_entry_w(wchar_t **wp, const wchar_t *prefix, int tag, - const wchar_t *wname, int perm, int id) -{ - if (prefix != NULL) { - wcscpy(*wp, prefix); - *wp += wcslen(*wp); - } - switch (tag) { - case ARCHIVE_ENTRY_ACL_USER_OBJ: - wname = NULL; - id = -1; - /* FALLTHROUGH */ - case ARCHIVE_ENTRY_ACL_USER: - wcscpy(*wp, L"user"); - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - wname = NULL; - id = -1; - /* FALLTHROUGH */ - case ARCHIVE_ENTRY_ACL_GROUP: - wcscpy(*wp, L"group"); - break; - case ARCHIVE_ENTRY_ACL_MASK: - wcscpy(*wp, L"mask"); - wname = NULL; - id = -1; - break; - case ARCHIVE_ENTRY_ACL_OTHER: - wcscpy(*wp, L"other"); - wname = NULL; - id = -1; - break; - } - *wp += wcslen(*wp); - *(*wp)++ = L':'; - if (wname != NULL) { - wcscpy(*wp, wname); - *wp += wcslen(*wp); - } else if (tag == ARCHIVE_ENTRY_ACL_USER - || tag == ARCHIVE_ENTRY_ACL_GROUP) { - append_id_w(wp, id); - id = -1; - } - *(*wp)++ = L':'; - *(*wp)++ = (perm & 0444) ? L'r' : L'-'; - *(*wp)++ = (perm & 0222) ? L'w' : L'-'; - *(*wp)++ = (perm & 0111) ? L'x' : L'-'; - if (id != -1) { - *(*wp)++ = L':'; - append_id_w(wp, id); - } - **wp = L'\0'; + return archive_acl_text_w(entry->archive, &entry->acl, flags); } -/* - * Parse a textual ACL. This automatically recognizes and supports - * extensions described above. The 'type' argument is used to - * indicate the type that should be used for any entries not - * explicitly marked as "default:". - */ -int -__archive_entry_acl_parse_w(struct archive_entry *entry, - const wchar_t *text, int default_type) -{ - struct { - const wchar_t *start; - const wchar_t *end; - } field[4], name; - - int fields; - int type, tag, permset, id; - wchar_t sep; - - while (text != NULL && *text != L'\0') { - /* - * Parse the fields out of the next entry, - * advance 'text' to start of next entry. - */ - fields = 0; - do { - const wchar_t *start, *end; - next_field_w(&text, &start, &end, &sep); - if (fields < 4) { - field[fields].start = start; - field[fields].end = end; - } - ++fields; - } while (sep == L':'); - - /* Check for a numeric ID in field 1 or 3. */ - id = -1; - isint_w(field[1].start, field[1].end, &id); - /* Field 3 is optional. */ - if (id == -1 && fields > 3) - isint_w(field[3].start, field[3].end, &id); - - /* - * Solaris extension: "defaultuser::rwx" is the - * default ACL corresponding to "user::rwx", etc. - */ - if (field[0].end-field[0].start > 7 - && wmemcmp(field[0].start, L"default", 7) == 0) { - type = ARCHIVE_ENTRY_ACL_TYPE_DEFAULT; - field[0].start += 7; - } else - type = default_type; - - name.start = name.end = NULL; - if (prefix_w(field[0].start, field[0].end, L"user")) { - if (!ismode_w(field[2].start, field[2].end, &permset)) - return (ARCHIVE_WARN); - if (id != -1 || field[1].start < field[1].end) { - tag = ARCHIVE_ENTRY_ACL_USER; - name = field[1]; - } else - tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - } else if (prefix_w(field[0].start, field[0].end, L"group")) { - if (!ismode_w(field[2].start, field[2].end, &permset)) - return (ARCHIVE_WARN); - if (id != -1 || field[1].start < field[1].end) { - tag = ARCHIVE_ENTRY_ACL_GROUP; - name = field[1]; - } else - tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - } else if (prefix_w(field[0].start, field[0].end, L"other")) { - if (fields == 2 - && field[1].start < field[1].end - && ismode_w(field[1].start, field[2].end, &permset)) { - /* This is Solaris-style "other:rwx" */ - } else if (fields == 3 - && field[1].start == field[1].end - && field[2].start < field[2].end - && ismode_w(field[2].start, field[2].end, &permset)) { - /* This is FreeBSD-style "other::rwx" */ - } else - return (ARCHIVE_WARN); - tag = ARCHIVE_ENTRY_ACL_OTHER; - } else if (prefix_w(field[0].start, field[0].end, L"mask")) { - if (fields == 2 - && field[1].start < field[1].end - && ismode_w(field[1].start, field[1].end, &permset)) { - /* This is Solaris-style "mask:rwx" */ - } else if (fields == 3 - && field[1].start == field[1].end - && field[2].start < field[2].end - && ismode_w(field[2].start, field[2].end, &permset)) { - /* This is FreeBSD-style "mask::rwx" */ - } else - return (ARCHIVE_WARN); - tag = ARCHIVE_ENTRY_ACL_MASK; - } else - return (ARCHIVE_WARN); - - /* Add entry to the internal list. */ - archive_entry_acl_add_entry_w_len(entry, type, permset, - tag, id, name.start, name.end - name.start); - } - return (ARCHIVE_OK); -} - -/* - * Parse a string to a positive decimal integer. Returns true if - * the string is non-empty and consists only of decimal digits, - * false otherwise. - */ -static int -isint_w(const wchar_t *start, const wchar_t *end, int *result) -{ - int n = 0; - if (start >= end) - return (0); - while (start < end) { - if (*start < '0' || *start > '9') - return (0); - if (n > (INT_MAX / 10)) - n = INT_MAX; - else { - n *= 10; - n += *start - '0'; - } - start++; - } - *result = n; - return (1); -} - -/* - * Parse a string as a mode field. Returns true if - * the string is non-empty and consists only of mode characters, - * false otherwise. - */ -static int -ismode_w(const wchar_t *start, const wchar_t *end, int *permset) -{ - const wchar_t *p; - - p = start; - *permset = 0; - while (p < end) { - switch (*p++) { - case 'r': case 'R': - *permset |= ARCHIVE_ENTRY_ACL_READ; - break; - case 'w': case 'W': - *permset |= ARCHIVE_ENTRY_ACL_WRITE; - break; - case 'x': case 'X': - *permset |= ARCHIVE_ENTRY_ACL_EXECUTE; - break; - case '-': - break; - default: - return (0); - } - } - return (1); -} - -/* - * Match "[:whitespace:]*(.*)[:whitespace:]*[:,\n]". *wp is updated - * to point to just after the separator. *start points to the first - * character of the matched text and *end just after the last - * character of the matched identifier. In particular *end - *start - * is the length of the field body, not including leading or trailing - * whitespace. - */ -static void -next_field_w(const wchar_t **wp, const wchar_t **start, - const wchar_t **end, wchar_t *sep) -{ - /* Skip leading whitespace to find start of field. */ - while (**wp == L' ' || **wp == L'\t' || **wp == L'\n') { - (*wp)++; - } - *start = *wp; - - /* Scan for the separator. */ - while (**wp != L'\0' && **wp != L',' && **wp != L':' && - **wp != L'\n') { - (*wp)++; - } - *sep = **wp; - - /* Trim trailing whitespace to locate end of field. */ - *end = *wp - 1; - while (**end == L' ' || **end == L'\t' || **end == L'\n') { - (*end)--; - } - (*end)++; - - /* Adjust scanner location. */ - if (**wp != L'\0') - (*wp)++; +const char * +archive_entry_acl_text(struct archive_entry *entry, int flags) +{ + const char *p; + if (archive_acl_text_l(&entry->acl, flags, &p, NULL, NULL) != 0 + && errno == ENOMEM) + return (NULL); + return (p); } -/* - * Return true if the characters [start...end) are a prefix of 'test'. - * This makes it easy to handle the obvious abbreviations: 'u' for 'user', etc. - */ -static int -prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test) +int +_archive_entry_acl_text_l(struct archive_entry *entry, int flags, + const char **acl_text, size_t *len, struct archive_string_conv *sc) { - if (start == end) - return (0); - - if (*start++ != *test++) - return (0); - - while (start < end && *start++ == *test++) - ; - - if (start < end) - return (0); - - return (1); + return (archive_acl_text_l(&entry->acl, flags, acl_text, len, sc)); } - /* * Following code is modified from UC Berkeley sources, and * is subject to the following copyright notice. @@ -1831,7 +1306,7 @@ prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test) /*- * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -1859,248 +1334,300 @@ prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test) */ static struct flag { - const char *name; - const wchar_t *wname; - unsigned long set; - unsigned long clear; + const char *name; + const wchar_t *wname; + unsigned long set; + unsigned long clear; } flags[] = { - /* Preferred (shorter) names per flag first, all prefixed by "no" */ + /* Preferred (shorter) names per flag first, all prefixed by "no" */ #ifdef SF_APPEND - { "nosappnd", L"nosappnd", SF_APPEND, 0 }, - { "nosappend", L"nosappend", SF_APPEND, 0 }, + { "nosappnd", L"nosappnd", SF_APPEND, 0 }, + { "nosappend", L"nosappend", SF_APPEND, 0 }, #endif -#ifdef EXT2_APPEND_FL /* 'a' */ - { "nosappnd", L"nosappnd", EXT2_APPEND_FL, 0 }, - { "nosappend", L"nosappend", EXT2_APPEND_FL, 0 }, +#ifdef EXT2_APPEND_FL /* 'a' */ + { "nosappnd", L"nosappnd", EXT2_APPEND_FL, 0 }, + { "nosappend", L"nosappend", EXT2_APPEND_FL, 0 }, #endif #ifdef SF_ARCHIVED - { "noarch", L"noarch", SF_ARCHIVED, 0 }, - { "noarchived", L"noarchived", SF_ARCHIVED, 0 }, + { "noarch", L"noarch", SF_ARCHIVED, 0 }, + { "noarchived", L"noarchived", SF_ARCHIVED, 0 }, #endif #ifdef SF_IMMUTABLE - { "noschg", L"noschg", SF_IMMUTABLE, 0 }, - { "noschange", L"noschange", SF_IMMUTABLE, 0 }, - { "nosimmutable", L"nosimmutable", SF_IMMUTABLE, 0 }, + { "noschg", L"noschg", SF_IMMUTABLE, 0 }, + { "noschange", L"noschange", SF_IMMUTABLE, 0 }, + { "nosimmutable", L"nosimmutable", SF_IMMUTABLE, 0 }, #endif -#ifdef EXT2_IMMUTABLE_FL /* 'i' */ - { "noschg", L"noschg", EXT2_IMMUTABLE_FL, 0 }, - { "noschange", L"noschange", EXT2_IMMUTABLE_FL, 0 }, - { "nosimmutable", L"nosimmutable", EXT2_IMMUTABLE_FL, 0 }, +#ifdef EXT2_IMMUTABLE_FL /* 'i' */ + { "noschg", L"noschg", EXT2_IMMUTABLE_FL, 0 }, + { "noschange", L"noschange", EXT2_IMMUTABLE_FL, 0 }, + { "nosimmutable", L"nosimmutable", EXT2_IMMUTABLE_FL, 0 }, #endif #ifdef SF_NOUNLINK - { "nosunlnk", L"nosunlnk", SF_NOUNLINK, 0 }, - { "nosunlink", L"nosunlink", SF_NOUNLINK, 0 }, + { "nosunlnk", L"nosunlnk", SF_NOUNLINK, 0 }, + { "nosunlink", L"nosunlink", SF_NOUNLINK, 0 }, #endif #ifdef SF_SNAPSHOT - { "nosnapshot", L"nosnapshot", SF_SNAPSHOT, 0 }, + { "nosnapshot", L"nosnapshot", SF_SNAPSHOT, 0 }, #endif #ifdef UF_APPEND - { "nouappnd", L"nouappnd", UF_APPEND, 0 }, - { "nouappend", L"nouappend", UF_APPEND, 0 }, + { "nouappnd", L"nouappnd", UF_APPEND, 0 }, + { "nouappend", L"nouappend", UF_APPEND, 0 }, #endif #ifdef UF_IMMUTABLE - { "nouchg", L"nouchg", UF_IMMUTABLE, 0 }, - { "nouchange", L"nouchange", UF_IMMUTABLE, 0 }, - { "nouimmutable", L"nouimmutable", UF_IMMUTABLE, 0 }, + { "nouchg", L"nouchg", UF_IMMUTABLE, 0 }, + { "nouchange", L"nouchange", UF_IMMUTABLE, 0 }, + { "nouimmutable", L"nouimmutable", UF_IMMUTABLE, 0 }, #endif #ifdef UF_NODUMP - { "nodump", L"nodump", 0, UF_NODUMP}, + { "nodump", L"nodump", 0, UF_NODUMP}, #endif -#ifdef EXT2_NODUMP_FL /* 'd' */ - { "nodump", L"nodump", 0, EXT2_NODUMP_FL}, +#ifdef EXT2_NODUMP_FL /* 'd' */ + { "nodump", L"nodump", 0, EXT2_NODUMP_FL}, #endif #ifdef UF_OPAQUE - { "noopaque", L"noopaque", UF_OPAQUE, 0 }, + { "noopaque", L"noopaque", UF_OPAQUE, 0 }, #endif #ifdef UF_NOUNLINK - { "nouunlnk", L"nouunlnk", UF_NOUNLINK, 0 }, - { "nouunlink", L"nouunlink", UF_NOUNLINK, 0 }, + { "nouunlnk", L"nouunlnk", UF_NOUNLINK, 0 }, + { "nouunlink", L"nouunlink", UF_NOUNLINK, 0 }, +#endif +#ifdef EXT2_UNRM_FL + { "nouunlink", L"nouunlink", EXT2_UNRM_FL, 0}, +#endif + +#ifdef EXT2_BTREE_FL + { "nobtree", L"nobtree", EXT2_BTREE_FL, 0 }, +#endif + +#ifdef EXT2_ECOMPR_FL + { "nocomperr", L"nocomperr", EXT2_ECOMPR_FL, 0 }, #endif -#ifdef EXT2_COMPR_FL /* 'c' */ - { "nocompress", L"nocompress", EXT2_COMPR_FL, 0 }, + +#ifdef EXT2_COMPR_FL /* 'c' */ + { "nocompress", L"nocompress", EXT2_COMPR_FL, 0 }, +#endif + +#ifdef EXT2_NOATIME_FL /* 'A' */ + { "noatime", L"noatime", 0, EXT2_NOATIME_FL}, #endif -#ifdef EXT2_NOATIME_FL /* 'A' */ - { "noatime", L"noatime", 0, EXT2_NOATIME_FL}, +#ifdef EXT2_DIRTY_FL + { "nocompdirty",L"nocompdirty", EXT2_DIRTY_FL, 0}, +#endif + +#ifdef EXT2_COMPRBLK_FL +#ifdef EXT2_NOCOMPR_FL + { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, EXT2_NOCOMPR_FL}, +#else + { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, 0}, #endif - { NULL, NULL, 0, 0 } +#endif +#ifdef EXT2_DIRSYNC_FL + { "nodirsync", L"nodirsync", EXT2_DIRSYNC_FL, 0}, +#endif +#ifdef EXT2_INDEX_FL + { "nohashidx", L"nohashidx", EXT2_INDEX_FL, 0}, +#endif +#ifdef EXT2_IMAGIC_FL + { "noimagic", L"noimagic", EXT2_IMAGIC_FL, 0}, +#endif +#ifdef EXT3_JOURNAL_DATA_FL + { "nojournal", L"nojournal", EXT3_JOURNAL_DATA_FL, 0}, +#endif +#ifdef EXT2_SECRM_FL + { "nosecuredeletion",L"nosecuredeletion",EXT2_SECRM_FL, 0}, +#endif +#ifdef EXT2_SYNC_FL + { "nosync", L"nosync", EXT2_SYNC_FL, 0}, +#endif +#ifdef EXT2_NOTAIL_FL + { "notail", L"notail", 0, EXT2_NOTAIL_FL}, +#endif +#ifdef EXT2_TOPDIR_FL + { "notopdir", L"notopdir", EXT2_TOPDIR_FL, 0}, +#endif +#ifdef EXT2_RESERVED_FL + { "noreserved", L"noreserved", EXT2_RESERVED_FL, 0}, +#endif + + { NULL, NULL, 0, 0 } }; /* * fflagstostr -- - * Convert file flags to a comma-separated string. If no flags - * are set, return the empty string. + * Convert file flags to a comma-separated string. If no flags + * are set, return the empty string. */ static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear) { - char *string, *dp; - const char *sp; - unsigned long bits; - struct flag *flag; - size_t length; - - bits = bitset | bitclear; - length = 0; - for (flag = flags; flag->name != NULL; flag++) - if (bits & (flag->set | flag->clear)) { - length += strlen(flag->name) + 1; - bits &= ~(flag->set | flag->clear); - } - - if (length == 0) - return (NULL); - string = (char *)malloc(length); - if (string == NULL) - return (NULL); - - dp = string; - for (flag = flags; flag->name != NULL; flag++) { - if (bitset & flag->set || bitclear & flag->clear) { - sp = flag->name + 2; - } else if (bitset & flag->clear || bitclear & flag->set) { - sp = flag->name; - } else - continue; - bitset &= ~(flag->set | flag->clear); - bitclear &= ~(flag->set | flag->clear); - if (dp > string) - *dp++ = ','; - while ((*dp++ = *sp++) != '\0') - ; - dp--; - } - - *dp = '\0'; - return (string); + char *string, *dp; + const char *sp; + unsigned long bits; + struct flag *flag; + size_t length; + + bits = bitset | bitclear; + length = 0; + for (flag = flags; flag->name != NULL; flag++) + if (bits & (flag->set | flag->clear)) { + length += strlen(flag->name) + 1; + bits &= ~(flag->set | flag->clear); + } + + if (length == 0) + return (NULL); + string = (char *)malloc(length); + if (string == NULL) + return (NULL); + + dp = string; + for (flag = flags; flag->name != NULL; flag++) { + if (bitset & flag->set || bitclear & flag->clear) { + sp = flag->name + 2; + } else if (bitset & flag->clear || bitclear & flag->set) { + sp = flag->name; + } else + continue; + bitset &= ~(flag->set | flag->clear); + bitclear &= ~(flag->set | flag->clear); + if (dp > string) + *dp++ = ','; + while ((*dp++ = *sp++) != '\0') + ; + dp--; + } + + *dp = '\0'; + return (string); } /* * strtofflags -- - * Take string of arguments and return file flags. This - * version works a little differently than strtofflags(3). - * In particular, it always tests every token, skipping any - * unrecognized tokens. It returns a pointer to the first - * unrecognized token, or NULL if every token was recognized. - * This version is also const-correct and does not modify the - * provided string. + * Take string of arguments and return file flags. This + * version works a little differently than strtofflags(3). + * In particular, it always tests every token, skipping any + * unrecognized tokens. It returns a pointer to the first + * unrecognized token, or NULL if every token was recognized. + * This version is also const-correct and does not modify the + * provided string. */ static const char * ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp) { - const char *start, *end; - struct flag *flag; - unsigned long set, clear; - const char *failed; - - set = clear = 0; - start = s; - failed = NULL; - /* Find start of first token. */ - while (*start == '\t' || *start == ' ' || *start == ',') - start++; - while (*start != '\0') { - /* Locate end of token. */ - end = start; - while (*end != '\0' && *end != '\t' && - *end != ' ' && *end != ',') - end++; - for (flag = flags; flag->name != NULL; flag++) { - if (memcmp(start, flag->name, end - start) == 0) { - /* Matched "noXXXX", so reverse the sense. */ - clear |= flag->set; - set |= flag->clear; - break; - } else if (memcmp(start, flag->name + 2, end - start) - == 0) { - /* Matched "XXXX", so don't reverse. */ - set |= flag->set; - clear |= flag->clear; - break; - } - } - /* Ignore unknown flag names. */ - if (flag->name == NULL && failed == NULL) - failed = start; - - /* Find start of next token. */ - start = end; - while (*start == '\t' || *start == ' ' || *start == ',') - start++; - - } - - if (setp) - *setp = set; - if (clrp) - *clrp = clear; - - /* Return location of first failure. */ - return (failed); + const char *start, *end; + struct flag *flag; + unsigned long set, clear; + const char *failed; + + set = clear = 0; + start = s; + failed = NULL; + /* Find start of first token. */ + while (*start == '\t' || *start == ' ' || *start == ',') + start++; + while (*start != '\0') { + /* Locate end of token. */ + end = start; + while (*end != '\0' && *end != '\t' && + *end != ' ' && *end != ',') + end++; + for (flag = flags; flag->name != NULL; flag++) { + if (memcmp(start, flag->name, end - start) == 0) { + /* Matched "noXXXX", so reverse the sense. */ + clear |= flag->set; + set |= flag->clear; + break; + } else if (memcmp(start, flag->name + 2, end - start) + == 0) { + /* Matched "XXXX", so don't reverse. */ + set |= flag->set; + clear |= flag->clear; + break; + } + } + /* Ignore unknown flag names. */ + if (flag->name == NULL && failed == NULL) + failed = start; + + /* Find start of next token. */ + start = end; + while (*start == '\t' || *start == ' ' || *start == ',') + start++; + + } + + if (setp) + *setp = set; + if (clrp) + *clrp = clear; + + /* Return location of first failure. */ + return (failed); } /* * wcstofflags -- - * Take string of arguments and return file flags. This - * version works a little differently than strtofflags(3). - * In particular, it always tests every token, skipping any - * unrecognized tokens. It returns a pointer to the first - * unrecognized token, or NULL if every token was recognized. - * This version is also const-correct and does not modify the - * provided string. + * Take string of arguments and return file flags. This + * version works a little differently than strtofflags(3). + * In particular, it always tests every token, skipping any + * unrecognized tokens. It returns a pointer to the first + * unrecognized token, or NULL if every token was recognized. + * This version is also const-correct and does not modify the + * provided string. */ static const wchar_t * ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) { - const wchar_t *start, *end; - struct flag *flag; - unsigned long set, clear; - const wchar_t *failed; - - set = clear = 0; - start = s; - failed = NULL; - /* Find start of first token. */ - while (*start == L'\t' || *start == L' ' || *start == L',') - start++; - while (*start != L'\0') { - /* Locate end of token. */ - end = start; - while (*end != L'\0' && *end != L'\t' && - *end != L' ' && *end != L',') - end++; - for (flag = flags; flag->wname != NULL; flag++) { - if (wmemcmp(start, flag->wname, end - start) == 0) { - /* Matched "noXXXX", so reverse the sense. */ - clear |= flag->set; - set |= flag->clear; - break; - } else if (wmemcmp(start, flag->wname + 2, end - start) - == 0) { - /* Matched "XXXX", so don't reverse. */ - set |= flag->set; - clear |= flag->clear; - break; - } - } - /* Ignore unknown flag names. */ - if (flag->wname == NULL && failed == NULL) - failed = start; - - /* Find start of next token. */ - start = end; - while (*start == L'\t' || *start == L' ' || *start == L',') - start++; - - } - - if (setp) - *setp = set; - if (clrp) - *clrp = clear; - - /* Return location of first failure. */ - return (failed); + const wchar_t *start, *end; + struct flag *flag; + unsigned long set, clear; + const wchar_t *failed; + + set = clear = 0; + start = s; + failed = NULL; + /* Find start of first token. */ + while (*start == L'\t' || *start == L' ' || *start == L',') + start++; + while (*start != L'\0') { + /* Locate end of token. */ + end = start; + while (*end != L'\0' && *end != L'\t' && + *end != L' ' && *end != L',') + end++; + for (flag = flags; flag->wname != NULL; flag++) { + if (wmemcmp(start, flag->wname, end - start) == 0) { + /* Matched "noXXXX", so reverse the sense. */ + clear |= flag->set; + set |= flag->clear; + break; + } else if (wmemcmp(start, flag->wname + 2, end - start) + == 0) { + /* Matched "XXXX", so don't reverse. */ + set |= flag->set; + clear |= flag->clear; + break; + } + } + /* Ignore unknown flag names. */ + if (flag->wname == NULL && failed == NULL) + failed = start; + + /* Find start of next token. */ + start = end; + while (*start == L'\t' || *start == L' ' || *start == L',') + start++; + + } + + if (setp) + *setp = set; + if (clrp) + *clrp = clear; + + /* Return location of first failure. */ + return (failed); } @@ -2109,16 +1636,16 @@ ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp) int main(int argc, char **argv) { - struct archive_entry *entry = archive_entry_new(); - unsigned long set, clear; - const wchar_t *remainder; + struct archive_entry *entry = archive_entry_new(); + unsigned long set, clear; + const wchar_t *remainder; - remainder = archive_entry_copy_fflags_text_w(entry, L"nosappnd dump archive,,,,,,,"); - archive_entry_fflags(entry, &set, &clear); + remainder = archive_entry_copy_fflags_text_w(entry, L"nosappnd dump archive,,,,,,,"); + archive_entry_fflags(entry, &set, &clear); - wprintf(L"set=0x%lX clear=0x%lX remainder='%ls'\n", set, clear, remainder); + wprintf(L"set=0x%lX clear=0x%lX remainder='%ls'\n", set, clear, remainder); - wprintf(L"new flags='%s'\n", archive_entry_fflags_text(entry)); - return (0); + wprintf(L"new flags='%s'\n", archive_entry_fflags_text(entry)); + return (0); } #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_entry.h b/Utilities/cmlibarchive/libarchive/archive_entry.h index e85285f9d..9c44e25f8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry.h @@ -22,11 +22,14 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_entry.h,v 1.31 2008/12/06 06:18:46 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_entry.h 201096 2009-12-28 02:41:27Z kientzle $ */ #ifndef ARCHIVE_ENTRY_H_INCLUDED -#define ARCHIVE_ENTRY_H_INCLUDED +#define ARCHIVE_ENTRY_H_INCLUDED + +/* Note: Compiler will complain if this does not match archive.h! */ +#define ARCHIVE_VERSION_NUMBER 3000002 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -47,38 +50,35 @@ /* Get appropriate definitions of standard POSIX-style types. */ /* These should match the types used in 'struct stat' */ #if defined(_WIN32) && !defined(__CYGWIN__) -#define __LA_INT64_T __int64 +#define __LA_INT64_T __int64 # if defined(__BORLANDC__) -# define __LA_UID_T uid_t -# define __LA_GID_T gid_t -# define __LA_DEV_T dev_t -# define __LA_MODE_T mode_t +# define __LA_UID_T uid_t /* Remove in libarchive 3.2 */ +# define __LA_GID_T gid_t /* Remove in libarchive 3.2 */ +# define __LA_DEV_T dev_t +# define __LA_MODE_T mode_t # else -# define __LA_UID_T short -# define __LA_GID_T short -# define __LA_DEV_T unsigned int -# define __LA_MODE_T unsigned short +# define __LA_UID_T short /* Remove in libarchive 3.2 */ +# define __LA_GID_T short /* Remove in libarchive 3.2 */ +# define __LA_DEV_T unsigned int +# define __LA_MODE_T unsigned short # endif #else -# include -#ifdef __osf__ -# define __LA_INT64_T long long -#else -# define __LA_INT64_T int64_t -#endif -#define __LA_UID_T uid_t -#define __LA_GID_T gid_t -#define __LA_DEV_T dev_t -#define __LA_MODE_T mode_t +#include +# if defined(_SCO_DS) || defined(__osf__) +# define __LA_INT64_T long long +# else +# define __LA_INT64_T int64_t +# endif +# define __LA_UID_T uid_t /* Remove in libarchive 3.2 */ +# define __LA_GID_T gid_t /* Remove in libarchive 3.2 */ +# define __LA_DEV_T dev_t +# define __LA_MODE_T mode_t #endif /* - * XXX Is this defined for all Windows compilers? If so, in what - * header? It would be nice to remove the __LA_INO_T indirection and - * just use plain ino_t everywhere. Likewise for the other types just - * above. + * Remove this for libarchive 3.2, since ino_t is no longer used. */ -#define __LA_INO_T ino_t +#define __LA_INO_T ino_t /* @@ -89,15 +89,15 @@ #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) # ifdef __LIBARCHIVE_BUILD # ifdef __GNUC__ -# define __LA_DECL __attribute__((dllexport)) extern +# define __LA_DECL __attribute__((dllexport)) extern # else -# define __LA_DECL __declspec(dllexport) +# define __LA_DECL __declspec(dllexport) # endif # else # ifdef __GNUC__ -# define __LA_DECL __attribute__((dllimport)) extern +# define __LA_DECL # else -# define __LA_DECL __declspec(dllimport) +# define __LA_DECL __declspec(dllimport) # endif # endif #else @@ -125,6 +125,7 @@ extern "C" { * applications (e.g., a package manager could attach special * package-management attributes to each entry). */ +struct archive; struct archive_entry; /* @@ -148,24 +149,33 @@ struct archive_entry; * portable values to platform-native values when entries are read from * or written to disk. */ -#define AE_IFMT ((__LA_MODE_T)0170000) -#define AE_IFREG ((__LA_MODE_T)0100000) -#define AE_IFLNK ((__LA_MODE_T)0120000) -#define AE_IFSOCK ((__LA_MODE_T)0140000) -#define AE_IFCHR ((__LA_MODE_T)0020000) -#define AE_IFBLK ((__LA_MODE_T)0060000) -#define AE_IFDIR ((__LA_MODE_T)0040000) -#define AE_IFIFO ((__LA_MODE_T)0010000) +#define AE_IFMT ((__LA_MODE_T)0170000) +#define AE_IFREG ((__LA_MODE_T)0100000) +#define AE_IFLNK ((__LA_MODE_T)0120000) +#define AE_IFSOCK ((__LA_MODE_T)0140000) +#define AE_IFCHR ((__LA_MODE_T)0020000) +#define AE_IFBLK ((__LA_MODE_T)0060000) +#define AE_IFDIR ((__LA_MODE_T)0040000) +#define AE_IFIFO ((__LA_MODE_T)0010000) /* * Basic object manipulation */ -__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *); +__LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *); /* The 'clone' function does a deep copy; all of the strings are copied too. */ -__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *); -__LA_DECL void archive_entry_free(struct archive_entry *); -__LA_DECL struct archive_entry *archive_entry_new(void); +__LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *); +__LA_DECL void archive_entry_free(struct archive_entry *); +__LA_DECL struct archive_entry *archive_entry_new(void); + +/* + * This form of archive_entry_new2() will pull character-set + * conversion information from the specified archive handle. The + * older archive_entry_new(void) form is equivalent to calling + * archive_entry_new2(NULL) and will result in the use of an internal + * default character-set conversion. + */ +__LA_DECL struct archive_entry *archive_entry_new2(struct archive *); /* * Retrieve fields from an archive_entry. @@ -186,125 +196,124 @@ __LA_DECL struct archive_entry *archive_entry_new(void); * also return NULL when implicit character set conversions fail. * This is usually what you want. */ -__LA_DECL time_t archive_entry_atime(struct archive_entry *); -__LA_DECL long archive_entry_atime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_atime_is_set(struct archive_entry *); -__LA_DECL time_t archive_entry_birthtime(struct archive_entry *); -__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *); -__LA_DECL time_t archive_entry_ctime(struct archive_entry *); -__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *); -__LA_DECL dev_t archive_entry_dev(struct archive_entry *); -__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); -__LA_DECL dev_t archive_entry_devminor(struct archive_entry *); -__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); -__LA_DECL void archive_entry_fflags(struct archive_entry *, - unsigned long * /* set */, - unsigned long * /* clear */); -__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); -__LA_DECL __LA_GID_T archive_entry_gid(struct archive_entry *); -__LA_DECL const char *archive_entry_gname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); -__LA_DECL const char *archive_entry_hardlink(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); -__LA_DECL __LA_INO_T archive_entry_ino(struct archive_entry *); -__LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); -__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); -__LA_DECL time_t archive_entry_mtime(struct archive_entry *); -__LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); -__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); -__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); -__LA_DECL const char *archive_entry_pathname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdev(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); -__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); -__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); -__LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); -__LA_DECL int archive_entry_size_is_set(struct archive_entry *); -__LA_DECL const char *archive_entry_strmode(struct archive_entry *); -__LA_DECL const char *archive_entry_symlink(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); -__LA_DECL __LA_UID_T archive_entry_uid(struct archive_entry *); -__LA_DECL const char *archive_entry_uname(struct archive_entry *); -__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); +__LA_DECL time_t archive_entry_atime(struct archive_entry *); +__LA_DECL long archive_entry_atime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_atime_is_set(struct archive_entry *); +__LA_DECL time_t archive_entry_birthtime(struct archive_entry *); +__LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *); +__LA_DECL time_t archive_entry_ctime(struct archive_entry *); +__LA_DECL long archive_entry_ctime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_ctime_is_set(struct archive_entry *); +__LA_DECL dev_t archive_entry_dev(struct archive_entry *); +__LA_DECL int archive_entry_dev_is_set(struct archive_entry *); +__LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); +__LA_DECL dev_t archive_entry_devminor(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); +__LA_DECL void archive_entry_fflags(struct archive_entry *, + unsigned long * /* set */, + unsigned long * /* clear */); +__LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); +__LA_DECL __LA_INT64_T archive_entry_gid(struct archive_entry *); +__LA_DECL const char *archive_entry_gname(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); +__LA_DECL const char *archive_entry_hardlink(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); +__LA_DECL __LA_INT64_T archive_entry_ino(struct archive_entry *); +__LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); +__LA_DECL int archive_entry_ino_is_set(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); +__LA_DECL time_t archive_entry_mtime(struct archive_entry *); +__LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); +__LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); +__LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); +__LA_DECL const char *archive_entry_pathname(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); +__LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdev(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); +__LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); +__LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *); +__LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); +__LA_DECL int archive_entry_size_is_set(struct archive_entry *); +__LA_DECL const char *archive_entry_strmode(struct archive_entry *); +__LA_DECL const char *archive_entry_symlink(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); +__LA_DECL __LA_INT64_T archive_entry_uid(struct archive_entry *); +__LA_DECL const char *archive_entry_uname(struct archive_entry *); +__LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); /* * Set fields in an archive_entry. * - * Note that string 'set' functions do not copy the string, only the pointer. - * In contrast, 'copy' functions do copy the object pointed to. - * - * Note: As of libarchive 2.4, 'set' functions do copy the string and - * are therefore exact synonyms for the 'copy' versions. The 'copy' - * names will be retired in libarchive 3.0. + * Note: Before libarchive 2.4, there were 'set' and 'copy' versions + * of the string setters. 'copy' copied the actual string, 'set' just + * stored the pointer. In libarchive 2.4 and later, strings are + * always copied. */ -__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_atime(struct archive_entry *); #if defined(_WIN32) && !defined(__CYGWIN__) -__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, - BY_HANDLE_FILE_INFORMATION *); +__LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, BY_HANDLE_FILE_INFORMATION *); #endif -__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_birthtime(struct archive_entry *); -__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long); +__LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_ctime(struct archive_entry *); -__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int); -__LA_DECL void archive_entry_set_fflags(struct archive_entry *, - unsigned long /* set */, unsigned long /* clear */); +__LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int); +__LA_DECL void archive_entry_set_fflags(struct archive_entry *, + unsigned long /* set */, unsigned long /* clear */); /* Returns pointer to start of first invalid token, or NULL if none. */ /* Note that all recognized tokens are processed, regardless. */ __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *, - const char *); + const char *); __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, - const wchar_t *); -__LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_GID_T); -__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); -#if ARCHIVE_VERSION_NUMBER >= 3000000 -/* Starting with libarchive 3.0, this will be synonym for ino64. */ -__LA_DECL void archive_entry_set_ino(struct archive_entry *, int64_t); -#else -__LA_DECL void archive_entry_set_ino(struct archive_entry *, unsigned long); -#endif -__LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); -__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T); -__LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); + const wchar_t *); +__LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_INT64_T); +__LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T); +__LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); +__LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T); +__LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); __LA_DECL void archive_entry_unset_mtime(struct archive_entry *); -__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); -__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); -__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); -__LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T); -__LA_DECL void archive_entry_unset_size(struct archive_entry *); -__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); -__LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_UID_T); -__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); -__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); -__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); +__LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); +__LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); +__LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T); +__LA_DECL void archive_entry_unset_size(struct archive_entry *); +__LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *); +__LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); +__LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_INT64_T); +__LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); +__LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); +__LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); /* * Routines to bulk copy fields to/from a platform-native "struct * stat." Libarchive used to just store a struct stat inside of each @@ -314,9 +323,18 @@ __LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const ch * * TODO: On Linux, provide both stat32 and stat64 versions of these functions. */ -__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *); -__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *); +__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *); +__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *); +/* + * Storage for Mac OS-specific AppleDouble metadata information. + * Apple-format tar files store a separate binary blob containing + * encoded metadata with ACL, extended attributes, etc. + * This provides a place to store that blob. + */ + +__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); /* * ACL routines. This used to simply store and return text-format ACL @@ -328,32 +346,95 @@ __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct sta * * This last point, in particular, forces me to implement a reasonably * complete set of ACL support routines. - * - * TODO: Extend this to support NFSv4/NTFS permissions. That should - * allow full ACL support on Mac OS, in particular, which uses - * POSIX.1e-style interfaces to manipulate NFSv4/NTFS permissions. */ /* - * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's - * "permset"/"perm" abstract type nonsense. A permset is just a simple - * bitmap, following long-standing Unix tradition. + * Permission bits. */ -#define ARCHIVE_ENTRY_ACL_EXECUTE 1 -#define ARCHIVE_ENTRY_ACL_WRITE 2 -#define ARCHIVE_ENTRY_ACL_READ 4 +#define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001 +#define ARCHIVE_ENTRY_ACL_WRITE 0x00000002 +#define ARCHIVE_ENTRY_ACL_READ 0x00000004 +#define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008 +#define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008 +#define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010 +#define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010 +#define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020 +#define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020 +#define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040 +#define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080 +#define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100 +#define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200 +#define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400 +#define ARCHIVE_ENTRY_ACL_DELETE 0x00000800 +#define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000 +#define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000 +#define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000 +#define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000 + +#define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \ + (ARCHIVE_ENTRY_ACL_EXECUTE \ + | ARCHIVE_ENTRY_ACL_WRITE \ + | ARCHIVE_ENTRY_ACL_READ) + +#define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \ + (ARCHIVE_ENTRY_ACL_EXECUTE \ + | ARCHIVE_ENTRY_ACL_READ_DATA \ + | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \ + | ARCHIVE_ENTRY_ACL_WRITE_DATA \ + | ARCHIVE_ENTRY_ACL_ADD_FILE \ + | ARCHIVE_ENTRY_ACL_APPEND_DATA \ + | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \ + | ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \ + | ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \ + | ARCHIVE_ENTRY_ACL_DELETE_CHILD \ + | ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \ + | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \ + | ARCHIVE_ENTRY_ACL_DELETE \ + | ARCHIVE_ENTRY_ACL_READ_ACL \ + | ARCHIVE_ENTRY_ACL_WRITE_ACL \ + | ARCHIVE_ENTRY_ACL_WRITE_OWNER \ + | ARCHIVE_ENTRY_ACL_SYNCHRONIZE) -/* We need to be able to specify either or both of these. */ -#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 -#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 +/* + * Inheritance values (NFS4 ACLs only); included in permset. + */ +#define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000 +#define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000 + +#define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \ + (ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \ + | ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \ + | ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \ + | ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS) + +/* We need to be able to specify combinations of these. */ +#define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 /* POSIX.1e only */ +#define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 /* POSIX.1e only */ +#define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 1024 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_DENY 2048 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 4096 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_ALARM 8192 /* NFS4 only */ +#define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \ + | ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) +#define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \ + | ARCHIVE_ENTRY_ACL_TYPE_DENY \ + | ARCHIVE_ENTRY_ACL_TYPE_AUDIT \ + | ARCHIVE_ENTRY_ACL_TYPE_ALARM) /* Tag values mimic POSIX.1e */ -#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ -#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ -#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ -#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ -#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */ -#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */ +#define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ +#define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ +#define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ +#define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ +#define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */ +#define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */ +#define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */ /* * Set the ACL by clearing it and adding entries one at a time. @@ -364,80 +445,91 @@ __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct sta * POSIX.1e) is useful for handling archive formats that combine * default and access information in a single ACL list. */ -__LA_DECL void archive_entry_acl_clear(struct archive_entry *); -__LA_DECL void archive_entry_acl_add_entry(struct archive_entry *, - int /* type */, int /* permset */, int /* tag */, - int /* qual */, const char * /* name */); -__LA_DECL void archive_entry_acl_add_entry_w(struct archive_entry *, - int /* type */, int /* permset */, int /* tag */, - int /* qual */, const wchar_t * /* name */); +__LA_DECL void archive_entry_acl_clear(struct archive_entry *); +__LA_DECL int archive_entry_acl_add_entry(struct archive_entry *, + int /* type */, int /* permset */, int /* tag */, + int /* qual */, const char * /* name */); +__LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *, + int /* type */, int /* permset */, int /* tag */, + int /* qual */, const wchar_t * /* name */); /* * To retrieve the ACL, first "reset", then repeatedly ask for the * "next" entry. The want_type parameter allows you to request only - * access entries or only default entries. + * certain types of entries. */ -__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */); -__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */, - int * /* type */, int * /* permset */, int * /* tag */, - int * /* qual */, const char ** /* name */); -__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */, - int * /* type */, int * /* permset */, int * /* tag */, - int * /* qual */, const wchar_t ** /* name */); +__LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */); +__LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */, + int * /* type */, int * /* permset */, int * /* tag */, + int * /* qual */, const char ** /* name */); +__LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */, + int * /* type */, int * /* permset */, int * /* tag */, + int * /* qual */, const wchar_t ** /* name */); /* * Construct a text-format ACL. The flags argument is a bitmask that * can include any of the following: * - * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries. - * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries. + * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries. + * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries. + * ARCHIVE_ENTRY_ACL_TYPE_NFS4 - Include NFS4 entries. * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in - * each ACL entry. (As used by 'star'.) + * each ACL entry. ('star' introduced this for POSIX.1e, this flag + * also applies to NFS4.) * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each - * default ACL entry. + * default ACL entry, as used in old Solaris ACLs. */ -#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 -#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 -__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *, - int /* flags */); +#define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 +#define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 +__LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *, + int /* flags */); +__LA_DECL const char *archive_entry_acl_text(struct archive_entry *, + int /* flags */); /* Return a count of entries matching 'want_type' */ -__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */); +__LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */); + +/* Return an opaque ACL object. */ +/* There's not yet anything clients can actually do with this... */ +struct archive_acl; +__LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *); /* - * Private ACL parser. This is private because it handles some - * very weird formats that clients should not be messing with. - * Clients should only deal with their platform-native formats. - * Because of the need to support many formats cleanly, new arguments - * are likely to get added on a regular basis. Clients who try to use - * this interface are likely to be surprised when it changes. - * - * You were warned! - * - * TODO: Move this declaration out of the public header and into - * a private header. Warnings above are silly. + * extended attributes + */ + +__LA_DECL void archive_entry_xattr_clear(struct archive_entry *); +__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *, + const char * /* name */, const void * /* value */, + size_t /* size */); + +/* + * To retrieve the xattr list, first "reset", then repeatedly ask for the + * "next" entry. */ -__LA_DECL int __archive_entry_acl_parse_w(struct archive_entry *, - const wchar_t *, int /* type */); + +__LA_DECL int archive_entry_xattr_count(struct archive_entry *); +__LA_DECL int archive_entry_xattr_reset(struct archive_entry *); +__LA_DECL int archive_entry_xattr_next(struct archive_entry *, + const char ** /* name */, const void ** /* value */, size_t *); /* - * extended attributes + * sparse */ -__LA_DECL void archive_entry_xattr_clear(struct archive_entry *); -__LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *, - const char * /* name */, const void * /* value */, - size_t /* size */); +__LA_DECL void archive_entry_sparse_clear(struct archive_entry *); +__LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *, + __LA_INT64_T /* offset */, __LA_INT64_T /* length */); /* * To retrieve the xattr list, first "reset", then repeatedly ask for the * "next" entry. */ -__LA_DECL int archive_entry_xattr_count(struct archive_entry *); -__LA_DECL int archive_entry_xattr_reset(struct archive_entry *); -__LA_DECL int archive_entry_xattr_next(struct archive_entry *, - const char ** /* name */, const void ** /* value */, size_t *); +__LA_DECL int archive_entry_sparse_count(struct archive_entry *); +__LA_DECL int archive_entry_sparse_reset(struct archive_entry *); +__LA_DECL int archive_entry_sparse_next(struct archive_entry *, + __LA_INT64_T * /* offset */, __LA_INT64_T * /* length */); /* * Utility to match up hardlinks. @@ -451,7 +543,7 @@ __LA_DECL int archive_entry_xattr_next(struct archive_entry *, * be written. * 4. Call archive_entry_linkify(resolver, NULL) until * no more entries are returned. - * 5. Call archive_entry_link_resolver_free(resolver) to free resources. + * 5. Call archive_entry_linkresolver_free(resolver) to free resources. * * The entries returned have their hardlink and size fields updated * appropriately. If an entry is passed in that does not refer to @@ -501,7 +593,7 @@ struct archive_entry_linkresolver; * linkify(l2) => l1 * linkify(NULL) => l2 (at end, you retrieve remaining links) * As the name suggests, this strategy is used by newer cpio variants. - * It's noticably more complex for the archiver, slightly more complex + * It's noticeably more complex for the archiver, slightly more complex * for the dearchiver than the tar strategy, but makes it straightforward * to restore a file using any link by simply continuing to scan until * you see a link that is stored with a body. In contrast, the tar @@ -511,10 +603,12 @@ struct archive_entry_linkresolver; __LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void); __LA_DECL void archive_entry_linkresolver_set_strategy( - struct archive_entry_linkresolver *, int /* format_code */); + struct archive_entry_linkresolver *, int /* format_code */); __LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *); __LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *, struct archive_entry **, struct archive_entry **); +__LA_DECL struct archive_entry *archive_entry_partial_links( + struct archive_entry_linkresolver *res, unsigned int *links); #ifdef __cplusplus } diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 new file mode 100644 index 000000000..93906e798 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_acl.3 @@ -0,0 +1,233 @@ +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd February 21, 2010 +.Dt ARCHIVE_ENTRY_ACL 3 +.Os +.Sh NAME +.Nm archive_entry_acl_add_entry , +.Nm archive_entry_acl_add_entry_w , +.Nm archive_entry_acl_clear , +.Nm archive_entry_acl_count , +.Nm archive_entry_acl_next , +.Nm archive_entry_acl_next_w , +.Nm archive_entry_acl_reset , +.Nm archive_entry_acl_text_w +.Nd functions for manipulating Access Control Lists in archive entry descriptions +.Sh SYNOPSIS +.In archive_entry.h +.Ft void +.Fo archive_entry_acl_add_entry +.Fa "struct archive_entry *a" +.Fa "int type" +.Fa "int permset" +.Fa "int tag" +.Fa "int qualifier" +.Fa "const char *name" +.Fc +.Ft void +.Fo archive_entry_acl_add_entry_w +.Fa "struct archive_entry *a" +.Fa "int type" +.Fa "int permset" +.Fa "int tag" +.Fa "int qualifier" +.Fa "const wchar_t *name" +.Fc +.Ft void +.Fn archive_entry_acl_clear "struct archive_entry *a" +.Ft int +.Fn archive_entry_acl_count "struct archive_entry *a" "int type" +.Ft int +.Fo archive_entry_acl_next +.Fa "struct archive_entry *a" +.Fa "int type" +.Fa "int *ret_type" +.Fa "int *ret_permset" +.Fa "int *ret_tag" +.Fa "int *ret_qual" +.Fa "const char **ret_name" +.Fc +.Ft int +.Fo archive_entry_acl_next_w +.Fa "struct archive_entry *a" +.Fa "int type" +.Fa "int *ret_type" +.Fa "int *ret_permset" +.Fa "int *ret_tag" +.Fa "int *ret_qual" +.Fa "const wchar_t **ret_name" +.Fc +.Ft int +.Fn archive_entry_acl_reset "struct archive_entry *a" "int type" +.Ft const wchar_t * +.Fn archive_entry_acl_text_w "struct archive_entry *a" "int flags" +.\" enum? +.Sh DESCRIPTION +An +.Dq Access Control List +is a generalisation of the classic Unix permission system. +The ACL interface of +.Nm libarchive +is derived from the POSIX.1e draft, but restricted to simplify dealing +with practical implementations in various Operating Systems and archive formats. +.Pp +An ACL consists of a number of independent entries. +Each entry specifies the permission set as bitmask of basic permissions. +Valid permissions are: +.Bl -tag -offset indent -compact -width "ARCHIVE_ENTRY_ACL_EXECUTE" +.It Dv ARCHIVE_ENTRY_ACL_EXECUTE +.It Dv ARCHIVE_ENTRY_ACL_WRITE +.It Dv ARCHIVE_ENTRY_ACL_READ +.El +The permissions correspond to the normal Unix permissions. +.Pp +The tag specifies the principal to which the permission applies. +Valid values are: +.Bl -tag -offset indent -compact -width "ARCHIVE_ENTRY_ACL_GROUP_OBJ" +.It Dv ARCHIVE_ENTRY_ACL_USER +The user specified by the name field. +.It Dv ARCHIVE_ENTRY_ACL_USER_OBJ +The owner of the file. +.It Dv ARCHIVE_ENTRY_ACL_GROUP +The group specied by the name field. +.It Dv ARCHIVE_ENTRY_ACL_GROUP_OBJ +The group who owns the file. +.It Dv ARCHIVE_ENTRY_ACL_MASK +The maximum permissions to be obtained via group permissions. +.It Dv ARCHIVE_ENTRY_ACL_OTHER +Any principal who doesn't have a user or group entry. +.El +The principals +.Dv ARCHIVE_ENTRY_ACL_USER_OBJ , +.Dv ARCHIVE_ENTRY_ACL_GROUP_OBJ +and +.Dv ARCHIVE_ENTRY_ACL_OTHER +are equivalent to user, group and other in the classic Unix permission +model and specify non-extended ACL entries. +.Pp +All files have an access ACL +.Pq Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS . +This specifies the permissions required for access to the file itself. +Directories have an additional ACL +.Pq Dv ARCHIVE_ENTRY_ACL_TYPE_DEFAULT , +which controlls the initial access ACL for newly created directory entries. +.Pp +.Fn archive_entry_acl_add_entry +and +.Fn archive_entry_acl_add_entry_w +add a single ACL entry. +For the access ACL and non-extended principals, the classic Unix permissions +are updated. +.Pp +.Fn archive_entry_acl_clear +removes all ACL entries and resets the enumeration pointer. +.Pp +.Fn archive_entry_acl_count +counts the ACL entries that have the given type mask. +.Fa type +can be the bitwise-or of +.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS +and +.Dv ARCHIVE_ENTRY_ACL_TYPE_DEFAULT . +If +.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS +is included and at least one extended ACL entry is found, +the three non-extened ACLs are added. +.Pp +.Fn archive_entry_acl_next +and +.Fn archive_entry_acl_next_w +return the next entry of the ACL list. +This functions may only be called after +.Fn archive_entry_acl_reset +has indicated the presence of extended ACL entries. +.Pp +.Fn archive_entry_acl_reset +prepare reading the list of ACL entries with +.Fn archive_entry_acl_next +or +.Fn archive_entry_acl_next_w . +The function returns either 0, if no non-extended ACLs are found. +In this case, the access permissions should be obtained by +.Xr archive_entry_mode 3 +or set using +.Xr chmod 2 . +Otherwise, the function returns the same value as +.Fn archive_entry_acl_count . +.Pp +.Fn archive_entry_acl_text_w +converts the ACL entries for the given type mask into a wide string. +In addition to the normal type flags, +.Dv ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID +and +.Dv ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT +can be specified to further customize the result. +The returned long string is valid until the next call to +.Fn archive_entry_acl_clear , +.Fn archive_entry_acl_add_entry , +.Fn archive_entry_acl_add_entry_w +or +.Fn archive_entry_acl_text_w . +.Sh RETURN VALUES +.Fn archive_entry_acl_count +and +.Fn archive_entry_acl_reset +returns the number of ACL entries that match the given type mask. +If the type mask includes +.Dv ARCHIVE_ENTRY_ACL_TYPE_ACCESS +and at least one extended ACL entry exists, the three classic Unix +permissions are counted. +.Pp +.Fn archive_entry_acl_next +and +.Fn archive_entry_acl_next_w +return +.Dv ARCHIVE_OK +on success, +.Dv ARCHIVE_EOF +if no more ACL entries exist +and +.Dv ARCHIVE_WARN +if +.Fn archive_entry_acl_reset +has not been called first. +.Pp +.Fn archive_entry_text_w +returns a wide string representation of the ACL entrise matching the +given type mask. +The returned long string is valid until the next call to +.Fn archive_entry_acl_clear , +.Fn archive_entry_acl_add_entry , +.Fn archive_entry_acl_add_entry_w +or +.Fn archive_entry_acl_text_w . +.Sh SEE ALSO +.Xr archive 3 , +.Xr archive_entry 3 +.Sh BUGS +.Dv ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID +and +.Dv ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT +are not documented. diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c b/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c index 00cad4cf8..7a4bc9cd0 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_copy_bhfi.c @@ -26,51 +26,50 @@ #include "archive_platform.h" __FBSDID("$FreeBSD$"); +#include "archive_private.h" #include "archive_entry.h" -#if defined(_WIN32) && !defined(__CYGWIN__) -#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) -# define EPOC_TIME (116444736000000000UI64) -#else -# define EPOC_TIME (116444736000000000ULL) -#endif +#if defined(_WIN32) && !defined(__CYGWIN__) +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) __inline static void fileTimeToUtc(const FILETIME *filetime, time_t *time, long *ns) { - ULARGE_INTEGER utc; + ULARGE_INTEGER utc; - utc.HighPart = filetime->dwHighDateTime; - utc.LowPart = filetime->dwLowDateTime; - if (utc.QuadPart >= EPOC_TIME) { - utc.QuadPart -= EPOC_TIME; - *time = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ - *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ - } else { - *time = 0; - *ns = 0; - } + utc.HighPart = filetime->dwHighDateTime; + utc.LowPart = filetime->dwLowDateTime; + if (utc.QuadPart >= EPOC_TIME) { + utc.QuadPart -= EPOC_TIME; + *time = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ + *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ + } else { + *time = 0; + *ns = 0; + } } void archive_entry_copy_bhfi(struct archive_entry *entry, - BY_HANDLE_FILE_INFORMATION *bhfi) + BY_HANDLE_FILE_INFORMATION *bhfi) { - time_t secs; - long nsecs; + time_t secs; + long nsecs; - fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs); - archive_entry_set_atime(entry, secs, nsecs); - fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs); - archive_entry_set_mtime(entry, secs, nsecs); - fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs); - archive_entry_set_birthtime(entry, secs, nsecs); - archive_entry_set_dev(entry, bhfi->dwVolumeSerialNumber); - archive_entry_set_ino64(entry, (((int64_t)bhfi->nFileIndexHigh) << 32) - + bhfi->nFileIndexLow); - archive_entry_set_nlink(entry, bhfi->nNumberOfLinks); - archive_entry_set_size(entry, (((int64_t)bhfi->nFileSizeHigh) << 32) - + bhfi->nFileSizeLow); + fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs); + archive_entry_set_atime(entry, secs, nsecs); + fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs); + archive_entry_set_mtime(entry, secs, nsecs); + fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs); + archive_entry_set_birthtime(entry, secs, nsecs); + archive_entry_set_ctime(entry, secs, nsecs); + archive_entry_set_dev(entry, bhfi->dwVolumeSerialNumber); + archive_entry_set_ino64(entry, (((int64_t)bhfi->nFileIndexHigh) << 32) + + bhfi->nFileIndexLow); + archive_entry_set_nlink(entry, bhfi->nNumberOfLinks); + archive_entry_set_size(entry, (((int64_t)bhfi->nFileSizeHigh) << 32) + + bhfi->nFileSizeLow); + /* archive_entry_set_mode(entry, st->st_mode); */ } #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c b/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c index 94da56b4e..37d4d6edb 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_copy_stat.c @@ -24,54 +24,56 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_copy_stat.c,v 1.2 2008/09/30 03:53:03 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_copy_stat.c 189466 2009-03-07 00:52:02Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include #endif +#include "archive.h" #include "archive_entry.h" void archive_entry_copy_stat(struct archive_entry *entry, const struct stat *st) { #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - archive_entry_set_atime(entry, st->st_atime, st->st_atimespec.tv_nsec); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctimespec.tv_nsec); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtimespec.tv_nsec); + archive_entry_set_atime(entry, st->st_atime, st->st_atimespec.tv_nsec); + archive_entry_set_ctime(entry, st->st_ctime, st->st_ctimespec.tv_nsec); + archive_entry_set_mtime(entry, st->st_mtime, st->st_mtimespec.tv_nsec); #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - archive_entry_set_atime(entry, st->st_atime, st->st_atim.tv_nsec); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctim.tv_nsec); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtim.tv_nsec); + archive_entry_set_atime(entry, st->st_atime, st->st_atim.tv_nsec); + archive_entry_set_ctime(entry, st->st_ctime, st->st_ctim.tv_nsec); + archive_entry_set_mtime(entry, st->st_mtime, st->st_mtim.tv_nsec); #elif HAVE_STRUCT_STAT_ST_MTIME_N - archive_entry_set_atime(entry, st->st_atime, st->st_atime_n); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_n); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_n); + archive_entry_set_atime(entry, st->st_atime, st->st_atime_n); + archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_n); + archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_n); #elif HAVE_STRUCT_STAT_ST_UMTIME - archive_entry_set_atime(entry, st->st_atime, st->st_uatime * 1000); - archive_entry_set_ctime(entry, st->st_ctime, st->st_uctime * 1000); - archive_entry_set_mtime(entry, st->st_mtime, st->st_umtime * 1000); + archive_entry_set_atime(entry, st->st_atime, st->st_uatime * 1000); + archive_entry_set_ctime(entry, st->st_ctime, st->st_uctime * 1000); + archive_entry_set_mtime(entry, st->st_mtime, st->st_umtime * 1000); #elif HAVE_STRUCT_STAT_ST_MTIME_USEC - archive_entry_set_atime(entry, st->st_atime, st->st_atime_usec * 1000); - archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_usec * 1000); - archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_usec * 1000); + archive_entry_set_atime(entry, st->st_atime, st->st_atime_usec * 1000); + archive_entry_set_ctime(entry, st->st_ctime, st->st_ctime_usec * 1000); + archive_entry_set_mtime(entry, st->st_mtime, st->st_mtime_usec * 1000); #else - archive_entry_set_atime(entry, st->st_atime, 0); - archive_entry_set_ctime(entry, st->st_ctime, 0); - archive_entry_set_mtime(entry, st->st_mtime, 0); -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - archive_entry_set_birthtime(entry, st->st_birthtime, 0); -#endif + archive_entry_set_atime(entry, st->st_atime, 0); + archive_entry_set_ctime(entry, st->st_ctime, 0); + archive_entry_set_mtime(entry, st->st_mtime, 0); #endif #if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC - archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec); + archive_entry_set_birthtime(entry, st->st_birthtime, st->st_birthtimespec.tv_nsec); +#elif HAVE_STRUCT_STAT_ST_BIRTHTIME + archive_entry_set_birthtime(entry, st->st_birthtime, 0); +#else + archive_entry_unset_birthtime(entry); #endif - archive_entry_set_dev(entry, st->st_dev); - archive_entry_set_gid(entry, st->st_gid); - archive_entry_set_uid(entry, st->st_uid); - archive_entry_set_ino(entry, st->st_ino); - archive_entry_set_nlink(entry, st->st_nlink); - archive_entry_set_rdev(entry, st->st_rdev); - archive_entry_set_size(entry, st->st_size); - archive_entry_set_mode(entry, st->st_mode); + archive_entry_set_dev(entry, st->st_dev); + archive_entry_set_gid(entry, st->st_gid); + archive_entry_set_uid(entry, st->st_uid); + archive_entry_set_ino(entry, st->st_ino); + archive_entry_set_nlink(entry, st->st_nlink); + archive_entry_set_rdev(entry, st->st_rdev); + archive_entry_set_size(entry, st->st_size); + archive_entry_set_mode(entry, st->st_mode); } diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c b/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c index 0835fb0a9..a18144dd5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_link_resolver.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_link_resolver.c,v 1.4 2008/09/05 06:15:25 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_link_resolver.c 201100 2009-12-28 03:05:31Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -59,345 +59,386 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_link_resolver.c,v 1.4 2008/ */ /* Users pass us a format code, we translate that into a strategy here. */ -#define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0 +#define ARCHIVE_ENTRY_LINKIFY_LIKE_TAR 0 #define ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE 1 #define ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO 2 #define ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO 3 /* Initial size of link cache. */ -#define links_cache_initial_size 1024 +#define links_cache_initial_size 1024 struct links_entry { - struct links_entry *next; - struct links_entry *previous; - int links; /* # links not yet seen */ - int hash; - struct archive_entry *canonical; - struct archive_entry *entry; + struct links_entry *next; + struct links_entry *previous; + struct archive_entry *canonical; + struct archive_entry *entry; + size_t hash; + unsigned int links; /* # links not yet seen */ }; struct archive_entry_linkresolver { - struct links_entry **buckets; - struct links_entry *spare; - unsigned long number_entries; - size_t number_buckets; - int strategy; + struct links_entry **buckets; + struct links_entry *spare; + unsigned long number_entries; + size_t number_buckets; + int strategy; }; +#define NEXT_ENTRY_DEFERRED 1 +#define NEXT_ENTRY_PARTIAL 2 +#define NEXT_ENTRY_ALL (NEXT_ENTRY_DEFERRED | NEXT_ENTRY_PARTIAL) + static struct links_entry *find_entry(struct archive_entry_linkresolver *, - struct archive_entry *); + struct archive_entry *); static void grow_hash(struct archive_entry_linkresolver *); static struct links_entry *insert_entry(struct archive_entry_linkresolver *, - struct archive_entry *); -static struct links_entry *next_entry(struct archive_entry_linkresolver *); + struct archive_entry *); +static struct links_entry *next_entry(struct archive_entry_linkresolver *, + int); struct archive_entry_linkresolver * archive_entry_linkresolver_new(void) { - struct archive_entry_linkresolver *res; - size_t i; - - res = malloc(sizeof(struct archive_entry_linkresolver)); - if (res == NULL) - return (NULL); - memset(res, 0, sizeof(struct archive_entry_linkresolver)); - res->number_buckets = links_cache_initial_size; - res->buckets = malloc(res->number_buckets * - sizeof(res->buckets[0])); - if (res->buckets == NULL) { - free(res); - return (NULL); - } - for (i = 0; i < res->number_buckets; i++) - res->buckets[i] = NULL; - return (res); + struct archive_entry_linkresolver *res; + + /* Check for positive power-of-two */ + if (links_cache_initial_size == 0 || + (links_cache_initial_size & (links_cache_initial_size - 1)) != 0) + return (NULL); + + res = calloc(1, sizeof(struct archive_entry_linkresolver)); + if (res == NULL) + return (NULL); + res->number_buckets = links_cache_initial_size; + res->buckets = calloc(res->number_buckets, sizeof(res->buckets[0])); + if (res->buckets == NULL) { + free(res); + return (NULL); + } + return (res); } void archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *res, int fmt) { - int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK; - - switch (fmtbase) { - case ARCHIVE_FORMAT_CPIO: - switch (fmt) { - case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC: - case ARCHIVE_FORMAT_CPIO_SVR4_CRC: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO; - break; - default: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; - break; - } - break; - case ARCHIVE_FORMAT_MTREE: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE; - break; - case ARCHIVE_FORMAT_TAR: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; - break; - default: - res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; - break; - } + int fmtbase = fmt & ARCHIVE_FORMAT_BASE_MASK; + + switch (fmtbase) { + case ARCHIVE_FORMAT_7ZIP: + case ARCHIVE_FORMAT_AR: + case ARCHIVE_FORMAT_ZIP: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; + break; + case ARCHIVE_FORMAT_CPIO: + switch (fmt) { + case ARCHIVE_FORMAT_CPIO_SVR4_NOCRC: + case ARCHIVE_FORMAT_CPIO_SVR4_CRC: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO; + break; + default: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; + break; + } + break; + case ARCHIVE_FORMAT_MTREE: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE; + break; + case ARCHIVE_FORMAT_ISO9660: + case ARCHIVE_FORMAT_SHAR: + case ARCHIVE_FORMAT_TAR: + case ARCHIVE_FORMAT_XAR: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_TAR; + break; + default: + res->strategy = ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO; + break; + } } void archive_entry_linkresolver_free(struct archive_entry_linkresolver *res) { - struct links_entry *le; - - if (res == NULL) - return; - - if (res->buckets != NULL) { - while ((le = next_entry(res)) != NULL) - archive_entry_free(le->entry); - free(res->buckets); - res->buckets = NULL; - } - free(res); + struct links_entry *le; + + if (res == NULL) + return; + + while ((le = next_entry(res, NEXT_ENTRY_ALL)) != NULL) + archive_entry_free(le->entry); + free(res->buckets); + free(res); } void archive_entry_linkify(struct archive_entry_linkresolver *res, struct archive_entry **e, struct archive_entry **f) { - struct links_entry *le; - struct archive_entry *t; - - *f = NULL; /* Default: Don't return a second entry. */ - - if (*e == NULL) { - le = next_entry(res); - if (le != NULL) { - *e = le->entry; - le->entry = NULL; - } - return; - } - - /* If it has only one link, then we're done. */ - if (archive_entry_nlink(*e) == 1) - return; - /* Directories never have hardlinks. */ - if (archive_entry_filetype(*e) == AE_IFDIR) - return; - - switch (res->strategy) { - case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR: - le = find_entry(res, *e); - if (le != NULL) { - archive_entry_unset_size(*e); - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - } else - insert_entry(res, *e); - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE: - le = find_entry(res, *e); - if (le != NULL) { - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - } else - insert_entry(res, *e); - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO: - /* This one is trivial. */ - return; - case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO: - le = find_entry(res, *e); - if (le != NULL) { - /* - * Put the new entry in le, return the - * old entry from le. - */ - t = *e; - *e = le->entry; - le->entry = t; - /* Make the old entry into a hardlink. */ - archive_entry_unset_size(*e); - archive_entry_copy_hardlink(*e, - archive_entry_pathname(le->canonical)); - /* If we ran out of links, return the - * final entry as well. */ - if (le->links == 0) { - *f = le->entry; - le->entry = NULL; - } - } else { - /* - * If we haven't seen it, tuck it away - * for future use. - */ - le = insert_entry(res, *e); - le->entry = *e; - *e = NULL; - } - return; - default: - break; - } - return; + struct links_entry *le; + struct archive_entry *t; + + *f = NULL; /* Default: Don't return a second entry. */ + + if (*e == NULL) { + le = next_entry(res, NEXT_ENTRY_DEFERRED); + if (le != NULL) { + *e = le->entry; + le->entry = NULL; + } + return; + } + + /* If it has only one link, then we're done. */ + if (archive_entry_nlink(*e) == 1) + return; + /* Directories, devices never have hardlinks. */ + if (archive_entry_filetype(*e) == AE_IFDIR + || archive_entry_filetype(*e) == AE_IFBLK + || archive_entry_filetype(*e) == AE_IFCHR) + return; + + switch (res->strategy) { + case ARCHIVE_ENTRY_LINKIFY_LIKE_TAR: + le = find_entry(res, *e); + if (le != NULL) { + archive_entry_unset_size(*e); + archive_entry_copy_hardlink(*e, + archive_entry_pathname(le->canonical)); + } else + insert_entry(res, *e); + return; + case ARCHIVE_ENTRY_LINKIFY_LIKE_MTREE: + le = find_entry(res, *e); + if (le != NULL) { + archive_entry_copy_hardlink(*e, + archive_entry_pathname(le->canonical)); + } else + insert_entry(res, *e); + return; + case ARCHIVE_ENTRY_LINKIFY_LIKE_OLD_CPIO: + /* This one is trivial. */ + return; + case ARCHIVE_ENTRY_LINKIFY_LIKE_NEW_CPIO: + le = find_entry(res, *e); + if (le != NULL) { + /* + * Put the new entry in le, return the + * old entry from le. + */ + t = *e; + *e = le->entry; + le->entry = t; + /* Make the old entry into a hardlink. */ + archive_entry_unset_size(*e); + archive_entry_copy_hardlink(*e, + archive_entry_pathname(le->canonical)); + /* If we ran out of links, return the + * final entry as well. */ + if (le->links == 0) { + *f = le->entry; + le->entry = NULL; + } + } else { + /* + * If we haven't seen it, tuck it away + * for future use. + */ + le = insert_entry(res, *e); + le->entry = *e; + *e = NULL; + } + return; + default: + break; + } + return; } static struct links_entry * find_entry(struct archive_entry_linkresolver *res, struct archive_entry *entry) { - struct links_entry *le; - int hash, bucket; - dev_t dev; - int64_t ino; - - /* Free a held entry. */ - if (res->spare != NULL) { - archive_entry_free(res->spare->canonical); - archive_entry_free(res->spare->entry); - free(res->spare); - res->spare = NULL; - } - - /* If the links cache overflowed and got flushed, don't bother. */ - if (res->buckets == NULL) - return (NULL); - - dev = archive_entry_dev(entry); - ino = archive_entry_ino64(entry); - hash = (int)(dev ^ ino); - - /* Try to locate this entry in the links cache. */ - bucket = hash % (int)res->number_buckets; - for (le = res->buckets[bucket]; le != NULL; le = le->next) { - if (le->hash == hash - && dev == archive_entry_dev(le->canonical) - && ino == archive_entry_ino64(le->canonical)) { - /* - * Decrement link count each time and release - * the entry if it hits zero. This saves - * memory and is necessary for detecting - * missed links. - */ - --le->links; - if (le->links > 0) - return (le); - /* Remove it from this hash bucket. */ - if (le->previous != NULL) - le->previous->next = le->next; - if (le->next != NULL) - le->next->previous = le->previous; - if (res->buckets[bucket] == le) - res->buckets[bucket] = le->next; - res->number_entries--; - /* Defer freeing this entry. */ - res->spare = le; - return (le); - } - } - return (NULL); + struct links_entry *le; + size_t hash, bucket; + dev_t dev; + int64_t ino; + + /* Free a held entry. */ + if (res->spare != NULL) { + archive_entry_free(res->spare->canonical); + archive_entry_free(res->spare->entry); + free(res->spare); + res->spare = NULL; + } + + dev = archive_entry_dev(entry); + ino = archive_entry_ino64(entry); + hash = (size_t)(dev ^ ino); + + /* Try to locate this entry in the links cache. */ + bucket = hash & (res->number_buckets - 1); + for (le = res->buckets[bucket]; le != NULL; le = le->next) { + if (le->hash == hash + && dev == archive_entry_dev(le->canonical) + && ino == archive_entry_ino64(le->canonical)) { + /* + * Decrement link count each time and release + * the entry if it hits zero. This saves + * memory and is necessary for detecting + * missed links. + */ + --le->links; + if (le->links > 0) + return (le); + /* Remove it from this hash bucket. */ + if (le->previous != NULL) + le->previous->next = le->next; + if (le->next != NULL) + le->next->previous = le->previous; + if (res->buckets[bucket] == le) + res->buckets[bucket] = le->next; + res->number_entries--; + /* Defer freeing this entry. */ + res->spare = le; + return (le); + } + } + return (NULL); } static struct links_entry * -next_entry(struct archive_entry_linkresolver *res) +next_entry(struct archive_entry_linkresolver *res, int mode) { - struct links_entry *le; - size_t bucket; - - /* Free a held entry. */ - if (res->spare != NULL) { - archive_entry_free(res->spare->canonical); - free(res->spare); - res->spare = NULL; - } - - /* If the links cache overflowed and got flushed, don't bother. */ - if (res->buckets == NULL) - return (NULL); - - /* Look for next non-empty bucket in the links cache. */ - for (bucket = 0; bucket < res->number_buckets; bucket++) { - le = res->buckets[bucket]; - if (le != NULL) { - /* Remove it from this hash bucket. */ - if (le->next != NULL) - le->next->previous = le->previous; - res->buckets[bucket] = le->next; - res->number_entries--; - /* Defer freeing this entry. */ - res->spare = le; - return (le); - } - } - return (NULL); + struct links_entry *le; + size_t bucket; + + /* Free a held entry. */ + if (res->spare != NULL) { + archive_entry_free(res->spare->canonical); + archive_entry_free(res->spare->entry); + free(res->spare); + res->spare = NULL; + } + + /* Look for next non-empty bucket in the links cache. */ + for (bucket = 0; bucket < res->number_buckets; bucket++) { + for (le = res->buckets[bucket]; le != NULL; le = le->next) { + if (le->entry != NULL && + (mode & NEXT_ENTRY_DEFERRED) == 0) + continue; + if (le->entry == NULL && + (mode & NEXT_ENTRY_PARTIAL) == 0) + continue; + /* Remove it from this hash bucket. */ + if (le->next != NULL) + le->next->previous = le->previous; + if (le->previous != NULL) + le->previous->next = le->next; + else + res->buckets[bucket] = le->next; + res->number_entries--; + /* Defer freeing this entry. */ + res->spare = le; + return (le); + } + } + return (NULL); } static struct links_entry * insert_entry(struct archive_entry_linkresolver *res, struct archive_entry *entry) { - struct links_entry *le; - int hash, bucket; - - /* Add this entry to the links cache. */ - le = malloc(sizeof(struct links_entry)); - if (le == NULL) - return (NULL); - memset(le, 0, sizeof(*le)); - le->canonical = archive_entry_clone(entry); - - /* If the links cache is getting too full, enlarge the hash table. */ - if (res->number_entries > res->number_buckets * 2) - grow_hash(res); - - hash = archive_entry_dev(entry) ^ archive_entry_ino64(entry); - bucket = hash % (int)res->number_buckets; - - /* If we could allocate the entry, record it. */ - if (res->buckets[bucket] != NULL) - res->buckets[bucket]->previous = le; - res->number_entries++; - le->next = res->buckets[bucket]; - le->previous = NULL; - res->buckets[bucket] = le; - le->hash = hash; - le->links = archive_entry_nlink(entry) - 1; - return (le); + struct links_entry *le; + size_t hash, bucket; + + /* Add this entry to the links cache. */ + le = calloc(1, sizeof(struct links_entry)); + if (le == NULL) + return (NULL); + le->canonical = archive_entry_clone(entry); + + /* If the links cache is getting too full, enlarge the hash table. */ + if (res->number_entries > res->number_buckets * 2) + grow_hash(res); + + hash = archive_entry_dev(entry) ^ archive_entry_ino64(entry); + bucket = hash & (res->number_buckets - 1); + + /* If we could allocate the entry, record it. */ + if (res->buckets[bucket] != NULL) + res->buckets[bucket]->previous = le; + res->number_entries++; + le->next = res->buckets[bucket]; + le->previous = NULL; + res->buckets[bucket] = le; + le->hash = hash; + le->links = archive_entry_nlink(entry) - 1; + return (le); } static void grow_hash(struct archive_entry_linkresolver *res) { - struct links_entry *le, **new_buckets; - size_t new_size; - size_t i, bucket; - - /* Try to enlarge the bucket list. */ - new_size = res->number_buckets * 2; - new_buckets = malloc(new_size * sizeof(struct links_entry *)); - - if (new_buckets != NULL) { - memset(new_buckets, 0, - new_size * sizeof(struct links_entry *)); - for (i = 0; i < res->number_buckets; i++) { - while (res->buckets[i] != NULL) { - /* Remove entry from old bucket. */ - le = res->buckets[i]; - res->buckets[i] = le->next; - - /* Add entry to new bucket. */ - bucket = le->hash % new_size; - - if (new_buckets[bucket] != NULL) - new_buckets[bucket]->previous = - le; - le->next = new_buckets[bucket]; - le->previous = NULL; - new_buckets[bucket] = le; - } - } - free(res->buckets); - res->buckets = new_buckets; - res->number_buckets = new_size; - } + struct links_entry *le, **new_buckets; + size_t new_size; + size_t i, bucket; + + /* Try to enlarge the bucket list. */ + new_size = res->number_buckets * 2; + if (new_size < res->number_buckets) + return; + new_buckets = calloc(new_size, sizeof(struct links_entry *)); + + if (new_buckets == NULL) + return; + + for (i = 0; i < res->number_buckets; i++) { + while (res->buckets[i] != NULL) { + /* Remove entry from old bucket. */ + le = res->buckets[i]; + res->buckets[i] = le->next; + + /* Add entry to new bucket. */ + bucket = le->hash & (new_size - 1); + + if (new_buckets[bucket] != NULL) + new_buckets[bucket]->previous = le; + le->next = new_buckets[bucket]; + le->previous = NULL; + new_buckets[bucket] = le; + } + } + free(res->buckets); + res->buckets = new_buckets; + res->number_buckets = new_size; +} + +struct archive_entry * +archive_entry_partial_links(struct archive_entry_linkresolver *res, + unsigned int *links) +{ + struct archive_entry *e; + struct links_entry *le; + + /* Free a held entry. */ + if (res->spare != NULL) { + archive_entry_free(res->spare->canonical); + archive_entry_free(res->spare->entry); + free(res->spare); + res->spare = NULL; + } + + le = next_entry(res, NEXT_ENTRY_PARTIAL); + if (le != NULL) { + e = le->canonical; + if (links != NULL) + *links = le->links; + le->canonical = NULL; + } else { + e = NULL; + if (links != NULL) + *links = 0; + } + return (e); } diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3 b/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3 new file mode 100644 index 000000000..a34b095e7 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_linkify.3 @@ -0,0 +1,224 @@ +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd February 20, 2010 +.Dt ARCHIVE_ENTRY_LINKIFY 3 +.Os +.Sh NAME +.Nm archive_entry_linkresolver , +.Nm archive_entry_linkresolver_new , +.Nm archive_entry_linkresolver_set_strategy , +.Nm archive_entry_linkresolver_free , +.Nm archive_entry_linkify +.Nd hardlink resolver functions +.Sh LIBRARY +.Lb libarchive +.Sh SYNOPSIS +.In archive_entry.h +.Ft struct archive_entry_linkresolver * +.Fn archive_entry_linkresolver_new void +.Ft void +.Fo archive_entry_linkresolver_set_strategy +.Fa "struct archive_entry_linkresolver *resolver" +.Fa "int format" +.Fc +.Ft void +.Fo archive_entry_linkresolver_free +.Fa "struct archive_entry_linkresolver *resolver" +.Fc +.Ft void +.Fo archive_entry_linkify +.Fa "struct archive_entry_linkresolver *resolver" +.Fa "struct archive_entry **entry" +.Fa "struct archive_entry **sparse" +.Fc +.Sh DESCRIPTION +Programs that want to create archives have to deal with hardlinks. +Hardlinks are handled in different ways by the archive formats. +The basic strategies are: +.Bl -enum +.It +Ignore hardlinks and store the body for each reference (old cpio, zip). +.It +Store the body the first time an inode is seen (ustar, pax). +.It +Store the body the last time an inode is seen (new cpio). +.El +.Pp +The +.Nm +functions help by providing a unified interface and handling the complexity +behind the scene. +.Pp +The +.Nm +functions assume that +.Vt archive_entry +instances have valid nlinks, inode and device values. +The inode and device value is used to match entries. +The nlinks value is used to determined if all references have been found and +if the internal references can be recycled. +.Pp +The +.Fn archive_entry_linkresolver_new +function allocates a new link resolver. +The instance can be freed using +.Fn archive_entry_linkresolver_free . +All deferred entries are flushed and the internal storage is freed. +.Pp +The +.Fn archive_entry_linkresolver_set_strategy +function selects the optimal hardlink strategy for the given format. +The format code can be obtained from +.Xr archive_format 3 . +The function can be called more than once, but it is recommended to +flush all deferred entries first. +.Pp +The +.Fn archive_entry_linkify +function is the core of +.Nm . +The +.Fn entry +argument points to the +.Vt archive_entry +that should be written. +Depending on the strategy one of the following actions is taken: +.Bl -enum +.It +For the simple archive formats +.Va *entry +is left unmodified and +.Va *sparse +is set to +.Dv NULL . +.It +For tar like archive formats, +.Va *sparse +is set to +.Dv NULL . +If +.Va *entry +is +.Dv NULL , +no action is taken. +If the hardlink count of +.Va *entry +is larger than 1 and the file type is a regular file or symbolic link, +the internal list is searched for a matching inode. +If such an inode is found, the link count is decremented and the file size +of +.Va *entry +is set to 0 to notify that no body should be written. +If no such inode is found, a copy of the entry is added to the internal cache +with a link count reduced by one. +.It +For new cpio like archive formats a value for +.Va *entry +of +.Dv NULL +is used to flush deferred entries. +In that case +.Va *entry +is set to an arbitrary deferred entry and the entry itself is removed from the +internal list. +If the internal list is empty, +.Va *entry +is set to +.Dv NULL . +In either case, +.Va *sparse +is set to +.Dv NULL +and the function returns. +If the hardlink count of +.Va *entry +is one or the file type is a directory or device, +.Va *sparse +is set to +.Dv NULL +and no further action is taken. +Otherwise, the internal list is searched for a matching inode. +If such an inode is not found, the entry is added to the internal list, +both +.Va *entry +and +.Va *sparse +are set to +.Dv NULL +and the function returns. +If such an inode is found, the link count is decremented. +If it remains larger than one, the existing entry on the internal list +is swapped with +.Va *entry +after retaining the link count. +The existing entry is returned in +.Va *entry . +If the link count reached one, the new entry is also removed from the +internal list and returned in +.Va *sparse . +Otherwise +.Va *sparse +is set to +.Dv NULL . +.El +.Pp +The general usage is therefore: +.Bl -enum +.It +For each new archive entry, call +.Fn archive_entry_linkify . +.It +Keep in mind that the entries returned may have a size of 0 now. +.It +If +.Va *entry +is not +.Dv NULL , +archive it. +.It +If +.Va *sparse +is not +.Dv NULL , +archive it. +.It +After all entries have been written to disk, call +.Fn archive_entry_linkify +with +.Va *entry +set to +.Dv NULL +and archive the returned entry as long as it is not +.Dv NULL . +.El +.Sh RETURN VALUES +.Fn archive_entry_linkresolver_new +returns +.Dv NULL +on +.Xr malloc 3 +failures. +.Sh SEE ALSO +.Xr archive_entry 3 diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_locale.h b/Utilities/cmlibarchive/libarchive/archive_entry_locale.h new file mode 100644 index 000000000..02e024ae2 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_locale.h @@ -0,0 +1,88 @@ +/*- + * Copyright (c) 2011 Michihiro NAKAJIMA + * 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. + * + * $FreeBSD$ + */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_ENTRY_LOCALE_H_INCLUDED +#define ARCHIVE_ENTRY_LOCALE_H_INCLUDED + +struct archive_entry; +struct archive_string_conv; + +/* + * Utility functions to set and get entry attributes by translating + * character-set. These are designed for use in format readers and writers. + * + * The return code and interface of these are quite different from other + * functions for archive_entry defined in archive_entry.h. + * Common return code are: + * Return 0 if the string conversion succeeded. + * Return -1 if the string conversion failed. + */ + +#define archive_entry_gname_l _archive_entry_gname_l +int _archive_entry_gname_l(struct archive_entry *, + const char **, size_t *, struct archive_string_conv *); +#define archive_entry_hardlink_l _archive_entry_hardlink_l +int _archive_entry_hardlink_l(struct archive_entry *, + const char **, size_t *, struct archive_string_conv *); +#define archive_entry_pathname_l _archive_entry_pathname_l +int _archive_entry_pathname_l(struct archive_entry *, + const char **, size_t *, struct archive_string_conv *); +#define archive_entry_symlink_l _archive_entry_symlink_l +int _archive_entry_symlink_l(struct archive_entry *, + const char **, size_t *, struct archive_string_conv *); +#define archive_entry_uname_l _archive_entry_uname_l +int _archive_entry_uname_l(struct archive_entry *, + const char **, size_t *, struct archive_string_conv *); +#define archive_entry_acl_text_l _archive_entry_acl_text_l +int _archive_entry_acl_text_l(struct archive_entry *, int, + const char **, size_t *, struct archive_string_conv *); + + +#define archive_entry_copy_gname_l _archive_entry_copy_gname_l +int _archive_entry_copy_gname_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); +#define archive_entry_copy_hardlink_l _archive_entry_copy_hardlink_l +int _archive_entry_copy_hardlink_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); +#define archive_entry_copy_link_l _archive_entry_copy_link_l +int _archive_entry_copy_link_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); +#define archive_entry_copy_pathname_l _archive_entry_copy_pathname_l +int _archive_entry_copy_pathname_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); +#define archive_entry_copy_symlink_l _archive_entry_copy_symlink_l +int _archive_entry_copy_symlink_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); +#define archive_entry_copy_uname_l _archive_entry_copy_uname_l +int _archive_entry_copy_uname_l(struct archive_entry *, + const char *, size_t, struct archive_string_conv *); + +#endif /* ARCHIVE_ENTRY_LOCALE_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 new file mode 100644 index 000000000..621f65518 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_paths.3 @@ -0,0 +1,151 @@ +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd February 22, 2010 +.Dt ARCHIVE_ENTRY_PATHS 3 +.Os +.Sh NAME +.Nm archive_entry_hardlink , +.Nm archive_entry_hardlink_w , +.Nm archive_entry_set_hardlink , +.Nm archive_entry_copy_hardlink , +.Nm archive_entry_copy_hardlink_w , +.Nm archve_entry_update_hardlink_utf8 , +.Nm archive_entry_set_link , +.Nm archive_entry_copy_link , +.Nm archive_entry_copy_link_w , +.Nm archve_entry_update_link_utf8 , +.Nm archive_entry_pathname , +.Nm archive_entry_pathname_w , +.Nm archive_entry_set_pathname , +.Nm archive_entry_copy_pathname , +.Nm archive_entry_copy_pathname_w , +.Nm archve_entry_update_pathname_utf8 , +.Nm archive_entry_sourcepath , +.Nm archive_entry_copy_sourcepath , +.Nm archive_entry_symlink, +.Nm archive_entry_symlink_w, +.Nm archive_entry_set_symlink , +.Nm archive_entry_copy_symlink , +.Nm archive_entry_copy_symlink_w , +.Nm archve_entry_update_symlink_utf8 +.Nd functions for manipulating path names in archive entry descriptions +.Sh SYNOPSIS +.In archive_entry.h +.Ft const char * +.Fn archive_entry_hardlink "struct archive_entry *a" +.Ft const wchar_t * +.Fn archive_entry_hardlink_w "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_hardlink "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_hardlink "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_hardlink_w "struct archive_entry *a "const wchar_t *path" +.Ft int +.Fn archive_entry_update_hardlink_utf8 "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_set_link "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_link "struct archive_entry *a" " const char *path" +.Ft void +.Fn archive_entry_copy_link_w "struct archive_entry *a" " const wchar_t *path" +.Ft int +.Fn archive_entry_update_link_utf8 "struct archive_entry *a" " const char *path" +.Ft const char * +.Fn archive_entry_pathname "struct archive_entry *a" +.Ft const wchar_t * +.Fn archive_entry_pathname_w "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_pathname "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_pathname "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_pathname_w "struct archive_entry *a" "const wchar_t *path" +.Ft int +.Fn archive_entry_update_pathname_utf8 "struct archive_entry *a" "const char *path" +.Ft const char * +.Fn archive_entry_sourcepath "struct archive_entry *a" +.Ft void +.Fn archive_entry_copy_sourcepath "struct archive_entry *a" "const char *path" +.Ft const char * +.Fn archive_entry_symlink "struct archive_entry *a" +.Ft const wchar_t * +.Fn archive_entry_symlink_w "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_symlink "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_symlink "struct archive_entry *a" "const char *path" +.Ft void +.Fn archive_entry_copy_symlink_w "struct archive_entry *a" "const wchar_t *path" +.Ft int +.Fn archive_entry_update_symlink_utf8 "struct archive_entry *a" "const char *path" +.Sh DESCRIPTION +Path names supported by +.Xr archive_entry 3 : +.Bl -tag -width "sourcepath" -compact +.It hardlink +Destination of the hardlink. +.It link +Update only. +For a symlink, update the destination. +Otherwise, make the entry a hardlink and alter +the destination for that. +.It pathname +Path in the archive +.It sourcepath +Path on the disk for use by +.Xr archive_read_disk 3 . +.It symlink +Destination of the symbolic link. +.El +.Pp +Path names can be provided in one of three different ways: +.Bl -tag -width "wchar_t *" +.It char * +Multibyte strings in the current locale. +.It wchar_t * +Wide character strings in the current locale. +The accessor functions are named +.Fn XXX_w . +.It UTF-8 +Unicode strings encoded as UTF-8. +This are convience functions to update both the multibyte and wide +character strings at the same time. +.El +.Pp +The sourcepath is a pure filesystem concept and never stored in an +archive directly. +.Pp +For that reason, it is only available as multibyte string. +The link path is a convience function for conditionally setting +hardlink or symlink destination. +It doesn't have a corresponding get accessor function. +.Pp +.Fn archive_entry_set_XXX +is an alias for +.Fn archive_entry_copy_XXX . +.Sh SEE ALSO +.Xr archive 3 , +.Xr archive_entry 3 diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 new file mode 100644 index 000000000..164af9731 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_perms.3 @@ -0,0 +1,207 @@ +.\" Copyright (c) 2003-2007 Tim Kientzle +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd February 22, 2010 +.Dt ARCHIVE_ENTRY_PERMS 3 +.Os +.Sh NAME +.Nm archive_entry_gid , +.Nm archive_entry_set_gid , +.Nm archive_entry_uid , +.Nm archive_entry_set_uid , +.Nm archive_entry_perm , +.Nm archive_entry_set_perm , +.Nm archive_entry_strmode , +.Nm archive_entry_uname +.Nm archive_entry_uname_w +.Nm archive_entry_set_uname , +.Nm archive_entry_copy_uname , +.Nm archive_entry_copy_uname_w , +.Nm archive_entry_update_uname_utf8 , +.Nm archive_entry_gname , +.Nm archive_entry_gname_w , +.Nm archive_entry_set_gname , +.Nm archive_entry_copy_gname , +.Nm archive_entry_copy_gname_w , +.Nm archive_entry_update_gname_utf8 , +.Nm archive_entry_fflags , +.Nm archive_entry_fflags_text , +.Nm archive_entry_set_fflags , +.Nm archive_entry_copy_fflags_text , +.Nm archive_entry_copy_fflags_text_w +.Nd functions for manipulating ownership and permissions in archive entry descriptions +.Sh SYNOPSIS +.In archive_entry.h +.Ft gid_t +.Fn archive_entry_gid "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_gid "struct archive_entry *a" "gid_t gid" +.Ft uid_t +.Fn archive_entry_uid "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_uid "struct archive_entry *a" "uid_t uid" +.Ft mode_t +.Fn archive_entry_perm "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_perm "struct archive_entry *a" "mode_t mode" +.Ft const char * +.Fn archive_entry_strmode "struct archive_entry *a" +.Ft const char * +.Fn archive_entry_gname "struct archive_entry *a" +.Ft const wchar_t * +.Fn archive_entry_gname_w "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_gname "struct archive_entry *a" "const char *a" +.Ft void +.Fn archive_entry_copy_gname "struct archive_entry *a" "const char *name" +.Ft void +.Fn archive_entry_copy_gname_w "struct archive_entry *a" "const wchar_t *name" +.Ft int +.Fn archive_entry_update_gname_utf8 "struct archive_entry *a" "const char *name" +.Ft const char * +.Fn archive_entry_uname "struct archive_entry *a" +.Ft const wchar_t * +.Fn archive_entry_uname_w "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_uname "struct archive_entry *a" "const char *name" +.Ft void +.Fn archive_entry_copy_uname "struct archive_entry *a" "const char *name" +.Ft void +.Fn archive_entry_copy_uname_w "struct archive_entry *a" "const wchar_t *name" +.Ft int +.Fn archive_entry_update_uname_utf8 "struct archive_entry *a" "const char *name" +.Ft void +.Fo archive_entry_fflags +.Fa "struct archive_entry *a" +.Fa "unsigned long *set_bits" +.Fa "unsigned long *clear_bits" +.Fc +.Ft const char * +.Fn archive_entry_fflags_text "struct archive_entry *a" +.Ft void +.Fo archive_entry_set_fflags +.Fa "struct archive_entry *a" +.Fa "unsigned long set_bits" +.Fa "unsigned long clear_bits" +.Fc +.Ft const char * +.Fn archive_entry_copy_fflags_text "struct archive_entry *a" "const char *text" +.Ft const wchar_t * +.Fn archive_entry_copy_fflags_text_w "struct archive_entry *a" "const wchar_t *text" +.Sh DESCRIPTION +.Ss User id, group id and mode +The functions +.Fn archive_entry_uid , +.Fn archive_entry_gid , +and +.Fn archive_entry_perm +can be used to extract the user id, group id and permission from the given entry. +The corresponding functions +.Fn archive_entry_set_uid , +.Fn archive_entry_set_gid , +and +.Fn archive_entry_set_perm +store the given user id, group id and permission in the entry. +The permission is also set as side effect of calling +.Fn archive_entry_set_mode . +.Pp +.Fn archive_entry_strmode +returns a string representation of the permission as used by the long mode of +.Xr ls 1 . +.Ss User and group name +User and group names can be provided in one of three different ways: +.Bl -tag -width "wchar_t *" +.It char * +Multibyte strings in the current locale. +.It wchar_t * +Wide character strings in the current locale. +The accessor functions are named +.Fn XXX_w . +.It UTF-8 +Unicode strings encoded as UTF-8. +This are convience functions to update both the multibyte and wide +character strings at the same time. +.El +.Pp +.Fn archive_entry_set_XXX +is an alias for +.Fn archive_entry_copy_XXX . +.Ss File Flags +File flags are transparently converted between a bitmap +representation and a textual format. +For example, if you set the bitmap and ask for text, the library +will build a canonical text format. +However, if you set a text format and request a text format, +you will get back the same text, even if it is ill-formed. +If you need to canonicalize a textual flags string, you should first set the +text form, then request the bitmap form, then use that to set the bitmap form. +Setting the bitmap format will clear the internal text representation +and force it to be reconstructed when you next request the text form. +.Pp +The bitmap format consists of two integers, one containing bits +that should be set, the other specifying bits that should be +cleared. +Bits not mentioned in either bitmap will be ignored. +Usually, the bitmap of bits to be cleared will be set to zero. +In unusual circumstances, you can force a fully-specified set +of file flags by setting the bitmap of flags to clear to the complement +of the bitmap of flags to set. +(This differs from +.Xr fflagstostr 3 , +which only includes names for set bits.) +Converting a bitmap to a textual string is a platform-specific +operation; bits that are not meaningful on the current platform +will be ignored. +.Pp +The canonical text format is a comma-separated list of flag names. +The +.Fn archive_entry_copy_fflags_text +and +.Fn archive_entry_copy_fflags_text_w +functions parse the provided text and sets the internal bitmap values. +This is a platform-specific operation; names that are not meaningful +on the current platform will be ignored. +The function returns a pointer to the start of the first name that was not +recognized, or NULL if every name was recognized. +Note that every name \(em including names that follow an unrecognized +name \(em will be evaluated, and the bitmaps will be set to reflect +every name that is recognized. +(In particular, this differs from +.Xr strtofflags 3 , +which stops parsing at the first unrecognized name.) +.Sh SEE ALSO +.Xr archive 3 , +.Xr archive_entry 3 , +.Xr archive_entry_acl 3 , +.Xr archive_read_disk 3 , +.Xr archive_write_disk 3 +.Sh BUGS +The platform types +.Vt uid_t +and +.Vt gid_t +are often 16 or 32 bit wide. +In this case it is possible that the ids can not be correctly restored +from archives and get truncated. diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_private.h b/Utilities/cmlibarchive/libarchive/archive_entry_private.h index 6caf53176..e3547c3e3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_entry_private.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_entry_private.h,v 1.6 2008/09/30 03:53:03 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_entry_private.h 201096 2009-12-28 02:41:27Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -30,44 +30,24 @@ #endif #ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED -#define ARCHIVE_ENTRY_PRIVATE_H_INCLUDED +#define ARCHIVE_ENTRY_PRIVATE_H_INCLUDED +#include "archive_acl_private.h" #include "archive_string.h" -/* - * Handle wide character (i.e., Unicode) and non-wide character - * strings transparently. - */ - -struct aes { - struct archive_string aes_mbs; - struct archive_string aes_utf8; - const wchar_t *aes_wcs; - /* Bitmap of which of the above are valid. Because we're lazy - * about malloc-ing and reusing the underlying storage, we - * can't rely on NULL pointers to indicate whether a string - * has been set. */ - int aes_set; -#define AES_SET_MBS 1 -#define AES_SET_UTF8 2 -#define AES_SET_WCS 4 -}; +struct ae_xattr { + struct ae_xattr *next; -struct ae_acl { - struct ae_acl *next; - int type; /* E.g., access or default */ - int tag; /* E.g., user/group/other/mask */ - int permset; /* r/w/x bits */ - int id; /* uid/gid for user/group */ - struct aes name; /* uname/gname */ + char *name; + void *value; + size_t size; }; -struct ae_xattr { - struct ae_xattr *next; +struct ae_sparse { + struct ae_sparse *next; - char *name; - void *value; - size_t size; + int64_t offset; + int64_t length; }; /* @@ -91,94 +71,106 @@ struct ae_xattr { * TODO: Design a good API for handling sparse files. */ struct archive_entry { - /* - * Note that ae_stat.st_mode & AE_IFMT can be 0! - * - * This occurs when the actual file type of the object is not - * in the archive. For example, 'tar' archives store - * hardlinks without marking the type of the underlying - * object. - */ - - /* - * Read archive_entry_copy_stat.c for an explanation of why I - * don't just use "struct stat" instead of "struct aest" here - * and why I have this odd pointer to a separately-allocated - * struct stat. - */ - void *stat; - int stat_valid; /* Set to 0 whenever a field in aest changes. */ - - struct aest { - int64_t aest_atime; - uint32_t aest_atime_nsec; - int64_t aest_ctime; - uint32_t aest_ctime_nsec; - int64_t aest_mtime; - uint32_t aest_mtime_nsec; - int64_t aest_birthtime; - uint32_t aest_birthtime_nsec; - gid_t aest_gid; - int64_t aest_ino; - mode_t aest_mode; - uint32_t aest_nlink; - uint64_t aest_size; - uid_t aest_uid; - /* - * Because converting between device codes and - * major/minor values is platform-specific and - * inherently a bit risky, we only do that conversion - * lazily. That way, we will do a better job of - * preserving information in those cases where no - * conversion is actually required. - */ - int aest_dev_is_broken_down; - dev_t aest_dev; - dev_t aest_devmajor; - dev_t aest_devminor; - int aest_rdev_is_broken_down; - dev_t aest_rdev; - dev_t aest_rdevmajor; - dev_t aest_rdevminor; - } ae_stat; - - int ae_set; /* bitmap of fields that are currently set */ -#define AE_SET_HARDLINK 1 -#define AE_SET_SYMLINK 2 -#define AE_SET_ATIME 4 -#define AE_SET_CTIME 8 -#define AE_SET_MTIME 16 -#define AE_SET_BIRTHTIME 32 -#define AE_SET_SIZE 64 - - /* - * Use aes here so that we get transparent mbs<->wcs conversions. - */ - struct aes ae_fflags_text; /* Text fflags per fflagstostr(3) */ - unsigned long ae_fflags_set; /* Bitmap fflags */ - unsigned long ae_fflags_clear; - struct aes ae_gname; /* Name of owning group */ - struct aes ae_hardlink; /* Name of target for hardlink */ - struct aes ae_pathname; /* Name of entry */ - struct aes ae_symlink; /* symlink contents */ - struct aes ae_uname; /* Name of owner */ - - /* Not used within libarchive; useful for some clients. */ - struct aes ae_sourcepath; /* Path this entry is sourced from. */ - - /* ACL support. */ - struct ae_acl *acl_head; - struct ae_acl *acl_p; - int acl_state; /* See acl_next for details. */ - wchar_t *acl_text_w; - - /* extattr support. */ - struct ae_xattr *xattr_head; - struct ae_xattr *xattr_p; - - /* Miscellaneous. */ - char strmode[12]; + struct archive *archive; + + /* + * Note that ae_stat.st_mode & AE_IFMT can be 0! + * + * This occurs when the actual file type of the object is not + * in the archive. For example, 'tar' archives store + * hardlinks without marking the type of the underlying + * object. + */ + + /* + * We have a "struct aest" for holding file metadata rather than just + * a "struct stat" because on some platforms the "struct stat" has + * fields which are too narrow to hold the range of possible values; + * we don't want to lose information if we read an archive and write + * out another (e.g., in "tar -cf new.tar @old.tar"). + * + * The "stat" pointer points to some form of platform-specific struct + * stat; it is declared as a void * rather than a struct stat * as + * some platforms have multiple varieties of stat structures. + */ + void *stat; + int stat_valid; /* Set to 0 whenever a field in aest changes. */ + + struct aest { + int64_t aest_atime; + uint32_t aest_atime_nsec; + int64_t aest_ctime; + uint32_t aest_ctime_nsec; + int64_t aest_mtime; + uint32_t aest_mtime_nsec; + int64_t aest_birthtime; + uint32_t aest_birthtime_nsec; + int64_t aest_gid; + int64_t aest_ino; + uint32_t aest_nlink; + uint64_t aest_size; + int64_t aest_uid; + /* + * Because converting between device codes and + * major/minor values is platform-specific and + * inherently a bit risky, we only do that conversion + * lazily. That way, we will do a better job of + * preserving information in those cases where no + * conversion is actually required. + */ + int aest_dev_is_broken_down; + dev_t aest_dev; + dev_t aest_devmajor; + dev_t aest_devminor; + int aest_rdev_is_broken_down; + dev_t aest_rdev; + dev_t aest_rdevmajor; + dev_t aest_rdevminor; + } ae_stat; + + int ae_set; /* bitmap of fields that are currently set */ +#define AE_SET_HARDLINK 1 +#define AE_SET_SYMLINK 2 +#define AE_SET_ATIME 4 +#define AE_SET_CTIME 8 +#define AE_SET_MTIME 16 +#define AE_SET_BIRTHTIME 32 +#define AE_SET_SIZE 64 +#define AE_SET_INO 128 +#define AE_SET_DEV 256 + + /* + * Use aes here so that we get transparent mbs<->wcs conversions. + */ + struct archive_mstring ae_fflags_text; /* Text fflags per fflagstostr(3) */ + unsigned long ae_fflags_set; /* Bitmap fflags */ + unsigned long ae_fflags_clear; + struct archive_mstring ae_gname; /* Name of owning group */ + struct archive_mstring ae_hardlink; /* Name of target for hardlink */ + struct archive_mstring ae_pathname; /* Name of entry */ + struct archive_mstring ae_symlink; /* symlink contents */ + struct archive_mstring ae_uname; /* Name of owner */ + + /* Not used within libarchive; useful for some clients. */ + struct archive_mstring ae_sourcepath; /* Path this entry is sourced from. */ + + void *mac_metadata; + size_t mac_metadata_size; + + /* ACL support. */ + struct archive_acl acl; + + /* extattr support. */ + struct ae_xattr *xattr_head; + struct ae_xattr *xattr_p; + + /* sparse support. */ + struct ae_sparse *sparse_head; + struct ae_sparse *sparse_tail; + struct ae_sparse *sparse_p; + + /* Miscellaneous. */ + char strmode[12]; }; - #endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c new file mode 100644 index 000000000..10c54474a --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_sparse.c @@ -0,0 +1,156 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2010-2011 Michihiro NAKAJIMA + * 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_entry.h" +#include "archive_private.h" +#include "archive_entry_private.h" + +/* + * sparse handling + */ + +void +archive_entry_sparse_clear(struct archive_entry *entry) +{ + struct ae_sparse *sp; + + while (entry->sparse_head != NULL) { + sp = entry->sparse_head->next; + free(entry->sparse_head); + entry->sparse_head = sp; + } + entry->sparse_tail = NULL; +} + +void +archive_entry_sparse_add_entry(struct archive_entry *entry, + int64_t offset, int64_t length) +{ + struct ae_sparse *sp; + + if (offset < 0 || length < 0) + /* Invalid value */ + return; + if (offset + length < 0 || + offset + length > archive_entry_size(entry)) + /* A value of "length" parameter is too large. */ + return; + if ((sp = entry->sparse_tail) != NULL) { + if (sp->offset + sp->length > offset) + /* Invalid value. */ + return; + if (sp->offset + sp->length == offset) { + if (sp->offset + sp->length + length < 0) + /* A value of "length" parameter is + * too large. */ + return; + /* Expand existing sparse block size. */ + sp->length += length; + return; + } + } + + if ((sp = (struct ae_sparse *)malloc(sizeof(*sp))) == NULL) + /* XXX Error XXX */ + return; + + sp->offset = offset; + sp->length = length; + sp->next = NULL; + + if (entry->sparse_head == NULL) + entry->sparse_head = entry->sparse_tail = sp; + else { + /* Add a new sparse block to the tail of list. */ + if (entry->sparse_tail != NULL) + entry->sparse_tail->next = sp; + entry->sparse_tail = sp; + } +} + + +/* + * returns number of the sparse entries + */ +int +archive_entry_sparse_count(struct archive_entry *entry) +{ + struct ae_sparse *sp; + int count = 0; + + for (sp = entry->sparse_head; sp != NULL; sp = sp->next) + count++; + + /* + * Sanity check if this entry is exactly sparse. + * If amount of sparse blocks is just one and it indicates the whole + * file data, we should remove it and return zero. + */ + if (count == 1) { + sp = entry->sparse_head; + if (sp->offset == 0 && + sp->length >= archive_entry_size(entry)) { + count = 0; + archive_entry_sparse_clear(entry); + } + } + + return (count); +} + +int +archive_entry_sparse_reset(struct archive_entry * entry) +{ + entry->sparse_p = entry->sparse_head; + + return archive_entry_sparse_count(entry); +} + +int +archive_entry_sparse_next(struct archive_entry * entry, + int64_t *offset, int64_t *length) +{ + if (entry->sparse_p) { + *offset = entry->sparse_p->offset; + *length = entry->sparse_p->length; + + entry->sparse_p = entry->sparse_p->next; + + return (ARCHIVE_OK); + } else { + *offset = 0; + *length = 0; + return (ARCHIVE_WARN); + } +} + +/* + * end of sparse handling + */ diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 new file mode 100644 index 000000000..36a7efb23 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.3 @@ -0,0 +1,272 @@ +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd May 12, 2008 +.Dt ARCHIVE_ENTRY 3 +.Os +.Sh NAME +.Nm archive_entry_stat , +.Nm archive_entry_copy_stat , +.Nm archive_entry_filetype , +.Nm archive_entry_set_filetype , +.Nm archive_entry_mode , +.Nm archive_entry_set_mode , +.Nm archive_entry_size , +.Nm archive_entry_size_is_set , +.Nm archive_entry_set_size , +.Nm archive_entry_unset_size , +.Nm archive_entry_dev , +.Nm archive_entry_set_dev , +.Nm archive_entry_dev_is_set , +.Nm archive_entry_devmajor , +.Nm archive_entry_set_devmajor , +.Nm archive_entry_devminor , +.Nm archive_entry_set_devminor , +.Nm archive_entry_ino , +.Nm archive_entry_set_ino , +.Nm archive_entry_ino_is_set , +.Nm archive_entry_ino64 , +.Nm archive_entry_set_ino64 , +.Nm archive_entry_nlink , +.Nm archive_entry_rdev , +.Nm archive_entry_set_rdev , +.Nm archive_entry_rdevmajor , +.Nm archive_entry_set_rdevmajor , +.Nm archive_entry_rdevminor , +.Nm archive_entry_set_rdevminor , +.Nd accessor functions for manipulating archive entry descriptions +.Sh SYNOPSIS +.In archive_entry.h +.Ft const struct stat * +.Fn archive_entry_stat "struct archive_entry *a" +.Ft void +.Fn archive_entry_copy_stat "struct archive_entry *a" "const struct stat *sb" +.Ft mode_t +.Fn archive_entry_filetype "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_filetype "struct archive_entry *a" "unsigned int type" +.Ft mode_t +.Fn archive_entry_mode "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_mode "struct archive_entry *a" "mode_t mode" +.Ft int64_t +.Fn archive_entry_size "struct archive_entry *a" +.Ft int +.Fn archive_entry_size_is_set "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_size "struct archive_entry *a" "int64_t size" +.Ft void +.Fn archive_entry_unset_size "struct archive_entry *a" +.Ft dev_t +.Fn archive_entry_dev "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_dev "struct archive_entry *a" "dev_t dev" +.Ft int +.Fn archive_entry_dev_is_set "struct archive_entry *a" +.Ft dev_t +.Fn archive_entry_devmajor "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_devmajor "struct archive_entry *a" "dev_t major" +.Ft dev_t +.Fn archive_entry_devminor "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_devminor "struct archive_entry *a" "dev_t minor" +.Ft ino_t +.Fn archive_entry_ino "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_ino "struct archive_entry *a" "unsigned long ino" +.Ft int +.Fn archive_entry_ino_is_set "struct archive_entry *a" +.Ft int64_t +.Fn archive_entry_ino64 "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_ino64 "struct archive_entry *a" "int64_t ino" +.Ft unsigned int +.Fn archive_entry_nlink "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_nlink "struct archive_entry *a" "unsigned int count" +.Ft dev_t +.Fn archive_entry_rdev "struct archive_entry *a" +.Ft dev_t +.Fn archive_entry_rdevmajor "struct archive_entry *a" +.Ft dev_t +.Fn archive_entry_rdevminor "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_rdev "struct archive_entry *a" "dev_t dev" +.Ft void +.Fn archive_entry_set_rdevmajor "struct archive_entry *a" "dev_t major" +.Ft void +.Fn archive_entry_set_rdevminor "struct archive_entry *a" "dev_t minor" +.Sh DESCRIPTION +.Ss Copying to and from Vt struct stat +The function +.Fn archive_entry_stat +converts the various fields stored in the archive entry to the format +used by +.Xr stat 2 . +The return value remains valid until either +.Fn archive_entry_clear +or +.Fn archive_entry_free +is called. +It is not affected by calls to the set accessor functions. +It currently sets the following values in +.Vt struct stat : +.Vt st_atime , +.Vt st_ctime , +.Vt st_dev , +.Vt st_gid , +.Vt st_ino , +.Vt st_mode , +.Vt st_mtime , +.Vt st_nlink , +.Vt st_rdev , +.Vt st_size , +.Vt st_uid . +In addition, +.Vt st_birthtime +and high-precision information for time-related fields +will be included on platforms that support it. +.Pp +The function +.Fn archive_entry_copy_stat +copies fields from the platform's +.Vt struct stat . +Fields not provided by +.Vt struct stat +are unchanged. +.Ss General accessor functions +The functions +.Fn archive_entry_filetype +and +.Fn archive_entry_set_filetype +get respectively set the filetype. +The file type is one of the following constants: +.Bl -tag -width "AE_IFSOCK" -compact -offset indent +.It AE_IFREG +Regular file +.It AE_IFLNK +Symbolic link +.It AE_IFSOCK +Socket +.It AE_IFCHR +Character device +.It AE_IFBLK +Block device +.It AE_IFDIR +Directory +.It AE_IFIFO +Named pipe (fifo) +.El +Not all file types are supported by all platforms. +The constants used by +.Xr stat 2 +may have different numeric values from the +corresponding constants above. +.Pp +The functions +.Fn archive_entry_mode +and +.Fn archive_entry_set_mode +get/set a combination of file type and permissions and provide the +equivalent of +.Va st_mode . +Use of +.Fn archive_entry_filetype +and +.Fn archive_entry_perm +for getting and +.Fn archive_entry_set_filetype +and +.Fn archive_entry_set_perm +for setting is recommended. +.Pp +The function +.Fn archive_entry_size +returns the file size, if it has been set, and 0 otherwise. +.Fn archive_entry_size +can be used to query that status. +.Fn archive_entry_set_size +and +.Fn archive_entry_unset_size +set and unset the size, respectively. +.Pp +The number of references (hardlinks) can be obtained by calling +.Fn archive_entry_nlinks +and set with +.Fn archive_entry_set_nlinks . +.Ss Identifying unique files +The functions +.Fn archive_entry_dev +and +.Fn archive_entry_ino64 +are used by +.Xr archive_entry_linkify 3 +to find hardlinks. +The pair of device and inode is suppossed to identify hardlinked files. +.Pp +The device major and minor number can be obtained independently using +.Fn archive_entry_devmajor +and +.Fn archive_entry_devminor . +The device can be set either via +.Fn archive_entry_set_dev +or by the combination of major and minor number using +.Fn archive_entry_set_devmajor +and +.Fn archive_entry_set_devminor . +.Pp +The inode number can be obtained using +.Fn archive_entry_ino . +This is a legacy interface that uses the platform +.Vt ino_t , +which may be very small. +To set the inode number, +.Fn archive_entry_set_ino64 +is the preferred interface. +.Ss Accessor functions for block and character devices +Block and character devices are characterised either using a device number +or a pair of major and minor number. +The combined device number can be obtained with +.Fn archive_device_rdev +and set with +.Fn archive_device_set_rdev . +The major and minor numbers are accessed by +.Fn archive_device_rdevmajor , +.Fn archive_device_rdevminor +.Fn archive_device_set_rdevmajor +and +.Fn archive_device_set_rdevminor . +.Pp +The process of splitting the combined device number into major and +minor number and the reverse process of combing them differs between +platforms. +Some archive formats use the combined form, while other formats use +the split form. +.Sh SEE ALSO +.Xr archive 3 , +.Xr archive_entry_acl 3 , +.Xr archive_entry_perms 3 , +.Xr archive_entry_time 3 , +.Xr stat 2 diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_stat.c b/Utilities/cmlibarchive/libarchive/archive_entry_stat.c index 1c661659a..d5ed1cb13 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_stat.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_stat.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_stat.c,v 1.2 2008/09/30 03:53:03 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_stat.c 201100 2009-12-28 03:05:31Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -39,80 +39,80 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_stat.c,v 1.2 2008/09/30 03: const struct stat * archive_entry_stat(struct archive_entry *entry) { - struct stat *st; - if (entry->stat == NULL) { - entry->stat = malloc(sizeof(*st)); - if (entry->stat == NULL) - return (NULL); - entry->stat_valid = 0; - } + struct stat *st; + if (entry->stat == NULL) { + entry->stat = calloc(1, sizeof(*st)); + if (entry->stat == NULL) + return (NULL); + entry->stat_valid = 0; + } - /* - * If none of the underlying fields have been changed, we - * don't need to regenerate. In theory, we could use a bitmap - * here to flag only those items that have changed, but the - * extra complexity probably isn't worth it. It will be very - * rare for anyone to change just one field then request a new - * stat structure. - */ - if (entry->stat_valid) - return (entry->stat); + /* + * If none of the underlying fields have been changed, we + * don't need to regenerate. In theory, we could use a bitmap + * here to flag only those items that have changed, but the + * extra complexity probably isn't worth it. It will be very + * rare for anyone to change just one field then request a new + * stat structure. + */ + if (entry->stat_valid) + return (entry->stat); - st = entry->stat; - /* - * Use the public interfaces to extract items, so that - * the appropriate conversions get invoked. - */ - st->st_atime = archive_entry_atime(entry); + st = entry->stat; + /* + * Use the public interfaces to extract items, so that + * the appropriate conversions get invoked. + */ + st->st_atime = archive_entry_atime(entry); #if HAVE_STRUCT_STAT_ST_BIRTHTIME - st->st_birthtime = archive_entry_birthtime(entry); + st->st_birthtime = archive_entry_birthtime(entry); #endif - st->st_ctime = archive_entry_ctime(entry); - st->st_mtime = archive_entry_mtime(entry); - st->st_dev = archive_entry_dev(entry); - st->st_gid = archive_entry_gid(entry); - st->st_uid = archive_entry_uid(entry); - st->st_ino = archive_entry_ino64(entry); - st->st_nlink = archive_entry_nlink(entry); - st->st_rdev = archive_entry_rdev(entry); - st->st_size = archive_entry_size(entry); - st->st_mode = archive_entry_mode(entry); + st->st_ctime = archive_entry_ctime(entry); + st->st_mtime = archive_entry_mtime(entry); + st->st_dev = archive_entry_dev(entry); + st->st_gid = archive_entry_gid(entry); + st->st_uid = archive_entry_uid(entry); + st->st_ino = archive_entry_ino64(entry); + st->st_nlink = archive_entry_nlink(entry); + st->st_rdev = archive_entry_rdev(entry); + st->st_size = archive_entry_size(entry); + st->st_mode = archive_entry_mode(entry); - /* - * On systems that support high-res timestamps, copy that - * information into struct stat. - */ + /* + * On systems that support high-res timestamps, copy that + * information into struct stat. + */ #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - st->st_atimespec.tv_nsec = archive_entry_atime_nsec(entry); - st->st_ctimespec.tv_nsec = archive_entry_ctime_nsec(entry); - st->st_mtimespec.tv_nsec = archive_entry_mtime_nsec(entry); + st->st_atimespec.tv_nsec = archive_entry_atime_nsec(entry); + st->st_ctimespec.tv_nsec = archive_entry_ctime_nsec(entry); + st->st_mtimespec.tv_nsec = archive_entry_mtime_nsec(entry); #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - st->st_atim.tv_nsec = archive_entry_atime_nsec(entry); - st->st_ctim.tv_nsec = archive_entry_ctime_nsec(entry); - st->st_mtim.tv_nsec = archive_entry_mtime_nsec(entry); + st->st_atim.tv_nsec = archive_entry_atime_nsec(entry); + st->st_ctim.tv_nsec = archive_entry_ctime_nsec(entry); + st->st_mtim.tv_nsec = archive_entry_mtime_nsec(entry); #elif HAVE_STRUCT_STAT_ST_MTIME_N - st->st_atime_n = archive_entry_atime_nsec(entry); - st->st_ctime_n = archive_entry_ctime_nsec(entry); - st->st_mtime_n = archive_entry_mtime_nsec(entry); + st->st_atime_n = archive_entry_atime_nsec(entry); + st->st_ctime_n = archive_entry_ctime_nsec(entry); + st->st_mtime_n = archive_entry_mtime_nsec(entry); #elif HAVE_STRUCT_STAT_ST_UMTIME - st->st_uatime = archive_entry_atime_nsec(entry) / 1000; - st->st_uctime = archive_entry_ctime_nsec(entry) / 1000; - st->st_umtime = archive_entry_mtime_nsec(entry) / 1000; + st->st_uatime = archive_entry_atime_nsec(entry) / 1000; + st->st_uctime = archive_entry_ctime_nsec(entry) / 1000; + st->st_umtime = archive_entry_mtime_nsec(entry) / 1000; #elif HAVE_STRUCT_STAT_ST_MTIME_USEC - st->st_atime_usec = archive_entry_atime_nsec(entry) / 1000; - st->st_ctime_usec = archive_entry_ctime_nsec(entry) / 1000; - st->st_mtime_usec = archive_entry_mtime_nsec(entry) / 1000; + st->st_atime_usec = archive_entry_atime_nsec(entry) / 1000; + st->st_ctime_usec = archive_entry_ctime_nsec(entry) / 1000; + st->st_mtime_usec = archive_entry_mtime_nsec(entry) / 1000; #endif #if HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC - st->st_birthtimespec.tv_nsec = archive_entry_birthtime_nsec(entry); + st->st_birthtimespec.tv_nsec = archive_entry_birthtime_nsec(entry); #endif - /* - * TODO: On Linux, store 32 or 64 here depending on whether - * the cached stat structure is a stat32 or a stat64. This - * will allow us to support both variants interchangably. - */ - entry->stat_valid = 1; + /* + * TODO: On Linux, store 32 or 64 here depending on whether + * the cached stat structure is a stat32 or a stat64. This + * will allow us to support both variants interchangably. + */ + entry->stat_valid = 1; - return (st); + return (st); } diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c b/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c index 3ff314975..16cb3f7bb 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_strmode.c @@ -39,49 +39,49 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_strmode.c,v 1.4 2008/06/15 const char * archive_entry_strmode(struct archive_entry *entry) { - static const mode_t permbits[] = - { 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 }; - char *bp = entry->strmode; - mode_t mode; - int i; + static const mode_t permbits[] = + { 0400, 0200, 0100, 0040, 0020, 0010, 0004, 0002, 0001 }; + char *bp = entry->strmode; + mode_t mode; + int i; - /* Fill in a default string, then selectively override. */ - strcpy(bp, "?rwxrwxrwx "); + /* Fill in a default string, then selectively override. */ + strcpy(bp, "?rwxrwxrwx "); - mode = archive_entry_mode(entry); - switch (archive_entry_filetype(entry)) { - case AE_IFREG: bp[0] = '-'; break; - case AE_IFBLK: bp[0] = 'b'; break; - case AE_IFCHR: bp[0] = 'c'; break; - case AE_IFDIR: bp[0] = 'd'; break; - case AE_IFLNK: bp[0] = 'l'; break; - case AE_IFSOCK: bp[0] = 's'; break; - case AE_IFIFO: bp[0] = 'p'; break; - default: - if (archive_entry_hardlink(entry) != NULL) { - bp[0] = 'h'; - break; - } - } + mode = archive_entry_mode(entry); + switch (archive_entry_filetype(entry)) { + case AE_IFREG: bp[0] = '-'; break; + case AE_IFBLK: bp[0] = 'b'; break; + case AE_IFCHR: bp[0] = 'c'; break; + case AE_IFDIR: bp[0] = 'd'; break; + case AE_IFLNK: bp[0] = 'l'; break; + case AE_IFSOCK: bp[0] = 's'; break; + case AE_IFIFO: bp[0] = 'p'; break; + default: + if (archive_entry_hardlink(entry) != NULL) { + bp[0] = 'h'; + break; + } + } - for (i = 0; i < 9; i++) - if (!(mode & permbits[i])) - bp[i+1] = '-'; + for (i = 0; i < 9; i++) + if (!(mode & permbits[i])) + bp[i+1] = '-'; - if (mode & S_ISUID) { - if (mode & 0100) bp[3] = 's'; - else bp[3] = 'S'; - } - if (mode & S_ISGID) { - if (mode & 0010) bp[6] = 's'; - else bp[6] = 'S'; - } - if (mode & S_ISVTX) { - if (mode & 0001) bp[9] = 't'; - else bp[9] = 'T'; - } - if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)) - bp[10] = '+'; + if (mode & S_ISUID) { + if (mode & 0100) bp[3] = 's'; + else bp[3] = 'S'; + } + if (mode & S_ISGID) { + if (mode & 0010) bp[6] = 's'; + else bp[6] = 'S'; + } + if (mode & S_ISVTX) { + if (mode & 0001) bp[9] = 't'; + else bp[9] = 'T'; + } + if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)) + bp[10] = '+'; - return (bp); + return (bp); } diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_time.3 b/Utilities/cmlibarchive/libarchive/archive_entry_time.3 new file mode 100644 index 000000000..85a8209e8 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_entry_time.3 @@ -0,0 +1,127 @@ +.\" Copyright (c) 2003-2007 Tim Kientzle +.\" Copyright (c) 2010 Joerg Sonnenberger +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libarchive/archive_entry.3,v 1.18 2008/05/26 17:00:22 kientzle Exp $ +.\" +.Dd February 21, 2010 +.Dt ARCHIVE_ENTRY_TIME 3 +.Os +.Sh NAME +.Nm archive_entry_atime , +.Nm archive_entry_atime_nsec , +.Nm archive_entry_atime_is_set , +.Nm archive_entry_set_atime , +.Nm archive_entry_unset_atime , +.Nm archive_entry_birthtime , +.Nm archive_entry_birthtime_nsec , +.Nm archive_entry_birthtime_is_set , +.Nm archive_entry_set_birthtime , +.Nm archive_entry_unset_birthtime , +.Nm archive_entry_ctime , +.Nm archive_entry_ctime_nsec , +.Nm archive_entry_ctime_is_set , +.Nm archive_entry_set_ctime , +.Nm archive_entry_unset_ctime , +.Nm archive_entry_mtime , +.Nm archive_entry_mtime_nsec , +.Nm archive_entry_mtime_is_set , +.Nm archive_entry_set_mtime , +.Nm archive_entry_unset_mtime , +.Nd functions for manipulating times in archive entry descriptions +.Sh SYNOPSIS +.In archive_entry.h +.Ft time_t +.Fn archive_entry_atime "struct archive_entry *a" +.Ft long +.Fn archive_entry_atime_nsec "struct archive_entry *a" +.Ft int +.Fn archive_entry_atime_is_set "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_atime "struct archive_entry *a" "time_t sec" "long nanosec" +.Ft void +.Fn archive_entry_unset_atime "struct archive_entry *a" +.Ft time_t +.Fn archive_entry_birthtime "struct archive_entry *a" +.Ft long +.Fn archive_entry_birthtime_nsec "struct archive_entry *a" +.Ft int +.Fn archive_entry_birthtime_is_set "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_birthtime "struct archive_entry *a" "time_t sec" "long nanosec" +.Ft void +.Fn archive_entry_unset_birthtime "struct archive_entry *a" +.Ft time_t +.Fn archive_entry_ctime "struct archive_entry *a" +.Ft long +.Fn archive_entry_ctime_nsec "struct archive_entry *a" +.Ft int +.Fn archive_entry_ctime_is_set "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_ctime "struct archive_entry *a" "time_t sec" "long nanosec" +.Ft void +.Fn archive_entry_unset_ctime "struct archive_entry *a" +.Ft time_t +.Fn archive_entry_mtime "struct archive_entry *a" +.Ft long +.Fn archive_entry_mtime_nsec "struct archive_entry *a" +.Ft int +.Fn archive_entry_mtime_is_set "struct archive_entry *a" +.Ft void +.Fn archive_entry_set_mtime "struct archive_entry *a" "time_t sec" "long nanosec" +.Ft void +.Fn archive_entry_unset_mtime "struct archive_entry *a" +.Sh DESCRIPTION +These functions create and manipulate the time fields in an +.Vt archive_entry . +Supported time fields are atime (access time), birthtime (creation time), +ctime (last time an inode property was changed) and mtime (modification time). +.Pp +.Xr libarchive 3 +provides a high-resolution interface. +The timestamps are truncated automatically depending on the archive format +(for archiving) or the filesystem capabilities (for restoring). +.Pp +All timestamp fields are optional. +The +.Fn XXX_unset +functions can be used to mark the corresponding field as missing. +The current state can be queried using +.Fn XXX_is_set . +Unset time fields have a second and nanosecond field of 0. +.Sh SEE ALSO +.Xr archive 3 , +.Xr archive_entry 3 +.Sh HISTORY +The +.Nm libarchive +library first appeared in +.Fx 5.3 . +.Sh AUTHORS +.An -nosplit +The +.Nm libarchive +library was written by +.An Tim Kientzle Aq kientzle@acm.org . +.\" .Sh BUGS diff --git a/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c index 28b8ff5d4..a3efe7ca8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c +++ b/Utilities/cmlibarchive/libarchive/archive_entry_xattr.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:43 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_xattr.c 201096 2009-12-28 02:41:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -36,17 +36,17 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:4 #include #endif #ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif /* * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. * As the include guards don't agree, the order of include is important. */ #ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* for Linux file flags */ +#include /* for Linux file flags */ #endif #include #include @@ -72,41 +72,41 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry.c,v 1.55 2008/12/23 05:01:4 void archive_entry_xattr_clear(struct archive_entry *entry) { - struct ae_xattr *xp; + struct ae_xattr *xp; - while (entry->xattr_head != NULL) { - xp = entry->xattr_head->next; - free(entry->xattr_head->name); - free(entry->xattr_head->value); - free(entry->xattr_head); - entry->xattr_head = xp; - } + while (entry->xattr_head != NULL) { + xp = entry->xattr_head->next; + free(entry->xattr_head->name); + free(entry->xattr_head->value); + free(entry->xattr_head); + entry->xattr_head = xp; + } - entry->xattr_head = NULL; + entry->xattr_head = NULL; } void archive_entry_xattr_add_entry(struct archive_entry *entry, - const char *name, const void *value, size_t size) + const char *name, const void *value, size_t size) { - struct ae_xattr *xp; + struct ae_xattr *xp; - for (xp = entry->xattr_head; xp != NULL; xp = xp->next) - ; + for (xp = entry->xattr_head; xp != NULL; xp = xp->next) + ; - if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL) - /* XXX Error XXX */ - return; + if ((xp = (struct ae_xattr *)malloc(sizeof(struct ae_xattr))) == NULL) + /* XXX Error XXX */ + return; - xp->name = strdup(name); - if ((xp->value = malloc(size)) != NULL) { - memcpy(xp->value, value, size); - xp->size = size; - } else - xp->size = 0; + xp->name = strdup(name); + if ((xp->value = malloc(size)) != NULL) { + memcpy(xp->value, value, size); + xp->size = size; + } else + xp->size = 0; - xp->next = entry->xattr_head; - entry->xattr_head = xp; + xp->next = entry->xattr_head; + entry->xattr_head = xp; } @@ -116,41 +116,41 @@ archive_entry_xattr_add_entry(struct archive_entry *entry, int archive_entry_xattr_count(struct archive_entry *entry) { - struct ae_xattr *xp; - int count = 0; + struct ae_xattr *xp; + int count = 0; - for (xp = entry->xattr_head; xp != NULL; xp = xp->next) - count++; + for (xp = entry->xattr_head; xp != NULL; xp = xp->next) + count++; - return count; + return count; } int archive_entry_xattr_reset(struct archive_entry * entry) { - entry->xattr_p = entry->xattr_head; + entry->xattr_p = entry->xattr_head; - return archive_entry_xattr_count(entry); + return archive_entry_xattr_count(entry); } int archive_entry_xattr_next(struct archive_entry * entry, - const char **name, const void **value, size_t *size) + const char **name, const void **value, size_t *size) { - if (entry->xattr_p) { - *name = entry->xattr_p->name; - *value = entry->xattr_p->value; - *size = entry->xattr_p->size; - - entry->xattr_p = entry->xattr_p->next; - - return (ARCHIVE_OK); - } else { - *name = NULL; - *value = NULL; - *size = (size_t)0; - return (ARCHIVE_WARN); - } + if (entry->xattr_p) { + *name = entry->xattr_p->name; + *value = entry->xattr_p->value; + *size = entry->xattr_p->size; + + entry->xattr_p = entry->xattr_p->next; + + return (ARCHIVE_OK); + } else { + *name = NULL; + *value = NULL; + *size = (size_t)0; + return (ARCHIVE_WARN); + } } /* diff --git a/Utilities/cmlibarchive/libarchive/archive_haiku.h b/Utilities/cmlibarchive/libarchive/archive_haiku.h deleted file mode 100644 index 17924ac00..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_haiku.h +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 2009 Chris Roberts - * 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 - * in this position and unchanged. - * 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. - * - * $FreeBSD$ - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - - -#ifndef LIBARCHIVE_ARCHIVE_HAIKU_H_INCLUDED -#define LIBARCHIVE_ARCHIVE_HAIKU_H_INCLUDED - -/* Replacement for major/minor/makedev. */ -#define major(x) ((int)(0x00ff & ((x) >> 8))) -#define minor(x) ((int)(0xffff00ff & (x))) -#define makedev(maj,min) ((0xff00 & ((maj)<<8))|(0xffff00ff & (min))) - - -#endif /* LIBARCHIVE_ARCHIVE_HAIKU_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_hash.h b/Utilities/cmlibarchive/libarchive/archive_hash.h deleted file mode 100644 index 0552aae24..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_hash.h +++ /dev/null @@ -1,164 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * 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. - */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -/* - * Hash function support in various Operating Systems: - * - * NetBSD: - * - MD5 and SHA1 in libc: without _ after algorithm name - * - SHA2 in libc: with _ after algorithm name - * - * OpenBSD: - * - MD5, SHA1 and SHA2 in libc: without _ after algorithm name - * - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name - * - * DragonFly and FreeBSD (XXX not used yet): - * - MD5 and SHA1 in libmd: without _ after algorithm name - * - SHA256: with _ after algorithm name - * - * OpenSSL: - * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name - */ - -#if defined(HAVE_MD5_H) && defined(HAVE_MD5INIT) -# include -# define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5Init(ctx) -# define archive_md5_final(ctx, buf) MD5Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_MD5_H) -# include -# define ARCHIVE_HAS_MD5 -typedef MD5_CTX archive_md5_ctx; -# define archive_md5_init(ctx) MD5_Init(ctx) -# define archive_md5_final(ctx, buf) MD5_Final(buf, ctx) -# define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n) -#endif - -#if defined(HAVE_RMD160_H) && defined(HAVE_RMD160INIT) -# include -# define ARCHIVE_HAS_RMD160 -typedef RMD160_CTX archive_rmd160_ctx; -# define archive_rmd160_init(ctx) RMD160Init(ctx) -# define archive_rmd160_final(ctx, buf) RMD160Final(buf, ctx) -# define archive_rmd160_update(ctx, buf, n) RMD160Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_RIPEMD_H) -# include -# define ARCHIVE_HAS_RMD160 -typedef RIPEMD160_CTX archive_rmd160_ctx; -# define archive_rmd160_init(ctx) RIPEMD160_Init(ctx) -# define archive_rmd160_final(ctx, buf) RIPEMD160_Final(buf, ctx) -# define archive_rmd160_update(ctx, buf, n) RIPEMD160_Update(ctx, buf, n) -#endif - -#if defined(HAVE_SHA1_H) && defined(HAVE_SHA1INIT) -# include -# define ARCHIVE_HAS_SHA1 -typedef SHA1_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) -# include -# define ARCHIVE_HAS_SHA1 -typedef SHA_CTX archive_sha1_ctx; -# define archive_sha1_init(ctx) SHA1_Init(ctx) -# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx) -# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n) -#endif - -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA256_INIT) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA256INIT) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_SHA256_INIT) -# include -# define ARCHIVE_HAS_SHA256 -typedef SHA256_CTX archive_sha256_ctx; -# define archive_sha256_init(ctx) SHA256_Init(ctx) -# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx) -# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n) -#endif - -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA384_INIT) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA384_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384_Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA384INIT) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA384_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_SHA384_INIT) -# include -# define ARCHIVE_HAS_SHA384 -typedef SHA512_CTX archive_sha384_ctx; -# define archive_sha384_init(ctx) SHA384_Init(ctx) -# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx) -# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n) -#endif - -#if defined(HAVE_SHA2_H) && defined(HAVE_SHA512_INIT) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA512INIT) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_SHA512_INIT) -# include -# define ARCHIVE_HAS_SHA512 -typedef SHA512_CTX archive_sha512_ctx; -# define archive_sha512_init(ctx) SHA512_Init(ctx) -# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx) -# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n) -#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_options.c b/Utilities/cmlibarchive/libarchive/archive_options.c new file mode 100644 index 000000000..79b4ffbda --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_options.c @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 2011 Tim Kientzle + * 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_options_private.h" + +static const char * +parse_option(const char **str, + const char **mod, const char **opt, const char **val); + +int +_archive_set_option(struct archive *a, + const char *m, const char *o, const char *v, + int magic, const char *fn, option_handler use_option) +{ + const char *mp, *op, *vp; + + archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn); + + mp = m != NULL && m[0] != '\0' ? m : NULL; + op = o != NULL && o[0] != '\0' ? o : NULL; + vp = v != NULL && v[0] != '\0' ? v : NULL; + + if (op == NULL && vp == NULL) + return (ARCHIVE_OK); + if (op == NULL) + return (ARCHIVE_FAILED); + + return use_option(a, mp, op, vp); +} + +int +_archive_set_either_option(struct archive *a, const char *m, const char *o, const char *v, + option_handler use_format_option, option_handler use_filter_option) +{ + int r1, r2; + + if (o == NULL && v == NULL) + return (ARCHIVE_OK); + if (o == NULL) + return (ARCHIVE_FAILED); + + r1 = use_format_option(a, m, o, v); + if (r1 == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + r2 = use_filter_option(a, m, o, v); + if (r2 == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + return r1 > r2 ? r1 : r2; +} + +int +_archive_set_options(struct archive *a, const char *options, + int magic, const char *fn, option_handler use_option) +{ + int allok = 1, anyok = 0, r; + char *data; + const char *s, *mod, *opt, *val; + + archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn); + + if (options == NULL || options[0] == '\0') + return ARCHIVE_OK; + + data = (char *)malloc(strlen(options) + 1); + strcpy(data, options); + s = (const char *)data; + + do { + mod = opt = val = NULL; + + parse_option(&s, &mod, &opt, &val); + + r = use_option(a, mod, opt, val); + if (r == ARCHIVE_FATAL) { + free(data); + return (ARCHIVE_FATAL); + } + if (r == ARCHIVE_OK) + anyok = 1; + else + allok = 0; + } while (s != NULL); + + free(data); + return allok ? ARCHIVE_OK : anyok ? ARCHIVE_WARN : ARCHIVE_FAILED; +} + +static const char * +parse_option(const char **s, const char **m, const char **o, const char **v) +{ + const char *end, *mod, *opt, *val; + char *p; + + end = NULL; + mod = NULL; + opt = *s; + val = "1"; + + p = strchr(opt, ','); + + if (p != NULL) { + *p = '\0'; + end = ((const char *)p) + 1; + } + + if (0 == strlen(opt)) { + *s = end; + *m = NULL; + *o = NULL; + *v = NULL; + return end; + } + + p = strchr(opt, ':'); + if (p != NULL) { + *p = '\0'; + mod = opt; + opt = ++p; + } + + p = strchr(opt, '='); + if (p != NULL) { + *p = '\0'; + val = ++p; + } else if (opt[0] == '!') { + ++opt; + val = NULL; + } + + *s = end; + *m = mod; + *o = opt; + *v = val; + + return end; +} + diff --git a/Utilities/cmlibarchive/cpio/test/test_option_l.c b/Utilities/cmlibarchive/libarchive/archive_options_private.h similarity index 66% rename from Utilities/cmlibarchive/cpio/test/test_option_l.c rename to Utilities/cmlibarchive/libarchive/archive_options_private.h index 899478cad..6ef0165af 100644 --- a/Utilities/cmlibarchive/cpio/test/test_option_l.c +++ b/Utilities/cmlibarchive/libarchive/archive_options_private.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,29 +22,26 @@ * (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 "test.h" + +#include "archive_platform.h" __FBSDID("$FreeBSD$"); -DEFINE_TEST(test_option_l) -{ - int r; +#include "archive_private.h" - /* Create a file. */ - assertMakeFile("f", 0644, "a"); +typedef int (*option_handler)(struct archive *a, + const char *mod, const char *opt, const char *val); - /* Copy the file to the "copy" dir. */ - r = systemf("echo f | %s -pd copy >copy.out 2>copy.err", - testprog); - assertEqualInt(r, 0); +int +_archive_set_option(struct archive *a, + const char *mod, const char *opt, const char *val, + int magic, const char *fn, option_handler use_option); - /* Check that the copy is a true copy and not a link. */ - assertIsNotHardlink("f", "copy/f"); +int +_archive_set_options(struct archive *a, const char *options, + int magic, const char *fn, option_handler use_option); - /* Copy the file to the "link" dir with the -l option. */ - r = systemf("echo f | %s -pld link >link.out 2>link.err", - testprog); - assertEqualInt(r, 0); +int +_archive_set_either_option(struct archive *a, + const char *m, const char *o, const char *v, + option_handler use_format_option, option_handler use_filter_option); - /* Check that this is a link and not a copy. */ - assertIsHardlink("f", "link/f"); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_platform.h b/Utilities/cmlibarchive/libarchive/archive_platform.h index c90057f55..cdd9c7c86 100644 --- a/Utilities/cmlibarchive/libarchive/archive_platform.h +++ b/Utilities/cmlibarchive/libarchive/archive_platform.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_platform.h,v 1.32 2008/12/06 05:53:05 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_platform.h 201090 2009-12-28 02:22:04Z kientzle $ */ /* !!ONLY FOR USE INTERNALLY TO LIBARCHIVE!! */ @@ -36,10 +36,10 @@ */ #ifndef ARCHIVE_PLATFORM_H_INCLUDED -#define ARCHIVE_PLATFORM_H_INCLUDED +#define ARCHIVE_PLATFORM_H_INCLUDED /* archive.h and archive_entry.h require this. */ -#define __LIBARCHIVE_BUILD 1 +#define __LIBARCHIVE_BUILD 1 #if defined(PLATFORM_CONFIG_H) /* Use hand-built config.h in environments that need it. */ @@ -52,14 +52,6 @@ #error Oops: No config.h and no pre-built configuration in archive_platform.h. #endif -/* Try to get standard C99-style integer type definitions. */ -#if HAVE_INTTYPES_H -#include -#endif -#if HAVE_STDINT_H -#include -#endif - /* It should be possible to get rid of this by extending the feature-test * macros to cover Windows API functions, probably along with non-trivial * refactoring of code to find structures that sit more cleanly on top of @@ -68,66 +60,73 @@ #include "archive_windows.h" #endif -#if defined(__HAIKU__) -#include "archive_haiku.h" -#endif - /* * The config files define a lot of feature macros. The following * uses those macros to select/define replacements and include key * headers as required. */ -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ -#define __FBSDID(a) struct _undefined_hack +/* Get a real definition for __FBSDID if we can */ +#if HAVE_SYS_CDEFS_H +#include +#endif + +/* If not, define it so as to avoid dangling semicolons. */ +#ifndef __FBSDID +#define __FBSDID(a) struct _undefined_hack +#endif + +/* Old glibc mbsnrtowcs fails assertions in our use case. */ +#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 1 +# undef HAVE_MBSNRTOWCS +#endif + +/* Try to get standard C99-style integer type definitions. */ +#if HAVE_INTTYPES_H +#include +#endif +#if HAVE_STDINT_H +#include #endif /* Borland warns about its own constants! */ #if defined(__BORLANDC__) # if HAVE_DECL_UINT64_MAX -# undef UINT64_MAX -# undef HAVE_DECL_UINT64_MAX -# define HAVE_DECL_UINT64_MAX 0 +# undef UINT64_MAX +# undef HAVE_DECL_UINT64_MAX # endif # if HAVE_DECL_UINT64_MIN -# undef UINT64_MIN -# undef HAVE_DECL_UINT64_MIN -# define HAVE_DECL_UINT64_MIN 0 +# undef UINT64_MIN +# undef HAVE_DECL_UINT64_MIN # endif # if HAVE_DECL_INT64_MAX -# undef INT64_MAX -# undef HAVE_DECL_INT64_MAX -# define HAVE_DECL_INT64_MAX 0 +# undef INT64_MAX +# undef HAVE_DECL_INT64_MAX # endif # if HAVE_DECL_INT64_MIN -# undef INT64_MIN -# undef HAVE_DECL_INT64_MIN -# define HAVE_DECL_INT64_MIN 0 +# undef INT64_MIN +# undef HAVE_DECL_INT64_MIN # endif #endif /* Some platforms lack the standard *_MAX definitions. */ #if !HAVE_DECL_SIZE_MAX -#define SIZE_MAX (~(size_t)0) +#define SIZE_MAX (~(size_t)0) #endif #if !HAVE_DECL_SSIZE_MAX -#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) +#define SSIZE_MAX ((ssize_t)(SIZE_MAX >> 1)) #endif #if !HAVE_DECL_UINT32_MAX -#define UINT32_MAX (~(uint32_t)0) +#define UINT32_MAX (~(uint32_t)0) #endif #if !HAVE_DECL_UINT64_MAX -#define UINT64_MAX (~(uint64_t)0) +#define UINT64_MAX (~(uint64_t)0) #endif #if !HAVE_DECL_INT64_MAX -#define INT64_MAX ((int64_t)(UINT64_MAX >> 1)) +#define INT64_MAX ((int64_t)(UINT64_MAX >> 1)) #endif #if !HAVE_DECL_INT64_MIN -#define INT64_MIN ((int64_t)(~INT64_MAX)) +#define INT64_MIN ((int64_t)(~INT64_MAX)) #endif /* @@ -136,7 +135,7 @@ * POSIX.1e draft functions used in archive_read_extract.c. */ #if HAVE_SYS_ACL_H && HAVE_ACL_CREATE_ENTRY && HAVE_ACL_INIT && HAVE_ACL_SET_FILE && HAVE_ACL_USER -#define HAVE_POSIX_ACL 1 +#define HAVE_POSIX_ACL 1 #endif /* @@ -144,28 +143,28 @@ * for compatibility's sake, close files before trying to restore metadata. */ #if defined(HAVE_FCHMOD) || defined(HAVE_FUTIMES) || defined(HAVE_ACL_SET_FD) || defined(HAVE_ACL_SET_FD_NP) || defined(HAVE_FCHOWN) -#define CAN_RESTORE_METADATA_FD +#define CAN_RESTORE_METADATA_FD #endif /* Set up defaults for internal error codes. */ #ifndef ARCHIVE_ERRNO_FILE_FORMAT #if HAVE_EFTYPE -#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE +#define ARCHIVE_ERRNO_FILE_FORMAT EFTYPE #else #if HAVE_EILSEQ -#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ +#define ARCHIVE_ERRNO_FILE_FORMAT EILSEQ #else -#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL +#define ARCHIVE_ERRNO_FILE_FORMAT EINVAL #endif #endif #endif #ifndef ARCHIVE_ERRNO_PROGRAMMER -#define ARCHIVE_ERRNO_PROGRAMMER EINVAL +#define ARCHIVE_ERRNO_PROGRAMMER EINVAL #endif #ifndef ARCHIVE_ERRNO_MISC -#define ARCHIVE_ERRNO_MISC (-1) +#define ARCHIVE_ERRNO_MISC (-1) #endif #endif /* !ARCHIVE_PLATFORM_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7.c b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c new file mode 100644 index 000000000..b2e8c3a34 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7.c @@ -0,0 +1,1164 @@ +/* Ppmd7.c -- PPMdH codec +2010-03-12 : Igor Pavlov : Public domain +This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ + +#include "archive_platform.h" + +#include + +#include "archive_ppmd7_private.h" + +#ifdef PPMD_32BIT + #define Ppmd7_GetPtr(p, ptr) (ptr) + #define Ppmd7_GetContext(p, ptr) (ptr) + #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats) +#else + #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs))) + #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs))) + #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats))) +#endif + +#define Ppmd7_GetBinSumm(p) \ + &p->BinSumm[Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \ + p->NS2BSIndx[Ppmd7_GetContext(p, p->MinContext->Suffix)->NumStats - 1] + \ + (p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]) + \ + 2 * p->HB2Flag[Ppmd7Context_OneState(p->MinContext)->Symbol] + \ + ((p->RunLength >> 26) & 0x20)] + +#define kTopValue (1 << 24) +#define MAX_FREQ 124 +#define UNIT_SIZE 12 + +#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE) +#define U2I(nu) (p->Units2Indx[(nu) - 1]) +#define I2U(indx) (p->Indx2Units[indx]) + +#ifdef PPMD_32BIT + #define REF(ptr) (ptr) +#else + #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base)) +#endif + +#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr)) + +#define CTX(ref) ((CPpmd7_Context *)Ppmd7_GetContext(p, ref)) +#define STATS(ctx) Ppmd7_GetStats(p, ctx) +#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx) +#define SUFFIX(ctx) CTX((ctx)->Suffix) + +static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051}; +static const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; + +typedef CPpmd7_Context * CTX_PTR; + +struct CPpmd7_Node_; + +typedef + #ifdef PPMD_32BIT + struct CPpmd7_Node_ * + #else + UInt32 + #endif + CPpmd7_Node_Ref; + +typedef struct CPpmd7_Node_ +{ + UInt16 Stamp; /* must be at offset 0 as CPpmd7_Context::NumStats. Stamp=0 means free */ + UInt16 NU; + CPpmd7_Node_Ref Next; /* must be at offset >= 4 */ + CPpmd7_Node_Ref Prev; +} CPpmd7_Node; + +#ifdef PPMD_32BIT + #define NODE(ptr) (ptr) +#else + #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs))) +#endif + +static void Ppmd7_Update1(CPpmd7 *p); +static void Ppmd7_Update1_0(CPpmd7 *p); +static void Ppmd7_Update2(CPpmd7 *p); +static void Ppmd7_UpdateBin(CPpmd7 *p); +static CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, + UInt32 *scale); + +/* ----------- Base ----------- */ + +static void Ppmd7_Construct(CPpmd7 *p) +{ + unsigned i, k, m; + + p->Base = 0; + + for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++) + { + unsigned step = (i >= 12 ? 4 : (i >> 2) + 1); + do { p->Units2Indx[k++] = (Byte)i; } while(--step); + p->Indx2Units[i] = (Byte)k; + } + + p->NS2BSIndx[0] = (0 << 1); + p->NS2BSIndx[1] = (1 << 1); + memset(p->NS2BSIndx + 2, (2 << 1), 9); + memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11); + + for (i = 0; i < 3; i++) + p->NS2Indx[i] = (Byte)i; + for (m = i, k = 1; i < 256; i++) + { + p->NS2Indx[i] = (Byte)m; + if (--k == 0) + k = (++m) - 2; + } + + memset(p->HB2Flag, 0, 0x40); + memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40); +} + +static void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc) +{ + alloc->Free(alloc, p->Base); + p->Size = 0; + p->Base = 0; +} + +static Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) +{ + if (p->Base == 0 || p->Size != size) + { + Ppmd7_Free(p, alloc); + p->AlignOffset = + #ifdef PPMD_32BIT + (4 - size) & 3; + #else + 4 - (size & 3); + #endif + if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size + #ifndef PPMD_32BIT + + UNIT_SIZE + #endif + )) == 0) + return False; + p->Size = size; + } + return True; +} + +static void InsertNode(CPpmd7 *p, void *node, unsigned indx) +{ + *((CPpmd_Void_Ref *)node) = p->FreeList[indx]; + p->FreeList[indx] = REF(node); +} + +static void *RemoveNode(CPpmd7 *p, unsigned indx) +{ + CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]); + p->FreeList[indx] = *node; + return node; +} + +static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx) +{ + unsigned i, nu = I2U(oldIndx) - I2U(newIndx); + ptr = (Byte *)ptr + U2B(I2U(newIndx)); + if (I2U(i = U2I(nu)) != nu) + { + unsigned k = I2U(--i); + InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1); + } + InsertNode(p, ptr, i); +} + +static void GlueFreeBlocks(CPpmd7 *p) +{ + #ifdef PPMD_32BIT + CPpmd7_Node headItem; + CPpmd7_Node_Ref head = &headItem; + #else + CPpmd7_Node_Ref head = p->AlignOffset + p->Size; + #endif + + CPpmd7_Node_Ref n = head; + unsigned i; + + p->GlueCount = 255; + + /* create doubly-linked list of free blocks */ + for (i = 0; i < PPMD_NUM_INDEXES; i++) + { + UInt16 nu = I2U(i); + CPpmd7_Node_Ref next = (CPpmd7_Node_Ref)p->FreeList[i]; + p->FreeList[i] = 0; + while (next != 0) + { + CPpmd7_Node *node = NODE(next); + node->Next = n; + n = NODE(n)->Prev = next; + next = *(const CPpmd7_Node_Ref *)node; + node->Stamp = 0; + node->NU = (UInt16)nu; + } + } + NODE(head)->Stamp = 1; + NODE(head)->Next = n; + NODE(n)->Prev = head; + if (p->LoUnit != p->HiUnit) + ((CPpmd7_Node *)p->LoUnit)->Stamp = 1; + + /* Glue free blocks */ + while (n != head) + { + CPpmd7_Node *node = NODE(n); + UInt32 nu = (UInt32)node->NU; + for (;;) + { + CPpmd7_Node *node2 = NODE(n) + nu; + nu += node2->NU; + if (node2->Stamp != 0 || nu >= 0x10000) + break; + NODE(node2->Prev)->Next = node2->Next; + NODE(node2->Next)->Prev = node2->Prev; + node->NU = (UInt16)nu; + } + n = node->Next; + } + + /* Fill lists of free blocks */ + for (n = NODE(head)->Next; n != head;) + { + CPpmd7_Node *node = NODE(n); + unsigned nu; + CPpmd7_Node_Ref next = node->Next; + for (nu = node->NU; nu > 128; nu -= 128, node += 128) + InsertNode(p, node, PPMD_NUM_INDEXES - 1); + if (I2U(i = U2I(nu)) != nu) + { + unsigned k = I2U(--i); + InsertNode(p, node + k, nu - k - 1); + } + InsertNode(p, node, i); + n = next; + } +} + +static void *AllocUnitsRare(CPpmd7 *p, unsigned indx) +{ + unsigned i; + void *retVal; + if (p->GlueCount == 0) + { + GlueFreeBlocks(p); + if (p->FreeList[indx] != 0) + return RemoveNode(p, indx); + } + i = indx; + do + { + if (++i == PPMD_NUM_INDEXES) + { + UInt32 numBytes = U2B(I2U(indx)); + p->GlueCount--; + return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL); + } + } + while (p->FreeList[i] == 0); + retVal = RemoveNode(p, i); + SplitBlock(p, retVal, i, indx); + return retVal; +} + +static void *AllocUnits(CPpmd7 *p, unsigned indx) +{ + UInt32 numBytes; + if (p->FreeList[indx] != 0) + return RemoveNode(p, indx); + numBytes = U2B(I2U(indx)); + if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit)) + { + void *retVal = p->LoUnit; + p->LoUnit += numBytes; + return retVal; + } + return AllocUnitsRare(p, indx); +} + +#define MyMem12Cpy(dest, src, num) \ + { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \ + do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); } + +static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU) +{ + unsigned i0 = U2I(oldNU); + unsigned i1 = U2I(newNU); + if (i0 == i1) + return oldPtr; + if (p->FreeList[i1] != 0) + { + void *ptr = RemoveNode(p, i1); + MyMem12Cpy(ptr, oldPtr, newNU); + InsertNode(p, oldPtr, i0); + return ptr; + } + SplitBlock(p, oldPtr, i0, i1); + return oldPtr; +} + +#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16))) + +static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v) +{ + (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF); + (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF); +} + +static void RestartModel(CPpmd7 *p) +{ + unsigned i, k, m; + + memset(p->FreeList, 0, sizeof(p->FreeList)); + p->Text = p->Base + p->AlignOffset; + p->HiUnit = p->Text + p->Size; + p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE; + p->GlueCount = 0; + + p->OrderFall = p->MaxOrder; + p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1; + p->PrevSuccess = 0; + + p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */ + p->MinContext->Suffix = 0; + p->MinContext->NumStats = 256; + p->MinContext->SummFreq = 256 + 1; + p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */ + p->LoUnit += U2B(256 / 2); + p->MinContext->Stats = REF(p->FoundState); + for (i = 0; i < 256; i++) + { + CPpmd_State *s = &p->FoundState[i]; + s->Symbol = (Byte)i; + s->Freq = 1; + SetSuccessor(s, 0); + } + + for (i = 0; i < 128; i++) + for (k = 0; k < 8; k++) + { + UInt16 *dest = p->BinSumm[i] + k; + UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2)); + for (m = 0; m < 64; m += 8) + dest[m] = val; + } + + for (i = 0; i < 25; i++) + for (k = 0; k < 16; k++) + { + CPpmd_See *s = &p->See[i][k]; + s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4)); + s->Count = 4; + } +} + +static void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder) +{ + p->MaxOrder = maxOrder; + RestartModel(p); + p->DummySee.Shift = PPMD_PERIOD_BITS; + p->DummySee.Summ = 0; /* unused */ + p->DummySee.Count = 64; /* unused */ +} + +static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) +{ + CPpmd_State upState; + CTX_PTR c = p->MinContext; + CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); + CPpmd_State *ps[PPMD7_MAX_ORDER]; + unsigned numPs = 0; + + if (!skip) + ps[numPs++] = p->FoundState; + + while (c->Suffix) + { + CPpmd_Void_Ref successor; + CPpmd_State *s; + c = SUFFIX(c); + if (c->NumStats != 1) + { + for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++); + } + else + s = ONE_STATE(c); + successor = SUCCESSOR(s); + if (successor != upBranch) + { + c = CTX(successor); + if (numPs == 0) + return c; + break; + } + ps[numPs++] = s; + } + + upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch); + SetSuccessor(&upState, upBranch + 1); + + if (c->NumStats == 1) + upState.Freq = ONE_STATE(c)->Freq; + else + { + UInt32 cf, s0; + CPpmd_State *s; + for (s = STATS(c); s->Symbol != upState.Symbol; s++); + cf = s->Freq - 1; + s0 = c->SummFreq - c->NumStats - cf; + upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((2 * cf + 3 * s0 - 1) / (2 * s0)))); + } + + do + { + /* Create Child */ + CTX_PTR c1; /* = AllocContext(p); */ + if (p->HiUnit != p->LoUnit) + c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); + else if (p->FreeList[0] != 0) + c1 = (CTX_PTR)RemoveNode(p, 0); + else + { + c1 = (CTX_PTR)AllocUnitsRare(p, 0); + if (!c1) + return NULL; + } + c1->NumStats = 1; + *ONE_STATE(c1) = upState; + c1->Suffix = REF(c); + SetSuccessor(ps[--numPs], REF(c1)); + c = c1; + } + while (numPs != 0); + + return c; +} + +static void SwapStates(CPpmd_State *t1, CPpmd_State *t2) +{ + CPpmd_State tmp = *t1; + *t1 = *t2; + *t2 = tmp; +} + +static void UpdateModel(CPpmd7 *p) +{ + CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState); + CTX_PTR c; + unsigned s0, ns; + + if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0) + { + c = SUFFIX(p->MinContext); + + if (c->NumStats == 1) + { + CPpmd_State *s = ONE_STATE(c); + if (s->Freq < 32) + s->Freq++; + } + else + { + CPpmd_State *s = STATS(c); + if (s->Symbol != p->FoundState->Symbol) + { + do { s++; } while (s->Symbol != p->FoundState->Symbol); + if (s[0].Freq >= s[-1].Freq) + { + SwapStates(&s[0], &s[-1]); + s--; + } + } + if (s->Freq < MAX_FREQ - 9) + { + s->Freq += 2; + c->SummFreq += 2; + } + } + } + + if (p->OrderFall == 0) + { + p->MinContext = p->MaxContext = CreateSuccessors(p, True); + if (p->MinContext == 0) + { + RestartModel(p); + return; + } + SetSuccessor(p->FoundState, REF(p->MinContext)); + return; + } + + *p->Text++ = p->FoundState->Symbol; + successor = REF(p->Text); + if (p->Text >= p->UnitsStart) + { + RestartModel(p); + return; + } + + if (fSuccessor) + { + if (fSuccessor <= successor) + { + CTX_PTR cs = CreateSuccessors(p, False); + if (cs == NULL) + { + RestartModel(p); + return; + } + fSuccessor = REF(cs); + } + if (--p->OrderFall == 0) + { + successor = fSuccessor; + p->Text -= (p->MaxContext != p->MinContext); + } + } + else + { + SetSuccessor(p->FoundState, successor); + fSuccessor = REF(p->MinContext); + } + + s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1); + + for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c)) + { + unsigned ns1; + UInt32 cf, sf; + if ((ns1 = c->NumStats) != 1) + { + if ((ns1 & 1) == 0) + { + /* Expand for one UNIT */ + unsigned oldNU = ns1 >> 1; + unsigned i = U2I(oldNU); + if (i != U2I(oldNU + 1)) + { + void *ptr = AllocUnits(p, i + 1); + void *oldPtr; + if (!ptr) + { + RestartModel(p); + return; + } + oldPtr = STATS(c); + MyMem12Cpy(ptr, oldPtr, oldNU); + InsertNode(p, oldPtr, i); + c->Stats = STATS_REF(ptr); + } + } + c->SummFreq = (UInt16)(c->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) & (c->SummFreq <= 8 * ns1))); + } + else + { + CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0); + if (!s) + { + RestartModel(p); + return; + } + *s = *ONE_STATE(c); + c->Stats = REF(s); + if (s->Freq < MAX_FREQ / 4 - 1) + s->Freq <<= 1; + else + s->Freq = MAX_FREQ - 4; + c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 3)); + } + cf = 2 * (UInt32)p->FoundState->Freq * (c->SummFreq + 6); + sf = (UInt32)s0 + c->SummFreq; + if (cf < 6 * sf) + { + cf = 1 + (cf > sf) + (cf >= 4 * sf); + c->SummFreq += 3; + } + else + { + cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf); + c->SummFreq = (UInt16)(c->SummFreq + cf); + } + { + CPpmd_State *s = STATS(c) + ns1; + SetSuccessor(s, successor); + s->Symbol = p->FoundState->Symbol; + s->Freq = (Byte)cf; + c->NumStats = (UInt16)(ns1 + 1); + } + } + p->MaxContext = p->MinContext = CTX(fSuccessor); +} + +static void Rescale(CPpmd7 *p) +{ + unsigned i, adder, sumFreq, escFreq; + CPpmd_State *stats = STATS(p->MinContext); + CPpmd_State *s = p->FoundState; + { + CPpmd_State tmp = *s; + for (; s != stats; s--) + s[0] = s[-1]; + *s = tmp; + } + escFreq = p->MinContext->SummFreq - s->Freq; + s->Freq += 4; + adder = (p->OrderFall != 0); + s->Freq = (Byte)((s->Freq + adder) >> 1); + sumFreq = s->Freq; + + i = p->MinContext->NumStats - 1; + do + { + escFreq -= (++s)->Freq; + s->Freq = (Byte)((s->Freq + adder) >> 1); + sumFreq += s->Freq; + if (s[0].Freq > s[-1].Freq) + { + CPpmd_State *s1 = s; + CPpmd_State tmp = *s1; + do + s1[0] = s1[-1]; + while (--s1 != stats && tmp.Freq > s1[-1].Freq); + *s1 = tmp; + } + } + while (--i); + + if (s->Freq == 0) + { + unsigned numStats = p->MinContext->NumStats; + unsigned n0, n1; + do { i++; } while ((--s)->Freq == 0); + escFreq += i; + p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i); + if (p->MinContext->NumStats == 1) + { + CPpmd_State tmp = *stats; + do + { + tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1)); + escFreq >>= 1; + } + while (escFreq > 1); + InsertNode(p, stats, U2I(((numStats + 1) >> 1))); + *(p->FoundState = ONE_STATE(p->MinContext)) = tmp; + return; + } + n0 = (numStats + 1) >> 1; + n1 = (p->MinContext->NumStats + 1) >> 1; + if (n0 != n1) + p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1)); + } + p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1)); + p->FoundState = STATS(p->MinContext); +} + +static CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq) +{ + CPpmd_See *see; + unsigned nonMasked = p->MinContext->NumStats - numMasked; + if (p->MinContext->NumStats != 256) + { + see = p->See[p->NS2Indx[nonMasked - 1]] + + (nonMasked < (unsigned)SUFFIX(p->MinContext)->NumStats - p->MinContext->NumStats) + + 2 * (p->MinContext->SummFreq < 11 * p->MinContext->NumStats) + + 4 * (numMasked > nonMasked) + + p->HiBitsFlag; + { + unsigned r = (see->Summ >> see->Shift); + see->Summ = (UInt16)(see->Summ - r); + *escFreq = r + (r == 0); + } + } + else + { + see = &p->DummySee; + *escFreq = 1; + } + return see; +} + +static void NextContext(CPpmd7 *p) +{ + CTX_PTR c = CTX(SUCCESSOR(p->FoundState)); + if (p->OrderFall == 0 && (Byte *)c > p->Text) + p->MinContext = p->MaxContext = c; + else + UpdateModel(p); +} + +static void Ppmd7_Update1(CPpmd7 *p) +{ + CPpmd_State *s = p->FoundState; + s->Freq += 4; + p->MinContext->SummFreq += 4; + if (s[0].Freq > s[-1].Freq) + { + SwapStates(&s[0], &s[-1]); + p->FoundState = --s; + if (s->Freq > MAX_FREQ) + Rescale(p); + } + NextContext(p); +} + +static void Ppmd7_Update1_0(CPpmd7 *p) +{ + p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq); + p->RunLength += p->PrevSuccess; + p->MinContext->SummFreq += 4; + if ((p->FoundState->Freq += 4) > MAX_FREQ) + Rescale(p); + NextContext(p); +} + +static void Ppmd7_UpdateBin(CPpmd7 *p) +{ + p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0)); + p->PrevSuccess = 1; + p->RunLength++; + NextContext(p); +} + +static void Ppmd7_Update2(CPpmd7 *p) +{ + p->MinContext->SummFreq += 4; + if ((p->FoundState->Freq += 4) > MAX_FREQ) + Rescale(p); + p->RunLength = p->InitRL; + UpdateModel(p); +} + +/* ---------- Decode ---------- */ + +static Bool Ppmd_RangeDec_Init(CPpmd7z_RangeDec *p) +{ + unsigned i; + p->Low = p->Bottom = 0; + p->Range = 0xFFFFFFFF; + for (i = 0; i < 4; i++) + p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); + return (p->Code < 0xFFFFFFFF); +} + +static Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) +{ + if (p->Stream->Read((void *)p->Stream) != 0) + return False; + return Ppmd_RangeDec_Init(p); +} + +static Bool PpmdRAR_RangeDec_Init(CPpmd7z_RangeDec *p) +{ + if (!Ppmd_RangeDec_Init(p)) + return False; + p->Bottom = 0x8000; + return True; +} + +static UInt32 Range_GetThreshold(void *pp, UInt32 total) +{ + CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; + return (p->Code - p->Low) / (p->Range /= total); +} + +static void Range_Normalize(CPpmd7z_RangeDec *p) +{ + while (1) + { + if((p->Low ^ (p->Low + p->Range)) >= kTopValue) + { + if(p->Range >= p->Bottom) + break; + else + p->Range = -p->Low & (p->Bottom - 1); + } + p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); + p->Range <<= 8; + p->Low <<= 8; + } +} + +static void Range_Decode_7z(void *pp, UInt32 start, UInt32 size) +{ + CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; + p->Code -= start * p->Range; + p->Range *= size; + Range_Normalize(p); +} + +static void Range_Decode_RAR(void *pp, UInt32 start, UInt32 size) +{ + CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; + p->Low += start * p->Range; + p->Range *= size; + Range_Normalize(p); +} + +static UInt32 Range_DecodeBit_7z(void *pp, UInt32 size0) +{ + CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; + UInt32 newBound = (p->Range >> 14) * size0; + UInt32 symbol; + if (p->Code < newBound) + { + symbol = 0; + p->Range = newBound; + } + else + { + symbol = 1; + p->Code -= newBound; + p->Range -= newBound; + } + Range_Normalize(p); + return symbol; +} + +static UInt32 Range_DecodeBit_RAR(void *pp, UInt32 size0) +{ + CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; + UInt32 bit, value = p->p.GetThreshold(p, PPMD_BIN_SCALE); + if(value < size0) + { + bit = 0; + p->p.Decode(p, 0, size0); + } + else + { + bit = 1; + p->p.Decode(p, size0, PPMD_BIN_SCALE - size0); + } + return bit; +} + +static void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) +{ + p->p.GetThreshold = Range_GetThreshold; + p->p.Decode = Range_Decode_7z; + p->p.DecodeBit = Range_DecodeBit_7z; +} + +static void PpmdRAR_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) +{ + p->p.GetThreshold = Range_GetThreshold; + p->p.Decode = Range_Decode_RAR; + p->p.DecodeBit = Range_DecodeBit_RAR; +} + +#define MASK(sym) ((signed char *)charMask)[sym] + +static int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) +{ + size_t charMask[256 / sizeof(size_t)]; + if (p->MinContext->NumStats != 1) + { + CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); + unsigned i; + UInt32 count, hiCnt; + if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq)) + { + Byte symbol; + rc->Decode(rc, 0, s->Freq); + p->FoundState = s; + symbol = s->Symbol; + Ppmd7_Update1_0(p); + return symbol; + } + p->PrevSuccess = 0; + i = p->MinContext->NumStats - 1; + do + { + if ((hiCnt += (++s)->Freq) > count) + { + Byte symbol; + rc->Decode(rc, hiCnt - s->Freq, s->Freq); + p->FoundState = s; + symbol = s->Symbol; + Ppmd7_Update1(p); + return symbol; + } + } + while (--i); + if (count >= p->MinContext->SummFreq) + return -2; + p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; + rc->Decode(rc, hiCnt, p->MinContext->SummFreq - hiCnt); + PPMD_SetAllBitsIn256Bytes(charMask); + MASK(s->Symbol) = 0; + i = p->MinContext->NumStats - 1; + do { MASK((--s)->Symbol) = 0; } while (--i); + } + else + { + UInt16 *prob = Ppmd7_GetBinSumm(p); + if (rc->DecodeBit(rc, *prob) == 0) + { + Byte symbol; + *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); + symbol = (p->FoundState = Ppmd7Context_OneState(p->MinContext))->Symbol; + Ppmd7_UpdateBin(p); + return symbol; + } + *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); + p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; + PPMD_SetAllBitsIn256Bytes(charMask); + MASK(Ppmd7Context_OneState(p->MinContext)->Symbol) = 0; + p->PrevSuccess = 0; + } + for (;;) + { + CPpmd_State *ps[256], *s; + UInt32 freqSum, count, hiCnt; + CPpmd_See *see; + unsigned i, num, numMasked = p->MinContext->NumStats; + do + { + p->OrderFall++; + if (!p->MinContext->Suffix) + return -1; + p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); + } + while (p->MinContext->NumStats == numMasked); + hiCnt = 0; + s = Ppmd7_GetStats(p, p->MinContext); + i = 0; + num = p->MinContext->NumStats - numMasked; + do + { + int k = (int)(MASK(s->Symbol)); + hiCnt += (s->Freq & k); + ps[i] = s++; + i -= k; + } + while (i != num); + + see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum); + freqSum += hiCnt; + count = rc->GetThreshold(rc, freqSum); + + if (count < hiCnt) + { + Byte symbol; + CPpmd_State **pps = ps; + for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++); + s = *pps; + rc->Decode(rc, hiCnt - s->Freq, s->Freq); + Ppmd_See_Update(see); + p->FoundState = s; + symbol = s->Symbol; + Ppmd7_Update2(p); + return symbol; + } + if (count >= freqSum) + return -2; + rc->Decode(rc, hiCnt, freqSum - hiCnt); + see->Summ = (UInt16)(see->Summ + freqSum); + do { MASK(ps[--i]->Symbol) = 0; } while (i != 0); + } +} + +/* ---------- Encode ---------- Ppmd7Enc.c */ + +#define kTopValue (1 << 24) + +static void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p) +{ + p->Low = 0; + p->Range = 0xFFFFFFFF; + p->Cache = 0; + p->CacheSize = 1; +} + +static void RangeEnc_ShiftLow(CPpmd7z_RangeEnc *p) +{ + if ((UInt32)p->Low < (UInt32)0xFF000000 || (unsigned)(p->Low >> 32) != 0) + { + Byte temp = p->Cache; + do + { + p->Stream->Write(p->Stream, (Byte)(temp + (Byte)(p->Low >> 32))); + temp = 0xFF; + } + while(--p->CacheSize != 0); + p->Cache = (Byte)((UInt32)p->Low >> 24); + } + p->CacheSize++; + p->Low = (UInt32)p->Low << 8; +} + +static void RangeEnc_Encode(CPpmd7z_RangeEnc *p, UInt32 start, UInt32 size, UInt32 total) +{ + p->Low += start * (p->Range /= total); + p->Range *= size; + while (p->Range < kTopValue) + { + p->Range <<= 8; + RangeEnc_ShiftLow(p); + } +} + +static void RangeEnc_EncodeBit_0(CPpmd7z_RangeEnc *p, UInt32 size0) +{ + p->Range = (p->Range >> 14) * size0; + while (p->Range < kTopValue) + { + p->Range <<= 8; + RangeEnc_ShiftLow(p); + } +} + +static void RangeEnc_EncodeBit_1(CPpmd7z_RangeEnc *p, UInt32 size0) +{ + UInt32 newBound = (p->Range >> 14) * size0; + p->Low += newBound; + p->Range -= newBound; + while (p->Range < kTopValue) + { + p->Range <<= 8; + RangeEnc_ShiftLow(p); + } +} + +static void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p) +{ + unsigned i; + for (i = 0; i < 5; i++) + RangeEnc_ShiftLow(p); +} + + +#define MASK(sym) ((signed char *)charMask)[sym] + +static void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol) +{ + size_t charMask[256 / sizeof(size_t)]; + if (p->MinContext->NumStats != 1) + { + CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); + UInt32 sum; + unsigned i; + if (s->Symbol == symbol) + { + RangeEnc_Encode(rc, 0, s->Freq, p->MinContext->SummFreq); + p->FoundState = s; + Ppmd7_Update1_0(p); + return; + } + p->PrevSuccess = 0; + sum = s->Freq; + i = p->MinContext->NumStats - 1; + do + { + if ((++s)->Symbol == symbol) + { + RangeEnc_Encode(rc, sum, s->Freq, p->MinContext->SummFreq); + p->FoundState = s; + Ppmd7_Update1(p); + return; + } + sum += s->Freq; + } + while (--i); + + p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol]; + PPMD_SetAllBitsIn256Bytes(charMask); + MASK(s->Symbol) = 0; + i = p->MinContext->NumStats - 1; + do { MASK((--s)->Symbol) = 0; } while (--i); + RangeEnc_Encode(rc, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq); + } + else + { + UInt16 *prob = Ppmd7_GetBinSumm(p); + CPpmd_State *s = Ppmd7Context_OneState(p->MinContext); + if (s->Symbol == symbol) + { + RangeEnc_EncodeBit_0(rc, *prob); + *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob); + p->FoundState = s; + Ppmd7_UpdateBin(p); + return; + } + else + { + RangeEnc_EncodeBit_1(rc, *prob); + *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob); + p->InitEsc = PPMD7_kExpEscape[*prob >> 10]; + PPMD_SetAllBitsIn256Bytes(charMask); + MASK(s->Symbol) = 0; + p->PrevSuccess = 0; + } + } + for (;;) + { + UInt32 escFreq; + CPpmd_See *see; + CPpmd_State *s; + UInt32 sum; + unsigned i, numMasked = p->MinContext->NumStats; + do + { + p->OrderFall++; + if (!p->MinContext->Suffix) + return; /* EndMarker (symbol = -1) */ + p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix); + } + while (p->MinContext->NumStats == numMasked); + + see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq); + s = Ppmd7_GetStats(p, p->MinContext); + sum = 0; + i = p->MinContext->NumStats; + do + { + int cur = s->Symbol; + if (cur == symbol) + { + UInt32 low = sum; + CPpmd_State *s1 = s; + do + { + sum += (s->Freq & (int)(MASK(s->Symbol))); + s++; + } + while (--i); + RangeEnc_Encode(rc, low, s1->Freq, sum + escFreq); + Ppmd_See_Update(see); + p->FoundState = s1; + Ppmd7_Update2(p); + return; + } + sum += (s->Freq & (int)(MASK(cur))); + MASK(cur) = 0; + s++; + } + while (--i); + + RangeEnc_Encode(rc, sum, escFreq, sum + escFreq); + see->Summ = (UInt16)(see->Summ + sum + escFreq); + } +} + +const IPpmd7 __archive_ppmd7_functions = +{ + &Ppmd7_Construct, + &Ppmd7_Alloc, + &Ppmd7_Free, + &Ppmd7_Init, + &Ppmd7z_RangeDec_CreateVTable, + &PpmdRAR_RangeDec_CreateVTable, + &Ppmd7z_RangeDec_Init, + &PpmdRAR_RangeDec_Init, + &Ppmd7_DecodeSymbol, + &Ppmd7z_RangeEnc_Init, + &Ppmd7z_RangeEnc_FlushData, + &Ppmd7_EncodeSymbol +}; diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h new file mode 100644 index 000000000..3a6b9eb41 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_ppmd7_private.h @@ -0,0 +1,119 @@ +/* Ppmd7.h -- PPMdH compression codec +2010-03-12 : Igor Pavlov : Public domain +This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ + +/* This code supports virtual RangeDecoder and includes the implementation +of RangeCoder from 7z, instead of RangeCoder from original PPMd var.H. +If you need the compatibility with original PPMd var.H, you can use external RangeDecoder */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_PPMD7_PRIVATE_H_INCLUDED +#define ARCHIVE_PPMD7_PRIVATE_H_INCLUDED + +#include "archive_ppmd_private.h" + +#define PPMD7_MIN_ORDER 2 +#define PPMD7_MAX_ORDER 64 + +#define PPMD7_MIN_MEM_SIZE (1 << 11) +#define PPMD7_MAX_MEM_SIZE (0xFFFFFFFF - 12 * 3) + +struct CPpmd7_Context_; + +typedef + #ifdef PPMD_32BIT + struct CPpmd7_Context_ * + #else + UInt32 + #endif + CPpmd7_Context_Ref; + +typedef struct CPpmd7_Context_ +{ + UInt16 NumStats; + UInt16 SummFreq; + CPpmd_State_Ref Stats; + CPpmd7_Context_Ref Suffix; +} CPpmd7_Context; + +#define Ppmd7Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq) + +typedef struct +{ + CPpmd7_Context *MinContext, *MaxContext; + CPpmd_State *FoundState; + unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; + Int32 RunLength, InitRL; /* must be 32-bit at least */ + + UInt32 Size; + UInt32 GlueCount; + Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart; + UInt32 AlignOffset; + + Byte Indx2Units[PPMD_NUM_INDEXES]; + Byte Units2Indx[128]; + CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES]; + Byte NS2Indx[256], NS2BSIndx[256], HB2Flag[256]; + CPpmd_See DummySee, See[25][16]; + UInt16 BinSumm[128][64]; +} CPpmd7; + +/* ---------- Decode ---------- */ + +typedef struct +{ + UInt32 (*GetThreshold)(void *p, UInt32 total); + void (*Decode)(void *p, UInt32 start, UInt32 size); + UInt32 (*DecodeBit)(void *p, UInt32 size0); +} IPpmd7_RangeDec; + +typedef struct +{ + IPpmd7_RangeDec p; + UInt32 Range; + UInt32 Code; + UInt32 Low; + UInt32 Bottom; + IByteIn *Stream; +} CPpmd7z_RangeDec; + +/* ---------- Encode ---------- */ + +typedef struct +{ + UInt64 Low; + UInt32 Range; + Byte Cache; + UInt64 CacheSize; + IByteOut *Stream; +} CPpmd7z_RangeEnc; + +typedef struct +{ + /* Base Functions */ + void (*Ppmd7_Construct)(CPpmd7 *p); + Bool (*Ppmd7_Alloc)(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); + void (*Ppmd7_Free)(CPpmd7 *p, ISzAlloc *alloc); + void (*Ppmd7_Init)(CPpmd7 *p, unsigned maxOrder); + #define Ppmd7_WasAllocated(p) ((p)->Base != NULL) + + /* Decode Functions */ + void (*Ppmd7z_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); + void (*PpmdRAR_RangeDec_CreateVTable)(CPpmd7z_RangeDec *p); + Bool (*Ppmd7z_RangeDec_Init)(CPpmd7z_RangeDec *p); + Bool (*PpmdRAR_RangeDec_Init)(CPpmd7z_RangeDec *p); + #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) + int (*Ppmd7_DecodeSymbol)(CPpmd7 *p, IPpmd7_RangeDec *rc); + + /* Encode Functions */ + void (*Ppmd7z_RangeEnc_Init)(CPpmd7z_RangeEnc *p); + void (*Ppmd7z_RangeEnc_FlushData)(CPpmd7z_RangeEnc *p); + + void (*Ppmd7_EncodeSymbol)(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); +} IPpmd7; + +extern const IPpmd7 __archive_ppmd7_functions; +#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h new file mode 100644 index 000000000..266676878 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_ppmd_private.h @@ -0,0 +1,158 @@ +/* Ppmd.h -- PPMD codec common code +2010-03-12 : Igor Pavlov : Public domain +This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_PPMD_PRIVATE_H_INCLUDED +#define ARCHIVE_PPMD_PRIVATE_H_INCLUDED + +#include + +#include "archive_read_private.h" + +/*** Begin defined in Types.h ***/ + +#if !defined(ZCONF_H) +typedef unsigned char Byte; +#endif +typedef short Int16; +typedef unsigned short UInt16; + +#ifdef _LZMA_UINT32_IS_ULONG +typedef long Int32; +typedef unsigned long UInt32; +#else +typedef int Int32; +typedef unsigned int UInt32; +#endif + +#ifdef _SZ_NO_INT_64 + +/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. + NOTES: Some code will work incorrectly in that case! */ + +typedef long Int64; +typedef unsigned long UInt64; + +#else + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef __int64 Int64; +typedef unsigned __int64 UInt64; +#define UINT64_CONST(n) n +#else +typedef long long int Int64; +typedef unsigned long long int UInt64; +#define UINT64_CONST(n) n ## ULL +#endif + +#endif + +typedef int Bool; +#define True 1 +#define False 0 + +/* The following interfaces use first parameter as pointer to structure */ + +typedef struct +{ + struct archive_read *a; + Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ +} IByteIn; + +typedef struct +{ + struct archive_write *a; + void (*Write)(void *p, Byte b); +} IByteOut; + + +typedef struct +{ + void *(*Alloc)(void *p, size_t size); + void (*Free)(void *p, void *address); /* address can be 0 */ +} ISzAlloc; + +/*** End defined in Types.h ***/ +/*** Begin defined in CpuArch.h ***/ + +#if defined(_M_IX86) || defined(__i386__) +#define MY_CPU_X86 +#endif + +#if defined(MY_CPU_X86) || defined(_M_ARM) +#define MY_CPU_32BIT +#endif + +#ifdef MY_CPU_32BIT +#define PPMD_32BIT +#endif + +/*** End defined in CpuArch.h ***/ + +#define PPMD_INT_BITS 7 +#define PPMD_PERIOD_BITS 7 +#define PPMD_BIN_SCALE (1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS)) + +#define PPMD_GET_MEAN_SPEC(summ, shift, round) (((summ) + (1 << ((shift) - (round)))) >> (shift)) +#define PPMD_GET_MEAN(summ) PPMD_GET_MEAN_SPEC((summ), PPMD_PERIOD_BITS, 2) +#define PPMD_UPDATE_PROB_0(prob) ((prob) + (1 << PPMD_INT_BITS) - PPMD_GET_MEAN(prob)) +#define PPMD_UPDATE_PROB_1(prob) ((prob) - PPMD_GET_MEAN(prob)) + +#define PPMD_N1 4 +#define PPMD_N2 4 +#define PPMD_N3 4 +#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4) +#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4) + +/* SEE-contexts for PPM-contexts with masked symbols */ +typedef struct +{ + UInt16 Summ; /* Freq */ + Byte Shift; /* Speed of Freq change; low Shift is for fast change */ + Byte Count; /* Count to next change of Shift */ +} CPpmd_See; + +#define Ppmd_See_Update(p) if ((p)->Shift < PPMD_PERIOD_BITS && --(p)->Count == 0) \ + { (p)->Summ <<= 1; (p)->Count = (Byte)(3 << (p)->Shift++); } + +typedef struct +{ + Byte Symbol; + Byte Freq; + UInt16 SuccessorLow; + UInt16 SuccessorHigh; +} CPpmd_State; + +typedef + #ifdef PPMD_32BIT + CPpmd_State * + #else + UInt32 + #endif + CPpmd_State_Ref; + +typedef + #ifdef PPMD_32BIT + void * + #else + UInt32 + #endif + CPpmd_Void_Ref; + +typedef + #ifdef PPMD_32BIT + Byte * + #else + UInt32 + #endif + CPpmd_Byte_Ref; + +#define PPMD_SetAllBitsIn256Bytes(p) \ + { unsigned i; for (i = 0; i < 256 / sizeof(p[0]); i += 8) { \ + p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }} + +#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_private.h b/Utilities/cmlibarchive/libarchive/archive_private.h index 7a023e07a..9941e9661 100644 --- a/Utilities/cmlibarchive/libarchive/archive_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_private.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_private.h,v 1.32 2008/12/06 06:23:37 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_private.h 201098 2009-12-28 02:58:14Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -30,104 +30,121 @@ #endif #ifndef ARCHIVE_PRIVATE_H_INCLUDED -#define ARCHIVE_PRIVATE_H_INCLUDED +#define ARCHIVE_PRIVATE_H_INCLUDED -#include "archive.h" -#include "archive_string.h" - -#if defined(__BORLANDC__) -# pragma warn -8004 /* Assigned value never used. */ -# pragma warn -8008 /* Condition is always true/false. */ -# pragma warn -8012 /* Compare signed/unsigned. */ -# pragma warn -8053 /* Called function is obsolete. */ -# pragma warn -8057 /* Unused parameter. */ -# pragma warn -8060 /* Possibly incorrect assignment. */ -# pragma warn -8065 /* Call to function without prototype. */ -# pragma warn -8066 /* Unreachable code. */ -# pragma warn -8068 /* Constant out of range in comparison. */ -# pragma warn -8072 /* Suspicious pointer arithmetic. */ +#if HAVE_ICONV_H +#include #endif -#if defined(_MSC_VER) -# pragma warning (push,1) -#endif +#include "archive.h" +#include "archive_string.h" #if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) + (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) +#define __LA_DEAD __attribute__((__noreturn__)) #else -#define __LA_DEAD +#define __LA_DEAD #endif -#define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) -#define ARCHIVE_READ_MAGIC (0xdeb0c5U) -#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) -#define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U) +#define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) +#define ARCHIVE_READ_MAGIC (0xdeb0c5U) +#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) +#define ARCHIVE_READ_DISK_MAGIC (0xbadb0c5U) -#define ARCHIVE_STATE_ANY 0xFFFFU -#define ARCHIVE_STATE_NEW 1U -#define ARCHIVE_STATE_HEADER 2U -#define ARCHIVE_STATE_DATA 4U -#define ARCHIVE_STATE_DATA_END 8U -#define ARCHIVE_STATE_EOF 0x10U -#define ARCHIVE_STATE_CLOSED 0x20U -#define ARCHIVE_STATE_FATAL 0x8000U +#define ARCHIVE_STATE_NEW 1U +#define ARCHIVE_STATE_HEADER 2U +#define ARCHIVE_STATE_DATA 4U +#define ARCHIVE_STATE_EOF 0x10U +#define ARCHIVE_STATE_CLOSED 0x20U +#define ARCHIVE_STATE_FATAL 0x8000U +#define ARCHIVE_STATE_ANY (0xFFFFU & ~ARCHIVE_STATE_FATAL) struct archive_vtable { - int (*archive_close)(struct archive *); - int (*archive_finish)(struct archive *); - int (*archive_write_header)(struct archive *, - struct archive_entry *); - int (*archive_write_finish_entry)(struct archive *); - ssize_t (*archive_write_data)(struct archive *, - const void *, size_t); - ssize_t (*archive_write_data_block)(struct archive *, - const void *, size_t, off_t); + int (*archive_close)(struct archive *); + int (*archive_free)(struct archive *); + int (*archive_write_header)(struct archive *, + struct archive_entry *); + int (*archive_write_finish_entry)(struct archive *); + ssize_t (*archive_write_data)(struct archive *, + const void *, size_t); + ssize_t (*archive_write_data_block)(struct archive *, + const void *, size_t, int64_t); + + int (*archive_read_next_header)(struct archive *, + struct archive_entry **); + int (*archive_read_next_header2)(struct archive *, + struct archive_entry *); + int (*archive_read_data_block)(struct archive *, + const void **, size_t *, int64_t *); + + int (*archive_filter_count)(struct archive *); + int64_t (*archive_filter_bytes)(struct archive *, int); + int (*archive_filter_code)(struct archive *, int); + const char * (*archive_filter_name)(struct archive *, int); }; +struct archive_string_conv; + struct archive { - /* - * The magic/state values are used to sanity-check the - * client's usage. If an API function is called at a - * ridiculous time, or the client passes us an invalid - * pointer, these values allow me to catch that. - */ - unsigned int magic; - unsigned int state; - - /* - * Some public API functions depend on the "real" type of the - * archive object. - */ - struct archive_vtable *vtable; - - int archive_format; - const char *archive_format_name; - - int compression_code; /* Currently active compression. */ - const char *compression_name; - - /* Position in UNCOMPRESSED data stream. */ - int64_t file_position; - /* Position in COMPRESSED data stream. */ - int64_t raw_position; - /* Number of file entries processed. */ - int file_count; - - int archive_error_number; - const char *error; - struct archive_string error_string; + /* + * The magic/state values are used to sanity-check the + * client's usage. If an API function is called at a + * ridiculous time, or the client passes us an invalid + * pointer, these values allow me to catch that. + */ + unsigned int magic; + unsigned int state; + + /* + * Some public API functions depend on the "real" type of the + * archive object. + */ + struct archive_vtable *vtable; + + int archive_format; + const char *archive_format_name; + + int compression_code; /* Currently active compression. */ + const char *compression_name; + + /* Number of file entries processed. */ + int file_count; + + int archive_error_number; + const char *error; + struct archive_string error_string; + + char *current_code; + unsigned current_codepage; /* Current ACP(ANSI CodePage). */ + unsigned current_oemcp; /* Current OEMCP(OEM CodePage). */ + struct archive_string_conv *sconv; }; -/* Check magic value and state; exit if it isn't valid. */ -void __archive_check_magic(struct archive *, unsigned int magic, - unsigned int state, const char *func); +/* Check magic value and state; return(ARCHIVE_FATAL) if it isn't valid. */ +int __archive_check_magic(struct archive *, unsigned int magic, + unsigned int state, const char *func); +#define archive_check_magic(a, expected_magic, allowed_states, function_name) \ + do { \ + int magic_test = __archive_check_magic((a), (expected_magic), \ + (allowed_states), (function_name)); \ + if (magic_test == ARCHIVE_FATAL) \ + return ARCHIVE_FATAL; \ + } while (0) + +void __archive_errx(int retvalue, const char *msg) __LA_DEAD; + +int __archive_mktemp(const char *tmpdir); -void __archive_errx(int retvalue, const char *msg) __LA_DEAD; +int __archive_clean(struct archive *); -int __archive_parse_options(const char *p, const char *fn, - int keysize, char *key, int valsize, char *val); +#define err_combine(a,b) ((a) < (b) ? (a) : (b)) -#define err_combine(a,b) ((a) < (b) ? (a) : (b)) +#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) +# define ARCHIVE_LITERAL_LL(x) x##i64 +# define ARCHIVE_LITERAL_ULL(x) x##ui64 +#else +# define ARCHIVE_LITERAL_LL(x) x##ll +# define ARCHIVE_LITERAL_ULL(x) x##ull +#endif #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_rb.c b/Utilities/cmlibarchive/libarchive/archive_rb.c new file mode 100644 index 000000000..f8035d9df --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_rb.c @@ -0,0 +1,701 @@ +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas . + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Based on: NetBSD: rb.c,v 1.6 2010/04/30 13:58:09 joerg Exp + */ + +#include "archive_platform.h" + +#include + +#include "archive_rb.h" + +/* Keep in sync with archive_rb.h */ +#define RB_DIR_LEFT 0 +#define RB_DIR_RIGHT 1 +#define RB_DIR_OTHER 1 +#define rb_left rb_nodes[RB_DIR_LEFT] +#define rb_right rb_nodes[RB_DIR_RIGHT] + +#define RB_FLAG_POSITION 0x2 +#define RB_FLAG_RED 0x1 +#define RB_FLAG_MASK (RB_FLAG_POSITION|RB_FLAG_RED) +#define RB_FATHER(rb) \ + ((struct archive_rb_node *)((rb)->rb_info & ~RB_FLAG_MASK)) +#define RB_SET_FATHER(rb, father) \ + ((void)((rb)->rb_info = (uintptr_t)(father)|((rb)->rb_info & RB_FLAG_MASK))) + +#define RB_SENTINEL_P(rb) ((rb) == NULL) +#define RB_LEFT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_left) +#define RB_RIGHT_SENTINEL_P(rb) RB_SENTINEL_P((rb)->rb_right) +#define RB_FATHER_SENTINEL_P(rb) RB_SENTINEL_P(RB_FATHER((rb))) +#define RB_CHILDLESS_P(rb) \ + (RB_SENTINEL_P(rb) || (RB_LEFT_SENTINEL_P(rb) && RB_RIGHT_SENTINEL_P(rb))) +#define RB_TWOCHILDREN_P(rb) \ + (!RB_SENTINEL_P(rb) && !RB_LEFT_SENTINEL_P(rb) && !RB_RIGHT_SENTINEL_P(rb)) + +#define RB_POSITION(rb) \ + (((rb)->rb_info & RB_FLAG_POSITION) ? RB_DIR_RIGHT : RB_DIR_LEFT) +#define RB_RIGHT_P(rb) (RB_POSITION(rb) == RB_DIR_RIGHT) +#define RB_LEFT_P(rb) (RB_POSITION(rb) == RB_DIR_LEFT) +#define RB_RED_P(rb) (!RB_SENTINEL_P(rb) && ((rb)->rb_info & RB_FLAG_RED) != 0) +#define RB_BLACK_P(rb) (RB_SENTINEL_P(rb) || ((rb)->rb_info & RB_FLAG_RED) == 0) +#define RB_MARK_RED(rb) ((void)((rb)->rb_info |= RB_FLAG_RED)) +#define RB_MARK_BLACK(rb) ((void)((rb)->rb_info &= ~RB_FLAG_RED)) +#define RB_INVERT_COLOR(rb) ((void)((rb)->rb_info ^= RB_FLAG_RED)) +#define RB_ROOT_P(rbt, rb) ((rbt)->rbt_root == (rb)) +#define RB_SET_POSITION(rb, position) \ + ((void)((position) ? ((rb)->rb_info |= RB_FLAG_POSITION) : \ + ((rb)->rb_info &= ~RB_FLAG_POSITION))) +#define RB_ZERO_PROPERTIES(rb) ((void)((rb)->rb_info &= ~RB_FLAG_MASK)) +#define RB_COPY_PROPERTIES(dst, src) \ + ((void)((dst)->rb_info ^= ((dst)->rb_info ^ (src)->rb_info) & RB_FLAG_MASK)) +#define RB_SWAP_PROPERTIES(a, b) do { \ + uintptr_t xorinfo = ((a)->rb_info ^ (b)->rb_info) & RB_FLAG_MASK; \ + (a)->rb_info ^= xorinfo; \ + (b)->rb_info ^= xorinfo; \ + } while (/*CONSTCOND*/ 0) + +static void __archive_rb_tree_insert_rebalance(struct archive_rb_tree *, + struct archive_rb_node *); +static void __archive_rb_tree_removal_rebalance(struct archive_rb_tree *, + struct archive_rb_node *, unsigned int); + +#define RB_SENTINEL_NODE NULL + +#define T 1 +#define F 0 + +void +__archive_rb_tree_init(struct archive_rb_tree *rbt, + const struct archive_rb_tree_ops *ops) +{ + rbt->rbt_ops = ops; + *((const struct archive_rb_node **)&rbt->rbt_root) = RB_SENTINEL_NODE; +} + +struct archive_rb_node * +__archive_rb_tree_find_node(struct archive_rb_tree *rbt, const void *key) +{ + archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key; + struct archive_rb_node *parent = rbt->rbt_root; + + while (!RB_SENTINEL_P(parent)) { + const signed int diff = (*compare_key)(parent, key); + if (diff == 0) + return parent; + parent = parent->rb_nodes[diff > 0]; + } + + return NULL; +} + +struct archive_rb_node * +__archive_rb_tree_find_node_geq(struct archive_rb_tree *rbt, const void *key) +{ + archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key; + struct archive_rb_node *parent = rbt->rbt_root; + struct archive_rb_node *last = NULL; + + while (!RB_SENTINEL_P(parent)) { + const signed int diff = (*compare_key)(parent, key); + if (diff == 0) + return parent; + if (diff < 0) + last = parent; + parent = parent->rb_nodes[diff > 0]; + } + + return last; +} + +struct archive_rb_node * +__archive_rb_tree_find_node_leq(struct archive_rb_tree *rbt, const void *key) +{ + archive_rbto_compare_key_fn compare_key = rbt->rbt_ops->rbto_compare_key; + struct archive_rb_node *parent = rbt->rbt_root; + struct archive_rb_node *last = NULL; + + while (!RB_SENTINEL_P(parent)) { + const signed int diff = (*compare_key)(parent, key); + if (diff == 0) + return parent; + if (diff > 0) + last = parent; + parent = parent->rb_nodes[diff > 0]; + } + + return last; +} + +int +__archive_rb_tree_insert_node(struct archive_rb_tree *rbt, + struct archive_rb_node *self) +{ + archive_rbto_compare_nodes_fn compare_nodes = rbt->rbt_ops->rbto_compare_nodes; + struct archive_rb_node *parent, *tmp; + unsigned int position; + int rebalance; + + tmp = rbt->rbt_root; + /* + * This is a hack. Because rbt->rbt_root is just a + * struct archive_rb_node *, just like rb_node->rb_nodes[RB_DIR_LEFT], + * we can use this fact to avoid a lot of tests for root and know + * that even at root, updating + * RB_FATHER(rb_node)->rb_nodes[RB_POSITION(rb_node)] will + * update rbt->rbt_root. + */ + parent = (struct archive_rb_node *)(void *)&rbt->rbt_root; + position = RB_DIR_LEFT; + + /* + * Find out where to place this new leaf. + */ + while (!RB_SENTINEL_P(tmp)) { + const signed int diff = (*compare_nodes)(tmp, self); + if (diff == 0) { + /* + * Node already exists; don't insert. + */ + return F; + } + parent = tmp; + position = (diff > 0); + tmp = parent->rb_nodes[position]; + } + + /* + * Initialize the node and insert as a leaf into the tree. + */ + RB_SET_FATHER(self, parent); + RB_SET_POSITION(self, position); + if (parent == (struct archive_rb_node *)(void *)&rbt->rbt_root) { + RB_MARK_BLACK(self); /* root is always black */ + rebalance = F; + } else { + /* + * All new nodes are colored red. We only need to rebalance + * if our parent is also red. + */ + RB_MARK_RED(self); + rebalance = RB_RED_P(parent); + } + self->rb_left = parent->rb_nodes[position]; + self->rb_right = parent->rb_nodes[position]; + parent->rb_nodes[position] = self; + + /* + * Rebalance tree after insertion + */ + if (rebalance) + __archive_rb_tree_insert_rebalance(rbt, self); + + return T; +} + +/* + * Swap the location and colors of 'self' and its child @ which. The child + * can not be a sentinel node. This is our rotation function. However, + * since it preserves coloring, it great simplifies both insertion and + * removal since rotation almost always involves the exchanging of colors + * as a separate step. + */ +/*ARGSUSED*/ +static void +__archive_rb_tree_reparent_nodes( + struct archive_rb_node *old_father, const unsigned int which) +{ + const unsigned int other = which ^ RB_DIR_OTHER; + struct archive_rb_node * const grandpa = RB_FATHER(old_father); + struct archive_rb_node * const old_child = old_father->rb_nodes[which]; + struct archive_rb_node * const new_father = old_child; + struct archive_rb_node * const new_child = old_father; + + /* + * Exchange descendant linkages. + */ + grandpa->rb_nodes[RB_POSITION(old_father)] = new_father; + new_child->rb_nodes[which] = old_child->rb_nodes[other]; + new_father->rb_nodes[other] = new_child; + + /* + * Update ancestor linkages + */ + RB_SET_FATHER(new_father, grandpa); + RB_SET_FATHER(new_child, new_father); + + /* + * Exchange properties between new_father and new_child. The only + * change is that new_child's position is now on the other side. + */ + RB_SWAP_PROPERTIES(new_father, new_child); + RB_SET_POSITION(new_child, other); + + /* + * Make sure to reparent the new child to ourself. + */ + if (!RB_SENTINEL_P(new_child->rb_nodes[which])) { + RB_SET_FATHER(new_child->rb_nodes[which], new_child); + RB_SET_POSITION(new_child->rb_nodes[which], which); + } + +} + +static void +__archive_rb_tree_insert_rebalance(struct archive_rb_tree *rbt, + struct archive_rb_node *self) +{ + struct archive_rb_node * father = RB_FATHER(self); + struct archive_rb_node * grandpa; + struct archive_rb_node * uncle; + unsigned int which; + unsigned int other; + + for (;;) { + /* + * We are red and our parent is red, therefore we must have a + * grandfather and he must be black. + */ + grandpa = RB_FATHER(father); + which = (father == grandpa->rb_right); + other = which ^ RB_DIR_OTHER; + uncle = grandpa->rb_nodes[other]; + + if (RB_BLACK_P(uncle)) + break; + + /* + * Case 1: our uncle is red + * Simply invert the colors of our parent and + * uncle and make our grandparent red. And + * then solve the problem up at his level. + */ + RB_MARK_BLACK(uncle); + RB_MARK_BLACK(father); + if (RB_ROOT_P(rbt, grandpa)) { + /* + * If our grandpa is root, don't bother + * setting him to red, just return. + */ + return; + } + RB_MARK_RED(grandpa); + self = grandpa; + father = RB_FATHER(self); + if (RB_BLACK_P(father)) { + /* + * If our greatgrandpa is black, we're done. + */ + return; + } + } + + /* + * Case 2&3: our uncle is black. + */ + if (self == father->rb_nodes[other]) { + /* + * Case 2: we are on the same side as our uncle + * Swap ourselves with our parent so this case + * becomes case 3. Basically our parent becomes our + * child. + */ + __archive_rb_tree_reparent_nodes(father, other); + } + /* + * Case 3: we are opposite a child of a black uncle. + * Swap our parent and grandparent. Since our grandfather + * is black, our father will become black and our new sibling + * (former grandparent) will become red. + */ + __archive_rb_tree_reparent_nodes(grandpa, which); + + /* + * Final step: Set the root to black. + */ + RB_MARK_BLACK(rbt->rbt_root); +} + +static void +__archive_rb_tree_prune_node(struct archive_rb_tree *rbt, + struct archive_rb_node *self, int rebalance) +{ + const unsigned int which = RB_POSITION(self); + struct archive_rb_node *father = RB_FATHER(self); + + /* + * Since we are childless, we know that self->rb_left is pointing + * to the sentinel node. + */ + father->rb_nodes[which] = self->rb_left; + + /* + * Rebalance if requested. + */ + if (rebalance) + __archive_rb_tree_removal_rebalance(rbt, father, which); +} + +/* + * When deleting an interior node + */ +static void +__archive_rb_tree_swap_prune_and_rebalance(struct archive_rb_tree *rbt, + struct archive_rb_node *self, struct archive_rb_node *standin) +{ + const unsigned int standin_which = RB_POSITION(standin); + unsigned int standin_other = standin_which ^ RB_DIR_OTHER; + struct archive_rb_node *standin_son; + struct archive_rb_node *standin_father = RB_FATHER(standin); + int rebalance = RB_BLACK_P(standin); + + if (standin_father == self) { + /* + * As a child of self, any childen would be opposite of + * our parent. + */ + standin_son = standin->rb_nodes[standin_which]; + } else { + /* + * Since we aren't a child of self, any childen would be + * on the same side as our parent. + */ + standin_son = standin->rb_nodes[standin_other]; + } + + if (RB_RED_P(standin_son)) { + /* + * We know we have a red child so if we flip it to black + * we don't have to rebalance. + */ + RB_MARK_BLACK(standin_son); + rebalance = F; + + if (standin_father != self) { + /* + * Change the son's parentage to point to his grandpa. + */ + RB_SET_FATHER(standin_son, standin_father); + RB_SET_POSITION(standin_son, standin_which); + } + } + + if (standin_father == self) { + /* + * If we are about to delete the standin's father, then when + * we call rebalance, we need to use ourselves as our father. + * Otherwise remember our original father. Also, sincef we are + * our standin's father we only need to reparent the standin's + * brother. + * + * | R --> S | + * | Q S --> Q T | + * | t --> | + * + * Have our son/standin adopt his brother as his new son. + */ + standin_father = standin; + } else { + /* + * | R --> S . | + * | / \ | T --> / \ | / | + * | ..... | S --> ..... | T | + * + * Sever standin's connection to his father. + */ + standin_father->rb_nodes[standin_which] = standin_son; + /* + * Adopt the far son. + */ + standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; + RB_SET_FATHER(standin->rb_nodes[standin_other], standin); + /* + * Use standin_other because we need to preserve standin_which + * for the removal_rebalance. + */ + standin_other = standin_which; + } + + /* + * Move the only remaining son to our standin. If our standin is our + * son, this will be the only son needed to be moved. + */ + standin->rb_nodes[standin_other] = self->rb_nodes[standin_other]; + RB_SET_FATHER(standin->rb_nodes[standin_other], standin); + + /* + * Now copy the result of self to standin and then replace + * self with standin in the tree. + */ + RB_COPY_PROPERTIES(standin, self); + RB_SET_FATHER(standin, RB_FATHER(self)); + RB_FATHER(standin)->rb_nodes[RB_POSITION(standin)] = standin; + + if (rebalance) + __archive_rb_tree_removal_rebalance(rbt, standin_father, standin_which); +} + +/* + * We could do this by doing + * __archive_rb_tree_node_swap(rbt, self, which); + * __archive_rb_tree_prune_node(rbt, self, F); + * + * But it's more efficient to just evalate and recolor the child. + */ +static void +__archive_rb_tree_prune_blackred_branch( + struct archive_rb_node *self, unsigned int which) +{ + struct archive_rb_node *father = RB_FATHER(self); + struct archive_rb_node *son = self->rb_nodes[which]; + + /* + * Remove ourselves from the tree and give our former child our + * properties (position, color, root). + */ + RB_COPY_PROPERTIES(son, self); + father->rb_nodes[RB_POSITION(son)] = son; + RB_SET_FATHER(son, father); +} +/* + * + */ +void +__archive_rb_tree_remove_node(struct archive_rb_tree *rbt, + struct archive_rb_node *self) +{ + struct archive_rb_node *standin; + unsigned int which; + + /* + * In the following diagrams, we (the node to be removed) are S. Red + * nodes are lowercase. T could be either red or black. + * + * Remember the major axiom of the red-black tree: the number of + * black nodes from the root to each leaf is constant across all + * leaves, only the number of red nodes varies. + * + * Thus removing a red leaf doesn't require any other changes to a + * red-black tree. So if we must remove a node, attempt to rearrange + * the tree so we can remove a red node. + * + * The simpliest case is a childless red node or a childless root node: + * + * | T --> T | or | R --> * | + * | s --> * | + */ + if (RB_CHILDLESS_P(self)) { + const int rebalance = RB_BLACK_P(self) && !RB_ROOT_P(rbt, self); + __archive_rb_tree_prune_node(rbt, self, rebalance); + return; + } + if (!RB_TWOCHILDREN_P(self)) { + /* + * The next simpliest case is the node we are deleting is + * black and has one red child. + * + * | T --> T --> T | + * | S --> R --> R | + * | r --> s --> * | + */ + which = RB_LEFT_SENTINEL_P(self) ? RB_DIR_RIGHT : RB_DIR_LEFT; + __archive_rb_tree_prune_blackred_branch(self, which); + return; + } + + /* + * We invert these because we prefer to remove from the inside of + * the tree. + */ + which = RB_POSITION(self) ^ RB_DIR_OTHER; + + /* + * Let's find the node closes to us opposite of our parent + * Now swap it with ourself, "prune" it, and rebalance, if needed. + */ + standin = __archive_rb_tree_iterate(rbt, self, which); + __archive_rb_tree_swap_prune_and_rebalance(rbt, self, standin); +} + +static void +__archive_rb_tree_removal_rebalance(struct archive_rb_tree *rbt, + struct archive_rb_node *parent, unsigned int which) +{ + + while (RB_BLACK_P(parent->rb_nodes[which])) { + unsigned int other = which ^ RB_DIR_OTHER; + struct archive_rb_node *brother = parent->rb_nodes[other]; + + /* + * For cases 1, 2a, and 2b, our brother's children must + * be black and our father must be black + */ + if (RB_BLACK_P(parent) + && RB_BLACK_P(brother->rb_left) + && RB_BLACK_P(brother->rb_right)) { + if (RB_RED_P(brother)) { + /* + * Case 1: Our brother is red, swap its + * position (and colors) with our parent. + * This should now be case 2b (unless C or E + * has a red child which is case 3; thus no + * explicit branch to case 2b). + * + * B -> D + * A d -> b E + * C E -> A C + */ + __archive_rb_tree_reparent_nodes(parent, other); + brother = parent->rb_nodes[other]; + } else { + /* + * Both our parent and brother are black. + * Change our brother to red, advance up rank + * and go through the loop again. + * + * B -> *B + * *A D -> A d + * C E -> C E + */ + RB_MARK_RED(brother); + if (RB_ROOT_P(rbt, parent)) + return; /* root == parent == black */ + which = RB_POSITION(parent); + parent = RB_FATHER(parent); + continue; + } + } + /* + * Avoid an else here so that case 2a above can hit either + * case 2b, 3, or 4. + */ + if (RB_RED_P(parent) + && RB_BLACK_P(brother) + && RB_BLACK_P(brother->rb_left) + && RB_BLACK_P(brother->rb_right)) { + /* + * We are black, our father is red, our brother and + * both nephews are black. Simply invert/exchange the + * colors of our father and brother (to black and red + * respectively). + * + * | f --> F | + * | * B --> * b | + * | N N --> N N | + */ + RB_MARK_BLACK(parent); + RB_MARK_RED(brother); + break; /* We're done! */ + } else { + /* + * Our brother must be black and have at least one + * red child (it may have two). + */ + if (RB_BLACK_P(brother->rb_nodes[other])) { + /* + * Case 3: our brother is black, our near + * nephew is red, and our far nephew is black. + * Swap our brother with our near nephew. + * This result in a tree that matches case 4. + * (Our father could be red or black). + * + * | F --> F | + * | x B --> x B | + * | n --> n | + */ + __archive_rb_tree_reparent_nodes(brother, which); + brother = parent->rb_nodes[other]; + } + /* + * Case 4: our brother is black and our far nephew + * is red. Swap our father and brother locations and + * change our far nephew to black. (these can be + * done in either order so we change the color first). + * The result is a valid red-black tree and is a + * terminal case. (again we don't care about the + * father's color) + * + * If the father is red, we will get a red-black-black + * tree: + * | f -> f --> b | + * | B -> B --> F N | + * | n -> N --> | + * + * If the father is black, we will get an all black + * tree: + * | F -> F --> B | + * | B -> B --> F N | + * | n -> N --> | + * + * If we had two red nephews, then after the swap, + * our former father would have a red grandson. + */ + RB_MARK_BLACK(brother->rb_nodes[other]); + __archive_rb_tree_reparent_nodes(parent, other); + break; /* We're done! */ + } + } +} + +struct archive_rb_node * +__archive_rb_tree_iterate(struct archive_rb_tree *rbt, + struct archive_rb_node *self, const unsigned int direction) +{ + const unsigned int other = direction ^ RB_DIR_OTHER; + + if (self == NULL) { + self = rbt->rbt_root; + if (RB_SENTINEL_P(self)) + return NULL; + while (!RB_SENTINEL_P(self->rb_nodes[direction])) + self = self->rb_nodes[direction]; + return self; + } + /* + * We can't go any further in this direction. We proceed up in the + * opposite direction until our parent is in direction we want to go. + */ + if (RB_SENTINEL_P(self->rb_nodes[direction])) { + while (!RB_ROOT_P(rbt, self)) { + if (other == RB_POSITION(self)) + return RB_FATHER(self); + self = RB_FATHER(self); + } + return NULL; + } + + /* + * Advance down one in current direction and go down as far as possible + * in the opposite direction. + */ + self = self->rb_nodes[direction]; + while (!RB_SENTINEL_P(self->rb_nodes[other])) + self = self->rb_nodes[other]; + return self; +} diff --git a/Utilities/cmlibarchive/libarchive/archive_rb.h b/Utilities/cmlibarchive/libarchive/archive_rb.h new file mode 100644 index 000000000..4562e9ebc --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_rb.h @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Matt Thomas . + * + * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Based on NetBSD: rb.h,v 1.13 2009/08/16 10:57:01 yamt Exp + */ +#ifndef ARCHIVE_RB_H_ +#define ARCHIVE_RB_H_ + +struct archive_rb_node { + struct archive_rb_node *rb_nodes[2]; + /* + * rb_info contains the two flags and the parent back pointer. + * We put the two flags in the low two bits since we know that + * rb_node will have an alignment of 4 or 8 bytes. + */ + uintptr_t rb_info; +}; + +#define ARCHIVE_RB_DIR_LEFT 0 +#define ARCHIVE_RB_DIR_RIGHT 1 + +#define ARCHIVE_RB_TREE_MIN(T) \ + __archive_rb_tree_iterate((T), NULL, ARCHIVE_RB_DIR_LEFT) +#define ARCHIVE_RB_TREE_MAX(T) \ + __archive_rb_tree_iterate((T), NULL, ARCHIVE_RB_DIR_RIGHT) +#define ARCHIVE_RB_TREE_FOREACH(N, T) \ + for ((N) = ARCHIVE_RB_TREE_MIN(T); (N); \ + (N) = __archive_rb_tree_iterate((T), (N), ARCHIVE_RB_DIR_RIGHT)) +#define ARCHIVE_RB_TREE_FOREACH_REVERSE(N, T) \ + for ((N) = ARCHIVE_RB_TREE_MAX(T); (N); \ + (N) = __archive_rb_tree_iterate((T), (N), ARCHIVE_RB_DIR_LEFT)) + +/* + * archive_rbto_compare_nodes_fn: + * return a positive value if the first node < the second node. + * return a negative value if the first node > the second node. + * return 0 if they are considered same. + * + * archive_rbto_compare_key_fn: + * return a positive value if the node < the key. + * return a negative value if the node > the key. + * return 0 if they are considered same. + */ + +typedef signed int (*const archive_rbto_compare_nodes_fn)(const struct archive_rb_node *, + const struct archive_rb_node *); +typedef signed int (*const archive_rbto_compare_key_fn)(const struct archive_rb_node *, + const void *); + +struct archive_rb_tree_ops { + archive_rbto_compare_nodes_fn rbto_compare_nodes; + archive_rbto_compare_key_fn rbto_compare_key; +}; + +struct archive_rb_tree { + struct archive_rb_node *rbt_root; + const struct archive_rb_tree_ops *rbt_ops; +}; + +void __archive_rb_tree_init(struct archive_rb_tree *, + const struct archive_rb_tree_ops *); +int __archive_rb_tree_insert_node(struct archive_rb_tree *, + struct archive_rb_node *); +struct archive_rb_node * + __archive_rb_tree_find_node(struct archive_rb_tree *, const void *); +struct archive_rb_node * + __archive_rb_tree_find_node_geq(struct archive_rb_tree *, const void *); +struct archive_rb_node * + __archive_rb_tree_find_node_leq(struct archive_rb_tree *, const void *); +void __archive_rb_tree_remove_node(struct archive_rb_tree *, struct archive_rb_node *); +struct archive_rb_node * + __archive_rb_tree_iterate(struct archive_rb_tree *, + struct archive_rb_node *, const unsigned int); + +#endif /* ARCHIVE_RB_H_*/ diff --git a/Utilities/cmlibarchive/libarchive/archive_read.3 b/Utilities/cmlibarchive/libarchive/archive_read.3 index 0124c04da..52851925c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read.3 @@ -22,181 +22,16 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/archive_read.3,v 1.37 2008/05/26 17:00:22 kientzle Exp $ +.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $ .\" -.Dd April 13, 2009 -.Dt archive_read 3 +.Dd March 23, 2011 +.Dt ARCHIVE_READ 3 .Os .Sh NAME -.Nm archive_read_new , -.Nm archive_read_set_filter_options , -.Nm archive_read_set_format_options , -.Nm archive_read_set_options , -.Nm archive_read_support_compression_all , -.Nm archive_read_support_compression_bzip2 , -.Nm archive_read_support_compression_compress , -.Nm archive_read_support_compression_gzip , -.Nm archive_read_support_compression_lzma , -.Nm archive_read_support_compression_none , -.Nm archive_read_support_compression_xz , -.Nm archive_read_support_compression_program , -.Nm archive_read_support_compression_program_signature , -.Nm archive_read_support_format_all , -.Nm archive_read_support_format_ar , -.Nm archive_read_support_format_cpio , -.Nm archive_read_support_format_empty , -.Nm archive_read_support_format_iso9660 , -.Nm archive_read_support_format_mtree, -.Nm archive_read_support_format_raw, -.Nm archive_read_support_format_tar , -.Nm archive_read_support_format_zip , -.Nm archive_read_open , -.Nm archive_read_open2 , -.Nm archive_read_open_fd , -.Nm archive_read_open_FILE , -.Nm archive_read_open_filename , -.Nm archive_read_open_memory , -.Nm archive_read_next_header , -.Nm archive_read_next_header2 , -.Nm archive_read_data , -.Nm archive_read_data_block , -.Nm archive_read_data_skip , -.\" #if ARCHIVE_API_VERSION < 3 -.Nm archive_read_data_into_buffer , -.\" #endif -.Nm archive_read_data_into_fd , -.Nm archive_read_extract , -.Nm archive_read_extract2 , -.Nm archive_read_extract_set_progress_callback , -.Nm archive_read_close , -.Nm archive_read_finish +.Nm archive_read .Nd functions for reading streaming archives .Sh SYNOPSIS .In archive.h -.Ft struct archive * -.Fn archive_read_new "void" -.Ft int -.Fn archive_read_support_compression_all "struct archive *" -.Ft int -.Fn archive_read_support_compression_bzip2 "struct archive *" -.Ft int -.Fn archive_read_support_compression_compress "struct archive *" -.Ft int -.Fn archive_read_support_compression_gzip "struct archive *" -.Ft int -.Fn archive_read_support_compression_lzma "struct archive *" -.Ft int -.Fn archive_read_support_compression_none "struct archive *" -.Ft int -.Fn archive_read_support_compression_xz "struct archive *" -.Ft int -.Fo archive_read_support_compression_program -.Fa "struct archive *" -.Fa "const char *cmd" -.Fc -.Ft int -.Fo archive_read_support_compression_program_signature -.Fa "struct archive *" -.Fa "const char *cmd" -.Fa "const void *signature" -.Fa "size_t signature_length" -.Fc -.Ft int -.Fn archive_read_support_format_all "struct archive *" -.Ft int -.Fn archive_read_support_format_ar "struct archive *" -.Ft int -.Fn archive_read_support_format_cpio "struct archive *" -.Ft int -.Fn archive_read_support_format_empty "struct archive *" -.Ft int -.Fn archive_read_support_format_iso9660 "struct archive *" -.Ft int -.Fn archive_read_support_format_mtree "struct archive *" -.Ft int -.Fn archive_read_support_format_raw "struct archive *" -.Ft int -.Fn archive_read_support_format_tar "struct archive *" -.Ft int -.Fn archive_read_support_format_zip "struct archive *" -.Ft int -.Fn archive_read_set_filter_options "struct archive *" "const char *" -.Ft int -.Fn archive_read_set_format_options "struct archive *" "const char *" -.Ft int -.Fn archive_read_set_options "struct archive *" "const char *" -.Ft int -.Fo archive_read_open -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_read_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fo archive_read_open2 -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_read_callback *" -.Fa "archive_skip_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fn archive_read_open_FILE "struct archive *" "FILE *file" -.Ft int -.Fn archive_read_open_fd "struct archive *" "int fd" "size_t block_size" -.Ft int -.Fo archive_read_open_filename -.Fa "struct archive *" -.Fa "const char *filename" -.Fa "size_t block_size" -.Fc -.Ft int -.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size" -.Ft int -.Fn archive_read_next_header "struct archive *" "struct archive_entry **" -.Ft int -.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *" -.Ft ssize_t -.Fn archive_read_data "struct archive *" "void *buff" "size_t len" -.Ft int -.Fo archive_read_data_block -.Fa "struct archive *" -.Fa "const void **buff" -.Fa "size_t *len" -.Fa "off_t *offset" -.Fc -.Ft int -.Fn archive_read_data_skip "struct archive *" -.\" #if ARCHIVE_API_VERSION < 3 -.Ft int -.Fn archive_read_data_into_buffer "struct archive *" "void *" "ssize_t len" -.\" #endif -.Ft int -.Fn archive_read_data_into_fd "struct archive *" "int fd" -.Ft int -.Fo archive_read_extract -.Fa "struct archive *" -.Fa "struct archive_entry *" -.Fa "int flags" -.Fc -.Ft int -.Fo archive_read_extract2 -.Fa "struct archive *src" -.Fa "struct archive_entry *" -.Fa "struct archive *dest" -.Fc -.Ft void -.Fo archive_read_extract_set_progress_callback -.Fa "struct archive *" -.Fa "void (*func)(void *)" -.Fa "void *user_data" -.Fc -.Ft int -.Fn archive_read_close "struct archive *" -.Ft int -.Fn archive_read_finish "struct archive *" .Sh DESCRIPTION These functions provide a complete API for reading streaming archives. The general process is to first create the @@ -204,375 +39,120 @@ The general process is to first create the object, set options, initialize the reader, iterate over the archive headers and associated data, then close the archive and release all resources. -The following summary describes the functions in approximately the -order they would be used: -.Bl -tag -compact -width indent -.It Fn archive_read_new -Allocates and initializes a +.\" +.Ss Create archive object +See +.Xr archive_read_new 3 . +.Pp +To read an archive, you must first obtain an initialized .Tn struct archive -object suitable for reading from an archive. -.It Xo -.Fn archive_read_support_compression_bzip2 , -.Fn archive_read_support_compression_compress , -.Fn archive_read_support_compression_gzip , -.Fn archive_read_support_compression_lzma , -.Fn archive_read_support_compression_none , -.Fn archive_read_support_compression_xz -.Xc -Enables auto-detection code and decompression support for the -specified compression. -Returns -.Cm ARCHIVE_OK -if the compression is fully supported, or -.Cm ARCHIVE_WARN -if the compression is supported only through an external program. -Note that decompression using an external program is usually slower than -decompression through built-in libraries. -Note that -.Dq none -is always enabled by default. -.It Fn archive_read_support_compression_all -Enables all available decompression filters. -.It Fn archive_read_support_compression_program -Data is fed through the specified external program before being dearchived. -Note that this disables automatic detection of the compression format, -so it makes no sense to specify this in conjunction with any other -decompression option. -.It Fn archive_read_support_compression_program_signature -This feeds data through the specified external program -but only if the initial bytes of the data match the specified -signature value. -.It Xo -.Fn archive_read_support_format_all , -.Fn archive_read_support_format_ar , -.Fn archive_read_support_format_cpio , -.Fn archive_read_support_format_empty , -.Fn archive_read_support_format_iso9660 , -.Fn archive_read_support_format_mtree , -.Fn archive_read_support_format_tar , -.Fn archive_read_support_format_zip -.Xc -Enables support---including auto-detection code---for the -specified archive format. -For example, -.Fn archive_read_support_format_tar -enables support for a variety of standard tar formats, old-style tar, -ustar, pax interchange format, and many common variants. -For convenience, -.Fn archive_read_support_format_all -enables support for all available formats. -Only empty archives are supported by default. -.It Fn archive_read_support_format_raw -The -.Dq raw -format handler allows libarchive to be used to read arbitrary data. -It treats any data stream as an archive with a single entry. -The pathname of this entry is -.Dq data ; -all other entry fields are unset. -This is not enabled by +object from +.Fn archive_read_new . +.\" +.Ss Enable filters and formats +See +.Xr archive_read_filter 3 +and +.Xr archive_read_format 3 . +.Pp +You can then modify this object for the desired operations with the +various +.Fn archive_read_set_XXX +and +.Fn archive_read_support_XXX +functions. +In particular, you will need to invoke appropriate +.Fn archive_read_support_XXX +functions to enable the corresponding compression and format +support. +Note that these latter functions perform two distinct operations: +they cause the corresponding support code to be linked into your +program, and they enable the corresponding auto-detect code. +Unless you have specific constraints, you will generally want +to invoke +.Fn archive_read_support_filter_all +and .Fn archive_read_support_format_all -in order to avoid erroneous handling of damaged archives. -.It Xo -.Fn archive_read_set_filter_options , -.Fn archive_read_set_format_options , -.Fn archive_read_set_options -.Xc -Specifies options that will be passed to currently-registered -filters (including decompression filters) and/or format readers. -The argument is a comma-separated list of individual options. -Individual options have one of the following forms: -.Bl -tag -compact -width indent -.It Ar option=value -The option/value pair will be provided to every module. -Modules that do not accept an option with this name will ignore it. -.It Ar option -The option will be provided to every module with a value of -.Dq 1 . -.It Ar !option -The option will be provided to every module with a NULL value. -.It Ar module:option=value , Ar module:option , Ar module:!option -As above, but the corresponding option and value will be provided -only to modules whose name matches -.Ar module . -.El -The return value will be -.Cm ARCHIVE_OK -if any module accepts the option, or -.Cm ARCHIVE_WARN -if no module accepted the option, or -.Cm ARCHIVE_FATAL -if there was a fatal error while attempting to process the option. +to enable auto-detect for all formats and compression types +currently supported by the library. +.\" +.Ss Set options +See +.Xr archive_read_set_options 3 . +.\" +.Ss Open archive +See +.Xr archive_read_open 3 . .Pp -The currently supported options are: -.Bl -tag -compact -width indent -.It Format iso9660 -.Bl -tag -compact -width indent -.It Cm joliet -Support Joliet extensions. -Defaults to enabled, use -.Cm !joliet -to disable. -.El -.El -.It Fn archive_read_open -The same as -.Fn archive_read_open2 , -except that the skip callback is assumed to be -.Dv NULL . -.It Fn archive_read_open2 -Freeze the settings, open the archive, and prepare for reading entries. -This is the most generic version of this call, which accepts -four callback functions. -Most clients will want to use -.Fn archive_read_open_filename , -.Fn archive_read_open_FILE , -.Fn archive_read_open_fd , -or -.Fn archive_read_open_memory -instead. -The library invokes the client-provided functions to obtain -raw bytes from the archive. -.It Fn archive_read_open_FILE -Like -.Fn archive_read_open , -except that it accepts a +Once you have prepared the +.Tn struct archive +object, you call +.Fn archive_read_open +to actually open the archive and prepare it for reading. +There are several variants of this function; +the most basic expects you to provide pointers to several +functions that can provide blocks of bytes from the archive. +There are convenience forms that allow you to +specify a filename, file descriptor, .Ft "FILE *" -pointer. -This function should not be used with tape drives or other devices -that require strict I/O blocking. -.It Fn archive_read_open_fd -Like -.Fn archive_read_open , -except that it accepts a file descriptor and block size rather than -a set of function pointers. -Note that the file descriptor will not be automatically closed at -end-of-archive. -This function is safe for use with tape drives or other blocked devices. -.It Fn archive_read_open_file -This is a deprecated synonym for -.Fn archive_read_open_filename . -.It Fn archive_read_open_filename -Like -.Fn archive_read_open , -except that it accepts a simple filename and a block size. -A NULL filename represents standard input. -This function is safe for use with tape drives or other blocked devices. -.It Fn archive_read_open_memory -Like -.Fn archive_read_open , -except that it accepts a pointer and size of a block of -memory containing the archive data. -.It Fn archive_read_next_header -Read the header for the next entry and return a pointer to -a -.Tn struct archive_entry . -This is a convenience wrapper around -.Fn archive_read_next_header2 -that reuses an internal +object, or a block of memory from which to read the archive data. +Note that the core library makes no assumptions about the +size of the blocks read; +callback functions are free to read whatever block size is +most appropriate for the medium. +.\" +.Ss Consume archive +See +.Xr archive_read_header 3 , +.Xr archive_read_data 3 +and +.Xr archive_read_extract 3 . +.Pp +Each archive entry consists of a header followed by a certain +amount of data. +You can obtain the next header with +.Fn archive_read_next_header , +which returns a pointer to an .Tn struct archive_entry -object for each request. -.It Fn archive_read_next_header2 -Read the header for the next entry and populate the provided -.Tn struct archive_entry . -.It Fn archive_read_data -Read data associated with the header just read. -Internally, this is a convenience function that calls -.Fn archive_read_data_block -and fills any gaps with nulls so that callers see a single -continuous stream of data. -.It Fn archive_read_data_block -Return the next available block of data for this entry. -Unlike -.Fn archive_read_data , -the -.Fn archive_read_data_block -function avoids copying data and allows you to correctly handle -sparse files, as supported by some archive formats. -The library guarantees that offsets will increase and that blocks -will not overlap. -Note that the blocks returned from this function can be much larger -than the block size read from disk, due to compression -and internal buffer optimizations. -.It Fn archive_read_data_skip -A convenience function that repeatedly calls -.Fn archive_read_data_block -to skip all of the data for this archive entry. -.\" #if ARCHIVE_API_VERSION < 3 -.It Fn archive_read_data_into_buffer -This function is deprecated and will be removed. -Use +structure with information about the current archive element. +If the entry is a regular file, then the header will be followed +by the file data. +You can use .Fn archive_read_data -instead. -.\" #endif -.It Fn archive_read_data_into_fd -A convenience function that repeatedly calls +(which works much like the +.Xr read 2 +system call) +to read this data from the archive, or .Fn archive_read_data_block -to copy the entire entry to the provided file descriptor. -.It Fn archive_read_extract , Fn archive_read_extract_set_skip_file -A convenience function that wraps the corresponding -.Xr archive_write_disk 3 -interfaces. -The first call to -.Fn archive_read_extract -creates a restore object using -.Xr archive_write_disk_new 3 -and -.Xr archive_write_disk_set_standard_lookup 3 , -then transparently invokes -.Xr archive_write_disk_set_options 3 , -.Xr archive_write_header 3 , -.Xr archive_write_data 3 , -and -.Xr archive_write_finish_entry 3 -to create the entry on disk and copy data into it. -The -.Va flags -argument is passed unmodified to -.Xr archive_write_disk_set_options 3 . -.It Fn archive_read_extract2 -This is another version of +which provides a slightly more efficient interface. +You may prefer to use the higher-level +.Fn archive_read_data_skip , +which reads and discards the data for this entry, +.Fn archive_read_data_to_file , +which copies the data to the provided file descriptor, or +.Fn archive_read_extract , +which recreates the specified entry on disk and copies data +from the archive. +In particular, note that .Fn archive_read_extract -that allows you to provide your own restore object. -In particular, this allows you to override the standard lookup functions -using -.Xr archive_write_disk_set_group_lookup 3 , -and -.Xr archive_write_disk_set_user_lookup 3 . -Note that -.Fn archive_read_extract2 -does not accept a -.Va flags -argument; you should use -.Fn archive_write_disk_set_options -to set the restore options yourself. -.It Fn archive_read_extract_set_progress_callback -Sets a pointer to a user-defined callback that can be used -for updating progress displays during extraction. -The progress function will be invoked during the extraction of large -regular files. -The progress function will be invoked with the pointer provided to this call. -Generally, the data pointed to should include a reference to the archive -object and the archive_entry object so that various statistics -can be retrieved for the progress display. -.It Fn archive_read_close -Complete the archive and invoke the close callback. -.It Fn archive_read_finish -Invokes -.Fn archive_read_close -if it was not invoked manually, then release all resources. -Note: In libarchive 1.x, this function was declared to return -.Ft void , -which made it impossible to detect certain errors when -.Fn archive_read_close -was invoked implicitly from this function. -The declaration is corrected beginning with libarchive 2.0. -.El -.Pp -Note that the library determines most of the relevant information about -the archive by inspection. -In particular, it automatically detects -.Xr gzip 1 -or -.Xr bzip2 1 -compression and transparently performs the appropriate decompression. -It also automatically detects the archive format. -.Pp -A complete description of the -.Tn struct archive -and +uses the .Tn struct archive_entry -objects can be found in the overview manual page for -.Xr libarchive 3 . -.Sh CLIENT CALLBACKS -The callback functions must match the following prototypes: -.Bl -item -offset indent -.It -.Ft typedef ssize_t -.Fo archive_read_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "const void **buffer" -.Fc -.It -.\" #if ARCHIVE_API_VERSION < 2 -.Ft typedef int -.Fo archive_skip_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "size_t request" -.Fc -.\" #else -.\" .Ft typedef off_t -.\" .Fo archive_skip_callback -.\" .Fa "struct archive *" -.\" .Fa "void *client_data" -.\" .Fa "off_t request" -.\" .Fc -.\" #endif -.It -.Ft typedef int -.Fn archive_open_callback "struct archive *" "void *client_data" -.It -.Ft typedef int -.Fn archive_close_callback "struct archive *" "void *client_data" -.El -.Pp -The open callback is invoked by -.Fn archive_open . -It should return -.Cm ARCHIVE_OK -if the underlying file or data source is successfully -opened. -If the open fails, it should call -.Fn archive_set_error -to register an error code and message and return -.Cm ARCHIVE_FATAL . -.Pp -The read callback is invoked whenever the library -requires raw bytes from the archive. -The read callback should read data into a buffer, -set the -.Li const void **buffer -argument to point to the available data, and -return a count of the number of bytes available. -The library will invoke the read callback again -only after it has consumed this data. -The library imposes no constraints on the size -of the data blocks returned. -On end-of-file, the read callback should -return zero. -On error, the read callback should invoke -.Fn archive_set_error -to register an error code and message and -return -1. -.Pp -The skip callback is invoked when the -library wants to ignore a block of data. -The return value is the number of bytes actually -skipped, which may differ from the request. -If the callback cannot skip data, it should return -zero. -If the skip callback is not provided (the -function pointer is -.Dv NULL ), -the library will invoke the read function -instead and simply discard the result. -A skip callback can provide significant -performance gains when reading uncompressed -archives from slow disk drives or other media -that can skip quickly. +structure that you provide it, which may differ from the +entry just read from the archive. +In particular, many applications will want to override the +pathname, file permissions, or ownership. +.\" +.Ss Release resources +See +.Xr archive_read_free 3 . .Pp -The close callback is invoked by archive_close when -the archive processing is complete. -The callback should return -.Cm ARCHIVE_OK -on success. -On failure, the callback should invoke -.Fn archive_set_error -to register an error code and message and -return -.Cm ARCHIVE_FATAL. +Once you have finished reading data from the archive, you +should call +.Fn archive_read_close +to close the archive, then call +.Fn archive_read_free +to release all resources, including all memory allocated by the library. +.\" .Sh EXAMPLE The following illustrates basic usage of the library. In this example, @@ -593,14 +173,14 @@ list_archive(const char *name) mydata = malloc(sizeof(struct mydata)); a = archive_read_new(); mydata->name = name; - archive_read_support_compression_all(a); + archive_read_support_filter_all(a); archive_read_support_format_all(a); archive_read_open(a, mydata, myopen, myread, myclose); while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - printf("%s\\n",archive_entry_pathname(entry)); + printf("%s\en",archive_entry_pathname(entry)); archive_read_data_skip(a); } - archive_read_finish(a); + archive_read_free(a); free(mydata); } @@ -632,62 +212,18 @@ myclose(struct archive *a, void *client_data) return (ARCHIVE_OK); } .Ed -.Sh RETURN VALUES -Most functions return zero on success, non-zero on error. -The possible return codes include: -.Cm ARCHIVE_OK -(the operation succeeded), -.Cm ARCHIVE_WARN -(the operation succeeded but a non-critical error was encountered), -.Cm ARCHIVE_EOF -(end-of-archive was encountered), -.Cm ARCHIVE_RETRY -(the operation failed but can be retried), -and -.Cm ARCHIVE_FATAL -(there was a fatal error; the archive should be closed immediately). -Detailed error codes and textual descriptions are available from the -.Fn archive_errno -and -.Fn archive_error_string -functions. -.Pp -.Fn archive_read_new -returns a pointer to a freshly allocated -.Tn struct archive -object. -It returns -.Dv NULL -on error. -.Pp -.Fn archive_read_data -returns a count of bytes actually read or zero at the end of the entry. -On error, a value of -.Cm ARCHIVE_FATAL , -.Cm ARCHIVE_WARN , -or -.Cm ARCHIVE_RETRY -is returned and an error code and textual description can be retrieved from the -.Fn archive_errno -and -.Fn archive_error_string -functions. -.Pp -The library expects the client callbacks to behave similarly. -If there is an error, you can use -.Fn archive_set_error -to set an appropriate error code and description, -then return one of the non-zero values above. -(Note that the value eventually returned to the client may -not be the same; many errors that are not critical at the level -of basic I/O can prevent the archive from being properly read, -thus most I/O errors eventually cause -.Cm ARCHIVE_FATAL -to be returned.) .\" .Sh ERRORS .Sh SEE ALSO .Xr tar 1 , -.Xr archive 3 , +.Xr libarchive 3 , +.Xr archive_read_new 3 , +.Xr archive_read_data 3 , +.Xr archive_read_extract 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_header 3 , +.Xr archive_read_open 3 , +.Xr archive_read_set_options 3 , .Xr archive_util 3 , .Xr tar 5 .Sh HISTORY diff --git a/Utilities/cmlibarchive/libarchive/archive_read.c b/Utilities/cmlibarchive/libarchive/archive_read.c index 79dd1f874..baf9dc467 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read.c +++ b/Utilities/cmlibarchive/libarchive/archive_read.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read.c,v 1.39 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read.c 201157 2009-12-29 05:30:23Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -55,23 +55,44 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read.c,v 1.39 2008/12/06 06:45:15 #define minimum(a, b) (a < b ? a : b) -static int build_stream(struct archive_read *); -static int choose_format(struct archive_read *); +static int choose_filters(struct archive_read *); +static int choose_format(struct archive_read *); +static void free_filters(struct archive_read *); +static int close_filters(struct archive_read *); static struct archive_vtable *archive_read_vtable(void); -static int _archive_read_close(struct archive *); -static int _archive_read_finish(struct archive *); +static int64_t _archive_filter_bytes(struct archive *, int); +static int _archive_filter_code(struct archive *, int); +static const char *_archive_filter_name(struct archive *, int); +static int _archive_filter_count(struct archive *); +static int _archive_read_close(struct archive *); +static int _archive_read_data_block(struct archive *, + const void **, size_t *, int64_t *); +static int _archive_read_free(struct archive *); +static int _archive_read_next_header(struct archive *, + struct archive_entry **); +static int _archive_read_next_header2(struct archive *, + struct archive_entry *); +static int64_t advance_file_pointer(struct archive_read_filter *, int64_t); static struct archive_vtable * archive_read_vtable(void) { - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_finish = _archive_read_finish; - av.archive_close = _archive_read_close; - } - return (&av); + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_filter_bytes = _archive_filter_bytes; + av.archive_filter_code = _archive_filter_code; + av.archive_filter_name = _archive_filter_name; + av.archive_filter_count = _archive_filter_count; + av.archive_read_data_block = _archive_read_data_block; + av.archive_read_next_header = _archive_read_next_header; + av.archive_read_next_header2 = _archive_read_next_header2; + av.archive_free = _archive_read_free; + av.archive_close = _archive_read_close; + inited = 1; + } + return (&av); } /* @@ -80,268 +101,281 @@ archive_read_vtable(void) struct archive * archive_read_new(void) { - struct archive_read *a; + struct archive_read *a; - a = (struct archive_read *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_READ_MAGIC; + a = (struct archive_read *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_READ_MAGIC; - a->archive.state = ARCHIVE_STATE_NEW; - a->entry = archive_entry_new(); - a->archive.vtable = archive_read_vtable(); + a->archive.state = ARCHIVE_STATE_NEW; + a->entry = archive_entry_new2(&a->archive); + a->archive.vtable = archive_read_vtable(); - return (&a->archive); + return (&a->archive); } /* * Record the do-not-extract-to file. This belongs in archive_read_extract.c. */ void -archive_read_extract_set_skip_file(struct archive *_a, dev_t d, ino_t i) +archive_read_extract_set_skip_file(struct archive *_a, int64_t d, int64_t i) { - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY, - "archive_read_extract_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; + struct archive_read *a = (struct archive_read *)_a; + + if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_extract_set_skip_file")) + return; + a->skip_file_set = 1; + a->skip_file_dev = d; + a->skip_file_ino = i; } /* - * Set read options for the format. + * Open the archive */ int -archive_read_set_format_options(struct archive *_a, const char *s) +archive_read_open(struct archive *a, void *client_data, + archive_open_callback *client_opener, archive_read_callback *client_reader, + archive_close_callback *client_closer) { - struct archive_read *a; - struct archive_format_descriptor *format; - char key[64], val[64]; - char *valp; - size_t i; - int len, r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_format_options"); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - a = (struct archive_read *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_NEW, "archive_read_set_format_options"); - len = 0; - for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) { - format = &a->formats[i]; - if (format == NULL || format->options == NULL || - format->name == NULL) - /* This format does not support option. */ - continue; - - while ((len = __archive_parse_options(s, format->name, - sizeof(key), key, sizeof(val), val)) > 0) { - valp = val[0] == '\0' ? NULL : val; - a->format = format; - r = format->options(a, key, valp); - a->format = NULL; - if (r == ARCHIVE_FATAL) - return (r); - s += len; - } - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); + /* Old archive_read_open() is just a thin shell around + * archive_read_open1. */ + archive_read_set_open_callback(a, client_opener); + archive_read_set_read_callback(a, client_reader); + archive_read_set_close_callback(a, client_closer); + archive_read_set_callback_data(a, client_data); + return archive_read_open1(a); } -/* - * Set read options for the filter. - */ -int -archive_read_set_filter_options(struct archive *_a, const char *s) -{ - struct archive_read *a; - struct archive_read_filter *filter; - struct archive_read_filter_bidder *bidder; - char key[64], val[64]; - int len, r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_filter_options"); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - a = (struct archive_read *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_NEW, "archive_read_set_filter_options"); - filter = a->filter; - len = 0; - for (filter = a->filter; filter != NULL; filter = filter->upstream) { - bidder = filter->bidder; - if (bidder == NULL) - continue; - if (bidder->options == NULL) - /* This bidder does not support option */ - continue; - while ((len = __archive_parse_options(s, filter->name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = bidder->options(bidder, key, NULL); - else - r = bidder->options(bidder, key, val); - if (r == ARCHIVE_FATAL) - return (r); - s += len; - } - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} -/* - * Set read options for the format and the filter. - */ int -archive_read_set_options(struct archive *_a, const char *s) -{ - int r; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_set_options"); - archive_clear_error(_a); - - r = archive_read_set_format_options(_a, s); - if (r != ARCHIVE_OK) - return (r); - r = archive_read_set_filter_options(_a, s); - if (r != ARCHIVE_OK) - return (r); - return (ARCHIVE_OK); -} - -/* - * Open the archive - */ -int -archive_read_open(struct archive *a, void *client_data, - archive_open_callback *client_opener, archive_read_callback *client_reader, +archive_read_open2(struct archive *a, void *client_data, + archive_open_callback *client_opener, + archive_read_callback *client_reader, + archive_skip_callback *client_skipper, archive_close_callback *client_closer) { - /* Old archive_read_open() is just a thin shell around - * archive_read_open2. */ - return archive_read_open2(a, client_data, client_opener, - client_reader, NULL, client_closer); + /* Old archive_read_open2() is just a thin shell around + * archive_read_open1. */ + archive_read_set_callback_data(a, client_data); + archive_read_set_open_callback(a, client_opener); + archive_read_set_read_callback(a, client_reader); + archive_read_set_skip_callback(a, client_skipper); + archive_read_set_close_callback(a, client_closer); + return archive_read_open1(a); } static ssize_t client_read_proxy(struct archive_read_filter *self, const void **buff) { - ssize_t r; - r = (self->archive->client.reader)(&self->archive->archive, - self->data, buff); - self->archive->archive.raw_position += r; - return (r); + ssize_t r; + r = (self->archive->client.reader)(&self->archive->archive, + self->data, buff); + return (r); } static int64_t client_skip_proxy(struct archive_read_filter *self, int64_t request) { - int64_t ask, get, total; - /* Limit our maximum seek request to 1GB on platforms - * with 32-bit off_t (such as Windows). */ - int64_t skip_limit = ((int64_t)1) << (sizeof(off_t) * 8 - 2); - - if (self->archive->client.skipper == NULL) - return (0); - total = 0; - for (;;) { - ask = request; - if (ask > skip_limit) - ask = skip_limit; - get = (self->archive->client.skipper)(&self->archive->archive, - self->data, ask); - if (get == 0) - return (total); - request -= get; - self->archive->archive.raw_position += get; - total += get; - } + if (request < 0) + __archive_errx(1, "Negative skip requested."); + if (request == 0) + return 0; + + if (self->archive->client.skipper != NULL) { + /* Seek requests over 1GiB are broken down into + * multiple seeks. This avoids overflows when the + * requests get passed through 32-bit arguments. */ + int64_t skip_limit = (int64_t)1 << 30; + int64_t total = 0; + for (;;) { + int64_t get, ask = request; + if (ask > skip_limit) + ask = skip_limit; + get = (self->archive->client.skipper)(&self->archive->archive, + self->data, ask); + if (get == 0) + return (total); + request -= get; + total += get; + } + return total; + } else if (self->archive->client.seeker != NULL + && request > 64 * 1024) { + /* If the client provided a seeker but not a skipper, + * we can use the seeker to skip forward. + * + * Note: This isn't always a good idea. The client + * skipper is allowed to skip by less than requested + * if it needs to maintain block alignment. The + * seeker is not allowed to play such games, so using + * the seeker here may be a performance loss compared + * to just reading and discarding. That's why we + * only do this for skips of over 64k. + */ + int64_t before = self->position; + int64_t after = (self->archive->client.seeker)(&self->archive->archive, + self->data, request, SEEK_CUR); + if (after != before + request) + return ARCHIVE_FATAL; + return after - before; + } + return 0; +} + +static int64_t +client_seek_proxy(struct archive_read_filter *self, int64_t offset, int whence) +{ + /* DO NOT use the skipper here! If we transparently handled + * forward seek here by using the skipper, that will break + * other libarchive code that assumes a successful forward + * seek means it can also seek backwards. + */ + if (self->archive->client.seeker == NULL) + return (ARCHIVE_FAILED); + return (self->archive->client.seeker)(&self->archive->archive, + self->data, offset, whence); } static int client_close_proxy(struct archive_read_filter *self) { - int r = ARCHIVE_OK; + int r = ARCHIVE_OK; + + if (self->archive->client.closer != NULL) + r = (self->archive->client.closer)((struct archive *)self->archive, + self->data); + return (r); +} + +int +archive_read_set_open_callback(struct archive *_a, + archive_open_callback *client_opener) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_open_callback"); + a->client.opener = client_opener; + return ARCHIVE_OK; +} - if (self->archive->client.closer != NULL) - r = (self->archive->client.closer)((struct archive *)self->archive, - self->data); - self->data = NULL; - return (r); +int +archive_read_set_read_callback(struct archive *_a, + archive_read_callback *client_reader) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_read_callback"); + a->client.reader = client_reader; + return ARCHIVE_OK; } +int +archive_read_set_skip_callback(struct archive *_a, + archive_skip_callback *client_skipper) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_skip_callback"); + a->client.skipper = client_skipper; + return ARCHIVE_OK; +} int -archive_read_open2(struct archive *_a, void *client_data, - archive_open_callback *client_opener, - archive_read_callback *client_reader, - archive_skip_callback *client_skipper, +archive_read_set_seek_callback(struct archive *_a, + archive_seek_callback *client_seeker) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_seek_callback"); + a->client.seeker = client_seeker; + return ARCHIVE_OK; +} + +int +archive_read_set_close_callback(struct archive *_a, archive_close_callback *client_closer) { - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter *filter; - int e; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "archive_read_open"); - archive_clear_error(&a->archive); - - if (client_reader == NULL) - __archive_errx(1, - "No reader function provided to archive_read_open"); - - /* Open data source. */ - if (client_opener != NULL) { - e =(client_opener)(&a->archive, client_data); - if (e != 0) { - /* If the open failed, call the closer to clean up. */ - if (client_closer) - (client_closer)(&a->archive, client_data); - return (e); - } - } - - /* Save the client functions and mock up the initial source. */ - a->client.reader = client_reader; - a->client.skipper = client_skipper; - a->client.closer = client_closer; - - filter = calloc(1, sizeof(*filter)); - if (filter == NULL) - return (ARCHIVE_FATAL); - filter->bidder = NULL; - filter->upstream = NULL; - filter->archive = a; - filter->data = client_data; - filter->read = client_read_proxy; - filter->skip = client_skip_proxy; - filter->close = client_close_proxy; - filter->name = "none"; - filter->code = ARCHIVE_COMPRESSION_NONE; - a->filter = filter; - - /* Build out the input pipeline. */ - e = build_stream(a); - if (e == ARCHIVE_OK) - a->archive.state = ARCHIVE_STATE_HEADER; - - return (e); + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_close_callback"); + a->client.closer = client_closer; + return ARCHIVE_OK; +} + +int +archive_read_set_callback_data(struct archive *_a, void *client_data) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_set_callback_data"); + a->client.data = client_data; + return ARCHIVE_OK; +} + +int +archive_read_open1(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter *filter; + int slot, e; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_open"); + archive_clear_error(&a->archive); + + if (a->client.reader == NULL) { + archive_set_error(&a->archive, EINVAL, + "No reader function provided to archive_read_open"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + /* Open data source. */ + if (a->client.opener != NULL) { + e =(a->client.opener)(&a->archive, a->client.data); + if (e != 0) { + /* If the open failed, call the closer to clean up. */ + if (a->client.closer) + (a->client.closer)(&a->archive, a->client.data); + return (e); + } + } + + filter = calloc(1, sizeof(*filter)); + if (filter == NULL) + return (ARCHIVE_FATAL); + filter->bidder = NULL; + filter->upstream = NULL; + filter->archive = a; + filter->data = a->client.data; + filter->read = client_read_proxy; + filter->skip = client_skip_proxy; + filter->seek = client_seek_proxy; + filter->close = client_close_proxy; + filter->name = "none"; + filter->code = ARCHIVE_COMPRESSION_NONE; + a->filter = filter; + + /* Build out the input pipeline. */ + e = choose_filters(a); + if (e < ARCHIVE_WARN) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + slot = choose_format(a); + if (slot < 0) { + close_filters(a); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + a->format = &(a->formats[slot]); + + a->archive.state = ARCHIVE_STATE_HEADER; + return (e); } /* @@ -350,146 +384,137 @@ archive_read_open2(struct archive *_a, void *client_data, * building the pipeline. */ static int -build_stream(struct archive_read *a) +choose_filters(struct archive_read *a) { - int number_bidders, i, bid, best_bid; - struct archive_read_filter_bidder *bidder, *best_bidder; - struct archive_read_filter *filter; - ssize_t avail; - int r; - - for (;;) { - number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]); - - best_bid = 0; - best_bidder = NULL; - - bidder = a->bidders; - for (i = 0; i < number_bidders; i++, bidder++) { - if (bidder->bid != NULL) { - bid = (bidder->bid)(bidder, a->filter); - if (bid > best_bid) { - best_bid = bid; - best_bidder = bidder; - } - } - } - - /* If no bidder, we're done. */ - if (best_bidder == NULL) { - a->archive.compression_name = a->filter->name; - a->archive.compression_code = a->filter->code; - return (ARCHIVE_OK); - } - - filter - = (struct archive_read_filter *)calloc(1, sizeof(*filter)); - if (filter == NULL) - return (ARCHIVE_FATAL); - filter->bidder = best_bidder; - filter->archive = a; - filter->upstream = a->filter; - r = (best_bidder->init)(filter); - if (r != ARCHIVE_OK) { - free(filter); - return (r); - } - /* Verify the filter by asking it for some data. */ - __archive_read_filter_ahead(filter, 1, &avail); - if (avail < 0) { - /* If the read failed, bail out now. */ - free(filter); - return (avail); - } - a->filter = filter; - } + int number_bidders, i, bid, best_bid; + struct archive_read_filter_bidder *bidder, *best_bidder; + struct archive_read_filter *filter; + ssize_t avail; + int r; + + for (;;) { + number_bidders = sizeof(a->bidders) / sizeof(a->bidders[0]); + + best_bid = 0; + best_bidder = NULL; + + bidder = a->bidders; + for (i = 0; i < number_bidders; i++, bidder++) { + if (bidder->bid != NULL) { + bid = (bidder->bid)(bidder, a->filter); + if (bid > best_bid) { + best_bid = bid; + best_bidder = bidder; + } + } + } + + /* If no bidder, we're done. */ + if (best_bidder == NULL) { + /* Verify the filter by asking it for some data. */ + __archive_read_filter_ahead(a->filter, 1, &avail); + if (avail < 0) { + close_filters(a); + free_filters(a); + return (ARCHIVE_FATAL); + } + a->archive.compression_name = a->filter->name; + a->archive.compression_code = a->filter->code; + return (ARCHIVE_OK); + } + + filter + = (struct archive_read_filter *)calloc(1, sizeof(*filter)); + if (filter == NULL) + return (ARCHIVE_FATAL); + filter->bidder = best_bidder; + filter->archive = a; + filter->upstream = a->filter; + a->filter = filter; + r = (best_bidder->init)(a->filter); + if (r != ARCHIVE_OK) { + close_filters(a); + free_filters(a); + return (ARCHIVE_FATAL); + } + } } /* * Read header of next entry. */ -int -archive_read_next_header2(struct archive *_a, struct archive_entry *entry) +static int +_archive_read_next_header2(struct archive *_a, struct archive_entry *entry) { - struct archive_read *a = (struct archive_read *)_a; - int slot, ret; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_read_next_header"); - - ++_a->file_count; - archive_entry_clear(entry); - archive_clear_error(&a->archive); - - /* - * If no format has yet been chosen, choose one. - */ - if (a->format == NULL) { - slot = choose_format(a); - if (slot < 0) { - a->archive.state = ARCHIVE_STATE_FATAL; - return (ARCHIVE_FATAL); - } - a->format = &(a->formats[slot]); - } - - /* - * If client didn't consume entire data, skip any remainder - * (This is especially important for GNU incremental directories.) - */ - if (a->archive.state == ARCHIVE_STATE_DATA) { - ret = archive_read_data_skip(&a->archive); - if (ret == ARCHIVE_EOF) { - archive_set_error(&a->archive, EIO, "Premature end-of-file."); - a->archive.state = ARCHIVE_STATE_FATAL; - return (ARCHIVE_FATAL); - } - if (ret != ARCHIVE_OK) - return (ret); - } - - /* Record start-of-header. */ - a->header_position = a->archive.file_position; - - ret = (a->format->read_header)(a, entry); - - /* - * EOF and FATAL are persistent at this layer. By - * modifying the state, we guarantee that future calls to - * read a header or read data will fail. - */ - switch (ret) { - case ARCHIVE_EOF: - a->archive.state = ARCHIVE_STATE_EOF; - break; - case ARCHIVE_OK: - a->archive.state = ARCHIVE_STATE_DATA; - break; - case ARCHIVE_WARN: - a->archive.state = ARCHIVE_STATE_DATA; - break; - case ARCHIVE_RETRY: - break; - case ARCHIVE_FATAL: - a->archive.state = ARCHIVE_STATE_FATAL; - break; - } - - a->read_data_output_offset = 0; - a->read_data_remaining = 0; - return (ret); + struct archive_read *a = (struct archive_read *)_a; + int r1 = ARCHIVE_OK, r2; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_read_next_header"); + + archive_entry_clear(entry); + archive_clear_error(&a->archive); + + /* + * If client didn't consume entire data, skip any remainder + * (This is especially important for GNU incremental directories.) + */ + if (a->archive.state == ARCHIVE_STATE_DATA) { + r1 = archive_read_data_skip(&a->archive); + if (r1 == ARCHIVE_EOF) + archive_set_error(&a->archive, EIO, + "Premature end-of-file."); + if (r1 == ARCHIVE_EOF || r1 == ARCHIVE_FATAL) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + } + + /* Record start-of-header offset in uncompressed stream. */ + a->header_position = a->filter->position; + + ++_a->file_count; + r2 = (a->format->read_header)(a, entry); + + /* + * EOF and FATAL are persistent at this layer. By + * modifying the state, we guarantee that future calls to + * read a header or read data will fail. + */ + switch (r2) { + case ARCHIVE_EOF: + a->archive.state = ARCHIVE_STATE_EOF; + --_a->file_count;/* Revert a file counter. */ + break; + case ARCHIVE_OK: + a->archive.state = ARCHIVE_STATE_DATA; + break; + case ARCHIVE_WARN: + a->archive.state = ARCHIVE_STATE_DATA; + break; + case ARCHIVE_RETRY: + break; + case ARCHIVE_FATAL: + a->archive.state = ARCHIVE_STATE_FATAL; + break; + } + + a->read_data_output_offset = 0; + a->read_data_remaining = 0; + /* EOF always wins; otherwise return the worst error. */ + return (r2 < r1 || r2 == ARCHIVE_EOF) ? r2 : r1; } int -archive_read_next_header(struct archive *_a, struct archive_entry **entryp) +_archive_read_next_header(struct archive *_a, struct archive_entry **entryp) { - int ret; - struct archive_read *a = (struct archive_read *)_a; - *entryp = NULL; - ret = archive_read_next_header2(_a, a->entry); - *entryp = a->entry; - return ret; + int ret; + struct archive_read *a = (struct archive_read *)_a; + *entryp = NULL; + ret = _archive_read_next_header2(_a, a->entry); + *entryp = a->entry; + return ret; } /* @@ -499,49 +524,52 @@ archive_read_next_header(struct archive *_a, struct archive_entry **entryp) static int choose_format(struct archive_read *a) { - int slots; - int i; - int bid, best_bid; - int best_bid_slot; - - slots = sizeof(a->formats) / sizeof(a->formats[0]); - best_bid = -1; - best_bid_slot = -1; - - /* Set up a->format and a->pformat_data for convenience of bidders. */ - a->format = &(a->formats[0]); - for (i = 0; i < slots; i++, a->format++) { - if (a->format->bid) { - bid = (a->format->bid)(a); - if (bid == ARCHIVE_FATAL) - return (ARCHIVE_FATAL); - if ((bid > best_bid) || (best_bid_slot < 0)) { - best_bid = bid; - best_bid_slot = i; - } - } - } - - /* - * There were no bidders; this is a serious programmer error - * and demands a quick and definitive abort. - */ - if (best_bid_slot < 0) - __archive_errx(1, "No formats were registered; you must " - "invoke at least one archive_read_support_format_XXX " - "function in order to successfully read an archive."); - - /* - * There were bidders, but no non-zero bids; this means we - * can't support this stream. - */ - if (best_bid < 1) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized archive format"); - return (ARCHIVE_FATAL); - } - - return (best_bid_slot); + int slots; + int i; + int bid, best_bid; + int best_bid_slot; + + slots = sizeof(a->formats) / sizeof(a->formats[0]); + best_bid = -1; + best_bid_slot = -1; + + /* Set up a->format for convenience of bidders. */ + a->format = &(a->formats[0]); + for (i = 0; i < slots; i++, a->format++) { + if (a->format->bid) { + bid = (a->format->bid)(a, best_bid); + if (bid == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + if (a->filter->position != 0) + __archive_read_seek(a, 0, SEEK_SET); + if ((bid > best_bid) || (best_bid_slot < 0)) { + best_bid = bid; + best_bid_slot = i; + } + } + } + + /* + * There were no bidders; this is a serious programmer error + * and demands a quick and definitive abort. + */ + if (best_bid_slot < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "No formats registered"); + return (ARCHIVE_FATAL); + } + + /* + * There were bidders, but no non-zero bids; this means we + * can't support this stream. + */ + if (best_bid < 1) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unrecognized archive format"); + return (ARCHIVE_FATAL); + } + + return (best_bid_slot); } /* @@ -551,10 +579,10 @@ choose_format(struct archive_read *a) int64_t archive_read_header_position(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_header_position"); - return (a->header_position); + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_header_position"); + return (a->header_position); } /* @@ -571,90 +599,74 @@ archive_read_header_position(struct archive *_a) ssize_t archive_read_data(struct archive *_a, void *buff, size_t s) { - struct archive_read *a = (struct archive_read *)_a; - char *dest; - const void *read_buf; - size_t bytes_read; - size_t len; - int r; - - bytes_read = 0; - dest = (char *)buff; - - while (s > 0) { - if (a->read_data_remaining == 0) { - read_buf = a->read_data_block; - r = archive_read_data_block(&a->archive, &read_buf, - &a->read_data_remaining, &a->read_data_offset); - a->read_data_block = read_buf; - if (r == ARCHIVE_EOF) - return (bytes_read); - /* - * Error codes are all negative, so the status - * return here cannot be confused with a valid - * byte count. (ARCHIVE_OK is zero.) - */ - if (r < ARCHIVE_OK) - return (r); - } - - if (a->read_data_offset < a->read_data_output_offset) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Encountered out-of-order sparse blocks"); - return (ARCHIVE_RETRY); - } - - /* Compute the amount of zero padding needed. */ - if (a->read_data_output_offset + (off_t)s < - a->read_data_offset) { - len = s; - } else if (a->read_data_output_offset < - a->read_data_offset) { - len = a->read_data_offset - - a->read_data_output_offset; - } else - len = 0; - - /* Add zeroes. */ - memset(dest, 0, len); - s -= len; - a->read_data_output_offset += len; - dest += len; - bytes_read += len; - - /* Copy data if there is any space left. */ - if (s > 0) { - len = a->read_data_remaining; - if (len > s) - len = s; - 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; - } - } - return (bytes_read); -} - -#if ARCHIVE_API_VERSION < 3 -/* - * Obsolete function provided for compatibility only. Note that the API - * of this function doesn't allow the caller to detect if the remaining - * data from the archive entry is shorter than the buffer provided, or - * even if an error occurred while reading data. - */ -int -archive_read_data_into_buffer(struct archive *a, void *d, ssize_t len) -{ - - archive_read_data(a, d, len); - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + char *dest; + const void *read_buf; + size_t bytes_read; + size_t len; + int r; + + bytes_read = 0; + dest = (char *)buff; + + while (s > 0) { + if (a->read_data_remaining == 0) { + read_buf = a->read_data_block; + r = _archive_read_data_block(&a->archive, &read_buf, + &a->read_data_remaining, &a->read_data_offset); + a->read_data_block = read_buf; + if (r == ARCHIVE_EOF) + return (bytes_read); + /* + * Error codes are all negative, so the status + * return here cannot be confused with a valid + * byte count. (ARCHIVE_OK is zero.) + */ + if (r < ARCHIVE_OK) + return (r); + } + + if (a->read_data_offset < a->read_data_output_offset) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Encountered out-of-order sparse blocks"); + return (ARCHIVE_RETRY); + } + + /* Compute the amount of zero padding needed. */ + if (a->read_data_output_offset + s < + a->read_data_offset) { + len = s; + } else if (a->read_data_output_offset < + a->read_data_offset) { + len = a->read_data_offset - + a->read_data_output_offset; + } else + len = 0; + + /* Add zeroes. */ + memset(dest, 0, len); + s -= len; + a->read_data_output_offset += len; + dest += len; + bytes_read += len; + + /* Copy data if there is any space left. */ + if (s > 0) { + len = a->read_data_remaining; + if (len > s) + len = s; + 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; + } + } + return (bytes_read); } -#endif /* * Skip over all remaining data in this entry. @@ -662,29 +674,29 @@ archive_read_data_into_buffer(struct archive *a, void *d, ssize_t len) int archive_read_data_skip(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - int r; - const void *buff; - size_t size; - off_t offset; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, - "archive_read_data_skip"); - - if (a->format->read_data_skip != NULL) - r = (a->format->read_data_skip)(a); - else { - while ((r = archive_read_data_block(&a->archive, - &buff, &size, &offset)) - == ARCHIVE_OK) - ; - } - - if (r == ARCHIVE_EOF) - r = ARCHIVE_OK; - - a->archive.state = ARCHIVE_STATE_HEADER; - return (r); + struct archive_read *a = (struct archive_read *)_a; + int r; + const void *buff; + size_t size; + int64_t offset; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_skip"); + + if (a->format->read_data_skip != NULL) + r = (a->format->read_data_skip)(a); + else { + while ((r = archive_read_data_block(&a->archive, + &buff, &size, &offset)) + == ARCHIVE_OK) + ; + } + + if (r == ARCHIVE_EOF) + r = ARCHIVE_OK; + + a->archive.state = ARCHIVE_STATE_HEADER; + return (r); } /* @@ -695,108 +707,193 @@ archive_read_data_skip(struct archive *_a) * Returns ARCHIVE_OK if the operation is successful, ARCHIVE_EOF if * the end of entry is encountered. */ -int -archive_read_data_block(struct archive *_a, - const void **buff, size_t *size, off_t *offset) +static int +_archive_read_data_block(struct archive *_a, + const void **buff, size_t *size, int64_t *offset) { - struct archive_read *a = (struct archive_read *)_a; - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, - "archive_read_data_block"); - - if (a->format->read_data == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Internal error: " - "No format_read_data_block function registered"); - return (ARCHIVE_FATAL); - } - - return (a->format->read_data)(a, buff, size, offset); + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_block"); + + if (a->format->read_data == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, + "Internal error: " + "No format_read_data_block function registered"); + return (ARCHIVE_FATAL); + } + + return (a->format->read_data)(a, buff, size, offset); +} + +static int +close_filters(struct archive_read *a) +{ + struct archive_read_filter *f = a->filter; + int r = ARCHIVE_OK; + /* Close each filter in the pipeline. */ + while (f != NULL) { + struct archive_read_filter *t = f->upstream; + if (!f->closed && f->close != NULL) { + int r1 = (f->close)(f); + f->closed = 1; + if (r1 < r) + r = r1; + } + free(f->buffer); + f->buffer = NULL; + f = t; + } + return r; +} + +static void +free_filters(struct archive_read *a) +{ + while (a->filter != NULL) { + struct archive_read_filter *t = a->filter->upstream; + free(a->filter); + a->filter = t; + } } /* - * Close the file and release most resources. - * - * Be careful: client might just call read_new and then read_finish. - * Don't assume we actually read anything or performed any non-trivial - * initialization. + * return the count of # of filters in use + */ +static int +_archive_filter_count(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter *p = a->filter; + int count = 0; + while(p) { + count++; + p = p->upstream; + } + return count; +} + +/* + * Close the file and all I/O. */ static int _archive_read_close(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - int r = ARCHIVE_OK, r1 = ARCHIVE_OK; - size_t i, n; - - __archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_close"); - archive_clear_error(&a->archive); - a->archive.state = ARCHIVE_STATE_CLOSED; - - - /* Call cleanup functions registered by optional components. */ - if (a->cleanup_archive_extract != NULL) - r = (a->cleanup_archive_extract)(a); - - /* TODO: Clean up the formatters. */ - - /* Clean up the filter pipeline. */ - while (a->filter != NULL) { - struct archive_read_filter *t = a->filter->upstream; - if (a->filter->close != NULL) { - r1 = (a->filter->close)(a->filter); - if (r1 < r) - r = r1; - } - free(a->filter->buffer); - free(a->filter); - a->filter = t; - } - - /* Release the bidder objects. */ - n = sizeof(a->bidders)/sizeof(a->bidders[0]); - for (i = 0; i < n; i++) { - if (a->bidders[i].free != NULL) { - r1 = (a->bidders[i].free)(&a->bidders[i]); - if (r1 < r) - r = r1; - } - } - - return (r); + struct archive_read *a = (struct archive_read *)_a; + int r = ARCHIVE_OK, r1 = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close"); + if (a->archive.state == ARCHIVE_STATE_CLOSED) + return (ARCHIVE_OK); + archive_clear_error(&a->archive); + a->archive.state = ARCHIVE_STATE_CLOSED; + + /* TODO: Clean up the formatters. */ + + /* Release the filter objects. */ + r1 = close_filters(a); + if (r1 < r) + r = r1; + + return (r); } /* * Release memory and other resources. */ static int -_archive_read_finish(struct archive *_a) +_archive_read_free(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - int i; - int slots; - int r = ARCHIVE_OK; - - __archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_ANY, - "archive_read_finish"); - if (a->archive.state != ARCHIVE_STATE_CLOSED) - r = archive_read_close(&a->archive); - - /* Cleanup format-specific data. */ - slots = sizeof(a->formats) / sizeof(a->formats[0]); - for (i = 0; i < slots; i++) { - a->format = &(a->formats[i]); - if (a->formats[i].cleanup) - (a->formats[i].cleanup)(a); - } - - archive_string_free(&a->archive.error_string); - if (a->entry) - archive_entry_free(a->entry); - a->archive.magic = 0; - free(a); -#if ARCHIVE_API_VERSION > 1 - return (r); -#endif + struct archive_read *a = (struct archive_read *)_a; + int i, n; + int slots; + int r = ARCHIVE_OK; + + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free"); + if (a->archive.state != ARCHIVE_STATE_CLOSED + && a->archive.state != ARCHIVE_STATE_FATAL) + r = archive_read_close(&a->archive); + + /* Call cleanup functions registered by optional components. */ + if (a->cleanup_archive_extract != NULL) + r = (a->cleanup_archive_extract)(a); + + /* Cleanup format-specific data. */ + slots = sizeof(a->formats) / sizeof(a->formats[0]); + for (i = 0; i < slots; i++) { + a->format = &(a->formats[i]); + if (a->formats[i].cleanup) + (a->formats[i].cleanup)(a); + } + + /* Free the filters */ + free_filters(a); + + /* Release the bidder objects. */ + n = sizeof(a->bidders)/sizeof(a->bidders[0]); + for (i = 0; i < n; i++) { + if (a->bidders[i].free != NULL) { + int r1 = (a->bidders[i].free)(&a->bidders[i]); + if (r1 < r) + r = r1; + } + } + + archive_string_free(&a->archive.error_string); + if (a->entry) + archive_entry_free(a->entry); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a); + return (r); +} + +static struct archive_read_filter * +get_filter(struct archive *_a, int n) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter *f = a->filter; + /* We use n == -1 for 'the last filter', which is always the client proxy. */ + if (n == -1 && f != NULL) { + struct archive_read_filter *last = f; + f = f->upstream; + while (f != NULL) { + last = f; + f = f->upstream; + } + return (last); + } + if (n < 0) + return NULL; + while (n > 0 && f != NULL) { + f = f->upstream; + --n; + } + return (f); +} + +static int +_archive_filter_code(struct archive *_a, int n) +{ + struct archive_read_filter *f = get_filter(_a, n); + return f == NULL ? -1 : f->code; +} + +static const char * +_archive_filter_name(struct archive *_a, int n) +{ + struct archive_read_filter *f = get_filter(_a, n); + return f != NULL ? f->name : NULL; +} + +static int64_t +_archive_filter_bytes(struct archive *_a, int n) +{ + struct archive_read_filter *f = get_filter(_a, n); + return f == NULL ? -1 : f->position; } /* @@ -807,105 +904,99 @@ int __archive_read_register_format(struct archive_read *a, void *format_data, const char *name, - int (*bid)(struct archive_read *), + int (*bid)(struct archive_read *, int), int (*options)(struct archive_read *, const char *, const char *), int (*read_header)(struct archive_read *, struct archive_entry *), - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *), + int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *), int (*read_data_skip)(struct archive_read *), int (*cleanup)(struct archive_read *)) { - int i, number_slots; - - __archive_check_magic(&a->archive, - ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "__archive_read_register_format"); - - number_slots = sizeof(a->formats) / sizeof(a->formats[0]); - - for (i = 0; i < number_slots; i++) { - if (a->formats[i].bid == bid) - return (ARCHIVE_WARN); /* We've already installed */ - if (a->formats[i].bid == NULL) { - a->formats[i].bid = bid; - a->formats[i].options = options; - a->formats[i].read_header = read_header; - a->formats[i].read_data = read_data; - a->formats[i].read_data_skip = read_data_skip; - a->formats[i].cleanup = cleanup; - a->formats[i].data = format_data; - a->formats[i].name = name; - return (ARCHIVE_OK); - } - } - - __archive_errx(1, "Not enough slots for format registration"); - return (ARCHIVE_FATAL); /* Never actually called. */ + int i, number_slots; + + archive_check_magic(&a->archive, + ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "__archive_read_register_format"); + + number_slots = sizeof(a->formats) / sizeof(a->formats[0]); + + for (i = 0; i < number_slots; i++) { + if (a->formats[i].bid == bid) + return (ARCHIVE_WARN); /* We've already installed */ + if (a->formats[i].bid == NULL) { + a->formats[i].bid = bid; + a->formats[i].options = options; + a->formats[i].read_header = read_header; + a->formats[i].read_data = read_data; + a->formats[i].read_data_skip = read_data_skip; + a->formats[i].cleanup = cleanup; + a->formats[i].data = format_data; + a->formats[i].name = name; + return (ARCHIVE_OK); + } + } + + archive_set_error(&a->archive, ENOMEM, + "Not enough slots for format registration"); + return (ARCHIVE_FATAL); } /* * Used internally by decompression routines to register their bid and * initialization functions. */ -struct archive_read_filter_bidder * -__archive_read_get_bidder(struct archive_read *a) +int +__archive_read_get_bidder(struct archive_read *a, + struct archive_read_filter_bidder **bidder) { - int i, number_slots; + int i, number_slots; - __archive_check_magic(&a->archive, - ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, - "__archive_read_get_bidder"); + number_slots = sizeof(a->bidders) / sizeof(a->bidders[0]); - number_slots = sizeof(a->bidders) / sizeof(a->bidders[0]); + for (i = 0; i < number_slots; i++) { + if (a->bidders[i].bid == NULL) { + memset(a->bidders + i, 0, sizeof(a->bidders[0])); + *bidder = (a->bidders + i); + return (ARCHIVE_OK); + } + } - for (i = 0; i < number_slots; i++) { - if (a->bidders[i].bid == NULL) { - memset(a->bidders + i, 0, sizeof(a->bidders[0])); - return (a->bidders + i); - } - } - - __archive_errx(1, "Not enough slots for compression registration"); - return (NULL); /* Never actually executed. */ + archive_set_error(&a->archive, ENOMEM, + "Not enough slots for filter registration"); + return (ARCHIVE_FATAL); } /* - * The next three functions comprise the peek/consume internal I/O - * system used by archive format readers. This system allows fairly - * flexible read-ahead and allows the I/O code to operate in a - * zero-copy manner most of the time. + * The next section implements the peek/consume internal I/O + * system used by archive readers. This system allows simple + * read-ahead for consumers while preserving zero-copy operation + * most of the time. + * + * The two key operations: + * * The read-ahead function returns a pointer to a block of data + * that satisfies a minimum request. + * * The consume function advances the file pointer. * * In the ideal case, filters generate blocks of data * and __archive_read_ahead() just returns pointers directly into * those blocks. Then __archive_read_consume() just bumps those * pointers. Only if your request would span blocks does the I/O * layer use a copy buffer to provide you with a contiguous block of - * data. The __archive_read_skip() is an optimization; it scans ahead - * very quickly (it usually translates into a seek() operation if - * you're reading uncompressed disk files). + * data. * * A couple of useful idioms: * * "I just want some data." Ask for 1 byte and pay attention to * the "number of bytes available" from __archive_read_ahead(). - * You can consume more than you asked for; you just can't consume - * more than is available. If you consume everything that's - * immediately available, the next read_ahead() call will pull - * the next block. + * Consume whatever you actually use. * * "I want to output a large block of data." As above, ask for 1 byte, - * emit all that's available (up to whatever limit you have), then - * repeat until you're done. + * emit all that's available (up to whatever limit you have), consume + * it all, then repeat until you're done. This effectively means that + * you're passing along the blocks that came from your provider. * * "I want to peek ahead by a large amount." Ask for 4k or so, then * double and repeat until you get an error or have enough. Note * that the I/O layer will likely end up expanding its copy buffer * to fit your request, so use this technique cautiously. This * technique is used, for example, by some of the format tasting * code that has uncertain look-ahead needs. - * - * TODO: Someday, provide a more generic __archive_read_seek() for - * those cases where it's useful. This is tricky because there are lots - * of cases where seek() is not available (reading gzip data from a - * network socket, for instance), so there needs to be a good way to - * communicate whether seek() is available and users of that interface - * need to use non-seeking strategies whenever seek() is not available. */ /* @@ -914,8 +1005,8 @@ __archive_read_get_bidder(struct archive_read *a) * in the current buffer, which may be much larger than requested. * * If end-of-file, *avail gets set to zero. * * If error, *avail gets error code. - * * If request can be met, returns pointer to data, returns NULL - * if request is not met. + * * If request can be met, returns pointer to data. + * * If minimum request cannot be met, returns NULL. * * Note: If you just want "some data", ask for 1 byte and pay attention * to *avail, which will have the actual amount available. If you @@ -925,317 +1016,327 @@ __archive_read_get_bidder(struct archive_read *a) * Important: This does NOT move the file pointer. See * __archive_read_consume() below. */ - -/* - * This is tricky. We need to provide our clients with pointers to - * contiguous blocks of memory but we want to avoid copying whenever - * possible. - * - * Mostly, this code returns pointers directly into the block of data - * provided by the client_read routine. It can do this unless the - * request would split across blocks. In that case, we have to copy - * into an internal buffer to combine reads. - */ const void * __archive_read_ahead(struct archive_read *a, size_t min, ssize_t *avail) { - return (__archive_read_filter_ahead(a->filter, min, avail)); + return (__archive_read_filter_ahead(a->filter, min, avail)); } const void * __archive_read_filter_ahead(struct archive_read_filter *filter, size_t min, ssize_t *avail) { - ssize_t bytes_read; - size_t tocopy; - - if (filter->fatal) { - if (avail) - *avail = ARCHIVE_FATAL; - return (NULL); - } - - /* - * Keep pulling more data until we can satisfy the request. - */ - for (;;) { - - /* - * If we can satisfy from the copy buffer (and the - * copy buffer isn't empty), we're done. In particular, - * note that min == 0 is a perfectly well-defined - * request. - */ - if (filter->avail >= min && filter->avail > 0) { - if (avail != NULL) - *avail = filter->avail; - return (filter->next); - } - - /* - * We can satisfy directly from client buffer if everything - * currently in the copy buffer is still in the client buffer. - */ - if (filter->client_total >= filter->client_avail + filter->avail - && filter->client_avail + filter->avail >= min) { - /* "Roll back" to client buffer. */ - filter->client_avail += filter->avail; - filter->client_next -= filter->avail; - /* Copy buffer is now empty. */ - filter->avail = 0; - filter->next = filter->buffer; - /* Return data from client buffer. */ - if (avail != NULL) - *avail = filter->client_avail; - return (filter->client_next); - } - - /* Move data forward in copy buffer if necessary. */ - if (filter->next > filter->buffer && - filter->next + min > filter->buffer + filter->buffer_size) { - if (filter->avail > 0) - memmove(filter->buffer, filter->next, filter->avail); - filter->next = filter->buffer; - } - - /* If we've used up the client data, get more. */ - if (filter->client_avail <= 0) { - if (filter->end_of_file) { - if (avail != NULL) - *avail = 0; - return (NULL); - } - bytes_read = (filter->read)(filter, - &filter->client_buff); - if (bytes_read < 0) { /* Read error. */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - if (bytes_read == 0) { /* Premature end-of-file. */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->end_of_file = 1; - /* Return whatever we do have. */ - if (avail != NULL) - *avail = filter->avail; - return (NULL); - } - filter->position += bytes_read; - filter->client_total = bytes_read; - filter->client_avail = filter->client_total; - filter->client_next = filter->client_buff; - } - else - { - /* - * We can't satisfy the request from the copy - * buffer or the existing client data, so we - * need to copy more client data over to the - * copy buffer. - */ - - /* Ensure the buffer is big enough. */ - if (min > filter->buffer_size) { - size_t s, t; - char *p; - - /* Double the buffer; watch for overflow. */ - s = t = filter->buffer_size; - if (s == 0) - s = min; - while (s < min) { - t *= 2; - if (t <= s) { /* Integer overflow! */ - archive_set_error( - &filter->archive->archive, - ENOMEM, - "Unable to allocate copy buffer"); - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - s = t; - } - /* Now s >= min, so allocate a new buffer. */ - p = (char *)malloc(s); - if (p == NULL) { - archive_set_error( - &filter->archive->archive, - ENOMEM, - "Unable to allocate copy buffer"); - filter->fatal = 1; - if (avail != NULL) - *avail = ARCHIVE_FATAL; - return (NULL); - } - /* Move data into newly-enlarged buffer. */ - if (filter->avail > 0) - memmove(p, filter->next, filter->avail); - free(filter->buffer); - filter->next = filter->buffer = p; - filter->buffer_size = s; - } - - /* We can add client data to copy buffer. */ - /* First estimate: copy to fill rest of buffer. */ - tocopy = (filter->buffer + filter->buffer_size) - - (filter->next + filter->avail); - /* Don't waste time buffering more than we need to. */ - if (tocopy + filter->avail > min) - tocopy = min - filter->avail; - /* Don't copy more than is available. */ - if (tocopy > filter->client_avail) - tocopy = filter->client_avail; - - memcpy(filter->next + filter->avail, filter->client_next, - tocopy); - /* Remove this data from client buffer. */ - filter->client_next += tocopy; - filter->client_avail -= tocopy; - /* add it to copy buffer. */ - filter->avail += tocopy; - } - } + ssize_t bytes_read; + size_t tocopy; + + if (filter->fatal) { + if (avail) + *avail = ARCHIVE_FATAL; + return (NULL); + } + + /* + * Keep pulling more data until we can satisfy the request. + */ + for (;;) { + + /* + * If we can satisfy from the copy buffer (and the + * copy buffer isn't empty), we're done. In particular, + * note that min == 0 is a perfectly well-defined + * request. + */ + if (filter->avail >= min && filter->avail > 0) { + if (avail != NULL) + *avail = filter->avail; + return (filter->next); + } + + /* + * We can satisfy directly from client buffer if everything + * currently in the copy buffer is still in the client buffer. + */ + if (filter->client_total >= filter->client_avail + filter->avail + && filter->client_avail + filter->avail >= min) { + /* "Roll back" to client buffer. */ + filter->client_avail += filter->avail; + filter->client_next -= filter->avail; + /* Copy buffer is now empty. */ + filter->avail = 0; + filter->next = filter->buffer; + /* Return data from client buffer. */ + if (avail != NULL) + *avail = filter->client_avail; + return (filter->client_next); + } + + /* Move data forward in copy buffer if necessary. */ + if (filter->next > filter->buffer && + filter->next + min > filter->buffer + filter->buffer_size) { + if (filter->avail > 0) + memmove(filter->buffer, filter->next, filter->avail); + filter->next = filter->buffer; + } + + /* If we've used up the client data, get more. */ + if (filter->client_avail <= 0) { + if (filter->end_of_file) { + if (avail != NULL) + *avail = 0; + return (NULL); + } + bytes_read = (filter->read)(filter, + &filter->client_buff); + if (bytes_read < 0) { /* Read error. */ + filter->client_total = filter->client_avail = 0; + filter->client_next = filter->client_buff = NULL; + filter->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + if (bytes_read == 0) { /* Premature end-of-file. */ + filter->client_total = filter->client_avail = 0; + filter->client_next = filter->client_buff = NULL; + filter->end_of_file = 1; + /* Return whatever we do have. */ + if (avail != NULL) + *avail = filter->avail; + return (NULL); + } + filter->client_total = bytes_read; + filter->client_avail = filter->client_total; + filter->client_next = filter->client_buff; + } + else + { + /* + * We can't satisfy the request from the copy + * buffer or the existing client data, so we + * need to copy more client data over to the + * copy buffer. + */ + + /* Ensure the buffer is big enough. */ + if (min > filter->buffer_size) { + size_t s, t; + char *p; + + /* Double the buffer; watch for overflow. */ + s = t = filter->buffer_size; + if (s == 0) + s = min; + while (s < min) { + t *= 2; + if (t <= s) { /* Integer overflow! */ + archive_set_error( + &filter->archive->archive, + ENOMEM, + "Unable to allocate copy buffer"); + filter->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + s = t; + } + /* Now s >= min, so allocate a new buffer. */ + p = (char *)malloc(s); + if (p == NULL) { + archive_set_error( + &filter->archive->archive, + ENOMEM, + "Unable to allocate copy buffer"); + filter->fatal = 1; + if (avail != NULL) + *avail = ARCHIVE_FATAL; + return (NULL); + } + /* Move data into newly-enlarged buffer. */ + if (filter->avail > 0) + memmove(p, filter->next, filter->avail); + free(filter->buffer); + filter->next = filter->buffer = p; + filter->buffer_size = s; + } + + /* We can add client data to copy buffer. */ + /* First estimate: copy to fill rest of buffer. */ + tocopy = (filter->buffer + filter->buffer_size) + - (filter->next + filter->avail); + /* Don't waste time buffering more than we need to. */ + if (tocopy + filter->avail > min) + tocopy = min - filter->avail; + /* Don't copy more than is available. */ + if (tocopy > filter->client_avail) + tocopy = filter->client_avail; + + memcpy(filter->next + filter->avail, filter->client_next, + tocopy); + /* Remove this data from client buffer. */ + filter->client_next += tocopy; + filter->client_avail -= tocopy; + /* add it to copy buffer. */ + filter->avail += tocopy; + } + } } /* - * Move the file pointer forward. This should be called after - * __archive_read_ahead() returns data to you. Don't try to move - * ahead by more than the amount of data available according to - * __archive_read_ahead(). + * Move the file pointer forward. */ -/* - * Mark the appropriate data as used. Note that the request here will - * often be much smaller than the size of the previous read_ahead - * request. - */ -ssize_t -__archive_read_consume(struct archive_read *a, size_t request) +int64_t +__archive_read_consume(struct archive_read *a, int64_t request) { - ssize_t r; - r = __archive_read_filter_consume(a->filter, request); - a->archive.file_position += r; - return (r); + return (__archive_read_filter_consume(a->filter, request)); } -ssize_t +int64_t __archive_read_filter_consume(struct archive_read_filter * filter, - size_t request) + int64_t request) { - if (filter->avail > 0) { - /* Read came from copy buffer. */ - filter->next += request; - filter->avail -= request; - } else { - /* Read came from client buffer. */ - filter->client_next += request; - filter->client_avail -= request; - } - return (request); + int64_t skipped; + + if (request == 0) + return 0; + + skipped = advance_file_pointer(filter, request); + if (skipped == request) + return (skipped); + /* We hit EOF before we satisfied the skip request. */ + if (skipped < 0) /* Map error code to 0 for error message below. */ + skipped = 0; + archive_set_error(&filter->archive->archive, + ARCHIVE_ERRNO_MISC, + "Truncated input file (needed %jd bytes, only %jd available)", + (intmax_t)request, (intmax_t)skipped); + return (ARCHIVE_FATAL); } /* - * Move the file pointer ahead by an arbitrary amount. If you're - * reading uncompressed data from a disk file, this will actually - * translate into a seek() operation. Even in cases where seek() - * isn't feasible, this at least pushes the read-and-discard loop - * down closer to the data source. + * Advance the file pointer by the amount requested. + * Returns the amount actually advanced, which may be less than the + * request if EOF is encountered first. + * Returns a negative value if there's an I/O error. */ -int64_t -__archive_read_skip(struct archive_read *a, int64_t request) +static int64_t +advance_file_pointer(struct archive_read_filter *filter, int64_t request) { - int64_t skipped = __archive_read_skip_lenient(a, request); - if (skipped == request) - return (skipped); - /* We hit EOF before we satisfied the skip request. */ - if (skipped < 0) /* Map error code to 0 for error message below. */ - skipped = 0; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Truncated input file (needed %jd bytes, only %jd available)", - (intmax_t)request, (intmax_t)skipped); - return (ARCHIVE_FATAL); + int64_t bytes_skipped, total_bytes_skipped = 0; + ssize_t bytes_read; + size_t min; + + if (filter->fatal) + return (-1); + + /* Use up the copy buffer first. */ + if (filter->avail > 0) { + min = minimum(request, (int64_t)filter->avail); + filter->next += min; + filter->avail -= min; + request -= min; + filter->position += min; + total_bytes_skipped += min; + } + + /* Then use up the client buffer. */ + if (filter->client_avail > 0) { + min = minimum(request, (int64_t)filter->client_avail); + filter->client_next += min; + filter->client_avail -= min; + request -= min; + filter->position += min; + total_bytes_skipped += min; + } + if (request == 0) + return (total_bytes_skipped); + + /* If there's an optimized skip function, use it. */ + if (filter->skip != NULL) { + bytes_skipped = (filter->skip)(filter, request); + if (bytes_skipped < 0) { /* error */ + filter->fatal = 1; + return (bytes_skipped); + } + filter->position += bytes_skipped; + total_bytes_skipped += bytes_skipped; + request -= bytes_skipped; + if (request == 0) + return (total_bytes_skipped); + } + + /* Use ordinary reads as necessary to complete the request. */ + for (;;) { + bytes_read = (filter->read)(filter, &filter->client_buff); + if (bytes_read < 0) { + filter->client_buff = NULL; + filter->fatal = 1; + return (bytes_read); + } + + if (bytes_read == 0) { + filter->client_buff = NULL; + filter->end_of_file = 1; + return (total_bytes_skipped); + } + + if (bytes_read >= request) { + filter->client_next = + ((const char *)filter->client_buff) + request; + filter->client_avail = bytes_read - request; + filter->client_total = bytes_read; + total_bytes_skipped += request; + filter->position += request; + return (total_bytes_skipped); + } + + filter->position += bytes_read; + total_bytes_skipped += bytes_read; + request -= bytes_read; + } } +/** + * Returns ARCHIVE_FAILED if seeking isn't supported. + */ int64_t -__archive_read_skip_lenient(struct archive_read *a, int64_t request) +__archive_read_seek(struct archive_read *a, int64_t offset, int whence) { - int64_t skipped = __archive_read_filter_skip(a->filter, request); - if (skipped > 0) - a->archive.file_position += skipped; - return (skipped); + return __archive_read_filter_seek(a->filter, offset, whence); } int64_t -__archive_read_filter_skip(struct archive_read_filter *filter, int64_t request) +__archive_read_filter_seek(struct archive_read_filter *filter, int64_t offset, int whence) { - int64_t bytes_skipped, total_bytes_skipped = 0; - size_t min; - - if (filter->fatal) - return (-1); - /* - * If there is data in the buffers already, use that first. - */ - if (filter->avail > 0) { - min = minimum(request, (off_t)filter->avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (filter->client_avail > 0) { - min = minimum(request, (int64_t)filter->client_avail); - bytes_skipped = __archive_read_filter_consume(filter, min); - request -= bytes_skipped; - total_bytes_skipped += bytes_skipped; - } - if (request == 0) - return (total_bytes_skipped); - /* - * If a client_skipper was provided, try that first. - */ -#if ARCHIVE_API_VERSION < 2 - if ((filter->skip != NULL) && (request < SSIZE_MAX)) { -#else - if (filter->skip != NULL) { -#endif - bytes_skipped = (filter->skip)(filter, request); - if (bytes_skipped < 0) { /* error */ - filter->client_total = filter->client_avail = 0; - filter->client_next = filter->client_buff = NULL; - filter->fatal = 1; - return (bytes_skipped); - } - total_bytes_skipped += bytes_skipped; - request -= bytes_skipped; - filter->client_next = filter->client_buff; - filter->client_avail = filter->client_total = 0; - } - /* - * Note that client_skipper will usually not satisfy the - * full request (due to low-level blocking concerns), - * so even if client_skipper is provided, we may still - * have to use ordinary reads to finish out the request. - */ - while (request > 0) { - const void* dummy_buffer; - ssize_t bytes_read; - dummy_buffer = __archive_read_filter_ahead(filter, - 1, &bytes_read); - if (bytes_read < 0) - return (bytes_read); - if (bytes_read == 0) { - return (total_bytes_skipped); - } - min = (size_t)(minimum(bytes_read, request)); - bytes_read = __archive_read_filter_consume(filter, min); - total_bytes_skipped += bytes_read; - request -= bytes_read; - } - return (total_bytes_skipped); + int64_t r; + + if (filter->closed || filter->fatal) + return (ARCHIVE_FATAL); + if (filter->seek == NULL) + return (ARCHIVE_FAILED); + r = filter->seek(filter, offset, whence); + if (r >= 0) { + /* + * Ouch. Clearing the buffer like this hurts, especially + * at bid time. A lot of our efficiency at bid time comes + * from having bidders reuse the data we've already read. + * + * TODO: If the seek request is in data we already + * have, then don't call the seek callback. + * + * TODO: Zip seeks to end-of-file at bid time. If + * other formats also start doing this, we may need to + * find a way for clients to fudge the seek offset to + * a block boundary. + * + * Hmmm... If whence was SEEK_END, we know the file + * size is (r - offset). Can we use that to simplify + * the TODO items above? + */ + filter->avail = filter->client_avail = 0; + filter->next = filter->buffer; + filter->position = r; + filter->end_of_file = 0; + } + return r; } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_data.3 b/Utilities/cmlibarchive/libarchive/archive_read_data.3 new file mode 100644 index 000000000..78d049782 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_data.3 @@ -0,0 +1,128 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 22, 2011 +.Dt ARCHIVE_READ_DATA 3 +.Os +.Sh NAME +.Nm archive_read_data +.Nm archive_read_data_block , +.Nm archive_read_data_skip , +.Nm archive_read_data_into_fd +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft ssize_t +.Fn archive_read_data "struct archive *" "void *buff" "size_t len" +.Ft int +.Fo archive_read_data_block +.Fa "struct archive *" +.Fa "const void **buff" +.Fa "size_t *len" +.Fa "off_t *offset" +.Fc +.Ft int +.Fn archive_read_data_skip "struct archive *" +.Ft int +.Fn archive_read_data_into_fd "struct archive *" "int fd" +.\" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Fn archive_read_data +Read data associated with the header just read. +Internally, this is a convenience function that calls +.Fn archive_read_data_block +and fills any gaps with nulls so that callers see a single +continuous stream of data. +.It Fn archive_read_data_block +Return the next available block of data for this entry. +Unlike +.Fn archive_read_data , +the +.Fn archive_read_data_block +function avoids copying data and allows you to correctly handle +sparse files, as supported by some archive formats. +The library guarantees that offsets will increase and that blocks +will not overlap. +Note that the blocks returned from this function can be much larger +than the block size read from disk, due to compression +and internal buffer optimizations. +.It Fn archive_read_data_skip +A convenience function that repeatedly calls +.Fn archive_read_data_block +to skip all of the data for this archive entry. +Note that this function is invoked automatically by +.Fn archive_read_next_header2 +if the previous entry was not completely consumed. +.It Fn archive_read_data_into_fd +A convenience function that repeatedly calls +.Fn archive_read_data_block +to copy the entire entry to the provided file descriptor. +.El +.\" +.Sh RETURN VALUES +Most functions return zero on success, non-zero on error. +The possible return codes include: +.Cm ARCHIVE_OK +(the operation succeeded), +.Cm ARCHIVE_WARN +(the operation succeeded but a non-critical error was encountered), +.Cm ARCHIVE_EOF +(end-of-archive was encountered), +.Cm ARCHIVE_RETRY +(the operation failed but can be retried), +and +.Cm ARCHIVE_FATAL +(there was a fatal error; the archive should be closed immediately). +.Pp +.Fn archive_read_data +returns a count of bytes actually read or zero at the end of the entry. +On error, a value of +.Cm ARCHIVE_FATAL , +.Cm ARCHIVE_WARN , +or +.Cm ARCHIVE_RETRY +is returned. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_extract 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_header 3 , +.Xr archive_read_open 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c index 0628a1e0c..14f941070 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_data_into_fd.c @@ -40,54 +40,100 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_data_into_fd.c,v 1.16 2008/0 #include "archive_private.h" /* Maximum amount of data to write at one time. */ -#define MAX_WRITE (1024 * 1024) +#define MAX_WRITE (1024 * 1024) /* * This implementation minimizes copying of data and is sparse-file aware. */ +static int +pad_to(struct archive *a, int fd, int can_lseek, + size_t nulls_size, const char *nulls, + int64_t target_offset, int64_t actual_offset) +{ + size_t to_write; + ssize_t bytes_written; + + if (can_lseek) { + actual_offset = lseek(fd, + target_offset - actual_offset, SEEK_CUR); + if (actual_offset != target_offset) { + archive_set_error(a, errno, "Seek error"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); + } + while (target_offset > actual_offset) { + to_write = nulls_size; + if (target_offset < actual_offset + nulls_size) + to_write = (size_t)(target_offset - actual_offset); + bytes_written = write(fd, nulls, to_write); + if (bytes_written < 0) { + archive_set_error(a, errno, "Write error"); + return (ARCHIVE_FATAL); + } + actual_offset += bytes_written; + } + return (ARCHIVE_OK); +} + + int archive_read_data_into_fd(struct archive *a, int fd) { - int r; - const void *buff; - size_t size, bytes_to_write; - ssize_t bytes_written, total_written; - off_t offset; - off_t output_offset; + struct stat st; + int r, r2; + const void *buff; + size_t size, bytes_to_write; + ssize_t bytes_written; + int64_t target_offset; + int64_t actual_offset = 0; + int can_lseek; + char *nulls = NULL; + size_t nulls_size = 16384; + + archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_into_fd"); - __archive_check_magic(a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_DATA, "archive_read_data_into_fd"); + can_lseek = (fstat(fd, &st) == 0) && S_ISREG(st.st_mode); + if (!can_lseek) + nulls = calloc(1, nulls_size); - total_written = 0; - output_offset = 0; + while ((r = archive_read_data_block(a, &buff, &size, &target_offset)) == + ARCHIVE_OK) { + const char *p = buff; + if (target_offset > actual_offset) { + r = pad_to(a, fd, can_lseek, nulls_size, nulls, + target_offset, actual_offset); + if (r != ARCHIVE_OK) + break; + actual_offset = target_offset; + } + while (size > 0) { + bytes_to_write = size; + if (bytes_to_write > MAX_WRITE) + bytes_to_write = MAX_WRITE; + bytes_written = write(fd, p, bytes_to_write); + if (bytes_written < 0) { + archive_set_error(a, errno, "Write error"); + r = ARCHIVE_FATAL; + goto cleanup; + } + actual_offset += bytes_written; + p += bytes_written; + size -= bytes_written; + } + } - while ((r = archive_read_data_block(a, &buff, &size, &offset)) == - ARCHIVE_OK) { - const char *p = buff; - if (offset > output_offset) { - output_offset = lseek(fd, - offset - output_offset, SEEK_CUR); - if (output_offset != offset) { - archive_set_error(a, errno, "Seek error"); - return (ARCHIVE_FATAL); - } - } - while (size > 0) { - bytes_to_write = size; - if (bytes_to_write > MAX_WRITE) - bytes_to_write = MAX_WRITE; - bytes_written = write(fd, p, bytes_to_write); - if (bytes_written < 0) { - archive_set_error(a, errno, "Write error"); - return (ARCHIVE_FATAL); - } - output_offset += bytes_written; - total_written += bytes_written; - p += bytes_written; - size -= bytes_written; - } - } + if (r == ARCHIVE_EOF && target_offset > actual_offset) { + r2 = pad_to(a, fd, can_lseek, nulls_size, nulls, + target_offset, actual_offset); + if (r2 != ARCHIVE_OK) + r = r2; + } - if (r != ARCHIVE_EOF) - return (r); - return (ARCHIVE_OK); +cleanup: + free(nulls); + if (r != ARCHIVE_EOF) + return (r); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 b/Utilities/cmlibarchive/libarchive/archive_read_disk.3 index fd5309535..3c49bffc8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk.3 +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk.3 @@ -22,10 +22,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD$ +.\" $FreeBSD: head/lib/libarchive/archive_read_disk.3 190957 2009-04-12 05:04:02Z kientzle $ .\" .Dd March 10, 2009 -.Dt archive_read_disk 3 +.Dt ARCHIVE_READ_DISK 3 .Os .Sh NAME .Nm archive_read_disk_new , @@ -39,7 +39,8 @@ .Nm archive_read_disk_set_gname_lookup , .Nm archive_read_disk_set_standard_lookup , .Nm archive_read_close , -.Nm archive_read_finish +.Nm archive_read_finish , +.Nm archive_read_free .Nd functions for reading objects from disk .Sh SYNOPSIS .In archive.h @@ -82,6 +83,8 @@ .Fn archive_read_close "struct archive *" .Ft int .Fn archive_read_finish "struct archive *" +.Ft int +.Fn archive_read_free "struct archive *" .Sh DESCRIPTION These functions provide an API for reading information about objects on disk. @@ -133,16 +136,16 @@ object is destroyed or when new lookup functions are registered. This convenience function installs a standard set of user and group name lookup functions. These functions use -.Xr getpwid 3 +.Xr getpwuid 3 and -.Xr getgrid 3 +.Xr getgrgid 3 to convert ids to names, defaulting to NULL if the names cannot be looked up. These functions also implement a simple memory cache to reduce the number of calls to -.Xr getpwid 3 +.Xr getpwuid 3 and -.Xr getgrid 3 . +.Xr getgrgid 3 . .It Fn archive_read_disk_entry_from_file Populates a .Tn struct archive_entry @@ -177,10 +180,15 @@ This affects the file ownership fields and ACL values in the .Tn struct archive_entry object. .It Fn archive_read_close -This currently does nothing. -.It Fn archive_write_finish +Does nothing for +.Tn archive_read_disk +handles. +.It Fn archive_read_finish +This is a deprecated synonym for +.Fn archive_read_free . +.It Fn archive_read_free Invokes -.Fn archive_write_close +.Fn archive_read_close if it was not invoked manually, then releases all resources. .El More information about the @@ -207,13 +215,13 @@ file_to_archive(struct archive *a, const char *name) fd = open(name, O_RDONLY); if (fd < 0) return; - archive_entry_copy_sourcepath(entry, name); + archive_entry_copy_pathname(entry, name); archive_read_disk_entry_from_file(ard, entry, fd, NULL); archive_write_header(a, entry); while ((bytes_read = read(fd, buff, sizeof(buff))) > 0) archive_write_data(a, buff, bytes_read); archive_write_finish_entry(a); - archive_read_finish(ard); + archive_read_free(ard); archive_entry_free(entry); } .Ed @@ -229,15 +237,6 @@ for operations that might succeed if retried, for unusual conditions that do not prevent further operations, and .Cm ARCHIVE_FATAL for serious errors that make remaining operations impossible. -The -.Xr archive_errno 3 -and -.Xr archive_error_string 3 -functions can be used to retrieve an appropriate error code and a -textual error message. -(See -.Xr archive_util 3 -for details.) .Pp .Fn archive_read_disk_new returns a pointer to a newly-allocated @@ -253,9 +252,17 @@ pointers to the textual name or NULL if the lookup failed for any reason. The returned pointer points to internal storage that may be reused on the next call to either of these functions; callers should copy the string if they need to continue accessing it. -.Pp +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" .Sh SEE ALSO .Xr archive_read 3 , +.Xr archive_util 3 , .Xr archive_write 3 , .Xr archive_write_disk 3 , .Xr tar 1 , @@ -276,14 +283,14 @@ and first appeared in The .Nm libarchive library was written by -.An Tim Kientzle Aq kientzle@freebsd.org . +.An Tim Kientzle Aq kientzle@FreeBSD.org . .Sh BUGS The .Dq standard user name and group name lookup functions are not the defaults because -.Xr getgrid 3 +.Xr getgrgid 3 and -.Xr getpwid 3 +.Xr getpwuid 3 are sometimes too large for particular applications. The current design allows the application author to use a more compact implementation when appropriate. diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk.c b/Utilities/cmlibarchive/libarchive/archive_read_disk.c deleted file mode 100644 index 219268e3b..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk.c +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 - * in this position and unchanged. - * 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_string.h" -#include "archive_entry.h" -#include "archive_private.h" -#include "archive_read_disk_private.h" - -static int _archive_read_finish(struct archive *); -static int _archive_read_close(struct archive *); -static const char *trivial_lookup_gname(void *, gid_t gid); -static const char *trivial_lookup_uname(void *, uid_t uid); - -static struct archive_vtable * -archive_read_disk_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_finish = _archive_read_finish; - av.archive_close = _archive_read_close; - } - return (&av); -} - -const char * -archive_read_disk_gname(struct archive *_a, gid_t gid) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - if (a->lookup_gname != NULL) - return ((*a->lookup_gname)(a->lookup_gname_data, gid)); - return (NULL); -} - -const char * -archive_read_disk_uname(struct archive *_a, uid_t uid) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - if (a->lookup_uname != NULL) - return ((*a->lookup_uname)(a->lookup_uname_data, uid)); - return (NULL); -} - -int -archive_read_disk_set_gname_lookup(struct archive *_a, - void *private_data, - const char * (*lookup_gname)(void *private, gid_t gid), - void (*cleanup_gname)(void *private)) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup"); - - if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) - (a->cleanup_gname)(a->lookup_gname_data); - - a->lookup_gname = lookup_gname; - a->cleanup_gname = cleanup_gname; - a->lookup_gname_data = private_data; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_uname_lookup(struct archive *_a, - void *private_data, - const char * (*lookup_uname)(void *private, uid_t uid), - void (*cleanup_uname)(void *private)) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup"); - - if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) - (a->cleanup_uname)(a->lookup_uname_data); - - a->lookup_uname = lookup_uname; - a->cleanup_uname = cleanup_uname; - a->lookup_uname_data = private_data; - return (ARCHIVE_OK); -} - -/* - * Create a new archive_read_disk object and initialize it with global state. - */ -struct archive * -archive_read_disk_new(void) -{ - struct archive_read_disk *a; - - a = (struct archive_read_disk *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_READ_DISK_MAGIC; - /* We're ready to write a header immediately. */ - a->archive.state = ARCHIVE_STATE_HEADER; - a->archive.vtable = archive_read_disk_vtable(); - a->lookup_uname = trivial_lookup_uname; - a->lookup_gname = trivial_lookup_gname; - return (&a->archive); -} - -static int -_archive_read_finish(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - - if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) - (a->cleanup_gname)(a->lookup_gname_data); - if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) - (a->cleanup_uname)(a->lookup_uname_data); - archive_string_free(&a->archive.error_string); - free(a); - return (ARCHIVE_OK); -} - -static int -_archive_read_close(struct archive *_a) -{ - (void)_a; /* UNUSED */ - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_logical(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'L'; - a->follow_symlinks = 1; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_physical(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'P'; - a->follow_symlinks = 0; - return (ARCHIVE_OK); -} - -int -archive_read_disk_set_symlink_hybrid(struct archive *_a) -{ - struct archive_read_disk *a = (struct archive_read_disk *)_a; - a->symlink_mode = 'H'; - a->follow_symlinks = 1; /* Follow symlinks initially. */ - return (ARCHIVE_OK); -} - -/* - * Trivial implementations of gname/uname lookup functions. - * These are normally overridden by the client, but these stub - * versions ensure that we always have something that works. - */ -static const char * -trivial_lookup_gname(void *private_data, gid_t gid) -{ - (void)private_data; /* UNUSED */ - (void)gid; /* UNUSED */ - return (NULL); -} - -static const char * -trivial_lookup_uname(void *private_data, uid_t uid) -{ - (void)private_data; /* UNUSED */ - (void)uid; /* UNUSED */ - return (NULL); -} 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 cb685c8dc..fdeb5166d 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_entry_from_file.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2010 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +25,10 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_entry_from_file.c 201084 2009-12-28 02:14:09Z kientzle $"); + +/* This is the tree-walking code for POSIX systems. */ +#if !defined(_WIN32) || defined(__CYGWIN__) #ifdef HAVE_SYS_TYPES_H /* Mac OSX requires sys/types.h before sys/acl.h. */ @@ -36,6 +40,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_EXTATTR_H #include #endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif #ifdef HAVE_SYS_PARAM_H #include #endif @@ -45,20 +52,51 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_XATTR_H #include #endif +#ifdef HAVE_SYS_EA_H +#include +#endif #ifdef HAVE_ACL_LIBACL_H #include #endif #ifdef HAVE_ATTR_XATTR_H #include #endif +#ifdef HAVE_COPYFILE_H +#include +#endif #ifdef HAVE_ERRNO_H #include #endif +#ifdef HAVE_FCNTL_H +#include +#endif #ifdef HAVE_LIMITS_H #include #endif -#ifdef HAVE_WINDOWS_H -#include +#ifdef HAVE_LINUX_TYPES_H +#include +#endif +#ifdef HAVE_LINUX_FIEMAP_H +#include +#endif +#ifdef HAVE_LINUX_FS_H +#include +#endif +/* + * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. + * As the include guards don't agree, the order of include is important. + */ +#ifdef HAVE_LINUX_EXT2_FS_H +#include /* for Linux file flags */ +#endif +#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) +#include /* Linux file flags, broken on Cygwin */ +#endif +#ifdef HAVE_PATHS_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include #endif #include "archive.h" @@ -71,111 +109,261 @@ __FBSDID("$FreeBSD$"); * different ways. */ #if HAVE_ACL_GET_PERM -#define ACL_GET_PERM acl_get_perm +#define ACL_GET_PERM acl_get_perm #elif HAVE_ACL_GET_PERM_NP -#define ACL_GET_PERM acl_get_perm_np +#define ACL_GET_PERM acl_get_perm_np #endif static int setup_acls_posix1e(struct archive_read_disk *, struct archive_entry *, int fd); +static int setup_mac_metadata(struct archive_read_disk *, + struct archive_entry *, int fd); static int setup_xattrs(struct archive_read_disk *, struct archive_entry *, int fd); +static int setup_sparse(struct archive_read_disk *, + struct archive_entry *, int fd); int archive_read_disk_entry_from_file(struct archive *_a, struct archive_entry *entry, - int fd, const struct stat *st) + int fd, + const struct stat *st) { - struct archive_read_disk *a = (struct archive_read_disk *)_a; - const char *path, *name; - struct stat s; - int initial_fd = fd; - int r, r1; - - archive_clear_error(_a); - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - -#ifdef EXT2_IOC_GETFLAGS - /* Linux requires an extra ioctl to pull the flags. Although - * this is an extra step, it has a nice side-effect: We get an - * open file descriptor which we can use in the subsequent lookups. */ - if ((S_ISREG(st->st_mode) || S_ISDIR(st->st_mode))) { - if (fd < 0) - fd = open(pathname, O_RDONLY | O_NONBLOCK | O_BINARY); - if (fd >= 0) { - unsigned long stflags; - int r = ioctl(fd, EXT2_IOC_GETFLAGS, &stflags); - if (r == 0 && stflags != 0) - archive_entry_set_fflags(entry, stflags, 0); - } - } -#endif - - if (st == NULL) { - /* TODO: On Windows, use GetFileInfoByHandle() here. - * Using Windows stat() call is badly broken, but - * even the stat() wrapper has problems because - * 'struct stat' is broken on Windows. - */ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + const char *path, *name; + struct stat s; + int initial_fd = fd; + int r, r1; + + archive_clear_error(_a); + path = archive_entry_sourcepath(entry); + if (path == NULL) + path = archive_entry_pathname(entry); + + if (a->tree == NULL) { + if (st == NULL) { #if HAVE_FSTAT - if (fd >= 0) { - if (fstat(fd, &s) != 0) - return (ARCHIVE_FATAL); - } else + if (fd >= 0) { + if (fstat(fd, &s) != 0) { + archive_set_error(&a->archive, errno, + "Can't fstat"); + return (ARCHIVE_FAILED); + } + } else #endif #if HAVE_LSTAT - if (!a->follow_symlinks) { - if (lstat(path, &s) != 0) - return (ARCHIVE_FATAL); - } else -#endif - if (stat(path, &s) != 0) - return (ARCHIVE_FATAL); - st = &s; - } - archive_entry_copy_stat(entry, st); - - /* Lookup uname/gname */ - name = archive_read_disk_uname(_a, archive_entry_uid(entry)); - if (name != NULL) - archive_entry_copy_uname(entry, name); - name = archive_read_disk_gname(_a, archive_entry_gid(entry)); - if (name != NULL) - archive_entry_copy_gname(entry, name); + if (!a->follow_symlinks) { + if (lstat(path, &s) != 0) { + archive_set_error(&a->archive, errno, + "Can't lstat %s", path); + return (ARCHIVE_FAILED); + } + } else +#endif + if (stat(path, &s) != 0) { + archive_set_error(&a->archive, errno, + "Can't stat %s", path); + return (ARCHIVE_FAILED); + } + st = &s; + } + archive_entry_copy_stat(entry, st); + } + + /* Lookup uname/gname */ + name = archive_read_disk_uname(_a, archive_entry_uid(entry)); + if (name != NULL) + archive_entry_copy_uname(entry, name); + name = archive_read_disk_gname(_a, archive_entry_gid(entry)); + if (name != NULL) + archive_entry_copy_gname(entry, name); #ifdef HAVE_STRUCT_STAT_ST_FLAGS - /* On FreeBSD, we get flags for free with the stat. */ - /* TODO: Does this belong in copy_stat()? */ - if (st->st_flags != 0) - archive_entry_set_fflags(entry, st->st_flags, 0); -#endif - -#ifdef HAVE_READLINK - if (S_ISLNK(st->st_mode)) { - char linkbuffer[PATH_MAX + 1]; - int lnklen = readlink(path, linkbuffer, PATH_MAX); - if (lnklen < 0) { - archive_set_error(&a->archive, errno, - "Couldn't read link data"); - return (ARCHIVE_WARN); - } - linkbuffer[lnklen] = 0; - archive_entry_set_symlink(entry, linkbuffer); - } -#endif - - r = setup_acls_posix1e(a, entry, fd); - r1 = setup_xattrs(a, entry, fd); - if (r1 < r) - r = r1; - /* If we opened the file earlier in this function, close it. */ - if (initial_fd != fd) - close(fd); - return (r); + /* On FreeBSD, we get flags for free with the stat. */ + /* TODO: Does this belong in copy_stat()? */ + if (st->st_flags != 0) + archive_entry_set_fflags(entry, st->st_flags, 0); +#endif + +#if defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) + /* Linux requires an extra ioctl to pull the flags. Although + * this is an extra step, it has a nice side-effect: We get an + * open file descriptor which we can use in the subsequent lookups. */ + if ((S_ISREG(st->st_mode) || S_ISDIR(st->st_mode))) { + if (fd < 0) + fd = open(path, O_RDONLY | O_NONBLOCK); + if (fd >= 0) { + unsigned long stflags; + int r = ioctl(fd, EXT2_IOC_GETFLAGS, &stflags); + if (r == 0 && stflags != 0) + archive_entry_set_fflags(entry, stflags, 0); + } + } +#endif + +#if defined(HAVE_READLINK) || defined(HAVE_READLINKAT) + if (S_ISLNK(st->st_mode)) { + size_t linkbuffer_len = st->st_size + 1; + char *linkbuffer; + int lnklen; + + linkbuffer = malloc(linkbuffer_len); + if (linkbuffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't read link data"); + return (ARCHIVE_FAILED); + } +#ifdef HAVE_READLINKAT + if (a->entry_wd_fd >= 0) + lnklen = readlinkat(a->entry_wd_fd, path, + linkbuffer, linkbuffer_len); + else +#endif /* HAVE_READLINKAT */ + lnklen = readlink(path, linkbuffer, linkbuffer_len); + if (lnklen < 0) { + archive_set_error(&a->archive, errno, + "Couldn't read link data"); + free(linkbuffer); + return (ARCHIVE_FAILED); + } + linkbuffer[lnklen] = 0; + archive_entry_set_symlink(entry, linkbuffer); + free(linkbuffer); + } +#endif /* HAVE_READLINK || HAVE_READLINKAT */ + + r = setup_acls_posix1e(a, entry, fd); + r1 = setup_xattrs(a, entry, fd); + if (r1 < r) + r = r1; + r1 = setup_mac_metadata(a, entry, fd); + if (r1 < r) + r = r1; + r1 = setup_sparse(a, entry, fd); + if (r1 < r) + r = r1; + + /* If we opened the file earlier in this function, close it. */ + if (initial_fd != fd) + close(fd); + return (r); } +#if defined(__APPLE__) && defined(HAVE_COPYFILE_H) +/* + * The Mac OS "copyfile()" API copies the extended metadata for a + * file into a separate file in AppleDouble format (see RFC 1740). + * + * Mac OS tar and cpio implementations store this extended + * metadata as a separate entry just before the regular entry + * with a "._" prefix added to the filename. + * + * Note that this is currently done unconditionally; the tar program has + * an option to discard this information before the archive is written. + * + * TODO: If there's a failure, report it and return ARCHIVE_WARN. + */ +static int +setup_mac_metadata(struct archive_read_disk *a, + struct archive_entry *entry, int fd) +{ + int tempfd = -1; + int copyfile_flags = COPYFILE_NOFOLLOW | COPYFILE_ACL | COPYFILE_XATTR; + struct stat copyfile_stat; + int ret = ARCHIVE_OK; + void *buff; + int have_attrs; + const char *name, *tempdir, *tempfile = NULL; + + name = archive_entry_sourcepath(entry); + if (name == NULL) + name = archive_entry_pathname(entry); + if (name == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't open file to read extended attributes: No name"); + return (ARCHIVE_WARN); + } + + /* Short-circuit if there's nothing to do. */ + have_attrs = copyfile(name, NULL, 0, copyfile_flags | COPYFILE_CHECK); + if (have_attrs == -1) { + archive_set_error(&a->archive, errno, + "Could not check extended attributes"); + return (ARCHIVE_WARN); + } + if (have_attrs == 0) + return (ARCHIVE_OK); + + tempdir = NULL; + if (issetugid() == 0) + tempdir = getenv("TMPDIR"); + if (tempdir == NULL) + tempdir = _PATH_TMP; + tempfile = tempnam(tempdir, "tar.md."); + + /* XXX I wish copyfile() could pack directly to a memory + * buffer; that would avoid the temp file here. For that + * matter, it would be nice if fcopyfile() actually worked, + * that would reduce the many open/close races here. */ + if (copyfile(name, tempfile, 0, copyfile_flags | COPYFILE_PACK)) { + archive_set_error(&a->archive, errno, + "Could not pack extended attributes"); + ret = ARCHIVE_WARN; + goto cleanup; + } + tempfd = open(tempfile, O_RDONLY); + if (tempfd < 0) { + archive_set_error(&a->archive, errno, + "Could not open extended attribute file"); + ret = ARCHIVE_WARN; + goto cleanup; + } + if (fstat(tempfd, ©file_stat)) { + archive_set_error(&a->archive, errno, + "Could not check size of extended attributes"); + ret = ARCHIVE_WARN; + goto cleanup; + } + buff = malloc(copyfile_stat.st_size); + if (buff == NULL) { + archive_set_error(&a->archive, errno, + "Could not allocate memory for extended attributes"); + ret = ARCHIVE_WARN; + goto cleanup; + } + if (copyfile_stat.st_size != read(tempfd, buff, copyfile_stat.st_size)) { + archive_set_error(&a->archive, errno, + "Could not read extended attributes into memory"); + ret = ARCHIVE_WARN; + goto cleanup; + } + archive_entry_copy_mac_metadata(entry, buff, copyfile_stat.st_size); + +cleanup: + if (tempfd >= 0) + close(tempfd); + if (tempfile != NULL) + unlink(tempfile); + return (ret); +} + +#else + +/* + * Stub implementation for non-Mac systems. + */ +static int +setup_mac_metadata(struct archive_read_disk *a, + struct archive_entry *entry, int fd) +{ + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)fd; /* UNUSED */ + return (ARCHIVE_OK); +} +#endif + + #ifdef HAVE_POSIX_ACL static void setup_acl_posix1e(struct archive_read_disk *a, struct archive_entry *entry, acl_t acl, int archive_entry_acl_type); @@ -184,40 +372,46 @@ static int setup_acls_posix1e(struct archive_read_disk *a, struct archive_entry *entry, int fd) { - const char *accpath; - acl_t acl; + const char *accpath; + acl_t acl; - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); + accpath = archive_entry_sourcepath(entry); + if (accpath == NULL) + accpath = archive_entry_pathname(entry); - archive_entry_acl_clear(entry); + archive_entry_acl_clear(entry); - /* Retrieve access ACL from file. */ - if (fd >= 0) - acl = acl_get_fd(fd); + /* Retrieve access ACL from file. */ + if (fd >= 0) + acl = acl_get_fd(fd); #if HAVE_ACL_GET_LINK_NP - else if (!a->follow_symlinks) - acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS); -#endif - else - acl = acl_get_file(accpath, ACL_TYPE_ACCESS); - if (acl != NULL) { - setup_acl_posix1e(a, entry, acl, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - acl_free(acl); - } - - /* Only directories can have default ACLs. */ - if (S_ISDIR(archive_entry_mode(entry))) { - acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); - if (acl != NULL) { - setup_acl_posix1e(a, entry, acl, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); - acl_free(acl); - } - } - return (ARCHIVE_OK); + else if (!a->follow_symlinks) + acl = acl_get_link_np(accpath, ACL_TYPE_ACCESS); +#else + else if ((!a->follow_symlinks) + && (archive_entry_filetype(entry) == AE_IFLNK)) + /* We can't get the ACL of a symlink, so we assume it can't + have one. */ + acl = NULL; +#endif + else + acl = acl_get_file(accpath, ACL_TYPE_ACCESS); + if (acl != NULL) { + setup_acl_posix1e(a, entry, acl, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS); + acl_free(acl); + } + + /* Only directories can have default ACLs. */ + if (S_ISDIR(archive_entry_mode(entry))) { + acl = acl_get_file(accpath, ACL_TYPE_DEFAULT); + if (acl != NULL) { + setup_acl_posix1e(a, entry, acl, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); + acl_free(acl); + } + } + return (ARCHIVE_OK); } /* @@ -227,75 +421,77 @@ static void setup_acl_posix1e(struct archive_read_disk *a, struct archive_entry *entry, acl_t acl, int archive_entry_acl_type) { - acl_tag_t acl_tag; - acl_entry_t acl_entry; - acl_permset_t acl_permset; - int s, ae_id, ae_tag, ae_perm; - const char *ae_name; - - s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); - while (s == 1) { - ae_id = -1; - ae_name = NULL; - - acl_get_tag_type(acl_entry, &acl_tag); - if (acl_tag == ACL_USER) { - ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry); - ae_name = archive_read_disk_uname(&a->archive, ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_USER; - } else if (acl_tag == ACL_GROUP) { - ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry); - ae_name = archive_read_disk_gname(&a->archive, ae_id); - ae_tag = ARCHIVE_ENTRY_ACL_GROUP; - } else if (acl_tag == ACL_MASK) { - ae_tag = ARCHIVE_ENTRY_ACL_MASK; - } else if (acl_tag == ACL_USER_OBJ) { - ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; - } else if (acl_tag == ACL_GROUP_OBJ) { - ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; - } else if (acl_tag == ACL_OTHER) { - ae_tag = ARCHIVE_ENTRY_ACL_OTHER; - } else { - /* Skip types that libarchive can't support. */ - continue; - } - - acl_get_permset(acl_entry, &acl_permset); - ae_perm = 0; - /* - * acl_get_perm() is spelled differently on different - * platforms; see above. - */ - if (ACL_GET_PERM(acl_permset, ACL_EXECUTE)) - ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE; - if (ACL_GET_PERM(acl_permset, ACL_READ)) - ae_perm |= ARCHIVE_ENTRY_ACL_READ; - if (ACL_GET_PERM(acl_permset, ACL_WRITE)) - ae_perm |= ARCHIVE_ENTRY_ACL_WRITE; - - archive_entry_acl_add_entry(entry, - archive_entry_acl_type, ae_perm, ae_tag, - ae_id, ae_name); - - s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); - } + acl_tag_t acl_tag; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + int s, ae_id, ae_tag, ae_perm; + const char *ae_name; + + s = acl_get_entry(acl, ACL_FIRST_ENTRY, &acl_entry); + while (s == 1) { + ae_id = -1; + ae_name = NULL; + + acl_get_tag_type(acl_entry, &acl_tag); + if (acl_tag == ACL_USER) { + ae_id = (int)*(uid_t *)acl_get_qualifier(acl_entry); + ae_name = archive_read_disk_uname(&a->archive, ae_id); + ae_tag = ARCHIVE_ENTRY_ACL_USER; + } else if (acl_tag == ACL_GROUP) { + ae_id = (int)*(gid_t *)acl_get_qualifier(acl_entry); + ae_name = archive_read_disk_gname(&a->archive, ae_id); + ae_tag = ARCHIVE_ENTRY_ACL_GROUP; + } else if (acl_tag == ACL_MASK) { + ae_tag = ARCHIVE_ENTRY_ACL_MASK; + } else if (acl_tag == ACL_USER_OBJ) { + ae_tag = ARCHIVE_ENTRY_ACL_USER_OBJ; + } else if (acl_tag == ACL_GROUP_OBJ) { + ae_tag = ARCHIVE_ENTRY_ACL_GROUP_OBJ; + } else if (acl_tag == ACL_OTHER) { + ae_tag = ARCHIVE_ENTRY_ACL_OTHER; + } else { + /* Skip types that libarchive can't support. */ + continue; + } + + acl_get_permset(acl_entry, &acl_permset); + ae_perm = 0; + /* + * acl_get_perm() is spelled differently on different + * platforms; see above. + */ + if (ACL_GET_PERM(acl_permset, ACL_EXECUTE)) + ae_perm |= ARCHIVE_ENTRY_ACL_EXECUTE; + if (ACL_GET_PERM(acl_permset, ACL_READ)) + ae_perm |= ARCHIVE_ENTRY_ACL_READ; + if (ACL_GET_PERM(acl_permset, ACL_WRITE)) + ae_perm |= ARCHIVE_ENTRY_ACL_WRITE; + + archive_entry_acl_add_entry(entry, + archive_entry_acl_type, ae_perm, ae_tag, + ae_id, ae_name); + + s = acl_get_entry(acl, ACL_NEXT_ENTRY, &acl_entry); + } } #else static int setup_acls_posix1e(struct archive_read_disk *a, struct archive_entry *entry, int fd) { - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)fd; /* UNUSED */ - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)fd; /* UNUSED */ + return (ARCHIVE_OK); } #endif -#if HAVE_LISTXATTR && HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR +#if (HAVE_FGETXATTR && HAVE_FLISTXATTR && HAVE_LISTXATTR && \ + HAVE_LLISTXATTR && HAVE_GETXATTR && HAVE_LGETXATTR) || \ + (HAVE_FGETEA && HAVE_FLISTEA && HAVE_LISTEA) /* - * Linux extended attribute support. + * Linux and AIX extended attribute support. * * TODO: By using a stack-allocated buffer for the first * call to getxattr(), we might be able to avoid the second @@ -310,107 +506,149 @@ static int setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, const char *name, int fd) { - ssize_t size; - void *value = NULL; - const char *accpath; - - (void)fd; /* UNUSED */ - - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - size = lgetxattr(accpath, name, NULL, 0); - else - size = getxattr(accpath, name, NULL, 0); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't query extended attribute"); - return (ARCHIVE_WARN); - } - - if (size > 0 && (value = malloc(size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - size = lgetxattr(accpath, name, value, size); - else - size = getxattr(accpath, name, value, size); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't read extended attribute"); - return (ARCHIVE_WARN); - } - - archive_entry_xattr_add_entry(entry, name, value, size); - - free(value); - return (ARCHIVE_OK); + ssize_t size; + void *value = NULL; + const char *accpath; + + accpath = archive_entry_sourcepath(entry); + if (accpath == NULL) + accpath = archive_entry_pathname(entry); + +#if HAVE_FGETXATTR + if (fd >= 0) + size = fgetxattr(fd, name, NULL, 0); + else if (!a->follow_symlinks) + size = lgetxattr(accpath, name, NULL, 0); + else + size = getxattr(accpath, name, NULL, 0); +#elif HAVE_FGETEA + if (fd >= 0) + size = fgetea(fd, name, NULL, 0); + else if (!a->follow_symlinks) + size = lgetea(accpath, name, NULL, 0); + else + size = getea(accpath, name, NULL, 0); +#endif + + if (size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't query extended attribute"); + return (ARCHIVE_WARN); + } + + if (size > 0 && (value = malloc(size)) == NULL) { + archive_set_error(&a->archive, errno, "Out of memory"); + return (ARCHIVE_FATAL); + } + +#if HAVE_FGETXATTR + if (fd >= 0) + size = fgetxattr(fd, name, value, size); + else if (!a->follow_symlinks) + size = lgetxattr(accpath, name, value, size); + else + size = getxattr(accpath, name, value, size); +#elif HAVE_FGETEA + if (fd >= 0) + size = fgetea(fd, name, value, size); + else if (!a->follow_symlinks) + size = lgetea(accpath, name, value, size); + else + size = getea(accpath, name, value, size); +#endif + + if (size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't read extended attribute"); + return (ARCHIVE_WARN); + } + + archive_entry_xattr_add_entry(entry, name, value, size); + + free(value); + return (ARCHIVE_OK); } static int setup_xattrs(struct archive_read_disk *a, struct archive_entry *entry, int fd) { - char *list, *p; - const char *path; - ssize_t list_size; - - - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - list_size = llistxattr(path, NULL, 0); - else - list_size = listxattr(path, NULL, 0); - - if (list_size == -1) { - if (errno == ENOTSUP) - return (ARCHIVE_OK); - archive_set_error(&a->archive, errno, - "Couldn't list extended attributes"); - return (ARCHIVE_WARN); - } - - if (list_size == 0) - return (ARCHIVE_OK); - - if ((list = malloc(list_size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - list_size = llistxattr(path, list, list_size); - else - list_size = listxattr(path, list, list_size); - - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't retrieve extended attributes"); - free(list); - return (ARCHIVE_WARN); - } - - for (p = list; (p - list) < list_size; p += strlen(p) + 1) { - if (strncmp(p, "system.", 7) == 0 || - strncmp(p, "xfsroot.", 8) == 0) - continue; - setup_xattr(a, entry, p, fd); - } - - free(list); - return (ARCHIVE_OK); + char *list, *p; + const char *path; + ssize_t list_size; + + path = archive_entry_sourcepath(entry); + if (path == NULL) + path = archive_entry_pathname(entry); + +#if HAVE_FLISTXATTR + if (fd >= 0) + list_size = flistxattr(fd, NULL, 0); + else if (!a->follow_symlinks) + list_size = llistxattr(path, NULL, 0); + else + list_size = listxattr(path, NULL, 0); +#elif HAVE_FLISTEA + if (fd >= 0) + list_size = flistea(fd, NULL, 0); + else if (!a->follow_symlinks) + list_size = llistea(path, NULL, 0); + else + list_size = listea(path, NULL, 0); +#endif + + if (list_size == -1) { + if (errno == ENOTSUP || errno == ENOSYS) + return (ARCHIVE_OK); + archive_set_error(&a->archive, errno, + "Couldn't list extended attributes"); + return (ARCHIVE_WARN); + } + + if (list_size == 0) + return (ARCHIVE_OK); + + if ((list = malloc(list_size)) == NULL) { + archive_set_error(&a->archive, errno, "Out of memory"); + return (ARCHIVE_FATAL); + } + +#if HAVE_FLISTXATTR + if (fd >= 0) + list_size = flistxattr(fd, list, list_size); + else if (!a->follow_symlinks) + list_size = llistxattr(path, list, list_size); + else + list_size = listxattr(path, list, list_size); +#elif HAVE_FLISTEA + if (fd >= 0) + list_size = flistea(fd, list, list_size); + else if (!a->follow_symlinks) + list_size = llistea(path, list, list_size); + else + list_size = listea(path, list, list_size); +#endif + + if (list_size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't retrieve extended attributes"); + free(list); + return (ARCHIVE_WARN); + } + + for (p = list; (p - list) < list_size; p += strlen(p) + 1) { + if (strncmp(p, "system.", 7) == 0 || + strncmp(p, "xfsroot.", 8) == 0) + continue; + setup_xattr(a, entry, p, fd); + } + + free(list); + return (ARCHIVE_OK); } -#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE +#elif HAVE_EXTATTR_GET_FILE && HAVE_EXTATTR_LIST_FILE && \ + HAVE_DECL_EXTATTR_NAMESPACE_USER /* * FreeBSD extattr interface. @@ -421,119 +659,125 @@ setup_xattrs(struct archive_read_disk *a, * to not include the system extattrs that hold ACLs; we handle * those separately. */ -int +static int setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, int namespace, const char *name, const char *fullname, int fd); -int +static int setup_xattr(struct archive_read_disk *a, struct archive_entry *entry, int namespace, const char *name, const char *fullname, int fd) { - ssize_t size; - void *value = NULL; - const char *accpath; - - (void)fd; /* UNUSED */ - - accpath = archive_entry_sourcepath(entry); - if (accpath == NULL) - accpath = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - size = extattr_get_link(accpath, namespace, name, NULL, 0); - else - size = extattr_get_file(accpath, namespace, name, NULL, 0); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't query extended attribute"); - return (ARCHIVE_WARN); - } - - if (size > 0 && (value = malloc(size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - size = extattr_get_link(accpath, namespace, name, value, size); - else - size = extattr_get_file(accpath, namespace, name, value, size); - - if (size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't read extended attribute"); - return (ARCHIVE_WARN); - } - - archive_entry_xattr_add_entry(entry, fullname, value, size); - - free(value); - return (ARCHIVE_OK); + ssize_t size; + void *value = NULL; + const char *accpath; + + accpath = archive_entry_sourcepath(entry); + if (accpath == NULL) + accpath = archive_entry_pathname(entry); + + if (fd >= 0) + size = extattr_get_fd(fd, namespace, name, NULL, 0); + else if (!a->follow_symlinks) + size = extattr_get_link(accpath, namespace, name, NULL, 0); + else + size = extattr_get_file(accpath, namespace, name, NULL, 0); + + if (size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't query extended attribute"); + return (ARCHIVE_WARN); + } + + if (size > 0 && (value = malloc(size)) == NULL) { + archive_set_error(&a->archive, errno, "Out of memory"); + return (ARCHIVE_FATAL); + } + + if (fd >= 0) + size = extattr_get_fd(fd, namespace, name, value, size); + else if (!a->follow_symlinks) + size = extattr_get_link(accpath, namespace, name, value, size); + else + size = extattr_get_file(accpath, namespace, name, value, size); + + if (size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't read extended attribute"); + return (ARCHIVE_WARN); + } + + archive_entry_xattr_add_entry(entry, fullname, value, size); + + free(value); + return (ARCHIVE_OK); } static int setup_xattrs(struct archive_read_disk *a, struct archive_entry *entry, int fd) { - char buff[512]; - char *list, *p; - ssize_t list_size; - const char *path; - int namespace = EXTATTR_NAMESPACE_USER; - - path = archive_entry_sourcepath(entry); - if (path == NULL) - path = archive_entry_pathname(entry); - - if (!a->follow_symlinks) - list_size = extattr_list_link(path, namespace, NULL, 0); - else - list_size = extattr_list_file(path, namespace, NULL, 0); - - if (list_size == -1 && errno == EOPNOTSUPP) - return (ARCHIVE_OK); - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't list extended attributes"); - return (ARCHIVE_WARN); - } - - if (list_size == 0) - return (ARCHIVE_OK); - - if ((list = malloc(list_size)) == NULL) { - archive_set_error(&a->archive, errno, "Out of memory"); - return (ARCHIVE_FATAL); - } - - if (!a->follow_symlinks) - list_size = extattr_list_link(path, namespace, list, list_size); - else - list_size = extattr_list_file(path, namespace, list, list_size); - - if (list_size == -1) { - archive_set_error(&a->archive, errno, - "Couldn't retrieve extended attributes"); - free(list); - return (ARCHIVE_WARN); - } - - p = list; - while ((p - list) < list_size) { - size_t len = 255 & (int)*p; - char *name; - - strcpy(buff, "user."); - name = buff + strlen(buff); - memcpy(name, p + 1, len); - name[len] = '\0'; - setup_xattr(a, entry, namespace, name, buff, fd); - p += 1 + len; - } - - free(list); - return (ARCHIVE_OK); + char buff[512]; + char *list, *p; + ssize_t list_size; + const char *path; + int namespace = EXTATTR_NAMESPACE_USER; + + path = archive_entry_sourcepath(entry); + if (path == NULL) + path = archive_entry_pathname(entry); + + if (fd >= 0) + list_size = extattr_list_fd(fd, namespace, NULL, 0); + else if (!a->follow_symlinks) + list_size = extattr_list_link(path, namespace, NULL, 0); + else + list_size = extattr_list_file(path, namespace, NULL, 0); + + if (list_size == -1 && errno == EOPNOTSUPP) + return (ARCHIVE_OK); + if (list_size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't list extended attributes"); + return (ARCHIVE_WARN); + } + + if (list_size == 0) + return (ARCHIVE_OK); + + if ((list = malloc(list_size)) == NULL) { + archive_set_error(&a->archive, errno, "Out of memory"); + return (ARCHIVE_FATAL); + } + + if (fd >= 0) + list_size = extattr_list_fd(fd, namespace, list, list_size); + else if (!a->follow_symlinks) + list_size = extattr_list_link(path, namespace, list, list_size); + else + list_size = extattr_list_file(path, namespace, list, list_size); + + if (list_size == -1) { + archive_set_error(&a->archive, errno, + "Couldn't retrieve extended attributes"); + free(list); + return (ARCHIVE_WARN); + } + + p = list; + while ((p - list) < list_size) { + size_t len = 255 & (int)*p; + char *name; + + strcpy(buff, "user."); + name = buff + strlen(buff); + memcpy(name, p + 1, len); + name[len] = '\0'; + setup_xattr(a, entry, namespace, name, buff, fd); + p += 1 + len; + } + + free(list); + return (ARCHIVE_OK); } #else @@ -545,10 +789,220 @@ static int setup_xattrs(struct archive_read_disk *a, struct archive_entry *entry, int fd) { - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ - (void)fd; /* UNUSED */ - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)fd; /* UNUSED */ + return (ARCHIVE_OK); } #endif + +#if defined(HAVE_LINUX_FIEMAP_H) + +/* + * Linux sparse interface. + * + * The FIEMAP ioctl returns an "extent" for each physical allocation + * on disk. We need to process those to generate a more compact list + * of logical file blocks. We also need to be very careful to use + * FIEMAP_FLAG_SYNC here, since there are reports that Linux sometimes + * does not report allocations for newly-written data that hasn't + * been synced to disk. + * + * It's important to return a minimal sparse file list because we want + * to not trigger sparse file extensions if we don't have to, since + * not all readers support them. + */ + +static int +setup_sparse(struct archive_read_disk *a, + struct archive_entry *entry, int fd) +{ + char buff[4096]; + struct fiemap *fm; + struct fiemap_extent *fe; + int64_t size; + int count, do_fiemap; + int initial_fd = fd; + int exit_sts = ARCHIVE_OK; + + if (archive_entry_filetype(entry) != AE_IFREG + || archive_entry_size(entry) <= 0 + || archive_entry_hardlink(entry) != NULL) + return (ARCHIVE_OK); + + if (fd < 0) { + const char *path; + + path = archive_entry_sourcepath(entry); + if (path == NULL) + path = archive_entry_pathname(entry); + fd = open(path, O_RDONLY | O_NONBLOCK); + if (fd < 0) { + archive_set_error(&a->archive, errno, + "Can't open `%s'", path); + return (ARCHIVE_FAILED); + } + } + + count = (sizeof(buff) - sizeof(*fm))/sizeof(*fe); + fm = (struct fiemap *)buff; + fm->fm_start = 0; + fm->fm_length = ~0ULL;; + fm->fm_flags = FIEMAP_FLAG_SYNC; + fm->fm_extent_count = count; + do_fiemap = 1; + size = archive_entry_size(entry); + for (;;) { + int i, r; + + r = ioctl(fd, FS_IOC_FIEMAP, fm); + if (r < 0) { + /* When errno is ENOTTY, it is better we should + * return ARCHIVE_OK because an earlier version + *(<2.6.28) cannot perfom FS_IOC_FIEMAP. + * We should also check if errno is EOPNOTSUPP, + * it means "Operation not supported". */ + if (errno != ENOTTY && errno != EOPNOTSUPP) { + archive_set_error(&a->archive, errno, + "FIEMAP failed"); + exit_sts = ARCHIVE_FAILED; + } + goto exit_setup_sparse; + } + if (fm->fm_mapped_extents == 0) + break; + fe = fm->fm_extents; + for (i = 0; i < fm->fm_mapped_extents; i++, fe++) { + if (!(fe->fe_flags & FIEMAP_EXTENT_UNWRITTEN)) { + /* The fe_length of the last block does not + * adjust itself to its size files. */ + int64_t length = fe->fe_length; + if (fe->fe_logical + length > size) + length -= fe->fe_logical + length - size; + if (fe->fe_logical == 0 && length == size) { + /* This is not sparse. */ + do_fiemap = 0; + break; + } + if (length > 0) + archive_entry_sparse_add_entry(entry, + fe->fe_logical, length); + } + if (fe->fe_flags & FIEMAP_EXTENT_LAST) + do_fiemap = 0; + } + if (do_fiemap) { + fe = fm->fm_extents + fm->fm_mapped_extents -1; + fm->fm_start = fe->fe_logical + fe->fe_length; + } else + break; + } +exit_setup_sparse: + if (initial_fd != fd) + close(fd); + return (exit_sts); +} + +#elif defined(SEEK_HOLE) && defined(SEEK_DATA) && defined(_PC_MIN_HOLE_SIZE) + +/* + * FreeBSD and Solaris sparse interface. + */ + +static int +setup_sparse(struct archive_read_disk *a, + struct archive_entry *entry, int fd) +{ + int64_t size; + int initial_fd = fd; + off_t initial_off; /* FreeBSD/Solaris only, so off_t okay here */ + off_t off_s, off_e; /* FreeBSD/Solaris only, so off_t okay here */ + int exit_sts = ARCHIVE_OK; + + if (archive_entry_filetype(entry) != AE_IFREG + || archive_entry_size(entry) <= 0 + || archive_entry_hardlink(entry) != NULL) + return (ARCHIVE_OK); + + /* Does filesystem support the reporting of hole ? */ + if (fd >= 0) { + if (fpathconf(fd, _PC_MIN_HOLE_SIZE) <= 0) + return (ARCHIVE_OK); + initial_off = lseek(fd, 0, SEEK_CUR); + if (initial_off != 0) + lseek(fd, 0, SEEK_SET); + } else { + const char *path; + + path = archive_entry_sourcepath(entry); + if (path == NULL) + path = archive_entry_pathname(entry); + if (pathconf(path, _PC_MIN_HOLE_SIZE) <= 0) + return (ARCHIVE_OK); + fd = open(path, O_RDONLY | O_NONBLOCK); + if (fd < 0) { + archive_set_error(&a->archive, errno, + "Can't open `%s'", path); + return (ARCHIVE_FAILED); + } + initial_off = 0; + } + + off_s = 0; + size = archive_entry_size(entry); + while (off_s < size) { + off_s = lseek(fd, off_s, SEEK_DATA); + if (off_s == (off_t)-1) { + if (errno == ENXIO) + break;/* no more hole */ + archive_set_error(&a->archive, errno, + "lseek(SEEK_HOLE) failed"); + exit_sts = ARCHIVE_FAILED; + goto exit_setup_sparse; + } + off_e = lseek(fd, off_s, SEEK_HOLE); + if (off_s == (off_t)-1) { + if (errno == ENXIO) { + off_e = lseek(fd, 0, SEEK_END); + if (off_e != (off_t)-1) + break;/* no more data */ + } + archive_set_error(&a->archive, errno, + "lseek(SEEK_DATA) failed"); + exit_sts = ARCHIVE_FAILED; + goto exit_setup_sparse; + } + if (off_s == 0 && off_e == size) + break;/* This is not spase. */ + archive_entry_sparse_add_entry(entry, off_s, + off_e - off_s); + off_s = off_e; + } +exit_setup_sparse: + if (initial_fd != fd) + close(fd); + else + lseek(fd, initial_off, SEEK_SET); + return (exit_sts); +} + +#else + +/* + * Generic (stub) sparse support. + */ +static int +setup_sparse(struct archive_read_disk *a, + struct archive_entry *entry, int fd) +{ + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ + (void)fd; /* UNUSED */ + return (ARCHIVE_OK); +} + +#endif + +#endif /* !defined(_WIN32) || defined(__CYGWIN__) */ + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c new file mode 100644 index 000000000..7d7eecadc --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_posix.c @@ -0,0 +1,2318 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2010,2011 Michihiro NAKAJIMA + * 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 + * in this position and unchanged. + * 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. + */ + +/* This is the tree-walking code for POSIX systems. */ +#if !defined(_WIN32) || defined(__CYGWIN__) + +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_STATFS_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_LINUX_MAGIC_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#endif +#ifdef HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "archive.h" +#include "archive_string.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" + +#ifndef HAVE_FCHDIR +#error fchdir function required. +#endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +/*- + * This is a new directory-walking system that addresses a number + * of problems I've had with fts(3). In particular, it has no + * pathname-length limits (other than the size of 'int'), handles + * deep logical traversals, uses considerably less memory, and has + * an opaque interface (easier to modify in the future). + * + * Internally, it keeps a single list of "tree_entry" items that + * represent filesystem objects that require further attention. + * Non-directories are not kept in memory: they are pulled from + * readdir(), returned to the client, then freed as soon as possible. + * Any directory entry to be traversed gets pushed onto the stack. + * + * There is surprisingly little information that needs to be kept for + * each item on the stack. Just the name, depth (represented here as the + * string length of the parent directory's pathname), and some markers + * indicating how to get back to the parent (via chdir("..") for a + * regular dir or via fchdir(2) for a symlink). + */ +/* + * TODO: + * 1) Loop checking. + * 3) Arbitrary logical traversals by closing/reopening intermediate fds. + */ + +struct restore_time { + const char *name; + time_t mtime; + long mtime_nsec; + time_t atime; + long atime_nsec; + mode_t filetype; + int noatime; +}; + +struct tree_entry { + int depth; + struct tree_entry *next; + struct tree_entry *parent; + struct archive_string name; + size_t dirname_length; + int64_t dev; + int64_t ino; + int flags; + int filesystem_id; + /* How to return back to the parent of a symlink. */ + int symlink_parent_fd; + /* How to restore time of a directory. */ + struct restore_time restore_time; +}; + +struct filesystem { + int64_t dev; + int synthetic; + int remote; + int noatime; +#if defined(HAVE_READDIR_R) + size_t name_max; +#endif + long incr_xfer_size; + long max_xfer_size; + long min_xfer_size; + long xfer_align; + + /* + * Buffer used for reading file contents. + */ + /* Exactly allocated memory pointer. */ + unsigned char *allocation_ptr; + /* Pointer adjusted to the filesystem alignment . */ + unsigned char *buff; + size_t buff_size; +}; + +/* Definitions for tree_entry.flags bitmap. */ +#define isDir 1 /* This entry is a regular directory. */ +#define isDirLink 2 /* This entry is a symbolic link to a directory. */ +#define needsFirstVisit 4 /* This is an initial entry. */ +#define needsDescent 8 /* This entry needs to be previsited. */ +#define needsOpen 16 /* This is a directory that needs to be opened. */ +#define needsAscent 32 /* This entry needs to be postvisited. */ + +/* + * Local data for this package. + */ +struct tree { + struct tree_entry *stack; + struct tree_entry *current; + DIR *d; +#define INVALID_DIR_HANDLE NULL + struct dirent *de; +#if defined(HAVE_READDIR_R) + struct dirent *dirent; + size_t dirent_allocated; +#endif + int flags; + int visit_type; + /* Error code from last failed operation. */ + int tree_errno; + + /* Dynamically-sized buffer for holding path */ + struct archive_string path; + + /* Last path element */ + const char *basename; + /* Leading dir length */ + size_t dirname_length; + + int depth; + int openCount; + int maxOpenCount; + int initial_dir_fd; + int working_dir_fd; + + struct stat lst; + struct stat st; + int descend; + int nlink; + /* How to restore time of a file. */ + struct restore_time restore_time; + + struct entry_sparse { + int64_t length; + int64_t offset; + } *sparse_list, *current_sparse; + int sparse_count; + int sparse_list_size; + + char initial_symlink_mode; + char symlink_mode; + struct filesystem *current_filesystem; + struct filesystem *filesystem_table; + int current_filesystem_id; + int max_filesystem_id; + int allocated_filesytem; + + int entry_fd; + int entry_eof; + int64_t entry_remaining_bytes; + int64_t entry_total; + unsigned char *entry_buff; + size_t entry_buff_size; +}; + +/* Definitions for tree.flags bitmap. */ +#define hasStat 16 /* The st entry is valid. */ +#define hasLstat 32 /* The lst entry is valid. */ +#define onWorkingDir 64 /* We are on the working dir where we are + * reading directory entry at this time. */ +#define needsRestoreTimes 128 + +static int +tree_dir_next_posix(struct tree *t); + +#ifdef HAVE_DIRENT_D_NAMLEN +/* BSD extension; avoids need for a strlen() call. */ +#define D_NAMELEN(dp) (dp)->d_namlen +#else +#define D_NAMELEN(dp) (strlen((dp)->d_name)) +#endif + +/* Initiate/terminate a tree traversal. */ +static struct tree *tree_open(const char *, int, int); +static struct tree *tree_reopen(struct tree *, const char *, int); +static void tree_close(struct tree *); +static void tree_free(struct tree *); +static void tree_push(struct tree *, const char *, int, int64_t, int64_t, + struct restore_time *); +static int tree_enter_initial_dir(struct tree *); +static int tree_enter_working_dir(struct tree *); +static int tree_current_dir_fd(struct tree *); + +/* + * tree_next() returns Zero if there is no next entry, non-zero if + * there is. Note that directories are visited three times. + * Directories are always visited first as part of enumerating their + * parent; that is a "regular" visit. If tree_descend() is invoked at + * that time, the directory is added to a work list and will + * subsequently be visited two more times: once just after descending + * into the directory ("postdescent") and again just after ascending + * back to the parent ("postascent"). + * + * TREE_ERROR_DIR is returned if the descent failed (because the + * directory couldn't be opened, for instance). This is returned + * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a + * fatal error, but it does imply that the relevant subtree won't be + * visited. TREE_ERROR_FATAL is returned for an error that left the + * traversal completely hosed. Right now, this is only returned for + * chdir() failures during ascent. + */ +#define TREE_REGULAR 1 +#define TREE_POSTDESCENT 2 +#define TREE_POSTASCENT 3 +#define TREE_ERROR_DIR -1 +#define TREE_ERROR_FATAL -2 + +static int tree_next(struct tree *); + +/* + * Return information about the current entry. + */ + +/* + * The current full pathname, length of the full pathname, and a name + * that can be used to access the file. Because tree does use chdir + * extensively, the access path is almost never the same as the full + * current path. + * + * TODO: On platforms that support it, use openat()-style operations + * to eliminate the chdir() operations entirely while still supporting + * arbitrarily deep traversals. This makes access_path troublesome to + * support, of course, which means we'll need a rich enough interface + * that clients can function without it. (In particular, we'll need + * tree_current_open() that returns an open file descriptor.) + * + */ +static const char *tree_current_path(struct tree *); +static const char *tree_current_access_path(struct tree *); + +/* + * Request the lstat() or stat() data for the current path. Since the + * tree package needs to do some of this anyway, and caches the + * results, you should take advantage of it here if you need it rather + * than make a redundant stat() or lstat() call of your own. + */ +static const struct stat *tree_current_stat(struct tree *); +static const struct stat *tree_current_lstat(struct tree *); +static int tree_current_is_symblic_link_target(struct tree *); + +/* The following functions use tricks to avoid a certain number of + * stat()/lstat() calls. */ +/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */ +static int tree_current_is_physical_dir(struct tree *); +/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */ +static int tree_current_is_dir(struct tree *); +static int update_current_filesystem(struct archive_read_disk *a, + int64_t dev); +static int setup_current_filesystem(struct archive_read_disk *); +static int tree_target_is_same_as_parent(struct tree *, const struct stat *); + +static int _archive_read_disk_open(struct archive *, const char *); +static int _archive_read_free(struct archive *); +static int _archive_read_close(struct archive *); +static int _archive_read_data_block(struct archive *, + const void **, size_t *, int64_t *); +static int _archive_read_next_header2(struct archive *, + struct archive_entry *); +static const char *trivial_lookup_gname(void *, int64_t gid); +static const char *trivial_lookup_uname(void *, int64_t uid); +static int setup_sparse(struct archive_read_disk *, struct archive_entry *); +static int close_and_restore_time(int fd, struct tree *, + struct restore_time *); + + +static struct archive_vtable * +archive_read_disk_vtable(void) +{ + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_free = _archive_read_free; + av.archive_close = _archive_read_close; + av.archive_read_data_block = _archive_read_data_block; + av.archive_read_next_header2 = _archive_read_next_header2; + inited = 1; + } + return (&av); +} + +const char * +archive_read_disk_gname(struct archive *_a, int64_t gid) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_gname")) + return (NULL); + if (a->lookup_gname == NULL) + return (NULL); + return ((*a->lookup_gname)(a->lookup_gname_data, gid)); +} + +const char * +archive_read_disk_uname(struct archive *_a, int64_t uid) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_uname")) + return (NULL); + if (a->lookup_uname == NULL) + return (NULL); + return ((*a->lookup_uname)(a->lookup_uname_data, uid)); +} + +int +archive_read_disk_set_gname_lookup(struct archive *_a, + void *private_data, + const char * (*lookup_gname)(void *private, int64_t gid), + void (*cleanup_gname)(void *private)) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup"); + + if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) + (a->cleanup_gname)(a->lookup_gname_data); + + a->lookup_gname = lookup_gname; + a->cleanup_gname = cleanup_gname; + a->lookup_gname_data = private_data; + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_uname_lookup(struct archive *_a, + void *private_data, + const char * (*lookup_uname)(void *private, int64_t uid), + void (*cleanup_uname)(void *private)) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup"); + + if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) + (a->cleanup_uname)(a->lookup_uname_data); + + a->lookup_uname = lookup_uname; + a->cleanup_uname = cleanup_uname; + a->lookup_uname_data = private_data; + return (ARCHIVE_OK); +} + +/* + * Create a new archive_read_disk object and initialize it with global state. + */ +struct archive * +archive_read_disk_new(void) +{ + struct archive_read_disk *a; + + a = (struct archive_read_disk *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_READ_DISK_MAGIC; + a->archive.state = ARCHIVE_STATE_NEW; + a->archive.vtable = archive_read_disk_vtable(); + a->lookup_uname = trivial_lookup_uname; + a->lookup_gname = trivial_lookup_gname; + a->entry_wd_fd = -1; + return (&a->archive); +} + +static int +_archive_read_free(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + int r; + + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free"); + + if (a->archive.state != ARCHIVE_STATE_CLOSED) + r = _archive_read_close(&a->archive); + else + r = ARCHIVE_OK; + + tree_free(a->tree); + if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) + (a->cleanup_gname)(a->lookup_gname_data); + if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) + (a->cleanup_uname)(a->lookup_uname_data); + archive_string_free(&a->archive.error_string); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a); + return (r); +} + +static int +_archive_read_close(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close"); + + if (a->archive.state != ARCHIVE_STATE_FATAL) + a->archive.state = ARCHIVE_STATE_CLOSED; + + tree_close(a->tree); + + return (ARCHIVE_OK); +} + +static void +setup_symlink_mode(struct archive_read_disk *a, char symlink_mode, + int follow_symlinks) +{ + a->symlink_mode = symlink_mode; + a->follow_symlinks = follow_symlinks; + if (a->tree != NULL) { + a->tree->initial_symlink_mode = a->symlink_mode; + a->tree->symlink_mode = a->symlink_mode; + } +} + +int +archive_read_disk_set_symlink_logical(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_logical"); + setup_symlink_mode(a, 'L', 1); + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_symlink_physical(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_physical"); + setup_symlink_mode(a, 'P', 0); + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_symlink_hybrid(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_hybrid"); + setup_symlink_mode(a, 'H', 1);/* Follow symlinks initially. */ + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_atime_restored(struct archive *_a) +{ +#ifndef HAVE_UTIMES + static int warning_done = 0; +#endif + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime"); +#ifdef HAVE_UTIMES + a->restore_time = 1; + if (a->tree != NULL) + a->tree->flags |= needsRestoreTimes; + return (ARCHIVE_OK); +#else + if (warning_done) + /* Warning was already emitted; suppress further warnings. */ + return (ARCHIVE_OK); + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Cannot restore access time on this system"); + warning_done = 1; + return (ARCHIVE_WARN); +#endif +} + +/* + * Trivial implementations of gname/uname lookup functions. + * These are normally overridden by the client, but these stub + * versions ensure that we always have something that works. + */ +static const char * +trivial_lookup_gname(void *private_data, int64_t gid) +{ + (void)private_data; /* UNUSED */ + (void)gid; /* UNUSED */ + return (NULL); +} + +static const char * +trivial_lookup_uname(void *private_data, int64_t uid) +{ + (void)private_data; /* UNUSED */ + (void)uid; /* UNUSED */ + return (NULL); +} + +/* + * Allocate memory for the reading buffer adjusted to the filesystem + * alignment. + */ +static int +setup_suitable_read_buffer(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + struct filesystem *cf = t->current_filesystem; + size_t asize; + size_t s; + + if (cf->allocation_ptr == NULL) { + /* If we couldn't get a filesystem alignment, + * we use 4096 as default value but we won't use + * O_DIRECT to open() and openat() operations. */ + long xfer_align = (cf->xfer_align == -1)?4096:cf->xfer_align; + + if (cf->max_xfer_size != -1) + asize = cf->max_xfer_size + xfer_align; + else { + long incr = cf->incr_xfer_size; + /* Some platform does not set a proper value to + * incr_xfer_size.*/ + if (incr < 0) + incr = cf->min_xfer_size; + if (cf->min_xfer_size < 0) { + incr = xfer_align; + asize = xfer_align; + } else + asize = cf->min_xfer_size; + + /* Increase a buffer size up to 64K bytes in + * a proper incremant size. */ + while (asize < 1024*64) + asize += incr; + /* Take a margin to adjust to the filesystem + * alignment. */ + asize += xfer_align; + } + cf->allocation_ptr = malloc(asize); + if (cf->allocation_ptr == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + /* + * Calculate proper address for the filesystem. + */ + s = (uintptr_t)cf->allocation_ptr; + s %= xfer_align; + if (s > 0) + s = xfer_align - s; + + /* + * Set a read buffer pointer in the proper alignment of + * the current filesystem. + */ + cf->buff = cf->allocation_ptr + s; + cf->buff_size = asize - xfer_align; + } + return (ARCHIVE_OK); +} + +static int +_archive_read_data_block(struct archive *_a, const void **buff, + size_t *size, int64_t *offset) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t = a->tree; + int r; + ssize_t bytes; + size_t buffbytes; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_block"); + + if (t->entry_eof || t->entry_remaining_bytes <= 0) { + r = ARCHIVE_EOF; + goto abort_read_data; + } + + /* + * Open the current file. + */ + if (t->entry_fd < 0) { + int flags = O_RDONLY | O_BINARY; + + /* + * Eliminate or reduce cache effects if we can. + * + * Carefully consider this to be enabled. + */ +#if defined(O_DIRECT) && 0/* Disabled for now */ + if (t->current_filesystem->xfer_align != -1 && + t->nlink == 1) + flags |= O_DIRECT; +#endif +#if defined(O_NOATIME) + /* + * Linux has O_NOATIME flag; use it if we need. + */ + if ((t->flags & needsRestoreTimes) != 0 && + t->restore_time.noatime == 0) + flags |= O_NOATIME; + do { +#endif +#ifdef HAVE_OPENAT + t->entry_fd = openat(tree_current_dir_fd(t), + tree_current_access_path(t), flags); +#else + tree_enter_working_dir(t); + t->entry_fd = open(tree_current_access_path(t), flags); +#endif +#if defined(O_NOATIME) + /* + * When we did open the file with O_NOATIME flag, + * if successful, set 1 to t->restore_time.noatime + * not to restore an atime of the file later. + * if failed by EPERM, retry it without O_NOATIME flag. + */ + if (flags & O_NOATIME) { + if (t->entry_fd >= 0) + t->restore_time.noatime = 1; + else if (errno == EPERM) { + flags &= ~O_NOATIME; + continue; + } + } + } while (0); +#endif + if (t->entry_fd < 0) { + archive_set_error(&a->archive, errno, + "Couldn't open %s", tree_current_path(t)); + r = ARCHIVE_FAILED; + tree_enter_initial_dir(t); + goto abort_read_data; + } + tree_enter_initial_dir(t); + } + + /* + * Allocate read buffer if not allocated. + */ + if (t->current_filesystem->allocation_ptr == NULL) { + r = setup_suitable_read_buffer(a); + if (r != ARCHIVE_OK) { + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + } + t->entry_buff = t->current_filesystem->buff; + t->entry_buff_size = t->current_filesystem->buff_size; + + buffbytes = t->entry_buff_size; + if (buffbytes > t->current_sparse->length) + buffbytes = t->current_sparse->length; + + /* + * Skip hole. + * TODO: Should we consider t->current_filesystem->xfer_align? + */ + if (t->current_sparse->offset > t->entry_total) { + if (lseek(t->entry_fd, + (off_t)t->current_sparse->offset, SEEK_SET) < 0) { + archive_set_error(&a->archive, errno, "Seek error"); + r = ARCHIVE_FATAL; + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + bytes = t->current_sparse->offset - t->entry_total; + t->entry_remaining_bytes -= bytes; + t->entry_total += bytes; + } + + /* + * Read file contents. + */ + if (buffbytes > 0) { + bytes = read(t->entry_fd, t->entry_buff, buffbytes); + if (bytes < 0) { + archive_set_error(&a->archive, errno, "Read error"); + r = ARCHIVE_FATAL; + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + } else + bytes = 0; + if (bytes == 0) { + /* Get EOF */ + t->entry_eof = 1; + r = ARCHIVE_EOF; + goto abort_read_data; + } + *buff = t->entry_buff; + *size = bytes; + *offset = t->entry_total; + t->entry_total += bytes; + t->entry_remaining_bytes -= bytes; + if (t->entry_remaining_bytes == 0) { + /* Close the current file descriptor */ + close_and_restore_time(t->entry_fd, t, &t->restore_time); + t->entry_fd = -1; + t->entry_eof = 1; + } + t->current_sparse->offset += bytes; + t->current_sparse->length -= bytes; + if (t->current_sparse->length == 0 && !t->entry_eof) + t->current_sparse++; + return (ARCHIVE_OK); + +abort_read_data: + *buff = NULL; + *size = 0; + *offset = t->entry_total; + if (t->entry_fd >= 0) { + /* Close the current file descriptor */ + close_and_restore_time(t->entry_fd, t, &t->restore_time); + t->entry_fd = -1; + } + return (r); +} + +static int +_archive_read_next_header2(struct archive *_a, struct archive_entry *entry) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t; + const struct stat *st; /* info to use for this entry */ + const struct stat *lst;/* lstat() information */ + int descend, fd = -1, r; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_read_next_header2"); + + t = a->tree; + if (t->entry_fd >= 0) { + close_and_restore_time(t->entry_fd, t, &t->restore_time); + t->entry_fd = -1; + } +#if !(defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR)) + /* Restore working directory. */ + tree_enter_working_dir(t); +#endif + st = NULL; + lst = NULL; + do { + switch (tree_next(t)) { + case TREE_ERROR_FATAL: + archive_set_error(&a->archive, t->tree_errno, + "%s: Unable to continue traversing directory tree", + tree_current_path(t)); + a->archive.state = ARCHIVE_STATE_FATAL; + tree_enter_initial_dir(t); + return (ARCHIVE_FATAL); + case TREE_ERROR_DIR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: Couldn't visit directory", + tree_current_path(t)); + tree_enter_initial_dir(t); + return (ARCHIVE_FAILED); + case 0: + tree_enter_initial_dir(t); + return (ARCHIVE_EOF); + case TREE_POSTDESCENT: + case TREE_POSTASCENT: + break; + case TREE_REGULAR: + lst = tree_current_lstat(t); + if (lst == NULL) { + archive_set_error(&a->archive, errno, + "%s: Cannot stat", + tree_current_path(t)); + tree_enter_initial_dir(t); + return (ARCHIVE_FAILED); + } + break; + } + } while (lst == NULL); + + /* + * Distinguish 'L'/'P'/'H' symlink following. + */ + switch(t->symlink_mode) { + case 'H': + /* 'H': After the first item, rest like 'P'. */ + t->symlink_mode = 'P'; + /* 'H': First item (from command line) like 'L'. */ + /* FALLTHROUGH */ + case 'L': + /* 'L': Do descend through a symlink to dir. */ + descend = tree_current_is_dir(t); + /* 'L': Follow symlinks to files. */ + a->symlink_mode = 'L'; + a->follow_symlinks = 1; + /* 'L': Archive symlinks as targets, if we can. */ + st = tree_current_stat(t); + if (st != NULL && !tree_target_is_same_as_parent(t, st)) + break; + /* If stat fails, we have a broken symlink; + * in that case, don't follow the link. */ + /* FALLTHROUGH */ + default: + /* 'P': Don't descend through a symlink to dir. */ + descend = tree_current_is_physical_dir(t); + /* 'P': Don't follow symlinks to files. */ + a->symlink_mode = 'P'; + a->follow_symlinks = 0; + /* 'P': Archive symlinks as symlinks. */ + st = lst; + break; + } + + if (update_current_filesystem(a, st->st_dev) != ARCHIVE_OK) { + a->archive.state = ARCHIVE_STATE_FATAL; + tree_enter_initial_dir(t); + return (ARCHIVE_FATAL); + } + t->descend = descend; + + archive_entry_set_pathname(entry, tree_current_path(t)); + archive_entry_copy_sourcepath(entry, tree_current_access_path(t)); + archive_entry_copy_stat(entry, st); + + /* Save the times to be restored. */ + t->restore_time.mtime = archive_entry_mtime(entry); + t->restore_time.mtime_nsec = archive_entry_mtime_nsec(entry); + t->restore_time.atime = archive_entry_atime(entry); + t->restore_time.atime_nsec = archive_entry_atime_nsec(entry); + t->restore_time.filetype = archive_entry_filetype(entry); + t->restore_time.noatime = t->current_filesystem->noatime; + +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + /* + * Open the current file to freely gather its metadata anywhere in + * working directory. + * Note: A symbolic link file cannot be opened with O_NOFOLLOW. + */ + if (a->follow_symlinks || archive_entry_filetype(entry) != AE_IFLNK) + fd = openat(tree_current_dir_fd(t), tree_current_access_path(t), + O_RDONLY | O_NONBLOCK); + /* Restore working directory if openat() operation failed or + * the file is a symbolic link. */ + if (fd < 0) + tree_enter_working_dir(t); + + /* The current direcotry fd is needed at + * archive_read_disk_entry_from_file() function to read link data + * with readlinkat(). */ + a->entry_wd_fd = tree_current_dir_fd(t); +#endif + + /* + * Populate the archive_entry with metadata from the disk. + */ + r = archive_read_disk_entry_from_file(&(a->archive), entry, fd, st); + + /* Close the file descriptor used for reding the current file + * metadata at archive_read_disk_entry_from_file(). */ + if (fd >= 0) + close(fd); + + /* Return to the initial directory. */ + tree_enter_initial_dir(t); + archive_entry_copy_sourcepath(entry, tree_current_path(t)); + + /* + * EOF and FATAL are persistent at this layer. By + * modifying the state, we guarantee that future calls to + * read a header or read data will fail. + */ + switch (r) { + case ARCHIVE_EOF: + a->archive.state = ARCHIVE_STATE_EOF; + break; + case ARCHIVE_OK: + case ARCHIVE_WARN: + t->entry_total = 0; + if (archive_entry_filetype(entry) == AE_IFREG) { + t->nlink = archive_entry_nlink(entry); + t->entry_remaining_bytes = archive_entry_size(entry); + t->entry_eof = (t->entry_remaining_bytes == 0)? 1: 0; + if (!t->entry_eof && + setup_sparse(a, entry) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + t->entry_remaining_bytes = 0; + t->entry_eof = 1; + } + a->archive.state = ARCHIVE_STATE_DATA; + break; + case ARCHIVE_RETRY: + break; + case ARCHIVE_FATAL: + a->archive.state = ARCHIVE_STATE_FATAL; + break; + } + + return (r); +} + +static int +setup_sparse(struct archive_read_disk *a, struct archive_entry *entry) +{ + struct tree *t = a->tree; + int64_t length, offset; + int i; + + t->sparse_count = archive_entry_sparse_reset(entry); + if (t->sparse_count+1 > t->sparse_list_size) { + free(t->sparse_list); + t->sparse_list_size = t->sparse_count + 1; + t->sparse_list = malloc(sizeof(t->sparse_list[0]) * + t->sparse_list_size); + if (t->sparse_list == NULL) { + t->sparse_list_size = 0; + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + } + for (i = 0; i < t->sparse_count; i++) { + archive_entry_sparse_next(entry, &offset, &length); + t->sparse_list[i].offset = offset; + t->sparse_list[i].length = length; + } + if (i == 0) { + t->sparse_list[i].offset = 0; + t->sparse_list[i].length = archive_entry_size(entry); + } else { + t->sparse_list[i].offset = archive_entry_size(entry); + t->sparse_list[i].length = 0; + } + t->current_sparse = t->sparse_list; + + return (ARCHIVE_OK); +} + +/* + * Called by the client to mark the directory just returned from + * tree_next() as needing to be visited. + */ +int +archive_read_disk_descend(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t = a->tree; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_descend"); + + if (t->visit_type != TREE_REGULAR || !t->descend) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignored the request descending the current object"); + return (ARCHIVE_WARN); + } + + if (tree_current_is_physical_dir(t)) { + tree_push(t, t->basename, t->current_filesystem_id, + t->lst.st_dev, t->lst.st_ino, &t->restore_time); + t->stack->flags |= isDir; + } else if (tree_current_is_dir(t)) { + tree_push(t, t->basename, t->current_filesystem_id, + t->st.st_dev, t->st.st_ino, &t->restore_time); + t->stack->flags |= isDirLink; + } + t->descend = 0; + return (ARCHIVE_OK); +} + +int +archive_read_disk_open(struct archive *_a, const char *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED, + "archive_read_disk_open"); + archive_clear_error(&a->archive); + + return (_archive_read_disk_open(_a, pathname)); +} + +int +archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct archive_string path; + int ret; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED, + "archive_read_disk_open_w"); + archive_clear_error(&a->archive); + + /* Make a char string from a wchar_t string. */ + archive_string_init(&path); + if (archive_string_append_from_wcs(&path, pathname, + wcslen(pathname)) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't convert a path to a char string"); + a->archive.state = ARCHIVE_STATE_FATAL; + ret = ARCHIVE_FATAL; + } else + ret = _archive_read_disk_open(_a, path.s); + + archive_string_free(&path); + return (ret); +} + +static int +_archive_read_disk_open(struct archive *_a, const char *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + if (a->tree != NULL) + a->tree = tree_reopen(a->tree, pathname, a->restore_time); + else + a->tree = tree_open(pathname, a->symlink_mode, + a->restore_time); + if (a->tree == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate tar data"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + a->archive.state = ARCHIVE_STATE_HEADER; + + return (ARCHIVE_OK); +} + +/* + * Return a current filesystem ID which is index of the filesystem entry + * you've visited through archive_read_disk. + */ +int +archive_read_disk_current_filesystem(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem_id); +} + +static int +update_current_filesystem(struct archive_read_disk *a, int64_t dev) +{ + struct tree *t = a->tree; + int i, fid; + + if (t->current_filesystem != NULL && + t->current_filesystem->dev == dev) + return (ARCHIVE_OK); + + for (i = 0; i < t->max_filesystem_id; i++) { + if (t->filesystem_table[i].dev == dev) { + /* There is the filesytem ID we've already generated. */ + t->current_filesystem_id = i; + t->current_filesystem = &(t->filesystem_table[i]); + return (ARCHIVE_OK); + } + } + + /* + * This is the new filesytem which we have to generate a new ID for. + */ + fid = t->max_filesystem_id++; + if (t->max_filesystem_id > t->allocated_filesytem) { + size_t s; + + s = t->max_filesystem_id * 2; + t->filesystem_table = realloc(t->filesystem_table, + s * sizeof(*t->filesystem_table)); + if (t->filesystem_table == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate tar data"); + return (ARCHIVE_FATAL); + } + t->allocated_filesytem = s; + } + t->current_filesystem_id = fid; + t->current_filesystem = &(t->filesystem_table[fid]); + t->current_filesystem->dev = dev; + t->current_filesystem->allocation_ptr = NULL; + t->current_filesystem->buff = NULL; + + /* Setup the current filesystem properties which depend on + * platform specific. */ + return (setup_current_filesystem(a)); +} + +/* + * Returns 1 if current filesystem is generated filesystem, 0 if it is not + * or -1 if it is unknown. + */ +int +archive_read_disk_current_filesystem_is_synthetic(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem->synthetic); +} + +/* + * Returns 1 if current filesystem is remote filesystem, 0 if it is not + * or -1 if it is unknown. + */ +int +archive_read_disk_current_filesystem_is_remote(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem->remote); +} + +#if defined(_PC_REC_INCR_XFER_SIZE) && defined(_PC_REC_MAX_XFER_SIZE) &&\ + defined(_PC_REC_MIN_XFER_SIZE) && defined(_PC_REC_XFER_ALIGN) +static int +get_xfer_size(struct tree *t, int fd, const char *path) +{ + t->current_filesystem->xfer_align = -1; + errno = 0; + if (fd >= 0) { + t->current_filesystem->incr_xfer_size = + fpathconf(fd, _PC_REC_INCR_XFER_SIZE); + t->current_filesystem->max_xfer_size = + fpathconf(fd, _PC_REC_MAX_XFER_SIZE); + t->current_filesystem->min_xfer_size = + fpathconf(fd, _PC_REC_MIN_XFER_SIZE); + t->current_filesystem->xfer_align = + fpathconf(fd, _PC_REC_XFER_ALIGN); + } else if (path != NULL) { + t->current_filesystem->incr_xfer_size = + pathconf(path, _PC_REC_INCR_XFER_SIZE); + t->current_filesystem->max_xfer_size = + pathconf(path, _PC_REC_MAX_XFER_SIZE); + t->current_filesystem->min_xfer_size = + pathconf(path, _PC_REC_MIN_XFER_SIZE); + t->current_filesystem->xfer_align = + pathconf(path, _PC_REC_XFER_ALIGN); + } + /* At least we need an alignment size. */ + if (t->current_filesystem->xfer_align == -1) + return ((errno == EINVAL)?1:-1); + else + return (0); +} +#else +static int +get_xfer_size(struct tree *t, int fd, const char *path) +{ + (void)t; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)path; /* UNUSED */ + return (1);/* Not supported */ +} +#endif + +#if defined(HAVE_STATFS) && defined(HAVE_FSTATFS) && defined(MNT_LOCAL) \ + && !defined(ST_LOCAL) + +/* + * Gather current filesystem properties on FreeBSD, OpenBSD and Mac OS X. + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + struct statfs sfs; +#if defined(HAVE_GETVFSBYNAME) && defined(VFCF_SYNTHETIC) + struct xvfsconf vfc; +#endif + int r, xr = 0; +#if !defined(HAVE_STRUCT_STATFS_F_NAMEMAX) + long nm; +#endif + + t->current_filesystem->synthetic = -1; + t->current_filesystem->remote = -1; + if (tree_current_is_symblic_link_target(t)) { +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + /* + * Get file system statistics on any directory + * where current is. + */ + int fd = openat(tree_current_dir_fd(t), + tree_current_access_path(t), O_RDONLY); + if (fd < 0) { + archive_set_error(&a->archive, errno, + "openat failed"); + return (ARCHIVE_FAILED); + } + r = fstatfs(fd, &sfs); + if (r == 0) + xr = get_xfer_size(t, fd, NULL); + close(fd); +#else + r = statfs(tree_current_access_path(t), &sfs); + if (r == 0) + xr = get_xfer_size(t, -1, tree_current_access_path(t)); +#endif + } else { + r = fstatfs(tree_current_dir_fd(t), &sfs); + if (r == 0) + xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); + } + if (r == -1 || xr == -1) { + archive_set_error(&a->archive, errno, "statfs failed"); + return (ARCHIVE_FAILED); + } else if (xr == 1) { + /* pathconf(_PC_REX_*) operations are not supported. */ + t->current_filesystem->xfer_align = sfs.f_bsize; + t->current_filesystem->max_xfer_size = -1; + t->current_filesystem->min_xfer_size = sfs.f_iosize; + t->current_filesystem->incr_xfer_size = sfs.f_iosize; + } + if (sfs.f_flags & MNT_LOCAL) + t->current_filesystem->remote = 0; + else + t->current_filesystem->remote = 1; + +#if defined(HAVE_GETVFSBYNAME) && defined(VFCF_SYNTHETIC) + r = getvfsbyname(sfs.f_fstypename, &vfc); + if (r == -1) { + archive_set_error(&a->archive, errno, "getvfsbyname failed"); + return (ARCHIVE_FAILED); + } + if (vfc.vfc_flags & VFCF_SYNTHETIC) + t->current_filesystem->synthetic = 1; + else + t->current_filesystem->synthetic = 0; +#endif + +#if defined(MNT_NOATIME) + if (sfs.f_flags & MNT_NOATIME) + t->current_filesystem->noatime = 1; + else +#endif + t->current_filesystem->noatime = 0; + +#if defined(HAVE_READDIR_R) + /* Set maximum filename length. */ +#if defined(HAVE_STRUCT_STATFS_F_NAMEMAX) + t->current_filesystem->name_max = sfs.f_namemax; +#else + /* Mac OS X does not have f_namemax in struct statfs. */ + if (tree_current_is_symblic_link_target(t)) + nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX); + else + nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX); + if (nm == -1) + t->current_filesystem->name_max = NAME_MAX; + else + t->current_filesystem->name_max = nm; +#endif +#endif /* HAVE_READDIR_R */ + return (ARCHIVE_OK); +} + +#elif (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)) && defined(ST_LOCAL) + +/* + * Gather current filesystem properties on NetBSD + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + struct statvfs sfs; + int r, xr = 0; + + t->current_filesystem->synthetic = -1; + if (tree_current_is_symblic_link_target(t)) { + r = statvfs(tree_current_access_path(t), &sfs); + 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); + if (r == 0) + xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); +#else + r = statvfs(".", &sfs); + if (r == 0) + xr = get_xfer_size(t, -1, "."); +#endif + } + if (r == -1 || xr == -1) { + t->current_filesystem->remote = -1; + archive_set_error(&a->archive, errno, "statvfs failed"); + return (ARCHIVE_FAILED); + } else if (xr == 1) { + /* Usuall come here unless NetBSD supports _PC_REC_XFER_ALIGN + * for pathconf() function. */ + t->current_filesystem->xfer_align = sfs.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; +#else + t->current_filesystem->min_xfer_size = sfs.f_bsize; + t->current_filesystem->incr_xfer_size = sfs.f_bsize; +#endif + } + if (sfs.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) + t->current_filesystem->noatime = 1; + else +#endif + t->current_filesystem->noatime = 0; + + /* Set maximum filename length. */ + t->current_filesystem->name_max = sfs.f_namemax; + return (ARCHIVE_OK); +} + +#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_LINUX_MAGIC_H) &&\ + defined(HAVE_STATFS) && defined(HAVE_FSTATFS) +/* + * Note: statfs is deprecated since LSB 3.2 + */ + +#ifndef CIFS_SUPER_MAGIC +#define CIFS_SUPER_MAGIC 0xFF534D42 +#endif +#ifndef DEVFS_SUPER_MAGIC +#define DEVFS_SUPER_MAGIC 0x1373 +#endif + +/* + * Gather current filesystem properties on Linux + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + struct statfs sfs; + struct statvfs svfs; + int r, vr = 0, xr = 0; + + if (tree_current_is_symblic_link_target(t)) { +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + /* + * Get file system statistics on any directory + * where current is. + */ + int fd = openat(tree_current_dir_fd(t), + tree_current_access_path(t), O_RDONLY); + if (fd < 0) { + archive_set_error(&a->archive, errno, + "openat failed"); + return (ARCHIVE_FAILED); + } + vr = fstatvfs(fd, &svfs);/* for f_flag, mount flags */ + r = fstatfs(fd, &sfs); + if (r == 0) + xr = get_xfer_size(t, fd, NULL); + close(fd); +#else + vr = statvfs(tree_current_access_path(t), &svfs); + r = statfs(tree_current_access_path(t), &sfs); + if (r == 0) + xr = get_xfer_size(t, -1, tree_current_access_path(t)); +#endif + } else { +#ifdef HAVE_FSTATFS + vr = fstatvfs(tree_current_dir_fd(t), &svfs); + r = fstatfs(tree_current_dir_fd(t), &sfs); + if (r == 0) + xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); +#elif defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) +#error "Unexpected case. Please tell us about this error." +#else + vr = statvfs(".", &svfs); + r = statfs(".", &sfs); + if (r == 0) + xr = get_xfer_size(t, -1, "."); +#endif + } + if (r == -1 || xr == -1 || vr == -1) { + t->current_filesystem->synthetic = -1; + t->current_filesystem->remote = -1; + archive_set_error(&a->archive, errno, "statfs failed"); + return (ARCHIVE_FAILED); + } else if (xr == 1) { + /* pathconf(_PC_REX_*) operations are not supported. */ + t->current_filesystem->xfer_align = svfs.f_frsize; + t->current_filesystem->max_xfer_size = -1; + t->current_filesystem->min_xfer_size = svfs.f_bsize; + t->current_filesystem->incr_xfer_size = svfs.f_bsize; + } + switch (sfs.f_type) { + case AFS_SUPER_MAGIC: + case CIFS_SUPER_MAGIC: + case CODA_SUPER_MAGIC: + case NCP_SUPER_MAGIC:/* NetWare */ + case NFS_SUPER_MAGIC: + case SMB_SUPER_MAGIC: + t->current_filesystem->remote = 1; + t->current_filesystem->synthetic = 0; + break; + case DEVFS_SUPER_MAGIC: + case PROC_SUPER_MAGIC: + case USBDEVICE_SUPER_MAGIC: + t->current_filesystem->remote = 0; + t->current_filesystem->synthetic = 1; + break; + default: + t->current_filesystem->remote = 0; + t->current_filesystem->synthetic = 0; + break; + } + +#if defined(ST_NOATIME) + if (svfs.f_flag & ST_NOATIME) + t->current_filesystem->noatime = 1; + else +#endif + t->current_filesystem->noatime = 0; + +#if defined(HAVE_READDIR_R) + /* Set maximum filename length. */ + t->current_filesystem->name_max = sfs.f_namelen; +#endif + return (ARCHIVE_OK); +} + +#elif defined(HAVE_SYS_STATVFS_H) &&\ + (defined(HAVE_STATVFS) || defined(HAVE_FSTATVFS)) + +/* + * Gather current filesystem properties on other posix platform. + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + struct statvfs sfs; + int r, xr = 0; + + t->current_filesystem->synthetic = -1;/* Not supported */ + t->current_filesystem->remote = -1;/* Not supported */ + if (tree_current_is_symblic_link_target(t)) { +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + /* + * Get file system statistics on any directory + * where current is. + */ + int fd = openat(tree_current_dir_fd(t), + tree_current_access_path(t), O_RDONLY); + if (fd < 0) { + archive_set_error(&a->archive, errno, + "openat failed"); + return (ARCHIVE_FAILED); + } + r = fstatvfs(fd, &sfs); + if (r == 0) + xr = get_xfer_size(t, fd, NULL); + close(fd); +#else + r = statvfs(tree_current_access_path(t), &sfs); + 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); + if (r == 0) + xr = get_xfer_size(t, tree_current_dir_fd(t), NULL); +#elif defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) +#error "Unexpected case. Please tell us about this error." +#else + r = statvfs(".", &sfs); + if (r == 0) + xr = get_xfer_size(t, -1, "."); +#endif + } + if (r == -1 || xr == -1) { + t->current_filesystem->synthetic = -1; + t->current_filesystem->remote = -1; + archive_set_error(&a->archive, errno, "statvfs failed"); + 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->max_xfer_size = -1; + t->current_filesystem->min_xfer_size = sfs.f_bsize; + t->current_filesystem->incr_xfer_size = sfs.f_bsize; + } + +#if defined(ST_NOATIME) + if (sfs.f_flag & ST_NOATIME) + t->current_filesystem->noatime = 1; + else +#endif + t->current_filesystem->noatime = 0; + +#if defined(HAVE_READDIR_R) + /* Set maximum filename length. */ + t->current_filesystem->name_max = sfs.f_namemax; +#endif + return (ARCHIVE_OK); +} + +#else + +/* + * Generic: Gather current filesystem properties. + * TODO: Is this generic function really needed? + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; +#if defined(_PC_NAME_MAX) && defined(HAVE_READDIR_R) + long nm; +#endif + t->current_filesystem->synthetic = -1;/* Not supported */ + t->current_filesystem->remote = -1;/* Not supported */ + t->current_filesystem->noatime = 0; + (void)get_xfer_size(t, -1, ".");/* Dummy call to avoid build error. */ + t->current_filesystem->xfer_align = -1;/* Unknown */ + t->current_filesystem->max_xfer_size = -1; + t->current_filesystem->min_xfer_size = -1; + t->current_filesystem->incr_xfer_size = -1; + +#if defined(HAVE_READDIR_R) + /* Set maximum filename length. */ +# if defined(_PC_NAME_MAX) + if (tree_current_is_symblic_link_target(t)) + nm = pathconf(tree_current_access_path(t), _PC_NAME_MAX); + else + nm = fpathconf(tree_current_dir_fd(t), _PC_NAME_MAX); + if (nm == -1) +# endif /* _PC_NAME_MAX */ + /* + * Some sysmtes (HP-UX or others?) incorrectly defined + * NAME_MAX macro to be a smaller value. + */ +# if defined(NAME_MAX) && NAME_MAX >= 255 + t->current_filesystem->name_max = NAME_MAX; +# else + /* No way to get a trusted value of maximum filename + * length. */ + t->current_filesystem->name_max = PATH_MAX; +# endif /* NAME_MAX */ +# if defined(_PC_NAME_MAX) + else + t->current_filesystem->name_max = nm; +# endif /* _PC_NAME_MAX */ +#endif /* HAVE_READDIR_R */ + return (ARCHIVE_OK); +} + +#endif + +static int +close_and_restore_time(int fd, struct tree *t, struct restore_time *rt) +{ +#ifndef HAVE_UTIMES + (void)a; /* UNUSED */ + return (close(fd)); +#else +#if defined(HAVE_FUTIMENS) && !defined(__CYGWIN__) + struct timespec timespecs[2]; +#endif + struct timeval times[2]; + + if ((t->flags & needsRestoreTimes) == 0 || rt->noatime) { + if (fd >= 0) + return (close(fd)); + else + return (0); + } + +#if defined(HAVE_FUTIMENS) && !defined(__CYGWIN__) + timespecs[1].tv_sec = rt->mtime; + timespecs[1].tv_nsec = rt->mtime_nsec; + + timespecs[0].tv_sec = rt->atime; + timespecs[0].tv_nsec = rt->atime_nsec; + /* futimens() is defined in POSIX.1-2008. */ + if (futimens(fd, timespecs) == 0) + return (close(fd)); +#endif + + times[1].tv_sec = rt->mtime; + times[1].tv_usec = rt->mtime_nsec / 1000; + + times[0].tv_sec = rt->atime; + times[0].tv_usec = rt->atime_nsec / 1000; + +#if !defined(HAVE_FUTIMENS) && defined(HAVE_FUTIMES) && !defined(__CYGWIN__) + if (futimes(fd, times) == 0) + return (close(fd)); +#endif + close(fd); +#if defined(HAVE_FUTIMESAT) + if (futimesat(tree_current_dir_fd(t), rt->name, times) == 0) + return (0); +#endif +#ifdef HAVE_LUTIMES + if (lutimes(rt->name, times) != 0) +#else + if (AE_IFLNK != rt->filetype && utimes(rt->name, times) != 0) +#endif + return (-1); +#endif + return (0); +} + +/* + * Add a directory path to the current stack. + */ +static void +tree_push(struct tree *t, const char *path, int filesystem_id, + int64_t dev, int64_t ino, struct restore_time *rt) +{ + struct tree_entry *te; + + te = malloc(sizeof(*te)); + memset(te, 0, sizeof(*te)); + te->next = t->stack; + te->parent = t->current; + if (te->parent) + te->depth = te->parent->depth + 1; + t->stack = te; + archive_string_init(&te->name); + te->symlink_parent_fd = -1; + archive_strcpy(&te->name, path); + te->flags = needsDescent | needsOpen | needsAscent; + te->filesystem_id = filesystem_id; + te->dev = dev; + te->ino = ino; + te->dirname_length = t->dirname_length; + te->restore_time.name = te->name.s; + if (rt != NULL) { + te->restore_time.mtime = rt->mtime; + te->restore_time.mtime_nsec = rt->mtime_nsec; + te->restore_time.atime = rt->atime; + te->restore_time.atime_nsec = rt->atime_nsec; + te->restore_time.filetype = rt->filetype; + te->restore_time.noatime = rt->noatime; + } +} + +/* + * Append a name to the current dir path. + */ +static void +tree_append(struct tree *t, const char *name, size_t name_length) +{ + size_t size_needed; + + t->path.s[t->dirname_length] = '\0'; + t->path.length = t->dirname_length; + /* Strip trailing '/' from name, unless entire name is "/". */ + while (name_length > 1 && name[name_length - 1] == '/') + name_length--; + + /* Resize pathname buffer as needed. */ + size_needed = name_length + t->dirname_length + 2; + archive_string_ensure(&t->path, size_needed); + /* Add a separating '/' if it's needed. */ + if (t->dirname_length > 0 && t->path.s[archive_strlen(&t->path)-1] != '/') + archive_strappend_char(&t->path, '/'); + t->basename = t->path.s + archive_strlen(&t->path); + archive_strncat(&t->path, name, name_length); + t->restore_time.name = t->basename; +} + +/* + * Open a directory tree for traversal. + */ +static struct tree * +tree_open(const char *path, int symlink_mode, int restore_time) +{ + struct tree *t; + + if ((t = malloc(sizeof(*t))) == NULL) + return (NULL); + memset(t, 0, sizeof(*t)); + archive_string_init(&t->path); + archive_string_ensure(&t->path, 31); + t->initial_symlink_mode = symlink_mode; + return (tree_reopen(t, path, restore_time)); +} + +static struct tree * +tree_reopen(struct tree *t, const char *path, int restore_time) +{ + t->flags = (restore_time)?needsRestoreTimes:0; + t->visit_type = 0; + t->tree_errno = 0; + t->dirname_length = 0; + t->depth = 0; + t->descend = 0; + t->current = NULL; + t->d = INVALID_DIR_HANDLE; + t->symlink_mode = t->initial_symlink_mode; + archive_string_empty(&t->path); + t->entry_fd = -1; + t->entry_eof = 0; + t->entry_remaining_bytes = 0; + + /* First item is set up a lot like a symlink traversal. */ + tree_push(t, path, 0, 0, 0, NULL); + t->stack->flags = needsFirstVisit; + t->maxOpenCount = t->openCount = 1; + t->initial_dir_fd = open(".", O_RDONLY); + t->working_dir_fd = dup(t->initial_dir_fd); + return (t); +} + +static int +tree_descent(struct tree *t) +{ + int r = 0; + +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + int new_fd; + t->dirname_length = archive_strlen(&t->path); + new_fd = openat(t->working_dir_fd, t->stack->name.s, O_RDONLY); + if (new_fd < 0) { + t->tree_errno = errno; + r = TREE_ERROR_DIR; + } else { + t->depth++; + /* If it is a link, set up fd for the ascent. */ + if (t->stack->flags & isDirLink) { + t->stack->symlink_parent_fd = t->working_dir_fd; + t->openCount++; + if (t->openCount > t->maxOpenCount) + t->maxOpenCount = t->openCount; + } else + close(t->working_dir_fd); + t->working_dir_fd = new_fd; + } +#else + /* If it is a link, set up fd for the ascent. */ + if (t->stack->flags & isDirLink) + t->stack->symlink_parent_fd = t->working_dir_fd; + else { + close(t->working_dir_fd); + t->openCount--; + } + t->working_dir_fd = -1; + t->dirname_length = archive_strlen(&t->path); + if (chdir(t->stack->name.s) != 0) + { + t->tree_errno = errno; + r = TREE_ERROR_DIR; + } else { + t->depth++; + t->working_dir_fd = open(".", O_RDONLY); + t->openCount++; + if (t->openCount > t->maxOpenCount) + t->maxOpenCount = t->openCount; + } +#endif + return (r); +} + +/* + * We've finished a directory; ascend back to the parent. + */ +static int +tree_ascend(struct tree *t) +{ + struct tree_entry *te; + int r = 0, prev_dir_fd; + + te = t->stack; + prev_dir_fd = t->working_dir_fd; +#if defined(HAVE_OPENAT) && defined(HAVE_FSTATAT) && defined(HAVE_FDOPENDIR) + if (te->flags & isDirLink) + t->working_dir_fd = te->symlink_parent_fd; + else { + int new_fd = openat(t->working_dir_fd, "..", O_RDONLY); + if (new_fd < 0) { + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } else + t->working_dir_fd = new_fd; + } +#else + if (te->flags & isDirLink) { + if (fchdir(te->symlink_parent_fd) != 0) { + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } else + t->working_dir_fd = te->symlink_parent_fd; + } else { + if (chdir("..") != 0) { + t->tree_errno = errno; + r = TREE_ERROR_FATAL; + } else + t->working_dir_fd = open(".", O_RDONLY); + } +#endif + if (r == 0) { + /* Current directory has been changed, we should + * close an fd of previous working directory. */ + close_and_restore_time(prev_dir_fd, t, &te->restore_time); + if (te->flags & isDirLink) { + t->openCount--; + te->symlink_parent_fd = -1; + } + t->depth--; + } + return (r); +} + +/* + * Return to the initial directory where tree_open() was performed. + */ +static int +tree_enter_initial_dir(struct tree *t) +{ + int r = 0; + + if (t->flags & onWorkingDir) { + r = fchdir(t->initial_dir_fd); + if (r == 0) + t->flags &= ~onWorkingDir; + } + return (r); +} + +/* + * Restore working directory of directory traversals. + */ +static int +tree_enter_working_dir(struct tree *t) +{ + int r = 0; + + /* + * Change the current directory if really needed. + * Sometimes this is unneeded when we did not do + * descent. + */ + if (t->depth > 0 && (t->flags & onWorkingDir) == 0) { + r = fchdir(t->working_dir_fd); + if (r == 0) + t->flags |= onWorkingDir; + } + return (r); +} + +static int +tree_current_dir_fd(struct tree *t) +{ + return (t->working_dir_fd); +} + +/* + * Pop the working stack. + */ +static void +tree_pop(struct tree *t) +{ + struct tree_entry *te; + + t->path.s[t->dirname_length] = '\0'; + t->path.length = t->dirname_length; + if (t->stack == t->current && t->current != NULL) + t->current = t->current->parent; + te = t->stack; + t->stack = te->next; + t->dirname_length = te->dirname_length; + t->basename = t->path.s + t->dirname_length; + while (t->basename[0] == '/') + t->basename++; + archive_string_free(&te->name); + free(te); +} + +/* + * Get the next item in the tree traversal. + */ +static int +tree_next(struct tree *t) +{ + int r; + + while (t->stack != NULL) { + /* If there's an open dir, get the next entry from there. */ + if (t->d != INVALID_DIR_HANDLE) { + r = tree_dir_next_posix(t); + if (r == 0) + continue; + return (r); + } + + if (t->stack->flags & needsFirstVisit) { + /* Top stack item needs a regular visit. */ + t->current = t->stack; + tree_append(t, t->stack->name.s, + archive_strlen(&(t->stack->name))); + /* t->dirname_length = t->path_length; */ + /* tree_pop(t); */ + t->stack->flags &= ~needsFirstVisit; + return (t->visit_type = TREE_REGULAR); + } else if (t->stack->flags & needsDescent) { + /* Top stack item is dir to descend into. */ + t->current = t->stack; + tree_append(t, t->stack->name.s, + archive_strlen(&(t->stack->name))); + t->stack->flags &= ~needsDescent; + r = tree_descent(t); + if (r != 0) { + tree_pop(t); + t->visit_type = r; + } else + t->visit_type = TREE_POSTDESCENT; + return (t->visit_type); + } else if (t->stack->flags & needsOpen) { + t->stack->flags &= ~needsOpen; + r = tree_dir_next_posix(t); + if (r == 0) + continue; + return (r); + } else if (t->stack->flags & needsAscent) { + /* Top stack item is dir and we're done with it. */ + r = tree_ascend(t); + tree_pop(t); + t->visit_type = r != 0 ? r : TREE_POSTASCENT; + return (t->visit_type); + } else { + /* Top item on stack is dead. */ + tree_pop(t); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + } + } + return (t->visit_type = 0); +} + +static int +tree_dir_next_posix(struct tree *t) +{ + int r; + const char *name; + size_t namelen; + + if (t->d == NULL) { +#if defined(HAVE_READDIR_R) + size_t dirent_size; +#endif + +#if defined(HAVE_FDOPENDIR) + if ((t->d = fdopendir(dup(t->working_dir_fd))) == NULL) { +#else + if ((t->d = opendir(".")) == NULL) { +#endif + r = tree_ascend(t); /* Undo "chdir" */ + tree_pop(t); + t->tree_errno = errno; + t->visit_type = r != 0 ? r : TREE_ERROR_DIR; + return (t->visit_type); + } +#if defined(HAVE_READDIR_R) + dirent_size = offsetof(struct dirent, d_name) + + t->filesystem_table[t->current->filesystem_id].name_max + 1; + if (t->dirent == NULL || t->dirent_allocated < dirent_size) { + free(t->dirent); + t->dirent = malloc(dirent_size); + if (t->dirent == NULL) { + closedir(t->d); + t->d = INVALID_DIR_HANDLE; + (void)tree_ascend(t); + tree_pop(t); + t->tree_errno = ENOMEM; + t->visit_type = TREE_ERROR_DIR; + return (t->visit_type); + } + t->dirent_allocated = dirent_size; + } +#endif /* HAVE_READDIR_R */ + } + for (;;) { +#if defined(HAVE_READDIR_R) + r = readdir_r(t->d, t->dirent, &t->de); + if (r != 0 || t->de == NULL) { +#else + errno = 0; + t->de = readdir(t->d); + if (t->de == NULL) { + r = errno; +#endif + closedir(t->d); + t->d = INVALID_DIR_HANDLE; + if (r != 0) { + t->tree_errno = r; + t->visit_type = TREE_ERROR_DIR; + return (t->visit_type); + } else + return (0); + } + name = t->de->d_name; + namelen = D_NAMELEN(t->de); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == '.' && name[1] == '\0') + continue; + if (name[0] == '.' && name[1] == '.' && name[2] == '\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } +} + + +/* + * Get the stat() data for the entry just returned from tree_next(). + */ +static const struct stat * +tree_current_stat(struct tree *t) +{ + if (!(t->flags & hasStat)) { +#ifdef HAVE_FSTATAT + if (fstatat(tree_current_dir_fd(t), + tree_current_access_path(t), &t->st, 0) != 0) +#else + if (stat(tree_current_access_path(t), &t->st) != 0) +#endif + return NULL; + t->flags |= hasStat; + } + return (&t->st); +} + +/* + * Get the lstat() data for the entry just returned from tree_next(). + */ +static const struct stat * +tree_current_lstat(struct tree *t) +{ + if (!(t->flags & hasLstat)) { +#ifdef HAVE_FSTATAT + if (fstatat(tree_current_dir_fd(t), + tree_current_access_path(t), &t->lst, + AT_SYMLINK_NOFOLLOW) != 0) +#else + if (lstat(tree_current_access_path(t), &t->lst) != 0) +#endif + return NULL; + t->flags |= hasLstat; + } + return (&t->lst); +} + +/* + * Test whether current entry is a dir or link to a dir. + */ +static int +tree_current_is_dir(struct tree *t) +{ + const struct stat *st; + /* + * If we already have lstat() info, then try some + * cheap tests to determine if this is a dir. + */ + if (t->flags & hasLstat) { + /* If lstat() says it's a dir, it must be a dir. */ + if (S_ISDIR(tree_current_lstat(t)->st_mode)) + return 1; + /* Not a dir; might be a link to a dir. */ + /* If it's not a link, then it's not a link to a dir. */ + if (!S_ISLNK(tree_current_lstat(t)->st_mode)) + return 0; + /* + * It's a link, but we don't know what it's a link to, + * so we'll have to use stat(). + */ + } + + st = tree_current_stat(t); + /* If we can't stat it, it's not a dir. */ + if (st == NULL) + return 0; + /* Use the definitive test. Hopefully this is cached. */ + return (S_ISDIR(st->st_mode)); +} + +/* + * Test whether current entry is a physical directory. Usually, we + * already have at least one of stat() or lstat() in memory, so we + * use tricks to try to avoid an extra trip to the disk. + */ +static int +tree_current_is_physical_dir(struct tree *t) +{ + const struct stat *st; + + /* + * If stat() says it isn't a dir, then it's not a dir. + * If stat() data is cached, this check is free, so do it first. + */ + if ((t->flags & hasStat) + && (!S_ISDIR(tree_current_stat(t)->st_mode))) + return 0; + + /* + * Either stat() said it was a dir (in which case, we have + * to determine whether it's really a link to a dir) or + * stat() info wasn't available. So we use lstat(), which + * hopefully is already cached. + */ + + st = tree_current_lstat(t); + /* If we can't stat it, it's not a dir. */ + if (st == NULL) + return 0; + /* Use the definitive test. Hopefully this is cached. */ + return (S_ISDIR(st->st_mode)); +} + +/* + * Test whether the same file has been in the tree as its parent. + */ +static int +tree_target_is_same_as_parent(struct tree *t, const struct stat *st) +{ + struct tree_entry *te; + + for (te = t->current->parent; te != NULL; te = te->parent) { + if (te->dev == st->st_dev && te->ino == st->st_ino) + return (1); + } + return (0); +} + +/* + * Test whether the current file is symbolic link target and + * on the other filesystem. + */ +static int +tree_current_is_symblic_link_target(struct tree *t) +{ + static const struct stat *lst, *st; + + lst = tree_current_lstat(t); + st = tree_current_stat(t); + return (st != NULL && st->st_dev == t->current_filesystem->dev && + st->st_dev != lst->st_dev); +} + +/* + * Return the access path for the entry just returned from tree_next(). + */ +static const char * +tree_current_access_path(struct tree *t) +{ + return (t->basename); +} + +/* + * Return the full path for the entry just returned from tree_next(). + */ +static const char * +tree_current_path(struct tree *t) +{ + return (t->path.s); +} + +/* + * Terminate the traversal. + */ +static void +tree_close(struct tree *t) +{ + + if (t == NULL) + return; + if (t->entry_fd >= 0) { + close_and_restore_time(t->entry_fd, t, &t->restore_time); + t->entry_fd = -1; + } + /* Close the handle of readdir(). */ + if (t->d != INVALID_DIR_HANDLE) { + closedir(t->d); + t->d = INVALID_DIR_HANDLE; + } + /* Release anything remaining in the stack. */ + while (t->stack != NULL) { + if (t->stack->flags & isDirLink) + close(t->stack->symlink_parent_fd); + tree_pop(t); + } + if (t->working_dir_fd >= 0) { + close(t->working_dir_fd); + t->working_dir_fd = -1; + } + if (t->initial_dir_fd >= 0) { + close(t->initial_dir_fd); + t->initial_dir_fd = -1; + } +} + +/* + * Release any resources. + */ +static void +tree_free(struct tree *t) +{ + int i; + + if (t == NULL) + return; + archive_string_free(&t->path); +#if defined(HAVE_READDIR_R) + free(t->dirent); +#endif + free(t->sparse_list); + for (i = 0; i < t->max_filesystem_id; i++) + free(t->filesystem_table[i].allocation_ptr); + free(t->filesystem_table); + free(t); +} + +#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h index 3f739e859..4446474eb 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_private.h @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD$ + * $FreeBSD: head/lib/libarchive/archive_read_disk_private.h 201105 2009-12-28 03:20:54Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -33,30 +33,39 @@ #ifndef ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED #define ARCHIVE_READ_DISK_PRIVATE_H_INCLUDED +struct tree; + struct archive_read_disk { - struct archive archive; - - /* - * Symlink mode is one of 'L'ogical, 'P'hysical, or 'H'ybrid, - * following an old BSD convention. 'L' follows all symlinks, - * 'P' follows none, 'H' follows symlinks only for the first - * item. - */ - char symlink_mode; - - /* - * Since symlink interaction changes, we need to track whether - * we're following symlinks for the current item. 'L' mode above - * sets this true, 'P' sets it false, 'H' changes it as we traverse. - */ - char follow_symlinks; /* Either 'L' or 'P'. */ - - const char * (*lookup_gname)(void *private, gid_t gid); - void (*cleanup_gname)(void *private); - void *lookup_gname_data; - const char * (*lookup_uname)(void *private, gid_t gid); - void (*cleanup_uname)(void *private); - void *lookup_uname_data; + struct archive archive; + + /* + * Symlink mode is one of 'L'ogical, 'P'hysical, or 'H'ybrid, + * following an old BSD convention. 'L' follows all symlinks, + * 'P' follows none, 'H' follows symlinks only for the first + * item. + */ + char symlink_mode; + + /* + * Since symlink interaction changes, we need to track whether + * we're following symlinks for the current item. 'L' mode above + * sets this true, 'P' sets it false, 'H' changes it as we traverse. + */ + char follow_symlinks; /* Either 'L' or 'P'. */ + + /* Directory traversals. */ + struct tree *tree; + + /* Set 1 if users request to restore atime . */ + int restore_time; + int entry_wd_fd; + + const char * (*lookup_gname)(void *private, int64_t gid); + void (*cleanup_gname)(void *private); + void *lookup_gname_data; + const char * (*lookup_uname)(void *private, int64_t uid); + void (*cleanup_uname)(void *private); + void *lookup_uname_data; }; #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c index 57d8228e5..3bc52c70d 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_set_standard_lookup.c @@ -23,12 +23,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 /* getpwuid_r and getgrgid_r signatures */ -#endif - #include "archive_platform.h" -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_disk_set_standard_lookup.c 201109 2009-12-28 03:30:31Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -55,32 +51,32 @@ __FBSDID("$FreeBSD$"); int archive_read_disk_set_standard_lookup(struct archive *a) { - archive_set_error(a, -1, "Standard lookups not available on Windows"); - return (ARCHIVE_FATAL); + archive_set_error(a, -1, "Standard lookups not available on Windows"); + return (ARCHIVE_FATAL); } #else /* ! (_WIN32 && !__CYGWIN__) */ -#define name_cache_size 127 +#define name_cache_size 127 static const char * const NO_NAME = "(noname)"; struct name_cache { - struct archive *archive; - char *buff; - size_t buff_size; - int probes; - int hits; - size_t size; - struct { - id_t id; - const char *name; - } cache[name_cache_size]; + struct archive *archive; + char *buff; + size_t buff_size; + int probes; + int hits; + size_t size; + struct { + id_t id; + const char *name; + } cache[name_cache_size]; }; -static const char * lookup_gname(void *, gid_t); -static const char * lookup_uname(void *, uid_t); -static void cleanup(void *); -static const char * lookup_gname_helper(struct name_cache *, id_t gid); -static const char * lookup_uname_helper(struct name_cache *, id_t uid); +static const char * lookup_gname(void *, int64_t); +static const char * lookup_uname(void *, int64_t); +static void cleanup(void *); +static const char * lookup_gname_helper(struct name_cache *, id_t gid); +static const char * lookup_uname_helper(struct name_cache *, id_t uid); /* * Installs functions that use getpwuid()/getgrgid()---along with @@ -98,45 +94,45 @@ static const char * lookup_uname_helper(struct name_cache *, id_t uid); int archive_read_disk_set_standard_lookup(struct archive *a) { - struct name_cache *ucache = malloc(sizeof(struct name_cache)); - struct name_cache *gcache = malloc(sizeof(struct name_cache)); - - if (ucache == NULL || gcache == NULL) { - archive_set_error(a, ENOMEM, - "Can't allocate uname/gname lookup cache"); - free(ucache); - free(gcache); - return (ARCHIVE_FATAL); - } - - memset(ucache, 0, sizeof(*ucache)); - ucache->archive = a; - ucache->size = name_cache_size; - memset(gcache, 0, sizeof(*gcache)); - gcache->archive = a; - gcache->size = name_cache_size; - - archive_read_disk_set_gname_lookup(a, gcache, lookup_gname, cleanup); - archive_read_disk_set_uname_lookup(a, ucache, lookup_uname, cleanup); - - return (ARCHIVE_OK); + struct name_cache *ucache = malloc(sizeof(struct name_cache)); + struct name_cache *gcache = malloc(sizeof(struct name_cache)); + + if (ucache == NULL || gcache == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate uname/gname lookup cache"); + free(ucache); + free(gcache); + return (ARCHIVE_FATAL); + } + + memset(ucache, 0, sizeof(*ucache)); + ucache->archive = a; + ucache->size = name_cache_size; + memset(gcache, 0, sizeof(*gcache)); + gcache->archive = a; + gcache->size = name_cache_size; + + archive_read_disk_set_gname_lookup(a, gcache, lookup_gname, cleanup); + archive_read_disk_set_uname_lookup(a, ucache, lookup_uname, cleanup); + + return (ARCHIVE_OK); } static void cleanup(void *data) { - struct name_cache *cache = (struct name_cache *)data; - size_t i; - - if (cache != NULL) { - for (i = 0; i < cache->size; i++) { - if (cache->cache[i].name != NULL && - cache->cache[i].name != NO_NAME) - free((void *)(uintptr_t)cache->cache[i].name); - } - free(cache->buff); - free(cache); - } + struct name_cache *cache = (struct name_cache *)data; + size_t i; + + if (cache != NULL) { + for (i = 0; i < cache->size; i++) { + if (cache->cache[i].name != NULL && + cache->cache[i].name != NO_NAME) + free((void *)(uintptr_t)cache->cache[i].name); + } + free(cache->buff); + free(cache); + } } /* @@ -146,131 +142,170 @@ static const char * lookup_name(struct name_cache *cache, const char * (*lookup_fn)(struct name_cache *, id_t), id_t id) { - const char *name; - int slot; - - - cache->probes++; - - slot = id % cache->size; - if (cache->cache[slot].name != NULL) { - if (cache->cache[slot].id == id) { - cache->hits++; - if (cache->cache[slot].name == NO_NAME) - return (NULL); - return (cache->cache[slot].name); - } - if (cache->cache[slot].name != NO_NAME) - free((void *)(uintptr_t)cache->cache[slot].name); - cache->cache[slot].name = NULL; - } - - name = (lookup_fn)(cache, id); - if (name == NULL) { - /* Cache and return the negative response. */ - cache->cache[slot].name = NO_NAME; - cache->cache[slot].id = id; - return (NULL); - } - - cache->cache[slot].name = name; - cache->cache[slot].id = id; - return (cache->cache[slot].name); + const char *name; + int slot; + + + cache->probes++; + + slot = id % cache->size; + if (cache->cache[slot].name != NULL) { + if (cache->cache[slot].id == id) { + cache->hits++; + if (cache->cache[slot].name == NO_NAME) + return (NULL); + return (cache->cache[slot].name); + } + if (cache->cache[slot].name != NO_NAME) + free((void *)(uintptr_t)cache->cache[slot].name); + cache->cache[slot].name = NULL; + } + + name = (lookup_fn)(cache, id); + if (name == NULL) { + /* Cache and return the negative response. */ + cache->cache[slot].name = NO_NAME; + cache->cache[slot].id = id; + return (NULL); + } + + cache->cache[slot].name = name; + cache->cache[slot].id = id; + return (cache->cache[slot].name); } static const char * -lookup_uname(void *data, uid_t uid) +lookup_uname(void *data, int64_t uid) { - struct name_cache *uname_cache = (struct name_cache *)data; - return (lookup_name(uname_cache, - &lookup_uname_helper, (id_t)uid)); + struct name_cache *uname_cache = (struct name_cache *)data; + return (lookup_name(uname_cache, + &lookup_uname_helper, (id_t)uid)); } +#if HAVE_GETPWUID_R static const char * lookup_uname_helper(struct name_cache *cache, id_t id) { - struct passwd pwent, *result; - int r; - - if (cache->buff_size == 0) { - cache->buff_size = 256; - cache->buff = malloc(cache->buff_size); - } - if (cache->buff == NULL) - return (NULL); - for (;;) { - result = &pwent; /* Old getpwuid_r ignores last argument. */ - r = getpwuid_r((uid_t)id, &pwent, - cache->buff, cache->buff_size, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - /* ERANGE means our buffer was too small, but POSIX - * doesn't tell us how big the buffer should be, so - * we just double it and try again. Because the buffer - * is kept around in the cache object, we shouldn't - * have to do this very often. */ - cache->buff_size *= 2; - cache->buff = realloc(cache->buff, cache->buff_size); - if (cache->buff == NULL) - break; - } - if (r != 0) { - archive_set_error(cache->archive, errno, - "Can't lookup user for id %d", (int)id); - return (NULL); - } - if (result == NULL) - return (NULL); - - return strdup(result->pw_name); + struct passwd pwent, *result; + char * nbuff; + size_t nbuff_size; + int r; + + if (cache->buff_size == 0) { + cache->buff_size = 256; + cache->buff = malloc(cache->buff_size); + } + if (cache->buff == NULL) + return (NULL); + for (;;) { + result = &pwent; /* Old getpwuid_r ignores last arg. */ + r = getpwuid_r((uid_t)id, &pwent, + cache->buff, cache->buff_size, &result); + if (r == 0) + break; + if (r != ERANGE) + break; + /* ERANGE means our buffer was too small, but POSIX + * doesn't tell us how big the buffer should be, so + * we just double it and try again. Because the buffer + * is kept around in the cache object, we shouldn't + * have to do this very often. */ + nbuff_size = cache->buff_size * 2; + nbuff = realloc(cache->buff, nbuff_size); + if (nbuff == NULL) + break; + cache->buff = nbuff; + cache->buff_size = nbuff_size; + } + if (r != 0) { + archive_set_error(cache->archive, errno, + "Can't lookup user for id %d", (int)id); + return (NULL); + } + if (result == NULL) + return (NULL); + + return strdup(result->pw_name); } +#else +static const char * +lookup_uname_helper(struct name_cache *cache, id_t id) +{ + struct passwd *result; + + result = getpwuid((uid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->pw_name); +} +#endif static const char * -lookup_gname(void *data, gid_t gid) +lookup_gname(void *data, int64_t gid) { - struct name_cache *gname_cache = (struct name_cache *)data; - return (lookup_name(gname_cache, - &lookup_gname_helper, (id_t)gid)); + struct name_cache *gname_cache = (struct name_cache *)data; + return (lookup_name(gname_cache, + &lookup_gname_helper, (id_t)gid)); } +#if HAVE_GETGRGID_R +static const char * +lookup_gname_helper(struct name_cache *cache, id_t id) +{ + struct group grent, *result; + char * nbuff; + size_t nbuff_size; + int r; + + if (cache->buff_size == 0) { + cache->buff_size = 256; + cache->buff = malloc(cache->buff_size); + } + if (cache->buff == NULL) + return (NULL); + for (;;) { + result = &grent; /* Old getgrgid_r ignores last arg. */ + r = getgrgid_r((gid_t)id, &grent, + cache->buff, cache->buff_size, &result); + if (r == 0) + break; + if (r != ERANGE) + break; + /* ERANGE means our buffer was too small, but POSIX + * doesn't tell us how big the buffer should be, so + * we just double it and try again. */ + nbuff_size = cache->buff_size * 2; + nbuff = realloc(cache->buff, nbuff_size); + if (nbuff == NULL) + break; + cache->buff = nbuff; + cache->buff_size = nbuff_size; + } + if (r != 0) { + archive_set_error(cache->archive, errno, + "Can't lookup group for id %d", (int)id); + return (NULL); + } + if (result == NULL) + return (NULL); + + return strdup(result->gr_name); +} +#else static const char * lookup_gname_helper(struct name_cache *cache, id_t id) { - struct group grent, *result; - int r; - - if (cache->buff_size == 0) { - cache->buff_size = 256; - cache->buff = malloc(cache->buff_size); - } - if (cache->buff == NULL) - return (NULL); - for (;;) { - result = &grent; /* Old getgrgid_r ignores last argument. */ - r = getgrgid_r((gid_t)id, &grent, - cache->buff, cache->buff_size, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - /* ERANGE means our buffer was too small, but POSIX - * doesn't tell us how big the buffer should be, so - * we just double it and try again. */ - cache->buff_size *= 2; - cache->buff = realloc(cache->buff, cache->buff_size); - if (cache->buff == NULL) - break; - } - if (r != 0) { - archive_set_error(cache->archive, errno, - "Can't lookup group for id %d", (int)id); - return (NULL); - } - if (result == NULL) - return (NULL); - - return strdup(result->gr_name); + struct group *result; + + result = getgrgid((gid_t)id); + + if (result == NULL) + return (NULL); + + return strdup(result->gr_name); } +#endif + #endif /* ! (_WIN32 && !__CYGWIN__) */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c new file mode 100644 index 000000000..d8a1f5577 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_disk_windows.c @@ -0,0 +1,1983 @@ +/*- + * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2010-2011 Michihiro NAKAJIMA + * 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 + * in this position and unchanged. + * 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$"); + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_MOUNT_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_STATVFS_H +#include +#endif +#ifdef HAVE_SYS_VFS_H +#include +#endif +#ifdef HAVE_LINUX_MAGIC_H +#include +#endif +#ifdef HAVE_DIRECT_H +#include +#endif +#ifdef HAVE_DIRENT_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#if defined(HAVE_WINIOCTL_H) && !defined(__CYGWIN__) +#include +#endif + +#include "archive.h" +#include "archive_string.h" +#include "archive_entry.h" +#include "archive_private.h" +#include "archive_read_disk_private.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif +#ifndef IO_REPARSE_TAG_SYMLINK +/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */ +#define IO_REPARSE_TAG_SYMLINK 0xA000000CL +#endif + +static BOOL SetFilePointerEx_perso(HANDLE hFile, + LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, + DWORD dwMoveMethod) +{ + LARGE_INTEGER li; + li.QuadPart = liDistanceToMove.QuadPart; + li.LowPart = SetFilePointer( + hFile, li.LowPart, &li.HighPart, dwMoveMethod); + if(lpNewFilePointer) { + lpNewFilePointer->QuadPart = li.QuadPart; + } + return li.LowPart != -1 || GetLastError() == NO_ERROR; +} + +/*- + * This is a new directory-walking system that addresses a number + * of problems I've had with fts(3). In particular, it has no + * pathname-length limits (other than the size of 'int'), handles + * deep logical traversals, uses considerably less memory, and has + * an opaque interface (easier to modify in the future). + * + * Internally, it keeps a single list of "tree_entry" items that + * represent filesystem objects that require further attention. + * Non-directories are not kept in memory: they are pulled from + * readdir(), returned to the client, then freed as soon as possible. + * Any directory entry to be traversed gets pushed onto the stack. + * + * There is surprisingly little information that needs to be kept for + * each item on the stack. Just the name, depth (represented here as the + * string length of the parent directory's pathname), and some markers + * indicating how to get back to the parent (via chdir("..") for a + * regular dir or via fchdir(2) for a symlink). + */ +/* + * TODO: + * 1) Loop checking. + * 3) Arbitrary logical traversals by closing/reopening intermediate fds. + */ + +struct restore_time { + const wchar_t *full_path; + FILETIME lastWriteTime; + FILETIME lastAccessTime; + mode_t filetype; +}; + +struct tree_entry { + int depth; + struct tree_entry *next; + struct tree_entry *parent; + size_t full_path_dir_length; + struct archive_wstring name; + struct archive_wstring full_path; + size_t dirname_length; + int64_t dev; + int64_t ino; + int flags; + int filesystem_id; + /* How to restore time of a directory. */ + struct restore_time restore_time; +}; + +struct filesystem { + int64_t dev; + int synthetic; + int remote; +}; + +/* Definitions for tree_entry.flags bitmap. */ +#define isDir 1 /* This entry is a regular directory. */ +#define isDirLink 2 /* This entry is a symbolic link to a directory. */ +#define needsFirstVisit 4 /* This is an initial entry. */ +#define needsDescent 8 /* This entry needs to be previsited. */ +#define needsOpen 16 /* This is a directory that needs to be opened. */ +#define needsAscent 32 /* This entry needs to be postvisited. */ + +/* + * On Windows, "first visit" is handled as a pattern to be handed to + * _findfirst(). This is consistent with Windows conventions that + * file patterns are handled within the application. On Posix, + * "first visit" is just returned to the client. + */ + +/* + * Local data for this package. + */ +struct tree { + struct tree_entry *stack; + struct tree_entry *current; + HANDLE d; +#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE + WIN32_FIND_DATAW _findData; + WIN32_FIND_DATAW *findData; + int flags; + int visit_type; + /* Error code from last failed operation. */ + int tree_errno; + + /* A full path with "\\?\" prefix. */ + struct archive_wstring full_path; + size_t full_path_dir_length; + /* Dynamically-sized buffer for holding path */ + struct archive_wstring path; + + /* Last path element */ + const wchar_t *basename; + /* Leading dir length */ + size_t dirname_length; + + int depth; + + BY_HANDLE_FILE_INFORMATION lst; + BY_HANDLE_FILE_INFORMATION st; + int descend; + /* How to restore time of a file. */ + struct restore_time restore_time; + + struct entry_sparse { + int64_t length; + int64_t offset; + } *sparse_list, *current_sparse; + int sparse_count; + int sparse_list_size; + + char initial_symlink_mode; + char symlink_mode; + struct filesystem *current_filesystem; + struct filesystem *filesystem_table; + int current_filesystem_id; + int max_filesystem_id; + int allocated_filesytem; + + HANDLE entry_fh; + int entry_eof; + int64_t entry_remaining_bytes; + int64_t entry_total; + unsigned char *entry_buff; + size_t entry_buff_size; +}; + +#define bhfi_dev(bhfi) ((bhfi)->dwVolumeSerialNumber) +/* Treat FileIndex as i-node. We should remove a sequence number + * which is high-16-bits of nFileIndexHigh. */ +#define bhfi_ino(bhfi) \ + ((((int64_t)((bhfi)->nFileIndexHigh & 0x0000FFFFUL)) << 32) \ + + (bhfi)->nFileIndexLow) + +/* Definitions for tree.flags bitmap. */ +#define hasStat 16 /* The st entry is valid. */ +#define hasLstat 32 /* The lst entry is valid. */ +#define needsRestoreTimes 128 + +static int +tree_dir_next_windows(struct tree *t, const wchar_t *pattern); + +#ifdef HAVE_DIRENT_D_NAMLEN +/* BSD extension; avoids need for a strlen() call. */ +#define D_NAMELEN(dp) (dp)->d_namlen +#else +#define D_NAMELEN(dp) (strlen((dp)->d_name)) +#endif + +/* Initiate/terminate a tree traversal. */ +static struct tree *tree_open(const wchar_t *, int, int); +static struct tree *tree_reopen(struct tree *, const wchar_t *, int); +static void tree_close(struct tree *); +static void tree_free(struct tree *); +static void tree_push(struct tree *, const wchar_t *, const wchar_t *, + int, int64_t, int64_t, struct restore_time *); + +/* + * tree_next() returns Zero if there is no next entry, non-zero if + * there is. Note that directories are visited three times. + * Directories are always visited first as part of enumerating their + * parent; that is a "regular" visit. If tree_descend() is invoked at + * that time, the directory is added to a work list and will + * subsequently be visited two more times: once just after descending + * into the directory ("postdescent") and again just after ascending + * back to the parent ("postascent"). + * + * TREE_ERROR_DIR is returned if the descent failed (because the + * directory couldn't be opened, for instance). This is returned + * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a + * fatal error, but it does imply that the relevant subtree won't be + * visited. TREE_ERROR_FATAL is returned for an error that left the + * traversal completely hosed. Right now, this is only returned for + * chdir() failures during ascent. + */ +#define TREE_REGULAR 1 +#define TREE_POSTDESCENT 2 +#define TREE_POSTASCENT 3 +#define TREE_ERROR_DIR -1 +#define TREE_ERROR_FATAL -2 + +static int tree_next(struct tree *); + +/* + * Return information about the current entry. + */ + +/* + * The current full pathname, length of the full pathname, and a name + * that can be used to access the file. Because tree does use chdir + * extensively, the access path is almost never the same as the full + * current path. + * + */ +static const wchar_t *tree_current_path(struct tree *); +static const wchar_t *tree_current_access_path(struct tree *); + +/* + * Request the lstat() or stat() data for the current path. Since the + * tree package needs to do some of this anyway, and caches the + * results, you should take advantage of it here if you need it rather + * than make a redundant stat() or lstat() call of your own. + */ +static const BY_HANDLE_FILE_INFORMATION *tree_current_stat(struct tree *); +static const BY_HANDLE_FILE_INFORMATION *tree_current_lstat(struct tree *); + +/* The following functions use tricks to avoid a certain number of + * stat()/lstat() calls. */ +/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */ +static int tree_current_is_physical_dir(struct tree *); +/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */ +static int tree_current_is_physical_link(struct tree *); +/* Instead of archive_entry_copy_stat for BY_HANDLE_FILE_INFORMATION */ +static void tree_archive_entry_copy_bhfi(struct archive_entry *, + struct tree *, const BY_HANDLE_FILE_INFORMATION *); +/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */ +static int tree_current_is_dir(struct tree *); +static int update_current_filesystem(struct archive_read_disk *a, + int64_t dev); +static int setup_current_filesystem(struct archive_read_disk *); +static int tree_target_is_same_as_parent(struct tree *, + const BY_HANDLE_FILE_INFORMATION *); + +static int _archive_read_disk_open_w(struct archive *, const wchar_t *); +static int _archive_read_free(struct archive *); +static int _archive_read_close(struct archive *); +static int _archive_read_data_block(struct archive *, + const void **, size_t *, int64_t *); +static int _archive_read_next_header2(struct archive *, + struct archive_entry *); +static const char *trivial_lookup_gname(void *, int64_t gid); +static const char *trivial_lookup_uname(void *, int64_t uid); +static int setup_sparse(struct archive_read_disk *, struct archive_entry *); +static int close_and_restore_time(HANDLE, struct tree *, + struct restore_time *); +static int setup_sparse_from_disk(struct archive_read_disk *, + struct archive_entry *, HANDLE); + + + +static struct archive_vtable * +archive_read_disk_vtable(void) +{ + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_free = _archive_read_free; + av.archive_close = _archive_read_close; + av.archive_read_data_block = _archive_read_data_block; + av.archive_read_next_header2 = _archive_read_next_header2; + inited = 1; + } + return (&av); +} + +const char * +archive_read_disk_gname(struct archive *_a, int64_t gid) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_gname")) + return (NULL); + if (a->lookup_gname == NULL) + return (NULL); + return ((*a->lookup_gname)(a->lookup_gname_data, gid)); +} + +const char * +archive_read_disk_uname(struct archive *_a, int64_t uid) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + if (ARCHIVE_OK != __archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_uname")) + return (NULL); + if (a->lookup_uname == NULL) + return (NULL); + return ((*a->lookup_uname)(a->lookup_uname_data, uid)); +} + +int +archive_read_disk_set_gname_lookup(struct archive *_a, + void *private_data, + const char * (*lookup_gname)(void *private, int64_t gid), + void (*cleanup_gname)(void *private)) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_gname_lookup"); + + if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) + (a->cleanup_gname)(a->lookup_gname_data); + + a->lookup_gname = lookup_gname; + a->cleanup_gname = cleanup_gname; + a->lookup_gname_data = private_data; + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_uname_lookup(struct archive *_a, + void *private_data, + const char * (*lookup_uname)(void *private, int64_t uid), + void (*cleanup_uname)(void *private)) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_uname_lookup"); + + if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) + (a->cleanup_uname)(a->lookup_uname_data); + + a->lookup_uname = lookup_uname; + a->cleanup_uname = cleanup_uname; + a->lookup_uname_data = private_data; + return (ARCHIVE_OK); +} + +/* + * Create a new archive_read_disk object and initialize it with global state. + */ +struct archive * +archive_read_disk_new(void) +{ + struct archive_read_disk *a; + + a = (struct archive_read_disk *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_READ_DISK_MAGIC; + a->archive.state = ARCHIVE_STATE_NEW; + a->archive.vtable = archive_read_disk_vtable(); + a->lookup_uname = trivial_lookup_uname; + a->lookup_gname = trivial_lookup_gname; + a->entry_wd_fd = -1; + return (&a->archive); +} + +static int +_archive_read_free(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + int r; + + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_free"); + + if (a->archive.state != ARCHIVE_STATE_CLOSED) + r = _archive_read_close(&a->archive); + else + r = ARCHIVE_OK; + + tree_free(a->tree); + if (a->cleanup_gname != NULL && a->lookup_gname_data != NULL) + (a->cleanup_gname)(a->lookup_gname_data); + if (a->cleanup_uname != NULL && a->lookup_uname_data != NULL) + (a->cleanup_uname)(a->lookup_uname_data); + archive_string_free(&a->archive.error_string); + a->archive.magic = 0; + free(a); + return (r); +} + +static int +_archive_read_close(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_read_close"); + + if (a->archive.state != ARCHIVE_STATE_FATAL) + a->archive.state = ARCHIVE_STATE_CLOSED; + + tree_close(a->tree); + + return (ARCHIVE_OK); +} + +static void +setup_symlink_mode(struct archive_read_disk *a, char symlink_mode, + int follow_symlinks) +{ + a->symlink_mode = symlink_mode; + a->follow_symlinks = follow_symlinks; + if (a->tree != NULL) { + a->tree->initial_symlink_mode = a->symlink_mode; + a->tree->symlink_mode = a->symlink_mode; + } +} + +int +archive_read_disk_set_symlink_logical(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_logical"); + setup_symlink_mode(a, 'L', 1); + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_symlink_physical(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_physical"); + setup_symlink_mode(a, 'P', 0); + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_symlink_hybrid(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_set_symlink_hybrid"); + setup_symlink_mode(a, 'H', 1);/* Follow symlinks initially. */ + return (ARCHIVE_OK); +} + +int +archive_read_disk_set_atime_restored(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_read_disk_restore_atime"); + a->restore_time = 1; + if (a->tree != NULL) + a->tree->flags |= needsRestoreTimes; + return (ARCHIVE_OK); +} + +/* + * Trivial implementations of gname/uname lookup functions. + * These are normally overridden by the client, but these stub + * versions ensure that we always have something that works. + */ +static const char * +trivial_lookup_gname(void *private_data, int64_t gid) +{ + (void)private_data; /* UNUSED */ + (void)gid; /* UNUSED */ + return (NULL); +} + +static const char * +trivial_lookup_uname(void *private_data, int64_t uid) +{ + (void)private_data; /* UNUSED */ + (void)uid; /* UNUSED */ + return (NULL); +} + +static int +_archive_read_data_block(struct archive *_a, const void **buff, + size_t *size, int64_t *offset) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t = a->tree; + int r; + int64_t bytes; + size_t buffbytes; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_data_block"); + + if (t->entry_eof || t->entry_remaining_bytes <= 0) { + r = ARCHIVE_EOF; + goto abort_read_data; + } + + /* Allocate read buffer. */ + if (t->entry_buff == NULL) { + t->entry_buff = malloc(1024 * 64); + if (t->entry_buff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory"); + r = ARCHIVE_FATAL; + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + t->entry_buff_size = 1024 * 64; + } + + buffbytes = t->entry_buff_size; + if (buffbytes > t->current_sparse->length) + buffbytes = t->current_sparse->length; + + /* + * Skip hole. + */ + if (t->current_sparse->offset > t->entry_total) { + LARGE_INTEGER distance; + distance.QuadPart = t->current_sparse->offset; + if (!SetFilePointerEx_perso(t->entry_fh, distance, NULL, FILE_BEGIN)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, "Seek error"); + r = ARCHIVE_FATAL; + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + bytes = t->current_sparse->offset - t->entry_total; + t->entry_remaining_bytes -= bytes; + t->entry_total += bytes; + } + if (buffbytes > 0) { + DWORD bytes_read; + if (!ReadFile(t->entry_fh, t->entry_buff, + (uint32_t)buffbytes, &bytes_read, NULL)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_NO_DATA) + errno = EAGAIN; + else if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, "Read error"); + r = ARCHIVE_FATAL; + a->archive.state = ARCHIVE_STATE_FATAL; + goto abort_read_data; + } + bytes = bytes_read; + } else + bytes = 0; + if (bytes == 0) { + /* Get EOF */ + t->entry_eof = 1; + r = ARCHIVE_EOF; + goto abort_read_data; + } + *buff = t->entry_buff; + *size = bytes; + *offset = t->entry_total; + t->entry_total += bytes; + t->entry_remaining_bytes -= bytes; + if (t->entry_remaining_bytes == 0) { + /* Close the current file descriptor */ + close_and_restore_time(t->entry_fh, t, &t->restore_time); + t->entry_fh = INVALID_HANDLE_VALUE; + t->entry_eof = 1; + } + t->current_sparse->offset += bytes; + t->current_sparse->length -= bytes; + if (t->current_sparse->length == 0 && !t->entry_eof) + t->current_sparse++; + return (ARCHIVE_OK); + +abort_read_data: + *buff = NULL; + *size = 0; + *offset = t->entry_total; + if (t->entry_fh != INVALID_HANDLE_VALUE) { + /* Close the current file descriptor */ + close_and_restore_time(t->entry_fh, t, &t->restore_time); + t->entry_fh = INVALID_HANDLE_VALUE; + } + return (r); +} + +static int +_archive_read_next_header2(struct archive *_a, struct archive_entry *entry) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t; + const BY_HANDLE_FILE_INFORMATION *st; + const BY_HANDLE_FILE_INFORMATION *lst; + const char*name; + int descend, r; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_read_next_header2"); + + t = a->tree; + if (t->entry_fh != INVALID_HANDLE_VALUE) { + close_and_restore_time(t->entry_fh, t, &t->restore_time); + t->entry_fh = INVALID_HANDLE_VALUE; + } + st = NULL; + lst = NULL; + do { + switch (tree_next(t)) { + case TREE_ERROR_FATAL: + archive_set_error(&a->archive, t->tree_errno, + "%ls: Unable to continue traversing directory tree", + tree_current_path(t)); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + case TREE_ERROR_DIR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%ls: Couldn't visit directory", + tree_current_path(t)); + return (ARCHIVE_FAILED); + case 0: + return (ARCHIVE_EOF); + case TREE_POSTDESCENT: + case TREE_POSTASCENT: + break; + case TREE_REGULAR: + lst = tree_current_lstat(t); + if (lst == NULL) { + archive_set_error(&a->archive, errno, + "%ls: Cannot stat", + tree_current_path(t)); + return (ARCHIVE_FAILED); + } + break; + } + } while (lst == NULL); + + /* + * Distinguish 'L'/'P'/'H' symlink following. + */ + switch(t->symlink_mode) { + case 'H': + /* 'H': After the first item, rest like 'P'. */ + t->symlink_mode = 'P'; + /* 'H': First item (from command line) like 'L'. */ + /* FALLTHROUGH */ + case 'L': + /* 'L': Do descend through a symlink to dir. */ + descend = tree_current_is_dir(t); + /* 'L': Follow symlinks to files. */ + a->symlink_mode = 'L'; + a->follow_symlinks = 1; + /* 'L': Archive symlinks as targets, if we can. */ + st = tree_current_stat(t); + if (st != NULL && !tree_target_is_same_as_parent(t, st)) + break; + /* If stat fails, we have a broken symlink; + * in that case, don't follow the link. */ + /* FALLTHROUGH */ + default: + /* 'P': Don't descend through a symlink to dir. */ + descend = tree_current_is_physical_dir(t); + /* 'P': Don't follow symlinks to files. */ + a->symlink_mode = 'P'; + a->follow_symlinks = 0; + /* 'P': Archive symlinks as symlinks. */ + st = lst; + break; + } + + if (update_current_filesystem(a, bhfi_dev(st)) != ARCHIVE_OK) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + t->descend = descend; + + archive_entry_copy_pathname_w(entry, tree_current_path(t)); + archive_entry_copy_sourcepath_w(entry, tree_current_access_path(t)); + tree_archive_entry_copy_bhfi(entry, t, st); + + /* Save the times to be restored. */ + t->restore_time.lastWriteTime = st->ftLastWriteTime; + t->restore_time.lastAccessTime = st->ftLastAccessTime; + t->restore_time.filetype = archive_entry_filetype(entry); + + /* Lookup uname/gname */ + name = archive_read_disk_uname(_a, archive_entry_uid(entry)); + if (name != NULL) + archive_entry_copy_uname(entry, name); + name = archive_read_disk_gname(_a, archive_entry_gid(entry)); + if (name != NULL) + archive_entry_copy_gname(entry, name); + + r = ARCHIVE_OK; + if (archive_entry_filetype(entry) == AE_IFREG && + archive_entry_size(entry) > 0) { + t->entry_fh = CreateFileW(tree_current_access_path(t), + GENERIC_READ, 0, NULL, OPEN_EXISTING, + FILE_FLAG_SEQUENTIAL_SCAN, NULL); + if (t->entry_fh == INVALID_HANDLE_VALUE) { + archive_set_error(&a->archive, errno, + "Couldn't open %ls", tree_current_path(a->tree)); + return (ARCHIVE_FAILED); + } + + /* Find sparse data from the disk. */ + if (archive_entry_hardlink(entry) == NULL && + (st->dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) != 0) + r = setup_sparse_from_disk(a, entry, t->entry_fh); + } + + /* + * EOF and FATAL are persistent at this layer. By + * modifying the state, we guarantee that future calls to + * read a header or read data will fail. + */ + switch (r) { + case ARCHIVE_EOF: + a->archive.state = ARCHIVE_STATE_EOF; + break; + case ARCHIVE_OK: + case ARCHIVE_WARN: + t->entry_total = 0; + if (archive_entry_filetype(entry) == AE_IFREG) { + t->entry_remaining_bytes = archive_entry_size(entry); + t->entry_eof = (t->entry_remaining_bytes == 0)? 1: 0; + if (!t->entry_eof && + setup_sparse(a, entry) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + t->entry_remaining_bytes = 0; + t->entry_eof = 1; + } + a->archive.state = ARCHIVE_STATE_DATA; + break; + case ARCHIVE_RETRY: + break; + case ARCHIVE_FATAL: + a->archive.state = ARCHIVE_STATE_FATAL; + break; + } + + return (r); +} + +static int +setup_sparse(struct archive_read_disk *a, struct archive_entry *entry) +{ + struct tree *t = a->tree; + int64_t length, offset; + int i; + + t->sparse_count = archive_entry_sparse_reset(entry); + if (t->sparse_count+1 > t->sparse_list_size) { + free(t->sparse_list); + t->sparse_list_size = t->sparse_count + 1; + t->sparse_list = malloc(sizeof(t->sparse_list[0]) * + t->sparse_list_size); + if (t->sparse_list == NULL) { + t->sparse_list_size = 0; + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + } + for (i = 0; i < t->sparse_count; i++) { + archive_entry_sparse_next(entry, &offset, &length); + t->sparse_list[i].offset = offset; + t->sparse_list[i].length = length; + } + if (i == 0) { + t->sparse_list[i].offset = 0; + t->sparse_list[i].length = archive_entry_size(entry); + } else { + t->sparse_list[i].offset = archive_entry_size(entry); + t->sparse_list[i].length = 0; + } + t->current_sparse = t->sparse_list; + + return (ARCHIVE_OK); +} + +/* + * Called by the client to mark the directory just returned from + * tree_next() as needing to be visited. + */ +int +archive_read_disk_descend(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct tree *t = a->tree; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_descend"); + + if (t->visit_type != TREE_REGULAR || !t->descend) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignored the request descending the current object"); + return (ARCHIVE_WARN); + } + + if (tree_current_is_physical_dir(t)) { + tree_push(t, t->basename, t->full_path.s, + t->current_filesystem_id, + bhfi_dev(&(t->lst)), bhfi_ino(&(t->lst)), + &t->restore_time); + t->stack->flags |= isDir; + } else if (tree_current_is_dir(t)) { + tree_push(t, t->basename, t->full_path.s, + t->current_filesystem_id, + bhfi_dev(&(t->st)), bhfi_ino(&(t->st)), + &t->restore_time); + t->stack->flags |= isDirLink; + } + t->descend = 0; + return (ARCHIVE_OK); +} + +int +archive_read_disk_open(struct archive *_a, const char *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + struct archive_wstring wpath; + int ret; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED, + "archive_read_disk_open"); + archive_clear_error(&a->archive); + + /* Make a wchar_t string from a char string. */ + archive_string_init(&wpath); + if (archive_wstring_append_from_mbs(&wpath, pathname, + strlen(pathname)) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't convert a path to a wchar_t string"); + a->archive.state = ARCHIVE_STATE_FATAL; + ret = ARCHIVE_FATAL; + } else + ret = _archive_read_disk_open_w(_a, wpath.s); + + archive_wstring_free(&wpath); + return (ret); +} + +int +archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, + ARCHIVE_STATE_NEW | ARCHIVE_STATE_CLOSED, + "archive_read_disk_open_w"); + archive_clear_error(&a->archive); + + return (_archive_read_disk_open_w(_a, pathname)); +} + +static int +_archive_read_disk_open_w(struct archive *_a, const wchar_t *pathname) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + if (a->tree != NULL) + a->tree = tree_reopen(a->tree, pathname, a->restore_time); + else + a->tree = tree_open(pathname, a->symlink_mode, a->restore_time); + if (a->tree == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate direcotry traversal data"); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + a->archive.state = ARCHIVE_STATE_HEADER; + + return (ARCHIVE_OK); +} + +/* + * Return a current filesystem ID which is index of the filesystem entry + * you've visited through archive_read_disk. + */ +int +archive_read_disk_current_filesystem(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem_id); +} + +static int +update_current_filesystem(struct archive_read_disk *a, int64_t dev) +{ + struct tree *t = a->tree; + int i, fid; + + if (t->current_filesystem != NULL && + t->current_filesystem->dev == dev) + return (ARCHIVE_OK); + + for (i = 0; i < t->max_filesystem_id; i++) { + if (t->filesystem_table[i].dev == dev) { + /* There is the filesytem ID we've already generated. */ + t->current_filesystem_id = i; + t->current_filesystem = &(t->filesystem_table[i]); + return (ARCHIVE_OK); + } + } + + /* + * There is a new filesytem, we generate a new ID for. + */ + fid = t->max_filesystem_id++; + if (t->max_filesystem_id > t->allocated_filesytem) { + size_t s; + + s = t->max_filesystem_id * 2; + t->filesystem_table = realloc(t->filesystem_table, + s * sizeof(*t->filesystem_table)); + if (t->filesystem_table == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate tar data"); + return (ARCHIVE_FATAL); + } + t->allocated_filesytem = s; + } + t->current_filesystem_id = fid; + t->current_filesystem = &(t->filesystem_table[fid]); + t->current_filesystem->dev = dev; + + return (setup_current_filesystem(a)); +} + +/* + * Returns 1 if current filesystem is generated filesystem, 0 if it is not + * or -1 if it is unknown. + */ +int +archive_read_disk_current_filesystem_is_synthetic(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem->synthetic); +} + +/* + * Returns 1 if current filesystem is remote filesystem, 0 if it is not + * or -1 if it is unknown. + */ +int +archive_read_disk_current_filesystem_is_remote(struct archive *_a) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + + archive_check_magic(_a, ARCHIVE_READ_DISK_MAGIC, ARCHIVE_STATE_DATA, + "archive_read_disk_current_filesystem"); + + return (a->tree->current_filesystem->remote); +} + +/* + * If symlink is broken, statfs or statvfs will fail. + * Use its directory path instead. + */ +static wchar_t * +safe_path_for_statfs(struct tree *t) +{ + const wchar_t *path; + wchar_t *cp, *p = NULL; + + path = tree_current_access_path(t); + if (tree_current_stat(t) == NULL) { + p = _wcsdup(path); + cp = wcsrchr(p, '/'); + if (cp != NULL && wcslen(cp) >= 2) { + cp[1] = '.'; + cp[2] = '\0'; + path = p; + } + } else + p = _wcsdup(path); + return (p); +} + +/* + * Get conditions of synthetic and remote on Windows + */ +static int +setup_current_filesystem(struct archive_read_disk *a) +{ + struct tree *t = a->tree; + wchar_t vol[256]; + wchar_t *path; + + t->current_filesystem->synthetic = -1;/* Not supported */ + path = safe_path_for_statfs(t); + if (!GetVolumePathNameW(path, vol, sizeof(vol)/sizeof(vol[0]))) { + free(path); + t->current_filesystem->remote = -1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "GetVolumePathName failed: %d", (int)GetLastError()); + return (ARCHIVE_FAILED); + } + free(path); + switch (GetDriveTypeW(vol)) { + case DRIVE_UNKNOWN: + case DRIVE_NO_ROOT_DIR: + t->current_filesystem->remote = -1; + break; + case DRIVE_REMOTE: + t->current_filesystem->remote = 1; + break; + default: + t->current_filesystem->remote = 0; + break; + } + + return (ARCHIVE_OK); +} + +static int +close_and_restore_time(HANDLE h, struct tree *t, struct restore_time *rt) +{ + HANDLE handle; + int r = 0; + + if (h == INVALID_HANDLE_VALUE && AE_IFLNK == rt->filetype) + return (0); + + /* Close a file descritor. + * It will not be used for SetFileTime() because it has been opened + * by a read only mode. + */ + if (h != INVALID_HANDLE_VALUE) + CloseHandle(h); + if ((t->flags & needsRestoreTimes) == 0) + return (r); + + handle = CreateFileW(rt->full_path, FILE_WRITE_ATTRIBUTES, + 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (handle == INVALID_HANDLE_VALUE) { + errno = EINVAL; + return (-1); + } + + if (SetFileTime(handle, NULL, &rt->lastAccessTime, + &rt->lastWriteTime) == 0) { + errno = EINVAL; + r = -1; + } else + r = 0; + CloseHandle(handle); + return (r); +} + +/* + * Add a directory path to the current stack. + */ +static void +tree_push(struct tree *t, const wchar_t *path, const wchar_t *full_path, + int filesystem_id, int64_t dev, int64_t ino, struct restore_time *rt) +{ + struct tree_entry *te; + + te = malloc(sizeof(*te)); + memset(te, 0, sizeof(*te)); + te->next = t->stack; + te->parent = t->current; + if (te->parent) + te->depth = te->parent->depth + 1; + t->stack = te; + archive_string_init(&te->name); + archive_wstrcpy(&te->name, path); + archive_string_init(&te->full_path); + archive_wstrcpy(&te->full_path, full_path); + te->flags = needsDescent | needsOpen | needsAscent; + te->filesystem_id = filesystem_id; + te->dev = dev; + te->ino = ino; + te->dirname_length = t->dirname_length; + te->full_path_dir_length = t->full_path_dir_length; + te->restore_time.full_path = te->full_path.s; + if (rt != NULL) { + te->restore_time.lastWriteTime = rt->lastWriteTime; + te->restore_time.lastAccessTime = rt->lastAccessTime; + te->restore_time.filetype = rt->filetype; + } +} + +/* + * Append a name to the current dir path. + */ +static void +tree_append(struct tree *t, const wchar_t *name, size_t name_length) +{ + size_t size_needed; + + t->path.s[t->dirname_length] = L'\0'; + t->path.length = t->dirname_length; + /* Strip trailing '/' from name, unless entire name is "/". */ + while (name_length > 1 && name[name_length - 1] == L'/') + name_length--; + + /* Resize pathname buffer as needed. */ + size_needed = name_length + t->dirname_length + 2; + archive_wstring_ensure(&t->path, size_needed); + /* Add a separating '/' if it's needed. */ + if (t->dirname_length > 0 && + t->path.s[archive_strlen(&t->path)-1] != L'/') + archive_wstrappend_wchar(&t->path, L'/'); + t->basename = t->path.s + archive_strlen(&t->path); + archive_wstrncat(&t->path, name, name_length); + t->restore_time.full_path = t->basename; + if (t->full_path_dir_length > 0) { + t->full_path.s[t->full_path_dir_length] = L'\0'; + t->full_path.length = t->full_path_dir_length; + size_needed = name_length + t->full_path_dir_length + 2; + archive_wstring_ensure(&t->full_path, size_needed); + /* Add a separating '\' if it's needed. */ + if (t->full_path.s[archive_strlen(&t->full_path)-1] != L'\\') + archive_wstrappend_wchar(&t->full_path, L'\\'); + archive_wstrncat(&t->full_path, name, name_length); + t->restore_time.full_path = t->full_path.s; + } +} + +/* + * Open a directory tree for traversal. + */ +static struct tree * +tree_open(const wchar_t *path, int symlink_mode, int restore_time) +{ + struct tree *t; + + t = malloc(sizeof(*t)); + memset(t, 0, sizeof(*t)); + archive_string_init(&(t->full_path)); + archive_string_init(&t->path); + archive_wstring_ensure(&t->path, 15); + t->initial_symlink_mode = symlink_mode; + return (tree_reopen(t, path, restore_time)); +} + +static struct tree * +tree_reopen(struct tree *t, const wchar_t *path, int restore_time) +{ + struct archive_wstring ws; + wchar_t *pathname, *p, *base; + + t->flags = (restore_time)?needsRestoreTimes:0; + t->visit_type = 0; + t->tree_errno = 0; + t->full_path_dir_length = 0; + t->dirname_length = 0; + t->depth = 0; + t->descend = 0; + t->current = NULL; + t->d = INVALID_DIR_HANDLE; + t->symlink_mode = t->initial_symlink_mode; + archive_string_empty(&(t->full_path)); + archive_string_empty(&t->path); + t->entry_fh = INVALID_HANDLE_VALUE; + t->entry_eof = 0; + t->entry_remaining_bytes = 0; + + /* Get wchar_t strings from char strings. */ + archive_string_init(&ws); + archive_wstrcpy(&ws, path); + pathname = ws.s; + /* Get a full-path-name. */ + p = __la_win_permissive_name_w(pathname); + if (p == NULL) + goto failed; + archive_wstrcpy(&(t->full_path), p); + free(p); + + /* Convert path separators from '\' to '/' */ + for (p = pathname; *p != L'\0'; ++p) { + if (*p == L'\\') + *p = L'/'; + } + base = pathname; + + /* First item is set up a lot like a symlink traversal. */ + /* printf("Looking for wildcard in %s\n", path); */ + /* TODO: wildcard detection here screws up on \\?\c:\ UNC names */ + if (wcschr(base, L'*') || wcschr(base, L'?')) { + // It has a wildcard in it... + // Separate the last element. + p = wcsrchr(base, L'/'); + if (p != NULL) { + *p = L'\0'; + tree_append(t, base, p - base); + t->dirname_length = archive_strlen(&t->path); + base = p + 1; + } + p = wcsrchr(t->full_path.s, L'\\'); + if (p != NULL) { + *p = L'\0'; + t->full_path.length = wcslen(t->full_path.s); + t->full_path_dir_length = archive_strlen(&t->full_path); + } + } + tree_push(t, base, t->full_path.s, 0, 0, 0, NULL); + archive_wstring_free(&ws); + t->stack->flags = needsFirstVisit; + return (t); +failed: + archive_wstring_free(&ws); + tree_free(t); + return (NULL); +} + +static int +tree_descent(struct tree *t) +{ + t->dirname_length = archive_strlen(&t->path); + t->full_path_dir_length = archive_strlen(&t->full_path); + t->depth++; + return (0); +} + +/* + * We've finished a directory; ascend back to the parent. + */ +static int +tree_ascend(struct tree *t) +{ + struct tree_entry *te; + + te = t->stack; + t->depth--; + close_and_restore_time(INVALID_DIR_HANDLE, t, &te->restore_time); + return (0); +} + +/* + * Pop the working stack. + */ +static void +tree_pop(struct tree *t) +{ + struct tree_entry *te; + + t->full_path.s[t->full_path_dir_length] = L'\0'; + t->full_path.length = t->full_path_dir_length; + t->path.s[t->dirname_length] = L'\0'; + t->path.length = t->dirname_length; + if (t->stack == t->current && t->current != NULL) + t->current = t->current->parent; + te = t->stack; + t->stack = te->next; + t->dirname_length = te->dirname_length; + t->basename = t->path.s + t->dirname_length; + t->full_path_dir_length = te->full_path_dir_length; + while (t->basename[0] == L'/') + t->basename++; + archive_wstring_free(&te->name); + archive_wstring_free(&te->full_path); + free(te); +} + +/* + * Get the next item in the tree traversal. + */ +static int +tree_next(struct tree *t) +{ + int r; + + while (t->stack != NULL) { + /* If there's an open dir, get the next entry from there. */ + if (t->d != INVALID_DIR_HANDLE) { + r = tree_dir_next_windows(t, NULL); + if (r == 0) + continue; + return (r); + } + + if (t->stack->flags & needsFirstVisit) { + wchar_t *d = t->stack->name.s; + t->stack->flags &= ~needsFirstVisit; + if (wcschr(d, L'*') || wcschr(d, L'?')) { + r = tree_dir_next_windows(t, d); + if (r == 0) + continue; + return (r); + } else { + HANDLE h = FindFirstFileW(d, &t->_findData); + if (h == INVALID_DIR_HANDLE) { + t->tree_errno = errno; + t->visit_type = TREE_ERROR_DIR; + return (t->visit_type); + } + t->findData = &t->_findData; + FindClose(h); + } + /* Top stack item needs a regular visit. */ + t->current = t->stack; + tree_append(t, t->stack->name.s, + archive_strlen(&(t->stack->name))); + //t->dirname_length = t->path_length; + //tree_pop(t); + t->stack->flags &= ~needsFirstVisit; + return (t->visit_type = TREE_REGULAR); + } else if (t->stack->flags & needsDescent) { + /* Top stack item is dir to descend into. */ + t->current = t->stack; + tree_append(t, t->stack->name.s, + archive_strlen(&(t->stack->name))); + t->stack->flags &= ~needsDescent; + r = tree_descent(t); + if (r != 0) { + tree_pop(t); + t->visit_type = r; + } else + t->visit_type = TREE_POSTDESCENT; + return (t->visit_type); + } else if (t->stack->flags & needsOpen) { + t->stack->flags &= ~needsOpen; + r = tree_dir_next_windows(t, L"*"); + if (r == 0) + continue; + return (r); + } else if (t->stack->flags & needsAscent) { + /* Top stack item is dir and we're done with it. */ + r = tree_ascend(t); + tree_pop(t); + t->visit_type = r != 0 ? r : TREE_POSTASCENT; + return (t->visit_type); + } else { + /* Top item on stack is dead. */ + tree_pop(t); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + } + } + return (t->visit_type = 0); +} + +static int +tree_dir_next_windows(struct tree *t, const wchar_t *pattern) +{ + const wchar_t *name; + size_t namelen; + int r; + + for (;;) { + if (pattern != NULL) { + struct archive_wstring pt; + + archive_string_init(&pt); + archive_wstring_ensure(&pt, + archive_strlen(&(t->full_path)) + + 2 + wcslen(pattern)); + archive_wstring_copy(&pt, &(t->full_path)); + archive_wstrappend_wchar(&pt, L'\\'); + archive_wstrcat(&pt, pattern); + t->d = FindFirstFileW(pt.s, &t->_findData); + archive_wstring_free(&pt); + if (t->d == INVALID_DIR_HANDLE) { + r = tree_ascend(t); /* Undo "chdir" */ + tree_pop(t); + t->tree_errno = errno; + t->visit_type = r != 0 ? r : TREE_ERROR_DIR; + return (t->visit_type); + } + t->findData = &t->_findData; + pattern = NULL; + } else if (!FindNextFileW(t->d, &t->_findData)) { + FindClose(t->d); + t->d = INVALID_DIR_HANDLE; + t->findData = NULL; + return (0); + } + name = t->findData->cFileName; + namelen = wcslen(name); + t->flags &= ~hasLstat; + t->flags &= ~hasStat; + if (name[0] == L'.' && name[1] == L'\0') + continue; + if (name[0] == L'.' && name[1] == L'.' && name[2] == L'\0') + continue; + tree_append(t, name, namelen); + return (t->visit_type = TREE_REGULAR); + } +} + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +static void +fileTimeToUtc(const FILETIME *filetime, time_t *time, long *ns) +{ + ULARGE_INTEGER utc; + + utc.HighPart = filetime->dwHighDateTime; + utc.LowPart = filetime->dwLowDateTime; + if (utc.QuadPart >= EPOC_TIME) { + utc.QuadPart -= EPOC_TIME; + /* milli seconds base */ + *time = (time_t)(utc.QuadPart / 10000000); + /* nano seconds base */ + *ns = (long)(utc.QuadPart % 10000000) * 100; + } else { + *time = 0; + *ns = 0; + } +} + +static void +entry_copy_bhfi(struct archive_entry *entry, const wchar_t *path, + const WIN32_FIND_DATAW *findData, + const BY_HANDLE_FILE_INFORMATION *bhfi) +{ + time_t secs; + long nsecs; + mode_t mode; + + fileTimeToUtc(&bhfi->ftLastAccessTime, &secs, &nsecs); + archive_entry_set_atime(entry, secs, nsecs); + fileTimeToUtc(&bhfi->ftLastWriteTime, &secs, &nsecs); + archive_entry_set_mtime(entry, secs, nsecs); + fileTimeToUtc(&bhfi->ftCreationTime, &secs, &nsecs); + archive_entry_set_birthtime(entry, secs, nsecs); + archive_entry_set_ctime(entry, secs, nsecs); + archive_entry_set_dev(entry, bhfi_dev(bhfi)); + archive_entry_set_ino64(entry, bhfi_ino(bhfi)); + if (bhfi->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + archive_entry_set_nlink(entry, bhfi->nNumberOfLinks + 1); + else + archive_entry_set_nlink(entry, bhfi->nNumberOfLinks); + archive_entry_set_size(entry, + (((int64_t)bhfi->nFileSizeHigh) << 32) + + bhfi->nFileSizeLow); + archive_entry_set_uid(entry, 0); + archive_entry_set_gid(entry, 0); + archive_entry_set_rdev(entry, 0); + + mode = S_IRUSR | S_IRGRP | S_IROTH; + if ((bhfi->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) + mode |= S_IWUSR | S_IWGRP | S_IWOTH; + if ((bhfi->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && + findData != NULL && + findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK) + mode |= S_IFLNK; + else if (bhfi->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else { + const wchar_t *p; + + mode |= S_IFREG; + p = wcsrchr(path, L'.'); + if (p != NULL && wcslen(p) == 4) { + switch (p[1]) { + case L'B': case L'b': + if ((p[2] == L'A' || p[2] == L'a' ) && + (p[3] == L'T' || p[3] == L't' )) + mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + case L'C': case L'c': + if (((p[2] == L'M' || p[2] == L'm' ) && + (p[3] == L'D' || p[3] == L'd' )) || + ((p[2] == L'M' || p[2] == L'm' ) && + (p[3] == L'D' || p[3] == L'd' ))) + mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + case L'E': case L'e': + if ((p[2] == L'X' || p[2] == L'x' ) && + (p[3] == L'E' || p[3] == L'e' )) + mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + default: + break; + } + } + } + archive_entry_set_mode(entry, mode); +} + +static void +tree_archive_entry_copy_bhfi(struct archive_entry *entry, struct tree *t, + const BY_HANDLE_FILE_INFORMATION *bhfi) +{ + entry_copy_bhfi(entry, tree_current_path(t), t->findData, bhfi); +} + +static int +tree_current_file_information(struct tree *t, BY_HANDLE_FILE_INFORMATION *st, + int sim_lstat) +{ + HANDLE h; + int r; + DWORD flag = FILE_FLAG_BACKUP_SEMANTICS; + + if (sim_lstat && tree_current_is_physical_link(t)) + flag |= FILE_FLAG_OPEN_REPARSE_POINT; + h = CreateFileW(tree_current_access_path(t), 0, 0, NULL, + OPEN_EXISTING, flag, NULL); + if (h == INVALID_HANDLE_VALUE) + return (0); + r = GetFileInformationByHandle(h, st); + CloseHandle(h); + return (r); +} + +/* + * Get the stat() data for the entry just returned from tree_next(). + */ +static const BY_HANDLE_FILE_INFORMATION * +tree_current_stat(struct tree *t) +{ + if (!(t->flags & hasStat)) { + if (!tree_current_file_information(t, &t->st, 0)) + return NULL; + t->flags |= hasStat; + } + return (&t->st); +} + +/* + * Get the lstat() data for the entry just returned from tree_next(). + */ +static const BY_HANDLE_FILE_INFORMATION * +tree_current_lstat(struct tree *t) +{ + if (!(t->flags & hasLstat)) { + if (!tree_current_file_information(t, &t->lst, 1)) + return NULL; + t->flags |= hasLstat; + } + return (&t->lst); +} + +/* + * Test whether current entry is a dir or link to a dir. + */ +static int +tree_current_is_dir(struct tree *t) +{ + if (t->findData) + return (t->findData->dwFileAttributes + & FILE_ATTRIBUTE_DIRECTORY); + return (0); +} + +/* + * Test whether current entry is a physical directory. Usually, we + * already have at least one of stat() or lstat() in memory, so we + * use tricks to try to avoid an extra trip to the disk. + */ +static int +tree_current_is_physical_dir(struct tree *t) +{ + if (tree_current_is_physical_link(t)) + return (0); + return (tree_current_is_dir(t)); +} + +/* + * Test whether current entry is a symbolic link. + */ +static int +tree_current_is_physical_link(struct tree *t) +{ + if (t->findData) + return ((t->findData->dwFileAttributes + & FILE_ATTRIBUTE_REPARSE_POINT) && + (t->findData->dwReserved0 + == IO_REPARSE_TAG_SYMLINK)); + return (0); +} + +/* + * Test whether the same file has been in the tree as its parent. + */ +static int +tree_target_is_same_as_parent(struct tree *t, + const BY_HANDLE_FILE_INFORMATION *st) +{ + struct tree_entry *te; + int64_t dev = bhfi_dev(st); + int64_t ino = bhfi_ino(st); + + for (te = t->current->parent; te != NULL; te = te->parent) { + if (te->dev == dev && te->ino == ino) + return (1); + } + return (0); +} + +/* + * Return the access path for the entry just returned from tree_next(). + */ +static const wchar_t * +tree_current_access_path(struct tree *t) +{ + return (t->full_path.s); +} + +/* + * Return the full path for the entry just returned from tree_next(). + */ +static const wchar_t * +tree_current_path(struct tree *t) +{ + return (t->path.s); +} + +/* + * Terminate the traversal. + */ +static void +tree_close(struct tree *t) +{ + + if (t == NULL) + return; + if (t->entry_fh != INVALID_HANDLE_VALUE) { + close_and_restore_time(t->entry_fh, t, &t->restore_time); + t->entry_fh = INVALID_HANDLE_VALUE; + } + /* Close the handle of FindFirstFileW */ + if (t->d != INVALID_DIR_HANDLE) { + FindClose(t->d); + t->d = INVALID_DIR_HANDLE; + t->findData = NULL; + } + /* Release anything remaining in the stack. */ + while (t->stack != NULL) + tree_pop(t); +} + +/* + * Release any resources. + */ +static void +tree_free(struct tree *t) +{ + if (t == NULL) + return; + archive_wstring_free(&t->path); + archive_wstring_free(&t->full_path); + free(t->sparse_list); + free(t->filesystem_table); + free(t->entry_buff); + free(t); +} + + +/* + * Populate the archive_entry with metadata from the disk. + */ +int +archive_read_disk_entry_from_file(struct archive *_a, + struct archive_entry *entry, int fd, const struct stat *st) +{ + struct archive_read_disk *a = (struct archive_read_disk *)_a; + const wchar_t *path; + const wchar_t *wname; + const char *name; + HANDLE h; + BY_HANDLE_FILE_INFORMATION bhfi; + DWORD fileAttributes = 0; + int r; + + archive_clear_error(_a); + wname = archive_entry_sourcepath_w(entry); + if (wname == NULL) + wname = archive_entry_pathname_w(entry); + if (wname == NULL) { + archive_set_error(&a->archive, EINVAL, + "Can't get a wide character version of the path"); + return (ARCHIVE_FAILED); + } + path = __la_win_permissive_name_w(wname); + + if (st == NULL) { + /* + * Get metadata through GetFileInformationByHandle(). + */ + if (fd >= 0) { + h = (HANDLE)_get_osfhandle(fd); + r = GetFileInformationByHandle(h, &bhfi); + if (r == 0) { + archive_set_error(&a->archive, GetLastError(), + "Can't GetFileInformationByHandle"); + return (ARCHIVE_FAILED); + } + entry_copy_bhfi(entry, path, NULL, &bhfi); + } else { + WIN32_FIND_DATAW findData; + DWORD flag, desiredAccess; + + h = FindFirstFileW(path, &findData); + if (h == INVALID_DIR_HANDLE) { + archive_set_error(&a->archive, GetLastError(), + "Can't FindFirstFileW"); + return (ARCHIVE_FAILED); + } + FindClose(h); + + flag = FILE_FLAG_BACKUP_SEMANTICS; + if (!a->follow_symlinks && + (findData.dwFileAttributes + & FILE_ATTRIBUTE_REPARSE_POINT) && + (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK)) { + flag |= FILE_FLAG_OPEN_REPARSE_POINT; + desiredAccess = 0; + } else if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + desiredAccess = 0; + } else + desiredAccess = GENERIC_READ; + + h = CreateFileW(path, desiredAccess, 0, NULL, + OPEN_EXISTING, flag, NULL); + if (h == INVALID_HANDLE_VALUE) { + archive_set_error(&a->archive, + GetLastError(), + "Can't CreateFileW"); + return (ARCHIVE_FAILED); + } + r = GetFileInformationByHandle(h, &bhfi); + if (r == 0) { + archive_set_error(&a->archive, + GetLastError(), + "Can't GetFileInformationByHandle"); + CloseHandle(h); + return (ARCHIVE_FAILED); + } + entry_copy_bhfi(entry, path, &findData, &bhfi); + } + fileAttributes = bhfi.dwFileAttributes; + } else { + archive_entry_copy_stat(entry, st); + h = INVALID_DIR_HANDLE; + } + + /* Lookup uname/gname */ + name = archive_read_disk_uname(_a, archive_entry_uid(entry)); + if (name != NULL) + archive_entry_copy_uname(entry, name); + name = archive_read_disk_gname(_a, archive_entry_gid(entry)); + if (name != NULL) + archive_entry_copy_gname(entry, name); + + /* + * Can this file be sparse file ? + */ + if (archive_entry_filetype(entry) != AE_IFREG + || archive_entry_size(entry) <= 0 + || archive_entry_hardlink(entry) != NULL) { + if (h != INVALID_HANDLE_VALUE && fd < 0) + CloseHandle(h); + return (ARCHIVE_OK); + } + + if (h == INVALID_HANDLE_VALUE) { + if (fd >= 0) { + h = (HANDLE)_get_osfhandle(fd); + } else { + h = CreateFileW(path, GENERIC_READ, 0, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (h == INVALID_HANDLE_VALUE) { + archive_set_error(&a->archive, GetLastError(), + "Can't CreateFileW"); + return (ARCHIVE_FAILED); + } + } + r = GetFileInformationByHandle(h, &bhfi); + if (r == 0) { + archive_set_error(&a->archive, GetLastError(), + "Can't GetFileInformationByHandle"); + if (h != INVALID_HANDLE_VALUE && fd < 0) + CloseHandle(h); + return (ARCHIVE_FAILED); + } + fileAttributes = bhfi.dwFileAttributes; + } + + /* Sparse file must be set a mark, FILE_ATTRIBUTE_SPARSE_FILE */ + if ((fileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) == 0) { + if (fd < 0) + CloseHandle(h); + return (ARCHIVE_OK); + } + + r = setup_sparse_from_disk(a, entry, h); + if (fd < 0) + CloseHandle(h); + + return (r); +} + +/* + * Windows sparse interface. + */ +#if defined(__MINGW32__) && !defined(FSCTL_QUERY_ALLOCATED_RANGES) +#define FSCTL_QUERY_ALLOCATED_RANGES 0x940CF +typedef struct { + LARGE_INTEGER FileOffset; + LARGE_INTEGER Length; +} FILE_ALLOCATED_RANGE_BUFFER; +#endif + +static int +setup_sparse_from_disk(struct archive_read_disk *a, + struct archive_entry *entry, HANDLE handle) +{ + FILE_ALLOCATED_RANGE_BUFFER range, *outranges = NULL; + size_t outranges_size; + int64_t entry_size = archive_entry_size(entry); + int exit_sts = ARCHIVE_OK; + + range.FileOffset.QuadPart = 0; + range.Length.QuadPart = entry_size; + outranges_size = 2048; + outranges = (FILE_ALLOCATED_RANGE_BUFFER *)malloc(outranges_size); + if (outranges == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't allocate memory"); + exit_sts = ARCHIVE_FATAL; + goto exit_setup_sparse; + } + + for (;;) { + DWORD retbytes; + BOOL ret; + + for (;;) { + ret = DeviceIoControl(handle, + FSCTL_QUERY_ALLOCATED_RANGES, + &range, sizeof(range), outranges, + outranges_size, &retbytes, NULL); + if (ret == 0 && GetLastError() == ERROR_MORE_DATA) { + free(outranges); + outranges_size *= 2; + outranges = (FILE_ALLOCATED_RANGE_BUFFER *) + malloc(outranges_size); + if (outranges == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Couldn't allocate memory"); + exit_sts = ARCHIVE_FATAL; + goto exit_setup_sparse; + } + continue; + } else + break; + } + if (ret != 0) { + if (retbytes > 0) { + DWORD i, n; + + n = retbytes / sizeof(outranges[0]); + if (n == 1 && + outranges[0].FileOffset.QuadPart == 0 && + outranges[0].Length.QuadPart == entry_size) + break;/* This is not sparse. */ + for (i = 0; i < n; i++) + archive_entry_sparse_add_entry(entry, + outranges[i].FileOffset.QuadPart, + outranges[i].Length.QuadPart); + range.FileOffset.QuadPart = + outranges[n-1].FileOffset.QuadPart + + outranges[n-1].Length.QuadPart; + range.Length.QuadPart = + entry_size - range.FileOffset.QuadPart; + if (range.Length.QuadPart > 0) + continue; + } else { + /* The remaining data is hole. */ + archive_entry_sparse_add_entry(entry, + range.FileOffset.QuadPart, + range.Length.QuadPart); + } + break; + } else { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "DeviceIoControl Failed: %lu", GetLastError()); + exit_sts = ARCHIVE_FAILED; + goto exit_setup_sparse; + } + } +exit_setup_sparse: + free(outranges); + + return (exit_sts); +} + +#endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract.3 b/Utilities/cmlibarchive/libarchive/archive_read_extract.3 new file mode 100644 index 000000000..882c6e199 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_extract.3 @@ -0,0 +1,135 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 22, 2011 +.Dt ARCHIVE_READ_EXTRACT 3 +.Os +.Sh NAME +.Nm archive_read_extract , +.Nm archive_read_extract2 , +.Nm archive_read_extract_set_progress_callback +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fo archive_read_extract +.Fa "struct archive *" +.Fa "struct archive_entry *" +.Fa "int flags" +.Fc +.Ft int +.Fo archive_read_extract2 +.Fa "struct archive *src" +.Fa "struct archive_entry *" +.Fa "struct archive *dest" +.Fc +.Ft void +.Fo archive_read_extract_set_progress_callback +.Fa "struct archive *" +.Fa "void (*func)(void *)" +.Fa "void *user_data" +.Fc +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Fn archive_read_extract , Fn archive_read_extract_set_skip_file +A convenience function that wraps the corresponding +.Xr archive_write_disk 3 +interfaces. +The first call to +.Fn archive_read_extract +creates a restore object using +.Xr archive_write_disk_new 3 +and +.Xr archive_write_disk_set_standard_lookup 3 , +then transparently invokes +.Xr archive_write_disk_set_options 3 , +.Xr archive_write_header 3 , +.Xr archive_write_data 3 , +and +.Xr archive_write_finish_entry 3 +to create the entry on disk and copy data into it. +The +.Va flags +argument is passed unmodified to +.Xr archive_write_disk_set_options 3 . +.It Fn archive_read_extract2 +This is another version of +.Fn archive_read_extract +that allows you to provide your own restore object. +In particular, this allows you to override the standard lookup functions +using +.Xr archive_write_disk_set_group_lookup 3 , +and +.Xr archive_write_disk_set_user_lookup 3 . +Note that +.Fn archive_read_extract2 +does not accept a +.Va flags +argument; you should use +.Fn archive_write_disk_set_options +to set the restore options yourself. +.It Fn archive_read_extract_set_progress_callback +Sets a pointer to a user-defined callback that can be used +for updating progress displays during extraction. +The progress function will be invoked during the extraction of large +regular files. +The progress function will be invoked with the pointer provided to this call. +Generally, the data pointed to should include a reference to the archive +object and the archive_entry object so that various statistics +can be retrieved for the progress display. +.El +.\" +.Sh RETURN VALUES +Most functions return zero on success, non-zero on error. +The possible return codes include: +.Cm ARCHIVE_OK +(the operation succeeded), +.Cm ARCHIVE_WARN +(the operation succeeded but a non-critical error was encountered), +.Cm ARCHIVE_EOF +(end-of-archive was encountered), +.Cm ARCHIVE_RETRY +(the operation failed but can be retried), +and +.Cm ARCHIVE_FATAL +(there was a fatal error; the archive should be closed immediately). +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_data 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_open 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_extract.c b/Utilities/cmlibarchive/libarchive/archive_read_extract.c index 4f142fd94..aad8ac516 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_extract.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_extract.c @@ -40,128 +40,132 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_extract.c,v 1.61 2008/05/26 #endif #include "archive.h" +#include "archive_entry.h" #include "archive_private.h" #include "archive_read_private.h" #include "archive_write_disk_private.h" struct extract { - struct archive *ad; /* archive_write_disk object */ + struct archive *ad; /* archive_write_disk object */ - /* Progress function invoked during extract. */ - void (*extract_progress)(void *); - void *extract_progress_user_data; + /* Progress function invoked during extract. */ + void (*extract_progress)(void *); + void *extract_progress_user_data; }; -static int archive_read_extract_cleanup(struct archive_read *); -static int copy_data(struct archive *ar, struct archive *aw); +static int archive_read_extract_cleanup(struct archive_read *); +static int copy_data(struct archive *ar, struct archive *aw); static struct extract *get_extract(struct archive_read *); static struct extract * get_extract(struct archive_read *a) { - /* If we haven't initialized, do it now. */ - /* This also sets up a lot of global state. */ - if (a->extract == NULL) { - a->extract = (struct extract *)malloc(sizeof(*a->extract)); - if (a->extract == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't extract"); - return (NULL); - } - memset(a->extract, 0, sizeof(*a->extract)); - a->extract->ad = archive_write_disk_new(); - if (a->extract->ad == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't extract"); - return (NULL); - } - archive_write_disk_set_standard_lookup(a->extract->ad); - a->cleanup_archive_extract = archive_read_extract_cleanup; - } - return (a->extract); + /* If we haven't initialized, do it now. */ + /* This also sets up a lot of global state. */ + if (a->extract == NULL) { + a->extract = (struct extract *)malloc(sizeof(*a->extract)); + if (a->extract == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't extract"); + return (NULL); + } + memset(a->extract, 0, sizeof(*a->extract)); + a->extract->ad = archive_write_disk_new(); + if (a->extract->ad == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't extract"); + return (NULL); + } + archive_write_disk_set_standard_lookup(a->extract->ad); + a->cleanup_archive_extract = archive_read_extract_cleanup; + } + return (a->extract); } int archive_read_extract(struct archive *_a, struct archive_entry *entry, int flags) { - struct extract *extract; + struct extract *extract; - extract = get_extract((struct archive_read *)_a); - if (extract == NULL) - return (ARCHIVE_FATAL); - archive_write_disk_set_options(extract->ad, flags); - return (archive_read_extract2(_a, entry, extract->ad)); + extract = get_extract((struct archive_read *)_a); + if (extract == NULL) + return (ARCHIVE_FATAL); + archive_write_disk_set_options(extract->ad, flags); + return (archive_read_extract2(_a, entry, extract->ad)); } int archive_read_extract2(struct archive *_a, struct archive_entry *entry, struct archive *ad) { - struct archive_read *a = (struct archive_read *)_a; - int r, r2; - - /* Set up for this particular entry. */ - archive_write_disk_set_skip_file(ad, - a->skip_file_dev, a->skip_file_ino); - r = archive_write_header(ad, entry); - if (r < ARCHIVE_WARN) - r = ARCHIVE_WARN; - if (r != ARCHIVE_OK) - /* If _write_header failed, copy the error. */ - archive_copy_error(&a->archive, ad); - else - /* Otherwise, pour data into the entry. */ - r = copy_data(_a, ad); - r2 = archive_write_finish_entry(ad); - if (r2 < ARCHIVE_WARN) - r2 = ARCHIVE_WARN; - /* Use the first message. */ - if (r2 != ARCHIVE_OK && r == ARCHIVE_OK) - archive_copy_error(&a->archive, ad); - /* Use the worst error return. */ - if (r2 < r) - r = r2; - return (r); + struct archive_read *a = (struct archive_read *)_a; + int r, r2; + + /* Set up for this particular entry. */ + if (a->skip_file_set) + archive_write_disk_set_skip_file(ad, + a->skip_file_dev, a->skip_file_ino); + r = archive_write_header(ad, entry); + if (r < ARCHIVE_WARN) + r = ARCHIVE_WARN; + if (r != ARCHIVE_OK) + /* If _write_header failed, copy the error. */ + archive_copy_error(&a->archive, ad); + else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) + /* Otherwise, pour data into the entry. */ + r = copy_data(_a, ad); + r2 = archive_write_finish_entry(ad); + if (r2 < ARCHIVE_WARN) + r2 = ARCHIVE_WARN; + /* Use the first message. */ + if (r2 != ARCHIVE_OK && r == ARCHIVE_OK) + archive_copy_error(&a->archive, ad); + /* Use the worst error return. */ + if (r2 < r) + r = r2; + return (r); } void archive_read_extract_set_progress_callback(struct archive *_a, void (*progress_func)(void *), void *user_data) { - struct archive_read *a = (struct archive_read *)_a; - struct extract *extract = get_extract(a); - if (extract != NULL) { - extract->extract_progress = progress_func; - extract->extract_progress_user_data = user_data; - } + struct archive_read *a = (struct archive_read *)_a; + struct extract *extract = get_extract(a); + if (extract != NULL) { + extract->extract_progress = progress_func; + extract->extract_progress_user_data = user_data; + } } static int copy_data(struct archive *ar, struct archive *aw) { - off_t offset; - const void *buff; - struct extract *extract; - size_t size; - int r; - - extract = get_extract((struct archive_read *)ar); - for (;;) { - r = archive_read_data_block(ar, &buff, &size, &offset); - if (r == ARCHIVE_EOF) - return (ARCHIVE_OK); - if (r != ARCHIVE_OK) - return (r); - r = archive_write_data_block(aw, buff, size, offset); - if (r < ARCHIVE_WARN) - r = ARCHIVE_WARN; - if (r != ARCHIVE_OK) { - archive_set_error(ar, archive_errno(aw), - "%s", archive_error_string(aw)); - return (r); - } - if (extract->extract_progress) - (extract->extract_progress) - (extract->extract_progress_user_data); - } + int64_t offset; + const void *buff; + struct extract *extract; + size_t size; + int r; + + extract = get_extract((struct archive_read *)ar); + if (extract == NULL) + return (ARCHIVE_FATAL); + for (;;) { + r = archive_read_data_block(ar, &buff, &size, &offset); + if (r == ARCHIVE_EOF) + return (ARCHIVE_OK); + if (r != ARCHIVE_OK) + return (r); + r = archive_write_data_block(aw, buff, size, offset); + if (r < ARCHIVE_WARN) + r = ARCHIVE_WARN; + if (r != ARCHIVE_OK) { + archive_set_error(ar, archive_errno(aw), + "%s", archive_error_string(aw)); + return (r); + } + if (extract->extract_progress) + (extract->extract_progress) + (extract->extract_progress_user_data); + } } /* @@ -170,13 +174,10 @@ copy_data(struct archive *ar, struct archive *aw) static int archive_read_extract_cleanup(struct archive_read *a) { - int ret = ARCHIVE_OK; + int ret = ARCHIVE_OK; -#if ARCHIVE_API_VERSION > 1 - ret = -#endif - archive_write_finish(a->extract->ad); - free(a->extract); - a->extract = NULL; - return (ret); + ret = archive_write_free(a->extract->ad); + free(a->extract); + a->extract = NULL; + return (ret); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_filter.3 b/Utilities/cmlibarchive/libarchive/archive_read_filter.3 new file mode 100644 index 000000000..1cfa21599 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_filter.3 @@ -0,0 +1,127 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 19, 2011 +.Dt ARCHIVE_READ_FILTER 3 +.Os +.Sh NAME +.Nm archive_read_support_filter_all , +.Nm archive_read_support_filter_bzip2 , +.Nm archive_read_support_filter_compress , +.Nm archive_read_support_filter_gzip , +.Nm archive_read_support_filter_lzma , +.Nm archive_read_support_filter_none , +.Nm archive_read_support_filter_xz , +.Nm archive_read_support_filter_program , +.Nm archive_read_support_filter_program_signature +.Nd functions for reading streaming archives +.\" +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_read_support_filter_all "struct archive *" +.Ft int +.Fn archive_read_support_filter_bzip2 "struct archive *" +.Ft int +.Fn archive_read_support_filter_compress "struct archive *" +.Ft int +.Fn archive_read_support_filter_gzip "struct archive *" +.Ft int +.Fn archive_read_support_filter_lzma "struct archive *" +.Ft int +.Fn archive_read_support_filter_none "struct archive *" +.Ft int +.Fn archive_read_support_filter_xz "struct archive *" +.Ft int +.Fo archive_read_support_filter_program +.Fa "struct archive *" +.Fa "const char *cmd" +.Fc +.Ft int +.Fo archive_read_support_filter_program_signature +.Fa "struct archive *" +.Fa "const char *cmd" +.Fa "const void *signature" +.Fa "size_t signature_length" +.Fc +.\" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Xo +.Fn archive_read_support_filter_bzip2 , +.Fn archive_read_support_filter_compress , +.Fn archive_read_support_filter_gzip , +.Fn archive_read_support_filter_lzma , +.Fn archive_read_support_filter_none , +.Fn archive_read_support_filter_xz +.Xc +Enables auto-detection code and decompression support for the +specified compression. +These functions may fall back on external programs if an appropriate +library was not available at build time. +Decompression using an external program is usually slower than +decompression through built-in libraries. +Note that +.Dq none +is always enabled by default. +.It Fn archive_read_support_filter_all +Enables all available decompression filters. +.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, +so it makes no sense to specify this in conjunction with any other +decompression option. +.It Fn archive_read_support_filter_program_signature +This feeds data through the specified external program +but only if the initial bytes of the data match the specified +signature value. +.El +.\" +.\". Sh EXAMPLE +.\" +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +if the compression is fully supported, +.Cm ARCHIVE_WARN +if the compression is supported only through an external program. +.Pp +.Fn archive_read_support_filter_none +always succeeds. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_data 3 , +.Xr archive_read_format 3 , +.Xr archive_read_format 3 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_format.3 b/Utilities/cmlibarchive/libarchive/archive_read_format.3 new file mode 100644 index 000000000..e707e05f6 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_format.3 @@ -0,0 +1,175 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $ +.\" +.Dd March 19, 2011 +.Dt ARCHIVE_READ_FORMAT 3 +.Os +.Sh NAME +.Nm archive_read_support_format_7zip , +.Nm archive_read_support_format_all , +.Nm archive_read_support_format_ar , +.Nm archive_read_support_format_by_code , +.Nm archive_read_support_format_cab , +.Nm archive_read_support_format_cpio , +.Nm archive_read_support_format_empty , +.Nm archive_read_support_format_iso9660 , +.Nm archive_read_support_format_lha , +.Nm archive_read_support_format_mtree, +.Nm archive_read_support_format_rar, +.Nm archive_read_support_format_raw, +.Nm archive_read_support_format_tar , +.Nm archive_read_support_format_xar , +.Nm archive_read_support_format_zip +.Nd functions for reading streaming archives +.\" +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_read_support_format_7zip "struct archive *" +.Ft int +.Fn archive_read_support_format_all "struct archive *" +.Ft int +.Fn archive_read_support_format_ar "struct archive *" +.Ft int +.Fn archive_read_support_format_by_code "struct archive *" "int" +.Ft int +.Fn archive_read_support_format_cab "struct archive *" +.Ft int +.Fn archive_read_support_format_cpio "struct archive *" +.Ft int +.Fn archive_read_support_format_empty "struct archive *" +.Ft int +.Fn archive_read_support_format_iso9660 "struct archive *" +.Ft int +.Fn archive_read_support_format_lha "struct archive *" +.Ft int +.Fn archive_read_support_format_mtree "struct archive *" +.Ft int +.Fn archive_read_support_format_rar "struct archive *" +.Ft int +.Fn archive_read_support_format_raw "struct archive *" +.Ft int +.Fn archive_read_support_format_tar "struct archive *" +.Ft int +.Fn archive_read_support_format_xar "struct archive *" +.Ft int +.Fn archive_read_support_format_zip "struct archive *" +.\" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Xo +.Fn archive_read_support_format_7zip , +.Fn archive_read_support_format_ar , +.Fn archive_read_support_format_cab , +.Fn archive_read_support_format_cpio , +.Fn archive_read_support_format_iso9660 , +.Fn archive_read_support_format_lha , +.Fn archive_read_support_format_mtree , +.Fn archive_read_support_format_rar , +.Fn archive_read_support_format_raw , +.Fn archive_read_support_format_tar , +.Fn archive_read_support_format_xar , +.Fn archive_read_support_format_zip +.Xc +Enables support---including auto-detection code---for the +specified archive format. +For example, +.Fn archive_read_support_format_tar +enables support for a variety of standard tar formats, old-style tar, +ustar, pax interchange format, and many common variants. +.It Fn archive_read_support_format_all +Enables support for all available formats except the +.Dq raw +format (see below). +.It Fn archive_read_support_format_by_code +Enables a single format specified by the format code. +This can be useful when reading a single archive twice; +use +.Fn archive_format +after reading the first time and pass the resulting code +to this function to selectively enable only the necessary +format support. +Note: In statically-linked executables, this will cause +your program to include support for every format. +If executable size is a concern, you may wish to avoid +using this function. +.It Fn archive_read_support_format_empty +Enables support for treating empty files as empty archives. +Because empty files are valid for several different formats, +it is not possible to accurately determine a format for +an empty file based purely on contents. +So empty files are treated by libarchive as a distinct +format. +.It Fn archive_read_support_format_raw +The +.Dq raw +format handler allows libarchive to be used to read arbitrary data. +It treats any data stream as an archive with a single entry. +The pathname of this entry is +.Dq data ; +all other entry fields are unset. +This is not enabled by +.Fn archive_read_support_format_all +in order to avoid erroneous handling of damaged archives. +.El +.\" .Sh EXAMPLE +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read_data 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 +.Sh BUGS +Many traditional archiver programs treat +empty files as valid empty archives. +For example, many implementations of +.Xr tar 1 +allow you to append entries to an empty file. +Of course, it is impossible to determine the format of an empty file +by inspecting the contents, so this library treats empty files as +having a special +.Dq empty +format. +.Pp +Using the +.Dq raw +handler together with any other handler will often work +but can produce surprising results. diff --git a/Utilities/cmlibarchive/libarchive/archive_read_free.3 b/Utilities/cmlibarchive/libarchive/archive_read_free.3 new file mode 100644 index 000000000..f5f2515a8 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_free.3 @@ -0,0 +1,91 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $ +.\" +.Dd March 20, 2011 +.Dt ARCHIVE_READ_FREE 3 +.Os +.Sh NAME +.Nm archive_read_close , +.Nm archive_read_finish , +.Nm archive_read_free +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_read_close "struct archive *" +.Ft int +.Fn archive_read_finish "struct archive *" +.Ft int +.Fn archive_read_free "struct archive *" +.\" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Fn archive_read_close +Complete the archive and invoke the close callback. +.It Fn archive_read_finish +This is a deprecated synonym for +.Fn archive_read_free . +The new name was introduced with libarchive 3.0. +Applications that need to compile with either libarchive 2 +or libarchive 3 should continue to use the +.Fn archive_read_finish +name. +Both names will be supported until libarchive 4.0 is +released, which is not expected to occur earlier +than 2013. +.It Fn archive_read_free +Invokes +.Fn archive_read_close +if it was not invoked manually, then release all resources. +Note: In libarchive 1.x, this function was declared to return +.Ft void , +which made it impossible to detect certain errors when +.Fn archive_read_close +was invoked implicitly from this function. +The declaration is corrected beginning with libarchive 2.0. +.El +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr libarchive 3 , +.Xr archive_read_new 3 , +.Xr archive_read_data 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_open 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_header.3 b/Utilities/cmlibarchive/libarchive/archive_read_header.3 new file mode 100644 index 000000000..999e963cf --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_header.3 @@ -0,0 +1,89 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 22, 2011 +.Dt ARCHIVE_READ_HEADER 3 +.Os +.Sh NAME +.Nm archive_read_next_header , +.Nm archive_read_next_header2 +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_read_next_header "struct archive *" "struct archive_entry **" +.Ft int +.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *" +.\" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Fn archive_read_next_header +Read the header for the next entry and return a pointer to +a +.Tn struct archive_entry . +This is a convenience wrapper around +.Fn archive_read_next_header2 +that reuses an internal +.Tn struct archive_entry +object for each request. +.It Fn archive_read_next_header2 +Read the header for the next entry and populate the provided +.Tn struct archive_entry . +.El +.\" +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +(the operation succeeded), +.Cm ARCHIVE_WARN +(the operation succeeded but a non-critical error was encountered), +.Cm ARCHIVE_EOF +(end-of-archive was encountered), +.Cm ARCHIVE_RETRY +(the operation failed but can be retried), +and +.Cm ARCHIVE_FATAL +(there was a fatal error; the archive should be closed immediately). +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_data 3 , +.Xr archive_read_extract 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_open 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_new.3 b/Utilities/cmlibarchive/libarchive/archive_read_new.3 new file mode 100644 index 000000000..e04406aa6 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_new.3 @@ -0,0 +1,57 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $ +.\" +.Dd March 20, 2011 +.Dt ARCHIVE_READ_NEW 3 +.Os +.Sh NAME +.Nm archive_read_new +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft struct archive * +.Fn archive_read_new "void" +.Sh DESCRIPTION +Allocates and initializes a +.Tn struct archive +object suitable for reading from an archive. +.Dv NULL +is returned on error. +.Pp +A complete description of the +.Tn struct archive +object can be found in the overview manual page for +.Xr libarchive 3 . +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read_data 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open.3 b/Utilities/cmlibarchive/libarchive/archive_read_open.3 new file mode 100644 index 000000000..09c057568 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_open.3 @@ -0,0 +1,231 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_read.3 191595 2009-04-27 20:13:13Z kientzle $ +.\" +.Dd March 19, 2011 +.Dt ARCHIVE_READ_OPEN 3 +.Os +.Sh NAME +.Nm archive_read_open , +.Nm archive_read_open2 , +.Nm archive_read_open_fd , +.Nm archive_read_open_FILE , +.Nm archive_read_open_filename , +.Nm archive_read_open_memory , +.Nd functions for reading streaming archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fo archive_read_open +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "archive_open_callback *" +.Fa "archive_read_callback *" +.Fa "archive_close_callback *" +.Fc +.Ft int +.Fo archive_read_open2 +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "archive_open_callback *" +.Fa "archive_read_callback *" +.Fa "archive_skip_callback *" +.Fa "archive_close_callback *" +.Fc +.Ft int +.Fn archive_read_open_FILE "struct archive *" "FILE *file" +.Ft int +.Fn archive_read_open_fd "struct archive *" "int fd" "size_t block_size" +.Ft int +.Fo archive_read_open_filename +.Fa "struct archive *" +.Fa "const char *filename" +.Fa "size_t block_size" +.Fc +.Ft int +.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size" +.Sh DESCRIPTION +.Bl -tag -compact -width indent +.It Fn archive_read_open +The same as +.Fn archive_read_open2 , +except that the skip callback is assumed to be +.Dv NULL . +.It Fn archive_read_open2 +Freeze the settings, open the archive, and prepare for reading entries. +This is the most generic version of this call, which accepts +four callback functions. +Most clients will want to use +.Fn archive_read_open_filename , +.Fn archive_read_open_FILE , +.Fn archive_read_open_fd , +or +.Fn archive_read_open_memory +instead. +The library invokes the client-provided functions to obtain +raw bytes from the archive. +.It Fn archive_read_open_FILE +Like +.Fn archive_read_open , +except that it accepts a +.Ft "FILE *" +pointer. +This function should not be used with tape drives or other devices +that require strict I/O blocking. +.It Fn archive_read_open_fd +Like +.Fn archive_read_open , +except that it accepts a file descriptor and block size rather than +a set of function pointers. +Note that the file descriptor will not be automatically closed at +end-of-archive. +This function is safe for use with tape drives or other blocked devices. +.It Fn archive_read_open_file +This is a deprecated synonym for +.Fn archive_read_open_filename . +.It Fn archive_read_open_filename +Like +.Fn archive_read_open , +except that it accepts a simple filename and a block size. +A NULL filename represents standard input. +This function is safe for use with tape drives or other blocked devices. +.It Fn archive_read_open_memory +Like +.Fn archive_read_open , +except that it accepts a pointer and size of a block of +memory containing the archive data. +.El +.Pp +A complete description of the +.Tn struct archive +and +.Tn struct archive_entry +objects can be found in the overview manual page for +.Xr libarchive 3 . +.Sh CLIENT CALLBACKS +The callback functions must match the following prototypes: +.Bl -item -offset indent +.It +.Ft typedef ssize_t +.Fo archive_read_callback +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "const void **buffer" +.Fc +.It +.Ft typedef off_t +.Fo archive_skip_callback +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "off_t request" +.Fc +.It +.Ft typedef int +.Fn archive_open_callback "struct archive *" "void *client_data" +.It +.Ft typedef int +.Fn archive_close_callback "struct archive *" "void *client_data" +.El +.Pp +The open callback is invoked by +.Fn archive_open . +It should return +.Cm ARCHIVE_OK +if the underlying file or data source is successfully +opened. +If the open fails, it should call +.Fn archive_set_error +to register an error code and message and return +.Cm ARCHIVE_FATAL . +.Pp +The read callback is invoked whenever the library +requires raw bytes from the archive. +The read callback should read data into a buffer, +set the +.Li const void **buffer +argument to point to the available data, and +return a count of the number of bytes available. +The library will invoke the read callback again +only after it has consumed this data. +The library imposes no constraints on the size +of the data blocks returned. +On end-of-file, the read callback should +return zero. +On error, the read callback should invoke +.Fn archive_set_error +to register an error code and message and +return -1. +.Pp +The skip callback is invoked when the +library wants to ignore a block of data. +The return value is the number of bytes actually +skipped, which may differ from the request. +If the callback cannot skip data, it should return +zero. +If the skip callback is not provided (the +function pointer is +.Dv NULL ), +the library will invoke the read function +instead and simply discard the result. +A skip callback can provide significant +performance gains when reading uncompressed +archives from slow disk drives or other media +that can skip quickly. +.Pp +The close callback is invoked by archive_close when +the archive processing is complete. +The callback should return +.Cm ARCHIVE_OK +on success. +On failure, the callback should invoke +.Fn archive_set_error +to register an error code and message and +return +.Cm ARCHIVE_FATAL. +.\" .Sh EXAMPLE +.\" +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_data 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_set_options 3 , +.Xr archive_util 3 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c index d1421f858..d8f657295 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_fd.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_fd.c,v 1.13 2007/06/26 03:06:48 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_fd.c 201103 2009-12-28 03:13:49Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -51,138 +51,131 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_fd.c,v 1.13 2007/06/26 #include "archive.h" struct read_fd_data { - int fd; - size_t block_size; - char can_skip; - void *buffer; + int fd; + size_t block_size; + char use_lseek; + void *buffer; }; -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif +static int file_close(struct archive *, void *); +static ssize_t file_read(struct archive *, void *, const void **buff); +static int64_t file_skip(struct archive *, void *, int64_t request); int archive_read_open_fd(struct archive *a, int fd, size_t block_size) { - struct stat st; - struct read_fd_data *mine; - void *b; - - archive_clear_error(a); - if (fstat(fd, &st) != 0) { - archive_set_error(a, errno, "Can't stat fd %d", fd); - return (ARCHIVE_FATAL); - } - - mine = (struct read_fd_data *)malloc(sizeof(*mine)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - mine->block_size = block_size; - mine->buffer = b; - mine->fd = fd; - /* - * Skip support is a performance optimization for anything - * that supports lseek(). On FreeBSD, only regular files and - * raw disk devices support lseek() and there's no portable - * way to determine if a device is a raw disk device, so we - * only enable this optimization for regular files. - */ - if (S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - mine->can_skip = 1; - } else - mine->can_skip = 0; -#if defined(__CYGWIN__) || defined(__BORLANDC__) - setmode(mine->fd, O_BINARY); -#elif defined(_WIN32) - _setmode(mine->fd, _O_BINARY); + struct stat st; + struct read_fd_data *mine; + void *b; + + archive_clear_error(a); + if (fstat(fd, &st) != 0) { + archive_set_error(a, errno, "Can't stat fd %d", fd); + return (ARCHIVE_FATAL); + } + + mine = (struct read_fd_data *)calloc(1, sizeof(*mine)); + b = malloc(block_size); + if (mine == NULL || b == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + free(mine); + free(b); + return (ARCHIVE_FATAL); + } + mine->block_size = block_size; + mine->buffer = b; + mine->fd = fd; + /* + * Skip support is a performance optimization for anything + * that supports lseek(). On FreeBSD, only regular files and + * raw disk devices support lseek() and there's no portable + * way to determine if a device is a raw disk device, so we + * only enable this optimization for regular files. + */ + if (S_ISREG(st.st_mode)) { + archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); + mine->use_lseek = 1; + } +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(mine->fd, O_BINARY); #endif - return (archive_read_open2(a, mine, - NULL, file_read, file_skip, file_close)); + archive_read_set_read_callback(a, file_read); + archive_read_set_skip_callback(a, file_skip); + archive_read_set_close_callback(a, file_close); + archive_read_set_callback_data(a, mine); + return (archive_read_open1(a)); } static ssize_t file_read(struct archive *a, void *client_data, const void **buff) { - struct read_fd_data *mine = (struct read_fd_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - archive_set_error(a, errno, "Error reading fd %d", mine->fd); - } - return (bytes_read); + struct read_fd_data *mine = (struct read_fd_data *)client_data; + ssize_t bytes_read; + + *buff = mine->buffer; + for (;;) { + bytes_read = read(mine->fd, mine->buffer, mine->block_size); + if (bytes_read < 0) { + if (errno == EINTR) + continue; + archive_set_error(a, errno, "Error reading fd %d", mine->fd); + } + return (bytes_read); + } } -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) -#else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) -#endif +static int64_t +file_skip(struct archive *a, void *client_data, int64_t request) { - struct read_fd_data *mine = (struct read_fd_data *)client_data; - off_t old_offset, new_offset; - - if (!mine->can_skip) - return (0); - - /* Reduce request to the next smallest multiple of block_size */ - request = (request / mine->block_size) * mine->block_size; - if (request == 0) - return (0); - - /* - * Hurray for lazy evaluation: if the first lseek fails, the second - * one will not be executed. - */ - if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) || - ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0)) - { - /* If seek failed once, it will probably fail again. */ - mine->can_skip = 0; - - if (errno == ESPIPE) - { - /* - * Failure to lseek() can be caused by the file - * descriptor pointing to a pipe, socket or FIFO. - * Return 0 here, so the compression layer will use - * read()s instead to advance the file descriptor. - * It's slower of course, but works as well. - */ - return (0); - } - /* - * There's been an error other than ESPIPE. This is most - * likely caused by a programmer error (too large request) - * or a corrupted archive file. - */ - archive_set_error(a, errno, "Error seeking"); - return (-1); - } - return (new_offset - old_offset); + struct read_fd_data *mine = (struct read_fd_data *)client_data; + off_t skip = (off_t)request; + off_t old_offset, new_offset; + int skip_bits = sizeof(skip) * 8 - 1; /* off_t is a signed type. */ + + if (!mine->use_lseek) + return (0); + + /* Reduce a request that would overflow the 'skip' variable. */ + if (sizeof(request) > sizeof(skip)) { + int64_t max_skip = + (((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1; + if (request > max_skip) + skip = max_skip; + } + + /* Reduce request to the next smallest multiple of block_size */ + request = (request / mine->block_size) * mine->block_size; + if (request == 0) + return (0); + + if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0) && + ((new_offset = lseek(mine->fd, skip, SEEK_CUR)) >= 0)) + return (new_offset - old_offset); + + /* If seek failed once, it will probably fail again. */ + mine->use_lseek = 0; + + /* Let libarchive recover with read+discard. */ + if (errno == ESPIPE) + return (0); + + /* + * There's been an error other than ESPIPE. This is most + * likely caused by a programmer error (too large request) + * or a corrupted archive file. + */ + archive_set_error(a, errno, "Error seeking"); + return (-1); } static int file_close(struct archive *a, void *client_data) { - struct read_fd_data *mine = (struct read_fd_data *)client_data; + struct read_fd_data *mine = (struct read_fd_data *)client_data; - (void)a; /* UNUSED */ - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + free(mine->buffer); + free(mine); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_file.c b/Utilities/cmlibarchive/libarchive/archive_read_open_file.c index a4f66fcf1..b1aac0a7c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_file.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_file.c,v 1.20 2007/06/26 03:06:48 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_file.c 201093 2009-12-28 02:28:44Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -51,117 +51,127 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_file.c,v 1.20 2007/06/2 #include "archive.h" struct read_FILE_data { - FILE *f; - size_t block_size; - void *buffer; - char can_skip; + FILE *f; + size_t block_size; + void *buffer; + char can_skip; }; -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif +static int file_close(struct archive *, void *); +static ssize_t file_read(struct archive *, void *, const void **buff); +static int64_t file_skip(struct archive *, void *, int64_t request); int archive_read_open_FILE(struct archive *a, FILE *f) { - struct stat st; - struct read_FILE_data *mine; - size_t block_size = 128 * 1024; - void *b; - - archive_clear_error(a); - mine = (struct read_FILE_data *)malloc(sizeof(*mine)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - mine->block_size = block_size; - mine->buffer = b; - mine->f = f; - /* - * If we can't fstat() the file, it may just be that it's not - * a file. (FILE * objects can wrap many kinds of I/O - * streams, some of which don't support fileno()).) - */ - if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - /* Enable the seek optimization only for regular files. */ - mine->can_skip = 1; - } else - mine->can_skip = 0; - -#if defined(__CYGWIN__) || defined(__BORLANDC__) - setmode(fileno(mine->f), O_BINARY); -#elif defined(_WIN32) - _setmode(_fileno(mine->f), _O_BINARY); + struct stat st; + struct read_FILE_data *mine; + size_t block_size = 128 * 1024; + void *b; + + archive_clear_error(a); + mine = (struct read_FILE_data *)malloc(sizeof(*mine)); + b = malloc(block_size); + if (mine == NULL || b == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + free(mine); + free(b); + return (ARCHIVE_FATAL); + } + mine->block_size = block_size; + mine->buffer = b; + mine->f = f; + /* + * If we can't fstat() the file, it may just be that it's not + * a file. (FILE * objects can wrap many kinds of I/O + * streams, some of which don't support fileno()).) + */ + if (fstat(fileno(mine->f), &st) == 0 && S_ISREG(st.st_mode)) { + archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); + /* Enable the seek optimization only for regular files. */ + mine->can_skip = 1; + } else + mine->can_skip = 0; + +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(fileno(mine->f), O_BINARY); #endif - return (archive_read_open2(a, mine, NULL, file_read, - file_skip, file_close)); + archive_read_set_read_callback(a, file_read); + archive_read_set_skip_callback(a, file_skip); + archive_read_set_close_callback(a, file_close); + archive_read_set_callback_data(a, mine); + return (archive_read_open1(a)); } static ssize_t file_read(struct archive *a, void *client_data, const void **buff) { - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f); - if (bytes_read < 0) { - archive_set_error(a, errno, "Error reading file"); - } - return (bytes_read); + struct read_FILE_data *mine = (struct read_FILE_data *)client_data; + ssize_t bytes_read; + + *buff = mine->buffer; + bytes_read = fread(mine->buffer, 1, mine->block_size, mine->f); + if (bytes_read < 0) { + archive_set_error(a, errno, "Error reading file"); + } + return (bytes_read); } -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) +static int64_t +file_skip(struct archive *a, void *client_data, int64_t request) +{ + struct read_FILE_data *mine = (struct read_FILE_data *)client_data; +#if HAVE_FSEEKO + off_t skip = (off_t)request; +#elif HAVE__FSEEKI64 + int64_t skip = request; #else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) + long skip = (long)request; #endif -{ - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - - (void)a; /* UNUSED */ - - /* - * If we can't skip, return 0 as the amount we did step and - * the caller will work around by reading and discarding. - */ - if (!mine->can_skip) - return (0); - if (request == 0) - return (0); + int skip_bits = sizeof(skip) * 8 - 1; + + (void)a; /* UNUSED */ + + /* + * If we can't skip, return 0 as the amount we did step and + * the caller will work around by reading and discarding. + */ + if (!mine->can_skip) + return (0); + if (request == 0) + return (0); + + /* If request is too big for a long or an off_t, reduce it. */ + if (sizeof(request) > sizeof(skip)) { + int64_t max_skip = + (((int64_t)1 << (skip_bits - 1)) - 1) * 2 + 1; + if (request > max_skip) + skip = max_skip; + } #if HAVE_FSEEKO - if (fseeko(mine->f, request, SEEK_CUR) != 0) + if (fseeko(mine->f, skip, SEEK_CUR) != 0) +#elif HAVE__FSEEKI64 + if (_fseeki64(mine->f, skip, SEEK_CUR) != 0) #else - if (fseek(mine->f, request, SEEK_CUR) != 0) + if (fseek(mine->f, skip, SEEK_CUR) != 0) #endif - { - mine->can_skip = 0; - return (0); - } - return (request); + { + mine->can_skip = 0; + return (0); + } + return (request); } static int file_close(struct archive *a, void *client_data) { - struct read_FILE_data *mine = (struct read_FILE_data *)client_data; + struct read_FILE_data *mine = (struct read_FILE_data *)client_data; - (void)a; /* UNUSED */ - if (mine->buffer != NULL) - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + if (mine->buffer != NULL) + free(mine->buffer); + free(mine); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c index 6c4dcf756..bf5269724 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_filename.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,8 +24,11 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_filename.c,v 1.21 2008/02/19 06:10:48 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_open_filename.c 201093 2009-12-28 02:28:44Z kientzle $"); +#ifdef HAVE_SYS_IOCTL_H +#include +#endif #ifdef HAVE_SYS_STAT_H #include #endif @@ -47,224 +50,460 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_filename.c,v 1.21 2008/ #ifdef HAVE_UNISTD_H #include #endif +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include +#elif defined(__NetBSD__) || defined(__OpenBSD__) +#include +#include +#elif defined(__DragonFly__) +#include +#endif #include "archive.h" +#include "archive_string.h" #ifndef O_BINARY #define O_BINARY 0 #endif struct read_file_data { - int fd; - size_t block_size; - void *buffer; - mode_t st_mode; /* Mode bits for opened file. */ - char can_skip; /* This file supports skipping. */ - char filename[1]; /* Must be last! */ + int fd; + size_t block_size; + void *buffer; + mode_t st_mode; /* Mode bits for opened file. */ + char use_lseek; + enum fnt_e { FNT_STDIN, FNT_MBS, FNT_WCS } filename_type; + union { + char m[1];/* MBS filename. */ + wchar_t w[1];/* WCS filename. */ + } filename; /* Must be last! */ }; -static int file_close(struct archive *, void *); -static ssize_t file_read(struct archive *, void *, const void **buff); -#if ARCHIVE_API_VERSION < 2 -static ssize_t file_skip(struct archive *, void *, size_t request); -#else -static off_t file_skip(struct archive *, void *, off_t request); -#endif +static int file_close(struct archive *, void *); +static int file_open_filename(struct archive *, enum fnt_e, const void *, + size_t); +static ssize_t file_read(struct archive *, void *, const void **buff); +static int64_t file_seek(struct archive *, void *, int64_t request, int); +static int64_t file_skip(struct archive *, void *, int64_t request); +static int64_t file_skip_lseek(struct archive *, void *, int64_t request); int archive_read_open_file(struct archive *a, const char *filename, size_t block_size) { - return (archive_read_open_filename(a, filename, block_size)); + return (archive_read_open_filename(a, filename, block_size)); } int archive_read_open_filename(struct archive *a, const char *filename, size_t block_size) { - struct stat st; - struct read_file_data *mine; - void *b; - int fd; - - archive_clear_error(a); - if (filename == NULL || filename[0] == '\0') { - /* We used to invoke archive_read_open_fd(a,0,block_size) - * here, but that doesn't (and shouldn't) handle the - * end-of-file flush when reading stdout from a pipe. - * Basically, read_open_fd() is intended for folks who - * are willing to handle such details themselves. This - * API is intended to be a little smarter for folks who - * want easy handling of the common case. - */ - filename = ""; /* Normalize NULL to "" */ - fd = 0; -#if defined(__CYGWIN__) || defined(__BORLANDC__) - setmode(0, O_BINARY); -#elif defined(_WIN32) - _setmode(0, _O_BINARY); + enum fnt_e filename_type; + + if (filename == NULL || filename[0] == '\0') { + filename_type = FNT_STDIN; + } else + filename_type = FNT_MBS; + return (file_open_filename(a, filename_type, filename, block_size)); +} + +int +archive_read_open_filename_w(struct archive *a, const wchar_t *wfilename, + size_t block_size) +{ + enum fnt_e filename_type; + + if (wfilename == NULL || wfilename[0] == L'\0') { + filename_type = FNT_STDIN; + } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + filename_type = FNT_WCS; +#else + /* + * POSIX system does not support a wchar_t interface for + * open() system call, so we have to translate a whcar_t + * filename to multi-byte one and use it. + */ + struct archive_string fn; + int r; + + archive_string_init(&fn); + if (archive_string_append_from_wcs(&fn, wfilename, + wcslen(wfilename)) != 0) { + archive_set_error(a, EINVAL, + "Failed to convert a wide-character filename to" + " a multi-byte filename"); + archive_string_free(&fn); + return (ARCHIVE_FATAL); + } + r = file_open_filename(a, FNT_MBS, fn.s, block_size); + archive_string_free(&fn); + return (r); +#endif + } + return (file_open_filename(a, filename_type, wfilename, block_size)); +} + +static int +file_open_filename(struct archive *a, enum fnt_e filename_type, + const void *_filename, size_t block_size) +{ + struct stat st; + struct read_file_data *mine; + void *buffer; + const char *filename = NULL; + const wchar_t *wfilename = NULL; + int fd; + int is_disk_like = 0; +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + off_t mediasize = 0; /* FreeBSD-specific, so off_t okay here. */ +#elif defined(__NetBSD__) || defined(__OpenBSD__) + struct disklabel dl; +#elif defined(__DragonFly__) + struct partinfo pi; +#endif + + archive_clear_error(a); + if (filename_type == FNT_STDIN) { + /* We used to delegate stdin support by + * directly calling archive_read_open_fd(a,0,block_size) + * here, but that doesn't (and shouldn't) handle the + * end-of-file flush when reading stdout from a pipe. + * Basically, read_open_fd() is intended for folks who + * are willing to handle such details themselves. This + * API is intended to be a little smarter for folks who + * want easy handling of the common case. + */ + fd = 0; +#if defined(__CYGWIN__) || defined(_WIN32) + setmode(0, O_BINARY); +#endif + filename = ""; + } else if (filename_type == FNT_MBS) { + filename = (const char *)_filename; + fd = open(filename, O_RDONLY | O_BINARY); + if (fd < 0) { + archive_set_error(a, errno, + "Failed to open '%s'", filename); + return (ARCHIVE_FATAL); + } + } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + wfilename = (const wchar_t *)_filename; + fd = _wopen(wfilename, O_RDONLY | O_BINARY); + if (fd < 0 && errno == ENOENT) { + wchar_t *fullpath; + fullpath = __la_win_permissive_name_w(wfilename); + if (fullpath != NULL) { + fd = _wopen(fullpath, O_RDONLY | O_BINARY); + free(fullpath); + } + } + if (fd < 0) { + archive_set_error(a, errno, + "Failed to open '%S'", wfilename); + return (ARCHIVE_FATAL); + } +#else + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unexpedted operation in archive_read_open_filename"); + return (ARCHIVE_FATAL); +#endif + } + if (fstat(fd, &st) != 0) { + if (filename_type == FNT_WCS) + archive_set_error(a, errno, "Can't stat '%S'", + wfilename); + else + archive_set_error(a, errno, "Can't stat '%s'", + filename); + return (ARCHIVE_FATAL); + } + + /* + * Determine whether the input looks like a disk device or a + * tape device. The results are used below to select an I/O + * strategy: + * = "disk-like" devices support arbitrary lseek() and will + * support I/O requests of any size. So we get easy skipping + * and can cheat on block sizes to get better performance. + * = "tape-like" devices require strict blocking and use + * specialized ioctls for seeking. + * = "socket-like" devices cannot seek at all but can improve + * performance by using nonblocking I/O to read "whatever is + * available right now". + * + * Right now, we only specially recognize disk-like devices, + * but it should be straightforward to add probes and strategy + * here for tape-like and socket-like devices. + */ + if (S_ISREG(st.st_mode)) { + /* Safety: Tell the extractor not to overwrite the input. */ + archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); + /* Regular files act like disks. */ + is_disk_like = 1; + } +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + /* FreeBSD: if it supports DIOCGMEDIASIZE ioctl, it's disk-like. */ + else if (S_ISCHR(st.st_mode) && + ioctl(fd, DIOCGMEDIASIZE, &mediasize) == 0 && + mediasize > 0) { + is_disk_like = 1; + } +#elif defined(__NetBSD__) || defined(__OpenBSD__) + /* Net/OpenBSD: if it supports DIOCGDINFO ioctl, it's disk-like. */ + else if ((S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) && + ioctl(fd, DIOCGDINFO, &dl) == 0 && + dl.d_partitions[DISKPART(st.st_rdev)].p_size > 0) { + is_disk_like = 1; + } +#elif defined(__DragonFly__) + /* DragonFly BSD: if it supports DIOCGPART ioctl, it's disk-like. */ + else if (S_ISCHR(st.st_mode) && + ioctl(fd, DIOCGPART, &pi) == 0 && + pi.media_size > 0) { + is_disk_like = 1; + } +#elif defined(__linux__) + /* Linux: All block devices are disk-like. */ + else if (S_ISBLK(st.st_mode) && + lseek(fd, 0, SEEK_CUR) == 0 && + lseek(fd, 0, SEEK_SET) == 0 && + lseek(fd, 0, SEEK_END) > 0 && + lseek(fd, 0, SEEK_SET) == 0) { + is_disk_like = 1; + } #endif - } else { - fd = open(filename, O_RDONLY | O_BINARY); - if (fd < 0) { - archive_set_error(a, errno, - "Failed to open '%s'", filename); - return (ARCHIVE_FATAL); - } - } - if (fstat(fd, &st) != 0) { - archive_set_error(a, errno, "Can't stat '%s'", filename); - return (ARCHIVE_FATAL); - } - - mine = (struct read_file_data *)calloc(1, - sizeof(*mine) + strlen(filename)); - b = malloc(block_size); - if (mine == NULL || b == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - free(mine); - free(b); - return (ARCHIVE_FATAL); - } - strcpy(mine->filename, filename); - mine->block_size = block_size; - mine->buffer = b; - mine->fd = fd; - /* Remember mode so close can decide whether to flush. */ - mine->st_mode = st.st_mode; - /* If we're reading a file from disk, ensure that we don't - overwrite it with an extracted file. */ - if (S_ISREG(st.st_mode)) { - archive_read_extract_set_skip_file(a, st.st_dev, st.st_ino); - /* - * Enabling skip here is a performance optimization - * for anything that supports lseek(). On FreeBSD - * (and probably many other systems), only regular - * files and raw disk devices support lseek() (on - * other input types, lseek() returns success but - * doesn't actually change the file pointer, which - * just completely screws up the position-tracking - * logic). In addition, I've yet to find a portable - * way to determine if a device is a raw disk device. - * So I don't see a way to do much better than to only - * enable this optimization for regular files. - */ - mine->can_skip = 1; - } - return (archive_read_open2(a, mine, - NULL, file_read, file_skip, file_close)); + /* TODO: Add an "is_tape_like" variable and appropriate tests. */ + + if (filename_type == FNT_WCS) + mine = (struct read_file_data *)calloc(1, + sizeof(*mine) + wcslen(wfilename) * sizeof(wchar_t)); + else + mine = (struct read_file_data *)calloc(1, + sizeof(*mine) + strlen(filename)); + /* Disk-like devices prefer power-of-two block sizes. */ + /* Use provided block_size as a guide so users have some control. */ + if (is_disk_like) { + size_t new_block_size = 64 * 1024; + while (new_block_size < block_size + && new_block_size < 64 * 1024 * 1024) + new_block_size *= 2; + block_size = new_block_size; + } + buffer = malloc(block_size); + if (mine == NULL || buffer == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + free(mine); + free(buffer); + return (ARCHIVE_FATAL); + } + if (filename_type == FNT_WCS) + wcscpy(mine->filename.w, wfilename); + else + strcpy(mine->filename.m, filename); + mine->filename_type = filename_type; + mine->block_size = block_size; + mine->buffer = buffer; + mine->fd = fd; + /* Remember mode so close can decide whether to flush. */ + mine->st_mode = st.st_mode; + + /* Disk-like inputs can use lseek(). */ + if (is_disk_like) { + archive_read_set_seek_callback(a, file_seek); + mine->use_lseek = 1; + } + + archive_read_set_read_callback(a, file_read); + archive_read_set_skip_callback(a, file_skip); + archive_read_set_close_callback(a, file_close); + archive_read_set_callback_data(a, mine); + return (archive_read_open1(a)); } static ssize_t file_read(struct archive *a, void *client_data, const void **buff) { - struct read_file_data *mine = (struct read_file_data *)client_data; - ssize_t bytes_read; - - *buff = mine->buffer; - bytes_read = read(mine->fd, mine->buffer, mine->block_size); - if (bytes_read < 0) { - if (mine->filename[0] == '\0') - archive_set_error(a, errno, "Error reading stdin"); - else - archive_set_error(a, errno, "Error reading '%s'", - mine->filename); - } - return (bytes_read); + struct read_file_data *mine = (struct read_file_data *)client_data; + ssize_t bytes_read; + + /* TODO: If a recent lseek() operation has left us + * mis-aligned, read and return a short block to try to get + * us back in alignment. */ + + /* TODO: Someday, try mmap() here; if that succeeds, give + * the entire file to libarchive as a single block. That + * could be a lot faster than block-by-block manual I/O. */ + + /* TODO: We might be able to improve performance on pipes and + * sockets by setting non-blocking I/O and just accepting + * whatever we get here instead of waiting for a full block + * worth of data. */ + + *buff = mine->buffer; + for (;;) { + bytes_read = read(mine->fd, mine->buffer, mine->block_size); + if (bytes_read < 0) { + if (errno == EINTR) + continue; + else if (mine->filename_type == FNT_STDIN) + archive_set_error(a, errno, + "Error reading stdin"); + else if (mine->filename_type == FNT_MBS) + archive_set_error(a, errno, + "Error reading '%s'", mine->filename.m); + else + archive_set_error(a, errno, + "Error reading '%S'", mine->filename.w); + } + return (bytes_read); + } } -#if ARCHIVE_API_VERSION < 2 -static ssize_t -file_skip(struct archive *a, void *client_data, size_t request) +/* + * Regular files and disk-like block devices can use simple lseek + * without needing to round the request to the block size. + * + * TODO: This can leave future reads mis-aligned. Since we know the + * offset here, we should store it and use it in file_read() above + * to determine whether we should perform a short read to get back + * into alignment. Long series of mis-aligned reads can negatively + * impact disk throughput. (Of course, the performance impact should + * be carefully tested; extra code complexity is only worthwhile if + * it does provide measurable improvement.) + * + * TODO: Be lazy about the actual seek. There are a few pathological + * cases where libarchive makes a bunch of seek requests in a row + * without any intervening reads. This isn't a huge performance + * problem, since the kernel handles seeks lazily already, but + * it would be very slightly faster if we simply remembered the + * seek request here and then actually performed the seek at the + * top of the read callback above. + */ +static int64_t +file_skip_lseek(struct archive *a, void *client_data, int64_t request) +{ + struct read_file_data *mine = (struct read_file_data *)client_data; +#if defined(_WIN32) && !defined(__CYGWIN__) + /* We use _lseeki64() on Windows. */ + int64_t old_offset, new_offset; #else -static off_t -file_skip(struct archive *a, void *client_data, off_t request) + off_t old_offset, new_offset; #endif + + /* We use off_t here because lseek() is declared that way. */ + + /* TODO: Deal with case where off_t isn't 64 bits. + * This shouldn't be a problem on Linux or other POSIX + * systems, since the configuration logic for libarchive + * tries to obtain a 64-bit off_t. It's still an issue + * on Windows, though, so it might suffice to just use + * _lseeki64() on Windows. + */ + if ((old_offset = lseek(mine->fd, 0, SEEK_CUR)) >= 0 && + (new_offset = lseek(mine->fd, request, SEEK_CUR)) >= 0) + return (new_offset - old_offset); + + /* If lseek() fails, don't bother trying again. */ + mine->use_lseek = 0; + + /* Let libarchive recover with read+discard */ + if (errno == ESPIPE) + return (0); + + /* If the input is corrupted or truncated, fail. */ + if (mine->filename_type == FNT_STDIN) + archive_set_error(a, errno, "Error seeking in stdin"); + else if (mine->filename_type == FNT_MBS) + archive_set_error(a, errno, "Error seeking in '%s'", + mine->filename.m); + else + archive_set_error(a, errno, "Error seeking in '%S'", + mine->filename.w); + return (-1); +} + + +/* + * TODO: Implement another file_skip_XXXX that uses MTIO ioctls to + * accelerate operation on tape drives. + */ + +static int64_t +file_skip(struct archive *a, void *client_data, int64_t request) +{ + struct read_file_data *mine = (struct read_file_data *)client_data; + + /* Delegate skip requests. */ + if (mine->use_lseek) + return (file_skip_lseek(a, client_data, request)); + + /* If we can't skip, return 0; libarchive will read+discard instead. */ + return (0); +} + +/* + * TODO: Store the offset and use it in the read callback. + */ +static int64_t +file_seek(struct archive *a, void *client_data, int64_t request, int whence) { - struct read_file_data *mine = (struct read_file_data *)client_data; - off_t old_offset, new_offset; - - if (!mine->can_skip) /* We can't skip, so ... */ - return (0); /* ... skip zero bytes. */ - - /* Reduce request to the next smallest multiple of block_size */ - request = (request / mine->block_size) * mine->block_size; - if (request == 0) - return (0); - - /* - * Hurray for lazy evaluation: if the first lseek fails, the second - * one will not be executed. - */ - if (((old_offset = lseek(mine->fd, 0, SEEK_CUR)) < 0) || - ((new_offset = lseek(mine->fd, request, SEEK_CUR)) < 0)) - { - /* If skip failed once, it will probably fail again. */ - mine->can_skip = 0; - - if (errno == ESPIPE) - { - /* - * Failure to lseek() can be caused by the file - * descriptor pointing to a pipe, socket or FIFO. - * Return 0 here, so the compression layer will use - * read()s instead to advance the file descriptor. - * It's slower of course, but works as well. - */ - return (0); - } - /* - * There's been an error other than ESPIPE. This is most - * likely caused by a programmer error (too large request) - * or a corrupted archive file. - */ - if (mine->filename[0] == '\0') - /* - * Should never get here, since lseek() on stdin ought - * to return an ESPIPE error. - */ - archive_set_error(a, errno, "Error seeking in stdin"); - else - archive_set_error(a, errno, "Error seeking in '%s'", - mine->filename); - return (-1); - } - return (new_offset - old_offset); + struct read_file_data *mine = (struct read_file_data *)client_data; + off_t r; + + /* We use off_t here because lseek() is declared that way. */ + /* See above for notes about when off_t is less than 64 bits. */ + r = lseek(mine->fd, request, whence); + if (r >= 0) + return r; + + /* If the input is corrupted or truncated, fail. */ + if (mine->filename_type == FNT_STDIN) + archive_set_error(a, errno, "Error seeking in stdin"); + else if (mine->filename_type == FNT_MBS) + archive_set_error(a, errno, "Error seeking in '%s'", + mine->filename.m); + else + archive_set_error(a, errno, "Error seeking in '%S'", + mine->filename.w); + return (ARCHIVE_FATAL); } static int file_close(struct archive *a, void *client_data) { - struct read_file_data *mine = (struct read_file_data *)client_data; - - (void)a; /* UNUSED */ - - /* Only flush and close if open succeeded. */ - if (mine->fd >= 0) { - /* - * Sometimes, we should flush the input before closing. - * Regular files: faster to just close without flush. - * Devices: must not flush (user might need to - * read the "next" item on a non-rewind device). - * Pipes and sockets: must flush (otherwise, the - * program feeding the pipe or socket may complain). - * Here, I flush everything except for regular files and - * device nodes. - */ - if (!S_ISREG(mine->st_mode) - && !S_ISCHR(mine->st_mode) - && !S_ISBLK(mine->st_mode)) { - ssize_t bytesRead; - do { - bytesRead = read(mine->fd, mine->buffer, - mine->block_size); - } while (bytesRead > 0); - } - /* If a named file was opened, then it needs to be closed. */ - if (mine->filename[0] != '\0') - close(mine->fd); - } - free(mine->buffer); - free(mine); - return (ARCHIVE_OK); + struct read_file_data *mine = (struct read_file_data *)client_data; + + (void)a; /* UNUSED */ + + /* Only flush and close if open succeeded. */ + if (mine->fd >= 0) { + /* + * Sometimes, we should flush the input before closing. + * Regular files: faster to just close without flush. + * Disk-like devices: Ditto. + * Tapes: must not flush (user might need to + * read the "next" item on a non-rewind device). + * Pipes and sockets: must flush (otherwise, the + * program feeding the pipe or socket may complain). + * Here, I flush everything except for regular files and + * device nodes. + */ + if (!S_ISREG(mine->st_mode) + && !S_ISCHR(mine->st_mode) + && !S_ISBLK(mine->st_mode)) { + ssize_t bytesRead; + do { + bytesRead = read(mine->fd, mine->buffer, + mine->block_size); + } while (bytesRead > 0); + } + /* If a named file was opened, then it needs to be closed. */ + if (mine->filename_type != FNT_STDIN) + close(mine->fd); + } + free(mine->buffer); + free(mine); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c index 6ed3d9126..07940a2ac 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_open_memory.c @@ -41,24 +41,22 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_open_memory.c,v 1.6 2007/07/ */ struct read_memory_data { - unsigned char *buffer; - unsigned char *end; - ssize_t read_size; + unsigned char *start; + unsigned char *p; + unsigned char *end; + ssize_t read_size; }; -static int memory_read_close(struct archive *, void *); -static int memory_read_open(struct archive *, void *); -#if ARCHIVE_API_VERSION < 2 -static ssize_t memory_read_skip(struct archive *, void *, size_t request); -#else -static off_t memory_read_skip(struct archive *, void *, off_t request); -#endif -static ssize_t memory_read(struct archive *, void *, const void **buff); +static int memory_read_close(struct archive *, void *); +static int memory_read_open(struct archive *, void *); +static int64_t memory_read_seek(struct archive *, void *, int64_t offset, int whence); +static int64_t memory_read_skip(struct archive *, void *, int64_t request); +static ssize_t memory_read(struct archive *, void *, const void **buff); int archive_read_open_memory(struct archive *a, void *buff, size_t size) { - return archive_read_open_memory2(a, buff, size, size); + return archive_read_open_memory2(a, buff, size, size); } /* @@ -70,19 +68,24 @@ int archive_read_open_memory2(struct archive *a, void *buff, size_t size, size_t read_size) { - struct read_memory_data *mine; - - mine = (struct read_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buffer = (unsigned char *)buff; - mine->end = mine->buffer + size; - mine->read_size = read_size; - return (archive_read_open2(a, mine, memory_read_open, - memory_read, memory_read_skip, memory_read_close)); + struct read_memory_data *mine; + + mine = (struct read_memory_data *)malloc(sizeof(*mine)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + memset(mine, 0, sizeof(*mine)); + mine->start = mine->p = (unsigned char *)buff; + mine->end = mine->start + size; + mine->read_size = read_size; + archive_read_set_open_callback(a, memory_read_open); + archive_read_set_read_callback(a, memory_read); + archive_read_set_seek_callback(a, memory_read_seek); + archive_read_set_skip_callback(a, memory_read_skip); + archive_read_set_close_callback(a, memory_read_close); + archive_read_set_callback_data(a, mine); + return (archive_read_open1(a)); } /* @@ -91,9 +94,9 @@ archive_read_open_memory2(struct archive *a, void *buff, static int memory_read_open(struct archive *a, void *client_data) { - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + (void)client_data; /* UNUSED */ + return (ARCHIVE_OK); } /* @@ -106,16 +109,16 @@ memory_read_open(struct archive *a, void *client_data) static ssize_t memory_read(struct archive *a, void *client_data, const void **buff) { - struct read_memory_data *mine = (struct read_memory_data *)client_data; - ssize_t size; - - (void)a; /* UNUSED */ - *buff = mine->buffer; - size = mine->end - mine->buffer; - if (size > mine->read_size) - size = mine->read_size; - mine->buffer += size; - return (size); + struct read_memory_data *mine = (struct read_memory_data *)client_data; + ssize_t size; + + (void)a; /* UNUSED */ + *buff = mine->p; + size = mine->end - mine->p; + if (size > mine->read_size) + size = mine->read_size; + mine->p += size; + return (size); } /* @@ -123,24 +126,51 @@ memory_read(struct archive *a, void *client_data, const void **buff) * necessary in order to better exercise internal code when used * as a test harness. */ -#if ARCHIVE_API_VERSION < 2 -static ssize_t -memory_read_skip(struct archive *a, void *client_data, size_t skip) -#else -static off_t -memory_read_skip(struct archive *a, void *client_data, off_t skip) -#endif +static int64_t +memory_read_skip(struct archive *a, void *client_data, int64_t skip) +{ + struct read_memory_data *mine = (struct read_memory_data *)client_data; + + (void)a; /* UNUSED */ + if ((int64_t)skip > (int64_t)(mine->end - mine->p)) + skip = mine->end - mine->p; + /* Round down to block size. */ + skip /= mine->read_size; + skip *= mine->read_size; + mine->p += skip; + return (skip); +} + +/* + * Seeking. + */ +static int64_t +memory_read_seek(struct archive *a, void *client_data, int64_t offset, int whence) { - struct read_memory_data *mine = (struct read_memory_data *)client_data; - - (void)a; /* UNUSED */ - if ((off_t)skip > (off_t)(mine->end - mine->buffer)) - skip = mine->end - mine->buffer; - /* Round down to block size. */ - skip /= mine->read_size; - skip *= mine->read_size; - mine->buffer += skip; - return (skip); + struct read_memory_data *mine = (struct read_memory_data *)client_data; + + switch (whence) { + case SEEK_SET: + mine->p = mine->start + offset; + break; + case SEEK_CUR: + mine->p += offset; + break; + case SEEK_END: + mine->p = mine->end + offset; + break; + default: + return ARCHIVE_FATAL; + } + if (mine->p < mine->start) { + mine->p = mine->start; + return ARCHIVE_FAILED; + } + if (mine->p > mine->end) { + mine->p = mine->end; + return ARCHIVE_FAILED; + } + return (mine->p - mine->start); } /* @@ -149,8 +179,8 @@ memory_read_skip(struct archive *a, void *client_data, off_t skip) static int memory_read_close(struct archive *a, void *client_data) { - struct read_memory_data *mine = (struct read_memory_data *)client_data; - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); + struct read_memory_data *mine = (struct read_memory_data *)client_data; + (void)a; /* UNUSED */ + free(mine); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_private.h b/Utilities/cmlibarchive/libarchive/archive_read_private.h index 3a5e3f2df..76d0b91d9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_read_private.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_read_private.h,v 1.7 2008/12/06 06:45:15 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_read_private.h 201088 2009-12-28 02:18:55Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -30,7 +30,7 @@ #endif #ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED -#define ARCHIVE_READ_PRIVATE_H_INCLUDED +#define ARCHIVE_READ_PRIVATE_H_INCLUDED #include "archive.h" #include "archive_string.h" @@ -42,27 +42,32 @@ struct archive_read_filter; /* * How bidding works for filters: - * * The bid manager reads the first block from the current source. - * * It shows that block to each registered bidder. + * * The bid manager initializes the client-provided reader as the + * first filter. + * * It invokes the bidder for each registered filter with the + * current head filter. + * * The bidders can use archive_read_filter_ahead() to peek ahead + * at the incoming data to compose their bids. * * The bid manager creates a new filter structure for the winning * bidder and gives the winning bidder a chance to initialize it. - * * The new filter becomes the top filter in the archive_read structure - * and we repeat the process. - * This ends only when no bidder provides a non-zero bid. + * * The new filter becomes the new top filter and we repeat the + * process. + * This ends only when no bidder provides a non-zero bid. Then + * we perform a similar dance with the registered format handlers. */ struct archive_read_filter_bidder { - /* Configuration data for the bidder. */ - void *data; - /* Taste the upstream filter to see if we handle this. */ - int (*bid)(struct archive_read_filter_bidder *, - struct archive_read_filter *); - /* Initialize a newly-created filter. */ - int (*init)(struct archive_read_filter *); - /* Set an option for the filter bidder. */ - int (*options)(struct archive_read_filter_bidder *, - const char *key, const char *value); - /* Release the bidder's configuration data. */ - int (*free)(struct archive_read_filter_bidder *); + /* Configuration data for the bidder. */ + void *data; + /* Taste the upstream filter to see if we handle this. */ + int (*bid)(struct archive_read_filter_bidder *, + struct archive_read_filter *); + /* Initialize a newly-created filter. */ + int (*init)(struct archive_read_filter *); + /* Set an option for the filter bidder. */ + int (*options)(struct archive_read_filter_bidder *, + const char *key, const char *value); + /* Release the bidder's configuration data. */ + int (*free)(struct archive_read_filter_bidder *); }; /* @@ -71,35 +76,38 @@ struct archive_read_filter_bidder { * corresponding bidder above. */ struct archive_read_filter { - /* Essentially all filters will need these values, so - * just declare them here. */ - struct archive_read_filter_bidder *bidder; /* My bidder. */ - struct archive_read_filter *upstream; /* Who I read from. */ - struct archive_read *archive; /* Associated archive. */ - /* Return next block. */ - ssize_t (*read)(struct archive_read_filter *, const void **); - /* Skip forward this many bytes. */ - int64_t (*skip)(struct archive_read_filter *self, int64_t request); - /* Close (just this filter) and free(self). */ - int (*close)(struct archive_read_filter *self); - /* My private data. */ - void *data; - - const char *name; - int code; - - /* Used by reblocking logic. */ - char *buffer; - size_t buffer_size; - char *next; /* Current read location. */ - size_t avail; /* Bytes in my buffer. */ - const void *client_buff; /* Client buffer information. */ - size_t client_total; - const char *client_next; - size_t client_avail; - int64_t position; - char end_of_file; - char fatal; + int64_t position; + /* Essentially all filters will need these values, so + * just declare them here. */ + struct archive_read_filter_bidder *bidder; /* My bidder. */ + struct archive_read_filter *upstream; /* Who I read from. */ + struct archive_read *archive; /* Associated archive. */ + /* Return next block. */ + ssize_t (*read)(struct archive_read_filter *, const void **); + /* Skip forward this many bytes. */ + int64_t (*skip)(struct archive_read_filter *self, int64_t request); + /* Seek to an absolute location. */ + int64_t (*seek)(struct archive_read_filter *self, int64_t offset, int whence); + /* Close (just this filter) and free(self). */ + int (*close)(struct archive_read_filter *self); + /* My private data. */ + void *data; + + const char *name; + int code; + + /* Used by reblocking logic. */ + char *buffer; + size_t buffer_size; + char *next; /* Current read location. */ + size_t avail; /* Bytes in my buffer. */ + const void *client_buff; /* Client buffer information. */ + size_t client_total; + const char *client_next; + size_t client_avail; + char end_of_file; + char closed; + char fatal; }; /* @@ -111,89 +119,92 @@ struct archive_read_filter { * so should be deferred at least until libarchive 3.0. */ struct archive_read_client { - archive_read_callback *reader; - archive_skip_callback *skipper; - archive_close_callback *closer; + archive_open_callback *opener; + archive_read_callback *reader; + archive_skip_callback *skipper; + archive_seek_callback *seeker; + archive_close_callback *closer; + void *data; }; struct archive_read { - struct archive archive; - - struct archive_entry *entry; - - /* Dev/ino of the archive being read/written. */ - dev_t skip_file_dev; - ino_t skip_file_ino; - - /* - * Used by archive_read_data() to track blocks and copy - * data to client buffers, filling gaps with zero bytes. - */ - const char *read_data_block; - off_t read_data_offset; - off_t read_data_output_offset; - size_t read_data_remaining; - - /* Callbacks to open/read/write/close client archive stream. */ - struct archive_read_client client; - - /* Registered filter bidders. */ - struct archive_read_filter_bidder bidders[8]; - - /* Last filter in chain */ - struct archive_read_filter *filter; - - /* File offset of beginning of most recently-read header. */ - off_t header_position; - - /* - * Format detection is mostly the same as compression - * detection, with one significant difference: The bidders - * use the read_ahead calls above to examine the stream rather - * than having the supervisor hand them a block of data to - * examine. - */ - - struct archive_format_descriptor { - void *data; - const char *name; - int (*bid)(struct archive_read *); - int (*options)(struct archive_read *, const char *key, - const char *value); - int (*read_header)(struct archive_read *, struct archive_entry *); - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *); - int (*read_data_skip)(struct archive_read *); - int (*cleanup)(struct archive_read *); - } formats[8]; - struct archive_format_descriptor *format; /* Active format. */ - - /* - * Various information needed by archive_extract. - */ - struct extract *extract; - int (*cleanup_archive_extract)(struct archive_read *); + struct archive archive; + + struct archive_entry *entry; + + /* Dev/ino of the archive being read/written. */ + int skip_file_set; + dev_t skip_file_dev; + ino_t skip_file_ino; + + /* + * Used by archive_read_data() to track blocks and copy + * data to client buffers, filling gaps with zero bytes. + */ + const char *read_data_block; + int64_t read_data_offset; + int64_t read_data_output_offset; + size_t read_data_remaining; + + /* Callbacks to open/read/write/close client archive stream. */ + struct archive_read_client client; + + /* Registered filter bidders. */ + struct archive_read_filter_bidder bidders[9]; + + /* Last filter in chain */ + struct archive_read_filter *filter; + + /* File offset of beginning of most recently-read header. */ + int64_t header_position; + + /* + * Format detection is mostly the same as compression + * detection, with one significant difference: The bidders + * use the read_ahead calls above to examine the stream rather + * than having the supervisor hand them a block of data to + * examine. + */ + + struct archive_format_descriptor { + void *data; + const char *name; + int (*bid)(struct archive_read *, int best_bid); + int (*options)(struct archive_read *, const char *key, + const char *value); + int (*read_header)(struct archive_read *, struct archive_entry *); + int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *); + int (*read_data_skip)(struct archive_read *); + int (*cleanup)(struct archive_read *); + } formats[16]; + struct archive_format_descriptor *format; /* Active format. */ + + /* + * Various information needed by archive_extract. + */ + struct extract *extract; + int (*cleanup_archive_extract)(struct archive_read *); }; -int __archive_read_register_format(struct archive_read *a, - void *format_data, - const char *name, - int (*bid)(struct archive_read *), - int (*options)(struct archive_read *, const char *, const char *), - int (*read_header)(struct archive_read *, struct archive_entry *), - int (*read_data)(struct archive_read *, const void **, size_t *, off_t *), - int (*read_data_skip)(struct archive_read *), - int (*cleanup)(struct archive_read *)); +int __archive_read_register_format(struct archive_read *a, + void *format_data, + const char *name, + int (*bid)(struct archive_read *, int), + int (*options)(struct archive_read *, const char *, const char *), + int (*read_header)(struct archive_read *, struct archive_entry *), + int (*read_data)(struct archive_read *, const void **, size_t *, int64_t *), + int (*read_data_skip)(struct archive_read *), + int (*cleanup)(struct archive_read *)); -struct archive_read_filter_bidder - *__archive_read_get_bidder(struct archive_read *a); +int __archive_read_get_bidder(struct archive_read *a, + struct archive_read_filter_bidder **bidder); const void *__archive_read_ahead(struct archive_read *, size_t, ssize_t *); const void *__archive_read_filter_ahead(struct archive_read_filter *, size_t, ssize_t *); -ssize_t __archive_read_consume(struct archive_read *, size_t); -ssize_t __archive_read_filter_consume(struct archive_read_filter *, size_t); -int64_t __archive_read_skip(struct archive_read *, int64_t); -int64_t __archive_read_skip_lenient(struct archive_read *, int64_t); -int64_t __archive_read_filter_skip(struct archive_read_filter *, int64_t); +int64_t __archive_read_seek(struct archive_read*, int64_t, int); +int64_t __archive_read_filter_seek(struct archive_read_filter *, int64_t, int); +int64_t __archive_read_consume(struct archive_read *, int64_t); +int64_t __archive_read_filter_consume(struct archive_read_filter *, int64_t); int __archive_read_program(struct archive_read_filter *, const char *); #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_read_set_options.3 new file mode 100644 index 000000000..81efb08b5 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_set_options.3 @@ -0,0 +1,207 @@ +.\" Copyright (c) 2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd April 13, 2009 +.Dt ARCHIVE_READ_OPTIONS 3 +.Os +.Sh NAME +.Nm archive_read_set_filter_option , +.Nm archive_read_set_format_option , +.Nm archive_read_set_option , +.Nm archive_read_set_options +.Nd functions controlling options for reading archives +.\" +.Sh SYNOPSIS +.Ft int +.Fo archive_read_set_filter_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_read_set_format_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_read_set_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_read_set_options +.Fa "struct archive *" +.Fa "const char *options" +.Fc +.Sh DESCRIPTION +These functions provide a way for libarchive clients to configure +specific read modules. +.Bl -tag -width indent +.It Xo +.Fn archive_read_set_filter_option , +.Fn archive_read_set_format_option +.Xc +Specifies an option that will be passed to currently-registered +filters (including decompression filters) or format readers. +.Pp +If +.Ar option +and +.Ar value +are both +.Dv NULL , +these functions will do nothing and +.Cm ARCHIVE_OK +will be returned. +If +.Ar option +is +.Dv NULL +but +.Ar value +is not, these functions will do nothing and +.Cm ARCHIVE_FAILED +will be returned. +.Pp +If +.Ar module +is not +.Dv NULL , +.Ar option +and +.Ar value +will be provided to the filter or reader named +.Ar module . +The return value will be that of the module. +If there is no such module, +.Cm ARCHIVE_FAILED +will be returned. +.Pp +If +.Ar module +is +.Dv NULL , +.Ar option +and +.Ar value +will be provided to every registered module. +If any module returns +.Cm ARCHIVE_FATAL , +this value will be returned immediately. +Otherwise, +.Cm ARCHIVE_OK +will be returned if any module accepts the option, and +.Cm ARCHIVE_FAILED +in all other cases. +.\" +.It Xo +.Fn archive_read_set_option +.Xc +Calls +.Fn archive_read_set_format_option , +then +.Fn archive_read_set_filter_option . +If either function returns +.Cm ARCHIVE_FATAL , +.Cm ARCHIVE_FATAL +will be returned +immediately. +Otherwise, greater of the two values will be returned. +.\" +.It Xo +.Fn archive_read_set_options +.Xc +.Ar options +is a comma-separated list of options. +If +.Ar options +is +.Dv NULL +or empty, +.Cm ARCHIVE_OK +will be returned immediately. +.Pp +Calls +.Fn archive_read_set_option +with each option in turn. +If any +.Fn archive_read_set_option +call returns +.Cm ARCHIVE_FATAL , +.Cm ARCHIVE_FATAL +will be returned immediately. +.Pp +Individual options have one of the following forms: +.Bl -tag -compact -width indent +.It Ar option=value +The option/value pair will be provided to every module. +Modules that do not accept an option with this name will ignore it. +.It Ar option +The option will be provided to every module with a value of +.Dq 1 . +.It Ar !option +The option will be provided to every module with a NULL value. +.It Ar module:option=value , Ar module:option , Ar module:!option +As above, but the corresponding option and value will be provided +only to modules whose name matches +.Ar module . +.El +.El +.\" +.Sh OPTIONS +.Bl -tag -compact -width indent +.It Format iso9660 +.Bl -tag -compact -width indent +.It Cm joliet +Support Joliet extensions. +Defaults to enabled, use +.Cm !joliet +to disable. +.It Cm rockridge +Support RockRidge extensions. +Defaults to enabled, use +.Cm !rockridge +to disable. +.El +.El +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_set_options 3 , +.Xr archive_read 3 diff --git a/Utilities/cmlibarchive/libarchive/archive_read_set_options.c b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c new file mode 100644 index 000000000..d6a5f45cc --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_set_options.c @@ -0,0 +1,148 @@ +/*- + * Copyright (c) 2011 Tim Kientzle + * 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_read_private.h" +#include "archive_options_private.h" + +static int archive_set_format_option(struct archive *a, + const char *m, const char *o, const char *v); +static int archive_set_filter_option(struct archive *a, + const char *m, const char *o, const char *v); +static int archive_set_option(struct archive *a, + const char *m, const char *o, const char *v); + +int +archive_read_set_format_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_READ_MAGIC, "archive_read_set_format_option", + archive_set_format_option); +} + +int +archive_read_set_filter_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_READ_MAGIC, "archive_read_set_filter_option", + archive_set_filter_option); +} + +int +archive_read_set_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_READ_MAGIC, "archive_read_set_option", + archive_set_option); +} + +int +archive_read_set_options(struct archive *a, const char *options) +{ + return _archive_set_options(a, options, + ARCHIVE_READ_MAGIC, "archive_read_set_options", + archive_set_option); +} + +static int +archive_set_format_option(struct archive *_a, const char *m, const char *o, + const char *v) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_format_descriptor *format; + size_t i; + int r, rv = ARCHIVE_FAILED; + + for (i = 0; i < sizeof(a->formats)/sizeof(a->formats[0]); i++) { + format = &a->formats[i]; + if (format == NULL || format->options == NULL || + format->name == NULL) + /* This format does not support option. */ + continue; + if (m != NULL && strcmp(format->name, m) != 0) + continue; + + a->format = format; + r = format->options(a, o, v); + a->format = NULL; + + if (r == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + if (m != NULL) + return (r); + + if (r == ARCHIVE_OK) + rv = ARCHIVE_OK; + } + return (rv); +} + +static int +archive_set_filter_option(struct archive *_a, const char *m, const char *o, + const char *v) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter *filter; + struct archive_read_filter_bidder *bidder; + int r, rv = ARCHIVE_FAILED; + + for (filter = a->filter; filter != NULL; filter = filter->upstream) { + bidder = filter->bidder; + if (bidder == NULL) + continue; + if (bidder->options == NULL) + /* This bidder does not support option */ + continue; + if (m != NULL && strcmp(filter->name, m) != 0) + continue; + + r = bidder->options(bidder, o, v); + + if (r == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + if (m != NULL) + return (r); + + if (r == ARCHIVE_OK) + rv = ARCHIVE_OK; + } + return (rv); +} + +static int +archive_set_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_either_option(a, m, o, v, + archive_set_format_option, + archive_set_filter_option); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_all.c deleted file mode 100644 index 9105e0670..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_all.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_read_support_compression_all.c,v 1.7 2008/12/06 06:45:15 kientzle Exp $"); - -#include "archive.h" - -int -archive_read_support_compression_all(struct archive *a) -{ - /* Bzip falls back to "bunzip2" command-line */ - archive_read_support_compression_bzip2(a); - /* The decompress code doesn't use an outside library. */ - archive_read_support_compression_compress(a); - /* Gzip decompress falls back to "gunzip" command-line. */ - archive_read_support_compression_gzip(a); - /* The LZMA file format has a very weak signature, so it - * may not be feasible to keep this here, but we'll try. - * This will come back out if there are problems. */ - /* Lzma falls back to "unlzma" command-line program. */ - archive_read_support_compression_lzma(a); - /* Xz falls back to "unxz" command-line program. */ - archive_read_support_compression_xz(a); - - /* Note: We always return ARCHIVE_OK here, even if some of the - * above return ARCHIVE_WARN. The intent here is to enable - * "as much as possible." Clients who need specific - * compression should enable those individually so they can - * verify the level of support. */ - /* Clear any warning messages set by the above functions. */ - archive_clear_error(a); - return (ARCHIVE_OK); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_bzip2.c deleted file mode 100644 index 8726fb34e..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_bzip2.c +++ /dev/null @@ -1,354 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_read_support_compression_bzip2.c,v 1.19 2008/12/06 06:45:15 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_BZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#if HAVE_BZLIB_H -struct private_data { - bz_stream stream; - char *out_block; - size_t out_block_size; - char valid; /* True = decompressor is initialized */ - char eof; /* True = found end of compressed data. */ -}; - -/* Bzip2 filter */ -static ssize_t bzip2_filter_read(struct archive_read_filter *, const void **); -static int bzip2_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect bzip2 archives even if we can't decompress - * them. (In fact, we like detecting them because we can give better - * error messages.) So the bid framework here gets compiled even - * if bzlib is unavailable. - */ -static int bzip2_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); -static int bzip2_reader_init(struct archive_read_filter *); -static int bzip2_reader_free(struct archive_read_filter_bidder *); - -int -archive_read_support_compression_bzip2(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *reader = __archive_read_get_bidder(a); - - if (reader == NULL) - return (ARCHIVE_FATAL); - - reader->data = NULL; - reader->bid = bzip2_reader_bid; - reader->init = bzip2_reader_init; - reader->options = NULL; - reader->free = bzip2_reader_free; -#if HAVE_BZLIB_H - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external bunzip2 program"); - return (ARCHIVE_WARN); -#endif -} - -static int -bzip2_reader_free(struct archive_read_filter_bidder *self){ - (void)self; /* UNUSED */ - return (ARCHIVE_OK); -} - -/* - * Test whether we can handle this data. - * - * This logic returns zero if any part of the signature fails. It - * also tries to Do The Right Thing if a very short buffer prevents us - * from verifying as much as we would like. - */ -static int -bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - /* Minimal bzip2 archive is 14 bytes. */ - buffer = __archive_read_filter_ahead(filter, 14, &avail); - if (buffer == NULL) - return (0); - - /* First three bytes must be "BZh" */ - bits_checked = 0; - if (buffer[0] != 'B' || buffer[1] != 'Z' || buffer[2] != 'h') - return (0); - bits_checked += 24; - - /* Next follows a compression flag which must be an ASCII digit. */ - if (buffer[3] < '1' || buffer[3] > '9') - return (0); - bits_checked += 5; - - /* After BZh[1-9], there must be either a data block - * which begins with 0x314159265359 or an end-of-data - * marker of 0x177245385090. */ - if (memcmp(buffer + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0) - bits_checked += 48; - else if (memcmp(buffer + 4, "\x17\x72\x45\x38\x50\x90", 6) == 0) - bits_checked += 48; - else - return (0); - - return (bits_checked); -} - -#ifndef HAVE_BZLIB_H - -/* - * If we don't have the library on this system, we can't actually do the - * decompression. We can, however, still detect compressed archives - * and emit a useful message. - */ -static int -bzip2_reader_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "bunzip2"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_BZIP2; - self->name = "bzip2"; - return (r); -} - - -#else - -/* - * Setup the callbacks. - */ -static int -bzip2_reader_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - - self->code = ARCHIVE_COMPRESSION_BZIP2; - self->name = "bzip2"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (self == NULL || state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for bzip2 decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = bzip2_filter_read; - self->skip = NULL; /* not supported */ - self->close = bzip2_filter_close; - - return (ARCHIVE_OK); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -bzip2_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t read_avail, decompressed; - const char *read_buf; - ssize_t ret; - - state = (struct private_data *)self->data; - read_avail = 0; - - if (state->eof) { - *p = NULL; - return (0); - } - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - for (;;) { - if (!state->valid) { - if (bzip2_reader_bid(self->bidder, self->upstream) == 0) { - state->eof = 1; - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - /* Initialize compression library. */ - ret = BZ2_bzDecompressInit(&(state->stream), - 0 /* library verbosity */, - 0 /* don't use low-mem algorithm */); - - /* If init fails, try low-memory algorithm instead. */ - if (ret == BZ_MEM_ERROR) - ret = BZ2_bzDecompressInit(&(state->stream), - 0 /* library verbosity */, - 1 /* do use low-mem algo */); - - if (ret != BZ_OK) { - const char *detail = NULL; - int err = ARCHIVE_ERRNO_MISC; - switch (ret) { - case BZ_PARAM_ERROR: - detail = "invalid setup parameter"; - break; - case BZ_MEM_ERROR: - err = ENOMEM; - detail = "out of memory"; - break; - case BZ_CONFIG_ERROR: - detail = "mis-compiled library"; - break; - } - archive_set_error(&self->archive->archive, err, - "Internal error initializing decompressor%s%s", - detail == NULL ? "" : ": ", - detail); - return (ARCHIVE_FATAL); - } - state->valid = 1; - } - - /* stream.next_in is really const, but bzlib - * doesn't declare it so. */ - read_buf = - __archive_read_filter_ahead(self->upstream, 1, &ret); - if (read_buf == NULL) - return (ARCHIVE_FATAL); - state->stream.next_in = (char *)(uintptr_t)read_buf; - state->stream.avail_in = ret; - /* There is no more data, return whatever we have. */ - if (ret == 0) { - state->eof = 1; - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - - /* Decompress as much as we can in one pass. */ - ret = BZ2_bzDecompress(&(state->stream)); - __archive_read_filter_consume(self->upstream, - state->stream.next_in - read_buf); - - switch (ret) { - case BZ_STREAM_END: /* Found end of stream. */ - switch (BZ2_bzDecompressEnd(&(state->stream))) { - case BZ_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up decompressor"); - return (ARCHIVE_FATAL); - } - state->valid = 0; - /* FALLTHROUGH */ - case BZ_OK: /* Decompressor made some progress. */ - /* If we filled our buffer, update stats and return. */ - if (state->stream.avail_out == 0) { - *p = state->out_block; - decompressed = state->stream.next_out - - state->out_block; - return (decompressed); - } - break; - default: /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, "bzip decompression failed"); - return (ARCHIVE_FATAL); - } - } -} - -/* - * Clean up the decompressor. - */ -static int -bzip2_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret = ARCHIVE_OK; - - state = (struct private_data *)self->data; - - if (state->valid) { - switch (BZ2_bzDecompressEnd(&state->stream)) { - case BZ_OK: - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up decompressor"); - ret = ARCHIVE_FATAL; - } - } - - free(state->out_block); - free(state); - return (ARCHIVE_OK); -} - -#endif /* HAVE_BZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_compress.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_compress.c deleted file mode 100644 index 4be4cbe0f..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_compress.c +++ /dev/null @@ -1,444 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - */ - -/* - * This code borrows heavily from "compress" source code, which is - * protected by the following copyright. (Clause 3 dropped by request - * of the Regents.) - */ - -/*- - * Copyright (c) 1985, 1986, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Diomidis Spinellis and James A. Woods, derived from original - * work by Spencer Thomas and Joseph Orost. - * - * 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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_compression_compress.c,v 1.11 2008/12/06 06:45:15 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -/* - * Because LZW decompression is pretty simple, I've just implemented - * the whole decompressor here (cribbing from "compress" source code, - * of course), rather than relying on an external library. I have - * made an effort to clarify and simplify the algorithm, so the - * names and structure here don't exactly match those used by compress. - */ - -struct private_data { - /* Input variables. */ - const unsigned char *next_in; - size_t avail_in; - int bit_buffer; - int bits_avail; - size_t bytes_in_section; - - /* Output variables. */ - size_t out_block_size; - void *out_block; - - /* Decompression status variables. */ - int use_reset_code; - int end_of_stream; /* EOF status. */ - int maxcode; /* Largest code. */ - int maxcode_bits; /* Length of largest code. */ - int section_end_code; /* When to increase bits. */ - int bits; /* Current code length. */ - int oldcode; /* Previous code. */ - int finbyte; /* Last byte of prev code. */ - - /* Dictionary. */ - int free_ent; /* Next dictionary entry. */ - unsigned char suffix[65536]; - uint16_t prefix[65536]; - - /* - * Scratch area for expanding dictionary entries. Note: - * "worst" case here comes from compressing /dev/zero: the - * last code in the dictionary will code a sequence of - * 65536-256 zero bytes. Thus, we need stack space to expand - * a 65280-byte dictionary entry. (Of course, 32640:1 - * compression could also be considered the "best" case. ;-) - */ - unsigned char *stackp; - unsigned char stack[65300]; -}; - -static int compress_bidder_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); -static int compress_bidder_init(struct archive_read_filter *); -static int compress_bidder_free(struct archive_read_filter_bidder *); - -static ssize_t compress_filter_read(struct archive_read_filter *, const void **); -static int compress_filter_close(struct archive_read_filter *); - -static int getbits(struct archive_read_filter *, int n); -static int next_code(struct archive_read_filter *); - -int -archive_read_support_compression_compress(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = compress_bidder_bid; - bidder->init = compress_bidder_init; - bidder->options = NULL; - bidder->free = compress_bidder_free; - return (ARCHIVE_OK); -} - -/* - * Test whether we can handle this data. - * - * This logic returns zero if any part of the signature fails. It - * also tries to Do The Right Thing if a very short buffer prevents us - * from verifying as much as we would like. - */ -static int -compress_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 2, &avail); - - if (buffer == NULL) - return (0); - - bits_checked = 0; - if (buffer[0] != 037) /* Verify first ID byte. */ - return (0); - bits_checked += 8; - - if (buffer[1] != 0235) /* Verify second ID byte. */ - return (0); - bits_checked += 8; - - /* - * TODO: Verify more. - */ - - return (bits_checked); -} - -/* - * Setup the callbacks. - */ -static int -compress_bidder_init(struct archive_read_filter *self) -{ - struct private_data *state; - static const size_t out_block_size = 64 * 1024; - void *out_block; - int code; - - self->code = ARCHIVE_COMPRESSION_COMPRESS; - self->name = "compress (.Z)"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = malloc(out_block_size); - if (state == NULL || out_block == NULL) { - free(out_block); - free(state); - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for %s decompression", - self->name); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = compress_filter_read; - self->skip = NULL; /* not supported */ - self->close = compress_filter_close; - - /* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */ - - code = getbits(self, 8); /* Skip first signature byte. */ - code = getbits(self, 8); /* Skip second signature byte. */ - - code = getbits(self, 8); - state->maxcode_bits = code & 0x1f; - state->maxcode = (1 << state->maxcode_bits); - state->use_reset_code = code & 0x80; - - /* Initialize decompressor. */ - state->free_ent = 256; - state->stackp = state->stack; - if (state->use_reset_code) - state->free_ent++; - state->bits = 9; - state->section_end_code = (1<bits) - 1; - state->oldcode = -1; - for (code = 255; code >= 0; code--) { - state->prefix[code] = 0; - state->suffix[code] = code; - } - next_code(self); - - return (ARCHIVE_OK); -} - -/* - * Return a block of data from the decompression buffer. Decompress more - * as necessary. - */ -static ssize_t -compress_filter_read(struct archive_read_filter *self, const void **pblock) -{ - struct private_data *state; - unsigned char *p, *start, *end; - int ret; - - state = (struct private_data *)self->data; - if (state->end_of_stream) { - *pblock = NULL; - return (0); - } - p = start = (unsigned char *)state->out_block; - end = start + state->out_block_size; - - while (p < end && !state->end_of_stream) { - if (state->stackp > state->stack) { - *p++ = *--state->stackp; - } else { - ret = next_code(self); - if (ret == -1) - state->end_of_stream = ret; - else if (ret != ARCHIVE_OK) - return (ret); - } - } - - *pblock = start; - return (p - start); -} - -/* - * Clean up the reader. - */ -static int -compress_bidder_free(struct archive_read_filter_bidder *self) -{ - self->data = NULL; - return (ARCHIVE_OK); -} - -/* - * Close and release the filter. - */ -static int -compress_filter_close(struct archive_read_filter *self) -{ - struct private_data *state = (struct private_data *)self->data; - - free(state->out_block); - free(state); - return (ARCHIVE_OK); -} - -/* - * Process the next code and fill the stack with the expansion - * of the code. Returns ARCHIVE_FATAL if there is a fatal I/O or - * format error, ARCHIVE_EOF if we hit end of data, ARCHIVE_OK otherwise. - */ -static int -next_code(struct archive_read_filter *self) -{ - struct private_data *state = (struct private_data *)self->data; - int code, newcode; - - static int debug_buff[1024]; - static unsigned debug_index; - - code = newcode = getbits(self, state->bits); - if (code < 0) - return (code); - - debug_buff[debug_index++] = code; - if (debug_index >= sizeof(debug_buff)/sizeof(debug_buff[0])) - debug_index = 0; - - /* If it's a reset code, reset the dictionary. */ - if ((code == 256) && state->use_reset_code) { - /* - * The original 'compress' implementation blocked its - * I/O in a manner that resulted in junk bytes being - * inserted after every reset. The next section skips - * this junk. (Yes, the number of *bytes* to skip is - * a function of the current *bit* length.) - */ - int skip_bytes = state->bits - - (state->bytes_in_section % state->bits); - skip_bytes %= state->bits; - state->bits_avail = 0; /* Discard rest of this byte. */ - while (skip_bytes-- > 0) { - code = getbits(self, 8); - if (code < 0) - return (code); - } - /* Now, actually do the reset. */ - state->bytes_in_section = 0; - state->bits = 9; - state->section_end_code = (1 << state->bits) - 1; - state->free_ent = 257; - state->oldcode = -1; - return (next_code(self)); - } - - if (code > state->free_ent) { - /* An invalid code is a fatal error. */ - archive_set_error(&(self->archive->archive), -1, - "Invalid compressed data"); - return (ARCHIVE_FATAL); - } - - /* Special case for KwKwK string. */ - if (code >= state->free_ent) { - *state->stackp++ = state->finbyte; - code = state->oldcode; - } - - /* Generate output characters in reverse order. */ - while (code >= 256) { - *state->stackp++ = state->suffix[code]; - code = state->prefix[code]; - } - *state->stackp++ = state->finbyte = code; - - /* Generate the new entry. */ - code = state->free_ent; - if (code < state->maxcode && state->oldcode >= 0) { - state->prefix[code] = state->oldcode; - state->suffix[code] = state->finbyte; - ++state->free_ent; - } - if (state->free_ent > state->section_end_code) { - state->bits++; - state->bytes_in_section = 0; - if (state->bits == state->maxcode_bits) - state->section_end_code = state->maxcode; - else - state->section_end_code = (1 << state->bits) - 1; - } - - /* Remember previous code. */ - state->oldcode = newcode; - return (ARCHIVE_OK); -} - -/* - * Return next 'n' bits from stream. - * - * -1 indicates end of available data. - */ -static int -getbits(struct archive_read_filter *self, int n) -{ - struct private_data *state = (struct private_data *)self->data; - int code; - ssize_t ret; - static const int mask[] = { - 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, - 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff - }; - - while (state->bits_avail < n) { - if (state->avail_in <= 0) { - state->next_in - = __archive_read_filter_ahead(self->upstream, - 1, &ret); - if (ret == 0) - return (-1); - if (ret < 0 || state->next_in == NULL) - return (ARCHIVE_FATAL); - state->avail_in = ret; - __archive_read_filter_consume(self->upstream, ret); - } - state->bit_buffer |= *state->next_in++ << state->bits_avail; - state->avail_in--; - state->bits_avail += 8; - state->bytes_in_section++; - } - - code = state->bit_buffer; - state->bit_buffer >>= n; - state->bits_avail -= n; - - return (code & mask[n]); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_gzip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_gzip.c deleted file mode 100644 index 5424b9619..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_gzip.c +++ /dev/null @@ -1,463 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_read_support_compression_gzip.c,v 1.17 2008/12/06 06:45:15 kientzle Exp $"); - - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#ifdef HAVE_ZLIB_H -struct private_data { - z_stream stream; - char in_stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - unsigned long crc; - char eof; /* True = found end of compressed data. */ -}; - -/* Gzip Filter. */ -static ssize_t gzip_filter_read(struct archive_read_filter *, const void **); -static int gzip_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect gzip archives even if we can't decompress - * them. (In fact, we like detecting them because we can give better - * error messages.) So the bid framework here gets compiled even - * if zlib is unavailable. - * - * TODO: If zlib is unavailable, gzip_bidder_init() should - * use the compress_program framework to try to fire up an external - * gunzip program. - */ -static int gzip_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int gzip_bidder_init(struct archive_read_filter *); - -int -archive_read_support_compression_gzip(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = gzip_bidder_bid; - bidder->init = gzip_bidder_init; - bidder->options = NULL; - bidder->free = NULL; /* No data, so no cleanup necessary. */ - /* Signal the extent of gzip support with the return value here. */ -#if HAVE_ZLIB_H - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external gunzip program"); - return (ARCHIVE_WARN); -#endif -} - -/* - * Read and verify the header. - * - * Returns zero if the header couldn't be validated, else returns - * number of bytes in header. If pbits is non-NULL, it receives a - * count of bits verified, suitable for use by bidder. - */ -static int -peek_at_header(struct archive_read_filter *filter, int *pbits) -{ - const unsigned char *p; - ssize_t avail, len; - int bits = 0; - int header_flags; - - /* Start by looking at the first ten bytes of the header, which - * is all fixed layout. */ - len = 10; - p = __archive_read_filter_ahead(filter, len, &avail); - if (p == NULL || avail == 0) - return (0); - if (p[0] != 037) - return (0); - bits += 8; - if (p[1] != 0213) - return (0); - bits += 8; - if (p[2] != 8) /* We only support deflation. */ - return (0); - bits += 8; - if ((p[3] & 0xE0)!= 0) /* No reserved flags set. */ - return (0); - bits += 3; - header_flags = p[3]; - /* Bytes 4-7 are mod time. */ - /* Byte 8 is deflate flags. */ - /* XXXX TODO: return deflate flags back to consume_header for use - in initializing the decompressor. */ - /* Byte 9 is OS. */ - - /* Optional extra data: 2 byte length plus variable body. */ - if (header_flags & 4) { - p = __archive_read_filter_ahead(filter, len + 2, &avail); - if (p == NULL) - return (0); - len += ((int)p[len + 1] << 8) | (int)p[len]; - len += 2; - } - - /* Null-terminated optional filename. */ - if (header_flags & 8) { - do { - ++len; - if (avail < len) - p = __archive_read_filter_ahead(filter, - len, &avail); - if (p == NULL) - return (0); - } while (p[len - 1] != 0); - } - - /* Null-terminated optional comment. */ - if (header_flags & 16) { - do { - ++len; - if (avail < len) - p = __archive_read_filter_ahead(filter, - len, &avail); - if (p == NULL) - return (0); - } while (p[len - 1] != 0); - } - - /* Optional header CRC */ - if ((header_flags & 2)) { - p = __archive_read_filter_ahead(filter, len + 2, &avail); - if (p == NULL) - return (0); -#if 0 - int hcrc = ((int)p[len + 1] << 8) | (int)p[len]; - int crc = /* XXX TODO: Compute header CRC. */; - if (crc != hcrc) - return (0); - bits += 16; -#endif - len += 2; - } - - if (pbits != NULL) - *pbits = bits; - return (len); -} - -/* - * Bidder just verifies the header and returns the number of verified bits. - */ -static int -gzip_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - int bits_checked; - - (void)self; /* UNUSED */ - - if (peek_at_header(filter, &bits_checked)) - return (bits_checked); - return (0); -} - - -#ifndef HAVE_ZLIB_H - -/* - * If we don't have the library on this system, we can't do the - * decompression directly. We can, however, try to run gunzip - * in case that's available. - */ -static int -gzip_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "gunzip"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_GZIP; - self->name = "gzip"; - return (r); -} - -#else - -/* - * Initialize the filter object. - */ -static int -gzip_bidder_init(struct archive_read_filter *self) -{ - struct private_data *state; - static const size_t out_block_size = 64 * 1024; - void *out_block; - - self->code = ARCHIVE_COMPRESSION_GZIP; - self->name = "gzip"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - free(out_block); - free(state); - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for gzip decompression"); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = gzip_filter_read; - self->skip = NULL; /* not supported */ - self->close = gzip_filter_close; - - state->in_stream = 0; /* We're not actually within a stream yet. */ - - return (ARCHIVE_OK); -} - -static int -consume_header(struct archive_read_filter *self) -{ - struct private_data *state; - ssize_t avail; - size_t len; - int ret; - - state = (struct private_data *)self->data; - - /* If this is a real header, consume it. */ - len = peek_at_header(self->upstream, NULL); - if (len == 0) - return (ARCHIVE_EOF); - __archive_read_filter_consume(self->upstream, len); - - /* Initialize CRC accumulator. */ - state->crc = crc32(0L, NULL, 0); - - /* Initialize compression library. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail); - state->stream.avail_in = avail; - ret = inflateInit2(&(state->stream), - -15 /* Don't check for zlib header */); - - /* Decipher the error code. */ - switch (ret) { - case Z_OK: - state->in_stream = 1; - return (ARCHIVE_OK); - case Z_STREAM_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid setup parameter"); - break; - case Z_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - case Z_VERSION_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid library version"); - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - " Zlib error %d", ret); - break; - } - return (ARCHIVE_FATAL); -} - -static int -consume_trailer(struct archive_read_filter *self) -{ - struct private_data *state; - const unsigned char *p; - ssize_t avail; - - state = (struct private_data *)self->data; - - state->in_stream = 0; - switch (inflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Failed to clean up gzip decompressor"); - return (ARCHIVE_FATAL); - } - - /* GZip trailer is a fixed 8 byte structure. */ - p = __archive_read_filter_ahead(self->upstream, 8, &avail); - if (p == NULL || avail == 0) - return (ARCHIVE_FATAL); - - /* XXX TODO: Verify the length and CRC. */ - - /* We've verified the trailer, so consume it now. */ - __archive_read_filter_consume(self->upstream, 8); - - return (ARCHIVE_OK); -} - -static ssize_t -gzip_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in; - int ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - /* If we're not in a stream, read a header - * and initialize the decompression library. */ - if (!state->in_stream) { - ret = consume_header(self); - if (ret == ARCHIVE_EOF) { - state->eof = 1; - break; - } - if (ret < ARCHIVE_OK) - return (ret); - } - - /* Peek at the next available data. */ - /* ZLib treats stream.next_in as const but doesn't declare - * it so, hence this ugly cast. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress and consume some of that data. */ - ret = inflate(&(state->stream), 0); - switch (ret) { - case Z_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case Z_STREAM_END: /* Found end of stream. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - /* Consume the stream trailer; release the - * decompression library. */ - ret = consume_trailer(self); - break; - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "gzip decompression failed"); - return (ARCHIVE_FATAL); - } - } - - /* We've read as much as we can. */ - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -gzip_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)self->data; - ret = ARCHIVE_OK; - - if (state->in_stream) { - switch (inflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up gzip compressor"); - ret = ARCHIVE_FATAL; - } - } - - free(state->out_block); - free(state); - return (ret); -} - -#endif /* HAVE_ZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_program.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_program.c deleted file mode 100644 index f58e51805..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_program.c +++ /dev/null @@ -1,457 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * 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: src/lib/libarchive/archive_read_support_compression_program.c,v 1.6 2008/12/06 06:45:15 kientzle Exp $"); - -#ifdef HAVE_SYS_WAIT_H -# include -#endif -#ifdef HAVE_ERRNO_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_LIMITS_H -# include -#endif -#ifdef HAVE_SIGNAL_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -int -archive_read_support_compression_program(struct archive *a, const char *cmd) -{ - return (archive_read_support_compression_program_signature(a, cmd, NULL, 0)); -} - - -/* This capability is only available on POSIX systems. */ -#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ - !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) - -/* - * On non-Posix systems, allow the program to build, but choke if - * this function is actually invoked. - */ -int -archive_read_support_compression_program_signature(struct archive *_a, - const char *cmd, const void *signature, size_t signature_len) -{ - (void)_a; /* UNUSED */ - (void)cmd; /* UNUSED */ - (void)signature; /* UNUSED */ - (void)signature_len; /* UNUSED */ - - archive_set_error(_a, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -int -__archive_read_program(struct archive_read_filter *self, const char *cmd) -{ - (void)self; /* UNUSED */ - (void)cmd; /* UNUSED */ - - archive_set_error(&self->archive->archive, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -#else - -#include "filter_fork.h" - -/* - * The bidder object stores the command and the signature to watch for. - * The 'inhibit' entry here is used to ensure that unchecked filters never - * bid twice in the same pipeline. - */ -struct program_bidder { - char *cmd; - void *signature; - size_t signature_len; - int inhibit; -}; - -static int program_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *upstream); -static int program_bidder_init(struct archive_read_filter *); -static int program_bidder_free(struct archive_read_filter_bidder *); - -/* - * The actual filter needs to track input and output data. - */ -struct program_filter { - char *description; - pid_t child; - int exit_status; - int waitpid_return; - int child_stdin, child_stdout; - - char *out_buf; - size_t out_buf_len; -}; - -static ssize_t program_filter_read(struct archive_read_filter *, - const void **); -static int program_filter_close(struct archive_read_filter *); - -int -archive_read_support_compression_program_signature(struct archive *_a, - const char *cmd, const void *signature, size_t signature_len) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder; - struct program_bidder *state; - - /* - * Get a bidder object from the read core. - */ - bidder = __archive_read_get_bidder(a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - /* - * Allocate our private state. - */ - state = (struct program_bidder *)calloc(sizeof (*state), 1); - if (state == NULL) - return (ARCHIVE_FATAL); - state->cmd = strdup(cmd); - if (signature != NULL && signature_len > 0) { - state->signature_len = signature_len; - state->signature = malloc(signature_len); - memcpy(state->signature, signature, signature_len); - } - - /* - * Fill in the bidder object. - */ - bidder->data = state; - bidder->bid = program_bidder_bid; - bidder->init = program_bidder_init; - bidder->options = NULL; - bidder->free = program_bidder_free; - return (ARCHIVE_OK); -} - -static int -program_bidder_free(struct archive_read_filter_bidder *self) -{ - struct program_bidder *state = (struct program_bidder *)self->data; - free(state->cmd); - free(state->signature); - free(self->data); - return (ARCHIVE_OK); -} - -/* - * If we do have a signature, bid only if that matches. - * - * If there's no signature, we bid INT_MAX the first time - * we're called, then never bid again. - */ -static int -program_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *upstream) -{ - struct program_bidder *state = self->data; - const char *p; - - /* If we have a signature, use that to match. */ - if (state->signature_len > 0) { - p = __archive_read_filter_ahead(upstream, - state->signature_len, NULL); - if (p == NULL) - return (0); - /* No match, so don't bid. */ - if (memcmp(p, state->signature, state->signature_len) != 0) - return (0); - return (state->signature_len * 8); - } - - /* Otherwise, bid once and then never bid again. */ - if (state->inhibit) - return (0); - state->inhibit = 1; - return (INT_MAX); -} - -/* - * Shut down the child, return ARCHIVE_OK if it exited normally. - * - * Note that the return value is sticky; if we're called again, - * we won't reap the child again, but we will return the same status - * (including error message if the child came to a bad end). - */ -static int -child_stop(struct archive_read_filter *self, struct program_filter *state) -{ - /* Close our side of the I/O with the child. */ - if (state->child_stdin != -1) { - close(state->child_stdin); - state->child_stdin = -1; - } - if (state->child_stdout != -1) { - close(state->child_stdout); - state->child_stdout = -1; - } - - if (state->child != 0) { - /* Reap the child. */ - do { - state->waitpid_return - = waitpid(state->child, &state->exit_status, 0); - } while (state->waitpid_return == -1 && errno == EINTR); - state->child = 0; - } - - if (state->waitpid_return < 0) { - /* waitpid() failed? This is ugly. */ - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Child process exited badly"); - return (ARCHIVE_WARN); - } - - if (WIFSIGNALED(state->exit_status)) { -#ifdef SIGPIPE - /* If the child died because we stopped reading before - * it was done, that's okay. Some archive formats - * have padding at the end that we routinely ignore. */ - /* The alternative to this would be to add a step - * before close(child_stdout) above to read from the - * child until the child has no more to write. */ - if (WTERMSIG(state->exit_status) == SIGPIPE) - return (ARCHIVE_OK); -#endif - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Child process exited with signal %d", - WTERMSIG(state->exit_status)); - return (ARCHIVE_WARN); - } - - if (WIFEXITED(state->exit_status)) { - if (WEXITSTATUS(state->exit_status) == 0) - return (ARCHIVE_OK); - - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Child process exited with status %d", - WEXITSTATUS(state->exit_status)); - return (ARCHIVE_WARN); - } - - return (ARCHIVE_WARN); -} - -/* - * Use select() to decide whether the child is ready for read or write. - */ -static ssize_t -child_read(struct archive_read_filter *self, char *buf, size_t buf_len) -{ - struct program_filter *state = self->data; - ssize_t ret, requested, avail; - const char *p; - - requested = buf_len > SSIZE_MAX ? SSIZE_MAX : buf_len; - - for (;;) { - do { - ret = read(state->child_stdout, buf, requested); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) - return (ret); - if (ret == 0 || (ret == -1 && errno == EPIPE)) - /* Child has closed its output; reap the child - * and return the status. */ - return (child_stop(self, state)); - if (ret == -1 && errno != EAGAIN) - return (-1); - - if (state->child_stdin == -1) { - /* Block until child has some I/O ready. */ - __archive_check_child(state->child_stdin, - state->child_stdout); - continue; - } - - /* Get some more data from upstream. */ - p = __archive_read_filter_ahead(self->upstream, 1, &avail); - if (p == NULL) { - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - if (avail < 0) - return (avail); - continue; - } - - do { - ret = write(state->child_stdin, p, avail); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) { - /* Consume whatever we managed to write. */ - __archive_read_filter_consume(self->upstream, ret); - } else if (ret == -1 && errno == EAGAIN) { - /* Block until child has some I/O ready. */ - __archive_check_child(state->child_stdin, - state->child_stdout); - } else { - /* Write failed. */ - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - /* If it was a bad error, we're done; otherwise - * it was EPIPE or EOF, and we can still read - * from the child. */ - if (ret == -1 && errno != EPIPE) - return (-1); - } - } -} - -int -__archive_read_program(struct archive_read_filter *self, const char *cmd) -{ - struct program_filter *state; - static const size_t out_buf_len = 65536; - char *out_buf; - char *description; - const char *prefix = "Program: "; - - state = (struct program_filter *)calloc(1, sizeof(*state)); - out_buf = (char *)malloc(out_buf_len); - description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); - if (state == NULL || out_buf == NULL || description == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate input data"); - free(state); - free(out_buf); - free(description); - return (ARCHIVE_FATAL); - } - - self->code = ARCHIVE_COMPRESSION_PROGRAM; - state->description = description; - strcpy(state->description, prefix); - strcat(state->description, cmd); - self->name = state->description; - - state->out_buf = out_buf; - state->out_buf_len = out_buf_len; - - if ((state->child = __archive_create_child(cmd, - &state->child_stdin, &state->child_stdout)) == -1) { - free(state->out_buf); - free(state); - archive_set_error(&self->archive->archive, EINVAL, - "Can't initialise filter"); - return (ARCHIVE_FATAL); - } - - self->data = state; - self->read = program_filter_read; - self->skip = NULL; - self->close = program_filter_close; - - /* XXX Check that we can read at least one byte? */ - return (ARCHIVE_OK); -} - -static int -program_bidder_init(struct archive_read_filter *self) -{ - struct program_bidder *bidder_state; - - bidder_state = (struct program_bidder *)self->bidder->data; - return (__archive_read_program(self, bidder_state->cmd)); -} - -static ssize_t -program_filter_read(struct archive_read_filter *self, const void **buff) -{ - struct program_filter *state; - ssize_t bytes; - size_t total; - char *p; - - state = (struct program_filter *)self->data; - - total = 0; - p = state->out_buf; - while (state->child_stdout != -1 && total < state->out_buf_len) { - bytes = child_read(self, p, state->out_buf_len - total); - if (bytes < 0) - /* No recovery is possible if we can no longer - * read from the child. */ - return (ARCHIVE_FATAL); - if (bytes == 0) - /* We got EOF from the child. */ - break; - total += bytes; - p += bytes; - } - - *buff = state->out_buf; - return (total); -} - -static int -program_filter_close(struct archive_read_filter *self) -{ - struct program_filter *state; - int e; - - state = (struct program_filter *)self->data; - e = child_stop(self, state); - - /* Release our private data. */ - free(state->out_buf); - free(state->description); - free(state); - - return (e); -} - -#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_xz.c b/Utilities/cmlibarchive/libarchive/archive_read_support_compression_xz.c deleted file mode 100644 index cb284cc78..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_xz.c +++ /dev/null @@ -1,644 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2008 Tim Kientzle and Miklos Vajna - * 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$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#if HAVE_LZMA_H -#include -#elif HAVE_LZMADEC_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_read_private.h" - -#if HAVE_LZMA_H && HAVE_LIBLZMA - -struct private_data { - lzma_stream stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - char eof; /* True = found end of compressed data. */ -}; - -/* Combined lzma/xz filter */ -static ssize_t xz_filter_read(struct archive_read_filter *, const void **); -static int xz_filter_close(struct archive_read_filter *); -static int xz_lzma_bidder_init(struct archive_read_filter *); - -#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC - -struct private_data { - lzmadec_stream stream; - unsigned char *out_block; - size_t out_block_size; - int64_t total_out; - char eof; /* True = found end of compressed data. */ -}; - -/* Lzma-only filter */ -static ssize_t lzma_filter_read(struct archive_read_filter *, const void **); -static int lzma_filter_close(struct archive_read_filter *); -#endif - -/* - * Note that we can detect xz and lzma compressed files even if we - * can't decompress them. (In fact, we like detecting them because we - * can give better error messages.) So the bid framework here gets - * compiled even if no lzma library is available. - */ -static int xz_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int xz_bidder_init(struct archive_read_filter *); -static int lzma_bidder_bid(struct archive_read_filter_bidder *, - struct archive_read_filter *); -static int lzma_bidder_init(struct archive_read_filter *); - -int -archive_read_support_compression_xz(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = xz_bidder_bid; - bidder->init = xz_bidder_init; - bidder->options = NULL; - bidder->free = NULL; -#if HAVE_LZMA_H && HAVE_LIBLZMA - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external unxz program for xz decompression"); - return (ARCHIVE_WARN); -#endif -} - -int -archive_read_support_compression_lzma(struct archive *_a) -{ - struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a); - - archive_clear_error(_a); - if (bidder == NULL) - return (ARCHIVE_FATAL); - - bidder->data = NULL; - bidder->bid = lzma_bidder_bid; - bidder->init = lzma_bidder_init; - bidder->options = NULL; - bidder->free = NULL; -#if HAVE_LZMA_H && HAVE_LIBLZMA - return (ARCHIVE_OK); -#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC - return (ARCHIVE_OK); -#else - archive_set_error(_a, ARCHIVE_ERRNO_MISC, - "Using external unlzma program for lzma decompression"); - return (ARCHIVE_WARN); -#endif -} - -/* - * Test whether we can handle this data. - */ -static int -xz_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 6, &avail); - if (buffer == NULL) - return (0); - - /* - * Verify Header Magic Bytes : FD 37 7A 58 5A 00 - */ - bits_checked = 0; - if (buffer[0] != 0xFD) - return (0); - bits_checked += 8; - if (buffer[1] != 0x37) - return (0); - bits_checked += 8; - if (buffer[2] != 0x7A) - return (0); - bits_checked += 8; - if (buffer[3] != 0x58) - return (0); - bits_checked += 8; - if (buffer[4] != 0x5A) - return (0); - bits_checked += 8; - if (buffer[5] != 0x00) - return (0); - bits_checked += 8; - - return (bits_checked); -} - -/* - * Test whether we can handle this data. - * - * LZMA has a rather poor file signature. Zeros do not - * make good signature bytes as a rule, and the only non-zero byte - * here is an ASCII character. For example, an uncompressed tar - * archive whose first file is ']' would satisfy this check. It may - * be necessary to exclude LZMA from compression_all() because of - * this. Clients of libarchive would then have to explicitly enable - * LZMA checking instead of (or in addition to) compression_all() when - * they have other evidence (file name, command-line option) to go on. - */ -static int -lzma_bidder_bid(struct archive_read_filter_bidder *self, - struct archive_read_filter *filter) -{ - const unsigned char *buffer; - ssize_t avail; - int bits_checked; - - (void)self; /* UNUSED */ - - buffer = __archive_read_filter_ahead(filter, 6, &avail); - if (buffer == NULL) - return (0); - - /* First byte of raw LZMA stream is always 0x5d. */ - bits_checked = 0; - if (buffer[0] != 0x5d) - return (0); - bits_checked += 8; - - /* Second through fifth bytes are dictionary code, stored in - * little-endian order. The two least-significant bytes are - * always zero. */ - if (buffer[1] != 0 || buffer[2] != 0) - return (0); - bits_checked += 16; - - /* ??? TODO: Fix this. ??? */ - /* NSIS format check uses this, but I've seen tar.lzma - * archives where this byte is 0xff, not 0. Can it - * ever be anything other than 0 or 0xff? - */ -#if 0 - if (buffer[5] != 0) - return (0); - bits_checked += 8; -#endif - - /* TODO: The above test is still very weak. It would be - * good to do better. */ - - return (bits_checked); -} - -#if HAVE_LZMA_H && HAVE_LIBLZMA - -/* - * liblzma 4.999.7 and later support both lzma and xz streams. - */ -static int -xz_bidder_init(struct archive_read_filter *self) -{ - self->code = ARCHIVE_COMPRESSION_XZ; - self->name = "xz"; - return (xz_lzma_bidder_init(self)); -} - -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - return (xz_lzma_bidder_init(self)); -} - -/* - * Setup the callbacks. - */ -static int -xz_lzma_bidder_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - int ret; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for xz decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = xz_filter_read; - self->skip = NULL; /* not supported */ - self->close = xz_filter_close; - - state->stream.avail_in = 0; - - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Initialize compression library. - * TODO: I don't know what value is best for memlimit. - * maybe, it needs to check memory size which - * running system has. - */ - if (self->code == ARCHIVE_COMPRESSION_XZ) - ret = lzma_stream_decoder(&(state->stream), - (1U << 30),/* memlimit */ - LZMA_CONCATENATED); - else - ret = lzma_alone_decoder(&(state->stream), - (1U << 30));/* memlimit */ - - if (ret == LZMA_OK) - return (ARCHIVE_OK); - - /* Library setup failed: Choose an error message and clean up. */ - switch (ret) { - case LZMA_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "Cannot allocate memory"); - break; - case LZMA_OPTIONS_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "Invalid or unsupported options"); - break; - default: - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing lzma library"); - break; - } - - free(state->out_block); - free(state); - self->data = NULL; - return (ARCHIVE_FATAL); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -xz_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in; - int ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - state->stream.next_in = - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL && avail_in < 0) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress as much as we can in one pass. */ - ret = lzma_code(&(state->stream), - (state->stream.avail_in == 0)? LZMA_FINISH: LZMA_RUN); - switch (ret) { - case LZMA_STREAM_END: /* Found end of stream. */ - state->eof = 1; - /* FALL THROUGH */ - case LZMA_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case LZMA_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Lzma library error: Cannot allocate memory"); - return (ARCHIVE_FATAL); - case LZMA_MEMLIMIT_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Lzma library error: Out of memory"); - return (ARCHIVE_FATAL); - case LZMA_FORMAT_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: format not recognized"); - return (ARCHIVE_FATAL); - case LZMA_OPTIONS_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: Invalid options"); - return (ARCHIVE_FATAL); - case LZMA_DATA_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: Corrupted input data"); - return (ARCHIVE_FATAL); - case LZMA_BUF_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma library error: No progress is possible"); - return (ARCHIVE_FATAL); - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma decompression failed: Unknown error"); - return (ARCHIVE_FATAL); - } - } - - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -xz_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - - state = (struct private_data *)self->data; - lzma_end(&(state->stream)); - free(state->out_block); - free(state); - return (ARCHIVE_OK); -} - -#else - -#if HAVE_LZMADEC_H && HAVE_LIBLZMADEC - -/* - * If we have the older liblzmadec library, then we can handle - * LZMA streams but not XZ streams. - */ - -/* - * Setup the callbacks. - */ -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - static const size_t out_block_size = 64 * 1024; - void *out_block; - struct private_data *state; - ssize_t ret, avail_in; - - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - - state = (struct private_data *)calloc(sizeof(*state), 1); - out_block = (unsigned char *)malloc(out_block_size); - if (state == NULL || out_block == NULL) { - archive_set_error(&self->archive->archive, ENOMEM, - "Can't allocate data for lzma decompression"); - free(out_block); - free(state); - return (ARCHIVE_FATAL); - } - - self->data = state; - state->out_block_size = out_block_size; - state->out_block = out_block; - self->read = lzma_filter_read; - self->skip = NULL; /* not supported */ - self->close = lzma_filter_close; - - /* Prime the lzma library with 18 bytes of input. */ - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 18, &avail_in); - if (state->stream.next_in == NULL) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Initialize compression library. */ - ret = lzmadec_init(&(state->stream)); - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - if (ret == LZMADEC_OK) - return (ARCHIVE_OK); - - /* Library setup failed: Clean up. */ - archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing lzma library"); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case LZMADEC_HEADER_ERROR: - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid header"); - break; - case LZMADEC_MEM_ERROR: - archive_set_error(&self->archive->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - } - - free(state->out_block); - free(state); - self->data = NULL; - return (ARCHIVE_FATAL); -} - -/* - * Return the next block of decompressed data. - */ -static ssize_t -lzma_filter_read(struct archive_read_filter *self, const void **p) -{ - struct private_data *state; - size_t decompressed; - ssize_t avail_in, ret; - - state = (struct private_data *)self->data; - - /* Empty our output buffer. */ - state->stream.next_out = state->out_block; - state->stream.avail_out = state->out_block_size; - - /* Try to fill the output buffer. */ - while (state->stream.avail_out > 0 && !state->eof) { - state->stream.next_in = (unsigned char *)(uintptr_t) - __archive_read_filter_ahead(self->upstream, 1, &avail_in); - if (state->stream.next_in == NULL && avail_in < 0) - return (ARCHIVE_FATAL); - state->stream.avail_in = avail_in; - - /* Decompress as much as we can in one pass. */ - ret = lzmadec_decode(&(state->stream), avail_in == 0); - switch (ret) { - case LZMADEC_STREAM_END: /* Found end of stream. */ - state->eof = 1; - /* FALL THROUGH */ - case LZMADEC_OK: /* Decompressor made some progress. */ - __archive_read_filter_consume(self->upstream, - avail_in - state->stream.avail_in); - break; - case LZMADEC_BUF_ERROR: /* Insufficient input data? */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Insufficient compressed data"); - return (ARCHIVE_FATAL); - default: - /* Return an error. */ - archive_set_error(&self->archive->archive, - ARCHIVE_ERRNO_MISC, - "Lzma decompression failed"); - return (ARCHIVE_FATAL); - } - } - - decompressed = state->stream.next_out - state->out_block; - state->total_out += decompressed; - if (decompressed == 0) - *p = NULL; - else - *p = state->out_block; - return (decompressed); -} - -/* - * Clean up the decompressor. - */ -static int -lzma_filter_close(struct archive_read_filter *self) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)self->data; - ret = ARCHIVE_OK; - switch (lzmadec_end(&(state->stream))) { - case LZMADEC_OK: - break; - default: - archive_set_error(&(self->archive->archive), - ARCHIVE_ERRNO_MISC, - "Failed to clean up %s compressor", - self->archive->archive.compression_name); - ret = ARCHIVE_FATAL; - } - - free(state->out_block); - free(state); - return (ret); -} - -#else - -/* - * - * If we have no suitable library on this system, we can't actually do - * the decompression. We can, however, still detect compressed - * archives and emit a useful message. - * - */ -static int -lzma_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "unlzma"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_LZMA; - self->name = "lzma"; - return (r); -} - -#endif /* HAVE_LZMADEC_H */ - - -static int -xz_bidder_init(struct archive_read_filter *self) -{ - int r; - - r = __archive_read_program(self, "unxz"); - /* Note: We set the format here even if __archive_read_program() - * above fails. We do, after all, know what the format is - * even if we weren't able to read it. */ - self->code = ARCHIVE_COMPRESSION_XZ; - self->name = "xz"; - return (r); -} - - -#endif /* HAVE_LZMA_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c new file mode 100644 index 000000000..733d86298 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_all.c @@ -0,0 +1,75 @@ +/*- + * Copyright (c) 2003-2011 Tim Kientzle + * 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" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_all(struct archive *a) +{ + return archive_read_support_filter_all(a); +} +#endif + +int +archive_read_support_filter_all(struct archive *a) +{ + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_all"); + + /* Bzip falls back to "bunzip2" command-line */ + archive_read_support_filter_bzip2(a); + /* The decompress code doesn't use an outside library. */ + archive_read_support_filter_compress(a); + /* Gzip decompress falls back to "gunzip" command-line. */ + archive_read_support_filter_gzip(a); + /* Lzip falls back to "unlzip" command-line program. */ + archive_read_support_filter_lzip(a); + /* The LZMA file format has a very weak signature, so it + * may not be feasible to keep this here, but we'll try. + * This will come back out if there are problems. */ + /* Lzma falls back to "unlzma" command-line program. */ + archive_read_support_filter_lzma(a); + /* Xz falls back to "unxz" command-line program. */ + archive_read_support_filter_xz(a); + /* The decode code doesn't use an outside library. */ + archive_read_support_filter_uu(a); + /* The decode code doesn't use an outside library. */ + archive_read_support_filter_rpm(a); + + /* Note: We always return ARCHIVE_OK here, even if some of the + * above return ARCHIVE_WARN. The intent here is to enable + * "as much as possible." Clients who need specific + * compression should enable those individually so they can + * verify the level of support. */ + /* Clear any warning messages set by the above functions. */ + archive_clear_error(a); + return (ARCHIVE_OK); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c new file mode 100644 index 000000000..af618b09a --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_bzip2.c @@ -0,0 +1,370 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +struct private_data { + bz_stream stream; + char *out_block; + size_t out_block_size; + char valid; /* True = decompressor is initialized */ + char eof; /* True = found end of compressed data. */ +}; + +/* Bzip2 filter */ +static ssize_t bzip2_filter_read(struct archive_read_filter *, const void **); +static int bzip2_filter_close(struct archive_read_filter *); +#endif + +/* + * Note that we can detect bzip2 archives even if we can't decompress + * them. (In fact, we like detecting them because we can give better + * error messages.) So the bid framework here gets compiled even + * if bzlib is unavailable. + */ +static int bzip2_reader_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); +static int bzip2_reader_init(struct archive_read_filter *); +static int bzip2_reader_free(struct archive_read_filter_bidder *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_bzip2(struct archive *a) +{ + return archive_read_support_filter_bzip2(a); +} +#endif + +int +archive_read_support_filter_bzip2(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *reader; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_bzip2"); + + if (__archive_read_get_bidder(a, &reader) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + reader->data = NULL; + reader->bid = bzip2_reader_bid; + reader->init = bzip2_reader_init; + reader->options = NULL; + reader->free = bzip2_reader_free; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external bunzip2 program"); + return (ARCHIVE_WARN); +#endif +} + +static int +bzip2_reader_free(struct archive_read_filter_bidder *self){ + (void)self; /* UNUSED */ + return (ARCHIVE_OK); +} + +/* + * Test whether we can handle this data. + * + * This logic returns zero if any part of the signature fails. It + * also tries to Do The Right Thing if a very short buffer prevents us + * from verifying as much as we would like. + */ +static int +bzip2_reader_bid(struct archive_read_filter_bidder *self, struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + int bits_checked; + + (void)self; /* UNUSED */ + + /* Minimal bzip2 archive is 14 bytes. */ + buffer = __archive_read_filter_ahead(filter, 14, &avail); + if (buffer == NULL) + return (0); + + /* First three bytes must be "BZh" */ + bits_checked = 0; + if (memcmp(buffer, "BZh", 3) != 0) + return (0); + bits_checked += 24; + + /* Next follows a compression flag which must be an ASCII digit. */ + if (buffer[3] < '1' || buffer[3] > '9') + return (0); + bits_checked += 5; + + /* After BZh[1-9], there must be either a data block + * which begins with 0x314159265359 or an end-of-data + * marker of 0x177245385090. */ + if (memcmp(buffer + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0) + bits_checked += 48; + else if (memcmp(buffer + 4, "\x17\x72\x45\x38\x50\x90", 6) == 0) + bits_checked += 48; + else + return (0); + + return (bits_checked); +} + +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) + +/* + * If we don't have the library on this system, we can't actually do the + * decompression. We can, however, still detect compressed archives + * and emit a useful message. + */ +static int +bzip2_reader_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "bunzip2"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_COMPRESSION_BZIP2; + self->name = "bzip2"; + return (r); +} + + +#else + +/* + * Setup the callbacks. + */ +static int +bzip2_reader_init(struct archive_read_filter *self) +{ + static const size_t out_block_size = 64 * 1024; + void *out_block; + struct private_data *state; + + self->code = ARCHIVE_COMPRESSION_BZIP2; + self->name = "bzip2"; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = (unsigned char *)malloc(out_block_size); + if (state == NULL || out_block == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for bzip2 decompression"); + free(out_block); + free(state); + return (ARCHIVE_FATAL); + } + + self->data = state; + state->out_block_size = out_block_size; + state->out_block = out_block; + self->read = bzip2_filter_read; + self->skip = NULL; /* not supported */ + self->close = bzip2_filter_close; + + return (ARCHIVE_OK); +} + +/* + * Return the next block of decompressed data. + */ +static ssize_t +bzip2_filter_read(struct archive_read_filter *self, const void **p) +{ + struct private_data *state; + size_t decompressed; + const char *read_buf; + ssize_t ret; + + state = (struct private_data *)self->data; + + if (state->eof) { + *p = NULL; + return (0); + } + + /* Empty our output buffer. */ + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + /* Try to fill the output buffer. */ + for (;;) { + if (!state->valid) { + if (bzip2_reader_bid(self->bidder, self->upstream) == 0) { + state->eof = 1; + *p = state->out_block; + decompressed = state->stream.next_out + - state->out_block; + return (decompressed); + } + /* Initialize compression library. */ + ret = BZ2_bzDecompressInit(&(state->stream), + 0 /* library verbosity */, + 0 /* don't use low-mem algorithm */); + + /* If init fails, try low-memory algorithm instead. */ + if (ret == BZ_MEM_ERROR) + ret = BZ2_bzDecompressInit(&(state->stream), + 0 /* library verbosity */, + 1 /* do use low-mem algo */); + + if (ret != BZ_OK) { + const char *detail = NULL; + int err = ARCHIVE_ERRNO_MISC; + switch (ret) { + case BZ_PARAM_ERROR: + detail = "invalid setup parameter"; + break; + case BZ_MEM_ERROR: + err = ENOMEM; + detail = "out of memory"; + break; + case BZ_CONFIG_ERROR: + detail = "mis-compiled library"; + break; + } + archive_set_error(&self->archive->archive, err, + "Internal error initializing decompressor%s%s", + detail == NULL ? "" : ": ", + detail); + return (ARCHIVE_FATAL); + } + state->valid = 1; + } + + /* stream.next_in is really const, but bzlib + * doesn't declare it so. */ + read_buf = + __archive_read_filter_ahead(self->upstream, 1, &ret); + if (read_buf == NULL) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "truncated bzip2 input"); + return (ARCHIVE_FATAL); + } + state->stream.next_in = (char *)(uintptr_t)read_buf; + state->stream.avail_in = ret; + /* There is no more data, return whatever we have. */ + if (ret == 0) { + state->eof = 1; + *p = state->out_block; + decompressed = state->stream.next_out + - state->out_block; + return (decompressed); + } + + /* Decompress as much as we can in one pass. */ + ret = BZ2_bzDecompress(&(state->stream)); + __archive_read_filter_consume(self->upstream, + state->stream.next_in - read_buf); + + switch (ret) { + case BZ_STREAM_END: /* Found end of stream. */ + switch (BZ2_bzDecompressEnd(&(state->stream))) { + case BZ_OK: + break; + default: + archive_set_error(&(self->archive->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + return (ARCHIVE_FATAL); + } + state->valid = 0; + /* FALLTHROUGH */ + case BZ_OK: /* Decompressor made some progress. */ + /* If we filled our buffer, update stats and return. */ + if (state->stream.avail_out == 0) { + *p = state->out_block; + decompressed = state->stream.next_out + - state->out_block; + return (decompressed); + } + break; + default: /* Return an error. */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, "bzip decompression failed"); + return (ARCHIVE_FATAL); + } + } +} + +/* + * Clean up the decompressor. + */ +static int +bzip2_filter_close(struct archive_read_filter *self) +{ + struct private_data *state; + int ret = ARCHIVE_OK; + + state = (struct private_data *)self->data; + + if (state->valid) { + switch (BZ2_bzDecompressEnd(&state->stream)) { + case BZ_OK: + break; + default: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + ret = ARCHIVE_FATAL; + } + state->valid = 0; + } + + free(state->out_block); + free(state); + return (ret); +} + +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c new file mode 100644 index 000000000..1b8530004 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_compress.c @@ -0,0 +1,454 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * 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. + */ + +/* + * This code borrows heavily from "compress" source code, which is + * protected by the following copyright. (Clause 3 dropped by request + * of the Regents.) + */ + +/*- + * Copyright (c) 1985, 1986, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Diomidis Spinellis and James A. Woods, derived from original + * work by Spencer Thomas and Joseph Orost. + * + * 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. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +#include "archive_platform.h" +__FBSDID("$FreeBSD$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_read_private.h" + +/* + * Because LZW decompression is pretty simple, I've just implemented + * the whole decompressor here (cribbing from "compress" source code, + * of course), rather than relying on an external library. I have + * made an effort to clarify and simplify the algorithm, so the + * names and structure here don't exactly match those used by compress. + */ + +struct private_data { + /* Input variables. */ + const unsigned char *next_in; + size_t avail_in; + size_t consume_unnotified; + int bit_buffer; + int bits_avail; + size_t bytes_in_section; + + /* Output variables. */ + size_t out_block_size; + void *out_block; + + /* Decompression status variables. */ + int use_reset_code; + int end_of_stream; /* EOF status. */ + int maxcode; /* Largest code. */ + int maxcode_bits; /* Length of largest code. */ + int section_end_code; /* When to increase bits. */ + int bits; /* Current code length. */ + int oldcode; /* Previous code. */ + int finbyte; /* Last byte of prev code. */ + + /* Dictionary. */ + int free_ent; /* Next dictionary entry. */ + unsigned char suffix[65536]; + uint16_t prefix[65536]; + + /* + * Scratch area for expanding dictionary entries. Note: + * "worst" case here comes from compressing /dev/zero: the + * last code in the dictionary will code a sequence of + * 65536-256 zero bytes. Thus, we need stack space to expand + * a 65280-byte dictionary entry. (Of course, 32640:1 + * compression could also be considered the "best" case. ;-) + */ + unsigned char *stackp; + unsigned char stack[65300]; +}; + +static int compress_bidder_bid(struct archive_read_filter_bidder *, struct archive_read_filter *); +static int compress_bidder_init(struct archive_read_filter *); +static int compress_bidder_free(struct archive_read_filter_bidder *); + +static ssize_t compress_filter_read(struct archive_read_filter *, const void **); +static int compress_filter_close(struct archive_read_filter *); + +static int getbits(struct archive_read_filter *, int n); +static int next_code(struct archive_read_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_compress(struct archive *a) +{ + return archive_read_support_filter_compress(a); +} +#endif + +int +archive_read_support_filter_compress(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_compress"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = compress_bidder_bid; + bidder->init = compress_bidder_init; + bidder->options = NULL; + bidder->free = compress_bidder_free; + return (ARCHIVE_OK); +} + +/* + * Test whether we can handle this data. + * This logic returns zero if any part of the signature fails. + */ +static int +compress_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + int bits_checked; + + (void)self; /* UNUSED */ + + buffer = __archive_read_filter_ahead(filter, 2, &avail); + + if (buffer == NULL) + return (0); + + bits_checked = 0; + if (buffer[0] != 0x1F || buffer[1] != 0x9D) + return (0); + bits_checked += 16; + + /* + * TODO: Verify more. + */ + + return (bits_checked); +} + +/* + * Setup the callbacks. + */ +static int +compress_bidder_init(struct archive_read_filter *self) +{ + struct private_data *state; + static const size_t out_block_size = 64 * 1024; + void *out_block; + int code; + + self->code = ARCHIVE_COMPRESSION_COMPRESS; + self->name = "compress (.Z)"; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = malloc(out_block_size); + if (state == NULL || out_block == NULL) { + free(out_block); + free(state); + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for %s decompression", + self->name); + return (ARCHIVE_FATAL); + } + + self->data = state; + state->out_block_size = out_block_size; + state->out_block = out_block; + self->read = compress_filter_read; + self->skip = NULL; /* not supported */ + self->close = compress_filter_close; + + /* XXX MOVE THE FOLLOWING OUT OF INIT() XXX */ + + (void)getbits(self, 8); /* Skip first signature byte. */ + (void)getbits(self, 8); /* Skip second signature byte. */ + + code = getbits(self, 8); + state->maxcode_bits = code & 0x1f; + state->maxcode = (1 << state->maxcode_bits); + state->use_reset_code = code & 0x80; + + /* Initialize decompressor. */ + state->free_ent = 256; + state->stackp = state->stack; + if (state->use_reset_code) + state->free_ent++; + state->bits = 9; + state->section_end_code = (1<bits) - 1; + state->oldcode = -1; + for (code = 255; code >= 0; code--) { + state->prefix[code] = 0; + state->suffix[code] = code; + } + next_code(self); + + return (ARCHIVE_OK); +} + +/* + * Return a block of data from the decompression buffer. Decompress more + * as necessary. + */ +static ssize_t +compress_filter_read(struct archive_read_filter *self, const void **pblock) +{ + struct private_data *state; + unsigned char *p, *start, *end; + int ret; + + state = (struct private_data *)self->data; + if (state->end_of_stream) { + *pblock = NULL; + return (0); + } + p = start = (unsigned char *)state->out_block; + end = start + state->out_block_size; + + while (p < end && !state->end_of_stream) { + if (state->stackp > state->stack) { + *p++ = *--state->stackp; + } else { + ret = next_code(self); + if (ret == -1) + state->end_of_stream = ret; + else if (ret != ARCHIVE_OK) + return (ret); + } + } + + *pblock = start; + return (p - start); +} + +/* + * Clean up the reader. + */ +static int +compress_bidder_free(struct archive_read_filter_bidder *self) +{ + self->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Close and release the filter. + */ +static int +compress_filter_close(struct archive_read_filter *self) +{ + struct private_data *state = (struct private_data *)self->data; + + free(state->out_block); + free(state); + return (ARCHIVE_OK); +} + +/* + * Process the next code and fill the stack with the expansion + * of the code. Returns ARCHIVE_FATAL if there is a fatal I/O or + * format error, ARCHIVE_EOF if we hit end of data, ARCHIVE_OK otherwise. + */ +static int +next_code(struct archive_read_filter *self) +{ + struct private_data *state = (struct private_data *)self->data; + int code, newcode; + + static int debug_buff[1024]; + static unsigned debug_index; + + code = newcode = getbits(self, state->bits); + if (code < 0) + return (code); + + debug_buff[debug_index++] = code; + if (debug_index >= sizeof(debug_buff)/sizeof(debug_buff[0])) + debug_index = 0; + + /* If it's a reset code, reset the dictionary. */ + if ((code == 256) && state->use_reset_code) { + /* + * The original 'compress' implementation blocked its + * I/O in a manner that resulted in junk bytes being + * inserted after every reset. The next section skips + * this junk. (Yes, the number of *bytes* to skip is + * a function of the current *bit* length.) + */ + int skip_bytes = state->bits - + (state->bytes_in_section % state->bits); + skip_bytes %= state->bits; + state->bits_avail = 0; /* Discard rest of this byte. */ + while (skip_bytes-- > 0) { + code = getbits(self, 8); + if (code < 0) + return (code); + } + /* Now, actually do the reset. */ + state->bytes_in_section = 0; + state->bits = 9; + state->section_end_code = (1 << state->bits) - 1; + state->free_ent = 257; + state->oldcode = -1; + return (next_code(self)); + } + + if (code > state->free_ent) { + /* An invalid code is a fatal error. */ + archive_set_error(&(self->archive->archive), -1, + "Invalid compressed data"); + return (ARCHIVE_FATAL); + } + + /* Special case for KwKwK string. */ + if (code >= state->free_ent) { + *state->stackp++ = state->finbyte; + code = state->oldcode; + } + + /* Generate output characters in reverse order. */ + while (code >= 256) { + *state->stackp++ = state->suffix[code]; + code = state->prefix[code]; + } + *state->stackp++ = state->finbyte = code; + + /* Generate the new entry. */ + code = state->free_ent; + if (code < state->maxcode && state->oldcode >= 0) { + state->prefix[code] = state->oldcode; + state->suffix[code] = state->finbyte; + ++state->free_ent; + } + if (state->free_ent > state->section_end_code) { + state->bits++; + state->bytes_in_section = 0; + if (state->bits == state->maxcode_bits) + state->section_end_code = state->maxcode; + else + state->section_end_code = (1 << state->bits) - 1; + } + + /* Remember previous code. */ + state->oldcode = newcode; + return (ARCHIVE_OK); +} + +/* + * Return next 'n' bits from stream. + * + * -1 indicates end of available data. + */ +static int +getbits(struct archive_read_filter *self, int n) +{ + struct private_data *state = (struct private_data *)self->data; + int code; + ssize_t ret; + static const int mask[] = { + 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, + 0x1ff, 0x3ff, 0x7ff, 0xfff, 0x1fff, 0x3fff, 0x7fff, 0xffff + }; + + while (state->bits_avail < n) { + if (state->avail_in <= 0) { + if (state->consume_unnotified) { + __archive_read_filter_consume(self->upstream, + state->consume_unnotified); + state->consume_unnotified = 0; + } + state->next_in + = __archive_read_filter_ahead(self->upstream, + 1, &ret); + if (ret == 0) + return (-1); + if (ret < 0 || state->next_in == NULL) + return (ARCHIVE_FATAL); + state->consume_unnotified = state->avail_in = ret; + } + state->bit_buffer |= *state->next_in++ << state->bits_avail; + state->avail_in--; + state->bits_avail += 8; + state->bytes_in_section++; + } + + code = state->bit_buffer; + state->bit_buffer >>= n; + state->bits_avail -= n; + + return (code & mask[n]); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c new file mode 100644 index 000000000..9d03b2b2c --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_gzip.c @@ -0,0 +1,476 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * 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$"); + + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#ifdef HAVE_ZLIB_H +struct private_data { + z_stream stream; + char in_stream; + unsigned char *out_block; + size_t out_block_size; + int64_t total_out; + unsigned long crc; + char eof; /* True = found end of compressed data. */ +}; + +/* Gzip Filter. */ +static ssize_t gzip_filter_read(struct archive_read_filter *, const void **); +static int gzip_filter_close(struct archive_read_filter *); +#endif + +/* + * Note that we can detect gzip archives even if we can't decompress + * them. (In fact, we like detecting them because we can give better + * error messages.) So the bid framework here gets compiled even + * if zlib is unavailable. + * + * TODO: If zlib is unavailable, gzip_bidder_init() should + * use the compress_program framework to try to fire up an external + * gunzip program. + */ +static int gzip_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int gzip_bidder_init(struct archive_read_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_gzip(struct archive *a) +{ + return archive_read_support_filter_gzip(a); +} +#endif + +int +archive_read_support_filter_gzip(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_gzip"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = gzip_bidder_bid; + bidder->init = gzip_bidder_init; + bidder->options = NULL; + bidder->free = NULL; /* No data, so no cleanup necessary. */ + /* Signal the extent of gzip support with the return value here. */ +#if HAVE_ZLIB_H + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external gunzip program"); + return (ARCHIVE_WARN); +#endif +} + +/* + * Read and verify the header. + * + * Returns zero if the header couldn't be validated, else returns + * number of bytes in header. If pbits is non-NULL, it receives a + * count of bits verified, suitable for use by bidder. + */ +static int +peek_at_header(struct archive_read_filter *filter, int *pbits) +{ + const unsigned char *p; + ssize_t avail, len; + int bits = 0; + int header_flags; + + /* Start by looking at the first ten bytes of the header, which + * is all fixed layout. */ + len = 10; + p = __archive_read_filter_ahead(filter, len, &avail); + if (p == NULL || avail == 0) + return (0); + /* We only support deflation- third byte must be 0x08. */ + if (memcmp(p, "\x1F\x8B\x08", 3) != 0) + return (0); + bits += 24; + if ((p[3] & 0xE0)!= 0) /* No reserved flags set. */ + return (0); + bits += 3; + header_flags = p[3]; + /* Bytes 4-7 are mod time. */ + /* Byte 8 is deflate flags. */ + /* XXXX TODO: return deflate flags back to consume_header for use + in initializing the decompressor. */ + /* Byte 9 is OS. */ + + /* Optional extra data: 2 byte length plus variable body. */ + if (header_flags & 4) { + p = __archive_read_filter_ahead(filter, len + 2, &avail); + if (p == NULL) + return (0); + len += ((int)p[len + 1] << 8) | (int)p[len]; + len += 2; + } + + /* Null-terminated optional filename. */ + if (header_flags & 8) { + do { + ++len; + if (avail < len) + p = __archive_read_filter_ahead(filter, + len, &avail); + if (p == NULL) + return (0); + } while (p[len - 1] != 0); + } + + /* Null-terminated optional comment. */ + if (header_flags & 16) { + do { + ++len; + if (avail < len) + p = __archive_read_filter_ahead(filter, + len, &avail); + if (p == NULL) + return (0); + } while (p[len - 1] != 0); + } + + /* Optional header CRC */ + if ((header_flags & 2)) { + p = __archive_read_filter_ahead(filter, len + 2, &avail); + if (p == NULL) + return (0); +#if 0 + int hcrc = ((int)p[len + 1] << 8) | (int)p[len]; + int crc = /* XXX TODO: Compute header CRC. */; + if (crc != hcrc) + return (0); + bits += 16; +#endif + len += 2; + } + + if (pbits != NULL) + *pbits = bits; + return (len); +} + +/* + * Bidder just verifies the header and returns the number of verified bits. + */ +static int +gzip_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + int bits_checked; + + (void)self; /* UNUSED */ + + if (peek_at_header(filter, &bits_checked)) + return (bits_checked); + return (0); +} + + +#ifndef HAVE_ZLIB_H + +/* + * If we don't have the library on this system, we can't do the + * decompression directly. We can, however, try to run gunzip + * in case that's available. + */ +static int +gzip_bidder_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "gunzip"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_COMPRESSION_GZIP; + self->name = "gzip"; + return (r); +} + +#else + +/* + * Initialize the filter object. + */ +static int +gzip_bidder_init(struct archive_read_filter *self) +{ + struct private_data *state; + static const size_t out_block_size = 64 * 1024; + void *out_block; + + self->code = ARCHIVE_COMPRESSION_GZIP; + self->name = "gzip"; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = (unsigned char *)malloc(out_block_size); + if (state == NULL || out_block == NULL) { + free(out_block); + free(state); + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for gzip decompression"); + return (ARCHIVE_FATAL); + } + + self->data = state; + state->out_block_size = out_block_size; + state->out_block = out_block; + self->read = gzip_filter_read; + self->skip = NULL; /* not supported */ + self->close = gzip_filter_close; + + state->in_stream = 0; /* We're not actually within a stream yet. */ + + return (ARCHIVE_OK); +} + +static int +consume_header(struct archive_read_filter *self) +{ + struct private_data *state; + ssize_t avail; + size_t len; + int ret; + + state = (struct private_data *)self->data; + + /* If this is a real header, consume it. */ + len = peek_at_header(self->upstream, NULL); + if (len == 0) + return (ARCHIVE_EOF); + __archive_read_filter_consume(self->upstream, len); + + /* Initialize CRC accumulator. */ + state->crc = crc32(0L, NULL, 0); + + /* Initialize compression library. */ + state->stream.next_in = (unsigned char *)(uintptr_t) + __archive_read_filter_ahead(self->upstream, 1, &avail); + state->stream.avail_in = avail; + ret = inflateInit2(&(state->stream), + -15 /* Don't check for zlib header */); + + /* Decipher the error code. */ + switch (ret) { + case Z_OK: + state->in_stream = 1; + return (ARCHIVE_OK); + case Z_STREAM_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "invalid setup parameter"); + break; + case Z_MEM_ERROR: + archive_set_error(&self->archive->archive, ENOMEM, + "Internal error initializing compression library: " + "out of memory"); + break; + case Z_VERSION_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "invalid library version"); + break; + default: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + " Zlib error %d", ret); + break; + } + return (ARCHIVE_FATAL); +} + +static int +consume_trailer(struct archive_read_filter *self) +{ + struct private_data *state; + const unsigned char *p; + ssize_t avail; + + state = (struct private_data *)self->data; + + state->in_stream = 0; + switch (inflateEnd(&(state->stream))) { + case Z_OK: + break; + default: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up gzip decompressor"); + return (ARCHIVE_FATAL); + } + + /* GZip trailer is a fixed 8 byte structure. */ + p = __archive_read_filter_ahead(self->upstream, 8, &avail); + if (p == NULL || avail == 0) + return (ARCHIVE_FATAL); + + /* XXX TODO: Verify the length and CRC. */ + + /* We've verified the trailer, so consume it now. */ + __archive_read_filter_consume(self->upstream, 8); + + return (ARCHIVE_OK); +} + +static ssize_t +gzip_filter_read(struct archive_read_filter *self, const void **p) +{ + struct private_data *state; + size_t decompressed; + ssize_t avail_in; + int ret; + + state = (struct private_data *)self->data; + + /* Empty our output buffer. */ + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + /* Try to fill the output buffer. */ + while (state->stream.avail_out > 0 && !state->eof) { + /* If we're not in a stream, read a header + * and initialize the decompression library. */ + if (!state->in_stream) { + ret = consume_header(self); + if (ret == ARCHIVE_EOF) { + state->eof = 1; + break; + } + if (ret < ARCHIVE_OK) + return (ret); + } + + /* Peek at the next available data. */ + /* ZLib treats stream.next_in as const but doesn't declare + * it so, hence this ugly cast. */ + state->stream.next_in = (unsigned char *)(uintptr_t) + __archive_read_filter_ahead(self->upstream, 1, &avail_in); + if (state->stream.next_in == NULL) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "truncated gzip input"); + return (ARCHIVE_FATAL); + } + state->stream.avail_in = avail_in; + + /* Decompress and consume some of that data. */ + ret = inflate(&(state->stream), 0); + switch (ret) { + case Z_OK: /* Decompressor made some progress. */ + __archive_read_filter_consume(self->upstream, + avail_in - state->stream.avail_in); + break; + case Z_STREAM_END: /* Found end of stream. */ + __archive_read_filter_consume(self->upstream, + avail_in - state->stream.avail_in); + /* Consume the stream trailer; release the + * decompression library. */ + ret = consume_trailer(self); + if (ret < ARCHIVE_OK) + return (ret); + break; + default: + /* Return an error. */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "gzip decompression failed"); + return (ARCHIVE_FATAL); + } + } + + /* We've read as much as we can. */ + decompressed = state->stream.next_out - state->out_block; + state->total_out += decompressed; + if (decompressed == 0) + *p = NULL; + else + *p = state->out_block; + return (decompressed); +} + +/* + * Clean up the decompressor. + */ +static int +gzip_filter_close(struct archive_read_filter *self) +{ + struct private_data *state; + int ret; + + state = (struct private_data *)self->data; + ret = ARCHIVE_OK; + + if (state->in_stream) { + switch (inflateEnd(&(state->stream))) { + case Z_OK: + break; + default: + archive_set_error(&(self->archive->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up gzip compressor"); + ret = ARCHIVE_FATAL; + } + } + + free(state->out_block); + free(state); + return (ret); +} + +#endif /* HAVE_ZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_none.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c similarity index 80% rename from Utilities/cmlibarchive/libarchive/archive_read_support_compression_none.c rename to Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c index 1456a1184..95e5cfdb1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_compression_none.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_none.c @@ -24,17 +24,29 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_compression_none.c,v 1.20 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD$"); #include "archive.h" +#include "archive_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_none(struct archive *a) +{ + return archive_read_support_filter_none(a); +} +#endif /* * Uncompressed streams are handled implicitly by the read core, * so this is now a no-op. */ int -archive_read_support_compression_none(struct archive *a) +archive_read_support_filter_none(struct archive *a) { - (void)a; /* UNUSED */ - return (ARCHIVE_OK); + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_none"); + + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c new file mode 100644 index 000000000..b05eb0342 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_program.c @@ -0,0 +1,476 @@ +/*- + * Copyright (c) 2007 Joerg Sonnenberger + * 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$"); + +#ifdef HAVE_SYS_WAIT_H +# include +#endif +#ifdef HAVE_ERRNO_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif +#ifdef HAVE_LIMITS_H +# include +#endif +#ifdef HAVE_SIGNAL_H +# include +#endif +#ifdef HAVE_STDLIB_H +# include +#endif +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_read_private.h" + + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_program(struct archive *a, const char *cmd) +{ + return archive_read_support_filter_program(a, cmd); +} + +int +archive_read_support_compression_program_signature(struct archive *a, + const char *cmd, const void *signature, size_t signature_len) +{ + return archive_read_support_filter_program_signature(a, + cmd, signature, signature_len); +} +#endif + +int +archive_read_support_filter_program(struct archive *a, const char *cmd) +{ + return (archive_read_support_filter_program_signature(a, cmd, NULL, 0)); +} + + +/* This capability is only available on POSIX systems. */ +#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ + !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) + +/* + * On non-Posix systems, allow the program to build, but choke if + * this function is actually invoked. + */ +int +archive_read_support_filter_program_signature(struct archive *_a, + const char *cmd, const void *signature, size_t signature_len) +{ + (void)_a; /* UNUSED */ + (void)cmd; /* UNUSED */ + (void)signature; /* UNUSED */ + (void)signature_len; /* UNUSED */ + + archive_set_error(_a, -1, + "External compression programs not supported on this platform"); + return (ARCHIVE_FATAL); +} + +int +__archive_read_program(struct archive_read_filter *self, const char *cmd) +{ + (void)self; /* UNUSED */ + (void)cmd; /* UNUSED */ + + archive_set_error(&self->archive->archive, -1, + "External compression programs not supported on this platform"); + return (ARCHIVE_FATAL); +} + +#else + +#include "filter_fork.h" + +/* + * The bidder object stores the command and the signature to watch for. + * The 'inhibit' entry here is used to ensure that unchecked filters never + * bid twice in the same pipeline. + */ +struct program_bidder { + char *cmd; + void *signature; + size_t signature_len; + int inhibit; +}; + +static int program_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *upstream); +static int program_bidder_init(struct archive_read_filter *); +static int program_bidder_free(struct archive_read_filter_bidder *); + +/* + * The actual filter needs to track input and output data. + */ +struct program_filter { + char *description; + pid_t child; + int exit_status; + int waitpid_return; + int child_stdin, child_stdout; + + char *out_buf; + size_t out_buf_len; +}; + +static ssize_t program_filter_read(struct archive_read_filter *, + const void **); +static int program_filter_close(struct archive_read_filter *); + +int +archive_read_support_filter_program_signature(struct archive *_a, + const char *cmd, const void *signature, size_t signature_len) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + struct program_bidder *state; + + /* + * Get a bidder object from the read core. + */ + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* + * Allocate our private state. + */ + state = (struct program_bidder *)calloc(sizeof (*state), 1); + if (state == NULL) + return (ARCHIVE_FATAL); + state->cmd = strdup(cmd); + if (signature != NULL && signature_len > 0) { + state->signature_len = signature_len; + state->signature = malloc(signature_len); + memcpy(state->signature, signature, signature_len); + } + + /* + * Fill in the bidder object. + */ + bidder->data = state; + bidder->bid = program_bidder_bid; + bidder->init = program_bidder_init; + bidder->options = NULL; + bidder->free = program_bidder_free; + return (ARCHIVE_OK); +} + +static int +program_bidder_free(struct archive_read_filter_bidder *self) +{ + struct program_bidder *state = (struct program_bidder *)self->data; + free(state->cmd); + free(state->signature); + free(self->data); + return (ARCHIVE_OK); +} + +/* + * If we do have a signature, bid only if that matches. + * + * If there's no signature, we bid INT_MAX the first time + * we're called, then never bid again. + */ +static int +program_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *upstream) +{ + struct program_bidder *state = self->data; + const char *p; + + /* If we have a signature, use that to match. */ + if (state->signature_len > 0) { + p = __archive_read_filter_ahead(upstream, + state->signature_len, NULL); + if (p == NULL) + return (0); + /* No match, so don't bid. */ + if (memcmp(p, state->signature, state->signature_len) != 0) + return (0); + return ((int)state->signature_len * 8); + } + + /* Otherwise, bid once and then never bid again. */ + if (state->inhibit) + return (0); + state->inhibit = 1; + return (INT_MAX); +} + +/* + * Shut down the child, return ARCHIVE_OK if it exited normally. + * + * Note that the return value is sticky; if we're called again, + * we won't reap the child again, but we will return the same status + * (including error message if the child came to a bad end). + */ +static int +child_stop(struct archive_read_filter *self, struct program_filter *state) +{ + /* Close our side of the I/O with the child. */ + if (state->child_stdin != -1) { + close(state->child_stdin); + state->child_stdin = -1; + } + if (state->child_stdout != -1) { + close(state->child_stdout); + state->child_stdout = -1; + } + + if (state->child != 0) { + /* Reap the child. */ + do { + state->waitpid_return + = waitpid(state->child, &state->exit_status, 0); + } while (state->waitpid_return == -1 && errno == EINTR); + state->child = 0; + } + + if (state->waitpid_return < 0) { + /* waitpid() failed? This is ugly. */ + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Child process exited badly"); + return (ARCHIVE_WARN); + } + +#if !defined(_WIN32) || defined(__CYGWIN__) + if (WIFSIGNALED(state->exit_status)) { +#ifdef SIGPIPE + /* If the child died because we stopped reading before + * it was done, that's okay. Some archive formats + * have padding at the end that we routinely ignore. */ + /* The alternative to this would be to add a step + * before close(child_stdout) above to read from the + * child until the child has no more to write. */ + if (WTERMSIG(state->exit_status) == SIGPIPE) + return (ARCHIVE_OK); +#endif + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Child process exited with signal %d", + WTERMSIG(state->exit_status)); + return (ARCHIVE_WARN); + } +#endif /* !_WIN32 || __CYGWIN__ */ + + if (WIFEXITED(state->exit_status)) { + if (WEXITSTATUS(state->exit_status) == 0) + return (ARCHIVE_OK); + + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Child process exited with status %d", + WEXITSTATUS(state->exit_status)); + return (ARCHIVE_WARN); + } + + return (ARCHIVE_WARN); +} + +/* + * Use select() to decide whether the child is ready for read or write. + */ +static ssize_t +child_read(struct archive_read_filter *self, char *buf, size_t buf_len) +{ + struct program_filter *state = self->data; + ssize_t ret, requested, avail; + const char *p; + + requested = buf_len > SSIZE_MAX ? SSIZE_MAX : buf_len; + + for (;;) { + do { + ret = read(state->child_stdout, buf, requested); + } while (ret == -1 && errno == EINTR); + + if (ret > 0) + return (ret); + if (ret == 0 || (ret == -1 && errno == EPIPE)) + /* Child has closed its output; reap the child + * and return the status. */ + return (child_stop(self, state)); + if (ret == -1 && errno != EAGAIN) + return (-1); + + if (state->child_stdin == -1) { + /* Block until child has some I/O ready. */ + __archive_check_child(state->child_stdin, + state->child_stdout); + continue; + } + + /* Get some more data from upstream. */ + p = __archive_read_filter_ahead(self->upstream, 1, &avail); + if (p == NULL) { + close(state->child_stdin); + state->child_stdin = -1; + fcntl(state->child_stdout, F_SETFL, 0); + if (avail < 0) + return (avail); + continue; + } + + do { + ret = write(state->child_stdin, p, avail); + } while (ret == -1 && errno == EINTR); + + if (ret > 0) { + /* Consume whatever we managed to write. */ + __archive_read_filter_consume(self->upstream, ret); + } else if (ret == -1 && errno == EAGAIN) { + /* Block until child has some I/O ready. */ + __archive_check_child(state->child_stdin, + state->child_stdout); + } else { + /* Write failed. */ + close(state->child_stdin); + state->child_stdin = -1; + fcntl(state->child_stdout, F_SETFL, 0); + /* If it was a bad error, we're done; otherwise + * it was EPIPE or EOF, and we can still read + * from the child. */ + if (ret == -1 && errno != EPIPE) + return (-1); + } + } +} + +int +__archive_read_program(struct archive_read_filter *self, const char *cmd) +{ + struct program_filter *state; + static const size_t out_buf_len = 65536; + char *out_buf; + char *description; + const char *prefix = "Program: "; + + state = (struct program_filter *)calloc(1, sizeof(*state)); + out_buf = (char *)malloc(out_buf_len); + description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); + if (state == NULL || out_buf == NULL || description == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate input data"); + free(state); + free(out_buf); + free(description); + return (ARCHIVE_FATAL); + } + + self->code = ARCHIVE_COMPRESSION_PROGRAM; + state->description = description; + strcpy(state->description, prefix); + strcat(state->description, cmd); + self->name = state->description; + + state->out_buf = out_buf; + state->out_buf_len = out_buf_len; + + if ((state->child = __archive_create_child(cmd, + &state->child_stdin, &state->child_stdout)) == -1) { + free(state->out_buf); + free(state); + archive_set_error(&self->archive->archive, EINVAL, + "Can't initialize filter; unable to run program \"%s\"", cmd); + return (ARCHIVE_FATAL); + } + + self->data = state; + self->read = program_filter_read; + self->skip = NULL; + self->close = program_filter_close; + + /* XXX Check that we can read at least one byte? */ + return (ARCHIVE_OK); +} + +static int +program_bidder_init(struct archive_read_filter *self) +{ + struct program_bidder *bidder_state; + + bidder_state = (struct program_bidder *)self->bidder->data; + return (__archive_read_program(self, bidder_state->cmd)); +} + +static ssize_t +program_filter_read(struct archive_read_filter *self, const void **buff) +{ + struct program_filter *state; + ssize_t bytes; + size_t total; + char *p; + + state = (struct program_filter *)self->data; + + total = 0; + p = state->out_buf; + while (state->child_stdout != -1 && total < state->out_buf_len) { + bytes = child_read(self, p, state->out_buf_len - total); + if (bytes < 0) + /* No recovery is possible if we can no longer + * read from the child. */ + return (ARCHIVE_FATAL); + if (bytes == 0) + /* We got EOF from the child. */ + break; + total += bytes; + p += bytes; + } + + *buff = state->out_buf; + return (total); +} + +static int +program_filter_close(struct archive_read_filter *self) +{ + struct program_filter *state; + int e; + + state = (struct program_filter *)self->data; + e = child_stop(self, state); + + /* Release our private data. */ + free(state->out_buf); + free(state->description); + free(state); + + return (e); +} + +#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c new file mode 100644 index 000000000..7dbfc0ebc --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_rpm.c @@ -0,0 +1,288 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * 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" + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_private.h" +#include "archive_read_private.h" + +struct rpm { + int64_t total_in; + size_t hpos; + size_t hlen; + unsigned char header[16]; + enum { + ST_LEAD, /* Skipping 'Lead' section. */ + ST_HEADER, /* Reading 'Header' section; + * first 16 bytes. */ + ST_HEADER_DATA, /* Skipping 'Header' section. */ + ST_PADDING, /* Skipping padding data after the + * 'Header' section. */ + ST_ARCHIVE /* Reading 'Archive' section. */ + } state; + int first_header; +}; +#define RPM_LEAD_SIZE 96 /* Size of 'Lead' section. */ + +static int rpm_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int rpm_bidder_init(struct archive_read_filter *); + +static ssize_t rpm_filter_read(struct archive_read_filter *, + const void **); +static int rpm_filter_close(struct archive_read_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_rpm(struct archive *a) +{ + return archive_read_support_filter_rpm(a); +} +#endif + +int +archive_read_support_filter_rpm(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_rpm"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = rpm_bidder_bid; + bidder->init = rpm_bidder_init; + bidder->options = NULL; + bidder->free = NULL; + return (ARCHIVE_OK); +} + +static int +rpm_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *b; + ssize_t avail; + int bits_checked; + + (void)self; /* UNUSED */ + + b = __archive_read_filter_ahead(filter, 8, &avail); + if (b == NULL) + return (0); + + bits_checked = 0; + /* + * Verify Header Magic Bytes : 0XED 0XAB 0XEE 0XDB + */ + if (memcmp(b, "\xED\xAB\xEE\xDB", 4) != 0) + return (0); + bits_checked += 32; + /* + * Check major version. + */ + if (b[4] != 3 && b[4] != 4) + return (0); + bits_checked += 8; + /* + * Check package type; binary or source. + */ + if (b[6] != 0) + return (0); + bits_checked += 8; + if (b[7] != 0 && b[7] != 1) + return (0); + bits_checked += 8; + + return (bits_checked); +} + +static int +rpm_bidder_init(struct archive_read_filter *self) +{ + struct rpm *rpm; + + self->code = ARCHIVE_COMPRESSION_RPM; + self->name = "rpm"; + self->read = rpm_filter_read; + self->skip = NULL; /* not supported */ + self->close = rpm_filter_close; + + rpm = (struct rpm *)calloc(sizeof(*rpm), 1); + if (rpm == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for rpm"); + return (ARCHIVE_FATAL); + } + + self->data = rpm; + rpm->state = ST_LEAD; + + return (ARCHIVE_OK); +} + +static ssize_t +rpm_filter_read(struct archive_read_filter *self, const void **buff) +{ + struct rpm *rpm; + const unsigned char *b; + ssize_t avail_in, total; + size_t used, n; + uint32_t section; + uint32_t bytes; + + rpm = (struct rpm *)self->data; + *buff = NULL; + total = avail_in = 0; + b = NULL; + used = 0; + do { + if (b == NULL) { + b = __archive_read_filter_ahead(self->upstream, 1, + &avail_in); + if (b == NULL) { + if (avail_in < 0) + return (ARCHIVE_FATAL); + else + break; + } + } + + switch (rpm->state) { + case ST_LEAD: + if (rpm->total_in + avail_in < RPM_LEAD_SIZE) + used += avail_in; + else { + n = RPM_LEAD_SIZE - rpm->total_in; + used += n; + b += n; + rpm->state = ST_HEADER; + rpm->hpos = 0; + rpm->hlen = 0; + rpm->first_header = 1; + } + break; + case ST_HEADER: + n = 16 - rpm->hpos; + if (n > avail_in - used) + n = avail_in - used; + memcpy(rpm->header+rpm->hpos, b, n); + b += n; + used += n; + rpm->hpos += n; + + if (rpm->hpos == 16) { + if (rpm->header[0] != 0x8e || + rpm->header[1] != 0xad || + rpm->header[2] != 0xe8 || + rpm->header[3] != 0x01) { + if (rpm->first_header) { + archive_set_error( + &self->archive->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unrecoginized rpm header"); + return (ARCHIVE_FATAL); + } + rpm->state = ST_ARCHIVE; + *buff = rpm->header; + total = rpm->hpos; + break; + } + /* Calculate 'Header' length. */ + section = archive_be32dec(rpm->header+8); + bytes = archive_be32dec(rpm->header+12); + rpm->hlen = 16 + section * 16 + bytes; + rpm->state = ST_HEADER_DATA; + rpm->first_header = 0; + } + break; + case ST_HEADER_DATA: + n = rpm->hlen - rpm->hpos; + if (n > avail_in - used) + n = avail_in - used; + b += n; + used += n; + rpm->hpos += n; + if (rpm->hpos == rpm->hlen) + rpm->state = ST_PADDING; + break; + case ST_PADDING: + while (used < (size_t)avail_in) { + if (*b != 0) { + /* Read next header. */ + rpm->state = ST_HEADER; + rpm->hpos = 0; + rpm->hlen = 0; + break; + } + b++; + used++; + } + break; + case ST_ARCHIVE: + *buff = b; + total = avail_in; + used = avail_in; + break; + } + if (used == (size_t)avail_in) { + rpm->total_in += used; + __archive_read_filter_consume(self->upstream, used); + b = NULL; + used = 0; + } + } while (total == 0 && avail_in > 0); + + if (used > 0 && b != NULL) { + rpm->total_in += used; + __archive_read_filter_consume(self->upstream, used); + } + return (total); +} + +static int +rpm_filter_close(struct archive_read_filter *self) +{ + struct rpm *rpm; + + rpm = (struct rpm *)self->data; + free(rpm); + + return (ARCHIVE_OK); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c new file mode 100644 index 000000000..a75ef7560 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_uu.c @@ -0,0 +1,680 @@ +/*- + * Copyright (c) 2009-2011 Michihiro NAKAJIMA + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_read_private.h" + +/* Maximum lookahead during bid phase */ +#define UUENCODE_BID_MAX_READ 128*1024 /* in bytes */ + +struct uudecode { + int64_t total; + unsigned char *in_buff; +#define IN_BUFF_SIZE (1024) + int in_cnt; + size_t in_allocated; + unsigned char *out_buff; +#define OUT_BUFF_SIZE (64 * 1024) + int state; +#define ST_FIND_HEAD 0 +#define ST_READ_UU 1 +#define ST_UUEND 2 +#define ST_READ_BASE64 3 +}; + +static int uudecode_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *filter); +static int uudecode_bidder_init(struct archive_read_filter *); + +static ssize_t uudecode_filter_read(struct archive_read_filter *, + const void **); +static int uudecode_filter_close(struct archive_read_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_uu(struct archive *a) +{ + return archive_read_support_filter_uu(a); +} +#endif + +int +archive_read_support_filter_uu(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_uu"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = uudecode_bidder_bid; + bidder->init = uudecode_bidder_init; + bidder->options = NULL; + bidder->free = NULL; + return (ARCHIVE_OK); +} + +static const unsigned char ascii[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\n', 0, 0, '\r', 0, 0, /* 00 - 0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ +}; + +static const unsigned char uuchar[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 30 - 3F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 60 - 6F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ +}; + +static const unsigned char base64[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, /* 20 - 2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, /* 30 - 3F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 50 - 5F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ +}; + +static const int base64num[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 62, 0, 0, 0, 63, /* 20 - 2F */ + 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 0, 0, 0, 0, 0, 0, /* 30 - 3F */ + 0, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */ + 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 0, 0, 0, 0, 0, /* 50 - 5F */ + 0, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */ + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 0, 0, 0, 0, 0, /* 70 - 7F */ +}; + +static ssize_t +get_line(const unsigned char *b, ssize_t avail, ssize_t *nlsize) +{ + ssize_t len; + + len = 0; + while (len < avail) { + switch (ascii[*b]) { + case 0: /* Non-ascii character or control character. */ + if (nlsize != NULL) + *nlsize = 0; + return (-1); + case '\r': + if (avail-len > 1 && b[1] == '\n') { + if (nlsize != NULL) + *nlsize = 2; + return (len+2); + } + /* FALL THROUGH */ + case '\n': + if (nlsize != NULL) + *nlsize = 1; + return (len+1); + case 1: + b++; + len++; + break; + } + } + if (nlsize != NULL) + *nlsize = 0; + return (avail); +} + +static ssize_t +bid_get_line(struct archive_read_filter *filter, + const unsigned char **b, ssize_t *avail, ssize_t *ravail, + ssize_t *nl, size_t* nbytes_read) +{ + ssize_t len; + int quit; + + quit = 0; + if (*avail == 0) { + *nl = 0; + len = 0; + } else + len = get_line(*b, *avail, nl); + + /* + * Read bytes more while it does not reach the end of line. + */ + while (*nl == 0 && len == *avail && !quit && + *nbytes_read < UUENCODE_BID_MAX_READ) { + ssize_t diff = *ravail - *avail; + size_t nbytes_req = (*ravail+1023) & ~1023U; + ssize_t tested; + + /* Increase reading bytes if it is not enough to at least + * new two lines. */ + if (nbytes_req < (size_t)*ravail + 160) + nbytes_req <<= 1; + + *b = __archive_read_filter_ahead(filter, nbytes_req, avail); + if (*b == NULL) { + if (*ravail >= *avail) + return (0); + /* Reading bytes reaches the end of a stream. */ + *b = __archive_read_filter_ahead(filter, *avail, avail); + quit = 1; + } + *nbytes_read = *avail; + *ravail = *avail; + *b += diff; + *avail -= diff; + tested = len;/* Skip some bytes we already determinated. */ + len = get_line(*b + tested, *avail - tested, nl); + if (len >= 0) + len += tested; + } + return (len); +} + +#define UUDECODE(c) (((c) - 0x20) & 0x3f) + +static int +uudecode_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *b; + ssize_t avail, ravail; + ssize_t len, nl; + int l; + int firstline; + size_t nbytes_read; + + (void)self; /* UNUSED */ + + b = __archive_read_filter_ahead(filter, 1, &avail); + if (b == NULL) + return (0); + + firstline = 20; + ravail = avail; + nbytes_read = avail; + for (;;) { + len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read); + if (len < 0 || nl == 0) + return (0); /* No match found. */ + if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) + l = 6; + else if (len -nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0) + l = 13; + else + l = 0; + + if (l > 0 && (b[l] < '0' || b[l] > '7' || + b[l+1] < '0' || b[l+1] > '7' || + b[l+2] < '0' || b[l+2] > '7' || b[l+3] != ' ')) + l = 0; + + b += len; + avail -= len; + if (l) + break; + firstline = 0; + + /* Do not read more than UUENCODE_BID_MAX_READ bytes */ + if (nbytes_read >= UUENCODE_BID_MAX_READ) + return (0); + } + if (!avail) + return (0); + len = bid_get_line(filter, &b, &avail, &ravail, &nl, &nbytes_read); + if (len < 0 || nl == 0) + return (0);/* There are non-ascii characters. */ + avail -= len; + + if (l == 6) { + if (!uuchar[*b]) + return (0); + /* Get a length of decoded bytes. */ + l = UUDECODE(*b++); len--; + if (l > 45) + /* Normally, maximum length is 45(character 'M'). */ + return (0); + while (l && len-nl > 0) { + if (l > 0) { + if (!uuchar[*b++]) + return (0); + if (!uuchar[*b++]) + return (0); + len -= 2; + --l; + } + if (l > 0) { + if (!uuchar[*b++]) + return (0); + --len; + --l; + } + if (l > 0) { + if (!uuchar[*b++]) + return (0); + --len; + --l; + } + } + if (len-nl < 0) + return (0); + if (len-nl == 1 && + (uuchar[*b] || /* Check sum. */ + (*b >= 'a' && *b <= 'z'))) {/* Padding data(MINIX). */ + ++b; + --len; + } + b += nl; + if (avail && uuchar[*b]) + return (firstline+30); + } + if (l == 13) { + while (len-nl > 0) { + if (!base64[*b++]) + return (0); + --len; + } + b += nl; + + if (avail >= 5 && memcmp(b, "====\n", 5) == 0) + return (firstline+40); + if (avail >= 6 && memcmp(b, "====\r\n", 6) == 0) + return (firstline+40); + if (avail > 0 && base64[*b]) + return (firstline+30); + } + + return (0); +} + +static int +uudecode_bidder_init(struct archive_read_filter *self) +{ + struct uudecode *uudecode; + void *out_buff; + void *in_buff; + + self->code = ARCHIVE_COMPRESSION_UU; + self->name = "uu"; + self->read = uudecode_filter_read; + self->skip = NULL; /* not supported */ + self->close = uudecode_filter_close; + + uudecode = (struct uudecode *)calloc(sizeof(*uudecode), 1); + out_buff = malloc(OUT_BUFF_SIZE); + in_buff = malloc(IN_BUFF_SIZE); + if (uudecode == NULL || out_buff == NULL || in_buff == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for uudecode"); + free(uudecode); + free(out_buff); + free(in_buff); + return (ARCHIVE_FATAL); + } + + self->data = uudecode; + uudecode->in_buff = in_buff; + uudecode->in_cnt = 0; + uudecode->in_allocated = IN_BUFF_SIZE; + uudecode->out_buff = out_buff; + uudecode->state = ST_FIND_HEAD; + + return (ARCHIVE_OK); +} + +static int +ensure_in_buff_size(struct archive_read_filter *self, + struct uudecode *uudecode, size_t size) +{ + + if (size > uudecode->in_allocated) { + unsigned char *ptr; + size_t newsize; + + /* + * Calculate a new buffer size for in_buff. + * Increase its value until it has enough size we need. + */ + newsize = uudecode->in_allocated; + do { + if (newsize < IN_BUFF_SIZE*32) + newsize <<= 1; + else + newsize += IN_BUFF_SIZE; + } while (size > newsize); + /* Allocate the new buffer. */ + ptr = malloc(newsize); + if (ptr == NULL) { + free(ptr); + archive_set_error(&self->archive->archive, + ENOMEM, + "Can't allocate data for uudecode"); + return (ARCHIVE_FATAL); + } + /* Move the remaining data in in_buff into the new buffer. */ + if (uudecode->in_cnt) + memmove(ptr, uudecode->in_buff, uudecode->in_cnt); + /* Replace in_buff with the new buffer. */ + free(uudecode->in_buff); + uudecode->in_buff = ptr; + uudecode->in_allocated = newsize; + } + return (ARCHIVE_OK); +} + +static ssize_t +uudecode_filter_read(struct archive_read_filter *self, const void **buff) +{ + struct uudecode *uudecode; + const unsigned char *b, *d; + unsigned char *out; + ssize_t avail_in, ravail; + ssize_t used; + ssize_t total; + ssize_t len, llen, nl; + + uudecode = (struct uudecode *)self->data; + +read_more: + d = __archive_read_filter_ahead(self->upstream, 1, &avail_in); + if (d == NULL && avail_in < 0) + return (ARCHIVE_FATAL); + /* Quiet a code analyzer; make sure avail_in must be zero + * when d is NULL. */ + if (d == NULL) + avail_in = 0; + used = 0; + total = 0; + out = uudecode->out_buff; + ravail = avail_in; + if (uudecode->in_cnt) { + /* + * If there is remaining data which is saved by + * previous calling, use it first. + */ + if (ensure_in_buff_size(self, uudecode, + avail_in + uudecode->in_cnt) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + memcpy(uudecode->in_buff + uudecode->in_cnt, + d, avail_in); + d = uudecode->in_buff; + avail_in += uudecode->in_cnt; + uudecode->in_cnt = 0; + } + for (;used < avail_in; d += llen, used += llen) { + int l, body; + + b = d; + len = get_line(b, avail_in - used, &nl); + if (len < 0) { + /* Non-ascii character is found. */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + llen = len; + if (nl == 0) { + /* + * Save remaining data which does not contain + * NL('\n','\r'). + */ + if (ensure_in_buff_size(self, uudecode, len) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (uudecode->in_buff != b) + memmove(uudecode->in_buff, b, len); + uudecode->in_cnt = len; + if (total == 0) { + /* Do not return 0; it means end-of-file. + * We should try to read bytes more. */ + __archive_read_filter_consume( + self->upstream, ravail); + goto read_more; + } + break; + } + switch (uudecode->state) { + default: + case ST_FIND_HEAD: + /* Do not read more than UUENCODE_BID_MAX_READ bytes */ + if (total + len >= UUENCODE_BID_MAX_READ) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid format data"); + return (ARCHIVE_FATAL); + } + if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) + l = 6; + else if (len - nl >= 18 && + memcmp(b, "begin-base64 ", 13) == 0) + l = 13; + else + l = 0; + if (l != 0 && b[l] >= '0' && b[l] <= '7' && + b[l+1] >= '0' && b[l+1] <= '7' && + b[l+2] >= '0' && b[l+2] <= '7' && b[l+3] == ' ') { + if (l == 6) + uudecode->state = ST_READ_UU; + else + uudecode->state = ST_READ_BASE64; + } + break; + case ST_READ_UU: + if (total + len * 2 > OUT_BUFF_SIZE) + break; + body = len - nl; + if (!uuchar[*b] || body <= 0) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + /* Get length of undecoded bytes of curent line. */ + l = UUDECODE(*b++); + body--; + if (l > body) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + if (l == 0) { + uudecode->state = ST_UUEND; + break; + } + while (l > 0) { + int n = 0; + + if (l > 0) { + if (!uuchar[b[0]] || !uuchar[b[1]]) + break; + n = UUDECODE(*b++) << 18; + n |= UUDECODE(*b++) << 12; + *out++ = n >> 16; total++; + --l; + } + if (l > 0) { + if (!uuchar[b[0]]) + break; + n |= UUDECODE(*b++) << 6; + *out++ = (n >> 8) & 0xFF; total++; + --l; + } + if (l > 0) { + if (!uuchar[b[0]]) + break; + n |= UUDECODE(*b++); + *out++ = n & 0xFF; total++; + --l; + } + } + if (l) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + break; + case ST_UUEND: + if (len - nl == 3 && memcmp(b, "end ", 3) == 0) + uudecode->state = ST_FIND_HEAD; + else { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + break; + case ST_READ_BASE64: + if (total + len * 2 > OUT_BUFF_SIZE) + break; + l = len - nl; + if (l >= 3 && b[0] == '=' && b[1] == '=' && + b[2] == '=') { + uudecode->state = ST_FIND_HEAD; + break; + } + while (l > 0) { + int n = 0; + + if (l > 0) { + if (!base64[b[0]] || !base64[b[1]]) + break; + n = base64num[*b++] << 18; + n |= base64num[*b++] << 12; + *out++ = n >> 16; total++; + l -= 2; + } + if (l > 0) { + if (*b == '=') + break; + if (!base64[*b]) + break; + n |= base64num[*b++] << 6; + *out++ = (n >> 8) & 0xFF; total++; + --l; + } + if (l > 0) { + if (*b == '=') + break; + if (!base64[*b]) + break; + n |= base64num[*b++]; + *out++ = n & 0xFF; total++; + --l; + } + } + if (l && *b != '=') { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + } + break; + } + } + + __archive_read_filter_consume(self->upstream, ravail); + + *buff = uudecode->out_buff; + uudecode->total += total; + return (total); +} + +static int +uudecode_filter_close(struct archive_read_filter *self) +{ + struct uudecode *uudecode; + + uudecode = (struct uudecode *)self->data; + free(uudecode->in_buff); + free(uudecode->out_buff); + free(uudecode); + + return (ARCHIVE_OK); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c new file mode 100644 index 000000000..cf762a46d --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_filter_xz.c @@ -0,0 +1,985 @@ +/*- + * Copyright (c) 2009-2011 Michihiro NAKAJIMA + * Copyright (c) 2003-2008 Tim Kientzle and Miklos Vajna + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#if HAVE_LZMA_H +#include +#elif HAVE_LZMADEC_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#if HAVE_LZMA_H && HAVE_LIBLZMA + +struct private_data { + lzma_stream stream; + unsigned char *out_block; + size_t out_block_size; + int64_t total_out; + char eof; /* True = found end of compressed data. */ + char in_stream; + + /* Following variables are used for lzip only. */ + char lzip_ver; + uint32_t crc32; + int64_t member_in; + int64_t member_out; +}; + +#if LZMA_VERSION_MAJOR >= 5 +/* Effectively disable the limiter. */ +#define LZMA_MEMLIMIT UINT64_MAX +#else +/* NOTE: This needs to check memory size which running system has. */ +#define LZMA_MEMLIMIT (1U << 30) +#endif + +/* Combined lzip/lzma/xz filter */ +static ssize_t xz_filter_read(struct archive_read_filter *, const void **); +static int xz_filter_close(struct archive_read_filter *); +static int xz_lzma_bidder_init(struct archive_read_filter *); + +#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC + +struct private_data { + lzmadec_stream stream; + unsigned char *out_block; + size_t out_block_size; + int64_t total_out; + char eof; /* True = found end of compressed data. */ +}; + +/* Lzma-only filter */ +static ssize_t lzma_filter_read(struct archive_read_filter *, const void **); +static int lzma_filter_close(struct archive_read_filter *); +#endif + +/* + * Note that we can detect xz and lzma compressed files even if we + * can't decompress them. (In fact, we like detecting them because we + * can give better error messages.) So the bid framework here gets + * compiled even if no lzma library is available. + */ +static int xz_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int xz_bidder_init(struct archive_read_filter *); +static int lzma_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int lzma_bidder_init(struct archive_read_filter *); +static int lzip_has_member(struct archive_read_filter *); +static int lzip_bidder_bid(struct archive_read_filter_bidder *, + struct archive_read_filter *); +static int lzip_bidder_init(struct archive_read_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* Deprecated; remove in libarchive 4.0 */ +int +archive_read_support_compression_xz(struct archive *a) +{ + return archive_read_support_filter_xz(a); +} +#endif + +int +archive_read_support_filter_xz(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_xz"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = xz_bidder_bid; + bidder->init = xz_bidder_init; + bidder->options = NULL; + bidder->free = NULL; +#if HAVE_LZMA_H && HAVE_LIBLZMA + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external unxz program for xz decompression"); + return (ARCHIVE_WARN); +#endif +} + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_read_support_compression_lzma(struct archive *a) +{ + return archive_read_support_filter_lzma(a); +} +#endif + +int +archive_read_support_filter_lzma(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_lzma"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = lzma_bidder_bid; + bidder->init = lzma_bidder_init; + bidder->options = NULL; + bidder->free = NULL; +#if HAVE_LZMA_H && HAVE_LIBLZMA + return (ARCHIVE_OK); +#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external unlzma program for lzma decompression"); + return (ARCHIVE_WARN); +#endif +} + + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_read_support_compression_lzip(struct archive *a) +{ + return archive_read_support_filter_lzip(a); +} +#endif + +int +archive_read_support_filter_lzip(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct archive_read_filter_bidder *bidder; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_filter_lzip"); + + if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + bidder->data = NULL; + bidder->bid = lzip_bidder_bid; + bidder->init = lzip_bidder_init; + bidder->options = NULL; + bidder->free = NULL; +#if HAVE_LZMA_H && HAVE_LIBLZMA + return (ARCHIVE_OK); +#else + archive_set_error(_a, ARCHIVE_ERRNO_MISC, + "Using external lzip program for lzip decompression"); + return (ARCHIVE_WARN); +#endif +} + +/* + * Test whether we can handle this data. + */ +static int +xz_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + + (void)self; /* UNUSED */ + + buffer = __archive_read_filter_ahead(filter, 6, &avail); + if (buffer == NULL) + return (0); + + /* + * Verify Header Magic Bytes : FD 37 7A 58 5A 00 + */ + if (memcmp(buffer, "\xFD\x37\x7A\x58\x5A\x00", 6) != 0) + return (0); + + return (48); +} + +/* + * Test whether we can handle this data. + * + * LZMA has a rather poor file signature. Zeros do not + * make good signature bytes as a rule, and the only non-zero byte + * here is an ASCII character. For example, an uncompressed tar + * archive whose first file is ']' would satisfy this check. It may + * be necessary to exclude LZMA from compression_all() because of + * this. Clients of libarchive would then have to explicitly enable + * LZMA checking instead of (or in addition to) compression_all() when + * they have other evidence (file name, command-line option) to go on. + */ +static int +lzma_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + uint32_t dicsize; + uint64_t uncompressed_size; + int bits_checked; + + (void)self; /* UNUSED */ + + buffer = __archive_read_filter_ahead(filter, 14, &avail); + if (buffer == NULL) + return (0); + + /* First byte of raw LZMA stream is commonly 0x5d. + * The first byte is a special number, which consists of + * three parameters of LZMA compression, a number of literal + * context bits(which is from 0 to 8, default is 3), a number + * of literal pos bits(which is from 0 to 4, default is 0), + * a number of pos bits(which is from 0 to 4, default is 2). + * The first byte is made by + * (pos bits * 5 + literal pos bit) * 9 + * literal contest bit, + * and so the default value in this field is + * (2 * 5 + 0) * 9 + 3 = 0x5d. + * lzma of LZMA SDK has options to change those parameters. + * It means a range of this field is from 0 to 224. And lzma of + * XZ Utils with option -e records 0x5e in this field. */ + /* NOTE: If this checking of the first byte increases false + * recognition, we should allow only 0x5d and 0x5e for the first + * byte of LZMA stream. */ + bits_checked = 0; + if (buffer[0] > (4 * 5 + 4) * 9 + 8) + return (0); + /* Most likely value in the first byte of LZMA stream. */ + if (buffer[0] == 0x5d || buffer[0] == 0x5e) + bits_checked += 8; + + /* Sixth through fourteenth bytes are uncompressed size, + * stored in little-endian order. `-1' means uncompressed + * size is unknown and lzma of XZ Utils always records `-1' + * in this field. */ + uncompressed_size = archive_le64dec(buffer+5); + if (uncompressed_size == (uint64_t)ARCHIVE_LITERAL_LL(-1)) + bits_checked += 64; + + /* Second through fifth bytes are dictionary size, stored in + * little-endian order. The minimum dictionary size is + * 1 << 12(4KiB) which the lzma of LZMA SDK uses with option + * -d12 and the maxinam dictionary size is 1 << 27(128MiB) + * which the one uses with option -d27. + * NOTE: A comment of LZMA SDK source code says this dictionary + * range is from 1 << 12 to 1 << 30. */ + dicsize = archive_le32dec(buffer+1); + switch (dicsize) { + case 0x00001000:/* lzma of LZMA SDK option -d12. */ + case 0x00002000:/* lzma of LZMA SDK option -d13. */ + case 0x00004000:/* lzma of LZMA SDK option -d14. */ + case 0x00008000:/* lzma of LZMA SDK option -d15. */ + case 0x00010000:/* lzma of XZ Utils option -0 and -1. + * lzma of LZMA SDK option -d16. */ + case 0x00020000:/* lzma of LZMA SDK option -d17. */ + case 0x00040000:/* lzma of LZMA SDK option -d18. */ + case 0x00080000:/* lzma of XZ Utils option -2. + * lzma of LZMA SDK option -d19. */ + case 0x00100000:/* lzma of XZ Utils option -3. + * lzma of LZMA SDK option -d20. */ + case 0x00200000:/* lzma of XZ Utils option -4. + * lzma of LZMA SDK option -d21. */ + case 0x00400000:/* lzma of XZ Utils option -5. + * lzma of LZMA SDK option -d22. */ + case 0x00800000:/* lzma of XZ Utils option -6. + * lzma of LZMA SDK option -d23. */ + case 0x01000000:/* lzma of XZ Utils option -7. + * lzma of LZMA SDK option -d24. */ + case 0x02000000:/* lzma of XZ Utils option -8. + * lzma of LZMA SDK option -d25. */ + case 0x04000000:/* lzma of XZ Utils option -9. + * lzma of LZMA SDK option -d26. */ + case 0x08000000:/* lzma of LZMA SDK option -d27. */ + bits_checked += 32; + break; + default: + /* If a memory usage for encoding was not enough on + * the platform where LZMA stream was made, lzma of + * XZ Utils automatically decreased the dictionary + * size to enough memory for encoding by 1Mi bytes + * (1 << 20).*/ + if (dicsize <= 0x03F00000 && dicsize >= 0x00300000 && + (dicsize & ((1 << 20)-1)) == 0 && + bits_checked == 8 + 64) { + bits_checked += 32; + break; + } + /* Otherwise dictionary size is unlikely. But it is + * possible that someone makes lzma stream with + * liblzma/LZMA SDK in one's dictionary size. */ + return (0); + } + + /* TODO: The above test is still very weak. It would be + * good to do better. */ + + return (bits_checked); +} + +static int +lzip_has_member(struct archive_read_filter *filter) +{ + const unsigned char *buffer; + ssize_t avail; + int bits_checked; + int log2dic; + + buffer = __archive_read_filter_ahead(filter, 6, &avail); + if (buffer == NULL) + return (0); + + /* + * Verify Header Magic Bytes : 4C 5A 49 50 (`LZIP') + */ + bits_checked = 0; + if (memcmp(buffer, "LZIP", 4) != 0) + return (0); + bits_checked += 32; + + /* A version number must be 0 or 1 */ + if (buffer[4] != 0 && buffer[4] != 1) + return (0); + bits_checked += 8; + + /* Dictionary size. */ + log2dic = buffer[5] & 0x1f; + if (log2dic < 12 || log2dic > 27) + return (0); + bits_checked += 8; + + return (bits_checked); +} + +static int +lzip_bidder_bid(struct archive_read_filter_bidder *self, + struct archive_read_filter *filter) +{ + + (void)self; /* UNUSED */ + return (lzip_has_member(filter)); +} + +#if HAVE_LZMA_H && HAVE_LIBLZMA + +/* + * liblzma 4.999.7 and later support both lzma and xz streams. + */ +static int +xz_bidder_init(struct archive_read_filter *self) +{ + self->code = ARCHIVE_COMPRESSION_XZ; + self->name = "xz"; + return (xz_lzma_bidder_init(self)); +} + +static int +lzma_bidder_init(struct archive_read_filter *self) +{ + self->code = ARCHIVE_COMPRESSION_LZMA; + self->name = "lzma"; + return (xz_lzma_bidder_init(self)); +} + +static int +lzip_bidder_init(struct archive_read_filter *self) +{ + self->code = ARCHIVE_COMPRESSION_LZIP; + self->name = "lzip"; + return (xz_lzma_bidder_init(self)); +} + +/* + * Set an error code and choose an error message + */ +static void +set_error(struct archive_read_filter *self, int ret) +{ + + switch (ret) { + case LZMA_STREAM_END: /* Found end of stream. */ + case LZMA_OK: /* Decompressor made some progress. */ + break; + case LZMA_MEM_ERROR: + archive_set_error(&self->archive->archive, ENOMEM, + "Lzma library error: Cannot allocate memory"); + break; + case LZMA_MEMLIMIT_ERROR: + archive_set_error(&self->archive->archive, ENOMEM, + "Lzma library error: Out of memory"); + break; + case LZMA_FORMAT_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: format not recognized"); + break; + case LZMA_OPTIONS_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Invalid options"); + break; + case LZMA_DATA_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Corrupted input data"); + break; + case LZMA_BUF_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: No progress is possible"); + break; + default: + /* Return an error. */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma decompression failed: Unknown error"); + break; + } +} + +/* + * Setup the callbacks. + */ +static int +xz_lzma_bidder_init(struct archive_read_filter *self) +{ + static const size_t out_block_size = 64 * 1024; + void *out_block; + struct private_data *state; + int ret; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = (unsigned char *)malloc(out_block_size); + if (state == NULL || out_block == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for xz decompression"); + free(out_block); + free(state); + return (ARCHIVE_FATAL); + } + + self->data = state; + state->out_block_size = out_block_size; + state->out_block = out_block; + self->read = xz_filter_read; + self->skip = NULL; /* not supported */ + self->close = xz_filter_close; + + state->stream.avail_in = 0; + + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + state->crc32 = 0; + if (self->code == ARCHIVE_COMPRESSION_LZIP) { + /* + * We have to read a lzip header and use it to initialize + * compression library, thus we cannot initialize the + * library for lzip here. + */ + state->in_stream = 0; + return (ARCHIVE_OK); + } else + state->in_stream = 1; + + /* Initialize compression library. */ + if (self->code == ARCHIVE_COMPRESSION_XZ) + ret = lzma_stream_decoder(&(state->stream), + LZMA_MEMLIMIT,/* memlimit */ + LZMA_CONCATENATED); + else + ret = lzma_alone_decoder(&(state->stream), + LZMA_MEMLIMIT);/* memlimit */ + + if (ret == LZMA_OK) + return (ARCHIVE_OK); + + /* Library setup failed: Choose an error message and clean up. */ + set_error(self, ret); + + free(state->out_block); + free(state); + self->data = NULL; + return (ARCHIVE_FATAL); +} + +static int +lzip_init(struct archive_read_filter *self) +{ + struct private_data *state; + const unsigned char *h; + lzma_filter filters[2]; + unsigned char props[5]; + ssize_t avail_in; + uint32_t dicsize; + int log2dic, ret; + + state = (struct private_data *)self->data; + h = __archive_read_filter_ahead(self->upstream, 6, &avail_in); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Get a version number. */ + state->lzip_ver = h[4]; + + /* + * Setup lzma property. + */ + props[0] = 0x5d; + + /* Get dictionary size. */ + log2dic = h[5] & 0x1f; + if (log2dic < 12 || log2dic > 27) + return (ARCHIVE_FATAL); + dicsize = 1U << log2dic; + if (log2dic > 12) + dicsize -= (dicsize / 16) * (h[5] >> 5); + archive_le32enc(props+1, dicsize); + + /* Consume lzip header. */ + __archive_read_filter_consume(self->upstream, 6); + state->member_in = 6; + + filters[0].id = LZMA_FILTER_LZMA1; + filters[0].options = NULL; + filters[1].id = LZMA_VLI_UNKNOWN; + filters[1].options = NULL; + + ret = lzma_properties_decode(&filters[0], NULL, props, sizeof(props)); + if (ret != LZMA_OK) { + set_error(self, ret); + return (ARCHIVE_FATAL); + } + ret = lzma_raw_decoder(&(state->stream), filters); +#if LZMA_VERSION < 50000030 + free(filters[0].options); +#endif + if (ret != LZMA_OK) { + set_error(self, ret); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static int +lzip_tail(struct archive_read_filter *self) +{ + struct private_data *state; + const unsigned char *f; + ssize_t avail_in; + int tail; + + state = (struct private_data *)self->data; + if (state->lzip_ver == 0) + tail = 12; + else + tail = 20; + f = __archive_read_filter_ahead(self->upstream, tail, &avail_in); + if (f == NULL && avail_in < 0) + return (ARCHIVE_FATAL); + if (avail_in < tail) { + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Lzip: Remaining data is less bytes"); + return (ARCHIVE_FAILED); + } + + /* Check the crc32 value of the uncompressed data of the current + * member */ + if (state->crc32 != archive_le32dec(f)) { + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Lzip: CRC32 error"); + return (ARCHIVE_FAILED); + } + + /* Check the uncompressed size of the current member */ + if ((uint64_t)state->member_out != archive_le64dec(f + 4)) { + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Lzip: Uncompressed size error"); + return (ARCHIVE_FAILED); + } + + /* Check the total size of the current member */ + if (state->lzip_ver == 1 && + (uint64_t)state->member_in + tail != archive_le64dec(f + 12)) { + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Lzip: Member size error"); + return (ARCHIVE_FAILED); + } + __archive_read_filter_consume(self->upstream, tail); + + /* If current lzip data consists of multi member, try decompressing + * a next member. */ + if (lzip_has_member(self->upstream) != 0) { + state->in_stream = 0; + state->crc32 = 0; + state->member_out = 0; + state->member_in = 0; + state->eof = 0; + } + return (ARCHIVE_OK); +} + +/* + * Return the next block of decompressed data. + */ +static ssize_t +xz_filter_read(struct archive_read_filter *self, const void **p) +{ + struct private_data *state; + size_t decompressed; + ssize_t avail_in; + int ret; + + state = (struct private_data *)self->data; + + /* Empty our output buffer. */ + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + /* Try to fill the output buffer. */ + while (state->stream.avail_out > 0 && !state->eof) { + if (!state->in_stream) { + /* + * Initialize liblzma for lzip + */ + ret = lzip_init(self); + if (ret != ARCHIVE_OK) + return (ret); + state->in_stream = 1; + } + state->stream.next_in = + __archive_read_filter_ahead(self->upstream, 1, &avail_in); + if (state->stream.next_in == NULL && avail_in < 0) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "truncated input"); + return (ARCHIVE_FATAL); + } + state->stream.avail_in = avail_in; + + /* Decompress as much as we can in one pass. */ + ret = lzma_code(&(state->stream), + (state->stream.avail_in == 0)? LZMA_FINISH: LZMA_RUN); + switch (ret) { + case LZMA_STREAM_END: /* Found end of stream. */ + state->eof = 1; + /* FALL THROUGH */ + case LZMA_OK: /* Decompressor made some progress. */ + __archive_read_filter_consume(self->upstream, + avail_in - state->stream.avail_in); + state->member_in += + avail_in - state->stream.avail_in; + break; + default: + set_error(self, ret); + return (ARCHIVE_FATAL); + } + } + + decompressed = state->stream.next_out - state->out_block; + state->total_out += decompressed; + state->member_out += decompressed; + if (decompressed == 0) + *p = NULL; + else { + *p = state->out_block; + if (self->code == ARCHIVE_COMPRESSION_LZIP) { + state->crc32 = lzma_crc32(state->out_block, + decompressed, state->crc32); + if (state->eof) { + ret = lzip_tail(self); + if (ret != ARCHIVE_OK) + return (ret); + } + } + } + return (decompressed); +} + +/* + * Clean up the decompressor. + */ +static int +xz_filter_close(struct archive_read_filter *self) +{ + struct private_data *state; + + state = (struct private_data *)self->data; + lzma_end(&(state->stream)); + free(state->out_block); + free(state); + return (ARCHIVE_OK); +} + +#else + +#if HAVE_LZMADEC_H && HAVE_LIBLZMADEC + +/* + * If we have the older liblzmadec library, then we can handle + * LZMA streams but not XZ streams. + */ + +/* + * Setup the callbacks. + */ +static int +lzma_bidder_init(struct archive_read_filter *self) +{ + static const size_t out_block_size = 64 * 1024; + void *out_block; + struct private_data *state; + ssize_t ret, avail_in; + + self->code = ARCHIVE_COMPRESSION_LZMA; + self->name = "lzma"; + + state = (struct private_data *)calloc(sizeof(*state), 1); + out_block = (unsigned char *)malloc(out_block_size); + if (state == NULL || out_block == NULL) { + archive_set_error(&self->archive->archive, ENOMEM, + "Can't allocate data for lzma decompression"); + free(out_block); + free(state); + return (ARCHIVE_FATAL); + } + + self->data = state; + state->out_block_size = out_block_size; + state->out_block = out_block; + self->read = lzma_filter_read; + self->skip = NULL; /* not supported */ + self->close = lzma_filter_close; + + /* Prime the lzma library with 18 bytes of input. */ + state->stream.next_in = (unsigned char *)(uintptr_t) + __archive_read_filter_ahead(self->upstream, 18, &avail_in); + if (state->stream.next_in == NULL) + return (ARCHIVE_FATAL); + state->stream.avail_in = avail_in; + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + /* Initialize compression library. */ + ret = lzmadec_init(&(state->stream)); + __archive_read_filter_consume(self->upstream, + avail_in - state->stream.avail_in); + if (ret == LZMADEC_OK) + return (ARCHIVE_OK); + + /* Library setup failed: Clean up. */ + archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing lzma library"); + + /* Override the error message if we know what really went wrong. */ + switch (ret) { + case LZMADEC_HEADER_ERROR: + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "invalid header"); + break; + case LZMADEC_MEM_ERROR: + archive_set_error(&self->archive->archive, ENOMEM, + "Internal error initializing compression library: " + "out of memory"); + break; + } + + free(state->out_block); + free(state); + self->data = NULL; + return (ARCHIVE_FATAL); +} + +/* + * Return the next block of decompressed data. + */ +static ssize_t +lzma_filter_read(struct archive_read_filter *self, const void **p) +{ + struct private_data *state; + size_t decompressed; + ssize_t avail_in, ret; + + state = (struct private_data *)self->data; + + /* Empty our output buffer. */ + state->stream.next_out = state->out_block; + state->stream.avail_out = state->out_block_size; + + /* Try to fill the output buffer. */ + while (state->stream.avail_out > 0 && !state->eof) { + state->stream.next_in = (unsigned char *)(uintptr_t) + __archive_read_filter_ahead(self->upstream, 1, &avail_in); + if (state->stream.next_in == NULL && avail_in < 0) { + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "truncated lzma input"); + return (ARCHIVE_FATAL); + } + state->stream.avail_in = avail_in; + + /* Decompress as much as we can in one pass. */ + ret = lzmadec_decode(&(state->stream), avail_in == 0); + switch (ret) { + case LZMADEC_STREAM_END: /* Found end of stream. */ + state->eof = 1; + /* FALL THROUGH */ + case LZMADEC_OK: /* Decompressor made some progress. */ + __archive_read_filter_consume(self->upstream, + avail_in - state->stream.avail_in); + break; + case LZMADEC_BUF_ERROR: /* Insufficient input data? */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Insufficient compressed data"); + return (ARCHIVE_FATAL); + default: + /* Return an error. */ + archive_set_error(&self->archive->archive, + ARCHIVE_ERRNO_MISC, + "Lzma decompression failed"); + return (ARCHIVE_FATAL); + } + } + + decompressed = state->stream.next_out - state->out_block; + state->total_out += decompressed; + if (decompressed == 0) + *p = NULL; + else + *p = state->out_block; + return (decompressed); +} + +/* + * Clean up the decompressor. + */ +static int +lzma_filter_close(struct archive_read_filter *self) +{ + struct private_data *state; + int ret; + + state = (struct private_data *)self->data; + ret = ARCHIVE_OK; + switch (lzmadec_end(&(state->stream))) { + case LZMADEC_OK: + break; + default: + archive_set_error(&(self->archive->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up %s compressor", + self->archive->archive.compression_name); + ret = ARCHIVE_FATAL; + } + + free(state->out_block); + free(state); + return (ret); +} + +#else + +/* + * + * If we have no suitable library on this system, we can't actually do + * the decompression. We can, however, still detect compressed + * archives and emit a useful message. + * + */ +static int +lzma_bidder_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "unlzma"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_COMPRESSION_LZMA; + self->name = "lzma"; + return (r); +} + +#endif /* HAVE_LZMADEC_H */ + + +static int +xz_bidder_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "unxz"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_COMPRESSION_XZ; + self->name = "xz"; + return (r); +} + +static int +lzip_bidder_init(struct archive_read_filter *self) +{ + int r; + + r = __archive_read_program(self, "unlzip"); + /* Note: We set the format here even if __archive_read_program() + * above fails. We do, after all, know what the format is + * even if we weren't able to read it. */ + self->code = ARCHIVE_COMPRESSION_LZIP; + self->name = "lzip"; + return (r); +} + + +#endif /* HAVE_LZMA_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c new file mode 100644 index 000000000..2be226726 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_7zip.c @@ -0,0 +1,3706 @@ +/*- + * Copyright (c) 2011 Michihiro NAKAJIMA + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#ifdef HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_endian.h" + +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif + +#define _7ZIP_SIGNATURE "7z\xBC\xAF\x27\x1C" +#define SFX_MIN_ADDR 0x27000 +#define SFX_MAX_ADDR 0x60000 + + +/* + * Codec ID + */ +#define _7Z_COPY 0 +#define _7Z_LZMA 0x030101 +#define _7Z_LZMA2 0x21 +#define _7Z_DEFLATE 0x040108 +#define _7Z_BZ2 0x040202 +#define _7Z_PPMD 0x030401 +#define _7Z_DELTA 0x03 +#define _7Z_CRYPTO 0x06F10701 +#define _7Z_X86 0x03030103 +#define _7Z_X86_BCJ2 0x0303011B +#define _7Z_POWERPC 0x03030205 +#define _7Z_IA64 0x03030401 +#define _7Z_ARM 0x03030501 +#define _7Z_ARMTHUMB 0x03030701 +#define _7Z_SPARC 0x03030805 + +/* + * 7-Zip header property IDs. + */ +#define kEnd 0x00 +#define kHeader 0x01 +#define kArchiveProperties 0x02 +#define kAdditionalStreamsInfo 0x03 +#define kMainStreamsInfo 0x04 +#define kFilesInfo 0x05 +#define kPackInfo 0x06 +#define kUnPackInfo 0x07 +#define kSubStreamsInfo 0x08 +#define kSize 0x09 +#define kCRC 0x0A +#define kFolder 0x0B +#define kCodersUnPackSize 0x0C +#define kNumUnPackStream 0x0D +#define kEmptyStream 0x0E +#define kEmptyFile 0x0F +#define kAnti 0x10 +#define kName 0x11 +#define kCTime 0x12 +#define kATime 0x13 +#define kMTime 0x14 +#define kAttributes 0x15 +#define kEncodedHeader 0x17 + +struct _7z_digests { + unsigned char *defineds; + uint32_t *digests; +}; + + +struct _7z_folder { + uint64_t numCoders; + struct _7z_coder { + unsigned long codec; + uint64_t numInStreams; + uint64_t numOutStreams; + uint64_t propertiesSize; + unsigned char *properties; + } *coders; + uint64_t numBindPairs; + struct { + uint64_t inIndex; + uint64_t outIndex; + } *bindPairs; + uint64_t numPackedStreams; + uint64_t *packedStreams; + uint64_t numInStreams; + uint64_t numOutStreams; + uint64_t *unPackSize; + unsigned char digest_defined; + uint32_t digest; + uint64_t numUnpackStreams; + uint32_t packIndex; + /* Unoperated bytes. */ + uint64_t skipped_bytes; +}; + +struct _7z_coders_info { + uint64_t numFolders; + struct _7z_folder *folders; + uint64_t dataStreamIndex; +}; + +struct _7z_pack_info { + uint64_t pos; + uint64_t numPackStreams; + uint64_t *sizes; + struct _7z_digests digest; + /* Calculated from pos and numPackStreams. */ + uint64_t *positions; +}; + +struct _7z_substream_info { + size_t unpack_streams; + uint64_t *unpackSizes; + unsigned char *digestsDefined; + uint32_t *digests; +}; + +struct _7z_stream_info { + struct _7z_pack_info pi; + struct _7z_coders_info ci; + struct _7z_substream_info ss; +}; + +struct _7z_header_info { + uint64_t dataIndex; + + unsigned char *emptyStreamBools; + unsigned char *emptyFileBools; + unsigned char *antiBools; + unsigned char *attrBools; +}; + +struct _7zip_entry { + size_t name_len; + unsigned char *utf16name; +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + const wchar_t *wname; +#endif + uint32_t folderIndex; + uint32_t ssIndex; + unsigned flg; +#define MTIME_IS_SET (1<<0) +#define ATIME_IS_SET (1<<1) +#define CTIME_IS_SET (1<<2) +#define CRC32_IS_SET (1<<3) +#define HAS_STREAM (1<<4) + + time_t mtime; + time_t atime; + time_t ctime; + long mtime_ns; + long atime_ns; + long ctime_ns; + uint32_t mode; + uint32_t attr; +}; + +struct _7zip { + /* Structural information about the archive. */ + struct _7z_stream_info si; + + int header_is_being_read; + int header_is_encoded; + uint64_t header_bytes_remaining; + unsigned long header_crc32; + /* Header offset to check that reading pointes of the file contens + * will not exceed the header. */ + uint64_t header_offset; + /* Base offset of the archive file for a seek in case reading SFX. */ + uint64_t seek_base; + + /* List of entries */ + size_t entries_remaining; + uint64_t numFiles; + struct _7zip_entry *entries; + struct _7zip_entry *entry; + unsigned char *entry_names; + + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_offset; + uint64_t entry_bytes_remaining; + + /* Running CRC32 of the decompressed data */ + unsigned long entry_crc32; + + /* Flags to mark progress of decompression. */ + char end_of_entry; + + /* Uncompressed buffer control. */ +#define UBUFF_SIZE (64 * 1024) + unsigned char *uncompressed_buffer; + unsigned char *uncompressed_buffer_pointer; + size_t uncompressed_buffer_size; + size_t uncompressed_buffer_bytes_remaining; + + /* Offset of the compressed data. */ + int64_t stream_offset; + + /* + * Decompressing control data. + */ + unsigned folder_index; + uint64_t folder_outbytes_remaining; + unsigned pack_stream_index; + unsigned pack_stream_remaining; + uint64_t pack_stream_inbytes_remaining; + size_t pack_stream_bytes_unconsumed; + + /* The codec information of a folder. */ + unsigned long codec; + unsigned long codec2; + + /* + * Decompressor controllers. + */ + /* Decording LZMA1 and LZMA2 data. */ +#ifdef HAVE_LZMA_H + lzma_stream lzstream; + int lzstream_valid; +#endif + /* Decording bzip2 data. */ +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + bz_stream bzstream; + int bzstream_valid; +#endif + /* Decording deflate data. */ +#ifdef HAVE_ZLIB_H + z_stream stream; + int stream_valid; +#endif + /* Decording PPMd data. */ + int ppmd7_stat; + CPpmd7 ppmd7_context; + CPpmd7z_RangeDec range_dec; + IByteIn bytein; + struct { + const unsigned char *next_in; + int64_t avail_in; + int64_t total_in; + unsigned char *next_out; + int64_t avail_out; + int64_t total_out; + int overconsumed; + } ppstream; + int ppmd7_valid; + + /* Decoding BCJ and BCJ2 data. */ + uint32_t bcj_state; + size_t odd_bcj_size; + unsigned char odd_bcj[4]; + /* Decoding BCJ data. */ + size_t bcj_prevPosT; + uint32_t bcj_prevMask; + uint32_t bcj_ip; + + /* Decoding BCJ2 data. */ + size_t main_stream_bytes_remaining; + unsigned char *sub_stream_buff[3]; + size_t sub_stream_size[3]; + size_t sub_stream_bytes_remaining[3]; + unsigned char *tmp_stream_buff; + size_t tmp_stream_buff_size; + size_t tmp_stream_bytes_avail; + size_t tmp_stream_bytes_remaining; +#ifdef _LZMA_PROB32 +#define CProb uint32_t +#else +#define CProb uint16_t +#endif + CProb bcj2_p[256 + 2]; + uint8_t bcj2_prevByte; + uint32_t bcj2_range; + uint32_t bcj2_code; + uint64_t bcj2_outPos; + + /* Filename character-set convertion data. */ + struct archive_string_conv *sconv; + + char format_name[64]; +}; + +static int archive_read_format_7zip_bid(struct archive_read *, int); +static int archive_read_format_7zip_cleanup(struct archive_read *); +static int archive_read_format_7zip_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_7zip_read_data_skip(struct archive_read *); +static int archive_read_format_7zip_read_header(struct archive_read *, + struct archive_entry *); +static int check_7zip_header_in_sfx(const char *); +static unsigned long decode_codec_id(const unsigned char *, size_t); +static int decode_encoded_header_info(struct archive_read *, + struct _7z_stream_info *); +static int decompress(struct archive_read *, struct _7zip *, + void *, size_t *, const void *, size_t *); +static ssize_t extract_pack_stream(struct archive_read *, size_t); +static void fileTimeToUtc(uint64_t, time_t *, long *); +static uint64_t folder_uncompressed_size(struct _7z_folder *); +static void free_CodersInfo(struct _7z_coders_info *); +static void free_Digest(struct _7z_digests *); +static void free_Folder(struct _7z_folder *); +static void free_Header(struct _7z_header_info *); +static void free_PackInfo(struct _7z_pack_info *); +static void free_StreamsInfo(struct _7z_stream_info *); +static void free_SubStreamsInfo(struct _7z_substream_info *); +static int free_decompression(struct archive_read *, struct _7zip *); +static ssize_t get_uncompressed_data(struct archive_read *, const void **, + size_t, size_t); +static const unsigned char * header_bytes(struct archive_read *, size_t); +static int init_decompression(struct archive_read *, struct _7zip *, + const struct _7z_coder *, const struct _7z_coder *); +static int parse_7zip_uint64(struct archive_read *, uint64_t *); +static int read_Bools(struct archive_read *, unsigned char *, size_t); +static int read_CodersInfo(struct archive_read *, + struct _7z_coders_info *); +static int read_Digests(struct archive_read *, struct _7z_digests *, + size_t); +static int read_Folder(struct archive_read *, struct _7z_folder *); +static int read_Header(struct archive_read *, struct _7z_header_info *, + int); +static int read_PackInfo(struct archive_read *, struct _7z_pack_info *); +static int read_StreamsInfo(struct archive_read *, + struct _7z_stream_info *); +static int read_SubStreamsInfo(struct archive_read *, + struct _7z_substream_info *, struct _7z_folder *, size_t); +static int read_Times(struct archive_read *, struct _7z_header_info *, + int); +static void read_consume(struct archive_read *); +static ssize_t read_stream(struct archive_read *, const void **, size_t, + size_t); +static int seek_pack(struct archive_read *); +static int64_t skip_stream(struct archive_read *, size_t); +static int skip_sfx(struct archive_read *, ssize_t); +static int slurp_central_directory(struct archive_read *, struct _7zip *, + struct _7z_header_info *); +static int setup_decode_folder(struct archive_read *, struct _7z_folder *, + int); +static void x86_Init(struct _7zip *); +static size_t x86_Convert(struct _7zip *, uint8_t *, size_t); +static ssize_t Bcj2_Decode(struct _7zip *, uint8_t *, size_t); + + +int +archive_read_support_format_7zip(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct _7zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_7zip"); + + zip = calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate 7zip data"); + return (ARCHIVE_FATAL); + } + + r = __archive_read_register_format(a, + zip, + "7zip", + archive_read_format_7zip_bid, + NULL, + archive_read_format_7zip_read_header, + archive_read_format_7zip_read_data, + archive_read_format_7zip_read_data_skip, + archive_read_format_7zip_cleanup); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} + +static int +archive_read_format_7zip_bid(struct archive_read *a, int best_bid) +{ + const char *p; + + /* If someone has already bid more than 32, then avoid + trashing the look-ahead buffers with a seek. */ + if (best_bid > 32) + return (-1); + + if ((p = __archive_read_ahead(a, 6, NULL)) == NULL) + return (0); + + /* If first six bytes are the 7-Zip signature, + * return the bid right now. */ + if (memcmp(p, _7ZIP_SIGNATURE, 6) == 0) + return (48); + + /* + * It may a 7-Zip SFX archive file. If first two bytes are + * 'M' and 'Z' available on Windows or first four bytes are + * "\x7F\x45LF" available on posix like system, seek the 7-Zip + * signature. Although we will perform a seek when reading + * a header, what we do not use __archive_read_seek() here is + * due to a bidding performance. + */ + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + ssize_t offset = SFX_MIN_ADDR; + ssize_t window = 4096; + ssize_t bytes_avail; + while (offset + window <= (SFX_MAX_ADDR)) { + const char *buff = __archive_read_ahead(a, + offset + window, &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + return (0); + continue; + } + p = buff + offset; + while (p + 32 < buff + bytes_avail) { + int step = check_7zip_header_in_sfx(p); + if (step == 0) + return (48); + p += step; + } + offset = p - buff; + } + } + return (0); +} + +static int +check_7zip_header_in_sfx(const char *p) +{ + switch ((unsigned char)p[5]) { + case 0x1C: + if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0) + return (6); + /* + * Test the CRC because its extraction code has 7-Zip + * Magic Code, so we should do this in order not to + * make a mis-detection. + */ + if (crc32(0, (unsigned char *)p + 12, 20) + != archive_le32dec(p + 8)) + return (6); + /* Hit the header! */ + return (0); + case 0x37: return (5); + case 0x7A: return (4); + case 0xBC: return (3); + case 0xAF: return (2); + case 0x27: return (1); + default: return (6); + } +} + +static int +skip_sfx(struct archive_read *a, ssize_t bytes_avail) +{ + const void *h; + const char *p, *q; + size_t skip, offset; + ssize_t bytes, window; + + /* + * If bytes_avail > SFX_MIN_ADDR we do not have to call + * __archive_read_seek() at this time since we have + * alredy had enough data. + */ + if (bytes_avail > SFX_MIN_ADDR) + __archive_read_consume(a, SFX_MIN_ADDR); + else if (__archive_read_seek(a, SFX_MIN_ADDR, SEEK_SET) < 0) + return (ARCHIVE_FATAL); + + offset = 0; + window = 1; + while (offset + window <= SFX_MAX_ADDR - SFX_MIN_ADDR) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + goto fatal; + continue; + } + if (bytes < 6) { + /* This case might happen when window == 1. */ + window = 4096; + continue; + } + p = (const char *)h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the 7-Zip header. + */ + while (p + 32 < q) { + int step = check_7zip_header_in_sfx(p); + if (step == 0) { + struct _7zip *zip = + (struct _7zip *)a->format->data; + skip = p - (const char *)h; + __archive_read_consume(a, skip); + zip->seek_base = SFX_MIN_ADDR + offset + skip; + return (ARCHIVE_OK); + } + p += step; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + offset += skip; + if (window == 1) + window = 4096; + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out 7-Zip header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_7zip_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + struct _7zip_entry *zip_entry; + int r, ret = ARCHIVE_OK; + + a->archive.archive_format = ARCHIVE_FORMAT_7ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "7-Zip"; + + if (zip->entries == NULL) { + struct _7z_header_info header; + + memset(&header, 0, sizeof(header)); + r = slurp_central_directory(a, zip, &header); + free_Header(&header); + if (r != ARCHIVE_OK) + return (r); + zip->entries_remaining = zip->numFiles; + zip->entry = zip->entries; + } else { + ++zip->entry; + } + zip_entry = zip->entry; + + if (zip->entries_remaining <= 0) + return ARCHIVE_EOF; + --zip->entries_remaining; + + zip->entry_offset = 0; + zip->end_of_entry = 0; + zip->entry_crc32 = crc32(0, NULL, 0); + + /* Setup a string conversion for a filename. */ + if (zip->sconv == NULL) { + zip->sconv = archive_string_conversion_from_charset( + &a->archive, "UTF-16LE", 1); + if (zip->sconv == NULL) + return (ARCHIVE_FATAL); + } + + if (archive_entry_copy_pathname_l(entry, + (const char *)zip_entry->utf16name, + zip_entry->name_len, zip->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(zip->sconv)); + ret = ARCHIVE_WARN; + } + + /* Populate some additional entry fields: */ + archive_entry_set_mode(entry, zip_entry->mode); + if (zip_entry->flg & MTIME_IS_SET) + archive_entry_set_mtime(entry, zip_entry->mtime, + zip_entry->mtime_ns); + if (zip_entry->flg & CTIME_IS_SET) + archive_entry_set_ctime(entry, zip_entry->ctime, + zip_entry->ctime_ns); + if (zip_entry->flg & ATIME_IS_SET) + archive_entry_set_atime(entry, zip_entry->atime, + zip_entry->atime_ns); + if (zip_entry->ssIndex != -1) { + zip->entry_bytes_remaining = + zip->si.ss.unpackSizes[zip_entry->ssIndex]; + archive_entry_set_size(entry, zip->entry_bytes_remaining); + } else { + zip->entry_bytes_remaining = 0; + archive_entry_set_size(entry, 0); + } + + /* If there's no body, force read_data() to return EOF immediately. */ + if (zip->entry_bytes_remaining < 1) + zip->end_of_entry = 1; + + if ((zip_entry->mode & AE_IFMT) == AE_IFLNK) { + unsigned char *symname = NULL; + size_t symsize = 0; + int r; + + /* + * Symbolic-name is recorded as its contents. We have to + * read the contents at this time. + */ + while (zip->entry_bytes_remaining > 0) { + const void *buff; + size_t size; + int64_t offset; + + r = archive_read_format_7zip_read_data(a, &buff, + &size, &offset); + if (r < ARCHIVE_WARN) + return (r); + symname = realloc(symname, symsize + size + 1); + if (symname == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Symname"); + return (ARCHIVE_FATAL); + } + memcpy(symname+symsize, buff, size); + symsize += size; + } + if (symsize == 0) { + /* If there is no synname, handle it as a regular + * file. */ + zip_entry->mode &= ~AE_IFMT; + zip_entry->mode |= AE_IFREG; + archive_entry_set_mode(entry, zip_entry->mode); + } else { + symname[symsize] = '\0'; + archive_entry_copy_symlink(entry, + (const char *)symname); + free(symname); + } + archive_entry_set_size(entry, 0); + } + + /* Set up a more descriptive format name. */ + sprintf(zip->format_name, "7-Zip"); + a->archive.archive_format_name = zip->format_name; + + return (ret); +} + +static int +archive_read_format_7zip_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct _7zip *zip; + ssize_t bytes; + int ret = ARCHIVE_OK; + + zip = (struct _7zip *)(a->format->data); + + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + /* + * If we hit end-of-entry last time, clean up and return + * ARCHIVE_EOF this time. + */ + if (zip->end_of_entry) { + *offset = zip->entry_offset; + *size = 0; + *buff = NULL; + return (ARCHIVE_EOF); + } + + bytes = read_stream(a, buff, zip->entry_bytes_remaining, 0); + if (bytes < 0) + return ((int)bytes); + if (bytes == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + zip->entry_bytes_remaining -= bytes; + if (zip->entry_bytes_remaining == 0) + zip->end_of_entry = 1; + + /* Update checksum */ + if ((zip->entry->flg & CRC32_IS_SET) && bytes) + zip->entry_crc32 = crc32(zip->entry_crc32, *buff, bytes); + + /* If we hit the end, swallow any end-of-data marker. */ + if (zip->end_of_entry) { + /* Check computed CRC against file contents. */ + if ((zip->entry->flg & CRC32_IS_SET) && + zip->si.ss.digests[zip->entry->ssIndex] != + zip->entry_crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "7-Zip bad CRC: 0x%lx should be 0x%lx", + (unsigned long)zip->entry_crc32, + (unsigned long)zip->si.ss.digests[ + zip->entry->ssIndex]); + ret = ARCHIVE_WARN; + } + } + + *size = bytes; + *offset = zip->entry_offset; + zip->entry_offset += bytes; + + return (ret); +} + +static int +archive_read_format_7zip_read_data_skip(struct archive_read *a) +{ + struct _7zip *zip; + int64_t bytes_skipped; + + zip = (struct _7zip *)(a->format->data); + + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + /* If we've already read to end of data, we're done. */ + if (zip->end_of_entry) + return (ARCHIVE_OK); + + /* + * If the length is at the beginning, we can skip the + * compressed data much more quickly. + */ + bytes_skipped = skip_stream(a, zip->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + zip->entry_bytes_remaining = 0; + + /* This entry is finished and done. */ + zip->end_of_entry = 1; + return (ARCHIVE_OK); +} + +static int +archive_read_format_7zip_cleanup(struct archive_read *a) +{ + struct _7zip *zip; + + zip = (struct _7zip *)(a->format->data); + free_StreamsInfo(&(zip->si)); + free(zip->entries); + free(zip->entry_names); + free_decompression(a, zip); + free(zip->uncompressed_buffer); + free(zip->sub_stream_buff[0]); + free(zip->sub_stream_buff[1]); + free(zip->sub_stream_buff[2]); + free(zip->tmp_stream_buff); + free(zip); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static void +read_consume(struct archive_read *a) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + + if (zip->pack_stream_bytes_unconsumed) { + __archive_read_consume(a, zip->pack_stream_bytes_unconsumed); + zip->stream_offset += zip->pack_stream_bytes_unconsumed; + zip->pack_stream_bytes_unconsumed = 0; + } +} + +#ifdef HAVE_LZMA_H + +/* + * Set an error code and choose an error message for liblzma. + */ +static void +set_error(struct archive_read *a, int ret) +{ + + switch (ret) { + case LZMA_STREAM_END: /* Found end of stream. */ + case LZMA_OK: /* Decompressor made some progress. */ + break; + case LZMA_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Lzma library error: Cannot allocate memory"); + break; + case LZMA_MEMLIMIT_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Lzma library error: Out of memory"); + break; + case LZMA_FORMAT_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: format not recognized"); + break; + case LZMA_OPTIONS_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Invalid options"); + break; + case LZMA_DATA_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: Corrupted input data"); + break; + case LZMA_BUF_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma library error: No progress is possible"); + break; + default: + /* Return an error. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Lzma decompression failed: Unknown error"); + break; + } +} + +#endif + +static unsigned long +decode_codec_id(const unsigned char *codecId, size_t id_size) +{ + unsigned i; + unsigned long id = 0; + + for (i = 0; i < id_size; i++) { + id <<= 8; + id += codecId[i]; + } + return (id); +} + +static void * +ppmd_alloc(void *p, size_t size) +{ + (void)p; + return malloc(size); +} +static void +ppmd_free(void *p, void *address) +{ + (void)p; + free(address); +} +static Byte +ppmd_read(void *p) +{ + struct archive_read *a = ((IByteIn*)p)->a; + struct _7zip *zip = (struct _7zip *)(a->format->data); + Byte b; + + if (zip->ppstream.avail_in == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + zip->ppstream.overconsumed = 1; + return (0); + } + b = *zip->ppstream.next_in++; + zip->ppstream.avail_in--; + zip->ppstream.total_in++; + return (b); +} + +static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; + +static int +init_decompression(struct archive_read *a, struct _7zip *zip, + const struct _7z_coder *coder1, const struct _7z_coder *coder2) +{ + int r; + + zip->codec = coder1->codec; + zip->codec2 = -1; + + switch (zip->codec) { + case _7Z_COPY: + case _7Z_BZ2: + case _7Z_DEFLATE: + case _7Z_PPMD: + if (coder2 != NULL) { + if (coder2->codec != _7Z_X86 && + coder2->codec != _7Z_X86_BCJ2) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Unsupported filter %lx for %lx", + coder2->codec, coder1->codec); + return (ARCHIVE_FAILED); + } + zip->codec2 = coder2->codec; + zip->bcj_state = 0; + if (coder2->codec == _7Z_X86) + x86_Init(zip); + } + break; + default: + break; + } + + switch (zip->codec) { + case _7Z_COPY: + break; + + case _7Z_LZMA: case _7Z_LZMA2: +#ifdef HAVE_LZMA_H +#if LZMA_VERSION_MAJOR >= 5 +/* Effectively disable the limiter. */ +#define LZMA_MEMLIMIT UINT64_MAX +#else +/* NOTE: This needs to check memory size which running system has. */ +#define LZMA_MEMLIMIT (1U << 30) +#endif + { + lzma_options_delta delta_opt; + lzma_filter filters[LZMA_FILTERS_MAX]; +#if LZMA_VERSION < 50000030 + lzma_filter *ff; +#endif + int fi = 0; + + if (zip->lzstream_valid) { + lzma_end(&(zip->lzstream)); + zip->lzstream_valid = 0; + } + + /* + * NOTE: liblzma incompletely handle the BCJ+LZMA compressed + * data made by 7-Zip because 7-Zip does not add End-Of- + * Payload Marker(EOPM) at the end of LZMA compressed data, + * and so liblzma cannot know the end of the compressed data + * without EOPM. So consequently liblzma will not return last + * three or four bytes of uncompressed data because + * LZMA_FILTER_X86 filter does not handle input data if its + * data size is less than five bytes. If liblzma detect EOPM + * or know the uncompressed data size, liblzma will flush out + * the remaining that three or four bytes of uncompressed + * data. That is why we have to use our converting program + * for BCJ+LZMA. If we were able to tell the uncompressed + * size to liblzma when using lzma_raw_decoder() liblzma + * could correctly deal with BCJ+LZMA. But unfortunately + * there is no way to do that. + * Discussion about this can be found at XZ Utils forum. + */ + if (coder2 != NULL) { + zip->codec2 = coder2->codec; + + filters[fi].options = NULL; + switch (zip->codec2) { + case _7Z_X86: + if (zip->codec == _7Z_LZMA2) { + filters[fi].id = LZMA_FILTER_X86; + fi++; + } else + /* Use our filter. */ + x86_Init(zip); + break; + case _7Z_X86_BCJ2: + /* Use our filter. */ + zip->bcj_state = 0; + break; + case _7Z_DELTA: + filters[fi].id = LZMA_FILTER_DELTA; + memset(&delta_opt, 0, sizeof(delta_opt)); + delta_opt.type = LZMA_DELTA_TYPE_BYTE; + delta_opt.dist = 1; + filters[fi].options = &delta_opt; + fi++; + break; + /* Following filters have not been tested yet. */ + case _7Z_POWERPC: + filters[fi].id = LZMA_FILTER_POWERPC; + fi++; + break; + case _7Z_IA64: + filters[fi].id = LZMA_FILTER_IA64; + fi++; + break; + case _7Z_ARM: + filters[fi].id = LZMA_FILTER_ARM; + fi++; + break; + case _7Z_ARMTHUMB: + filters[fi].id = LZMA_FILTER_ARMTHUMB; + fi++; + break; + case _7Z_SPARC: + filters[fi].id = LZMA_FILTER_SPARC; + fi++; + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Unexpected codec ID: %lX", zip->codec2); + return (ARCHIVE_FAILED); + } + } + + if (zip->codec == _7Z_LZMA2) + filters[fi].id = LZMA_FILTER_LZMA2; + else + filters[fi].id = LZMA_FILTER_LZMA1; + filters[fi].options = NULL; +#if LZMA_VERSION < 50000030 + ff = &filters[fi]; +#endif + r = lzma_properties_decode(&filters[fi], NULL, + coder1->properties, coder1->propertiesSize); + if (r != LZMA_OK) { + set_error(a, r); + return (ARCHIVE_FAILED); + } + fi++; + + filters[fi].id = LZMA_VLI_UNKNOWN; + filters[fi].options = NULL; + r = lzma_raw_decoder(&(zip->lzstream), filters); +#if LZMA_VERSION < 50000030 + free(ff->options); +#endif + if (r != LZMA_OK) { + set_error(a, r); + return (ARCHIVE_FAILED); + } + zip->lzstream_valid = 1; + zip->lzstream.total_in = 0; + zip->lzstream.total_out = 0; + break; + } +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LZMA codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_BZ2: +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (zip->bzstream_valid) { + BZ2_bzDecompressEnd(&(zip->bzstream)); + zip->bzstream_valid = 0; + } + r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 0); + if (r == BZ_MEM_ERROR) + r = BZ2_bzDecompressInit(&(zip->bzstream), 0, 1); + if (r != BZ_OK) { + int err = ARCHIVE_ERRNO_MISC; + const char *detail = NULL; + switch (r) { + case BZ_PARAM_ERROR: + detail = "invalid setup parameter"; + break; + case BZ_MEM_ERROR: + err = ENOMEM; + detail = "out of memory"; + break; + case BZ_CONFIG_ERROR: + detail = "mis-compiled library"; + break; + } + archive_set_error(&a->archive, err, + "Internal error initializing decompressor: %s", + detail != NULL ? detail : "??"); + zip->bzstream_valid = 0; + return (ARCHIVE_FAILED); + } + zip->bzstream_valid = 1; + zip->bzstream.total_in_lo32 = 0; + zip->bzstream.total_in_hi32 = 0; + zip->bzstream.total_out_lo32 = 0; + zip->bzstream.total_out_hi32 = 0; + break; +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "BZ2 codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_DEFLATE: +#ifdef HAVE_ZLIB_H + if (zip->stream_valid) + r = inflateReset(&(zip->stream)); + else + r = inflateInit2(&(zip->stream), + -15 /* Don't check for zlib header */); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't initialize zlib stream."); + return (ARCHIVE_FAILED); + } + zip->stream_valid = 1; + zip->stream.total_in = 0; + zip->stream.total_out = 0; + break; +#else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "DEFLATE codec is unsupported"); + return (ARCHIVE_FAILED); +#endif + case _7Z_PPMD: + { + unsigned order; + uint32_t msize; + + if (zip->ppmd7_valid) { + __archive_ppmd7_functions.Ppmd7_Free( + &zip->ppmd7_context, &g_szalloc); + zip->ppmd7_valid = 0; + } + + if (coder1->propertiesSize < 5) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed PPMd parameter"); + return (ARCHIVE_FAILED); + } + order = coder1->properties[0]; + msize = archive_le32dec(&(coder1->properties[1])); + if (order < PPMD7_MIN_ORDER || order > PPMD7_MAX_ORDER || + msize < PPMD7_MIN_MEM_SIZE || msize > PPMD7_MAX_MEM_SIZE) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed PPMd parameter"); + return (ARCHIVE_FAILED); + } + __archive_ppmd7_functions.Ppmd7_Construct(&zip->ppmd7_context); + r = __archive_ppmd7_functions.Ppmd7_Alloc( + &zip->ppmd7_context, msize, &g_szalloc); + if (r == 0) { + archive_set_error(&a->archive, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init( + &zip->ppmd7_context, order); + __archive_ppmd7_functions.Ppmd7z_RangeDec_CreateVTable( + &zip->range_dec); + zip->ppmd7_valid = 1; + zip->ppmd7_stat = 0; + zip->ppstream.overconsumed = 0; + zip->ppstream.total_in = 0; + zip->ppstream.total_out = 0; + break; + } + case _7Z_X86: + case _7Z_X86_BCJ2: + case _7Z_POWERPC: + case _7Z_IA64: + case _7Z_ARM: + case _7Z_ARMTHUMB: + case _7Z_SPARC: + case _7Z_DELTA: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Unexpected codec ID: %lX", zip->codec); + return (ARCHIVE_FAILED); + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Unknown codec ID: %lX", zip->codec); + return (ARCHIVE_FAILED); + } + + return (ARCHIVE_OK); +} + +static int +decompress(struct archive_read *a, struct _7zip *zip, + void *buff, size_t *outbytes, const void *b, size_t *used) +{ + const uint8_t *t_next_in; + uint8_t *t_next_out; + size_t o_avail_in, o_avail_out; + size_t t_avail_in, t_avail_out; + uint8_t *bcj2_next_out; + size_t bcj2_avail_out; + int r, ret = ARCHIVE_OK; + + t_avail_in = o_avail_in = *used; + t_avail_out = o_avail_out = *outbytes; + t_next_in = b; + t_next_out = buff; + + if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) { + int i; + + /* Do not copy out the BCJ remaining bytes when the output + * buffer size is less than five bytes. */ + if (o_avail_in != 0 && t_avail_out < 5 && zip->odd_bcj_size) { + *used = 0; + *outbytes = 0; + return (ret); + } + for (i = 0; zip->odd_bcj_size > 0 && t_avail_out; i++) { + *t_next_out++ = zip->odd_bcj[i]; + t_avail_out--; + zip->odd_bcj_size--; + } + if (o_avail_in == 0 || t_avail_out == 0) { + *used = o_avail_in - t_avail_in; + *outbytes = o_avail_out - t_avail_out; + if (o_avail_in == 0) + ret = ARCHIVE_EOF; + return (ret); + } + } + + bcj2_next_out = t_next_out; + bcj2_avail_out = t_avail_out; + if (zip->codec2 == _7Z_X86_BCJ2) { + /* + * Decord a remaining decompressed main stream for BCJ2. + */ + if (zip->tmp_stream_bytes_remaining) { + ssize_t bytes; + size_t remaining = zip->tmp_stream_bytes_remaining; + bytes = Bcj2_Decode(zip, t_next_out, t_avail_out); + if (bytes < 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "BCJ2 conversion Failed"); + return (ARCHIVE_FAILED); + } + zip->main_stream_bytes_remaining -= + remaining - zip->tmp_stream_bytes_remaining; + t_avail_out -= bytes; + if (o_avail_in == 0 || t_avail_out == 0) { + *used = 0; + *outbytes = o_avail_out - t_avail_out; + if (o_avail_in == 0 && + zip->tmp_stream_bytes_remaining) + ret = ARCHIVE_EOF; + return (ret); + } + t_next_out += bytes; + bcj2_next_out = t_next_out; + bcj2_avail_out = t_avail_out; + } + t_next_out = zip->tmp_stream_buff; + t_avail_out = zip->tmp_stream_buff_size; + } + + switch (zip->codec) { + case _7Z_COPY: + { + size_t bytes = + (t_avail_in > t_avail_out)?t_avail_out:t_avail_in; + + memcpy(t_next_out, t_next_in, bytes); + t_avail_in -= bytes; + t_avail_out -= bytes; + if (o_avail_in == 0) + ret = ARCHIVE_EOF; + break; + } +#ifdef HAVE_LZMA_H + case _7Z_LZMA: case _7Z_LZMA2: + zip->lzstream.next_in = t_next_in; + zip->lzstream.avail_in = t_avail_in; + zip->lzstream.next_out = t_next_out; + zip->lzstream.avail_out = t_avail_out; + + r = lzma_code(&(zip->lzstream), LZMA_RUN); + switch (r) { + case LZMA_STREAM_END: /* Found end of stream. */ + lzma_end(&(zip->lzstream)); + zip->lzstream_valid = 0; + ret = ARCHIVE_EOF; + break; + case LZMA_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Decompression failed(%d)", + r); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->lzstream.avail_in; + t_avail_out = zip->lzstream.avail_out; + break; +#endif +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case _7Z_BZ2: + zip->bzstream.next_in = (char *)(uintptr_t)t_next_in; + zip->bzstream.avail_in = t_avail_in; + zip->bzstream.next_out = (char *)(uintptr_t)t_next_out; + zip->bzstream.avail_out = t_avail_out; + r = BZ2_bzDecompress(&(zip->bzstream)); + switch (r) { + case BZ_STREAM_END: /* Found end of stream. */ + switch (BZ2_bzDecompressEnd(&(zip->bzstream))) { + case BZ_OK: + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + return (ARCHIVE_FAILED); + } + zip->bzstream_valid = 0; + ret = ARCHIVE_EOF; + break; + case BZ_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "bzip decompression failed"); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->bzstream.avail_in; + t_avail_out = zip->bzstream.avail_out; + break; +#endif +#ifdef HAVE_ZLIB_H + case _7Z_DEFLATE: + zip->stream.next_in = (Bytef *)(uintptr_t)t_next_in; + zip->stream.avail_in = t_avail_in; + zip->stream.next_out = t_next_out; + zip->stream.avail_out = t_avail_out; + r = inflate(&(zip->stream), 0); + switch (r) { + case Z_STREAM_END: /* Found end of stream. */ + ret = ARCHIVE_EOF; + break; + case Z_OK: /* Decompressor made some progress.*/ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File decompression failed (%d)", r); + return (ARCHIVE_FAILED); + } + t_avail_in = zip->stream.avail_in; + t_avail_out = zip->stream.avail_out; + break; +#endif + case _7Z_PPMD: + { + uint64_t flush_bytes; + + if (!zip->ppmd7_valid || zip->ppmd7_stat < 0 || + t_avail_in < 0 || t_avail_out <= 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Decompression internal error"); + return (ARCHIVE_FAILED); + } + zip->ppstream.next_in = t_next_in; + zip->ppstream.avail_in = t_avail_in; + zip->ppstream.next_out = t_next_out; + zip->ppstream.avail_out = t_avail_out; + if (zip->ppmd7_stat == 0) { + zip->bytein.a = a; + zip->bytein.Read = &ppmd_read; + zip->range_dec.Stream = &zip->bytein; + r = __archive_ppmd7_functions.Ppmd7z_RangeDec_Init( + &(zip->range_dec)); + if (r == 0) { + zip->ppmd7_stat = -1; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to initialize PPMd range decorder"); + return (ARCHIVE_FAILED); + } + if (zip->ppstream.overconsumed) { + zip->ppmd7_stat = -1; + return (ARCHIVE_FAILED); + } + zip->ppmd7_stat = 1; + } + + if (t_avail_in == 0) + /* XXX Flush out remaining decoded data XXX */ + flush_bytes = zip->folder_outbytes_remaining; + else + flush_bytes = 0; + + do { + int sym; + + sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &(zip->ppmd7_context), &(zip->range_dec.p)); + if (sym < 0) { + zip->ppmd7_stat = -1; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Failed to decode PPMd"); + return (ARCHIVE_FAILED); + } + if (zip->ppstream.overconsumed) { + zip->ppmd7_stat = -1; + return (ARCHIVE_FAILED); + } + *zip->ppstream.next_out++ = (unsigned char)sym; + zip->ppstream.avail_out--; + zip->ppstream.total_out++; + if (flush_bytes) + flush_bytes--; + } while (zip->ppstream.avail_out && + (zip->ppstream.avail_in || flush_bytes)); + + t_avail_in = zip->ppstream.avail_in; + t_avail_out = zip->ppstream.avail_out; + break; + } + default: + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompression internal error"); + return (ARCHIVE_FAILED); + } + if (ret != ARCHIVE_OK && ret != ARCHIVE_EOF) + return (ret); + + *used = o_avail_in - t_avail_in; + *outbytes = o_avail_out - t_avail_out; + + /* + * Decord BCJ. + */ + if (zip->codec != _7Z_LZMA2 && zip->codec2 == _7Z_X86) { + size_t l = x86_Convert(zip, buff, *outbytes); + zip->odd_bcj_size = *outbytes - l; + if (zip->odd_bcj_size > 0 && zip->odd_bcj_size <= 4 && + o_avail_in && ret != ARCHIVE_EOF) { + memcpy(zip->odd_bcj, ((unsigned char *)buff) + l, + zip->odd_bcj_size); + *outbytes = l; + } else + zip->odd_bcj_size = 0; + } + + /* + * Decord BCJ2 with a decompressed main stream. + */ + if (zip->codec2 == _7Z_X86_BCJ2) { + ssize_t bytes; + + zip->tmp_stream_bytes_avail = + zip->tmp_stream_buff_size - t_avail_out; + if (zip->tmp_stream_bytes_avail > + zip->main_stream_bytes_remaining) + zip->tmp_stream_bytes_avail = + zip->main_stream_bytes_remaining; + zip->tmp_stream_bytes_remaining = zip->tmp_stream_bytes_avail; + bytes = Bcj2_Decode(zip, bcj2_next_out, bcj2_avail_out); + if (bytes < 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "BCJ2 conversion Failed"); + return (ARCHIVE_FAILED); + } + zip->main_stream_bytes_remaining -= + zip->tmp_stream_bytes_avail + - zip->tmp_stream_bytes_remaining; + bcj2_avail_out -= bytes; + *outbytes = o_avail_out - bcj2_avail_out; + } + + return (ret); +} + +static int +free_decompression(struct archive_read *a, struct _7zip *zip) +{ + int r = ARCHIVE_OK; + +#ifdef HAVE_LZMA_H + if (zip->lzstream_valid) + lzma_end(&(zip->lzstream)); +#endif +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (zip->bzstream_valid) { + if (BZ2_bzDecompressEnd(&(zip->bzstream)) != BZ_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up bzip2 decompressor"); + r = ARCHIVE_FATAL; + } + zip->bzstream_valid = 0; + } +#endif +#ifdef HAVE_ZLIB_H + if (zip->stream_valid) { + if (inflateEnd(&(zip->stream)) != Z_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + zip->stream_valid = 0; + } +#endif + if (zip->ppmd7_valid) { + __archive_ppmd7_functions.Ppmd7_Free( + &zip->ppmd7_context, &g_szalloc); + zip->ppmd7_valid = 0; + } + return (r); +} + +static int +parse_7zip_uint64(struct archive_read *a, uint64_t *val) +{ + const unsigned char *p; + unsigned char avail, mask; + int i; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + avail = *p; + mask = 0x80; + *val = 0; + for (i = 0; i < 8; i++) { + if (avail & mask) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + *val |= ((uint64_t)*p) << (8 * i); + mask >>= 1; + continue; + } + *val += (avail & (mask -1)) << (8 * i); + break; + } + return (0); +} + +static int +read_Bools(struct archive_read *a, unsigned char *data, size_t num) +{ + const unsigned char *p; + unsigned i, mask = 0, avail = 0; + + for (i = 0; i < num; i++) { + if (mask == 0) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + avail = *p; + mask = 0x80; + } + data[i] = (avail & mask)?1:0; + mask >>= 1; + } + return (0); +} + +static void +free_Digest(struct _7z_digests *d) +{ + free(d->defineds); + free(d->digests); +} + +static int +read_Digests(struct archive_read *a, struct _7z_digests *d, size_t num) +{ + const unsigned char *p; + unsigned i; + + memset(d, 0, sizeof(*d)); + + + d->defineds = malloc(num); + if (d->defineds == NULL) + return (-1); + /* + * Read Bools. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == 0) { + if (read_Bools(a, d->defineds, num) < 0) + return (-1); + } else + /* All are defined */ + memset(d->defineds, 1, num); + + d->digests = calloc(num, sizeof(*d->digests)); + if (d->digests == NULL) + return (-1); + for (i = 0; i < num; i++) { + if (d->defineds[i]) { + if ((p = header_bytes(a, 4)) == NULL) + return (-1); + d->digests[i] = archive_le32dec(p); + } + } + + return (0); +} + +static void +free_PackInfo(struct _7z_pack_info *pi) +{ + free(pi->sizes); + free(pi->positions); + free_Digest(&(pi->digest)); +} + +static int +read_PackInfo(struct archive_read *a, struct _7z_pack_info *pi) +{ + const unsigned char *p; + unsigned i; + + memset(pi, 0, sizeof(*pi)); + + /* + * Read PackPos. + */ + if (parse_7zip_uint64(a, &(pi->pos)) < 0) + return (-1); + + /* + * Read NumPackStreams. + */ + if (parse_7zip_uint64(a, &(pi->numPackStreams)) < 0) + return (-1); + if (pi->numPackStreams == 0) + return (-1); + if (1000000 < pi->numPackStreams) + return (-1); + + /* + * Read PackSizes[num] + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kEnd) + /* PackSizes[num] are not present. */ + return (0); + if (*p != kSize) + return (-1); + pi->sizes = calloc(pi->numPackStreams, sizeof(uint64_t)); + pi->positions = calloc(pi->numPackStreams, sizeof(uint64_t)); + if (pi->sizes == NULL || pi->positions == NULL) + return (-1); + + for (i = 0; i < pi->numPackStreams; i++) { + if (parse_7zip_uint64(a, &(pi->sizes[i])) < 0) + return (-1); + } + + /* + * Read PackStreamDigests[num] + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kEnd) { + /* PackStreamDigests[num] are not present. */ + pi->digest.defineds = + calloc(pi->numPackStreams, sizeof(*pi->digest.defineds)); + pi->digest.digests = + calloc(pi->numPackStreams, sizeof(*pi->digest.digests)); + if (pi->digest.defineds == NULL || pi->digest.digests == NULL) + return (-1); + return (0); + } + + if (*p != kSize) + return (-1); + + if (read_Digests(a, &(pi->digest), pi->numPackStreams) < 0) + return (-1); + + /* + * Must be marked by kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p != kEnd) + return (-1); + return (0); +} + +static void +free_Folder(struct _7z_folder *f) +{ + unsigned i; + + if (f->coders) { + for (i = 0; i< f->numCoders; i++) { + free(f->coders[i].properties); + } + free(f->coders); + } + free(f->bindPairs); + free(f->packedStreams); + free(f->unPackSize); +} + +static int +read_Folder(struct archive_read *a, struct _7z_folder *f) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + uint64_t numInStreamsTotal = 0; + uint64_t numOutStreamsTotal = 0; + unsigned i; + + memset(f, 0, sizeof(*f)); + + /* + * Read NumCoders. + */ + if (parse_7zip_uint64(a, &(f->numCoders)) < 0) + return (-1); + if (f->numCoders > 4) + /* Too many coders. */ + return (-1); + + f->coders = calloc(f->numCoders, sizeof(*f->coders)); + if (f->coders == NULL) + return (-1); + for (i = 0; i< f->numCoders; i++) { + size_t codec_size; + int simple, attr; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + /* + * 0:3 CodecIdSize + * 4: 0 - IsSimple + * 1 - Is not Simple + * 5: 0 - No Attributes + * 1 - There are Attributes; + * 7: Must be zero. + */ + codec_size = *p & 0xf; + simple = (*p & 0x10)?0:1; + attr = *p & 0x20; + if (*p & 0x80) + return (-1);/* Not supported. */ + + /* + * Read Decompression Method IDs. + */ + if ((p = header_bytes(a, codec_size)) == NULL) + return (-1); + + f->coders[i].codec = decode_codec_id(p, codec_size); + + if (simple) { + f->coders[i].numInStreams = 1; + f->coders[i].numOutStreams = 1; + } else { + if (parse_7zip_uint64( + a, &(f->coders[i].numInStreams)) < 0) + return (-1); + if (1000000 < f->coders[i].numInStreams) + return (-1); + if (parse_7zip_uint64( + a, &(f->coders[i].numOutStreams)) < 0) + return (-1); + if (1000000 < f->coders[i].numOutStreams) + return (-1); + } + + if (attr) { + if (parse_7zip_uint64( + a, &(f->coders[i].propertiesSize)) < 0) + return (-1); + if ((p = header_bytes( + a, f->coders[i].propertiesSize)) == NULL) + return (-1); + f->coders[i].properties = + malloc(f->coders[i].propertiesSize); + if (f->coders[i].properties == NULL) + return (-1); + memcpy(f->coders[i].properties, p, + f->coders[i].propertiesSize); + } + + numInStreamsTotal += f->coders[i].numInStreams; + numOutStreamsTotal += f->coders[i].numOutStreams; + } + + if (numOutStreamsTotal == 0 || + numInStreamsTotal < numOutStreamsTotal-1) + return (-1); + + f->numBindPairs = numOutStreamsTotal - 1; + if (zip->header_bytes_remaining < f->numBindPairs) + return (-1); + f->bindPairs = calloc(f->numBindPairs, sizeof(*f->bindPairs)); + if (f->bindPairs == NULL) + return (-1); + for (i = 0; i < f->numBindPairs; i++) { + if (parse_7zip_uint64(a, &(f->bindPairs[i].inIndex)) < 0) + return (-1); + if (1000000 < f->bindPairs[i].inIndex) + return (-1); + if (parse_7zip_uint64(a, &(f->bindPairs[i].outIndex)) < 0) + return (-1); + if (1000000 < f->bindPairs[i].outIndex) + return (-1); + } + + f->numPackedStreams = numInStreamsTotal - f->numBindPairs; + f->packedStreams = + calloc(f->numPackedStreams, sizeof(*f->packedStreams)); + if (f->packedStreams == NULL) + return (-1); + if (f->numPackedStreams == 1) { + for (i = 0; i < numInStreamsTotal; i++) { + unsigned j; + for (j = 0; j < f->numBindPairs; j++) { + if (f->bindPairs[j].inIndex == i) + break; + } + if (j == f->numBindPairs) + break; + } + if (i == numInStreamsTotal) + return (-1); + f->packedStreams[0] = i; + } else { + for (i = 0; i < f->numPackedStreams; i++) { + if (parse_7zip_uint64(a, &(f->packedStreams[i])) < 0) + return (-1); + if (1000000 < f->packedStreams[i]) + return (-1); + } + } + f->numInStreams = numInStreamsTotal; + f->numOutStreams = numOutStreamsTotal; + + return (0); +} + +static void +free_CodersInfo(struct _7z_coders_info *ci) +{ + unsigned i; + + if (ci->folders) { + for (i = 0; i < ci->numFolders; i++) + free_Folder(&(ci->folders[i])); + free(ci->folders); + } +} + +static int +read_CodersInfo(struct archive_read *a, struct _7z_coders_info *ci) +{ + const unsigned char *p; + struct _7z_digests digest; + unsigned i; + + memset(ci, 0, sizeof(*ci)); + memset(&digest, 0, sizeof(digest)); + + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kFolder) + goto failed; + + /* + * Read NumFolders. + */ + if (parse_7zip_uint64(a, &(ci->numFolders)) < 0) + goto failed; + if (1000000 < ci->numFolders) + return (-1); + + /* + * Read External. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + switch (*p) { + case 0: + ci->folders = calloc(ci->numFolders, sizeof(*ci->folders)); + if (ci->folders == NULL) + return (-1); + for (i = 0; i < ci->numFolders; i++) { + if (read_Folder(a, &(ci->folders[i])) < 0) + goto failed; + } + break; + case 1: + if (parse_7zip_uint64(a, &(ci->dataStreamIndex)) < 0) + return (-1); + if (1000000 < ci->dataStreamIndex) + return (-1); + break; + } + + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kCodersUnPackSize) + goto failed; + + for (i = 0; i < ci->numFolders; i++) { + struct _7z_folder *folder = &(ci->folders[i]); + unsigned j; + + folder->unPackSize = + calloc(folder->numOutStreams, sizeof(*folder->unPackSize)); + if (folder->unPackSize == NULL) + goto failed; + for (j = 0; j < folder->numOutStreams; j++) { + if (parse_7zip_uint64(a, &(folder->unPackSize[j])) < 0) + goto failed; + } + } + + /* + * Read CRCs. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p == kEnd) + return (0); + if (*p != kCRC) + goto failed; + if (read_Digests(a, &digest, ci->numFolders) < 0) + goto failed; + for (i = 0; i < ci->numFolders; i++) { + ci->folders[i].digest_defined = digest.defineds[i]; + ci->folders[i].digest = digest.digests[i]; + } + + /* + * Must be kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p != kEnd) + goto failed; + free_Digest(&digest); + return (0); +failed: + free_Digest(&digest); + return (-1); +} + +static uint64_t +folder_uncompressed_size(struct _7z_folder *f) +{ + int n = f->numOutStreams; + unsigned pairs = f->numBindPairs; + + while (--n >= 0) { + unsigned i; + for (i = 0; i < pairs; i++) { + if (f->bindPairs[i].outIndex == n) + break; + } + if (i >= pairs) + return (f->unPackSize[n]); + } + return (0); +} + +static void +free_SubStreamsInfo(struct _7z_substream_info *ss) +{ + free(ss->unpackSizes); + free(ss->digestsDefined); + free(ss->digests); +} + +static int +read_SubStreamsInfo(struct archive_read *a, struct _7z_substream_info *ss, + struct _7z_folder *f, size_t numFolders) +{ + const unsigned char *p; + uint64_t *usizes; + size_t unpack_streams; + int type; + unsigned i; + uint32_t numDigests; + + memset(ss, 0, sizeof(*ss)); + + for (i = 0; i < numFolders; i++) + f[i].numUnpackStreams = 1; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + + if (type == kNumUnPackStream) { + unpack_streams = 0; + for (i = 0; i < numFolders; i++) { + if (parse_7zip_uint64(a, &(f[i].numUnpackStreams)) < 0) + return (-1); + if (1000000 < f[i].numUnpackStreams) + return (-1); + unpack_streams += f[i].numUnpackStreams; + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } else + unpack_streams = numFolders; + + ss->unpack_streams = unpack_streams; + if (unpack_streams) { + ss->unpackSizes = calloc(unpack_streams, + sizeof(*ss->unpackSizes)); + ss->digestsDefined = calloc(unpack_streams, + sizeof(*ss->digestsDefined)); + ss->digests = calloc(unpack_streams, + sizeof(*ss->digests)); + if (ss->unpackSizes == NULL || ss->digestsDefined == NULL || + ss->digests == NULL) + return (-1); + } + + usizes = ss->unpackSizes; + for (i = 0; i < numFolders; i++) { + unsigned pack; + uint64_t sum; + + if (f[i].numUnpackStreams == 0) + continue; + + sum = 0; + if (type == kSize) { + for (pack = 1; pack < f[i].numUnpackStreams; pack++) { + if (parse_7zip_uint64(a, usizes) < 0) + return (-1); + sum += *usizes++; + } + } + *usizes++ = folder_uncompressed_size(&f[i]) - sum; + } + + if (type == kSize) { + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } + + for (i = 0; i < unpack_streams; i++) { + ss->digestsDefined[i] = 0; + ss->digests[i] = 0; + } + + numDigests = 0; + for (i = 0; i < numFolders; i++) { + if (f[i].numUnpackStreams != 1 || !f[i].digest_defined) + numDigests += f[i].numUnpackStreams; + } + + if (type == kCRC) { + struct _7z_digests tmpDigests; + unsigned char *digestsDefined = ss->digestsDefined; + uint32_t * digests = ss->digests; + int di = 0; + + memset(&tmpDigests, 0, sizeof(tmpDigests)); + if (read_Digests(a, &(tmpDigests), numDigests) < 0) { + free_Digest(&tmpDigests); + return (-1); + } + for (i = 0; i < numFolders; i++) { + if (f[i].numUnpackStreams == 1 && f[i].digest_defined) { + *digestsDefined++ = 1; + *digests++ = f[i].digest; + } else { + unsigned j; + + for (j = 0; j < f[i].numUnpackStreams; + j++, di++) { + *digestsDefined++ = + tmpDigests.defineds[di]; + *digests++ = + tmpDigests.digests[di]; + } + } + } + free_Digest(&tmpDigests); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + } + + /* + * Must be kEnd. + */ + if (type != kEnd) + return (-1); + return (0); +} + +static void +free_StreamsInfo(struct _7z_stream_info *si) +{ + free_PackInfo(&(si->pi)); + free_CodersInfo(&(si->ci)); + free_SubStreamsInfo(&(si->ss)); +} + +static int +read_StreamsInfo(struct archive_read *a, struct _7z_stream_info *si) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + unsigned i; + + memset(si, 0, sizeof(*si)); + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kPackInfo) { + uint64_t packPos; + + if (read_PackInfo(a, &(si->pi)) < 0) + return (-1); + + if (si->pi.positions == NULL || si->pi.sizes == NULL) + return (-1); + /* + * Calculate packed stream positions. + */ + packPos = si->pi.pos; + for (i = 0; i < si->pi.numPackStreams; i++) { + si->pi.positions[i] = packPos; + packPos += si->pi.sizes[i]; + if (packPos > zip->header_offset) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + if (*p == kUnPackInfo) { + uint32_t packIndex; + struct _7z_folder *f; + + if (read_CodersInfo(a, &(si->ci)) < 0) + return (-1); + + /* + * Calculate packed stream indexes. + */ + packIndex = 0; + f = si->ci.folders; + for (i = 0; i < si->ci.numFolders; i++) { + f[i].packIndex = packIndex; + packIndex += f[i].numPackedStreams; + if (packIndex > si->pi.numPackStreams) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + if (*p == kSubStreamsInfo) { + if (read_SubStreamsInfo(a, &(si->ss), + si->ci.folders, si->ci.numFolders) < 0) + return (-1); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + /* + * Must be kEnd. + */ + if (*p != kEnd) + return (-1); + return (0); +} + +static void +free_Header(struct _7z_header_info *h) +{ + free(h->emptyStreamBools); + free(h->emptyFileBools); + free(h->antiBools); + free(h->attrBools); +} + +static int +read_Header(struct archive_read *a, struct _7z_header_info *h, + int check_header_id) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + struct _7z_folder *folders; + struct _7z_stream_info *si = &(zip->si); + struct _7zip_entry *entries; + uint32_t folderIndex, indexInFolder; + unsigned i; + int eindex, empty_streams, sindex; + + if (check_header_id) { + /* + * Read Header. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p != kHeader) + return (-1); + } + + /* + * Read ArchiveProperties. + */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == kArchiveProperties) { + for (;;) { + uint64_t size; + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + if (*p == 0) + break; + if (parse_7zip_uint64(a, &size) < 0) + return (-1); + } + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + + /* + * Read MainStreamsInfo. + */ + if (*p == kMainStreamsInfo) { + if (read_StreamsInfo(a, &(zip->si)) < 0) + return (-1); + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + } + if (*p == kEnd) + return (0); + + /* + * Read FilesInfo. + */ + if (*p != kFilesInfo) + return (-1); + + if (parse_7zip_uint64(a, &(zip->numFiles)) < 0) + return (-1); + if (1000000 < zip->numFiles) + return (-1); + + zip->entries = calloc(zip->numFiles, sizeof(*zip->entries)); + if (zip->entries == NULL) + return (-1); + entries = zip->entries; + + empty_streams = 0; + for (;;) { + int type; + uint64_t size; + size_t ll; + + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + type = *p; + if (type == kEnd) + break; + + if (parse_7zip_uint64(a, &size) < 0) + return (-1); + if (zip->header_bytes_remaining < size) + return (-1); + ll = (size_t)size; + + switch (type) { + case kEmptyStream: + h->emptyStreamBools = calloc(zip->numFiles, + sizeof(*h->emptyStreamBools)); + if (h->emptyStreamBools == NULL) + return (-1); + if (read_Bools( + a, h->emptyStreamBools, zip->numFiles) < 0) + return (-1); + empty_streams = 0; + for (i = 0; i < zip->numFiles; i++) { + if (h->emptyStreamBools[i]) + empty_streams++; + } + break; + case kEmptyFile: + h->emptyFileBools = calloc(empty_streams, + sizeof(*h->emptyFileBools)); + if (h->emptyFileBools == NULL) + return (-1); + if (read_Bools(a, h->emptyFileBools, empty_streams) < 0) + return (-1); + break; + case kAnti: + h->antiBools = calloc(empty_streams, + sizeof(*h->antiBools)); + if (h->antiBools == NULL) + return (-1); + if (read_Bools(a, h->antiBools, empty_streams) < 0) + return (-1); + break; + case kCTime: + case kATime: + case kMTime: + if (read_Times(a, h, type) < 0) + return (-1); + break; + case kName: + { + unsigned char *np; + size_t nl, nb; + + /* Skip one byte. */ + if ((p = header_bytes(a, 1)) == NULL) + return (-1); + ll--; + + if ((ll & 1) || ll < zip->numFiles * 4) + return (-1); + + zip->entry_names = malloc(ll); + if (zip->entry_names == NULL) + return (-1); + np = zip->entry_names; + nb = ll; + /* + * Copy whole file names. + * NOTE: This loop prevents from expanding + * the uncompressed buffer in order not to + * use extra memory resource. + */ + while (nb) { + size_t b; + if (nb > UBUFF_SIZE) + b = UBUFF_SIZE; + else + b = nb; + if ((p = header_bytes(a, b)) == NULL) + return (-1); + memcpy(np, p, b); + np += b; + nb -= b; + } + np = zip->entry_names; + nl = ll; + + for (i = 0; i < zip->numFiles; i++) { + entries[i].utf16name = np; +#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) + entries[i].wname = (wchar_t *)np; +#endif + + /* Find a terminator. */ + while (nl >= 2 && (np[0] || np[1])) { + np += 2; + nl -= 2; + } + if (nl < 2) + return (-1);/* Terminator not found */ + entries[i].name_len = np - entries[i].utf16name; + np += 2; + nl -= 2; + } + break; + } + case kAttributes: + { + int allAreDefined; + + if ((p = header_bytes(a, 2)) == NULL) + return (-1); + allAreDefined = *p; + h->attrBools = calloc(zip->numFiles, + sizeof(*h->attrBools)); + if (h->attrBools == NULL) + return (-1); + if (allAreDefined) + memset(h->attrBools, 1, zip->numFiles); + else { + if (read_Bools(a, h->attrBools, + zip->numFiles) < 0) + return (-1); + } + for (i = 0; i < zip->numFiles; i++) { + if (h->attrBools[i]) { + if ((p = header_bytes(a, 4)) == NULL) + return (-1); + entries[i].attr = archive_le32dec(p); + } + } + break; + } + default: + if (header_bytes(a, ll) == NULL) + return (-1); + break; + } + } + + /* + * Set up entry's attributes. + */ + folders = si->ci.folders; + eindex = sindex = 0; + folderIndex = indexInFolder = 0; + for (i = 0; i < zip->numFiles; i++) { + if (h->emptyStreamBools == NULL || h->emptyStreamBools[i] == 0) + entries[i].flg |= HAS_STREAM; + /* The high 16 bits of attributes is a posix file mode. */ + entries[i].mode = entries[i].attr >> 16; + if (entries[i].flg & HAS_STREAM) { + if ((size_t)sindex >= si->ss.unpack_streams) + return (-1); + if (entries[i].mode == 0) + entries[i].mode = AE_IFREG | 0777; + if (si->ss.digestsDefined[sindex]) + entries[i].flg |= CRC32_IS_SET; + entries[i].ssIndex = sindex; + sindex++; + } else { + int dir; + if (h->emptyFileBools == NULL) + dir = 1; + else { + if (h->emptyFileBools[eindex]) + dir = 0; + else + dir = 1; + eindex++; + } + if (entries[i].mode == 0) { + if (dir) + entries[i].mode = AE_IFDIR | 0777; + else + entries[i].mode = AE_IFREG | 0777; + } else if (dir && + (entries[i].mode & AE_IFMT) != AE_IFDIR) { + entries[i].mode &= ~AE_IFMT; + entries[i].mode |= AE_IFDIR; + } + if ((entries[i].mode & AE_IFMT) == AE_IFDIR && + entries[i].name_len >= 2 && + (entries[i].utf16name[entries[i].name_len-2] != '/' || + entries[i].utf16name[entries[i].name_len-1] != 0)) { + entries[i].utf16name[entries[i].name_len] = '/'; + entries[i].utf16name[entries[i].name_len+1] = 0; + entries[i].name_len += 2; + } + entries[i].ssIndex = -1; + } + if (entries[i].attr & 0x01) + entries[i].mode &= ~0222;/* Read only. */ + + if ((entries[i].flg & HAS_STREAM) == 0 && indexInFolder == 0) { + /* + * The entry is an empty file or a directory file, + * those both have no contents. + */ + entries[i].folderIndex = -1; + continue; + } + if (indexInFolder == 0) { + for (;;) { + if (folderIndex >= si->ci.numFolders) + return (-1); + if (folders[folderIndex].numUnpackStreams) + break; + folderIndex++; + } + } + entries[i].folderIndex = folderIndex; + if ((entries[i].flg & HAS_STREAM) == 0) + continue; + indexInFolder++; + if (indexInFolder >= folders[folderIndex].numUnpackStreams) { + folderIndex++; + indexInFolder = 0; + } + } + + return (0); +} + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +static void +fileTimeToUtc(uint64_t fileTime, time_t *time, long *ns) +{ + + if (fileTime >= EPOC_TIME) { + fileTime -= EPOC_TIME; + /* milli seconds base */ + *time = (time_t)(fileTime / 10000000); + /* nano seconds base */ + *ns = (long)(fileTime % 10000000) * 100; + } else { + *time = 0; + *ns = 0; + } +} + +static int +read_Times(struct archive_read *a, struct _7z_header_info *h, int type) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + struct _7zip_entry *entries = zip->entries; + unsigned char *timeBools; + int allAreDefined; + unsigned i; + + timeBools = calloc(zip->numFiles, sizeof(*timeBools)); + if (timeBools == NULL) + return (-1); + + /* Read allAreDefined. */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + allAreDefined = *p; + if (allAreDefined) + memset(timeBools, 1, zip->numFiles); + else { + if (read_Bools(a, timeBools, zip->numFiles) < 0) + goto failed; + } + + /* Read external. */ + if ((p = header_bytes(a, 1)) == NULL) + goto failed; + if (*p) { + if (parse_7zip_uint64(a, &(h->dataIndex)) < 0) + goto failed; + if (1000000 < h->dataIndex) + return (-1); + } + + for (i = 0; i < zip->numFiles; i++) { + if (!timeBools[i]) + continue; + if ((p = header_bytes(a, 8)) == NULL) + goto failed; + switch (type) { + case kCTime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].ctime), + &(entries[i].ctime_ns)); + entries[i].flg |= CTIME_IS_SET; + break; + case kATime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].atime), + &(entries[i].atime_ns)); + entries[i].flg |= ATIME_IS_SET; + break; + case kMTime: + fileTimeToUtc(archive_le64dec(p), + &(entries[i].mtime), + &(entries[i].mtime_ns)); + entries[i].flg |= MTIME_IS_SET; + break; + } + } + + free(timeBools); + return (0); +failed: + free(timeBools); + return (-1); +} + +static int +decode_encoded_header_info(struct archive_read *a, struct _7z_stream_info *si) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + + errno = 0; + if (read_StreamsInfo(a, si) < 0) { + if (errno == ENOMEM) + archive_set_error(&a->archive, -1, + "Couldn't allocate memory"); + else + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + if (si->pi.numPackStreams == 0 || si->ci.numFolders == 0) { + archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + if (zip->header_offset < si->pi.pos + si->pi.sizes[0] || + (int64_t)(si->pi.pos + si->pi.sizes[0]) < 0 || + si->pi.sizes[0] == 0 || (int64_t)si->pi.pos < 0) { + archive_set_error(&a->archive, -1, "Malformed Header offset"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +} + +static const unsigned char * +header_bytes(struct archive_read *a, size_t rbytes) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const unsigned char *p; + + if (zip->header_bytes_remaining < rbytes) + return (NULL); + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + + if (zip->header_is_encoded == 0) { + p = __archive_read_ahead(a, rbytes, NULL); + if (p == NULL) + return (NULL); + zip->header_bytes_remaining -= rbytes; + zip->pack_stream_bytes_unconsumed = rbytes; + } else { + const void *buff; + ssize_t bytes; + + bytes = read_stream(a, &buff, rbytes, rbytes); + if (bytes <= 0) + return (NULL); + zip->header_bytes_remaining -= bytes; + p = buff; + } + + /* Update checksum */ + zip->header_crc32 = crc32(zip->header_crc32, p, rbytes); + return (p); +} + +static int +slurp_central_directory(struct archive_read *a, struct _7zip *zip, + struct _7z_header_info *header) +{ + const unsigned char *p; + uint64_t next_header_offset; + uint64_t next_header_size; + uint32_t next_header_crc; + ssize_t bytes_avail; + int check_header_crc, r; + + if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL) + return (ARCHIVE_FATAL); + + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + /* This is an executable ? Must be self-extracting... */ + r = skip_sfx(a, bytes_avail); + if (r < ARCHIVE_WARN) + return (r); + if ((p = __archive_read_ahead(a, 32, &bytes_avail)) == NULL) + return (ARCHIVE_FATAL); + } + zip->seek_base += 32; + + if (memcmp(p, _7ZIP_SIGNATURE, 6) != 0) { + archive_set_error(&a->archive, -1, "Not 7-Zip archive file"); + return (ARCHIVE_FATAL); + } + + /* CRC check. */ + if (crc32(0, (unsigned char *)p + 12, 20) != archive_le32dec(p + 8)) { + archive_set_error(&a->archive, -1, "Header CRC error"); + return (ARCHIVE_FATAL); + } + + next_header_offset = archive_le64dec(p + 12); + next_header_size = archive_le64dec(p + 20); + next_header_crc = archive_le32dec(p + 28); + + if (next_header_size == 0) + /* There is no entry in an archive file. */ + return (ARCHIVE_EOF); + + if (((int64_t)next_header_offset) < 0) { + archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, 32); + if (next_header_offset != 0) { + if (bytes_avail >= next_header_offset) + __archive_read_consume(a, next_header_offset); + else if (__archive_read_seek(a, + next_header_offset + zip->seek_base, SEEK_SET) < 0) + return (ARCHIVE_FATAL); + } + zip->stream_offset = next_header_offset; + zip->header_offset = next_header_offset; + zip->header_bytes_remaining = next_header_size; + zip->header_crc32 = 0; + zip->header_is_encoded = 0; + zip->header_is_being_read = 1; + check_header_crc = 1; + + if ((p = header_bytes(a, 1)) == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + /* Parse ArchiveProperties. */ + switch (p[0]) { + case kEncodedHeader: + /* + * The archive has an encoded header and we have to decode it + * in order to parse the header correctly. + */ + r = decode_encoded_header_info(a, &(zip->si)); + + /* Check the EncodedHeader CRC.*/ + if (r == 0 && zip->header_crc32 != next_header_crc) { + archive_set_error(&a->archive, -1, + "Damaged 7-Zip archive"); + r = -1; + } + if (r == 0) { + if (zip->si.ci.folders[0].digest_defined) + next_header_crc = zip->si.ci.folders[0].digest; + else + check_header_crc = 0; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + r = setup_decode_folder(a, zip->si.ci.folders, 1); + if (r == 0) { + zip->header_bytes_remaining = + zip->folder_outbytes_remaining; + r = seek_pack(a); + } + } + /* Clean up StreamsInfo. */ + free_StreamsInfo(&(zip->si)); + memset(&(zip->si), 0, sizeof(zip->si)); + if (r < 0) + return (ARCHIVE_FATAL); + zip->header_is_encoded = 1; + zip->header_crc32 = 0; + /* FALL THROUGH */ + case kHeader: + /* + * Parse the header. + */ + errno = 0; + r = read_Header(a, header, zip->header_is_encoded); + if (r < 0) { + if (errno == ENOMEM) + archive_set_error(&a->archive, -1, + "Couldn't allocate memory"); + else + archive_set_error(&a->archive, -1, + "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* + * Must be kEnd. + */ + if ((p = header_bytes(a, 1)) == NULL ||*p != kEnd) { + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* Check the Header CRC.*/ + if (check_header_crc && zip->header_crc32 != next_header_crc) { + archive_set_error(&a->archive, -1, + "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + break; + default: + archive_set_error(&a->archive, -1, + "Unexpected Property ID = %X", p[0]); + return (ARCHIVE_FATAL); + } + + /* Clean up variables be used for decoding the archive header */ + zip->pack_stream_remaining = 0; + zip->pack_stream_index = 0; + zip->folder_outbytes_remaining = 0; + zip->uncompressed_buffer_bytes_remaining = 0; + zip->pack_stream_bytes_unconsumed = 0; + zip->header_is_being_read = 0; + + return (ARCHIVE_OK); +} + +static ssize_t +get_uncompressed_data(struct archive_read *a, const void **buff, size_t size, + size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + ssize_t bytes_avail; + + if (zip->codec == _7Z_COPY && zip->codec2 == -1) { + /* Copy mode. */ + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + *buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file data"); + return (ARCHIVE_FATAL); + } + if ((size_t)bytes_avail > + zip->uncompressed_buffer_bytes_remaining) + bytes_avail = (ssize_t) + zip->uncompressed_buffer_bytes_remaining; + if ((size_t)bytes_avail > size) + bytes_avail = (ssize_t)size; + + zip->pack_stream_bytes_unconsumed = bytes_avail; + } else if (zip->uncompressed_buffer_pointer == NULL) { + /* Decompression has failed. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } else { + /* Packed mode. */ + if (minimum > zip->uncompressed_buffer_bytes_remaining) { + /* + * If remaining uncompressed data size is less than + * the minimum size, fill the buffer up to the + * minimum size. + */ + if (extract_pack_stream(a, minimum) < 0) + return (ARCHIVE_FATAL); + } + if (size > zip->uncompressed_buffer_bytes_remaining) + bytes_avail = (ssize_t) + zip->uncompressed_buffer_bytes_remaining; + else + bytes_avail = (ssize_t)size; + *buff = zip->uncompressed_buffer_pointer; + zip->uncompressed_buffer_pointer += bytes_avail; + } + zip->uncompressed_buffer_bytes_remaining -= bytes_avail; + return (bytes_avail); +} + +static ssize_t +extract_pack_stream(struct archive_read *a, size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + ssize_t bytes_avail; + int r; + + if (zip->codec == _7Z_COPY && zip->codec2 == -1) { + if (minimum == 0) + minimum = 1; + if (__archive_read_ahead(a, minimum, &bytes_avail) == NULL + || bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > zip->pack_stream_inbytes_remaining) + bytes_avail = zip->pack_stream_inbytes_remaining; + zip->pack_stream_inbytes_remaining -= bytes_avail; + if (bytes_avail > zip->folder_outbytes_remaining) + bytes_avail = zip->folder_outbytes_remaining; + zip->folder_outbytes_remaining -= bytes_avail; + zip->uncompressed_buffer_bytes_remaining = bytes_avail; + return (ARCHIVE_OK); + } + + /* If the buffer hasn't been allocated, allocate it now. */ + if (zip->uncompressed_buffer == NULL) { + zip->uncompressed_buffer_size = UBUFF_SIZE; + if (zip->uncompressed_buffer_size < minimum) { + zip->uncompressed_buffer_size = minimum + 1023; + zip->uncompressed_buffer_size &= ~0x3ff; + } + zip->uncompressed_buffer = + malloc(zip->uncompressed_buffer_size); + if (zip->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + zip->uncompressed_buffer_bytes_remaining = 0; + } else if (zip->uncompressed_buffer_size < minimum || + zip->uncompressed_buffer_bytes_remaining < minimum) { + /* + * Make sure the uncompressed buffer can have bytes + * at least `minimum' bytes. + * NOTE: This case happen when reading the header. + */ + size_t used; + if (zip->uncompressed_buffer_pointer != 0) + used = zip->uncompressed_buffer_pointer - + zip->uncompressed_buffer; + else + used = 0; + if (zip->uncompressed_buffer_size < minimum) { + /* + * Expand the uncompressed buffer up to + * the minimum size. + */ + zip->uncompressed_buffer_size = minimum + 1023; + zip->uncompressed_buffer_size &= ~0x3ff; + zip->uncompressed_buffer = + realloc(zip->uncompressed_buffer, + zip->uncompressed_buffer_size); + if (zip->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + } + /* + * Move unconsumed bytes to the head. + */ + if (used) { + memmove(zip->uncompressed_buffer, + zip->uncompressed_buffer + used, + zip->uncompressed_buffer_bytes_remaining); + } + } else + zip->uncompressed_buffer_bytes_remaining = 0; + zip->uncompressed_buffer_pointer = NULL; + for (;;) { + size_t bytes_in, bytes_out; + const void *buff_in; + unsigned char *buff_out; + int eof; + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + buff_in = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + + buff_out = zip->uncompressed_buffer + + zip->uncompressed_buffer_bytes_remaining; + bytes_out = zip->uncompressed_buffer_size + - zip->uncompressed_buffer_bytes_remaining; + bytes_in = bytes_avail; + if (bytes_in > zip->pack_stream_inbytes_remaining) + bytes_in = zip->pack_stream_inbytes_remaining; + /* Drive decompression. */ + r = decompress(a, zip, buff_out, &bytes_out, + buff_in, &bytes_in); + switch (r) { + case ARCHIVE_OK: + eof = 0; + break; + case ARCHIVE_EOF: + eof = 1; + break; + default: + return (ARCHIVE_FATAL); + } + zip->pack_stream_inbytes_remaining -= bytes_in; + if (bytes_out > zip->folder_outbytes_remaining) + bytes_out = zip->folder_outbytes_remaining; + zip->folder_outbytes_remaining -= bytes_out; + zip->uncompressed_buffer_bytes_remaining += bytes_out; + zip->pack_stream_bytes_unconsumed = bytes_in; + + /* + * Continue decompression until uncompressed_buffer is full. + */ + if (zip->uncompressed_buffer_bytes_remaining == + zip->uncompressed_buffer_size) + break; + if (zip->codec2 == _7Z_X86 && zip->odd_bcj_size && + zip->uncompressed_buffer_bytes_remaining + 5 > + zip->uncompressed_buffer_size) + break; + if (zip->pack_stream_inbytes_remaining == 0 && + zip->folder_outbytes_remaining == 0) + break; + if (eof || (bytes_in == 0 && bytes_out == 0)) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + read_consume(a); + } + if (zip->uncompressed_buffer_bytes_remaining < minimum) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->uncompressed_buffer_pointer = zip->uncompressed_buffer; + return (ARCHIVE_OK); +} + +static int +seek_pack(struct archive_read *a) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + uint64_t pack_offset; + + if (zip->pack_stream_remaining <= 0) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Damaged 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->pack_stream_inbytes_remaining = + zip->si.pi.sizes[zip->pack_stream_index]; + pack_offset = zip->si.pi.positions[zip->pack_stream_index]; + if (zip->stream_offset != pack_offset) { + if (0 > __archive_read_seek(a, pack_offset + zip->seek_base, + SEEK_SET)) + return (ARCHIVE_FATAL); + zip->stream_offset = pack_offset; + } + zip->pack_stream_index++; + zip->pack_stream_remaining--; + return (ARCHIVE_OK); +} + +static ssize_t +read_stream(struct archive_read *a, const void **buff, size_t size, + size_t minimum) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + uint64_t skip_bytes = 0; + int r; + + if (zip->uncompressed_buffer_bytes_remaining == 0) { + if (zip->pack_stream_inbytes_remaining > 0) { + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + return (get_uncompressed_data(a, buff, size, minimum)); + } else if (zip->folder_outbytes_remaining > 0) { + /* Extract a remaining pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + return (get_uncompressed_data(a, buff, size, minimum)); + } + } else + return (get_uncompressed_data(a, buff, size, minimum)); + + /* + * Current pack stream has been consumed. + */ + if (zip->pack_stream_remaining == 0) { + if (zip->header_is_being_read) { + /* Invalid sequence. This might happen when + * reading a malformed archive. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, "Malformed 7-Zip archive"); + return (ARCHIVE_FATAL); + } + + /* + * All current folder's pack streams have been + * consumed. Switch to next folder. + */ + if (zip->folder_index == 0 && + (zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes + || zip->folder_index != zip->entry->folderIndex)) { + zip->folder_index = zip->entry->folderIndex; + skip_bytes = + zip->si.ci.folders[zip->folder_index].skipped_bytes; + } + + if (zip->folder_index >= zip->si.ci.numFolders) { + /* + * We have consumed all folders and its pack streams. + */ + *buff = NULL; + return (0); + } + r = setup_decode_folder(a, + &(zip->si.ci.folders[zip->folder_index]), 0); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + zip->folder_index++; + } + + /* + * Switch to next pack stream. + */ + r = seek_pack(a); + if (r < 0) + return (r); + + /* Extract a new pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + + /* + * Skip the bytes we alrady has skipped in skip_stream(). + */ + while (skip_bytes) { + ssize_t skipped; + + if (zip->uncompressed_buffer_bytes_remaining == 0) { + if (zip->pack_stream_inbytes_remaining > 0) { + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + } else if (zip->folder_outbytes_remaining > 0) { + /* Extract a remaining pack stream. */ + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + } else { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + } + skipped = get_uncompressed_data(a, buff, skip_bytes, 0); + if (skipped < 0) + return (skipped); + skip_bytes -= skipped; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + + return (get_uncompressed_data(a, buff, size, minimum)); +} + +static int +setup_decode_folder(struct archive_read *a, struct _7z_folder *folder, + int header) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const struct _7z_coder *coder1, *coder2; + const char *cname = (header)?"archive header":"file content"; + unsigned i; + int r, found_bcj2 = 0; + + /* + * Release the memory which the previous folder used for BCJ2. + */ + for (i = 0; i < 3; i++) { + if (zip->sub_stream_buff[i] != NULL) + free(zip->sub_stream_buff[i]); + zip->sub_stream_buff[i] = NULL; + } + + /* + * Initialize a stream reader. + */ + zip->pack_stream_remaining = (unsigned)folder->numPackedStreams; + zip->pack_stream_index = (unsigned)folder->packIndex; + zip->folder_outbytes_remaining = folder_uncompressed_size(folder); + zip->uncompressed_buffer_bytes_remaining = 0; + + /* + * Check coder types. + */ + for (i = 0; i < folder->numCoders; i++) { + if (folder->coders[i].codec == _7Z_CRYPTO) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "The %s is encrypted, " + "but currently not supported", cname); + return (ARCHIVE_FATAL); + } + if (folder->coders[i].codec == _7Z_X86_BCJ2) + found_bcj2++; + } + if ((folder->numCoders > 2 && !found_bcj2) || found_bcj2 > 1) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "The %s is encoded with many filters, " + "but currently not supported", cname); + return (ARCHIVE_FATAL); + } + coder1 = &(folder->coders[0]); + if (folder->numCoders == 2) + coder2 = &(folder->coders[1]); + else + coder2 = NULL; + + if (found_bcj2) { + /* + * Preparation to decode BCJ2. + * Decoding BCJ2 requires four sources. Those are at least, + * as far as I know, two types of the storage form. + */ + const struct _7z_coder *fc = folder->coders; + static const struct _7z_coder coder_copy = {0, 1, 1, 0, NULL}; + const struct _7z_coder *scoder[3] = + {&coder_copy, &coder_copy, &coder_copy}; + const void *buff; + ssize_t bytes; + unsigned char *b[3] = {NULL, NULL, NULL}; + uint64_t sunpack[3] ={-1, -1, -1}; + size_t s[3] = {0, 0, 0}; + int idx[3] = {0, 1, 2}; + + if (folder->numCoders == 4 && fc[3].codec == _7Z_X86_BCJ2 && + folder->numInStreams == 7 && folder->numOutStreams == 4 && + zip->pack_stream_remaining == 4) { + /* Source type 1 made by 7zr or 7z with -m options. */ + if (folder->bindPairs[0].inIndex == 5) { + /* The form made by 7zr */ + idx[0] = 1; idx[1] = 2; idx[2] = 0; + scoder[1] = &(fc[1]); + scoder[2] = &(fc[0]); + sunpack[1] = folder->unPackSize[1]; + sunpack[2] = folder->unPackSize[0]; + coder1 = &(fc[2]); + } else { + /* + * NOTE: Some patterns do not work. + * work: + * 7z a -m0=BCJ2 -m1=COPY -m2=COPY + * -m3=(any) + * 7z a -m0=BCJ2 -m1=COPY -m2=(any) + * -m3=COPY + * 7z a -m0=BCJ2 -m1=(any) -m2=COPY + * -m3=COPY + * not work: + * other patterns. + * + * We have to handle this like `pipe' or + * our libarchive7s filter frame work, + * decoding the BCJ2 main stream sequentially, + * m3 -> m2 -> m1 -> BCJ2. + * + */ + if (fc[0].codec == _7Z_COPY && + fc[1].codec == _7Z_COPY) + coder1 = &(folder->coders[2]); + else if (fc[0].codec == _7Z_COPY && + fc[2].codec == _7Z_COPY) + coder1 = &(folder->coders[1]); + else if (fc[1].codec == _7Z_COPY && + fc[2].codec == _7Z_COPY) + coder1 = &(folder->coders[0]); + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unsupported form of " + "BCJ2 streams"); + return (ARCHIVE_FATAL); + } + } + coder2 = &(fc[3]); + zip->main_stream_bytes_remaining = + folder->unPackSize[2]; + } else if (coder2 != NULL && coder2->codec == _7Z_X86_BCJ2 && + zip->pack_stream_remaining == 4 && + folder->numInStreams == 5 && folder->numOutStreams == 2) { + /* Source type 0 made by 7z */ + zip->main_stream_bytes_remaining = + folder->unPackSize[0]; + } else { + /* We got an unexpected form. */ + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unsupported form of BCJ2 streams"); + return (ARCHIVE_FATAL); + } + + /* Skip the main stream at this time. */ + if ((r = seek_pack(a)) < 0) + return (r); + zip->pack_stream_bytes_unconsumed = + zip->pack_stream_inbytes_remaining; + read_consume(a); + + /* Read following three sub streams. */ + for (i = 0; i < 3; i++) { + const struct _7z_coder *coder = scoder[i]; + + if ((r = seek_pack(a)) < 0) + return (r); + + if (sunpack[i] == -1) + zip->folder_outbytes_remaining = + zip->pack_stream_inbytes_remaining; + else + zip->folder_outbytes_remaining = sunpack[i]; + + r = init_decompression(a, zip, coder, NULL); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Allocate memory for the decorded data of a sub + * stream. */ + b[i] = malloc(zip->folder_outbytes_remaining); + if (b[i] == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + + /* Extract a sub stream. */ + while (zip->pack_stream_inbytes_remaining > 0) { + r = extract_pack_stream(a, 0); + if (r < 0) + return (r); + bytes = get_uncompressed_data(a, &buff, + zip->uncompressed_buffer_bytes_remaining, + 0); + if (bytes < 0) + return ((int)bytes); + memcpy(b[i]+s[i], buff, bytes); + s[i] += bytes; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + } + + /* Set the sub streams to the right place. */ + for (i = 0; i < 3; i++) { + zip->sub_stream_buff[i] = b[idx[i]]; + zip->sub_stream_size[i] = s[idx[i]]; + zip->sub_stream_bytes_remaining[i] = s[idx[i]]; + } + + /* Allocate memory used for decoded main stream bytes. */ + if (zip->tmp_stream_buff == NULL) { + zip->tmp_stream_buff_size = 32 * 1024; + zip->tmp_stream_buff = + malloc(zip->tmp_stream_buff_size); + if (zip->tmp_stream_buff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for 7-Zip decompression"); + return (ARCHIVE_FATAL); + } + } + zip->tmp_stream_bytes_avail = 0; + zip->tmp_stream_bytes_remaining = 0; + zip->odd_bcj_size = 0; + zip->bcj2_outPos = 0; + + /* + * Reset a stream reader in order to read the main stream + * of BCJ2. + */ + zip->pack_stream_remaining = 1; + zip->pack_stream_index = (unsigned)folder->packIndex; + zip->folder_outbytes_remaining = + folder_uncompressed_size(folder); + zip->uncompressed_buffer_bytes_remaining = 0; + } + + /* + * Initialize the decompressor for the new folder's pack streams. + */ + r = init_decompression(a, zip, coder1, coder2); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + +static int64_t +skip_stream(struct archive_read *a, size_t skip_bytes) +{ + struct _7zip *zip = (struct _7zip *)a->format->data; + const void *p; + int64_t skipped_bytes; + size_t bytes = skip_bytes; + + if (zip->folder_index == 0) { + /* + * Optimization for a list mode. + * Avoid unncecessary decoding operations. + */ + zip->si.ci.folders[zip->entry->folderIndex].skipped_bytes + += skip_bytes; + return (skip_bytes); + } + + while (bytes) { + skipped_bytes = read_stream(a, &p, bytes, 0); + if (skipped_bytes < 0) + return (skipped_bytes); + if (skipped_bytes == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated 7-Zip file body"); + return (ARCHIVE_FATAL); + } + bytes -= skipped_bytes; + if (zip->pack_stream_bytes_unconsumed) + read_consume(a); + } + return (skip_bytes); +} + +/* + * Brought from LZMA SDK. + * + * Bra86.c -- Converter for x86 code (BCJ) + * 2008-10-04 : Igor Pavlov : Public domain + * + */ + +#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF) + +static void +x86_Init(struct _7zip *zip) +{ + zip->bcj_state = 0; + zip->bcj_prevPosT = (size_t)0 - 1; + zip->bcj_prevMask = 0; + zip->bcj_ip = 5; +} + +static size_t +x86_Convert(struct _7zip *zip, uint8_t *data, size_t size) +{ + static const uint8_t kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0}; + static const uint8_t kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3}; + size_t bufferPos, prevPosT; + uint32_t ip, prevMask; + + if (size < 5) + return 0; + + bufferPos = 0; + prevPosT = zip->bcj_prevPosT; + prevMask = zip->bcj_prevMask; + ip = zip->bcj_ip; + + for (;;) { + uint8_t *p = data + bufferPos; + uint8_t *limit = data + size - 4; + + for (; p < limit; p++) + if ((*p & 0xFE) == 0xE8) + break; + bufferPos = (size_t)(p - data); + if (p >= limit) + break; + prevPosT = bufferPos - prevPosT; + if (prevPosT > 3) + prevMask = 0; + else { + prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7; + if (prevMask != 0) { + unsigned char b = + p[4 - kMaskToBitNumber[prevMask]]; + if (!kMaskToAllowedStatus[prevMask] || + Test86MSByte(b)) { + prevPosT = bufferPos; + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + continue; + } + } + } + prevPosT = bufferPos; + + if (Test86MSByte(p[4])) { + uint32_t src = ((uint32_t)p[4] << 24) | + ((uint32_t)p[3] << 16) | ((uint32_t)p[2] << 8) | + ((uint32_t)p[1]); + uint32_t dest; + for (;;) { + uint8_t b; + int index; + + dest = src - (ip + (uint32_t)bufferPos); + if (prevMask == 0) + break; + index = kMaskToBitNumber[prevMask] * 8; + b = (uint8_t)(dest >> (24 - index)); + if (!Test86MSByte(b)) + break; + src = dest ^ ((1 << (32 - index)) - 1); + } + p[4] = (uint8_t)(~(((dest >> 24) & 1) - 1)); + p[3] = (uint8_t)(dest >> 16); + p[2] = (uint8_t)(dest >> 8); + p[1] = (uint8_t)dest; + bufferPos += 5; + } else { + prevMask = ((prevMask << 1) & 0x7) | 1; + bufferPos++; + } + } + zip->bcj_prevPosT = prevPosT; + zip->bcj_prevMask = prevMask; + zip->bcj_ip += bufferPos; + return (bufferPos); +} + +/* + * Brought from LZMA SDK. + * + * Bcj2.c -- Converter for x86 code (BCJ2) + * 2008-10-04 : Igor Pavlov : Public domain + * + */ + +#define SZ_ERROR_DATA ARCHIVE_FAILED + +#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80) +#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)) + +#define kNumTopBits 24 +#define kTopValue ((uint32_t)1 << kNumTopBits) + +#define kNumBitModelTotalBits 11 +#define kBitModelTotal (1 << kNumBitModelTotalBits) +#define kNumMoveBits 5 + +#define RC_READ_BYTE (*buffer++) +#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; } +#define RC_INIT2 zip->bcj2_code = 0; zip->bcj2_range = 0xFFFFFFFF; \ + { int i; for (i = 0; i < 5; i++) { RC_TEST; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; }} + +#define NORMALIZE if (zip->bcj2_range < kTopValue) { RC_TEST; zip->bcj2_range <<= 8; zip->bcj2_code = (zip->bcj2_code << 8) | RC_READ_BYTE; } + +#define IF_BIT_0(p) ttt = *(p); bound = (zip->bcj2_range >> kNumBitModelTotalBits) * ttt; if (zip->bcj2_code < bound) +#define UPDATE_0(p) zip->bcj2_range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE; +#define UPDATE_1(p) zip->bcj2_range -= bound; zip->bcj2_code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE; + +static ssize_t +Bcj2_Decode(struct _7zip *zip, uint8_t *outBuf, size_t outSize) +{ + size_t inPos = 0, outPos = 0; + const uint8_t *buf0, *buf1, *buf2, *buf3; + size_t size0, size1, size2, size3; + const uint8_t *buffer, *bufferLim; + unsigned int i, j; + + size0 = zip->tmp_stream_bytes_remaining; + buf0 = zip->tmp_stream_buff + zip->tmp_stream_bytes_avail - size0; + size1 = zip->sub_stream_bytes_remaining[0]; + buf1 = zip->sub_stream_buff[0] + zip->sub_stream_size[0] - size1; + size2 = zip->sub_stream_bytes_remaining[1]; + buf2 = zip->sub_stream_buff[1] + zip->sub_stream_size[1] - size2; + size3 = zip->sub_stream_bytes_remaining[2]; + buf3 = zip->sub_stream_buff[2] + zip->sub_stream_size[2] - size3; + + buffer = buf3; + bufferLim = buffer + size3; + + if (zip->bcj_state == 0) { + /* + * Initialize. + */ + zip->bcj2_prevByte = 0; + for (i = 0; + i < sizeof(zip->bcj2_p) / sizeof(zip->bcj2_p[0]); i++) + zip->bcj2_p[i] = kBitModelTotal >> 1; + RC_INIT2; + zip->bcj_state = 1; + } + + /* + * Gather the odd bytes of a previous call. + */ + for (i = 0; zip->odd_bcj_size > 0 && outPos < outSize; i++) { + outBuf[outPos++] = zip->odd_bcj[i]; + zip->odd_bcj_size--; + } + + if (outSize == 0) { + zip->bcj2_outPos += outPos; + return (outPos); + } + + for (;;) { + uint8_t b; + CProb *prob; + uint32_t bound; + uint32_t ttt; + + size_t limit = size0 - inPos; + if (outSize - outPos < limit) + limit = outSize - outPos; + + if (zip->bcj_state == 1) { + while (limit != 0) { + uint8_t b = buf0[inPos]; + outBuf[outPos++] = b; + if (IsJ(zip->bcj2_prevByte, b)) { + zip->bcj_state = 2; + break; + } + inPos++; + zip->bcj2_prevByte = b; + limit--; + } + } + + if (limit == 0 || outPos == outSize) + break; + zip->bcj_state = 1; + + b = buf0[inPos++]; + + if (b == 0xE8) + prob = zip->bcj2_p + zip->bcj2_prevByte; + else if (b == 0xE9) + prob = zip->bcj2_p + 256; + else + prob = zip->bcj2_p + 257; + + IF_BIT_0(prob) { + UPDATE_0(prob) + zip->bcj2_prevByte = b; + } else { + uint32_t dest; + const uint8_t *v; + uint8_t out[4]; + + UPDATE_1(prob) + if (b == 0xE8) { + v = buf1; + if (size1 < 4) + return SZ_ERROR_DATA; + buf1 += 4; + size1 -= 4; + } else { + v = buf2; + if (size2 < 4) + return SZ_ERROR_DATA; + buf2 += 4; + size2 -= 4; + } + dest = (((uint32_t)v[0] << 24) | + ((uint32_t)v[1] << 16) | + ((uint32_t)v[2] << 8) | + ((uint32_t)v[3])) - + ((uint32_t)zip->bcj2_outPos + outPos + 4); + out[0] = (uint8_t)dest; + out[1] = (uint8_t)(dest >> 8); + out[2] = (uint8_t)(dest >> 16); + out[3] = zip->bcj2_prevByte = (uint8_t)(dest >> 24); + + for (i = 0; i < 4 && outPos < outSize; i++) + outBuf[outPos++] = out[i]; + if (i < 4) { + /* + * Save odd bytes which we could not add into + * the output buffer because of out of space. + */ + zip->odd_bcj_size = 4 -i; + for (; i < 4; i++) { + j = i - 4 + zip->odd_bcj_size; + zip->odd_bcj[j] = out[i]; + } + break; + } + } + } + zip->tmp_stream_bytes_remaining -= inPos; + zip->sub_stream_bytes_remaining[0] = size1; + zip->sub_stream_bytes_remaining[1] = size2; + zip->sub_stream_bytes_remaining[2] = bufferLim - buffer; + zip->bcj2_outPos += outPos; + + return ((ssize_t)outPos); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c index 84b9bd34b..53fe6fa39 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_all.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,19 +24,64 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_all.c,v 1.10 2007/12/30 04:58:21 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_all.c 174991 2007-12-30 04:58:22Z kientzle $"); #include "archive.h" +#include "archive_private.h" int archive_read_support_format_all(struct archive *a) { - archive_read_support_format_ar(a); - archive_read_support_format_cpio(a); - archive_read_support_format_empty(a); - archive_read_support_format_iso9660(a); - archive_read_support_format_mtree(a); - archive_read_support_format_tar(a); - archive_read_support_format_zip(a); - return (ARCHIVE_OK); + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_all"); + + /* TODO: It would be nice to compute the ordering + * here automatically so that people who enable just + * a few formats can still get the benefits. That + * may just require the format registration to include + * a "maximum read-ahead" value (anything that uses seek + * would be essentially infinite read-ahead). The core + * bid management can then sort the bidders before calling + * them. + * + * If you implement the above, please return the list below + * to alphabetic order. + */ + + /* + * These bidders are all pretty cheap; they just examine a + * small initial part of the archive. If one of these bids + * high, we can maybe avoid running any of the more expensive + * bidders below. + */ + archive_read_support_format_ar(a); + archive_read_support_format_cpio(a); + archive_read_support_format_empty(a); + archive_read_support_format_lha(a); + archive_read_support_format_mtree(a); + archive_read_support_format_tar(a); + archive_read_support_format_xar(a); + + /* + * Install expensive bidders last. By doing them last, we + * increase the chance that a high bid from someone else will + * make it unnecessary for these to do anything at all. + */ + /* These three have potentially large look-ahead. */ + archive_read_support_format_7zip(a); + archive_read_support_format_cab(a); + archive_read_support_format_rar(a); + archive_read_support_format_iso9660(a); + /* Seek is really bad, since it forces the read-ahead + * logic to discard buffered data. */ + archive_read_support_format_zip(a); + + /* Note: We always return ARCHIVE_OK here, even if some of the + * above return ARCHIVE_WARN. The intent here is to enable + * "as much as possible." Clients who need specific + * compression should enable those individually so they can + * verify the level of support. */ + /* Clear any warning messages set by the above functions. */ + archive_clear_error(a); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c index bacfbbcf7..9feb547db 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_ar.c @@ -26,7 +26,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_ar.c,v 1.12 2008/12/17 19:02:42 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_ar.c 201101 2009-12-28 03:06:27Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -50,11 +50,17 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_ar.c,v 1.12 2 #include "archive_read_private.h" struct ar { - off_t entry_bytes_remaining; - off_t entry_offset; - off_t entry_padding; - char *strtab; - size_t strtab_size; + int64_t entry_bytes_remaining; + /* unconsumed is purely to track data we've gotten from readahead, + * but haven't yet marked as consumed. Must be paired with + * entry_bytes_remaining usage/modification. + */ + size_t entry_bytes_unconsumed; + int64_t entry_offset; + int64_t entry_padding; + char *strtab; + size_t strtab_size; + char read_global_header; }; /* @@ -75,513 +81,545 @@ struct ar { #define AR_fmag_offset 58 #define AR_fmag_size 2 -static int archive_read_format_ar_bid(struct archive_read *a); -static int archive_read_format_ar_cleanup(struct archive_read *a); -static int archive_read_format_ar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static int archive_read_format_ar_skip(struct archive_read *a); -static int archive_read_format_ar_read_header(struct archive_read *a, - struct archive_entry *e); -static uint64_t ar_atol8(const char *p, unsigned char_cnt); -static uint64_t ar_atol10(const char *p, unsigned char_cnt); -static int ar_parse_gnu_filename_table(struct archive_read *a); -static int ar_parse_common_header(struct ar *ar, struct archive_entry *, - const char *h); +static int archive_read_format_ar_bid(struct archive_read *a, int); +static int archive_read_format_ar_cleanup(struct archive_read *a); +static int archive_read_format_ar_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset); +static int archive_read_format_ar_skip(struct archive_read *a); +static int archive_read_format_ar_read_header(struct archive_read *a, + struct archive_entry *e); +static uint64_t ar_atol8(const char *p, unsigned char_cnt); +static uint64_t ar_atol10(const char *p, unsigned char_cnt); +static int ar_parse_gnu_filename_table(struct archive_read *a); +static int ar_parse_common_header(struct ar *ar, struct archive_entry *, + const char *h); int archive_read_support_format_ar(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - struct ar *ar; - int r; - - ar = (struct ar *)malloc(sizeof(*ar)); - if (ar == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate ar data"); - return (ARCHIVE_FATAL); - } - memset(ar, 0, sizeof(*ar)); - ar->strtab = NULL; - - r = __archive_read_register_format(a, - ar, - "ar", - archive_read_format_ar_bid, - NULL, - archive_read_format_ar_read_header, - archive_read_format_ar_read_data, - archive_read_format_ar_skip, - archive_read_format_ar_cleanup); - - if (r != ARCHIVE_OK) { - free(ar); - return (r); - } - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + struct ar *ar; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_ar"); + + ar = (struct ar *)malloc(sizeof(*ar)); + if (ar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate ar data"); + return (ARCHIVE_FATAL); + } + memset(ar, 0, sizeof(*ar)); + ar->strtab = NULL; + + r = __archive_read_register_format(a, + ar, + "ar", + archive_read_format_ar_bid, + NULL, + archive_read_format_ar_read_header, + archive_read_format_ar_read_data, + archive_read_format_ar_skip, + archive_read_format_ar_cleanup); + + if (r != ARCHIVE_OK) { + free(ar); + return (r); + } + return (ARCHIVE_OK); } static int archive_read_format_ar_cleanup(struct archive_read *a) { - struct ar *ar; - - ar = (struct ar *)(a->format->data); - if (ar->strtab) - free(ar->strtab); - free(ar); - (a->format->data) = NULL; - return (ARCHIVE_OK); + struct ar *ar; + + ar = (struct ar *)(a->format->data); + if (ar->strtab) + free(ar->strtab); + free(ar); + (a->format->data) = NULL; + return (ARCHIVE_OK); } static int -archive_read_format_ar_bid(struct archive_read *a) +archive_read_format_ar_bid(struct archive_read *a, int best_bid) { - struct ar *ar; - const void *h; - - if (a->archive.archive_format != 0 && - (a->archive.archive_format & ARCHIVE_FORMAT_BASE_MASK) != - ARCHIVE_FORMAT_AR) - return(0); - - ar = (struct ar *)(a->format->data); - - /* - * Verify the 8-byte file signature. - * TODO: Do we need to check more than this? - */ - if ((h = __archive_read_ahead(a, 8, NULL)) == NULL) - return (-1); - if (strncmp((const char*)h, "!\n", 8) == 0) { - return (64); - } - return (-1); + const void *h; + + (void)best_bid; /* UNUSED */ + + /* + * Verify the 8-byte file signature. + * TODO: Do we need to check more than this? + */ + if ((h = __archive_read_ahead(a, 8, NULL)) == NULL) + return (-1); + if (memcmp(h, "!\n", 8) == 0) { + return (64); + } + return (-1); +} + +static int +_ar_read_header(struct archive_read *a, struct archive_entry *entry, + struct ar *ar, const char *h, size_t *unconsumed) +{ + char filename[AR_name_size + 1]; + uint64_t number; /* Used to hold parsed numbers before validation. */ + size_t bsd_name_length, entry_size; + char *p, *st; + const void *b; + int r; + + /* Verify the magic signature on the file header. */ + if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) { + archive_set_error(&a->archive, EINVAL, + "Incorrect file header signature"); + return (ARCHIVE_WARN); + } + + /* Copy filename into work buffer. */ + strncpy(filename, h + AR_name_offset, AR_name_size); + filename[AR_name_size] = '\0'; + + /* + * Guess the format variant based on the filename. + */ + if (a->archive.archive_format == ARCHIVE_FORMAT_AR) { + /* We don't already know the variant, so let's guess. */ + /* + * Biggest clue is presence of '/': GNU starts special + * filenames with '/', appends '/' as terminator to + * non-special names, so anything with '/' should be + * GNU except for BSD long filenames. + */ + if (strncmp(filename, "#1/", 3) == 0) + a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; + else if (strchr(filename, '/') != NULL) + a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; + else if (strncmp(filename, "__.SYMDEF", 9) == 0) + a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; + /* + * XXX Do GNU/SVR4 'ar' programs ever omit trailing '/' + * if name exactly fills 16-byte field? If so, we + * can't assume entries without '/' are BSD. XXX + */ + } + + /* Update format name from the code. */ + if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) + a->archive.archive_format_name = "ar (GNU/SVR4)"; + else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) + a->archive.archive_format_name = "ar (BSD)"; + else + a->archive.archive_format_name = "ar"; + + /* + * Remove trailing spaces from the filename. GNU and BSD + * variants both pad filename area out with spaces. + * This will only be wrong if GNU/SVR4 'ar' implementations + * omit trailing '/' for 16-char filenames and we have + * a 16-char filename that ends in ' '. + */ + p = filename + AR_name_size - 1; + while (p >= filename && *p == ' ') { + *p = '\0'; + p--; + } + + /* + * Remove trailing slash unless first character is '/'. + * (BSD entries never end in '/', so this will only trim + * GNU-format entries. GNU special entries start with '/' + * and are not terminated in '/', so we don't trim anything + * that starts with '/'.) + */ + if (filename[0] != '/' && *p == '/') + *p = '\0'; + + /* + * '//' is the GNU filename table. + * Later entries can refer to names in this table. + */ + if (strcmp(filename, "//") == 0) { + /* This must come before any call to _read_ahead. */ + ar_parse_common_header(ar, entry, h); + archive_entry_copy_pathname(entry, filename); + archive_entry_set_filetype(entry, AE_IFREG); + /* Get the size of the filename table. */ + number = ar_atol10(h + AR_size_offset, AR_size_size); + if (number > SIZE_MAX) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Filename table too large"); + return (ARCHIVE_FATAL); + } + entry_size = (size_t)number; + if (entry_size == 0) { + archive_set_error(&a->archive, EINVAL, + "Invalid string table"); + return (ARCHIVE_WARN); + } + if (ar->strtab != NULL) { + archive_set_error(&a->archive, EINVAL, + "More than one string tables exist"); + return (ARCHIVE_WARN); + } + + /* Read the filename table into memory. */ + st = malloc(entry_size); + if (st == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate filename table buffer"); + return (ARCHIVE_FATAL); + } + ar->strtab = st; + ar->strtab_size = entry_size; + + if (*unconsumed) { + __archive_read_consume(a, *unconsumed); + *unconsumed = 0; + } + + if ((b = __archive_read_ahead(a, entry_size, NULL)) == NULL) + return (ARCHIVE_FATAL); + memcpy(st, b, entry_size); + __archive_read_consume(a, entry_size); + /* All contents are consumed. */ + ar->entry_bytes_remaining = 0; + archive_entry_set_size(entry, ar->entry_bytes_remaining); + + /* Parse the filename table. */ + return (ar_parse_gnu_filename_table(a)); + } + + /* + * GNU variant handles long filenames by storing / + * to indicate a name stored in the filename table. + * XXX TODO: Verify that it's all digits... Don't be fooled + * by "/9xyz" XXX + */ + if (filename[0] == '/' && filename[1] >= '0' && filename[1] <= '9') { + number = ar_atol10(h + AR_name_offset + 1, AR_name_size - 1); + /* + * If we can't look up the real name, warn and return + * the entry with the wrong name. + */ + if (ar->strtab == NULL || number > ar->strtab_size) { + archive_set_error(&a->archive, EINVAL, + "Can't find long filename for entry"); + archive_entry_copy_pathname(entry, filename); + /* Parse the time, owner, mode, size fields. */ + ar_parse_common_header(ar, entry, h); + return (ARCHIVE_WARN); + } + + archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]); + /* Parse the time, owner, mode, size fields. */ + return (ar_parse_common_header(ar, entry, h)); + } + + /* + * BSD handles long filenames by storing "#1/" followed by the + * length of filename as a decimal number, then prepends the + * the filename to the file contents. + */ + if (strncmp(filename, "#1/", 3) == 0) { + /* Parse the time, owner, mode, size fields. */ + /* This must occur before _read_ahead is called again. */ + ar_parse_common_header(ar, entry, h); + + /* Parse the size of the name, adjust the file size. */ + number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3); + bsd_name_length = (size_t)number; + /* Guard against the filename + trailing NUL + * overflowing a size_t and against the filename size + * being larger than the entire entry. */ + if (number > (uint64_t)(bsd_name_length + 1) + || (int64_t)bsd_name_length > ar->entry_bytes_remaining) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Bad input file size"); + return (ARCHIVE_FATAL); + } + ar->entry_bytes_remaining -= bsd_name_length; + /* Adjust file size reported to client. */ + archive_entry_set_size(entry, ar->entry_bytes_remaining); + + if (*unconsumed) { + __archive_read_consume(a, *unconsumed); + *unconsumed = 0; + } + + /* Read the long name into memory. */ + if ((b = __archive_read_ahead(a, bsd_name_length, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated input file"); + return (ARCHIVE_FATAL); + } + /* Store it in the entry. */ + p = (char *)malloc(bsd_name_length + 1); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate fname buffer"); + return (ARCHIVE_FATAL); + } + strncpy(p, b, bsd_name_length); + p[bsd_name_length] = '\0'; + + __archive_read_consume(a, bsd_name_length); + + archive_entry_copy_pathname(entry, p); + free(p); + return (ARCHIVE_OK); + } + + /* + * "/" is the SVR4/GNU archive symbol table. + */ + if (strcmp(filename, "/") == 0) { + archive_entry_copy_pathname(entry, "/"); + /* Parse the time, owner, mode, size fields. */ + r = ar_parse_common_header(ar, entry, h); + /* Force the file type to a regular file. */ + archive_entry_set_filetype(entry, AE_IFREG); + return (r); + } + + /* + * "__.SYMDEF" is a BSD archive symbol table. + */ + if (strcmp(filename, "__.SYMDEF") == 0) { + archive_entry_copy_pathname(entry, filename); + /* Parse the time, owner, mode, size fields. */ + return (ar_parse_common_header(ar, entry, h)); + } + + /* + * Otherwise, this is a standard entry. The filename + * has already been trimmed as much as possible, based + * on our current knowledge of the format. + */ + archive_entry_copy_pathname(entry, filename); + return (ar_parse_common_header(ar, entry, h)); } static int archive_read_format_ar_read_header(struct archive_read *a, struct archive_entry *entry) { - char filename[AR_name_size + 1]; - struct ar *ar; - uint64_t number; /* Used to hold parsed numbers before validation. */ - ssize_t bytes_read; - size_t bsd_name_length, entry_size; - char *p, *st; - const void *b; - const char *h; - int r; - - ar = (struct ar*)(a->format->data); - - if (a->archive.file_position == 0) { - /* - * We are now at the beginning of the archive, - * so we need first consume the ar global header. - */ - __archive_read_consume(a, 8); - /* Set a default format code for now. */ - a->archive.archive_format = ARCHIVE_FORMAT_AR; - } - - /* Read the header for the next file entry. */ - if ((b = __archive_read_ahead(a, 60, &bytes_read)) == NULL) - /* Broken header. */ - return (ARCHIVE_EOF); - __archive_read_consume(a, 60); - h = (const char *)b; - - /* Verify the magic signature on the file header. */ - if (strncmp(h + AR_fmag_offset, "`\n", 2) != 0) { - archive_set_error(&a->archive, EINVAL, - "Incorrect file header signature"); - return (ARCHIVE_WARN); - } - - /* Copy filename into work buffer. */ - strncpy(filename, h + AR_name_offset, AR_name_size); - filename[AR_name_size] = '\0'; - - /* - * Guess the format variant based on the filename. - */ - if (a->archive.archive_format == ARCHIVE_FORMAT_AR) { - /* We don't already know the variant, so let's guess. */ - /* - * Biggest clue is presence of '/': GNU starts special - * filenames with '/', appends '/' as terminator to - * non-special names, so anything with '/' should be - * GNU except for BSD long filenames. - */ - if (strncmp(filename, "#1/", 3) == 0) - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - else if (strchr(filename, '/') != NULL) - a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; - else if (strncmp(filename, "__.SYMDEF", 9) == 0) - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - /* - * XXX Do GNU/SVR4 'ar' programs ever omit trailing '/' - * if name exactly fills 16-byte field? If so, we - * can't assume entries without '/' are BSD. XXX - */ - } - - /* Update format name from the code. */ - if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) - a->archive.archive_format_name = "ar (GNU/SVR4)"; - else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) - a->archive.archive_format_name = "ar (BSD)"; - else - a->archive.archive_format_name = "ar"; - - /* - * Remove trailing spaces from the filename. GNU and BSD - * variants both pad filename area out with spaces. - * This will only be wrong if GNU/SVR4 'ar' implementations - * omit trailing '/' for 16-char filenames and we have - * a 16-char filename that ends in ' '. - */ - p = filename + AR_name_size - 1; - while (p >= filename && *p == ' ') { - *p = '\0'; - p--; - } - - /* - * Remove trailing slash unless first character is '/'. - * (BSD entries never end in '/', so this will only trim - * GNU-format entries. GNU special entries start with '/' - * and are not terminated in '/', so we don't trim anything - * that starts with '/'.) - */ - if (filename[0] != '/' && *p == '/') - *p = '\0'; - - /* - * '//' is the GNU filename table. - * Later entries can refer to names in this table. - */ - if (strcmp(filename, "//") == 0) { - /* This must come before any call to _read_ahead. */ - ar_parse_common_header(ar, entry, h); - archive_entry_copy_pathname(entry, filename); - archive_entry_set_filetype(entry, AE_IFREG); - /* Get the size of the filename table. */ - number = ar_atol10(h + AR_size_offset, AR_size_size); - if (number > SIZE_MAX) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Filename table too large"); - return (ARCHIVE_FATAL); - } - entry_size = (size_t)number; - if (entry_size == 0) { - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - return (ARCHIVE_WARN); - } - if (ar->strtab != NULL) { - archive_set_error(&a->archive, EINVAL, - "More than one string tables exist"); - return (ARCHIVE_WARN); - } - - /* Read the filename table into memory. */ - st = malloc(entry_size); - if (st == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate filename table buffer"); - return (ARCHIVE_FATAL); - } - ar->strtab = st; - ar->strtab_size = entry_size; - if ((b = __archive_read_ahead(a, entry_size, NULL)) == NULL) - return (ARCHIVE_FATAL); - memcpy(st, b, entry_size); - __archive_read_consume(a, entry_size); - /* All contents are consumed. */ - ar->entry_bytes_remaining = 0; - archive_entry_set_size(entry, ar->entry_bytes_remaining); - - /* Parse the filename table. */ - return (ar_parse_gnu_filename_table(a)); - } - - /* - * GNU variant handles long filenames by storing / - * to indicate a name stored in the filename table. - * XXX TODO: Verify that it's all digits... Don't be fooled - * by "/9xyz" XXX - */ - if (filename[0] == '/' && filename[1] >= '0' && filename[1] <= '9') { - number = ar_atol10(h + AR_name_offset + 1, AR_name_size - 1); - /* - * If we can't look up the real name, warn and return - * the entry with the wrong name. - */ - if (ar->strtab == NULL || number > ar->strtab_size) { - archive_set_error(&a->archive, EINVAL, - "Can't find long filename for entry"); - archive_entry_copy_pathname(entry, filename); - /* Parse the time, owner, mode, size fields. */ - ar_parse_common_header(ar, entry, h); - return (ARCHIVE_WARN); - } - - archive_entry_copy_pathname(entry, &ar->strtab[(size_t)number]); - /* Parse the time, owner, mode, size fields. */ - return (ar_parse_common_header(ar, entry, h)); - } - - /* - * BSD handles long filenames by storing "#1/" followed by the - * length of filename as a decimal number, then prepends the - * the filename to the file contents. - */ - if (strncmp(filename, "#1/", 3) == 0) { - /* Parse the time, owner, mode, size fields. */ - /* This must occur before _read_ahead is called again. */ - ar_parse_common_header(ar, entry, h); - - /* Parse the size of the name, adjust the file size. */ - number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3); - bsd_name_length = (size_t)number; - /* Guard against the filename + trailing NUL - * overflowing a size_t and against the filename size - * being larger than the entire entry. */ - if (number > (uint64_t)(bsd_name_length + 1) - || (off_t)bsd_name_length > ar->entry_bytes_remaining) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Bad input file size"); - return (ARCHIVE_FATAL); - } - ar->entry_bytes_remaining -= bsd_name_length; - /* Adjust file size reported to client. */ - archive_entry_set_size(entry, ar->entry_bytes_remaining); - - /* Read the long name into memory. */ - if ((b = __archive_read_ahead(a, bsd_name_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated input file"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, bsd_name_length); - - /* Store it in the entry. */ - p = (char *)malloc(bsd_name_length + 1); - if (p == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate fname buffer"); - return (ARCHIVE_FATAL); - } - strncpy(p, b, bsd_name_length); - p[bsd_name_length] = '\0'; - archive_entry_copy_pathname(entry, p); - free(p); - return (ARCHIVE_OK); - } - - /* - * "/" is the SVR4/GNU archive symbol table. - */ - if (strcmp(filename, "/") == 0) { - archive_entry_copy_pathname(entry, "/"); - /* Parse the time, owner, mode, size fields. */ - r = ar_parse_common_header(ar, entry, h); - /* Force the file type to a regular file. */ - archive_entry_set_filetype(entry, AE_IFREG); - return (r); - } - - /* - * "__.SYMDEF" is a BSD archive symbol table. - */ - if (strcmp(filename, "__.SYMDEF") == 0) { - archive_entry_copy_pathname(entry, filename); - /* Parse the time, owner, mode, size fields. */ - return (ar_parse_common_header(ar, entry, h)); - } - - /* - * Otherwise, this is a standard entry. The filename - * has already been trimmed as much as possible, based - * on our current knowledge of the format. - */ - archive_entry_copy_pathname(entry, filename); - return (ar_parse_common_header(ar, entry, h)); + struct ar *ar = (struct ar*)(a->format->data); + size_t unconsumed; + const void *header_data; + int ret; + + if (!ar->read_global_header) { + /* + * We are now at the beginning of the archive, + * so we need first consume the ar global header. + */ + __archive_read_consume(a, 8); + ar->read_global_header = 1; + /* Set a default format code for now. */ + a->archive.archive_format = ARCHIVE_FORMAT_AR; + } + + /* Read the header for the next file entry. */ + if ((header_data = __archive_read_ahead(a, 60, NULL)) == NULL) + /* Broken header. */ + return (ARCHIVE_EOF); + + unconsumed = 60; + + ret = _ar_read_header(a, entry, ar, (const char *)header_data, &unconsumed); + + if (unconsumed) + __archive_read_consume(a, unconsumed); + + return ret; } + static int ar_parse_common_header(struct ar *ar, struct archive_entry *entry, const char *h) { - uint64_t n; - - /* Copy remaining header */ - archive_entry_set_mtime(entry, - (time_t)ar_atol10(h + AR_date_offset, AR_date_size), 0L); - archive_entry_set_uid(entry, - (uid_t)ar_atol10(h + AR_uid_offset, AR_uid_size)); - archive_entry_set_gid(entry, - (gid_t)ar_atol10(h + AR_gid_offset, AR_gid_size)); - archive_entry_set_mode(entry, - (mode_t)ar_atol8(h + AR_mode_offset, AR_mode_size)); - n = ar_atol10(h + AR_size_offset, AR_size_size); - - ar->entry_offset = 0; - ar->entry_padding = n % 2; - archive_entry_set_size(entry, n); - ar->entry_bytes_remaining = n; - return (ARCHIVE_OK); + uint64_t n; + + /* Copy remaining header */ + archive_entry_set_mtime(entry, + (time_t)ar_atol10(h + AR_date_offset, AR_date_size), 0L); + archive_entry_set_uid(entry, + (uid_t)ar_atol10(h + AR_uid_offset, AR_uid_size)); + archive_entry_set_gid(entry, + (gid_t)ar_atol10(h + AR_gid_offset, AR_gid_size)); + archive_entry_set_mode(entry, + (mode_t)ar_atol8(h + AR_mode_offset, AR_mode_size)); + n = ar_atol10(h + AR_size_offset, AR_size_size); + + ar->entry_offset = 0; + ar->entry_padding = n % 2; + archive_entry_set_size(entry, n); + ar->entry_bytes_remaining = n; + return (ARCHIVE_OK); } static int archive_read_format_ar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - ssize_t bytes_read; - struct ar *ar; - - ar = (struct ar *)(a->format->data); - - if (ar->entry_bytes_remaining > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated ar archive"); - return (ARCHIVE_FATAL); - } - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (bytes_read > ar->entry_bytes_remaining) - bytes_read = (ssize_t)ar->entry_bytes_remaining; - *size = bytes_read; - *offset = ar->entry_offset; - ar->entry_offset += bytes_read; - ar->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, (size_t)bytes_read); - return (ARCHIVE_OK); - } else { - while (ar->entry_padding > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > ar->entry_padding) - bytes_read = (ssize_t)ar->entry_padding; - __archive_read_consume(a, (size_t)bytes_read); - ar->entry_padding -= bytes_read; - } - *buff = NULL; - *size = 0; - *offset = ar->entry_offset; - return (ARCHIVE_EOF); - } + ssize_t bytes_read; + struct ar *ar; + + ar = (struct ar *)(a->format->data); + + if (ar->entry_bytes_unconsumed) { + __archive_read_consume(a, ar->entry_bytes_unconsumed); + ar->entry_bytes_unconsumed = 0; + } + + if (ar->entry_bytes_remaining > 0) { + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated ar archive"); + return (ARCHIVE_FATAL); + } + if (bytes_read < 0) + return (ARCHIVE_FATAL); + if (bytes_read > ar->entry_bytes_remaining) + bytes_read = (ssize_t)ar->entry_bytes_remaining; + *size = bytes_read; + ar->entry_bytes_unconsumed = bytes_read; + *offset = ar->entry_offset; + ar->entry_offset += bytes_read; + ar->entry_bytes_remaining -= bytes_read; + return (ARCHIVE_OK); + } else { + int64_t skipped = __archive_read_consume(a, ar->entry_padding); + if (skipped >= 0) { + ar->entry_padding -= skipped; + } + if (ar->entry_padding) { + if (skipped >= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated ar archive- failed consuming padding"); + } + return (ARCHIVE_FATAL); + } + *buff = NULL; + *size = 0; + *offset = ar->entry_offset; + return (ARCHIVE_EOF); + } } static int archive_read_format_ar_skip(struct archive_read *a) { - off_t bytes_skipped; - struct ar* ar; + int64_t bytes_skipped; + struct ar* ar; - ar = (struct ar *)(a->format->data); + ar = (struct ar *)(a->format->data); - bytes_skipped = __archive_read_skip(a, - ar->entry_bytes_remaining + ar->entry_padding); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); + bytes_skipped = __archive_read_consume(a, + ar->entry_bytes_remaining + ar->entry_padding + + ar->entry_bytes_unconsumed); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); - ar->entry_bytes_remaining = 0; - ar->entry_padding = 0; + ar->entry_bytes_remaining = 0; + ar->entry_bytes_unconsumed = 0; + ar->entry_padding = 0; - return (ARCHIVE_OK); + return (ARCHIVE_OK); } static int ar_parse_gnu_filename_table(struct archive_read *a) { - struct ar *ar; - char *p; - size_t size; - - ar = (struct ar*)(a->format->data); - size = ar->strtab_size; - - for (p = ar->strtab; p < ar->strtab + size - 1; ++p) { - if (*p == '/') { - *p++ = '\0'; - if (*p != '\n') - goto bad_string_table; - *p = '\0'; - } - } - /* - * GNU ar always pads the table to an even size. - * The pad character is either '\n' or '`'. - */ - if (p != ar->strtab + size && *p != '\n' && *p != '`') - goto bad_string_table; - - /* Enforce zero termination. */ - ar->strtab[size - 1] = '\0'; - - return (ARCHIVE_OK); + struct ar *ar; + char *p; + size_t size; + + ar = (struct ar*)(a->format->data); + size = ar->strtab_size; + + for (p = ar->strtab; p < ar->strtab + size - 1; ++p) { + if (*p == '/') { + *p++ = '\0'; + if (*p != '\n') + goto bad_string_table; + *p = '\0'; + } + } + /* + * GNU ar always pads the table to an even size. + * The pad character is either '\n' or '`'. + */ + if (p != ar->strtab + size && *p != '\n' && *p != '`') + goto bad_string_table; + + /* Enforce zero termination. */ + ar->strtab[size - 1] = '\0'; + + return (ARCHIVE_OK); bad_string_table: - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - free(ar->strtab); - ar->strtab = NULL; - return (ARCHIVE_WARN); + archive_set_error(&a->archive, EINVAL, + "Invalid string table"); + free(ar->strtab); + ar->strtab = NULL; + return (ARCHIVE_WARN); } static uint64_t ar_atol8(const char *p, unsigned char_cnt) { - uint64_t l, limit, last_digit_limit; - unsigned int digit, base; - - base = 8; - limit = UINT64_MAX / base; - last_digit_limit = UINT64_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = UINT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); + uint64_t l, limit, last_digit_limit; + unsigned int digit, base; + + base = 8; + limit = UINT64_MAX / base; + last_digit_limit = UINT64_MAX % base; + + while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) + p++; + + l = 0; + digit = *p - '0'; + while (*p >= '0' && digit < base && char_cnt-- > 0) { + if (l>limit || (l == limit && digit > last_digit_limit)) { + l = UINT64_MAX; /* Truncate on overflow. */ + break; + } + l = (l * base) + digit; + digit = *++p - '0'; + } + return (l); } static uint64_t ar_atol10(const char *p, unsigned char_cnt) { - uint64_t l, limit, last_digit_limit; - unsigned int base, digit; - - base = 10; - limit = UINT64_MAX / base; - last_digit_limit = UINT64_MAX % base; - - while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) - p++; - l = 0; - digit = *p - '0'; - while (*p >= '0' && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = UINT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (l); + uint64_t l, limit, last_digit_limit; + unsigned int base, digit; + + base = 10; + limit = UINT64_MAX / base; + last_digit_limit = UINT64_MAX % base; + + while ((*p == ' ' || *p == '\t') && char_cnt-- > 0) + p++; + l = 0; + digit = *p - '0'; + while (*p >= '0' && digit < base && char_cnt-- > 0) { + if (l > limit || (l == limit && digit > last_digit_limit)) { + l = UINT64_MAX; /* Truncate on overflow. */ + break; + } + l = (l * base) + digit; + digit = *++p - '0'; + } + return (l); } diff --git a/Utilities/cmlibarchive/cpio/test/test_option_C_upper.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c similarity index 50% rename from Utilities/cmlibarchive/cpio/test/test_option_C_upper.c rename to Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c index afc319f4f..084563f43 100644 --- a/Utilities/cmlibarchive/cpio/test/test_option_C_upper.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_by_code.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,41 +22,53 @@ * (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 "test.h" + +#include "archive_platform.h" __FBSDID("$FreeBSD$"); +#include "archive.h" +#include "archive_private.h" -DEFINE_TEST(test_option_C_upper) +int +archive_read_support_format_by_code(struct archive *a, int format_code) { - int r; - - /* - * Create a file on disk. - */ - assertMakeFile("file", 0644, NULL); - - /* Create an archive without -C; this should be 512 bytes. */ - r = systemf("echo file | %s -o > small.cpio 2>small.err", testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "small.err"); - assertFileSize("small.cpio", 512); - - /* Create an archive with -C 513; this should be 513 bytes. */ - r = systemf("echo file | %s -o -C 513 > 513.cpio 2>513.err", - testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "513.err"); - assertFileSize("513.cpio", 513); - - /* Create an archive with -C 12345; this should be 12345 bytes. */ - r = systemf("echo file | %s -o -C12345 > 12345.cpio 2>12345.err", - testprog); - assertEqualInt(r, 0); - assertTextFileContents("1 block\n", "12345.err"); - assertFileSize("12345.cpio", 12345); + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_by_code"); - /* Create an archive with invalid -C request */ - assert(0 != systemf("echo file | %s -o -C > bad.cpio 2>bad.err", - testprog)); - assertEmptyFile("bad.cpio"); + switch (format_code & ARCHIVE_FORMAT_BASE_MASK) { + case ARCHIVE_FORMAT_7ZIP: + return archive_read_support_format_7zip(a); + break; + case ARCHIVE_FORMAT_AR: + return archive_read_support_format_ar(a); + break; + case ARCHIVE_FORMAT_CAB: + return archive_read_support_format_cab(a); + break; + case ARCHIVE_FORMAT_CPIO: + return archive_read_support_format_cpio(a); + break; + case ARCHIVE_FORMAT_ISO9660: + return archive_read_support_format_iso9660(a); + break; + case ARCHIVE_FORMAT_LHA: + return archive_read_support_format_lha(a); + break; + case ARCHIVE_FORMAT_MTREE: + return archive_read_support_format_mtree(a); + break; + case ARCHIVE_FORMAT_RAR: + return archive_read_support_format_rar(a); + break; + case ARCHIVE_FORMAT_TAR: + return archive_read_support_format_tar(a); + break; + case ARCHIVE_FORMAT_XAR: + return archive_read_support_format_xar(a); + break; + case ARCHIVE_FORMAT_ZIP: + return archive_read_support_format_zip(a); + break; + } + 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 new file mode 100644 index 000000000..e65010e10 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cab.c @@ -0,0 +1,3315 @@ +/*- + * Copyright (c) 2010-2011 Michihiro NAKAJIMA + * 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" + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_endian.h" + + +struct lzx_dec { + /* Decoding status. */ + int state; + + /* + * Window to see last decoded data, from 32KBi to 2MBi. + */ + int w_size; + int w_mask; + /* Window buffer, which is a loop buffer. */ + unsigned char *w_buff; + /* The insert position to the window. */ + int w_pos; + /* The position where we can copy decoded code from the window. */ + int copy_pos; + /* The length how many bytes we can copy decoded code from + * the window. */ + int copy_len; + /* Translation reversal for x86 proccessor CALL byte sequence(E8). + * This is used for LZX only. */ + uint32_t translation_size; + char translation; + char block_type; +#define VERBATIM_BLOCK 1 +#define ALIGNED_OFFSET_BLOCK 2 +#define UNCOMPRESSED_BLOCK 3 + size_t block_size; + size_t block_bytes_avail; + /* Repeated offset. */ + int r0, r1, r2; + unsigned char rbytes[4]; + int rbytes_avail; + int length_header; + int position_slot; + int offset_bits; + + struct lzx_pos_tbl { + int base; + int footer_bits; + } *pos_tbl; + /* + * Bit stream reader. + */ + struct lzx_br { +#define CACHE_TYPE uint64_t +#define CACHE_BITS (8 * sizeof(CACHE_TYPE)) + /* Cache buffer. */ + CACHE_TYPE cache_buffer; + /* Indicates how many bits avail in cache_buffer. */ + int cache_avail; + unsigned char odd; + char have_odd; + } br; + + /* + * Huffman coding. + */ + struct huffman { + int len_size; + int freq[17]; + unsigned char *bitlen; + + /* + * Use a index table. It's faster than searching a huffman + * coding tree, which is a binary tree. But a use of a large + * index table causes L1 cache read miss many times. + */ +#define HTBL_BITS 10 + int max_bits; + int shift_bits; + int tbl_bits; + int tree_used; + int tree_avail; + /* Direct access table. */ + uint16_t *tbl; + /* Binary tree table for extra bits over the direct access. */ + struct htree_t { + uint16_t left; + uint16_t right; + } *tree; + } at, lt, mt, pt; + + int loop; + int error; +}; + +static const int slots[] = { + 30, 32, 34, 36, 38, 42, 50, 66, 98, 162, 290 +}; +#define SLOT_BASE 15 +#define SLOT_MAX 21/*->25*/ + +struct lzx_stream { + const unsigned char *next_in; + int64_t avail_in; + int64_t total_in; + unsigned char *next_out; + int64_t avail_out; + int64_t total_out; + struct lzx_dec *ds; +}; + +/* + * Cabinet file definitions. + */ +/* CFHEADER offset */ +#define CFHEADER_signature 0 +#define CFHEADER_cbCabinet 8 +#define CFHEADER_coffFiles 16 +#define CFHEADER_versionMinor 24 +#define CFHEADER_versionMajor 25 +#define CFHEADER_cFolders 26 +#define CFHEADER_cFiles 28 +#define CFHEADER_flags 30 +#define CFHEADER_setID 32 +#define CFHEADER_iCabinet 34 +#define CFHEADER_cbCFHeader 36 +#define CFHEADER_cbCFFolder 38 +#define CFHEADER_cbCFData 39 + +/* CFFOLDER offset */ +#define CFFOLDER_coffCabStart 0 +#define CFFOLDER_cCFData 4 +#define CFFOLDER_typeCompress 6 +#define CFFOLDER_abReserve 8 + +/* CFFILE offset */ +#define CFFILE_cbFile 0 +#define CFFILE_uoffFolderStart 4 +#define CFFILE_iFolder 8 +#define CFFILE_date_time 10 +#define CFFILE_attribs 14 + +/* CFDATA offset */ +#define CFDATA_csum 0 +#define CFDATA_cbData 4 +#define CFDATA_cbUncomp 6 + +static const char *compression_name[] = { + "NONE", + "MSZIP", + "Quantum", + "LZX", +}; + +struct cfdata { + /* Sum value of this CFDATA. */ + uint32_t sum; + uint16_t compressed_size; + uint16_t compressed_bytes_remaining; + uint16_t uncompressed_size; + uint16_t uncompressed_bytes_remaining; + /* To know how many bytes we have decompressed. */ + uint16_t uncompressed_avail; + /* Offset from the beginning of compressed data of this CFDATA */ + uint16_t read_offset; + int64_t unconsumed; + /* To keep memory image of this CFDATA to compute the sum. */ + size_t memimage_size; + unsigned char *memimage; + /* Result of calculation of sum. */ + uint32_t sum_calculated; + unsigned char sum_extra[4]; + int sum_extra_avail; + const void *sum_ptr; +}; + +struct cffolder { + uint32_t cfdata_offset_in_cab; + uint16_t cfdata_count; + uint16_t comptype; +#define COMPTYPE_NONE 0x0000 +#define COMPTYPE_MSZIP 0x0001 +#define COMPTYPE_QUANTUM 0x0002 +#define COMPTYPE_LZX 0x0003 + uint16_t compdata; + const char *compname; + /* At the time reading CFDATA */ + struct cfdata cfdata; + int cfdata_index; + /* Flags to mark progress of decompression. */ + char decompress_init; +}; + +struct cffile { + uint32_t uncompressed_size; + uint32_t offset; + time_t mtime; + uint16_t folder; +#define iFoldCONTINUED_FROM_PREV 0xFFFD +#define iFoldCONTINUED_TO_NEXT 0xFFFE +#define iFoldCONTINUED_PREV_AND_NEXT 0xFFFF + unsigned char attr; +#define ATTR_RDONLY 0x01 +#define ATTR_NAME_IS_UTF 0x80 + struct archive_string pathname; +}; + +struct cfheader { + /* Total bytes of all file size in a Cabinet. */ + uint32_t total_bytes; + uint32_t files_offset; + uint16_t folder_count; + uint16_t file_count; + uint16_t flags; +#define PREV_CABINET 0x0001 +#define NEXT_CABINET 0x0002 +#define RESERVE_PRESENT 0x0004 + uint16_t setid; + uint16_t cabinet; + /* Version number. */ + unsigned char major; + unsigned char minor; + unsigned char cffolder; + unsigned char cfdata; + /* All folders in a cabinet. */ + struct cffolder *folder_array; + /* All files in a cabinet. */ + struct cffile *file_array; + int file_index; +}; + +struct cab { + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_offset; + int64_t entry_bytes_remaining; + int64_t entry_unconsumed; + int64_t entry_compressed_bytes_read; + int64_t entry_uncompressed_bytes_read; + struct cffolder *entry_cffolder; + struct cffile *entry_cffile; + struct cfdata *entry_cfdata; + + /* Offset from beginning of a cabinet file. */ + int64_t cab_offset; + struct cfheader cfheader; + struct archive_wstring ws; + + /* Flag to mark progress that an archive was read their first header.*/ + char found_header; + char end_of_archive; + char end_of_entry; + char end_of_entry_cleanup; + + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; + + int init_default_conversion; + struct archive_string_conv *sconv; + struct archive_string_conv *sconv_default; + struct archive_string_conv *sconv_utf8; + char format_name[64]; + +#ifdef HAVE_ZLIB_H + z_stream stream; + char stream_valid; +#endif + struct lzx_stream xstrm; +}; + +static int archive_read_format_cab_bid(struct archive_read *, int); +static int archive_read_format_cab_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_cab_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_cab_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_cab_read_data_skip(struct archive_read *); +static int archive_read_format_cab_cleanup(struct archive_read *); + +static int cab_skip_sfx(struct archive_read *); +static time_t cab_dos_time(const unsigned char *); +static int cab_read_data(struct archive_read *, const void **, + size_t *, int64_t *); +static int cab_read_header(struct archive_read *); +static uint32_t cab_checksum_cfdata_4(const void *, size_t bytes, uint32_t); +static uint32_t cab_checksum_cfdata(const void *, size_t bytes, uint32_t); +static void cab_checksum_update(struct archive_read *, size_t); +static int cab_checksum_finish(struct archive_read *); +static int cab_next_cfdata(struct archive_read *); +static const void *cab_read_ahead_cfdata(struct archive_read *, ssize_t *); +static const void *cab_read_ahead_cfdata_none(struct archive_read *, ssize_t *); +static const void *cab_read_ahead_cfdata_deflate(struct archive_read *, + ssize_t *); +static const void *cab_read_ahead_cfdata_lzx(struct archive_read *, + ssize_t *); +static int64_t cab_consume_cfdata(struct archive_read *, int64_t); +static int64_t cab_minimum_consume_cfdata(struct archive_read *, int64_t); +static int lzx_decode_init(struct lzx_stream *, int); +static int lzx_read_blocks(struct lzx_stream *, int); +static int lzx_decode_blocks(struct lzx_stream *, int); +static void lzx_decode_free(struct lzx_stream *); +static void lzx_translation(struct lzx_stream *, void *, size_t, uint32_t); +static void lzx_cleanup_bitstream(struct lzx_stream *); +static int lzx_decode(struct lzx_stream *, int); +static int lzx_read_pre_tree(struct lzx_stream *); +static int lzx_read_bitlen(struct lzx_stream *, struct huffman *, int); +static int lzx_huffman_init(struct huffman *, size_t, int); +static void lzx_huffman_free(struct huffman *); +static int lzx_make_huffman_table(struct huffman *); +static int inline lzx_decode_huffman(struct huffman *, unsigned); +static int lzx_decode_huffman_tree(struct huffman *, unsigned, int); + + +int +archive_read_support_format_cab(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct cab *cab; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_cab"); + + cab = (struct cab *)calloc(1, sizeof(*cab)); + if (cab == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate CAB data"); + return (ARCHIVE_FATAL); + } + archive_string_init(&cab->ws); + archive_wstring_ensure(&cab->ws, 256); + + r = __archive_read_register_format(a, + cab, + "cab", + archive_read_format_cab_bid, + archive_read_format_cab_options, + archive_read_format_cab_read_header, + archive_read_format_cab_read_data, + archive_read_format_cab_read_data_skip, + archive_read_format_cab_cleanup); + + if (r != ARCHIVE_OK) + free(cab); + return (ARCHIVE_OK); +} + +static int +find_cab_magic(const char *p) +{ + switch (p[4]) { + case 0: + /* + * Note: Self-Extraction program has 'MSCF' string in their + * program. If we were finding 'MSCF' string only, we got + * wrong place for Cabinet header, thus, we have to check + * following four bytes which are reserved and must be set + * to zero. + */ + if (memcmp(p, "MSCF\0\0\0\0", 8) == 0) + return 0; + return 5; + case 'F': return 1; + case 'C': return 2; + case 'S': return 3; + case 'M': return 4; + default: return 5; + } +} + +static int +archive_read_format_cab_bid(struct archive_read *a, int best_bid) +{ + const char *p; + ssize_t bytes_avail, offset, window; + + /* If there's already a better bid than we can ever + make, don't bother testing. */ + if (best_bid > 64) + return (-1); + + if ((p = __archive_read_ahead(a, 8, NULL)) == NULL) + return (-1); + + if (memcmp(p, "MSCF\0\0\0\0", 8) == 0) + return (64); + + /* + * Attempt to handle self-extracting archives + * by noting a PE header and searching forward + * up to 128k for a 'MSCF' marker. + */ + if (p[0] == 'M' && p[1] == 'Z') { + offset = 0; + window = 4096; + while (offset < (1024 * 128)) { + const char *h = __archive_read_ahead(a, offset + window, + &bytes_avail); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 128) + return (0); + continue; + } + p = h + offset; + while (p + 8 < h + bytes_avail) { + int next; + if ((next = find_cab_magic(p)) == 0) + return (64); + p += next; + } + offset = p - h; + } + } + return (0); +} + +static int +archive_read_format_cab_options(struct archive_read *a, + const char *key, const char *val) +{ + struct cab *cab; + int ret = ARCHIVE_FAILED; + + cab = (struct cab *)(a->format->data); + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "cab: hdrcharset option needs a character-set name"); + else { + cab->sconv = archive_string_conversion_from_charset( + &a->archive, val, 0); + if (cab->sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "cab: unknown keyword ``%s''", key); + + return (ret); +} + +static int +cab_skip_sfx(struct archive_read *a) +{ + const char *p, *q; + size_t skip; + ssize_t bytes, window; + + window = 4096; + for (;;) { + const char *h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining size are less than window. */ + window >>= 1; + if (window < 128) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out CAB header"); + return (ARCHIVE_FATAL); + } + continue; + } + p = h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the cab header. + */ + while (p + 8 < q) { + int next; + if ((next = find_cab_magic(p)) == 0) { + skip = p - h; + __archive_read_consume(a, skip); + return (ARCHIVE_OK); + } + p += next; + } + skip = p - h; + __archive_read_consume(a, skip); + } +} + +static int +truncated_error(struct archive_read *a) +{ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated CAB header"); + return (ARCHIVE_FATAL); +} + +static int +cab_strnlen(const unsigned 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); +} + +/* Read bytes as much as remaining. */ +static const void * +cab_read_ahead_remaining(struct archive_read *a, size_t min, ssize_t *avail) +{ + const void *p; + + while (min > 0) { + p = __archive_read_ahead(a, min, avail); + if (p != NULL) + return (p); + min--; + } + return (NULL); +} + +/* Convert a path separator '\' -> '/' */ +static int +cab_convert_path_separator_1(struct archive_string *fn, unsigned char attr) +{ + size_t i; + int mb; + + /* Easy check if we have '\' in multi-byte string. */ + mb = 0; + for (i = 0; i < archive_strlen(fn); i++) { + if (fn->s[i] == '\\') { + if (mb) { + /* This may be second byte of multi-byte + * character. */ + break; + } + fn->s[i] = '/'; + mb = 0; + } else if ((fn->s[i] & 0x80) && !(attr & ATTR_NAME_IS_UTF)) + mb = 1; + else + mb = 0; + } + if (i == archive_strlen(fn)) + return (0); + return (-1); +} + +/* + * Replace a character '\' with '/' in wide character. + */ +static void +cab_convert_path_separator_2(struct cab *cab, struct archive_entry *entry) +{ + const wchar_t *wp; + size_t i; + + /* If a conversion to wide character failed, force the replacement. */ + if ((wp = archive_entry_pathname_w(entry)) != NULL) { + archive_wstrcpy(&(cab->ws), wp); + for (i = 0; i < archive_strlen(&(cab->ws)); i++) { + if (cab->ws.s[i] == L'\\') + cab->ws.s[i] = L'/'; + } + archive_entry_copy_pathname_w(entry, cab->ws.s); + } +} + +/* + * Read CFHEADER, CFFOLDER and CFFILE. + */ +static int +cab_read_header(struct archive_read *a) +{ + const unsigned char *p; + struct cab *cab; + struct cfheader *hd; + size_t bytes, used; + int64_t skip; + int err, i, len; + int cur_folder, prev_folder; + uint32_t offset32; + + a->archive.archive_format = ARCHIVE_FORMAT_CAB; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "CAB"; + + if ((p = __archive_read_ahead(a, 42, NULL)) == NULL) + return (truncated_error(a)); + + cab = (struct cab *)(a->format->data); + if (cab->found_header == 0 && + p[0] == 'M' && p[1] == 'Z') { + /* This is an executable? Must be self-extracting... */ + err = cab_skip_sfx(a); + if (err < ARCHIVE_WARN) + return (err); + + if ((p = __archive_read_ahead(a, sizeof(*p), NULL)) == NULL) + return (truncated_error(a)); + } + + cab->cab_offset = 0; + /* + * Read CFHEADER. + */ + hd = &cab->cfheader; + if (p[CFHEADER_signature+0] != 'M' || p[CFHEADER_signature+1] != 'S' || + p[CFHEADER_signature+2] != 'C' || p[CFHEADER_signature+3] != 'F') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out CAB header"); + return (ARCHIVE_FATAL); + } + hd->total_bytes = archive_le32dec(p + CFHEADER_cbCabinet); + hd->files_offset = archive_le32dec(p + CFHEADER_coffFiles); + hd->minor = p[CFHEADER_versionMinor]; + hd->major = p[CFHEADER_versionMajor]; + hd->folder_count = archive_le16dec(p + CFHEADER_cFolders); + if (hd->folder_count == 0) + goto invalid; + hd->file_count = archive_le16dec(p + CFHEADER_cFiles); + if (hd->file_count == 0) + goto invalid; + hd->flags = archive_le16dec(p + CFHEADER_flags); + hd->setid = archive_le16dec(p + CFHEADER_setID); + hd->cabinet = archive_le16dec(p + CFHEADER_iCabinet); + used = CFHEADER_iCabinet + 2; + if (hd->flags & RESERVE_PRESENT) { + uint16_t cfheader; + cfheader = archive_le16dec(p + CFHEADER_cbCFHeader); + if (cfheader > 60000U) + goto invalid; + hd->cffolder = p[CFHEADER_cbCFFolder]; + hd->cfdata = p[CFHEADER_cbCFData]; + used += 4;/* cbCFHeader, cbCFFolder and cbCFData */ + used += cfheader;/* abReserve */ + } else + hd->cffolder = 0;/* Avoid compiling warning. */ + if (hd->flags & PREV_CABINET) { + /* How many bytes are used for szCabinetPrev. */ + if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL) + return (truncated_error(a)); + if ((len = cab_strnlen(p + used, 255)) <= 0) + goto invalid; + used += len + 1; + /* How many bytes are used for szDiskPrev. */ + if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL) + return (truncated_error(a)); + if ((len = cab_strnlen(p + used, 255)) <= 0) + goto invalid; + used += len + 1; + } + if (hd->flags & NEXT_CABINET) { + /* How many bytes are used for szCabinetNext. */ + if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL) + return (truncated_error(a)); + if ((len = cab_strnlen(p + used, 255)) <= 0) + goto invalid; + used += len + 1; + /* How many bytes are used for szDiskNext. */ + if ((p = __archive_read_ahead(a, used+256, NULL)) == NULL) + return (truncated_error(a)); + if ((len = cab_strnlen(p + used, 255)) <= 0) + goto invalid; + used += len + 1; + } + __archive_read_consume(a, used); + cab->cab_offset += used; + used = 0; + + /* + * Read CFFOLDER. + */ + hd->folder_array = (struct cffolder *)calloc( + hd->folder_count, sizeof(struct cffolder)); + if (hd->folder_array == NULL) + goto nomem; + + bytes = 8; + if (hd->flags & RESERVE_PRESENT) + bytes += hd->cffolder; + bytes *= hd->folder_count; + if ((p = __archive_read_ahead(a, bytes, NULL)) == NULL) + return (truncated_error(a)); + offset32 = 0; + for (i = 0; i < hd->folder_count; i++) { + struct cffolder *folder = &(hd->folder_array[i]); + folder->cfdata_offset_in_cab = + archive_le32dec(p + CFFOLDER_coffCabStart); + folder->cfdata_count = archive_le16dec(p+CFFOLDER_cCFData); + folder->comptype = + archive_le16dec(p+CFFOLDER_typeCompress) & 0x0F; + folder->compdata = + archive_le16dec(p+CFFOLDER_typeCompress) >> 8; + /* Get a compression name. */ + if (folder->comptype < + sizeof(compression_name) / sizeof(compression_name[0])) + folder->compname = compression_name[folder->comptype]; + else + folder->compname = "UNKNOWN"; + p += 8; + used += 8; + if (hd->flags & RESERVE_PRESENT) { + p += hd->cffolder;/* abReserve */ + used += hd->cffolder; + } + /* + * Sanity check if each data is acceptable. + */ + if (offset32 >= folder->cfdata_offset_in_cab) + goto invalid; + offset32 = folder->cfdata_offset_in_cab; + + /* Set a request to initialize zlib for the CFDATA of + * this folder. */ + folder->decompress_init = 0; + } + __archive_read_consume(a, used); + cab->cab_offset += used; + + /* + * Read CFFILE. + */ + /* Seek read pointer to the offset of CFFILE if needed. */ + skip = (int64_t)hd->files_offset - cab->cab_offset; + if (skip < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid offset of CFFILE %jd < %jd", + (intmax_t)hd->files_offset, (intmax_t)cab->cab_offset); + return (ARCHIVE_FATAL); + } + if (skip) { + __archive_read_consume(a, skip); + cab->cab_offset += skip; + } + /* Allocate memory for CFDATA */ + hd->file_array = (struct cffile *)calloc( + hd->file_count, sizeof(struct cffile)); + if (hd->file_array == NULL) + goto nomem; + + prev_folder = -1; + for (i = 0; i < hd->file_count; i++) { + struct cffile *file = &(hd->file_array[i]); + ssize_t avail; + + if ((p = __archive_read_ahead(a, 16, NULL)) == NULL) + return (truncated_error(a)); + file->uncompressed_size = archive_le32dec(p + CFFILE_cbFile); + file->offset = archive_le32dec(p + CFFILE_uoffFolderStart); + file->folder = archive_le16dec(p + CFFILE_iFolder); + file->mtime = cab_dos_time(p + CFFILE_date_time); + file->attr = archive_le16dec(p + CFFILE_attribs); + __archive_read_consume(a, 16); + + cab->cab_offset += 16; + if ((p = cab_read_ahead_remaining(a, 256, &avail)) == NULL) + return (truncated_error(a)); + if ((len = cab_strnlen(p, avail-1)) <= 0) + goto invalid; + + /* Copy a pathname. */ + archive_string_init(&(file->pathname)); + archive_strncpy(&(file->pathname), p, len); + __archive_read_consume(a, len + 1); + cab->cab_offset += len + 1; + + /* + * Sanity check if each data is acceptable. + */ + if (file->uncompressed_size > 0x7FFF8000) + goto invalid;/* Too large */ + if ((int64_t)file->offset + (int64_t)file->uncompressed_size + > ARCHIVE_LITERAL_LL(0x7FFF8000)) + goto invalid;/* Too large */ + switch (file->folder) { + case iFoldCONTINUED_TO_NEXT: + /* This must be last file in a folder. */ + if (i != hd->file_count -1) + goto invalid; + cur_folder = hd->folder_count -1; + break; + case iFoldCONTINUED_PREV_AND_NEXT: + /* This must be only one file in a folder. */ + if (hd->file_count != 1) + goto invalid; + /* FALL THROUGH */ + case iFoldCONTINUED_FROM_PREV: + /* This must be first file in a folder. */ + if (i != 0) + goto invalid; + prev_folder = cur_folder = 0; + offset32 = file->offset; + break; + default: + if (file->folder >= hd->folder_count) + goto invalid; + cur_folder = file->folder; + break; + } + /* Dot not back track. */ + if (cur_folder < prev_folder) + goto invalid; + if (cur_folder != prev_folder) + offset32 = 0; + prev_folder = cur_folder; + + /* Make sure there are not any blanks from last file + * contents. */ + if (offset32 != file->offset) + goto invalid; + offset32 += file->uncompressed_size; + + /* CFDATA is available for file contents. */ + if (file->uncompressed_size > 0 && + hd->folder_array[cur_folder].cfdata_count == 0) + goto invalid; + } + + if (hd->cabinet != 0 || hd->flags & (PREV_CABINET | NEXT_CABINET)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Multivolume cabinet file is unsupported"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid CAB header"); + return (ARCHIVE_FATAL); +nomem: + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for CAB data"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_cab_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct cab *cab; + struct cfheader *hd; + struct cffolder *prev_folder; + struct cffile *file; + struct archive_string_conv *sconv; + int err = ARCHIVE_OK, r; + + cab = (struct cab *)(a->format->data); + if (cab->found_header == 0) { + err = cab_read_header(a); + if (err < ARCHIVE_WARN) + return (err); + /* We've found the header. */ + cab->found_header = 1; + } + hd = &cab->cfheader; + + if (hd->file_index >= hd->file_count) { + cab->end_of_archive = 1; + return (ARCHIVE_EOF); + } + file = &hd->file_array[hd->file_index++]; + + cab->end_of_entry = 0; + cab->end_of_entry_cleanup = 0; + cab->entry_compressed_bytes_read = 0; + cab->entry_uncompressed_bytes_read = 0; + cab->entry_unconsumed = 0; + cab->entry_cffile = file; + + /* + * Choose a proper folder. + */ + prev_folder = cab->entry_cffolder; + switch (file->folder) { + case iFoldCONTINUED_FROM_PREV: + case iFoldCONTINUED_PREV_AND_NEXT: + cab->entry_cffolder = &hd->folder_array[0]; + break; + case iFoldCONTINUED_TO_NEXT: + cab->entry_cffolder = &hd->folder_array[hd->folder_count-1]; + break; + default: + cab->entry_cffolder = &hd->folder_array[file->folder]; + break; + } + /* If a cffolder of this file is changed, reset a cfdata to read + * file contents from next cfdata. */ + if (prev_folder != cab->entry_cffolder) + cab->entry_cfdata = NULL; + + /* If a pathname is UTF-8, prepare a string conversion object + * for UTF-8 and use it. */ + if (file->attr & ATTR_NAME_IS_UTF) { + if (cab->sconv_utf8 == NULL) { + cab->sconv_utf8 = + archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (cab->sconv_utf8 == NULL) + return (ARCHIVE_FATAL); + } + sconv = cab->sconv_utf8; + } else if (cab->sconv != NULL) { + /* Choose the conversion specified by the option. */ + sconv = cab->sconv; + } else { + /* Choose the default conversion. */ + if (!cab->init_default_conversion) { + cab->sconv_default = + archive_string_default_conversion_for_read( + &(a->archive)); + cab->init_default_conversion = 1; + } + sconv = cab->sconv_default; + } + + /* + * Set a default value and common data + */ + r = cab_convert_path_separator_1(&(file->pathname), file->attr); + if (archive_entry_copy_pathname_l(entry, file->pathname.s, + archive_strlen(&(file->pathname)), sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + err = ARCHIVE_WARN; + } + if (r < 0) { + /* Convert a path separator '\' -> '/' */ + cab_convert_path_separator_2(cab, entry); + } + + archive_entry_set_size(entry, file->uncompressed_size); + if (file->attr & ATTR_RDONLY) + archive_entry_set_mode(entry, AE_IFREG | 0555); + else + archive_entry_set_mode(entry, AE_IFREG | 0777); + archive_entry_set_mtime(entry, file->mtime, 0); + + cab->entry_bytes_remaining = file->uncompressed_size; + cab->entry_offset = 0; + /* We don't need compress data. */ + if (file->uncompressed_size == 0) + cab->end_of_entry_cleanup = cab->end_of_entry = 1; + + /* Set up a more descriptive format name. */ + sprintf(cab->format_name, "CAB %d.%d (%s)", + hd->major, hd->minor, cab->entry_cffolder->compname); + a->archive.archive_format_name = cab->format_name; + + return (err); +} + +static int +archive_read_format_cab_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct cab *cab = (struct cab *)(a->format->data); + int r; + + switch (cab->entry_cffile->folder) { + case iFoldCONTINUED_FROM_PREV: + case iFoldCONTINUED_TO_NEXT: + case iFoldCONTINUED_PREV_AND_NEXT: + *buff = NULL; + *size = 0; + *offset = 0; + archive_clear_error(&a->archive); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Cannot restore this file split in multivolume."); + return (ARCHIVE_FAILED); + default: + break; + } + if (cab->entry_unconsumed) { + /* Consume as much as the compressor actually used. */ + r = cab_consume_cfdata(a, cab->entry_unconsumed); + cab->entry_unconsumed = 0; + if (r < 0) + return (r); + } + if (cab->end_of_archive || cab->end_of_entry) { + if (!cab->end_of_entry_cleanup) { + /* End-of-entry cleanup done. */ + cab->end_of_entry_cleanup = 1; + } + *offset = cab->entry_offset; + *size = 0; + *buff = NULL; + return (ARCHIVE_EOF); + } + + return (cab_read_data(a, buff, size, offset)); +} + +static uint32_t +cab_checksum_cfdata_4(const void *p, size_t bytes, uint32_t seed) +{ + const unsigned char *b; + int u32num; + uint32_t sum; + + u32num = bytes / 4; + sum = seed; + b = p; + while (--u32num >= 0) { + sum ^= archive_le32dec(b); + b += 4; + } + return (sum); +} + +static uint32_t +cab_checksum_cfdata(const void *p, size_t bytes, uint32_t seed) +{ + const unsigned char *b; + uint32_t sum; + uint32_t t; + + sum = cab_checksum_cfdata_4(p, bytes, seed); + b = p; + b += bytes & ~3; + t = 0; + switch (bytes & 3) { + case 3: + t |= ((uint32_t)(*b++)) << 16; + /* FALL THROUGH */ + case 2: + t |= ((uint32_t)(*b++)) << 8; + /* FALL THROUGH */ + case 1: + t |= *b; + /* FALL THROUGH */ + default: + break; + } + sum ^= t; + + return (sum); +} + +static void +cab_checksum_update(struct archive_read *a, size_t bytes) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata = cab->entry_cfdata; + const unsigned char *p; + size_t sumbytes; + + if (cfdata->sum == 0 || cfdata->sum_ptr == NULL) + return; + /* + * Calculate the sum of this CFDATA. + * Make sure CFDATA must be calculated in four bytes. + */ + p = cfdata->sum_ptr; + sumbytes = bytes; + if (cfdata->sum_extra_avail) { + while (cfdata->sum_extra_avail < 4 && sumbytes > 0) { + cfdata->sum_extra[ + cfdata->sum_extra_avail++] = *p++; + sumbytes--; + } + if (cfdata->sum_extra_avail == 4) { + cfdata->sum_calculated = cab_checksum_cfdata_4( + cfdata->sum_extra, 4, cfdata->sum_calculated); + cfdata->sum_extra_avail = 0; + } + } + if (sumbytes) { + int odd = sumbytes & 3; + if (sumbytes - odd > 0) + cfdata->sum_calculated = cab_checksum_cfdata_4( + p, sumbytes - odd, cfdata->sum_calculated); + if (odd) + memcpy(cfdata->sum_extra, p + sumbytes - odd, odd); + cfdata->sum_extra_avail = odd; + } + cfdata->sum_ptr = NULL; +} + +static int +cab_checksum_finish(struct archive_read *a) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata = cab->entry_cfdata; + int l; + + /* Do not need to compute a sum. */ + if (cfdata->sum == 0) + return (ARCHIVE_OK); + + /* + * Calculate the sum of remaining CFDATA. + */ + if (cfdata->sum_extra_avail) { + cfdata->sum_calculated = + cab_checksum_cfdata(cfdata->sum_extra, + cfdata->sum_extra_avail, cfdata->sum_calculated); + cfdata->sum_extra_avail = 0; + } + + l = 4; + if (cab->cfheader.flags & RESERVE_PRESENT) + l += cab->cfheader.cfdata; + cfdata->sum_calculated = cab_checksum_cfdata( + 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", + cab->entry_cffolder->cfdata_index -1, + cfdata->sum, cfdata->sum_calculated, + cfdata->compressed_size); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); +} + +/* + * Read CFDATA if needed. + */ +static int +cab_next_cfdata(struct archive_read *a) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata = cab->entry_cfdata; + + /* There are remaining bytes in current CFDATA, use it first. */ + if (cfdata != NULL && cfdata->uncompressed_bytes_remaining > 0) + return (ARCHIVE_OK); + + if (cfdata == NULL) { + int64_t skip; + + cab->entry_cffolder->cfdata_index = 0; + + /* Seek read pointer to the offset of CFDATA if needed. */ + skip = cab->entry_cffolder->cfdata_offset_in_cab + - cab->cab_offset; + if (skip < 0) { + int folder_index; + switch (cab->entry_cffile->folder) { + case iFoldCONTINUED_FROM_PREV: + case iFoldCONTINUED_PREV_AND_NEXT: + folder_index = 0; + break; + case iFoldCONTINUED_TO_NEXT: + folder_index = cab->cfheader.folder_count-1; + break; + default: + folder_index = cab->entry_cffile->folder; + break; + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid offset of CFDATA in folder(%d) %jd < %jd", + folder_index, + (intmax_t)cab->entry_cffolder->cfdata_offset_in_cab, + (intmax_t)cab->cab_offset); + return (ARCHIVE_FATAL); + } + if (skip > 0) { + if (__archive_read_consume(a, skip) < 0) + return (ARCHIVE_FATAL); + cab->cab_offset = + cab->entry_cffolder->cfdata_offset_in_cab; + } + } + + /* + * Read a CFDATA. + */ + if (cab->entry_cffolder->cfdata_index < + cab->entry_cffolder->cfdata_count) { + const unsigned char *p; + int l; + + cfdata = &(cab->entry_cffolder->cfdata); + cab->entry_cffolder->cfdata_index++; + cab->entry_cfdata = cfdata; + cfdata->sum_calculated = 0; + cfdata->sum_extra_avail = 0; + cfdata->sum_ptr = NULL; + l = 8; + if (cab->cfheader.flags & RESERVE_PRESENT) + l += cab->cfheader.cfdata; + if ((p = __archive_read_ahead(a, l, NULL)) == NULL) + return (truncated_error(a)); + cfdata->sum = archive_le32dec(p + CFDATA_csum); + cfdata->compressed_size = archive_le16dec(p + CFDATA_cbData); + cfdata->compressed_bytes_remaining = cfdata->compressed_size; + cfdata->uncompressed_size = + archive_le16dec(p + CFDATA_cbUncomp); + cfdata->uncompressed_bytes_remaining = + cfdata->uncompressed_size; + cfdata->uncompressed_avail = 0; + cfdata->read_offset = 0; + cfdata->unconsumed = 0; + + /* + * Sanity check if data size is acceptable. + */ + if (cfdata->compressed_size == 0 || + cfdata->compressed_size > (0x8000+6144)) + goto invalid; + if (cfdata->uncompressed_size > 0x8000) + goto invalid; + if (cfdata->uncompressed_size == 0) { + switch (cab->entry_cffile->folder) { + case iFoldCONTINUED_PREV_AND_NEXT: + case iFoldCONTINUED_TO_NEXT: + break; + case iFoldCONTINUED_FROM_PREV: + default: + goto invalid; + } + } + /* If CFDATA is not last in a folder, an uncompressed + * size must be 0x8000(32KBi) */ + if ((cab->entry_cffolder->cfdata_index < + cab->entry_cffolder->cfdata_count) && + cfdata->uncompressed_size != 0x8000) + goto invalid; + + /* A compressed data size and an uncompressed data size must + * be the same in no compression mode. */ + if (cab->entry_cffolder->comptype == COMPTYPE_NONE && + cfdata->compressed_size != cfdata->uncompressed_size) + goto invalid; + + /* + * Save CFDATA image for sum check. + */ + if (cfdata->memimage_size < (size_t)l) { + free(cfdata->memimage); + cfdata->memimage = malloc(l); + if (cfdata->memimage == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for CAB data"); + return (ARCHIVE_FATAL); + } + cfdata->memimage_size = l; + } + memcpy(cfdata->memimage, p, l); + + /* Consume bytes as much as we used. */ + __archive_read_consume(a, l); + cab->cab_offset += l; + } else if (cab->entry_cffolder->cfdata_count > 0) { + /* Run out of all CFDATA in a folder. */ + cfdata->compressed_size = 0; + cfdata->uncompressed_size = 0; + cfdata->compressed_bytes_remaining = 0; + cfdata->uncompressed_bytes_remaining = 0; + } else { + /* Current folder does not have any CFDATA. */ + cfdata = &(cab->entry_cffolder->cfdata); + cab->entry_cfdata = cfdata; + memset(cfdata, 0, sizeof(*cfdata)); + } + return (ARCHIVE_OK); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid CFDATA"); + return (ARCHIVE_FATAL); +} + +/* + * Read ahead CFDATA. + */ +static const void * +cab_read_ahead_cfdata(struct archive_read *a, ssize_t *avail) +{ + struct cab *cab = (struct cab *)(a->format->data); + int err; + + err = cab_next_cfdata(a); + if (err < ARCHIVE_OK) { + *avail = err; + return (NULL); + } + + switch (cab->entry_cffolder->comptype) { + case COMPTYPE_NONE: + return (cab_read_ahead_cfdata_none(a, avail)); + case COMPTYPE_MSZIP: + return (cab_read_ahead_cfdata_deflate(a, avail)); + case COMPTYPE_LZX: + return (cab_read_ahead_cfdata_lzx(a, avail)); + default: /* Unsupported compression. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported CAB compression : %s", + cab->entry_cffolder->compname); + *avail = ARCHIVE_FAILED; + return (NULL); + } +} + +/* + * Read ahead CFDATA as uncompressed data. + */ +static const void * +cab_read_ahead_cfdata_none(struct archive_read *a, ssize_t *avail) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata; + const void *d; + int64_t skipped_bytes; + + cfdata = cab->entry_cfdata; + + if (cfdata->uncompressed_avail == 0 && + cfdata->read_offset > 0) { + /* we've already skipped some bytes before really read. */ + skipped_bytes = cfdata->read_offset; + cfdata->read_offset = 0; + cfdata->uncompressed_bytes_remaining += skipped_bytes; + } else + skipped_bytes = 0; + do { + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + d = __archive_read_ahead(a, 1, avail); + if (*avail <= 0) { + *avail = truncated_error(a); + return (NULL); + } + if (*avail > cfdata->uncompressed_bytes_remaining) + *avail = cfdata->uncompressed_bytes_remaining; + cfdata->uncompressed_avail = cfdata->uncompressed_size; + cfdata->unconsumed = *avail; + cfdata->sum_ptr = d; + if (skipped_bytes > 0) { + skipped_bytes = + cab_minimum_consume_cfdata(a, skipped_bytes); + if (skipped_bytes < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + continue; + } + } while (0); + + return (d); +} + +/* + * Read ahead CFDATA as deflate data. + */ +#ifdef HAVE_ZLIB_H +static const void * +cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata; + const void *d; + int r, mszip; + uint16_t uavail; + char eod = 0; + + cfdata = cab->entry_cfdata; + /* If the buffer hasn't been allocated, allocate it now. */ + if (cab->uncompressed_buffer == NULL) { + cab->uncompressed_buffer_size = 0x8000; + cab->uncompressed_buffer + = (unsigned char *)malloc(cab->uncompressed_buffer_size); + if (cab->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for CAB reader"); + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + + uavail = cfdata->uncompressed_avail; + if (uavail == cfdata->uncompressed_size) { + d = cab->uncompressed_buffer + cfdata->read_offset; + *avail = uavail - cfdata->read_offset; + return (d); + } + + if (!cab->entry_cffolder->decompress_init) { + cab->stream.next_in = NULL; + cab->stream.avail_in = 0; + cab->stream.total_in = 0; + cab->stream.next_out = NULL; + cab->stream.avail_out = 0; + cab->stream.total_out = 0; + if (cab->stream_valid) + r = inflateReset(&cab->stream); + else + r = inflateInit2(&cab->stream, + -15 /* Don't check for zlib header */); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize deflate decompression."); + *avail = ARCHIVE_FATAL; + return (NULL); + } + /* Stream structure has been set up. */ + cab->stream_valid = 1; + /* We've initialized decompression for this stream. */ + cab->entry_cffolder->decompress_init = 1; + } + + if (cfdata->compressed_bytes_remaining == cfdata->compressed_size) + mszip = 2; + else + mszip = 0; + eod = 0; + cab->stream.total_out = uavail; + /* + * We always uncompress all data in current CFDATA. + */ + while (!eod && cab->stream.total_out < cfdata->uncompressed_size) { + ssize_t bytes_avail; + + cab->stream.next_out = + cab->uncompressed_buffer + cab->stream.total_out; + cab->stream.avail_out = + cfdata->uncompressed_size - cab->stream.total_out; + + d = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + *avail = truncated_error(a); + return (NULL); + } + if (bytes_avail > cfdata->compressed_bytes_remaining) + bytes_avail = cfdata->compressed_bytes_remaining; + /* + * A bug in zlib.h: stream.next_in should be marked 'const' + * but isn't (the library never alters data through the + * next_in pointer, only reads it). The result: this ugly + * cast to remove 'const'. + */ + cab->stream.next_in = (Bytef *)(uintptr_t)d; + cab->stream.avail_in = bytes_avail; + cab->stream.total_in = 0; + + /* Cut out a tow-byte MSZIP signature(0x43, 0x4b). */ + if (mszip > 0) { + if (bytes_avail <= mszip) { + if (mszip == 2) { + if (cab->stream.next_in[0] != 0x43) + goto nomszip; + if (bytes_avail > 1 && + cab->stream.next_in[1] != 0x4b) + goto nomszip; + } else if (cab->stream.next_in[0] != 0x4b) + goto nomszip; + cfdata->unconsumed = bytes_avail; + cfdata->sum_ptr = d; + if (cab_minimum_consume_cfdata( + a, cfdata->unconsumed) < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + mszip -= bytes_avail; + continue; + } + if (mszip == 1 && cab->stream.next_in[0] != 0x4b) + goto nomszip; + else if (cab->stream.next_in[0] != 0x43 || + cab->stream.next_in[1] != 0x4b) + goto nomszip; + cab->stream.next_in += mszip; + cab->stream.avail_in -= mszip; + cab->stream.total_in += mszip; + mszip = 0; + } + + r = inflate(&cab->stream, 0); + switch (r) { + case Z_OK: + break; + case Z_STREAM_END: + eod = 1; + break; + default: + goto zlibfailed; + } + cfdata->unconsumed = cab->stream.total_in; + cfdata->sum_ptr = d; + if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + uavail = cab->stream.total_out; + + if (uavail < cfdata->uncompressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid uncompressed size (%d < %d)", + uavail, cfdata->uncompressed_size); + *avail = ARCHIVE_FATAL; + return (NULL); + } + + /* + * Note: I suspect there is a bug in makecab.exe because, in rare + * case, compressed bytes are still remaining regardless we have + * gotten all uncompressed bytes, which size is recoded in CFDATA, + * as much as we need, and we have to use the garbage so as to + * correctly compute the sum of CFDATA accordingly. + */ + if (cfdata->compressed_bytes_remaining > 0) { + ssize_t bytes_avail; + + d = __archive_read_ahead(a, cfdata->compressed_bytes_remaining, + &bytes_avail); + if (bytes_avail <= 0) { + *avail = truncated_error(a); + return (NULL); + } + cfdata->unconsumed = cfdata->compressed_bytes_remaining; + cfdata->sum_ptr = d; + if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + + /* + * Set dictionary data for decompressing of next CFDATA, which + * in the same folder. This is why we always do decompress CFDATA + * even if beginning CFDATA or some of CFDATA are not used in + * skipping file data. + */ + if (cab->entry_cffolder->cfdata_index < + cab->entry_cffolder->cfdata_count) { + r = inflateReset(&cab->stream); + if (r != Z_OK) + goto zlibfailed; + r = inflateSetDictionary(&cab->stream, + cab->uncompressed_buffer, cfdata->uncompressed_size); + if (r != Z_OK) + goto zlibfailed; + } + + d = cab->uncompressed_buffer + cfdata->read_offset; + *avail = uavail - cfdata->read_offset; + cfdata->uncompressed_avail = uavail; + + return (d); + +zlibfailed: + switch (r) { + case Z_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Out of memory for deflate decompression"); + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Deflate decompression failed (%d)", r); + break; + } + *avail = ARCHIVE_FATAL; + return (NULL); +nomszip: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "CFDATA incorrect(no MSZIP signature)"); + *avail = ARCHIVE_FATAL; + return (NULL); +} + +#else /* HAVE_ZLIB_H */ + +static const void * +cab_read_ahead_cfdata_deflate(struct archive_read *a, ssize_t *avail) +{ + *avail = ARCHIVE_FATAL; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "libarchive compiled without deflate support (no libz)"); + return (NULL); +} + +#endif /* HAVE_ZLIB_H */ + +static const void * +cab_read_ahead_cfdata_lzx(struct archive_read *a, ssize_t *avail) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata; + const void *d; + int r; + uint16_t uavail; + + cfdata = cab->entry_cfdata; + /* If the buffer hasn't been allocated, allocate it now. */ + if (cab->uncompressed_buffer == NULL) { + cab->uncompressed_buffer_size = 0x8000; + cab->uncompressed_buffer + = (unsigned char *)malloc(cab->uncompressed_buffer_size); + if (cab->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for CAB reader"); + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + + uavail = cfdata->uncompressed_avail; + if (uavail == cfdata->uncompressed_size) { + d = cab->uncompressed_buffer + cfdata->read_offset; + *avail = uavail - cfdata->read_offset; + return (d); + } + + if (!cab->entry_cffolder->decompress_init) { + r = lzx_decode_init(&cab->xstrm, + cab->entry_cffolder->compdata); + if (r != ARCHIVE_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize LZX decompression."); + *avail = ARCHIVE_FATAL; + return (NULL); + } + /* We've initialized decompression for this stream. */ + cab->entry_cffolder->decompress_init = 1; + } + + /* Clean up remaining bits of previous CFDATA. */ + lzx_cleanup_bitstream(&cab->xstrm); + cab->xstrm.total_out = uavail; + while (cab->xstrm.total_out < cfdata->uncompressed_size) { + ssize_t bytes_avail; + + cab->xstrm.next_out = + cab->uncompressed_buffer + cab->xstrm.total_out; + cab->xstrm.avail_out = + cfdata->uncompressed_size - cab->xstrm.total_out; + + d = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated CAB file data"); + *avail = ARCHIVE_FATAL; + return (NULL); + } + if (bytes_avail > cfdata->compressed_bytes_remaining) + bytes_avail = cfdata->compressed_bytes_remaining; + + cab->xstrm.next_in = d; + cab->xstrm.avail_in = bytes_avail; + cab->xstrm.total_in = 0; + r = lzx_decode(&cab->xstrm, + cfdata->compressed_bytes_remaining == bytes_avail); + switch (r) { + case ARCHIVE_OK: + case ARCHIVE_EOF: + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LZX decompression failed (%d)", r); + *avail = ARCHIVE_FATAL; + return (NULL); + } + cfdata->unconsumed = cab->xstrm.total_in; + cfdata->sum_ptr = d; + if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + + uavail = cab->xstrm.total_out; + /* + * Make sure a read pointer advances to next CFDATA. + */ + if (cfdata->compressed_bytes_remaining > 0) { + ssize_t bytes_avail; + + d = __archive_read_ahead(a, cfdata->compressed_bytes_remaining, + &bytes_avail); + if (bytes_avail <= 0) { + *avail = truncated_error(a); + return (NULL); + } + cfdata->unconsumed = cfdata->compressed_bytes_remaining; + cfdata->sum_ptr = d; + if (cab_minimum_consume_cfdata(a, cfdata->unconsumed) < 0) { + *avail = ARCHIVE_FATAL; + return (NULL); + } + } + + /* + * Translation reversal of x86 proccessor CALL byte sequence(E8). + */ + lzx_translation(&cab->xstrm, cab->uncompressed_buffer, + cfdata->uncompressed_size, + (cab->entry_cffolder->cfdata_index-1) * 0x8000); + + d = cab->uncompressed_buffer + cfdata->read_offset; + *avail = uavail - cfdata->read_offset; + cfdata->uncompressed_avail = uavail; + + return (d); +} + +/* + * Consume CFDATA. + * We always decompress CFDATA to consume CFDATA as much as we need + * in uncompressed bytes because all CFDATA in a folder are related + * so we do not skip any CFDATA without decompressing. + * Note: If the folder of a CFFILE is iFoldCONTINUED_PREV_AND_NEXT or + * iFoldCONTINUED_FROM_PREV, we won't decompress because a CFDATA for + * the CFFILE is remaining bytes of previous Multivolume CAB file. + */ +static int64_t +cab_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata; + int64_t cbytes, rbytes; + int err; + + rbytes = cab_minimum_consume_cfdata(a, consumed_bytes); + if (rbytes < 0) + return (ARCHIVE_FATAL); + + cfdata = cab->entry_cfdata; + while (rbytes > 0) { + ssize_t avail; + + if (cfdata->compressed_size == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid CFDATA"); + return (ARCHIVE_FATAL); + } + cbytes = cfdata->uncompressed_bytes_remaining; + if (cbytes > rbytes) + cbytes = rbytes; + rbytes -= cbytes; + + if (cfdata->uncompressed_avail == 0 && + (cab->entry_cffolder->comptype == COMPTYPE_NONE || + cab->entry_cffile->folder == iFoldCONTINUED_PREV_AND_NEXT || + cab->entry_cffile->folder == iFoldCONTINUED_FROM_PREV)) { + /* We have not read any data yet. */ + if (cbytes == cfdata->uncompressed_bytes_remaining) { + /* Skip whole current CFDATA. */ + __archive_read_consume(a, + cfdata->compressed_size); + cab->cab_offset += cfdata->compressed_size; + cfdata->compressed_bytes_remaining = 0; + cfdata->uncompressed_bytes_remaining = 0; + err = cab_next_cfdata(a); + if (err < 0) + return (err); + cfdata = cab->entry_cfdata; + if (cfdata->uncompressed_size == 0) { + switch (cab->entry_cffile->folder) { + case iFoldCONTINUED_PREV_AND_NEXT: + case iFoldCONTINUED_TO_NEXT: + case iFoldCONTINUED_FROM_PREV: + rbytes = 0; + break; + default: + break; + } + } + continue; + } + cfdata->read_offset += cbytes; + cfdata->uncompressed_bytes_remaining -= cbytes; + break; + } else if (cbytes == 0) { + err = cab_next_cfdata(a); + if (err < 0) + return (err); + cfdata = cab->entry_cfdata; + if (cfdata->uncompressed_size == 0) { + switch (cab->entry_cffile->folder) { + case iFoldCONTINUED_PREV_AND_NEXT: + case iFoldCONTINUED_TO_NEXT: + case iFoldCONTINUED_FROM_PREV: + return (ARCHIVE_FATAL); + default: + break; + } + } + continue; + } + while (cbytes > 0) { + (void)cab_read_ahead_cfdata(a, &avail); + if (avail <= 0) + return (ARCHIVE_FATAL); + if (avail > cbytes) + avail = cbytes; + if (cab_minimum_consume_cfdata(a, avail) < 0) + return (ARCHIVE_FATAL); + cbytes -= avail; + } + } + return (consumed_bytes); +} + +/* + * Consume CFDATA as much as we have already gotten and + * compute the sum of CFDATA. + */ +static int64_t +cab_minimum_consume_cfdata(struct archive_read *a, int64_t consumed_bytes) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfdata *cfdata; + int64_t cbytes, rbytes; + int err; + + cfdata = cab->entry_cfdata; + rbytes = consumed_bytes; + if (cab->entry_cffolder->comptype == COMPTYPE_NONE) { + if (consumed_bytes < cfdata->unconsumed) + cbytes = consumed_bytes; + else + cbytes = cfdata->unconsumed; + rbytes -= cbytes; + cfdata->read_offset += cbytes; + cfdata->uncompressed_bytes_remaining -= cbytes; + cfdata->unconsumed -= cbytes; + } else { + cbytes = cfdata->uncompressed_avail - cfdata->read_offset; + if (cbytes > 0) { + if (consumed_bytes < cbytes) + cbytes = consumed_bytes; + rbytes -= cbytes; + cfdata->read_offset += cbytes; + cfdata->uncompressed_bytes_remaining -= cbytes; + } + + if (cfdata->unconsumed) { + cbytes = cfdata->unconsumed; + cfdata->unconsumed = 0; + } else + cbytes = 0; + } + if (cbytes) { + /* Compute the sum. */ + cab_checksum_update(a, cbytes); + + /* Consume as much as the compressor actually used. */ + __archive_read_consume(a, cbytes); + cab->cab_offset += cbytes; + cfdata->compressed_bytes_remaining -= cbytes; + if (cfdata->compressed_bytes_remaining == 0) { + err = cab_checksum_finish(a); + if (err < 0) + return (err); + } + } + return (rbytes); +} + +/* + * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets + * cab->end_of_entry if it consumes all of the data. + */ +static int +cab_read_data(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct cab *cab = (struct cab *)(a->format->data); + ssize_t bytes_avail; + + if (cab->entry_bytes_remaining == 0) { + *buff = NULL; + *size = 0; + *offset = cab->entry_offset; + cab->end_of_entry = 1; + return (ARCHIVE_OK); + } + + *buff = cab_read_ahead_cfdata(a, &bytes_avail); + if (bytes_avail <= 0) { + *buff = NULL; + *size = 0; + *offset = 0; + if (bytes_avail == 0 && + cab->entry_cfdata->uncompressed_size == 0) { + /* All of CFDATA in a folder has been handled. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, "Invalid CFDATA"); + return (ARCHIVE_FATAL); + } else + return (bytes_avail); + } + if (bytes_avail > cab->entry_bytes_remaining) + bytes_avail = cab->entry_bytes_remaining; + + *size = bytes_avail; + *offset = cab->entry_offset; + cab->entry_offset += bytes_avail; + cab->entry_bytes_remaining -= bytes_avail; + if (cab->entry_bytes_remaining == 0) + cab->end_of_entry = 1; + cab->entry_unconsumed = bytes_avail; + return (ARCHIVE_OK); +} + +static int +archive_read_format_cab_read_data_skip(struct archive_read *a) +{ + struct cab *cab; + int64_t bytes_skipped; + int r; + + cab = (struct cab *)(a->format->data); + + if (cab->end_of_archive) + return (ARCHIVE_EOF); + + if (cab->entry_unconsumed) { + /* Consume as much as the compressor actually used. */ + r = cab_consume_cfdata(a, cab->entry_unconsumed); + cab->entry_unconsumed = 0; + if (r < 0) + return (r); + } else if (cab->entry_cfdata == NULL) { + r = cab_next_cfdata(a); + if (r < 0) + return (r); + } + + /* if we've already read to end of data, we're done. */ + if (cab->end_of_entry_cleanup) + return (ARCHIVE_OK); + + /* + * If the length is at the beginning, we can skip the + * compressed data much more quickly. + */ + bytes_skipped = cab_consume_cfdata(a, cab->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + + /* This entry is finished and done. */ + cab->end_of_entry_cleanup = cab->end_of_entry = 1; + return (ARCHIVE_OK); +} + +static int +archive_read_format_cab_cleanup(struct archive_read *a) +{ + struct cab *cab = (struct cab *)(a->format->data); + struct cfheader *hd = &cab->cfheader; + int i; + + if (hd->folder_array != NULL) { + for (i = 0; i < hd->folder_count; i++) + free(hd->folder_array[i].cfdata.memimage); + free(hd->folder_array); + } + if (hd->file_array != NULL) { + for (i = 0; i < cab->cfheader.file_count; i++) + archive_string_free(&(hd->file_array[i].pathname)); + free(hd->file_array); + } +#ifdef HAVE_ZLIB_H + if (cab->stream_valid) + inflateEnd(&cab->stream); +#endif + lzx_decode_free(&cab->xstrm); + archive_wstring_free(&cab->ws); + free(cab->uncompressed_buffer); + free(cab); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +/* Convert an MSDOS-style date/time into Unix-style time. */ +static time_t +cab_dos_time(const unsigned char *p) +{ + int msTime, msDate; + struct tm ts; + + msDate = archive_le16dec(p); + msTime = archive_le16dec(p+2); + + memset(&ts, 0, sizeof(ts)); + ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ + ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ + ts.tm_mday = msDate & 0x1f; /* Day of month. */ + ts.tm_hour = (msTime >> 11) & 0x1f; + ts.tm_min = (msTime >> 5) & 0x3f; + ts.tm_sec = (msTime << 1) & 0x3e; + ts.tm_isdst = -1; + return (mktime(&ts)); +} + +/***************************************************************** + * + * LZX decompression code. + * + *****************************************************************/ + +/* + * Initialize LZX decoder. + * + * Returns ARCHIVE_OK if initialization was successful. + * Returns ARCHIVE_FAILED if w_bits has unsupported value. + * Returns ARCHIVE_FATAL if initialization failed; memory allocation + * error occurred. + */ +static int +lzx_decode_init(struct lzx_stream *strm, int w_bits) +{ + struct lzx_dec *ds; + int slot, w_size, w_slot; + int base, footer; + + if (strm->ds == NULL) { + strm->ds = calloc(1, sizeof(*strm->ds)); + if (strm->ds == NULL) + return (ARCHIVE_FATAL); + } + ds = strm->ds; + ds->error = ARCHIVE_FAILED; + + /* Allow bits from 15(32KBi) up to 21(2MBi) */ + if (w_bits < SLOT_BASE || w_bits > SLOT_MAX) + return (ARCHIVE_FAILED); + + ds->error = ARCHIVE_FATAL; + + /* + * Alloc window + */ + w_size = ds->w_size; + w_slot = slots[w_bits - SLOT_BASE]; + ds->w_size = 1U << w_bits; + ds->w_mask = ds->w_size -1; + if (ds->w_buff == NULL || w_size != ds->w_size) { + free(ds->w_buff); + ds->w_buff = malloc(ds->w_size); + if (ds->w_buff == NULL) + return (ARCHIVE_FATAL); + free(ds->pos_tbl); + ds->pos_tbl = malloc(sizeof(ds->pos_tbl[0]) * w_slot); + if (ds->pos_tbl == NULL) + return (ARCHIVE_FATAL); + lzx_huffman_free(&(ds->mt)); + } + + base = footer = 0; + for (slot = 0; slot < w_slot; slot++) { + int n; + if (footer == 0) + base = slot; + else + base += 1 << footer; + if (footer < 17) { + footer = -2; + for (n = base; n; n >>= 1) + footer++; + if (footer <= 0) + footer = 0; + } + ds->pos_tbl[slot].base = base; + ds->pos_tbl[slot].footer_bits = footer; + } + + ds->w_pos = 0; + ds->state = 0; + ds->br.cache_buffer = 0; + ds->br.cache_avail = 0; + ds->r0 = ds->r1 = ds->r2 = 1; + + /* Initialize aligned offset tree. */ + if (lzx_huffman_init(&(ds->at), 8, 8) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Initialize pre-tree. */ + if (lzx_huffman_init(&(ds->pt), 20, 10) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Initialize Main tree. */ + if (lzx_huffman_init(&(ds->mt), 256+(w_slot<<3), 16) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Initialize Length tree. */ + if (lzx_huffman_init(&(ds->lt), 249, 16) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + ds->error = 0; + + return (ARCHIVE_OK); +} + +/* + * Release LZX decoder. + */ +static void +lzx_decode_free(struct lzx_stream *strm) +{ + + if (strm->ds == NULL) + return; + free(strm->ds->w_buff); + free(strm->ds->pos_tbl); + lzx_huffman_free(&(strm->ds->at)); + lzx_huffman_free(&(strm->ds->pt)); + lzx_huffman_free(&(strm->ds->mt)); + lzx_huffman_free(&(strm->ds->lt)); + free(strm->ds); + strm->ds = NULL; +} + +/* + * E8 Call Translation reversal. + */ +static void +lzx_translation(struct lzx_stream *strm, void *p, size_t size, uint32_t offset) +{ + struct lzx_dec *ds = strm->ds; + unsigned char *b, *end; + + if (!ds->translation || size <= 10) + return; + b = p; + end = b + size - 10; + while (b < end && (b = memchr(b, 0xE8, end - b)) != NULL) { + size_t i = b - (unsigned char *)p; + long cp, displacement, value; + + cp = offset + i; + value = archive_le32dec(&b[1]); + if (value >= -cp && value < (long)ds->translation_size) { + if (value >= 0) + displacement = value - cp; + else + displacement = value + ds->translation_size; + archive_le32enc(&b[1], (uint32_t)displacement); + } + b += 5; + } +} + +/* + * Bit stream reader. + */ +/* Check that the cache buffer has enough bits. */ +#define lzx_br_has(br, n) ((br)->cache_avail >= n) +/* Get compressed data by bit. */ +#define lzx_br_bits(br, n) \ + (((uint32_t)((br)->cache_buffer >> \ + ((br)->cache_avail - (n)))) & cache_masks[n]) +#define lzx_br_bits_forced(br, n) \ + (((uint32_t)((br)->cache_buffer << \ + ((n) - (br)->cache_avail))) & cache_masks[n]) +/* Read ahead to make sure the cache buffer has enough compressed data we + * will use. + * True : completed, there is enough data in the cache buffer. + * False : we met that strm->next_in is empty, we have to get following + * bytes. */ +#define lzx_br_read_ahead_0(strm, br, n) \ + (lzx_br_has((br), (n)) || lzx_br_fillup(strm, br)) +/* True : the cache buffer has some bits as much as we need. + * False : there are no enough bits in the cache buffer to be used, + * we have to get following bytes if we could. */ +#define lzx_br_read_ahead(strm, br, n) \ + (lzx_br_read_ahead_0((strm), (br), (n)) || lzx_br_has((br), (n))) + +/* Notify how many bits we consumed. */ +#define lzx_br_consume(br, n) ((br)->cache_avail -= (n)) +#define lzx_br_consume_unalined_bits(br) ((br)->cache_avail &= ~0x0f) + +static const uint32_t cache_masks[] = { + 0x00000000, 0x00000001, 0x00000003, 0x00000007, + 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, + 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, + 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, + 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, + 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, + 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, + 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF +}; + +/* + * Shift away used bits in the cache data and fill it up with following bits. + * Call this when cache buffer does not have enough bits you need. + * + * Returns 1 if the cache buffer is full. + * Returns 0 if the cache buffer is not full; input buffer is empty. + */ +static int +lzx_br_fillup(struct lzx_stream *strm, struct lzx_br *br) +{ +/* + * x86 proccessor family can read misaligned data without an access error. + */ + int n = CACHE_BITS - br->cache_avail; + + for (;;) { + switch (n >> 4) { + case 4: + if (strm->avail_in >= 8) { + br->cache_buffer = + ((uint64_t)strm->next_in[1]) << 56 | + ((uint64_t)strm->next_in[0]) << 48 | + ((uint64_t)strm->next_in[3]) << 40 | + ((uint64_t)strm->next_in[2]) << 32 | + ((uint32_t)strm->next_in[5]) << 24 | + ((uint32_t)strm->next_in[4]) << 16 | + ((uint32_t)strm->next_in[7]) << 8 | + (uint32_t)strm->next_in[6]; + strm->next_in += 8; + strm->avail_in -= 8; + br->cache_avail += 8 * 8; + return (1); + } + break; + case 3: + if (strm->avail_in >= 6) { + br->cache_buffer = + (br->cache_buffer << 48) | + ((uint64_t)strm->next_in[1]) << 40 | + ((uint64_t)strm->next_in[0]) << 32 | + ((uint32_t)strm->next_in[3]) << 24 | + ((uint32_t)strm->next_in[2]) << 16 | + ((uint32_t)strm->next_in[5]) << 8 | + (uint32_t)strm->next_in[4]; + strm->next_in += 6; + strm->avail_in -= 6; + br->cache_avail += 6 * 8; + return (1); + } + break; + case 0: + /* We have enough compressed data in + * the cache buffer.*/ + return (1); + default: + break; + } + if (strm->avail_in < 2) { + /* There is not enough compressed data to + * fill up the cache buffer. */ + if (strm->avail_in == 1) { + br->odd = *strm->next_in++; + strm->avail_in--; + br->have_odd = 1; + } + return (0); + } + br->cache_buffer = + (br->cache_buffer << 16) | + archive_le16dec(strm->next_in); + strm->next_in += 2; + strm->avail_in -= 2; + br->cache_avail += 16; + n -= 16; + } +} + +static void +lzx_br_fixup(struct lzx_stream *strm, struct lzx_br *br) +{ + int n = CACHE_BITS - br->cache_avail; + + if (br->have_odd && n >= 16 && strm->avail_in > 0) { + br->cache_buffer = + (br->cache_buffer << 16) | + ((uint16_t)(*strm->next_in)) << 8 | br->odd; + strm->next_in++; + strm->avail_in--; + br->cache_avail += 16; + br->have_odd = 0; + } +} + +static void +lzx_cleanup_bitstream(struct lzx_stream *strm) +{ + strm->ds->br.cache_avail = 0; + strm->ds->br.have_odd = 0; +} + +/* + * Decode LZX. + * + * 1. Returns ARCHIVE_OK if output buffer or input buffer are empty. + * Please set available buffer and call this function again. + * 2. Returns ARCHIVE_EOF if decompression has been completed. + * 3. Returns ARCHIVE_FAILED if an error occurred; compressed data + * is broken or you do not set 'last' flag properly. + */ +#define ST_RD_TRANSLATION 0 +#define ST_RD_TRANSLATION_SIZE 1 +#define ST_RD_BLOCK_TYPE 2 +#define ST_RD_BLOCK_SIZE 3 +#define ST_RD_R0 4 +#define ST_RD_R1 5 +#define ST_RD_R2 6 +#define ST_COPY_UNCOMP1 7 +#define ST_COPY_UNCOMP2 8 +#define ST_RD_ALIGNED_OFFSET 9 +#define ST_RD_VERBATIM 10 +#define ST_RD_PRE_MAIN_TREE_256 11 +#define ST_MAIN_TREE_256 12 +#define ST_RD_PRE_MAIN_TREE_REM 13 +#define ST_MAIN_TREE_REM 14 +#define ST_RD_PRE_LENGTH_TREE 15 +#define ST_LENGTH_TREE 16 +#define ST_MAIN 17 +#define ST_LENGTH 18 +#define ST_OFFSET 19 +#define ST_REAL_POS 20 +#define ST_COPY 21 + +static int +lzx_decode(struct lzx_stream *strm, int last) +{ + struct lzx_dec *ds = strm->ds; + int64_t avail_in; + int r; + + if (ds->error) + return (ds->error); + + avail_in = strm->avail_in; + lzx_br_fixup(strm, &(ds->br)); + do { + if (ds->state < ST_MAIN) + r = lzx_read_blocks(strm, last); + else { + int64_t bytes_written = strm->avail_out; + r = lzx_decode_blocks(strm, last); + bytes_written -= strm->avail_out; + strm->next_out += bytes_written; + strm->total_out += bytes_written; + } + } while (r == 100); + strm->total_in += avail_in - strm->avail_in; + return (r); +} + +static int +lzx_read_blocks(struct lzx_stream *strm, int last) +{ + struct lzx_dec *ds = strm->ds; + struct lzx_br *br = &(ds->br); + int i, r; + + for (;;) { + switch (ds->state) { + case ST_RD_TRANSLATION: + if (!lzx_br_read_ahead(strm, br, 1)) { + ds->state = ST_RD_TRANSLATION; + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->translation = lzx_br_bits(br, 1); + lzx_br_consume(br, 1); + /* FALL THROUGH */ + case ST_RD_TRANSLATION_SIZE: + if (ds->translation) { + if (!lzx_br_read_ahead(strm, br, 32)) { + ds->state = ST_RD_TRANSLATION_SIZE; + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->translation_size = lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + ds->translation_size <<= 16; + ds->translation_size |= lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + } + /* FALL THROUGH */ + case ST_RD_BLOCK_TYPE: + if (!lzx_br_read_ahead(strm, br, 3)) { + ds->state = ST_RD_BLOCK_TYPE; + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->block_type = lzx_br_bits(br, 3); + lzx_br_consume(br, 3); + /* Check a block type. */ + switch (ds->block_type) { + case VERBATIM_BLOCK: + case ALIGNED_OFFSET_BLOCK: + case UNCOMPRESSED_BLOCK: + break; + default: + goto failed;/* Invalid */ + } + /* FALL THROUGH */ + case ST_RD_BLOCK_SIZE: + if (!lzx_br_read_ahead(strm, br, 24)) { + ds->state = ST_RD_BLOCK_SIZE; + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->block_size = lzx_br_bits(br, 8); + lzx_br_consume(br, 8); + ds->block_size <<= 16; + ds->block_size |= lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + if (ds->block_size == 0) + goto failed; + ds->block_bytes_avail = ds->block_size; + if (ds->block_type != UNCOMPRESSED_BLOCK) { + if (ds->block_type == VERBATIM_BLOCK) + ds->state = ST_RD_VERBATIM; + else + ds->state = ST_RD_ALIGNED_OFFSET; + break; + } + /* + * Handle an Uncompressed Block. + */ + /* Skip padding to align following field on + * 16-bit boundary. */ + lzx_br_consume_unalined_bits(br); + /* Preparation to read repeated offsets R0,R1 and R2. */ + ds->rbytes_avail = 0; + ds->state = ST_RD_R0; + /* FALL THROUGH */ + case ST_RD_R0: + case ST_RD_R1: + case ST_RD_R2: + do { + uint16_t u16; + /* Drain bits in the cache buffer of + * bit-stream. */ + if (lzx_br_has(br, 32)) { + u16 = lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + archive_le16enc(ds->rbytes, u16); + u16 = lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + archive_le16enc(ds->rbytes+2, u16); + ds->rbytes_avail = 4; + } else if (lzx_br_has(br, 16)) { + u16 = lzx_br_bits(br, 16); + lzx_br_consume(br, 16); + archive_le16enc(ds->rbytes, u16); + ds->rbytes_avail = 2; + } else + ds->rbytes_avail = 0; + if (ds->rbytes_avail < 4 && ds->br.have_odd) { + ds->rbytes[ds->rbytes_avail++] = + ds->br.odd; + ds->br.have_odd = 0; + } + while (ds->rbytes_avail < 4) { + if (strm->avail_in <= 0) { + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->rbytes[ds->rbytes_avail++] = + *strm->next_in++; + strm->avail_in--; + } + if (ds->state == ST_RD_R0) { + ds->r0 = archive_le32dec(ds->rbytes); + if (ds->r0 < 0) + goto failed; + ds->state = ST_RD_R1; + } else if (ds->state == ST_RD_R1) { + ds->r1 = archive_le32dec(ds->rbytes); + if (ds->r1 < 0) + goto failed; + ds->state = ST_RD_R2; + } else if (ds->state == ST_RD_R2) { + ds->r2 = archive_le32dec(ds->rbytes); + if (ds->r2 < 0) + goto failed; + /* We've gotten all repeated offsets. */ + ds->state = ST_COPY_UNCOMP1; + } + } while (ds->state != ST_COPY_UNCOMP1); + /* FALL THROUGH */ + case ST_COPY_UNCOMP1: + /* + * Copy bytes form next_in to next_out directly. + */ + while (ds->block_bytes_avail) { + unsigned char *d; + int l,ll; + + if (strm->avail_out <= 0) + /* Output buffer is empty. */ + return (ARCHIVE_OK); + if (strm->avail_in <= 0) { + /* Input buffer is empty. */ + if (last) + goto failed; + return (ARCHIVE_OK); + } + l = ds->block_bytes_avail; + if (l > ds->w_size - ds->w_pos) + l = ds->w_size - ds->w_pos; + if (l > strm->avail_out) + l = (int)strm->avail_out; + if (l > strm->avail_in) + l = (int)strm->avail_in; + ll = l; + d = &(ds->w_buff[ds->w_pos]); + while (--l >= 0) { + *strm->next_out++ = *strm->next_in; + *d++ = *strm->next_in++; + } + strm->avail_out -= ll; + strm->total_out += ll; + strm->avail_in -= ll; + ds->w_pos = (ds->w_pos + ll) & ds->w_mask; + ds->block_bytes_avail -= ll; + } + /* FALL THROUGH */ + case ST_COPY_UNCOMP2: + /* Re-align; skip padding byte. */ + if (ds->block_size & 1) { + if (strm->avail_in <= 0) { + /* Input buffer is empty. */ + ds->state = ST_COPY_UNCOMP2; + if (last) + goto failed; + return (ARCHIVE_OK); + } + strm->next_in++; + strm->avail_in --; + } + /* This block ended. */ + ds->state = ST_RD_BLOCK_TYPE; + return (ARCHIVE_EOF); + /********************/ + case ST_RD_ALIGNED_OFFSET: + /* + * Read Aligned offset tree. + */ + if (!lzx_br_read_ahead(strm, br, 3 * ds->at.len_size)) { + ds->state = ST_RD_ALIGNED_OFFSET; + if (last) + goto failed; + return (ARCHIVE_OK); + } + memset(ds->at.freq, 0, sizeof(ds->at.freq)); + for (i = 0; i < ds->at.len_size; i++) { + ds->at.bitlen[i] = lzx_br_bits(br, 3); + ds->at.freq[ds->at.bitlen[i]]++; + lzx_br_consume(br, 3); + } + if (!lzx_make_huffman_table(&ds->at)) + goto failed; + /* FALL THROUGH */ + case ST_RD_VERBATIM: + ds->loop = 0; + /* FALL THROUGH */ + case ST_RD_PRE_MAIN_TREE_256: + /* + * Read Pre-tree for first 256 elements of main tree. + */ + if (!lzx_read_pre_tree(strm)) { + ds->state = ST_RD_PRE_MAIN_TREE_256; + if (last) + goto failed; + return (ARCHIVE_OK); + } + if (!lzx_make_huffman_table(&ds->pt)) + goto failed; + ds->loop = 0; + /* FALL THROUGH */ + case ST_MAIN_TREE_256: + /* + * Get path lengths of first 256 elements of main tree. + */ + r = lzx_read_bitlen(strm, &ds->mt, 256); + if (r < 0) + goto failed; + else if (!r) { + ds->state = ST_MAIN_TREE_256; + if (last) + goto failed; + return (ARCHIVE_OK); + } + ds->loop = 0; + /* FALL THROUGH */ + case ST_RD_PRE_MAIN_TREE_REM: + /* + * Read Pre-tree for remaining elements of main tree. + */ + if (!lzx_read_pre_tree(strm)) { + ds->state = ST_RD_PRE_MAIN_TREE_REM; + if (last) + goto failed; + return (ARCHIVE_OK); + } + if (!lzx_make_huffman_table(&ds->pt)) + goto failed; + ds->loop = 256; + /* FALL THROUGH */ + case ST_MAIN_TREE_REM: + /* + * Get path lengths of remaining elements of main tree. + */ + r = lzx_read_bitlen(strm, &ds->mt, -1); + if (r < 0) + goto failed; + else if (!r) { + ds->state = ST_MAIN_TREE_REM; + if (last) + goto failed; + return (ARCHIVE_OK); + } + if (!lzx_make_huffman_table(&ds->mt)) + goto failed; + ds->loop = 0; + /* FALL THROUGH */ + case ST_RD_PRE_LENGTH_TREE: + /* + * Read Pre-tree for remaining elements of main tree. + */ + if (!lzx_read_pre_tree(strm)) { + ds->state = ST_RD_PRE_LENGTH_TREE; + if (last) + goto failed; + return (ARCHIVE_OK); + } + if (!lzx_make_huffman_table(&ds->pt)) + goto failed; + ds->loop = 0; + /* FALL THROUGH */ + case ST_LENGTH_TREE: + /* + * Get path lengths of remaining elements of main tree. + */ + r = lzx_read_bitlen(strm, &ds->lt, -1); + if (r < 0) + goto failed; + else if (!r) { + ds->state = ST_LENGTH_TREE; + if (last) + goto failed; + return (ARCHIVE_OK); + } + if (!lzx_make_huffman_table(&ds->lt)) + goto failed; + ds->state = ST_MAIN; + return (100); + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +} + +static int +lzx_decode_blocks(struct lzx_stream *strm, int last) +{ + struct lzx_dec *ds = strm->ds; + struct lzx_br bre = ds->br; + struct huffman *at = &(ds->at), *lt = &(ds->lt), *mt = &(ds->mt); + const struct lzx_pos_tbl *pos_tbl = ds->pos_tbl; + unsigned char *outp = strm->next_out; + unsigned char *endp = outp + strm->avail_out; + unsigned char *w_buff = ds->w_buff; + unsigned char *at_bitlen = at->bitlen; + unsigned char *lt_bitlen = lt->bitlen; + unsigned char *mt_bitlen = mt->bitlen; + size_t block_bytes_avail = ds->block_bytes_avail; + int at_max_bits = at->max_bits; + int lt_max_bits = lt->max_bits; + int mt_max_bits = mt->max_bits; + int c, copy_len = ds->copy_len, copy_pos = ds->copy_pos; + int w_pos = ds->w_pos, w_mask = ds->w_mask, w_size = ds->w_size; + int length_header = ds->length_header; + int offset_bits = ds->offset_bits; + int position_slot = ds->position_slot; + int r0 = ds->r0, r1 = ds->r1, r2 = ds->r2; + int state = ds->state; + char block_type = ds->block_type; + + for (;;) { + switch (state) { + case ST_MAIN: + for (;;) { + if (block_bytes_avail == 0) { + /* This block ended. */ + ds->state = ST_RD_BLOCK_TYPE; + ds->br = bre; + ds->block_bytes_avail = + block_bytes_avail; + ds->copy_len = copy_len; + ds->copy_pos = copy_pos; + ds->length_header = length_header; + ds->position_slot = position_slot; + ds->r0 = r0; ds->r1 = r1; ds->r2 = r2; + ds->w_pos = w_pos; + strm->avail_out = endp - outp; + return (ARCHIVE_EOF); + } + if (outp >= endp) + /* Output buffer is empty. */ + goto next_data; + + if (!lzx_br_read_ahead(strm, &bre, + mt_max_bits)) { + if (!last) + goto next_data; + /* Remaining bits are less than + * maximum bits(mt.max_bits) but maybe + * it still remains as much as we need, + * so we should try to use it with + * dummy bits. */ + c = lzx_decode_huffman(mt, + lzx_br_bits_forced( + &bre, mt_max_bits)); + lzx_br_consume(&bre, mt_bitlen[c]); + if (!lzx_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + c = lzx_decode_huffman(mt, + lzx_br_bits(&bre, mt_max_bits)); + lzx_br_consume(&bre, mt_bitlen[c]); + } + if (c > UCHAR_MAX) + break; + /* + * 'c' is exactly literal code. + */ + /* Save a decoded code to reference it + * afterward. */ + w_buff[w_pos] = c; + w_pos = (w_pos + 1) & w_mask; + /* Store the decoded code to output buffer. */ + *outp++ = c; + block_bytes_avail--; + } + /* + * Get a match code, its length and offset. + */ + c -= UCHAR_MAX + 1; + length_header = c & 7; + position_slot = c >> 3; + /* FALL THROUGH */ + case ST_LENGTH: + /* + * Get a length. + */ + if (length_header == 7) { + if (!lzx_br_read_ahead(strm, &bre, + lt_max_bits)) { + if (!last) { + state = ST_LENGTH; + goto next_data; + } + c = lzx_decode_huffman(lt, + lzx_br_bits_forced( + &bre, lt_max_bits)); + lzx_br_consume(&bre, lt_bitlen[c]); + if (!lzx_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + c = lzx_decode_huffman(lt, + lzx_br_bits(&bre, lt_max_bits)); + lzx_br_consume(&bre, lt_bitlen[c]); + } + copy_len = c + 7 + 2; + } else + copy_len = length_header + 2; + if ((size_t)copy_len > block_bytes_avail) + goto failed; + /* + * Get an offset. + */ + switch (position_slot) { + case 0: /* Use repeated offset 0. */ + copy_pos = r0; + state = ST_REAL_POS; + continue; + case 1: /* Use repeated offset 1. */ + copy_pos = r1; + /* Swap repeated offset. */ + r1 = r0; + r0 = copy_pos; + state = ST_REAL_POS; + continue; + case 2: /* Use repeated offset 2. */ + copy_pos = r2; + /* Swap repeated offset. */ + r2 = r0; + r0 = copy_pos; + state = ST_REAL_POS; + continue; + default: + offset_bits = + pos_tbl[position_slot].footer_bits; + break; + } + /* FALL THROUGH */ + case ST_OFFSET: + /* + * Get the offset, which is a distance from + * current window position. + */ + if (block_type == ALIGNED_OFFSET_BLOCK && + offset_bits >= 3) { + int offbits = offset_bits - 3; + + if (!lzx_br_read_ahead(strm, &bre, offbits)) { + state = ST_OFFSET; + if (last) + goto failed; + goto next_data; + } + copy_pos = lzx_br_bits(&bre, offbits) << 3; + + /* Get an aligned number. */ + if (!lzx_br_read_ahead(strm, &bre, + offbits + at_max_bits)) { + if (!last) { + state = ST_OFFSET; + goto next_data; + } + lzx_br_consume(&bre, offbits); + c = lzx_decode_huffman(at, + lzx_br_bits_forced(&bre, + at_max_bits)); + lzx_br_consume(&bre, at_bitlen[c]); + if (!lzx_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + lzx_br_consume(&bre, offbits); + c = lzx_decode_huffman(at, + lzx_br_bits(&bre, at_max_bits)); + lzx_br_consume(&bre, at_bitlen[c]); + } + /* Add an aligned number. */ + copy_pos += c; + } else { + if (!lzx_br_read_ahead(strm, &bre, + offset_bits)) { + state = ST_OFFSET; + if (last) + goto failed; + goto next_data; + } + copy_pos = lzx_br_bits(&bre, offset_bits); + lzx_br_consume(&bre, offset_bits); + } + copy_pos += pos_tbl[position_slot].base -2; + + /* Update repeated offset LRU queue. */ + r2 = r1; + r1 = r0; + r0 = copy_pos; + /* FALL THROUGH */ + case ST_REAL_POS: + /* + * Compute a real position in window. + */ + copy_pos = (w_pos - copy_pos) & w_mask; + /* FALL THROUGH */ + case ST_COPY: + /* + * Copy several bytes as extracted data from the window + * into the output buffer. + */ + for (;;) { + const unsigned char *s; + int l; + + l = copy_len; + if (copy_pos > w_pos) { + if (l > w_size - copy_pos) + l = w_size - copy_pos; + } else { + if (l > w_size - w_pos) + l = w_size - w_pos; + } + if (outp + l >= endp) + l = endp - outp; + s = w_buff + copy_pos; + if (l >= 8 && ((copy_pos + l < w_pos) + || (w_pos + l < copy_pos))) { + memcpy(w_buff + w_pos, s, l); + memcpy(outp, s, l); + } else { + unsigned char *d; + int li; + + d = w_buff + w_pos; + for (li = 0; li < l; li++) + outp[li] = d[li] = s[li]; + } + outp += l; + copy_pos = (copy_pos + l) & w_mask; + w_pos = (w_pos + l) & w_mask; + block_bytes_avail -= l; + if (copy_len <= l) + /* A copy of current pattern ended. */ + break; + copy_len -= l; + if (outp >= endp) { + /* Output buffer is empty. */ + state = ST_COPY; + goto next_data; + } + } + state = ST_MAIN; + break; + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +next_data: + ds->br = bre; + ds->block_bytes_avail = block_bytes_avail; + ds->copy_len = copy_len; + ds->copy_pos = copy_pos; + ds->length_header = length_header; + ds->offset_bits = offset_bits; + ds->position_slot = position_slot; + ds->r0 = r0; ds->r1 = r1; ds->r2 = r2; + ds->state = state; + ds->w_pos = w_pos; + strm->avail_out = endp - outp; + return (ARCHIVE_OK); +} + +static int +lzx_read_pre_tree(struct lzx_stream *strm) +{ + struct lzx_dec *ds = strm->ds; + struct lzx_br *br = &(ds->br); + int i; + + if (ds->loop == 0) + memset(ds->pt.freq, 0, sizeof(ds->pt.freq)); + for (i = ds->loop; i < ds->pt.len_size; i++) { + if (!lzx_br_read_ahead(strm, br, 4)) { + ds->loop = i; + return (0); + } + ds->pt.bitlen[i] = lzx_br_bits(br, 4); + ds->pt.freq[ds->pt.bitlen[i]]++; + lzx_br_consume(br, 4); + } + ds->loop = i; + return (1); +} + +/* + * Read a bunch of bit-lengths from pre-tree. + */ +static int +lzx_read_bitlen(struct lzx_stream *strm, struct huffman *d, int end) +{ + struct lzx_dec *ds = strm->ds; + struct lzx_br *br = &(ds->br); + int c, i, j, ret, same; + unsigned rbits; + + i = ds->loop; + if (i == 0) + memset(d->freq, 0, sizeof(d->freq)); + ret = 0; + if (end < 0) + end = d->len_size; + while (i < end) { + ds->loop = i; + if (!lzx_br_read_ahead(strm, br, ds->pt.max_bits)) + goto getdata; + rbits = lzx_br_bits(br, ds->pt.max_bits); + c = lzx_decode_huffman(&(ds->pt), rbits); + switch (c) { + case 17:/* several zero lengths, from 4 to 19. */ + if (!lzx_br_read_ahead(strm, br, ds->pt.bitlen[c]+4)) + goto getdata; + lzx_br_consume(br, ds->pt.bitlen[c]); + same = lzx_br_bits(br, 4) + 4; + if (i + same > end) + return (-1);/* Invalid */ + lzx_br_consume(br, 4); + for (j = 0; j < same; j++) + d->bitlen[i++] = 0; + break; + case 18:/* many zero lengths, from 20 to 51. */ + if (!lzx_br_read_ahead(strm, br, ds->pt.bitlen[c]+5)) + goto getdata; + lzx_br_consume(br, ds->pt.bitlen[c]); + same = lzx_br_bits(br, 5) + 20; + if (i + same > end) + return (-1);/* Invalid */ + lzx_br_consume(br, 5); + memset(d->bitlen + i, 0, same); + i += same; + break; + case 19:/* a few same lengths. */ + if (!lzx_br_read_ahead(strm, br, + ds->pt.bitlen[c]+1+ds->pt.max_bits)) + goto getdata; + lzx_br_consume(br, ds->pt.bitlen[c]); + same = lzx_br_bits(br, 1) + 4; + if (i + same > end) + return (-1); + lzx_br_consume(br, 1); + rbits = lzx_br_bits(br, ds->pt.max_bits); + c = lzx_decode_huffman(&(ds->pt), rbits); + lzx_br_consume(br, ds->pt.bitlen[c]); + c = (d->bitlen[i] - c + 17) % 17; + if (c < 0) + return (-1);/* Invalid */ + for (j = 0; j < same; j++) + d->bitlen[i++] = c; + d->freq[c] += same; + break; + default: + lzx_br_consume(br, ds->pt.bitlen[c]); + c = (d->bitlen[i] - c + 17) % 17; + if (c < 0) + return (-1);/* Invalid */ + d->freq[c]++; + d->bitlen[i++] = c; + break; + } + } + ret = 1; +getdata: + ds->loop = i; + return (ret); +} + +static int +lzx_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits) +{ + int bits; + + if (hf->bitlen == NULL || hf->len_size != (int)len_size) { + free(hf->bitlen); + hf->bitlen = calloc(len_size, sizeof(hf->bitlen[0])); + if (hf->bitlen == NULL) + return (ARCHIVE_FATAL); + hf->len_size = len_size; + } else + memset(hf->bitlen, 0, len_size * sizeof(hf->bitlen[0])); + if (hf->tbl == NULL) { + if (tbl_bits < HTBL_BITS) + bits = tbl_bits; + else + bits = HTBL_BITS; + hf->tbl = malloc((1 << bits) * sizeof(hf->tbl[0])); + if (hf->tbl == NULL) + return (ARCHIVE_FATAL); + hf->tbl_bits = tbl_bits; + } + if (hf->tree == NULL && tbl_bits > HTBL_BITS) { + hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4); + hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0])); + if (hf->tree == NULL) + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static void +lzx_huffman_free(struct huffman *hf) +{ + free(hf->bitlen); + free(hf->tbl); + free(hf->tree); +} + +/* + * Make a huffman coding table. + */ +static int +lzx_make_huffman_table(struct huffman *hf) +{ + uint16_t *tbl; + const unsigned char *bitlen; + int bitptn[17], weight[17]; + int i, maxbits = 0, ptn, tbl_size, w; + int diffbits, len_avail; + + /* + * Initialize bit patterns. + */ + ptn = 0; + for (i = 1, w = 1 << 15; i <= 16; i++, w >>= 1) { + bitptn[i] = ptn; + weight[i] = w; + if (hf->freq[i]) { + ptn += hf->freq[i] * w; + maxbits = i; + } + } + if ((ptn & 0xffff) != 0 || maxbits > hf->tbl_bits) + return (0);/* Invalid */ + + hf->max_bits = maxbits; + + /* + * Cut out extra bits which we won't house in the table. + * This preparation reduces the same calculation in the for-loop + * making the table. + */ + if (maxbits < 16) { + int ebits = 16 - maxbits; + for (i = 1; i <= maxbits; i++) { + bitptn[i] >>= ebits; + weight[i] >>= ebits; + } + } + if (maxbits > HTBL_BITS) { + int htbl_max; + uint16_t *p; + + diffbits = maxbits - HTBL_BITS; + for (i = 1; i <= HTBL_BITS; i++) { + bitptn[i] >>= diffbits; + weight[i] >>= diffbits; + } + htbl_max = bitptn[HTBL_BITS] + + weight[HTBL_BITS] * hf->freq[HTBL_BITS]; + p = &(hf->tbl[htbl_max]); + while (p < &hf->tbl[1U<shift_bits = diffbits; + + /* + * Make the table. + */ + tbl_size = 1 << HTBL_BITS; + tbl = hf->tbl; + bitlen = hf->bitlen; + len_avail = hf->len_size; + hf->tree_used = 0; + for (i = 0; i < len_avail; i++) { + uint16_t *p; + int len, cnt; + uint16_t bit; + int extlen; + struct htree_t *ht; + + if (bitlen[i] == 0) + continue; + /* Get a bit pattern */ + len = bitlen[i]; + ptn = bitptn[len]; + cnt = weight[len]; + if (len <= HTBL_BITS) { + /* Calculate next bit pattern */ + if ((bitptn[len] = ptn + cnt) > tbl_size) + return (0);/* Invalid */ + /* Update the table */ + p = &(tbl[ptn]); + while (--cnt >= 0) + p[cnt] = (uint16_t)i; + continue; + } + + /* + * A bit length is too big to be housed to a direct table, + * so we use a tree model for its extra bits. + */ + bitptn[len] = ptn + cnt; + bit = 1U << (diffbits -1); + extlen = len - HTBL_BITS; + + p = &(tbl[ptn >> diffbits]); + if (*p == 0) { + *p = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + if (*p < len_avail || + *p >= (len_avail + hf->tree_used)) + return (0);/* Invalid */ + ht = &(hf->tree[*p - len_avail]); + } + while (--extlen > 0) { + if (ptn & bit) { + if (ht->left < len_avail) { + ht->left = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->left - len_avail]); + } + } else { + if (ht->right < len_avail) { + ht->right = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->right - len_avail]); + } + } + bit >>= 1; + } + if (ptn & bit) { + if (ht->left != 0) + return (0);/* Invalid */ + ht->left = (uint16_t)i; + } else { + if (ht->right != 0) + return (0);/* Invalid */ + ht->right = (uint16_t)i; + } + } + return (1); +} + +static int +lzx_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c) +{ + struct htree_t *ht; + int extlen; + + ht = hf->tree; + extlen = hf->shift_bits; + while (c >= hf->len_size) { + c -= hf->len_size; + if (extlen-- <= 0 || c >= hf->tree_used) + return (0); + if (rbits & (1U << extlen)) + c = ht[c].left; + else + c = ht[c].right; + } + return (c); +} + +static inline int +lzx_decode_huffman(struct huffman *hf, unsigned rbits) +{ + int c; + /* + * At first search an index table for a bit pattern. + * If it fails, search a huffman tree for. + */ + c = hf->tbl[rbits >> hf->shift_bits]; + if (c < hf->len_size) + return (c); + /* This bit pattern needs to be found out at a huffman tree. */ + return (lzx_decode_huffman_tree(hf, rbits, c)); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c index 1519f34f9..5ae73d770 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_cpio.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2010-2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_cpio.c,v 1.27 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_cpio.c 201163 2009-12-29 05:50:34Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -39,53 +40,127 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_cpio.c,v 1.27 #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_read_private.h" -struct cpio_bin_header { - unsigned char c_magic[2]; - unsigned char c_dev[2]; - unsigned char c_ino[2]; - unsigned char c_mode[2]; - unsigned char c_uid[2]; - unsigned char c_gid[2]; - unsigned char c_nlink[2]; - unsigned char c_rdev[2]; - unsigned char c_mtime[4]; - unsigned char c_namesize[2]; - unsigned char c_filesize[4]; -}; +#define bin_magic_offset 0 +#define bin_magic_size 2 +#define bin_dev_offset 2 +#define bin_dev_size 2 +#define bin_ino_offset 4 +#define bin_ino_size 2 +#define bin_mode_offset 6 +#define bin_mode_size 2 +#define bin_uid_offset 8 +#define bin_uid_size 2 +#define bin_gid_offset 10 +#define bin_gid_size 2 +#define bin_nlink_offset 12 +#define bin_nlink_size 2 +#define bin_rdev_offset 14 +#define bin_rdev_size 2 +#define bin_mtime_offset 16 +#define bin_mtime_size 4 +#define bin_namesize_offset 20 +#define bin_namesize_size 2 +#define bin_filesize_offset 22 +#define bin_filesize_size 4 +#define bin_header_size 26 + +#define odc_magic_offset 0 +#define odc_magic_size 6 +#define odc_dev_offset 6 +#define odc_dev_size 6 +#define odc_ino_offset 12 +#define odc_ino_size 6 +#define odc_mode_offset 18 +#define odc_mode_size 6 +#define odc_uid_offset 24 +#define odc_uid_size 6 +#define odc_gid_offset 30 +#define odc_gid_size 6 +#define odc_nlink_offset 36 +#define odc_nlink_size 6 +#define odc_rdev_offset 42 +#define odc_rdev_size 6 +#define odc_mtime_offset 48 +#define odc_mtime_size 11 +#define odc_namesize_offset 59 +#define odc_namesize_size 6 +#define odc_filesize_offset 65 +#define odc_filesize_size 11 +#define odc_header_size 76 + +#define newc_magic_offset 0 +#define newc_magic_size 6 +#define newc_ino_offset 6 +#define newc_ino_size 8 +#define newc_mode_offset 14 +#define newc_mode_size 8 +#define newc_uid_offset 22 +#define newc_uid_size 8 +#define newc_gid_offset 30 +#define newc_gid_size 8 +#define newc_nlink_offset 38 +#define newc_nlink_size 8 +#define newc_mtime_offset 46 +#define newc_mtime_size 8 +#define newc_filesize_offset 54 +#define newc_filesize_size 8 +#define newc_devmajor_offset 62 +#define newc_devmajor_size 8 +#define newc_devminor_offset 70 +#define newc_devminor_size 8 +#define newc_rdevmajor_offset 78 +#define newc_rdevmajor_size 8 +#define newc_rdevminor_offset 86 +#define newc_rdevminor_size 8 +#define newc_namesize_offset 94 +#define newc_namesize_size 8 +#define newc_checksum_offset 102 +#define newc_checksum_size 8 +#define newc_header_size 110 -struct cpio_odc_header { - char c_magic[6]; - char c_dev[6]; - char c_ino[6]; - char c_mode[6]; - char c_uid[6]; - char c_gid[6]; - char c_nlink[6]; - char c_rdev[6]; - char c_mtime[11]; - char c_namesize[6]; - char c_filesize[11]; -}; +/* + * An afio large ASCII header, which they named itself. + * afio utility uses this header, if a file size is larger than 2G bytes + * or inode/uid/gid is bigger than 65535(0xFFFF) or mtime is bigger than + * 0x7fffffff, which we cannot record to odc header because of its limit. + * If not, uses odc header. + */ +#define afiol_magic_offset 0 +#define afiol_magic_size 6 +#define afiol_dev_offset 6 +#define afiol_dev_size 8 /* hex */ +#define afiol_ino_offset 14 +#define afiol_ino_size 16 /* hex */ +#define afiol_ino_m_offset 30 /* 'm' */ +#define afiol_mode_offset 31 +#define afiol_mode_size 6 /* oct */ +#define afiol_uid_offset 37 +#define afiol_uid_size 8 /* hex */ +#define afiol_gid_offset 45 +#define afiol_gid_size 8 /* hex */ +#define afiol_nlink_offset 53 +#define afiol_nlink_size 8 /* hex */ +#define afiol_rdev_offset 61 +#define afiol_rdev_size 8 /* hex */ +#define afiol_mtime_offset 69 +#define afiol_mtime_size 16 /* hex */ +#define afiol_mtime_n_offset 85 /* 'n' */ +#define afiol_namesize_offset 86 +#define afiol_namesize_size 4 /* hex */ +#define afiol_flag_offset 90 +#define afiol_flag_size 4 /* hex */ +#define afiol_xsize_offset 94 +#define afiol_xsize_size 4 /* hex */ +#define afiol_xsize_s_offset 98 /* 's' */ +#define afiol_filesize_offset 99 +#define afiol_filesize_size 16 /* hex */ +#define afiol_filesize_c_offset 115 /* ':' */ +#define afiol_header_size 116 -struct cpio_newc_header { - char c_magic[6]; - char c_ino[8]; - char c_mode[8]; - char c_uid[8]; - char c_gid[8]; - char c_nlink[8]; - char c_mtime[8]; - char c_filesize[8]; - char c_devmajor[8]; - char c_devminor[8]; - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; - char c_crc[8]; -}; struct links_entry { struct links_entry *next; @@ -96,220 +171,325 @@ struct links_entry { char *name; }; -#define CPIO_MAGIC 0x13141516 +#define CPIO_MAGIC 0x13141516 struct cpio { - int magic; - int (*read_header)(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); - struct links_entry *links_head; - struct archive_string entry_name; - struct archive_string entry_linkname; - off_t entry_bytes_remaining; - off_t entry_offset; - off_t entry_padding; + int magic; + int (*read_header)(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); + struct links_entry *links_head; + int64_t entry_bytes_remaining; + int64_t entry_bytes_unconsumed; + int64_t entry_offset; + int64_t entry_padding; + + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; }; -static int64_t atol16(const char *, unsigned); -static int64_t atol8(const char *, unsigned); -static int archive_read_format_cpio_bid(struct archive_read *); -static int archive_read_format_cpio_cleanup(struct archive_read *); -static int archive_read_format_cpio_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_cpio_read_header(struct archive_read *, - struct archive_entry *); -static int be4(const unsigned char *); -static int find_odc_header(struct archive_read *); -static int find_newc_header(struct archive_read *); -static int header_bin_be(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_bin_le(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_newc(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int header_odc(struct archive_read *, struct cpio *, - struct archive_entry *, size_t *, size_t *); -static int is_octal(const char *, size_t); -static int is_hex(const char *, size_t); -static int le4(const unsigned char *); -static void record_hardlink(struct cpio *cpio, struct archive_entry *entry); +static int64_t atol16(const char *, unsigned); +static int64_t atol8(const char *, unsigned); +static int archive_read_format_cpio_bid(struct archive_read *, int); +static int archive_read_format_cpio_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_cpio_cleanup(struct archive_read *); +static int archive_read_format_cpio_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_cpio_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_cpio_skip(struct archive_read *); +static int be4(const unsigned char *); +static int find_odc_header(struct archive_read *); +static int find_newc_header(struct archive_read *); +static int header_bin_be(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_bin_le(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_newc(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_odc(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int header_afiol(struct archive_read *, struct cpio *, + struct archive_entry *, size_t *, size_t *); +static int is_octal(const char *, size_t); +static int is_hex(const char *, size_t); +static int le4(const unsigned char *); +static int record_hardlink(struct archive_read *a, + struct cpio *cpio, struct archive_entry *entry); int archive_read_support_format_cpio(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - struct cpio *cpio; - int r; - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - cpio->magic = CPIO_MAGIC; - - r = __archive_read_register_format(a, - cpio, - "cpio", - archive_read_format_cpio_bid, - NULL, - archive_read_format_cpio_read_header, - archive_read_format_cpio_read_data, - NULL, - archive_read_format_cpio_cleanup); - - if (r != ARCHIVE_OK) - free(cpio); - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + struct cpio *cpio; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_cpio"); + + cpio = (struct cpio *)calloc(1, sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + cpio->magic = CPIO_MAGIC; + + r = __archive_read_register_format(a, + cpio, + "cpio", + archive_read_format_cpio_bid, + archive_read_format_cpio_options, + archive_read_format_cpio_read_header, + archive_read_format_cpio_read_data, + archive_read_format_cpio_skip, + archive_read_format_cpio_cleanup); + + if (r != ARCHIVE_OK) + free(cpio); + return (ARCHIVE_OK); } static int -archive_read_format_cpio_bid(struct archive_read *a) +archive_read_format_cpio_bid(struct archive_read *a, int best_bid) { - const void *h; - const unsigned char *p; - struct cpio *cpio; - int bid; - - cpio = (struct cpio *)(a->format->data); - - if ((h = __archive_read_ahead(a, 6, NULL)) == NULL) - return (-1); - - p = (const unsigned char *)h; - bid = 0; - if (memcmp(p, "070707", 6) == 0) { - /* ASCII cpio archive (odc, POSIX.1) */ - cpio->read_header = header_odc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only octal - * digits appear in appropriate header locations. XXX - */ - } else if (memcmp(p, "070701", 6) == 0) { - /* ASCII cpio archive (SVR4 without CRC) */ - cpio->read_header = header_newc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only hex - * digits appear in appropriate header locations. XXX - */ - } else if (memcmp(p, "070702", 6) == 0) { - /* ASCII cpio archive (SVR4 with CRC) */ - /* XXX TODO: Flag that we should check the CRC. XXX */ - cpio->read_header = header_newc; - bid += 48; - /* - * XXX TODO: More verification; Could check that only hex - * digits appear in appropriate header locations. XXX - */ - } else if (p[0] * 256 + p[1] == 070707) { - /* big-endian binary cpio archives */ - cpio->read_header = header_bin_be; - bid += 16; - /* Is more verification possible here? */ - } else if (p[0] + p[1] * 256 == 070707) { - /* little-endian binary cpio archives */ - cpio->read_header = header_bin_le; - bid += 16; - /* Is more verification possible here? */ - } else - return (ARCHIVE_WARN); - - return (bid); + const unsigned char *p; + struct cpio *cpio; + int bid; + + (void)best_bid; /* UNUSED */ + + cpio = (struct cpio *)(a->format->data); + + if ((p = __archive_read_ahead(a, 6, NULL)) == NULL) + return (-1); + + bid = 0; + if (memcmp(p, "070707", 6) == 0) { + /* ASCII cpio archive (odc, POSIX.1) */ + cpio->read_header = header_odc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only octal + * digits appear in appropriate header locations. XXX + */ + } else if (memcmp(p, "070727", 6) == 0) { + /* afio large ASCII cpio archive */ + cpio->read_header = header_odc; + bid += 48; + /* + * XXX TODO: More verification; Could check that almost hex + * digits appear in appropriate header locations. XXX + */ + } else if (memcmp(p, "070701", 6) == 0) { + /* ASCII cpio archive (SVR4 without CRC) */ + cpio->read_header = header_newc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only hex + * digits appear in appropriate header locations. XXX + */ + } else if (memcmp(p, "070702", 6) == 0) { + /* ASCII cpio archive (SVR4 with CRC) */ + /* XXX TODO: Flag that we should check the CRC. XXX */ + cpio->read_header = header_newc; + bid += 48; + /* + * XXX TODO: More verification; Could check that only hex + * digits appear in appropriate header locations. XXX + */ + } else if (p[0] * 256 + p[1] == 070707) { + /* big-endian binary cpio archives */ + cpio->read_header = header_bin_be; + bid += 16; + /* Is more verification possible here? */ + } else if (p[0] + p[1] * 256 == 070707) { + /* little-endian binary cpio archives */ + cpio->read_header = header_bin_le; + bid += 16; + /* Is more verification possible here? */ + } else + return (ARCHIVE_WARN); + + return (bid); +} + +static int +archive_read_format_cpio_options(struct archive_read *a, + const char *key, const char *val) +{ + struct cpio *cpio; + int ret = ARCHIVE_FAILED; + + cpio = (struct cpio *)(a->format->data); + if (strcmp(key, "compat-2x") == 0) { + /* Handle filnames as libarchive 2.x */ + cpio->init_default_conversion = (val != NULL)?1:0; + ret = ARCHIVE_OK; + } else if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "cpio: hdrcharset option needs a character-set name"); + else { + cpio->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (cpio->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "cpio: unknown keyword ``%s''", key); + + return (ret); } static int archive_read_format_cpio_read_header(struct archive_read *a, struct archive_entry *entry) { - struct cpio *cpio; - const void *h; - size_t namelength; - size_t name_pad; - int r; - - cpio = (struct cpio *)(a->format->data); - r = (cpio->read_header(a, cpio, entry, &namelength, &name_pad)); - - if (r < ARCHIVE_WARN) - return (r); - - /* Read name from buffer. */ - h = __archive_read_ahead(a, namelength + name_pad, NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, namelength + name_pad); - archive_strncpy(&cpio->entry_name, (const char *)h, namelength); - archive_entry_set_pathname(entry, cpio->entry_name.s); - cpio->entry_offset = 0; - - /* If this is a symlink, read the link contents. */ - if (archive_entry_filetype(entry) == AE_IFLNK) { - h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, cpio->entry_bytes_remaining); - archive_strncpy(&cpio->entry_linkname, (const char *)h, - cpio->entry_bytes_remaining); - archive_entry_set_symlink(entry, cpio->entry_linkname.s); - cpio->entry_bytes_remaining = 0; - } - - /* XXX TODO: If the full mode is 0160200, then this is a Solaris - * ACL description for the following entry. Read this body - * and parse it as a Solaris-style ACL, then read the next - * header. XXX */ - - /* Compare name to "TRAILER!!!" to test for end-of-archive. */ - if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { - /* TODO: Store file location of start of block. */ - archive_set_error(&a->archive, 0, NULL); - return (ARCHIVE_EOF); - } - - /* Detect and record hardlinks to previously-extracted entries. */ - record_hardlink(cpio, entry); - - return (r); + struct cpio *cpio; + const void *h; + struct archive_string_conv *sconv; + size_t namelength; + size_t name_pad; + int r; + + cpio = (struct cpio *)(a->format->data); + sconv = cpio->opt_sconv; + if (sconv == NULL) { + if (!cpio->init_default_conversion) { + cpio->sconv_default = + archive_string_default_conversion_for_read( + &(a->archive)); + cpio->init_default_conversion = 1; + } + sconv = cpio->sconv_default; + } + + r = (cpio->read_header(a, cpio, entry, &namelength, &name_pad)); + + if (r < ARCHIVE_WARN) + return (r); + + /* Read name from buffer. */ + h = __archive_read_ahead(a, namelength + name_pad, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + if (archive_entry_copy_pathname_l(entry, + (const char *)h, namelength, sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname can't be converted from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + r = ARCHIVE_WARN; + } + cpio->entry_offset = 0; + + __archive_read_consume(a, namelength + name_pad); + + /* If this is a symlink, read the link contents. */ + if (archive_entry_filetype(entry) == AE_IFLNK) { + h = __archive_read_ahead(a, cpio->entry_bytes_remaining, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + if (archive_entry_copy_symlink_l(entry, (const char *)h, + cpio->entry_bytes_remaining, sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname can't be converted from %s to " + "current locale.", + archive_string_conversion_charset_name(sconv)); + r = ARCHIVE_WARN; + } + __archive_read_consume(a, cpio->entry_bytes_remaining); + cpio->entry_bytes_remaining = 0; + } + + /* XXX TODO: If the full mode is 0160200, then this is a Solaris + * ACL description for the following entry. Read this body + * and parse it as a Solaris-style ACL, then read the next + * header. XXX */ + + /* Compare name to "TRAILER!!!" to test for end-of-archive. */ + if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { + /* TODO: Store file location of start of block. */ + archive_clear_error(&a->archive); + return (ARCHIVE_EOF); + } + + /* Detect and record hardlinks to previously-extracted entries. */ + if (record_hardlink(a, cpio, entry) != ARCHIVE_OK) { + return (ARCHIVE_FATAL); + } + + return (r); } static int archive_read_format_cpio_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - ssize_t bytes_read; - struct cpio *cpio; - - cpio = (struct cpio *)(a->format->data); - if (cpio->entry_bytes_remaining > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > cpio->entry_bytes_remaining) - bytes_read = cpio->entry_bytes_remaining; - *size = bytes_read; - *offset = cpio->entry_offset; - cpio->entry_offset += bytes_read; - cpio->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); - } else { - while (cpio->entry_padding > 0) { - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - if (bytes_read > cpio->entry_padding) - bytes_read = cpio->entry_padding; - __archive_read_consume(a, bytes_read); - cpio->entry_padding -= bytes_read; - } - *buff = NULL; - *size = 0; - *offset = cpio->entry_offset; - return (ARCHIVE_EOF); - } + ssize_t bytes_read; + struct cpio *cpio; + + cpio = (struct cpio *)(a->format->data); + + if (cpio->entry_bytes_unconsumed) { + __archive_read_consume(a, cpio->entry_bytes_unconsumed); + cpio->entry_bytes_unconsumed = 0; + } + + if (cpio->entry_bytes_remaining > 0) { + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + if (bytes_read > cpio->entry_bytes_remaining) + bytes_read = cpio->entry_bytes_remaining; + *size = bytes_read; + cpio->entry_bytes_unconsumed = bytes_read; + *offset = cpio->entry_offset; + cpio->entry_offset += bytes_read; + cpio->entry_bytes_remaining -= bytes_read; + return (ARCHIVE_OK); + } else { + if (cpio->entry_padding != + __archive_read_consume(a, cpio->entry_padding)) { + return (ARCHIVE_FATAL); + } + cpio->entry_padding = 0; + *buff = NULL; + *size = 0; + *offset = cpio->entry_offset; + return (ARCHIVE_EOF); + } +} + +static int +archive_read_format_cpio_skip(struct archive_read *a) +{ + struct cpio *cpio = (struct cpio *)(a->format->data); + int64_t to_skip = cpio->entry_bytes_remaining + cpio->entry_padding + + cpio->entry_bytes_unconsumed; + + if (to_skip != __archive_read_consume(a, to_skip)) { + return (ARCHIVE_FATAL); + } + cpio->entry_bytes_remaining = 0; + cpio->entry_padding = 0; + cpio->entry_bytes_unconsumed = 0; + return (ARCHIVE_OK); } /* @@ -320,133 +500,133 @@ archive_read_format_cpio_read_data(struct archive_read *a, static int is_hex(const char *p, size_t len) { - while (len-- > 0) { - if ((*p >= '0' && *p <= '9') - || (*p >= 'a' && *p <= 'f') - || (*p >= 'A' && *p <= 'F')) - ++p; - else - return (0); - } - return (1); + while (len-- > 0) { + if ((*p >= '0' && *p <= '9') + || (*p >= 'a' && *p <= 'f') + || (*p >= 'A' && *p <= 'F')) + ++p; + else + return (0); + } + return (1); } static int find_newc_header(struct archive_read *a) { - const void *h; - const char *p, *q; - size_t skip, skipped = 0; - ssize_t bytes; - - for (;;) { - h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* Try the typical case first, then go into the slow search.*/ - if (memcmp("07070", p, 5) == 0 - && (p[5] == '1' || p[5] == '2') - && is_hex(p, sizeof(struct cpio_newc_header))) - return (ARCHIVE_OK); - - /* - * Scan ahead until we find something that looks - * like an odc header. - */ - while (p + sizeof(struct cpio_newc_header) < q) { - switch (p[5]) { - case '1': - case '2': - if (memcmp("07070", p, 5) == 0 - && is_hex(p, sizeof(struct cpio_newc_header))) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - if (skipped > 0) { - archive_set_error(&a->archive, - 0, - "Skipped %d bytes before " - "finding valid header", - (int)skipped); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); - } - p += 2; - break; - case '0': - p++; - break; - default: - p += 6; - break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - } + const void *h; + const char *p, *q; + size_t skip, skipped = 0; + ssize_t bytes; + + for (;;) { + h = __archive_read_ahead(a, newc_header_size, &bytes); + if (h == NULL) + return (ARCHIVE_FATAL); + p = h; + q = p + bytes; + + /* Try the typical case first, then go into the slow search.*/ + if (memcmp("07070", p, 5) == 0 + && (p[5] == '1' || p[5] == '2') + && is_hex(p, newc_header_size)) + return (ARCHIVE_OK); + + /* + * Scan ahead until we find something that looks + * like a newc header. + */ + while (p + newc_header_size <= q) { + switch (p[5]) { + case '1': + case '2': + if (memcmp("07070", p, 5) == 0 + && is_hex(p, newc_header_size)) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + if (skipped > 0) { + archive_set_error(&a->archive, + 0, + "Skipped %d bytes before " + "finding valid header", + (int)skipped); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); + } + p += 2; + break; + case '0': + p++; + break; + default: + p += 6; + break; + } + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + } } static int header_newc(struct archive_read *a, struct cpio *cpio, struct archive_entry *entry, size_t *namelength, size_t *name_pad) { - const void *h; - const struct cpio_newc_header *header; - int r; - - r = find_newc_header(a); - if (r < ARCHIVE_WARN) - return (r); - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_newc_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_newc_header)); - - /* Parse out hex fields. */ - header = (const struct cpio_newc_header *)h; - - if (memcmp(header->c_magic, "070701", 6) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; - a->archive.archive_format_name = "ASCII cpio (SVR4 with no CRC)"; - } else if (memcmp(header->c_magic, "070702", 6) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_CRC; - a->archive.archive_format_name = "ASCII cpio (SVR4 with CRC)"; - } else { - /* TODO: Abort here? */ - } - - archive_entry_set_devmajor(entry, atol16(header->c_devmajor, sizeof(header->c_devmajor))); - archive_entry_set_devminor(entry, atol16(header->c_devminor, sizeof(header->c_devminor))); - archive_entry_set_ino(entry, atol16(header->c_ino, sizeof(header->c_ino))); - archive_entry_set_mode(entry, atol16(header->c_mode, sizeof(header->c_mode))); - archive_entry_set_uid(entry, atol16(header->c_uid, sizeof(header->c_uid))); - archive_entry_set_gid(entry, atol16(header->c_gid, sizeof(header->c_gid))); - archive_entry_set_nlink(entry, atol16(header->c_nlink, sizeof(header->c_nlink))); - archive_entry_set_rdevmajor(entry, atol16(header->c_rdevmajor, sizeof(header->c_rdevmajor))); - archive_entry_set_rdevminor(entry, atol16(header->c_rdevminor, sizeof(header->c_rdevminor))); - archive_entry_set_mtime(entry, atol16(header->c_mtime, sizeof(header->c_mtime)), 0); - *namelength = atol16(header->c_namesize, sizeof(header->c_namesize)); - /* Pad name to 2 more than a multiple of 4. */ - *name_pad = (2 - *namelength) & 3; - - /* - * Note: entry_bytes_remaining is at least 64 bits and - * therefore guaranteed to be big enough for a 33-bit file - * size. - */ - cpio->entry_bytes_remaining = - atol16(header->c_filesize, sizeof(header->c_filesize)); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - /* Pad file contents to a multiple of 4. */ - cpio->entry_padding = 3 & -cpio->entry_bytes_remaining; - return (r); + const void *h; + const char *header; + int r; + + r = find_newc_header(a); + if (r < ARCHIVE_WARN) + return (r); + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, newc_header_size, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Parse out hex fields. */ + header = (const char *)h; + + if (memcmp(header + newc_magic_offset, "070701", 6) == 0) { + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; + a->archive.archive_format_name = "ASCII cpio (SVR4 with no CRC)"; + } else if (memcmp(header + newc_magic_offset, "070702", 6) == 0) { + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_CRC; + a->archive.archive_format_name = "ASCII cpio (SVR4 with CRC)"; + } else { + /* TODO: Abort here? */ + } + + archive_entry_set_devmajor(entry, atol16(header + newc_devmajor_offset, newc_devmajor_size)); + archive_entry_set_devminor(entry, atol16(header + newc_devminor_offset, newc_devminor_size)); + archive_entry_set_ino(entry, atol16(header + newc_ino_offset, newc_ino_size)); + archive_entry_set_mode(entry, atol16(header + newc_mode_offset, newc_mode_size)); + archive_entry_set_uid(entry, atol16(header + newc_uid_offset, newc_uid_size)); + archive_entry_set_gid(entry, atol16(header + newc_gid_offset, newc_gid_size)); + archive_entry_set_nlink(entry, atol16(header + newc_nlink_offset, newc_nlink_size)); + archive_entry_set_rdevmajor(entry, atol16(header + newc_rdevmajor_offset, newc_rdevmajor_size)); + archive_entry_set_rdevminor(entry, atol16(header + newc_rdevminor_offset, newc_rdevminor_size)); + archive_entry_set_mtime(entry, atol16(header + newc_mtime_offset, newc_mtime_size), 0); + *namelength = atol16(header + newc_namesize_offset, newc_namesize_size); + /* Pad name to 2 more than a multiple of 4. */ + *name_pad = (2 - *namelength) & 3; + + /* + * Note: entry_bytes_remaining is at least 64 bits and + * therefore guaranteed to be big enough for a 33-bit file + * size. + */ + cpio->entry_bytes_remaining = + atol16(header + newc_filesize_offset, newc_filesize_size); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + /* Pad file contents to a multiple of 4. */ + cpio->entry_padding = 3 & -cpio->entry_bytes_remaining; + __archive_read_consume(a, newc_header_size); + return (r); } /* @@ -458,197 +638,280 @@ header_newc(struct archive_read *a, struct cpio *cpio, static int is_octal(const char *p, size_t len) { - while (len-- > 0) { - if (*p < '0' || *p > '7') - return (0); - ++p; - } - return (1); + while (len-- > 0) { + if (*p < '0' || *p > '7') + return (0); + ++p; + } + return (1); +} + +static int +is_afio_large(const char *h, size_t len) +{ + if (len < afiol_header_size) + return (0); + if (h[afiol_ino_m_offset] != 'm' + || h[afiol_mtime_n_offset] != 'n' + || h[afiol_xsize_s_offset] != 's' + || h[afiol_filesize_c_offset] != ':') + return (0); + if (!is_hex(h + afiol_dev_offset, afiol_ino_m_offset - afiol_dev_offset)) + return (0); + if (!is_hex(h + afiol_mode_offset, afiol_mtime_n_offset - afiol_mode_offset)) + return (0); + if (!is_hex(h + afiol_namesize_offset, afiol_xsize_s_offset - afiol_namesize_offset)) + return (0); + if (!is_hex(h + afiol_filesize_offset, afiol_filesize_size)) + return (0); + return (1); } static int find_odc_header(struct archive_read *a) { - const void *h; - const char *p, *q; - size_t skip, skipped = 0; - ssize_t bytes; - - for (;;) { - h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), &bytes); - if (h == NULL) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* Try the typical case first, then go into the slow search.*/ - if (memcmp("070707", p, 6) == 0 - && is_octal(p, sizeof(struct cpio_odc_header))) - return (ARCHIVE_OK); - - /* - * Scan ahead until we find something that looks - * like an odc header. - */ - while (p + sizeof(struct cpio_odc_header) < q) { - switch (p[5]) { - case '7': - if (memcmp("070707", p, 6) == 0 - && is_octal(p, sizeof(struct cpio_odc_header))) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - if (skipped > 0) { - archive_set_error(&a->archive, - 0, - "Skipped %d bytes before " - "finding valid header", - (int)skipped); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); - } - p += 2; - break; - case '0': - p++; - break; - default: - p += 6; - break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - skipped += skip; - } + const void *h; + const char *p, *q; + size_t skip, skipped = 0; + ssize_t bytes; + + for (;;) { + h = __archive_read_ahead(a, odc_header_size, &bytes); + if (h == NULL) + return (ARCHIVE_FATAL); + p = h; + q = p + bytes; + + /* Try the typical case first, then go into the slow search.*/ + if (memcmp("070707", p, 6) == 0 && is_octal(p, odc_header_size)) + return (ARCHIVE_OK); + if (memcmp("070727", p, 6) == 0 && is_afio_large(p, bytes)) { + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_AFIO_LARGE; + return (ARCHIVE_OK); + } + + /* + * Scan ahead until we find something that looks + * like an odc header. + */ + while (p + odc_header_size <= q) { + switch (p[5]) { + case '7': + if ((memcmp("070707", p, 6) == 0 + && is_octal(p, odc_header_size)) + || (memcmp("070727", p, 6) == 0 + && is_afio_large(p, q - p))) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + if (p[4] == '2') + a->archive.archive_format = + ARCHIVE_FORMAT_CPIO_AFIO_LARGE; + if (skipped > 0) { + archive_set_error(&a->archive, + 0, + "Skipped %d bytes before " + "finding valid header", + (int)skipped); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); + } + p += 2; + break; + case '0': + p++; + break; + default: + p += 6; + break; + } + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + skipped += skip; + } } static int header_odc(struct archive_read *a, struct cpio *cpio, struct archive_entry *entry, size_t *namelength, size_t *name_pad) { - const void *h; - int r; - const struct cpio_odc_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; - a->archive.archive_format_name = "POSIX octet-oriented cpio"; - - /* Find the start of the next header. */ - r = find_odc_header(a); - if (r < ARCHIVE_WARN) - return (r); - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_odc_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_odc_header)); - - /* Parse out octal fields. */ - header = (const struct cpio_odc_header *)h; - - archive_entry_set_dev(entry, atol8(header->c_dev, sizeof(header->c_dev))); - archive_entry_set_ino(entry, atol8(header->c_ino, sizeof(header->c_ino))); - archive_entry_set_mode(entry, atol8(header->c_mode, sizeof(header->c_mode))); - archive_entry_set_uid(entry, atol8(header->c_uid, sizeof(header->c_uid))); - archive_entry_set_gid(entry, atol8(header->c_gid, sizeof(header->c_gid))); - archive_entry_set_nlink(entry, atol8(header->c_nlink, sizeof(header->c_nlink))); - archive_entry_set_rdev(entry, atol8(header->c_rdev, sizeof(header->c_rdev))); - archive_entry_set_mtime(entry, atol8(header->c_mtime, sizeof(header->c_mtime)), 0); - *namelength = atol8(header->c_namesize, sizeof(header->c_namesize)); - *name_pad = 0; /* No padding of filename. */ - - /* - * Note: entry_bytes_remaining is at least 64 bits and - * therefore guaranteed to be big enough for a 33-bit file - * size. - */ - cpio->entry_bytes_remaining = - atol8(header->c_filesize, sizeof(header->c_filesize)); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = 0; - return (r); + const void *h; + int r; + const char *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; + a->archive.archive_format_name = "POSIX octet-oriented cpio"; + + /* Find the start of the next header. */ + r = find_odc_header(a); + if (r < ARCHIVE_WARN) + return (r); + + if (a->archive.archive_format == ARCHIVE_FORMAT_CPIO_AFIO_LARGE) { + int r2 = (header_afiol(a, cpio, entry, namelength, name_pad)); + if (r2 == ARCHIVE_OK) + return (r); + else + return (r2); + } + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, odc_header_size, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Parse out octal fields. */ + header = (const char *)h; + + archive_entry_set_dev(entry, atol8(header + odc_dev_offset, odc_dev_size)); + archive_entry_set_ino(entry, atol8(header + odc_ino_offset, odc_ino_size)); + archive_entry_set_mode(entry, atol8(header + odc_mode_offset, odc_mode_size)); + archive_entry_set_uid(entry, atol8(header + odc_uid_offset, odc_uid_size)); + archive_entry_set_gid(entry, atol8(header + odc_gid_offset, odc_gid_size)); + archive_entry_set_nlink(entry, atol8(header + odc_nlink_offset, odc_nlink_size)); + archive_entry_set_rdev(entry, atol8(header + odc_rdev_offset, odc_rdev_size)); + archive_entry_set_mtime(entry, atol8(header + odc_mtime_offset, odc_mtime_size), 0); + *namelength = atol8(header + odc_namesize_offset, odc_namesize_size); + *name_pad = 0; /* No padding of filename. */ + + /* + * Note: entry_bytes_remaining is at least 64 bits and + * therefore guaranteed to be big enough for a 33-bit file + * size. + */ + cpio->entry_bytes_remaining = + atol8(header + odc_filesize_offset, odc_filesize_size); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = 0; + __archive_read_consume(a, odc_header_size); + return (r); } +/* + * NOTE: if a filename suffix is ".z", it is the file gziped by afio. + * it would be nice that we can show uncompressed file size and we can + * uncompressed file contents automatically, unfortunately we have nothing + * to get a uncompressed file size while reading each header. it means + * we also cannot uncompressed file contens under the our framework. + */ +static int +header_afiol(struct archive_read *a, struct cpio *cpio, + struct archive_entry *entry, size_t *namelength, size_t *name_pad) +{ + const void *h; + const char *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_AFIO_LARGE; + a->archive.archive_format_name = "afio large ASCII"; + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, afiol_header_size, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Parse out octal fields. */ + header = (const char *)h; + + archive_entry_set_dev(entry, atol16(header + afiol_dev_offset, afiol_dev_size)); + archive_entry_set_ino(entry, atol16(header + afiol_ino_offset, afiol_ino_size)); + archive_entry_set_mode(entry, atol8(header + afiol_mode_offset, afiol_mode_size)); + archive_entry_set_uid(entry, atol16(header + afiol_uid_offset, afiol_uid_size)); + archive_entry_set_gid(entry, atol16(header + afiol_gid_offset, afiol_gid_size)); + archive_entry_set_nlink(entry, atol16(header + afiol_nlink_offset, afiol_nlink_size)); + archive_entry_set_rdev(entry, atol16(header + afiol_rdev_offset, afiol_rdev_size)); + archive_entry_set_mtime(entry, atol16(header + afiol_mtime_offset, afiol_mtime_size), 0); + *namelength = atol16(header + afiol_namesize_offset, afiol_namesize_size); + *name_pad = 0; /* No padding of filename. */ + + cpio->entry_bytes_remaining = + atol16(header + afiol_filesize_offset, afiol_filesize_size); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = 0; + __archive_read_consume(a, afiol_header_size); + return (ARCHIVE_OK); +} + + static int header_bin_le(struct archive_read *a, struct cpio *cpio, struct archive_entry *entry, size_t *namelength, size_t *name_pad) { - const void *h; - const struct cpio_bin_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE; - a->archive.archive_format_name = "cpio (little-endian binary)"; - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_bin_header)); - - /* Parse out binary fields. */ - header = (const struct cpio_bin_header *)h; - - archive_entry_set_dev(entry, header->c_dev[0] + header->c_dev[1] * 256); - archive_entry_set_ino(entry, header->c_ino[0] + header->c_ino[1] * 256); - archive_entry_set_mode(entry, header->c_mode[0] + header->c_mode[1] * 256); - archive_entry_set_uid(entry, header->c_uid[0] + header->c_uid[1] * 256); - archive_entry_set_gid(entry, header->c_gid[0] + header->c_gid[1] * 256); - archive_entry_set_nlink(entry, header->c_nlink[0] + header->c_nlink[1] * 256); - archive_entry_set_rdev(entry, header->c_rdev[0] + header->c_rdev[1] * 256); - archive_entry_set_mtime(entry, le4(header->c_mtime), 0); - *namelength = header->c_namesize[0] + header->c_namesize[1] * 256; - *name_pad = *namelength & 1; /* Pad to even. */ - - cpio->entry_bytes_remaining = le4(header->c_filesize); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ - return (ARCHIVE_OK); + const void *h; + const unsigned char *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_LE; + a->archive.archive_format_name = "cpio (little-endian binary)"; + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, bin_header_size, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Parse out binary fields. */ + header = (const unsigned char *)h; + + archive_entry_set_dev(entry, header[bin_dev_offset] + header[bin_dev_offset + 1] * 256); + archive_entry_set_ino(entry, header[bin_ino_offset] + header[bin_ino_offset + 1] * 256); + archive_entry_set_mode(entry, header[bin_mode_offset] + header[bin_mode_offset + 1] * 256); + archive_entry_set_uid(entry, header[bin_uid_offset] + header[bin_uid_offset + 1] * 256); + archive_entry_set_gid(entry, header[bin_gid_offset] + header[bin_gid_offset + 1] * 256); + archive_entry_set_nlink(entry, header[bin_nlink_offset] + header[bin_nlink_offset + 1] * 256); + archive_entry_set_rdev(entry, header[bin_rdev_offset] + header[bin_rdev_offset + 1] * 256); + archive_entry_set_mtime(entry, le4(header + bin_mtime_offset), 0); + *namelength = header[bin_namesize_offset] + header[bin_namesize_offset + 1] * 256; + *name_pad = *namelength & 1; /* Pad to even. */ + + cpio->entry_bytes_remaining = le4(header + bin_filesize_offset); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ + __archive_read_consume(a, bin_header_size); + return (ARCHIVE_OK); } static int header_bin_be(struct archive_read *a, struct cpio *cpio, struct archive_entry *entry, size_t *namelength, size_t *name_pad) { - const void *h; - const struct cpio_bin_header *header; - - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE; - a->archive.archive_format_name = "cpio (big-endian binary)"; - - /* Read fixed-size portion of header. */ - h = __archive_read_ahead(a, sizeof(struct cpio_bin_header), NULL); - if (h == NULL) - return (ARCHIVE_FATAL); - __archive_read_consume(a, sizeof(struct cpio_bin_header)); - - /* Parse out binary fields. */ - header = (const struct cpio_bin_header *)h; - archive_entry_set_dev(entry, header->c_dev[0] * 256 + header->c_dev[1]); - archive_entry_set_ino(entry, header->c_ino[0] * 256 + header->c_ino[1]); - archive_entry_set_mode(entry, header->c_mode[0] * 256 + header->c_mode[1]); - archive_entry_set_uid(entry, header->c_uid[0] * 256 + header->c_uid[1]); - archive_entry_set_gid(entry, header->c_gid[0] * 256 + header->c_gid[1]); - archive_entry_set_nlink(entry, header->c_nlink[0] * 256 + header->c_nlink[1]); - archive_entry_set_rdev(entry, header->c_rdev[0] * 256 + header->c_rdev[1]); - archive_entry_set_mtime(entry, be4(header->c_mtime), 0); - *namelength = header->c_namesize[0] * 256 + header->c_namesize[1]; - *name_pad = *namelength & 1; /* Pad to even. */ - - cpio->entry_bytes_remaining = be4(header->c_filesize); - archive_entry_set_size(entry, cpio->entry_bytes_remaining); - cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ - return (ARCHIVE_OK); + const void *h; + const unsigned char *header; + + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_BIN_BE; + a->archive.archive_format_name = "cpio (big-endian binary)"; + + /* Read fixed-size portion of header. */ + h = __archive_read_ahead(a, bin_header_size, NULL); + if (h == NULL) + return (ARCHIVE_FATAL); + + /* Parse out binary fields. */ + header = (const unsigned char *)h; + + archive_entry_set_dev(entry, header[bin_dev_offset] * 256 + header[bin_dev_offset + 1]); + archive_entry_set_ino(entry, header[bin_ino_offset] * 256 + header[bin_ino_offset + 1]); + archive_entry_set_mode(entry, header[bin_mode_offset] * 256 + header[bin_mode_offset + 1]); + archive_entry_set_uid(entry, header[bin_uid_offset] * 256 + header[bin_uid_offset + 1]); + archive_entry_set_gid(entry, header[bin_gid_offset] * 256 + header[bin_gid_offset + 1]); + archive_entry_set_nlink(entry, header[bin_nlink_offset] * 256 + header[bin_nlink_offset + 1]); + archive_entry_set_rdev(entry, header[bin_rdev_offset] * 256 + header[bin_rdev_offset + 1]); + archive_entry_set_mtime(entry, be4(header + bin_mtime_offset), 0); + *namelength = header[bin_namesize_offset] * 256 + header[bin_namesize_offset + 1]; + *name_pad = *namelength & 1; /* Pad to even. */ + + cpio->entry_bytes_remaining = be4(header + bin_filesize_offset); + archive_entry_set_size(entry, cpio->entry_bytes_remaining); + cpio->entry_padding = cpio->entry_bytes_remaining & 1; /* Pad to even. */ + __archive_read_consume(a, bin_header_size); + return (ARCHIVE_OK); } static int archive_read_format_cpio_cleanup(struct archive_read *a) { - struct cpio *cpio; + struct cpio *cpio; - cpio = (struct cpio *)(a->format->data); + cpio = (struct cpio *)(a->format->data); /* Free inode->name map */ while (cpio->links_head != NULL) { struct links_entry *lp = cpio->links_head->next; @@ -658,23 +921,22 @@ archive_read_format_cpio_cleanup(struct archive_read *a) free(cpio->links_head); cpio->links_head = lp; } - archive_string_free(&cpio->entry_name); - free(cpio); - (a->format->data) = NULL; - return (ARCHIVE_OK); + free(cpio); + (a->format->data) = NULL; + return (ARCHIVE_OK); } static int le4(const unsigned char *p) { - return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8)); + return ((p[0]<<16) + (p[1]<<24) + (p[2]<<0) + (p[3]<<8)); } static int be4(const unsigned char *p) { - return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3])); + return ((p[0]<<24) + (p[1]<<16) + (p[2]<<8) + (p[3])); } /* @@ -685,90 +947,102 @@ be4(const unsigned char *p) static int64_t atol8(const char *p, unsigned char_cnt) { - int64_t l; - int digit; - - l = 0; - while (char_cnt-- > 0) { - if (*p >= '0' && *p <= '7') - digit = *p - '0'; - else - return (l); - p++; - l <<= 3; - l |= digit; - } - return (l); + int64_t l; + int digit; + + l = 0; + while (char_cnt-- > 0) { + if (*p >= '0' && *p <= '7') + digit = *p - '0'; + else + return (l); + p++; + l <<= 3; + l |= digit; + } + return (l); } static int64_t atol16(const char *p, unsigned char_cnt) { - int64_t l; - int digit; - - l = 0; - while (char_cnt-- > 0) { - if (*p >= 'a' && *p <= 'f') - digit = *p - 'a' + 10; - else if (*p >= 'A' && *p <= 'F') - digit = *p - 'A' + 10; - else if (*p >= '0' && *p <= '9') - digit = *p - '0'; - else - return (l); - p++; - l <<= 4; - l |= digit; - } - return (l); + int64_t l; + int digit; + + l = 0; + while (char_cnt-- > 0) { + if (*p >= 'a' && *p <= 'f') + digit = *p - 'a' + 10; + else if (*p >= 'A' && *p <= 'F') + digit = *p - 'A' + 10; + else if (*p >= '0' && *p <= '9') + digit = *p - '0'; + else + return (l); + p++; + l <<= 4; + l |= digit; + } + return (l); } -static void -record_hardlink(struct cpio *cpio, struct archive_entry *entry) +static int +record_hardlink(struct archive_read *a, + struct cpio *cpio, struct archive_entry *entry) { - struct links_entry *le; - dev_t dev; - int64_t ino; - - dev = archive_entry_dev(entry); - ino = archive_entry_ino64(entry); - - /* - * First look in the list of multiply-linked files. If we've - * already dumped it, convert this entry to a hard link entry. - */ - for (le = cpio->links_head; le; le = le->next) { - if (le->dev == dev && le->ino == ino) { - archive_entry_copy_hardlink(entry, le->name); - - if (--le->links <= 0) { - if (le->previous != NULL) - le->previous->next = le->next; - if (le->next != NULL) - le->next->previous = le->previous; - if (cpio->links_head == le) - cpio->links_head = le->next; - free(le->name); - free(le); - } - - return; - } - } - - le = (struct links_entry *)malloc(sizeof(struct links_entry)); - if (le == NULL) - __archive_errx(1, "Out of memory adding file to list"); - if (cpio->links_head != NULL) - cpio->links_head->previous = le; - le->next = cpio->links_head; - le->previous = NULL; - cpio->links_head = le; - le->dev = dev; - le->ino = ino; - le->links = archive_entry_nlink(entry) - 1; - le->name = strdup(archive_entry_pathname(entry)); - if (le->name == NULL) - __archive_errx(1, "Out of memory adding file to list"); + struct links_entry *le; + dev_t dev; + int64_t ino; + + if (archive_entry_nlink(entry) <= 1) + return (ARCHIVE_OK); + + dev = archive_entry_dev(entry); + ino = archive_entry_ino64(entry); + + /* + * First look in the list of multiply-linked files. If we've + * already dumped it, convert this entry to a hard link entry. + */ + for (le = cpio->links_head; le; le = le->next) { + if (le->dev == dev && le->ino == ino) { + archive_entry_copy_hardlink(entry, le->name); + + if (--le->links <= 0) { + if (le->previous != NULL) + le->previous->next = le->next; + if (le->next != NULL) + le->next->previous = le->previous; + if (cpio->links_head == le) + cpio->links_head = le->next; + free(le->name); + free(le); + } + + return (ARCHIVE_OK); + } + } + + le = (struct links_entry *)malloc(sizeof(struct links_entry)); + if (le == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory adding file to list"); + return (ARCHIVE_FATAL); + } + if (cpio->links_head != NULL) + cpio->links_head->previous = le; + le->next = cpio->links_head; + le->previous = NULL; + cpio->links_head = le; + le->dev = dev; + le->ino = ino; + le->links = archive_entry_nlink(entry) - 1; + le->name = strdup(archive_entry_pathname(entry)); + if (le->name == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory adding file to list"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c index f0bb75359..3dc2196cb 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_empty.c @@ -24,70 +24,70 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_empty.c,v 1.4 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_empty.c 191524 2009-04-26 18:24:14Z kientzle $"); #include "archive.h" #include "archive_entry.h" #include "archive_private.h" #include "archive_read_private.h" -static int archive_read_format_empty_bid(struct archive_read *); -static int archive_read_format_empty_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_empty_read_header(struct archive_read *, - struct archive_entry *); +static int archive_read_format_empty_bid(struct archive_read *, int); +static int archive_read_format_empty_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_empty_read_header(struct archive_read *, + struct archive_entry *); int archive_read_support_format_empty(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - int r; + struct archive_read *a = (struct archive_read *)_a; + int r; - r = __archive_read_register_format(a, - NULL, - NULL, - archive_read_format_empty_bid, - NULL, - archive_read_format_empty_read_header, - archive_read_format_empty_read_data, - NULL, - NULL); + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_empty"); - return (r); + r = __archive_read_register_format(a, + NULL, + NULL, + archive_read_format_empty_bid, + NULL, + archive_read_format_empty_read_header, + archive_read_format_empty_read_data, + NULL, + NULL); + + return (r); } static int -archive_read_format_empty_bid(struct archive_read *a) +archive_read_format_empty_bid(struct archive_read *a, int best_bid) { - ssize_t avail; - - (void)__archive_read_ahead(a, 1, &avail); - if (avail != 0) - return (-1); - return (1); + if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) == NULL) + return (1); + return (-1); } static int archive_read_format_empty_read_header(struct archive_read *a, struct archive_entry *entry) { - (void)a; /* UNUSED */ - (void)entry; /* UNUSED */ + (void)a; /* UNUSED */ + (void)entry; /* UNUSED */ - a->archive.archive_format = ARCHIVE_FORMAT_EMPTY; - a->archive.archive_format_name = "Empty file"; + a->archive.archive_format = ARCHIVE_FORMAT_EMPTY; + a->archive.archive_format_name = "Empty file"; - return (ARCHIVE_EOF); + return (ARCHIVE_EOF); } static int archive_read_format_empty_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - (void)a; /* UNUSED */ - (void)buff; /* UNUSED */ - (void)size; /* UNUSED */ - (void)offset; /* UNUSED */ + (void)a; /* UNUSED */ + (void)buff; /* UNUSED */ + (void)size; /* UNUSED */ + (void)offset; /* UNUSED */ - return (ARCHIVE_EOF); + return (ARCHIVE_EOF); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c index c12b808e5..db7aa9d9b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_iso9660.c @@ -1,7 +1,7 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle * Copyright (c) 2009 Andreas Henriksson - * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2009-2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1.30 2008/12/06 06:57:45 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_iso9660.c 201246 2009-12-30 05:30:35Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -41,12 +41,13 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1 #endif #include #ifdef HAVE_ZLIB_H -#include +#include #endif #include "archive.h" #include "archive_endian.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_read_private.h" #include "archive_string.h" @@ -78,8 +79,8 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1 * the file body. This strategy allows us to read most compliant * CDs with a single pass through the data, as required by libarchive. */ -#define LOGICAL_BLOCK_SIZE 2048 -#define SYSTEM_AREA_BLOCK 16 +#define LOGICAL_BLOCK_SIZE 2048 +#define SYSTEM_AREA_BLOCK 16 /* Structure of on-disk primary volume descriptor. */ #define PVD_type_offset 0 @@ -165,8 +166,8 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1 #define SVD_version_offset (SVD_id_offset + SVD_id_size) #define SVD_version_size 1 /* ... */ -#define SVD_reserved1_offset 72 -#define SVD_reserved1_size 8 +#define SVD_reserved1_offset 72 +#define SVD_reserved1_size 8 #define SVD_volume_space_size_offset 80 #define SVD_volume_space_size_size 8 #define SVD_escape_sequences_offset (SVD_volume_space_size_offset + SVD_volume_space_size_size) @@ -174,13 +175,16 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1 /* ... */ #define SVD_logical_block_size_offset 128 #define SVD_logical_block_size_size 4 +#define SVD_type_L_path_table_offset 140 +#define SVD_type_M_path_table_offset 148 /* ... */ #define SVD_root_directory_record_offset 156 #define SVD_root_directory_record_size 34 -#define SVD_reserved2_offset 882 -#define SVD_reserved2_size 1 -#define SVD_reserved3_offset 1395 -#define SVD_reserved3_size 653 +#define SVD_file_structure_version_offset 881 +#define SVD_reserved2_offset 882 +#define SVD_reserved2_size 1 +#define SVD_reserved3_offset 1395 +#define SVD_reserved3_size 653 /* ... */ /* FIXME: validate correctness of last SVD entry offset. */ @@ -213,993 +217,1499 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_iso9660.c,v 1 #ifdef HAVE_ZLIB_H static const unsigned char zisofs_magic[8] = { - 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 + 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 }; struct zisofs { - /* Set 1 if this file compressed by paged zlib */ - int pz; - int pz_log2_bs; /* Log2 of block size */ - uint64_t pz_uncompressed_size; - - int initialized; - unsigned char *uncompressed_buffer; - size_t uncompressed_buffer_size; - - uint32_t pz_offset; - unsigned char header[16]; - size_t header_avail; - int header_passed; - unsigned char *block_pointers; - size_t block_pointers_alloc; - size_t block_pointers_size; - size_t block_pointers_avail; - size_t block_off; - uint32_t block_avail; - - z_stream stream; - int stream_valid; + /* Set 1 if this file compressed by paged zlib */ + int pz; + int pz_log2_bs; /* Log2 of block size */ + uint64_t pz_uncompressed_size; + + int initialized; + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; + + uint32_t pz_offset; + unsigned char header[16]; + size_t header_avail; + int header_passed; + unsigned char *block_pointers; + size_t block_pointers_alloc; + size_t block_pointers_size; + size_t block_pointers_avail; + size_t block_off; + uint32_t block_avail; + + z_stream stream; + int stream_valid; }; #else struct zisofs { - /* Set 1 if this file compressed by paged zlib */ - int pz; + /* Set 1 if this file compressed by paged zlib */ + int pz; }; #endif +struct content { + uint64_t offset;/* Offset on disk. */ + uint64_t size; /* File size in bytes. */ + struct content *next; +}; + /* In-memory storage for a directory record. */ struct file_info { - struct file_info *parent; - int refcount; - uint64_t offset; /* Offset on disk. */ - uint64_t size; /* File size in bytes. */ - uint64_t ce_offset; /* Offset of CE */ - uint64_t ce_size; /* Size of CE */ - time_t birthtime; /* File created time. */ - time_t mtime; /* File last modified time. */ - time_t atime; /* File last accessed time. */ - time_t ctime; /* File attribute change time. */ - uint64_t rdev; /* Device number */ - mode_t mode; - uid_t uid; - gid_t gid; - ino_t inode; - int nlinks; - struct archive_string name; /* Pathname */ - char name_continues; /* Non-zero if name continues */ - struct archive_string symlink; - char symlink_continues; /* Non-zero if link continues */ - /* Set 1 if this file compressed by paged zlib(zisofs) */ - int pz; - int pz_log2_bs; /* Log2 of block size */ - uint64_t pz_uncompressed_size; + struct file_info *use_next; + struct file_info *parent; + struct file_info *next; + struct file_info *re_next; + int subdirs; + uint64_t key; /* Heap Key. */ + uint64_t offset; /* Offset on disk. */ + uint64_t size; /* File size in bytes. */ + uint32_t ce_offset; /* Offset of CE. */ + uint32_t ce_size; /* Size of CE. */ + char rr_moved; /* Flag to rr_moved. */ + char rr_moved_has_re_only; + char re; /* Having RRIP "RE" extension. */ + char re_descendant; + uint64_t cl_offset; /* Having RRIP "CL" extension. */ + int birthtime_is_set; + time_t birthtime; /* File created time. */ + time_t mtime; /* File last modified time. */ + time_t atime; /* File last accessed time. */ + time_t ctime; /* File attribute change time. */ + uint64_t rdev; /* Device number. */ + mode_t mode; + uid_t uid; + gid_t gid; + int64_t number; + int nlinks; + struct archive_string name; /* Pathname */ + unsigned char *utf16be_name; + size_t utf16be_bytes; + char name_continues; /* Non-zero if name continues */ + struct archive_string symlink; + char symlink_continues; /* Non-zero if link continues */ + /* Set 1 if this file compressed by paged zlib(zisofs) */ + int pz; + int pz_log2_bs; /* Log2 of block size */ + uint64_t pz_uncompressed_size; + /* Set 1 if this file is multi extent. */ + int multi_extent; + struct { + struct content *first; + struct content **last; + } contents; + struct { + struct file_info *first; + struct file_info **last; + } rede_files; }; +struct heap_queue { + struct file_info **files; + int allocated; + int used; +}; struct iso9660 { - int magic; + int magic; #define ISO9660_MAGIC 0x96609660 - int option_ignore_joliet; - int option_ignore_rockridge; - - struct archive_string pathname; - char seenRockridge; /* Set true if RR extensions are used. */ - unsigned char suspOffset; - char seenJoliet; - - uint64_t previous_offset; - uint64_t previous_size; - struct archive_string previous_pathname; - - /* TODO: Make this a heap for fast inserts and deletions. */ - struct file_info **pending_files; - int pending_files_allocated; - int pending_files_used; - - uint64_t current_position; - ssize_t logical_block_size; - uint64_t volume_size; /* Total size of volume in bytes. */ - int32_t volume_block;/* Total size of volume in logical blocks. */ - - struct vd { - int sector_number; /* Logical Sector Number. */ - uint32_t block_size; - } primary, joliet; - - off_t entry_sparse_offset; - int64_t entry_bytes_remaining; - struct zisofs entry_zisofs; + int opt_support_joliet; + int opt_support_rockridge; + + struct archive_string pathname; + char seenRockridge; /* Set true if RR extensions are used. */ + char seenSUSP; /* Set true if SUSP is beging used. */ + char seenJoliet; + + unsigned char suspOffset; + struct file_info *rr_moved; + struct read_ce_queue { + struct read_ce_req { + uint64_t offset;/* Offset of CE on disk. */ + struct file_info *file; + } *reqs; + int cnt; + int allocated; + } read_ce_req; + + int64_t previous_number; + struct archive_string previous_pathname; + + struct file_info *use_files; + struct heap_queue pending_files; + struct { + struct file_info *first; + struct file_info **last; + } cache_files; + struct { + struct file_info *first; + struct file_info **last; + } re_files; + + uint64_t current_position; + ssize_t logical_block_size; + uint64_t volume_size; /* Total size of volume in bytes. */ + int32_t volume_block;/* Total size of volume in logical blocks. */ + + struct vd { + int location; /* Location of Extent. */ + uint32_t size; + } primary, joliet; + + int64_t entry_sparse_offset; + int64_t entry_bytes_remaining; + size_t entry_bytes_unconsumed; + struct zisofs entry_zisofs; + struct content *entry_content; + struct archive_string_conv *sconv_utf16be; + /* + * Buffers for a full pathname in UTF-16BE in Joliet extensions. + */ +#define UTF16_NAME_MAX 1024 + unsigned char *utf16be_path; + size_t utf16be_path_len; + unsigned char *utf16be_previous_path; + size_t utf16be_previous_path_len; }; -static void add_entry(struct iso9660 *iso9660, struct file_info *file); -static int archive_read_format_iso9660_bid(struct archive_read *); -static int archive_read_format_iso9660_options(struct archive_read *, - const char *, const char *); -static int archive_read_format_iso9660_cleanup(struct archive_read *); -static int archive_read_format_iso9660_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_iso9660_read_data_skip(struct archive_read *); -static int archive_read_format_iso9660_read_header(struct archive_read *, - struct archive_entry *); +static int archive_read_format_iso9660_bid(struct archive_read *, int); +static int archive_read_format_iso9660_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_iso9660_cleanup(struct archive_read *); +static int archive_read_format_iso9660_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_iso9660_read_data_skip(struct archive_read *); +static int archive_read_format_iso9660_read_header(struct archive_read *, + struct archive_entry *); static const char *build_pathname(struct archive_string *, struct file_info *); +static int build_pathname_utf16be(unsigned char *, size_t, size_t *, + struct file_info *); #if DEBUG -static void dump_isodirrec(FILE *, const unsigned char *isodirrec); +static void dump_isodirrec(FILE *, const unsigned char *isodirrec); #endif -static time_t time_from_tm(struct tm *); -static time_t isodate17(const unsigned char *); -static time_t isodate7(const unsigned char *); -static int isVDSetTerminator(struct iso9660 *iso9660, - const unsigned char *h); -static int isJolietSVD(struct iso9660 *, const unsigned char *); -static int isPVD(struct iso9660 *, const unsigned char *); -static struct file_info *next_entry(struct iso9660 *); -static int next_entry_seek(struct archive_read *a, struct iso9660 *iso9660, - struct file_info **pfile); +static time_t time_from_tm(struct tm *); +static time_t isodate17(const unsigned char *); +static time_t isodate7(const unsigned char *); +static int isBootRecord(struct iso9660 *, const unsigned char *); +static int isVolumePartition(struct iso9660 *, const unsigned char *); +static int isVDSetTerminator(struct iso9660 *, const unsigned char *); +static int isJolietSVD(struct iso9660 *, const unsigned char *); +static int isSVD(struct iso9660 *, const unsigned char *); +static int isEVD(struct iso9660 *, const unsigned char *); +static int isPVD(struct iso9660 *, const unsigned char *); +static int next_cache_entry(struct archive_read *, struct iso9660 *, + struct file_info **); +static int next_entry_seek(struct archive_read *, struct iso9660 *, + struct file_info **); static struct file_info * - parse_file_info(struct archive_read *a, - struct file_info *parent, const unsigned char *isodirrec); -static void parse_rockridge(struct iso9660 *iso9660, - struct file_info *file, const unsigned char *start, - const unsigned char *end); -static void parse_rockridge_NM1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_SL1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_TF1(struct file_info *, - const unsigned char *, int); -static void parse_rockridge_ZF1(struct file_info *, - const unsigned char *, int); -static void release_file(struct iso9660 *, struct file_info *); -static unsigned toi(const void *p, int n); + parse_file_info(struct archive_read *a, + struct file_info *parent, const unsigned char *isodirrec); +static int parse_rockridge(struct archive_read *a, + struct file_info *file, const unsigned char *start, + const unsigned char *end); +static int register_CE(struct archive_read *a, int32_t location, + struct file_info *file); +static int read_CE(struct archive_read *a, struct iso9660 *iso9660); +static void parse_rockridge_NM1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_SL1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_TF1(struct file_info *, + const unsigned char *, int); +static void parse_rockridge_ZF1(struct file_info *, + const unsigned char *, int); +static void register_file(struct iso9660 *, struct file_info *); +static void release_files(struct iso9660 *); +static unsigned toi(const void *p, int n); +static inline void re_add_entry(struct iso9660 *, struct file_info *); +static inline struct file_info * re_get_entry(struct iso9660 *); +static inline int rede_add_entry(struct file_info *); +static inline struct file_info * rede_get_entry(struct file_info *); +static inline void cache_add_entry(struct iso9660 *iso9660, + struct file_info *file); +static inline struct file_info *cache_get_entry(struct iso9660 *iso9660); +static int heap_add_entry(struct archive_read *a, struct heap_queue *heap, + struct file_info *file, uint64_t key); +static struct file_info *heap_get_entry(struct heap_queue *heap); + +#define add_entry(arch, iso9660, file) \ + heap_add_entry(arch, &((iso9660)->pending_files), file, file->offset) +#define next_entry(iso9660) \ + heap_get_entry(&((iso9660)->pending_files)) int archive_read_support_format_iso9660(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - struct iso9660 *iso9660; - int r; - - iso9660 = (struct iso9660 *)malloc(sizeof(*iso9660)); - if (iso9660 == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate iso9660 data"); - return (ARCHIVE_FATAL); - } - memset(iso9660, 0, sizeof(*iso9660)); - iso9660->magic = ISO9660_MAGIC; - - r = __archive_read_register_format(a, - iso9660, - "iso9660", - archive_read_format_iso9660_bid, - archive_read_format_iso9660_options, - archive_read_format_iso9660_read_header, - archive_read_format_iso9660_read_data, - archive_read_format_iso9660_read_data_skip, - archive_read_format_iso9660_cleanup); - - if (r != ARCHIVE_OK) { - free(iso9660); - return (r); - } - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + struct iso9660 *iso9660; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_iso9660"); + + iso9660 = (struct iso9660 *)calloc(1, sizeof(*iso9660)); + if (iso9660 == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate iso9660 data"); + return (ARCHIVE_FATAL); + } + iso9660->magic = ISO9660_MAGIC; + iso9660->cache_files.first = NULL; + iso9660->cache_files.last = &(iso9660->cache_files.first); + iso9660->re_files.first = NULL; + iso9660->re_files.last = &(iso9660->re_files.first); + /* Enable to support Joliet extensions by default. */ + iso9660->opt_support_joliet = 1; + /* Enable to support Rock Ridge extensions by default. */ + iso9660->opt_support_rockridge = 1; + + r = __archive_read_register_format(a, + iso9660, + "iso9660", + archive_read_format_iso9660_bid, + archive_read_format_iso9660_options, + archive_read_format_iso9660_read_header, + archive_read_format_iso9660_read_data, + archive_read_format_iso9660_read_data_skip, + archive_read_format_iso9660_cleanup); + + if (r != ARCHIVE_OK) { + free(iso9660); + return (r); + } + return (ARCHIVE_OK); } static int -archive_read_format_iso9660_bid(struct archive_read *a) +archive_read_format_iso9660_bid(struct archive_read *a, int best_bid) { - struct iso9660 *iso9660; - ssize_t bytes_read; - const void *h; - const unsigned char *p; - int seenTerminator; - - iso9660 = (struct iso9660 *)(a->format->data); - - /* - * Skip the first 32k (reserved area) and get the first - * 8 sectors of the volume descriptor table. Of course, - * if the I/O layer gives us more, we'll take it. - */ -#define RESERVED_AREA (SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE) - h = __archive_read_ahead(a, - RESERVED_AREA + 8 * LOGICAL_BLOCK_SIZE, - &bytes_read); - if (h == NULL) - return (-1); - p = (const unsigned char *)h; - - /* Skip the reserved area. */ - bytes_read -= RESERVED_AREA; - p += RESERVED_AREA; - - /* Check each volume descriptor. */ - seenTerminator = 0; - for (; bytes_read > LOGICAL_BLOCK_SIZE; - bytes_read -= LOGICAL_BLOCK_SIZE, p += LOGICAL_BLOCK_SIZE) { - int bid = 0; - - /* Do not handle undefined Volume Descriptor Type. */ - if (p[0] >= 4 && p[0] <= 254) - return (0); - /* Standard Identifier must be "CD001" */ - if (memcmp(p + 1, "CD001", 5) != 0) - return (0); - bid += isPVD(iso9660, p); - bid += isJolietSVD(iso9660, p); - if (bid == 0) { - if (isVDSetTerminator(iso9660, p)) { - seenTerminator = 1; - break; - } - return (0); - } - } - /* - * ISO 9660 format must have Primary Volume Descriptor and - * Volume Descriptor Set Terminator. - */ - if (seenTerminator && iso9660->primary.sector_number > 16) - return (48); - - /* We didn't find a valid PVD; return a bid of zero. */ - return (0); + struct iso9660 *iso9660; + ssize_t bytes_read; + const unsigned char *p; + int seenTerminator; + + /* If there's already a better bid than we can ever + make, don't bother testing. */ + if (best_bid > 48) + return (-1); + + iso9660 = (struct iso9660 *)(a->format->data); + + /* + * Skip the first 32k (reserved area) and get the first + * 8 sectors of the volume descriptor table. Of course, + * if the I/O layer gives us more, we'll take it. + */ +#define RESERVED_AREA (SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE) + p = __archive_read_ahead(a, + RESERVED_AREA + 8 * LOGICAL_BLOCK_SIZE, + &bytes_read); + if (p == NULL) + return (-1); + + /* Skip the reserved area. */ + bytes_read -= RESERVED_AREA; + p += RESERVED_AREA; + + /* Check each volume descriptor. */ + seenTerminator = 0; + for (; bytes_read > LOGICAL_BLOCK_SIZE; + bytes_read -= LOGICAL_BLOCK_SIZE, p += LOGICAL_BLOCK_SIZE) { + /* Do not handle undefined Volume Descriptor Type. */ + if (p[0] >= 4 && p[0] <= 254) + return (0); + /* Standard Identifier must be "CD001" */ + if (memcmp(p + 1, "CD001", 5) != 0) + return (0); + if (isPVD(iso9660, p)) + continue; + if (!iso9660->joliet.location) { + if (isJolietSVD(iso9660, p)) + continue; + } + if (isBootRecord(iso9660, p)) + continue; + if (isEVD(iso9660, p)) + continue; + if (isSVD(iso9660, p)) + continue; + if (isVolumePartition(iso9660, p)) + continue; + if (isVDSetTerminator(iso9660, p)) { + seenTerminator = 1; + break; + } + return (0); + } + /* + * ISO 9660 format must have Primary Volume Descriptor and + * Volume Descriptor Set Terminator. + */ + if (seenTerminator && iso9660->primary.location > 16) + return (48); + + /* We didn't find a valid PVD; return a bid of zero. */ + return (0); } static int archive_read_format_iso9660_options(struct archive_read *a, - const char *key, const char *val) + const char *key, const char *val) { - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); - - if (strcmp(key, "joliet") == 0) { - if (val == NULL || strcmp(val, "off") == 0 || - strcmp(val, "ignore") == 0 || - strcmp(val, "disable") == 0 || - strcmp(val, "0") == 0) - iso9660->option_ignore_joliet = 1; - else - iso9660->option_ignore_joliet = 0; - return (ARCHIVE_OK); - } - if (strcmp(key, "rock-ridge") == 0) { - iso9660->option_ignore_rockridge = val == NULL; - return (ARCHIVE_OK); - } - - /* Note: The "warn" return is just to inform the options - * supervisor that we didn't handle it. It will generate - * a suitable error if noone used this option. */ - return (ARCHIVE_WARN); + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (strcmp(key, "joliet") == 0) { + if (val == NULL || strcmp(val, "off") == 0 || + strcmp(val, "ignore") == 0 || + strcmp(val, "disable") == 0 || + strcmp(val, "0") == 0) + iso9660->opt_support_joliet = 0; + else + iso9660->opt_support_joliet = 1; + return (ARCHIVE_OK); + } + if (strcmp(key, "rockridge") == 0 || + strcmp(key, "Rockridge") == 0) { + iso9660->opt_support_rockridge = val != NULL; + return (ARCHIVE_OK); + } + + /* Note: The "warn" return is just to inform the options + * supervisor that we didn't handle it. It will generate + * a suitable error if no one used this option. */ + return (ARCHIVE_WARN); +} + +static int +isBootRecord(struct iso9660 *iso9660, const unsigned char *h) +{ + (void)iso9660; /* UNUSED */ + + /* Type of the Volume Descriptor Boot Record must be 0. */ + if (h[0] != 0) + return (0); + + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); + + return (1); +} + +static int +isVolumePartition(struct iso9660 *iso9660, const unsigned char *h) +{ + int32_t location; + + /* Type of the Volume Partition Descriptor must be 3. */ + if (h[0] != 3) + return (0); + + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); + /* Unused Field */ + if (h[7] != 0) + return (0); + + location = archive_le32dec(h + 72); + if (location <= SYSTEM_AREA_BLOCK || + location >= iso9660->volume_block) + return (0); + if ((uint32_t)location != archive_be32dec(h + 76)) + return (0); + + return (1); } static int isVDSetTerminator(struct iso9660 *iso9660, const unsigned char *h) { - int i; - (void)iso9660; + int i; + + (void)iso9660; /* UNUSED */ - /* Type of the Volume Descriptor Set Terminator must be 255. */ - if (h[0] != 255) - return (0); + /* Type of the Volume Descriptor Set Terminator must be 255. */ + if (h[0] != 255) + return (0); - /* Volume Descriptor Version must be 1. */ - if (h[6] != 1) - return (0); + /* Volume Descriptor Version must be 1. */ + if (h[6] != 1) + return (0); - /* Reserved field must be 0. */ - for (i = 7; i < 2048; ++i) - if (h[i] != 0) - return (0); + /* Reserved field must be 0. */ + for (i = 7; i < 2048; ++i) + if (h[i] != 0) + return (0); - return (1); + return (1); } static int isJolietSVD(struct iso9660 *iso9660, const unsigned char *h) { - const unsigned char *p; - int i; - - /* Type 2 means it's a SVD. */ - if (h[SVD_type_offset] != 2) - return (0); - - /* ID must be "CD001" */ - if (memcmp(h + SVD_id_offset, "CD001", 5) != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < SVD_reserved1_size; ++i) - if (h[SVD_reserved1_offset + i] != 0) - return (0); - for (i = 0; i < SVD_reserved2_size; ++i) - if (h[SVD_reserved2_offset + i] != 0) - return (0); - for (i = 0; i < SVD_reserved3_size; ++i) - if (h[SVD_reserved3_offset + i] != 0) - return (0); - - /* FIXME: do more validations according to joliet spec. */ - - /* check if this SVD contains joliet extension! */ - p = h + SVD_escape_sequences_offset; - /* N.B. Joliet spec says p[1] == '\\', but.... */ - if (p[0] == '%' && p[1] == '/') { - int level = 0; - - if (p[2] == '@') - level = 1; - else if (p[2] == 'C') - level = 2; - else if (p[2] == 'E') - level = 3; - else /* not joliet */ - return (0); - - iso9660->seenJoliet = level; - - } else /* not joliet */ - return (0); - - iso9660->logical_block_size = toi(h + SVD_logical_block_size_offset, 2); - if (iso9660->logical_block_size <= 0) - return (0); - - iso9660->volume_block = - archive_le32dec(h + SVD_volume_space_size_offset); - if (iso9660->volume_block <= SYSTEM_AREA_BLOCK+4) - return (0); - iso9660->volume_size = iso9660->logical_block_size - * (uint64_t)iso9660->volume_block; - - /* Read Root Directory Record in Volume Descriptor. */ - p = h + SVD_root_directory_record_offset; - if (p[DR_length_offset] != 34) - return (0); - iso9660->joliet.sector_number = archive_le32dec(p + DR_extent_offset); - iso9660->joliet.block_size = archive_le32dec(p + DR_size_offset); - - return (48); + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + + /* Check if current sector is a kind of Supplementary Volume + * Descriptor. */ + if (!isSVD(iso9660, h)) + return (0); + + /* FIXME: do more validations according to joliet spec. */ + + /* check if this SVD contains joliet extension! */ + p = h + SVD_escape_sequences_offset; + /* N.B. Joliet spec says p[1] == '\\', but.... */ + if (p[0] == '%' && p[1] == '/') { + int level = 0; + + if (p[2] == '@') + level = 1; + else if (p[2] == 'C') + level = 2; + else if (p[2] == 'E') + level = 3; + else /* not joliet */ + return (0); + + iso9660->seenJoliet = level; + + } else /* not joliet */ + return (0); + + logical_block_size = + archive_le16dec(h + SVD_logical_block_size_offset); + volume_block = archive_le32dec(h + SVD_volume_space_size_offset); + + iso9660->logical_block_size = logical_block_size; + iso9660->volume_block = volume_block; + iso9660->volume_size = logical_block_size * (uint64_t)volume_block; + /* Read Root Directory Record in Volume Descriptor. */ + p = h + SVD_root_directory_record_offset; + iso9660->joliet.location = archive_le32dec(p + DR_extent_offset); + iso9660->joliet.size = archive_le32dec(p + DR_size_offset); + + return (48); +} + +static int +isSVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + int i; + + (void)iso9660; /* UNUSED */ + + /* Type 2 means it's a SVD. */ + if (h[SVD_type_offset] != 2) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < SVD_reserved1_size; ++i) + if (h[SVD_reserved1_offset + i] != 0) + return (0); + for (i = 0; i < SVD_reserved2_size; ++i) + if (h[SVD_reserved2_offset + i] != 0) + return (0); + for (i = 0; i < SVD_reserved3_size; ++i) + if (h[SVD_reserved3_offset + i] != 0) + return (0); + + /* File structure version must be 1 for ISO9660/ECMA119. */ + if (h[SVD_file_structure_version_offset] != 1) + return (0); + + logical_block_size = + archive_le16dec(h + SVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = archive_le32dec(h + SVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+SVD_type_L_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* The Type M Path Table must be at a valid location (WinISO + * and probably other programs omit this, so we allow zero) + * + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+SVD_type_M_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + SVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + return (48); +} + +static int +isEVD(struct iso9660 *iso9660, const unsigned char *h) +{ + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + int i; + + (void)iso9660; /* UNUSED */ + + /* Type of the Enhanced Volume Descriptor must be 2. */ + if (h[PVD_type_offset] != 2) + return (0); + + /* EVD version must be 2. */ + if (h[PVD_version_offset] != 2) + return (0); + + /* Reserved field must be 0. */ + if (h[PVD_reserved1_offset] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved2_size; ++i) + if (h[PVD_reserved2_offset + i] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved3_size; ++i) + if (h[PVD_reserved3_offset + i] != 0) + return (0); + + /* Logical block size must be > 0. */ + /* I've looked at Ecma 119 and can't find any stronger + * restriction on this field. */ + logical_block_size = + archive_le16dec(h + PVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = + archive_le32dec(h + PVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* File structure version must be 2 for ISO9660:1999. */ + if (h[PVD_file_structure_version_offset] != 2) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+PVD_type_1_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* Location of Occurrence of Type M Path Table must be + * available location, + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+PVD_type_m_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved4_size; ++i) + if (h[PVD_reserved4_offset + i] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved5_size; ++i) + if (h[PVD_reserved5_offset + i] != 0) + return (0); + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + PVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + return (48); } static int isPVD(struct iso9660 *iso9660, const unsigned char *h) { - const unsigned char *p; - int i; - - /* Type of the Primary Volume Descriptor must be 1. */ - if (h[PVD_type_offset] != 1) - return (0); - - /* ID must be "CD001" */ - if (memcmp(h + PVD_id_offset, "CD001", 5) != 0) - return (0); - - /* PVD version must be 1. */ - if (h[PVD_version_offset] != 1) - return (0); - - /* Reserved field must be 0. */ - if (h[PVD_reserved1_offset] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved2_size; ++i) - if (h[PVD_reserved2_offset + i] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved3_size; ++i) - if (h[PVD_reserved3_offset + i] != 0) - return (0); - - /* Logical block size must be > 0. */ - /* I've looked at Ecma 119 and can't find any stronger - * restriction on this field. */ - iso9660->logical_block_size = toi(h + PVD_logical_block_size_offset, 2); - if (iso9660->logical_block_size <= 0) - return (0); - - iso9660->volume_block = - archive_le32dec(h + PVD_volume_space_size_offset); - if (iso9660->volume_block <= SYSTEM_AREA_BLOCK+4) - return (0); - iso9660->volume_size = iso9660->logical_block_size - * (uint64_t)iso9660->volume_block; - - /* File structure version must be 1 for ISO9660/ECMA119. */ - if (h[PVD_file_structure_version_offset] != 1) - return (0); - - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved4_size; ++i) - if (h[PVD_reserved4_offset + i] != 0) - return (0); - - /* Reserved field must be 0. */ - for (i = 0; i < PVD_reserved5_size; ++i) - if (h[PVD_reserved5_offset + i] != 0) - return (0); - - /* XXX TODO: Check other values for sanity; reject more - * malformed PVDs. XXX */ - - /* Read Root Directory Record in Volume Descriptor. */ - p = h + PVD_root_directory_record_offset; - if (p[DR_length_offset] != 34) - return (0); - iso9660->primary.sector_number = archive_le32dec(p + DR_extent_offset); - iso9660->primary.block_size = archive_le32dec(p + DR_size_offset); - - return (48); + const unsigned char *p; + ssize_t logical_block_size; + int32_t volume_block; + int32_t location; + int i; + + /* Type of the Primary Volume Descriptor must be 1. */ + if (h[PVD_type_offset] != 1) + return (0); + + /* PVD version must be 1. */ + if (h[PVD_version_offset] != 1) + return (0); + + /* Reserved field must be 0. */ + if (h[PVD_reserved1_offset] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved2_size; ++i) + if (h[PVD_reserved2_offset + i] != 0) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved3_size; ++i) + if (h[PVD_reserved3_offset + i] != 0) + return (0); + + /* Logical block size must be > 0. */ + /* I've looked at Ecma 119 and can't find any stronger + * restriction on this field. */ + logical_block_size = + archive_le16dec(h + PVD_logical_block_size_offset); + if (logical_block_size <= 0) + return (0); + + volume_block = archive_le32dec(h + PVD_volume_space_size_offset); + if (volume_block <= SYSTEM_AREA_BLOCK+4) + return (0); + + /* File structure version must be 1 for ISO9660/ECMA119. */ + if (h[PVD_file_structure_version_offset] != 1) + return (0); + + /* Location of Occurrence of Type L Path Table must be + * available location, + * > SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_le32dec(h+PVD_type_1_path_table_offset); + if (location < SYSTEM_AREA_BLOCK+2 || location >= volume_block) + return (0); + + /* The Type M Path Table must also be at a valid location + * (although ECMA 119 requires a Type M Path Table, WinISO and + * probably other programs omit it, so we permit a zero here) + * + * >= SYSTEM_AREA_BLOCK(16) + 2 and < Volume Space Size. */ + location = archive_be32dec(h+PVD_type_m_path_table_offset); + if ((location > 0 && location < SYSTEM_AREA_BLOCK+2) + || location >= volume_block) + return (0); + + /* Reserved field must be 0. */ + /* But accept NetBSD/FreeBSD "makefs" images with 0x20 here. */ + for (i = 0; i < PVD_reserved4_size; ++i) + if (h[PVD_reserved4_offset + i] != 0 + && h[PVD_reserved4_offset + i] != 0x20) + return (0); + + /* Reserved field must be 0. */ + for (i = 0; i < PVD_reserved5_size; ++i) + if (h[PVD_reserved5_offset + i] != 0) + return (0); + + /* XXX TODO: Check other values for sanity; reject more + * malformed PVDs. XXX */ + + /* Read Root Directory Record in Volume Descriptor. */ + p = h + PVD_root_directory_record_offset; + if (p[DR_length_offset] != 34) + return (0); + + if (!iso9660->primary.location) { + iso9660->logical_block_size = logical_block_size; + iso9660->volume_block = volume_block; + iso9660->volume_size = logical_block_size * (uint64_t)volume_block; + iso9660->primary.location = archive_le32dec(p + DR_extent_offset); + iso9660->primary.size = archive_le32dec(p + DR_size_offset); + } + + return (48); +} + +static int +read_children(struct archive_read *a, struct file_info *parent) +{ + struct iso9660 *iso9660; + const unsigned char *b, *p; + struct file_info *multi; + size_t step, skip_size; + + iso9660 = (struct iso9660 *)(a->format->data); + if (iso9660->current_position > parent->offset) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order directory (%s) %jd > %jd", + parent->name.s, + (intmax_t)iso9660->current_position, + (intmax_t)parent->offset); + return (ARCHIVE_WARN); + } + if (parent->offset + parent->size > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Directory is beyond end-of-media: %s", + parent->name.s); + return (ARCHIVE_WARN); + } + if (iso9660->current_position < parent->offset) { + int64_t skipsize; + + skipsize = parent->offset - iso9660->current_position; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position = parent->offset; + } + + step = ((parent->size + iso9660->logical_block_size -1) / + iso9660->logical_block_size) * iso9660->logical_block_size; + b = __archive_read_ahead(a, step, NULL); + if (b == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + iso9660->current_position += step; + multi = NULL; + skip_size = step; + while (step) { + p = b; + b += iso9660->logical_block_size; + step -= iso9660->logical_block_size; + for (; *p != 0 && p < b && p + *p <= b; p += *p) { + struct file_info *child; + + /* N.B.: these special directory identifiers + * are 8 bit "values" even on a + * Joliet CD with UCS-2 (16bit) encoding. + */ + + /* Skip '.' entry. */ + if (*(p + DR_name_len_offset) == 1 + && *(p + DR_name_offset) == '\0') + continue; + /* Skip '..' entry. */ + if (*(p + DR_name_len_offset) == 1 + && *(p + DR_name_offset) == '\001') + continue; + child = parse_file_info(a, parent, p); + if (child == NULL) { + __archive_read_consume(a, skip_size); + return (ARCHIVE_FATAL); + } + if (child->cl_offset == 0 && + (child->multi_extent || multi != NULL)) { + struct content *con; + + if (multi == NULL) { + multi = child; + multi->contents.first = NULL; + multi->contents.last = + &(multi->contents.first); + } + con = malloc(sizeof(struct content)); + if (con == NULL) { + archive_set_error( + &a->archive, ENOMEM, + "No memory for multi extent"); + __archive_read_consume(a, skip_size); + return (ARCHIVE_FATAL); + } + con->offset = child->offset; + con->size = child->size; + con->next = NULL; + *multi->contents.last = con; + multi->contents.last = &(con->next); + if (multi == child) { + if (add_entry(a, iso9660, child) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + multi->size += child->size; + if (!child->multi_extent) + multi = NULL; + } + } else + if (add_entry(a, iso9660, child) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + } + + __archive_read_consume(a, skip_size); + + /* Read data which recorded by RRIP "CE" extension. */ + if (read_CE(a, iso9660) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + return (ARCHIVE_OK); } static int archive_read_format_iso9660_read_header(struct archive_read *a, struct archive_entry *entry) { - struct iso9660 *iso9660; - struct file_info *file; - int r; - - iso9660 = (struct iso9660 *)(a->format->data); - - if (!a->archive.archive_format) { - a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; - a->archive.archive_format_name = "ISO9660"; - } - - if (iso9660->current_position == 0) { - int64_t skipsize; - struct vd *vd; - const void *block; - char seenJoliet; - - vd = &(iso9660->primary); - if (iso9660->seenJoliet && - vd->sector_number > iso9660->joliet.sector_number) - /* This condition is unlikely; by way of caution. */ - vd = &(iso9660->joliet); - - skipsize = LOGICAL_BLOCK_SIZE * vd->sector_number; - skipsize = __archive_read_skip(a, skipsize); - if (skipsize < 0) - return ((int)skipsize); - iso9660->current_position = skipsize; - - block = __archive_read_ahead(a, vd->block_size, NULL); - if (block == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - - /* - * While reading Root Directory, flag seenJoliet - * must be zero to avoid converting special name - * 0x00(Current Directory) and next byte to UCS2. - */ - seenJoliet = iso9660->seenJoliet;/* Save flag. */ - iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); - if (file == NULL) - return (ARCHIVE_FATAL); - iso9660->seenJoliet = seenJoliet; - if (vd == &(iso9660->primary) && iso9660->seenRockridge - && iso9660->seenJoliet) - /* - * If iso image has RockRidge and Joliet, - * we use RockRidge Extensions. - */ - iso9660->seenJoliet = 0; - if (vd == &(iso9660->primary) && !iso9660->seenRockridge - && iso9660->seenJoliet) { - /* Switch reading data from primary to joliet. */ - release_file(iso9660, file); - vd = &(iso9660->joliet); - skipsize = LOGICAL_BLOCK_SIZE * vd->sector_number; - skipsize -= LOGICAL_BLOCK_SIZE * - iso9660->primary.sector_number; - skipsize = __archive_read_skip(a, skipsize); - if (skipsize < 0) - return ((int)skipsize); - iso9660->current_position += skipsize; - - block = __archive_read_ahead(a, vd->block_size, NULL); - if (block == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning " - "ISO9660 directory list"); - return (ARCHIVE_FATAL); - } - seenJoliet = iso9660->seenJoliet;/* Save flag. */ - iso9660->seenJoliet = 0; - file = parse_file_info(a, NULL, block); - if (file == NULL) - return (ARCHIVE_FATAL); - iso9660->seenJoliet = seenJoliet; - } - /* Store the root directory in the pending list. */ - add_entry(iso9660, file); - if (iso9660->seenRockridge) { - a->archive.archive_format = - ARCHIVE_FORMAT_ISO9660_ROCKRIDGE; - a->archive.archive_format_name = - "ISO9660 with Rockridge extensions"; - } - } - - /* Get the next entry that appears after the current offset. */ - r = next_entry_seek(a, iso9660, &file); - if (r != ARCHIVE_OK) { - release_file(iso9660, file); - return (r); - } - - iso9660->entry_bytes_remaining = file->size; - iso9660->entry_sparse_offset = 0; /* Offset for sparse-file-aware clients. */ - - if (file->offset + file->size > iso9660->volume_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - release_file(iso9660, file); - return (ARCHIVE_WARN); - } - - /* Set up the entry structure with information about this entry. */ - archive_entry_set_mode(entry, file->mode); - archive_entry_set_uid(entry, file->uid); - archive_entry_set_gid(entry, file->gid); - archive_entry_set_nlink(entry, file->nlinks); - archive_entry_set_ino(entry, file->inode); - archive_entry_set_birthtime(entry, file->birthtime, 0); - archive_entry_set_mtime(entry, file->mtime, 0); - archive_entry_set_ctime(entry, file->ctime, 0); - archive_entry_set_atime(entry, file->atime, 0); - /* N.B.: Rock Ridge supports 64-bit device numbers. */ - archive_entry_set_rdev(entry, (dev_t)file->rdev); - archive_entry_set_size(entry, iso9660->entry_bytes_remaining); - archive_string_empty(&iso9660->pathname); - archive_entry_set_pathname(entry, - build_pathname(&iso9660->pathname, file)); - if (file->symlink.s != NULL) - archive_entry_copy_symlink(entry, file->symlink.s); - - /* Note: If the input isn't seekable, we can't rewind to - * return the same body again, so if the next entry refers to - * the same data, we have to return it as a hardlink to the - * original entry. */ - /* TODO: We have enough information here to compute an - * accurate value for nlinks. We should do so and ignore - * nlinks from the RR extensions. */ - if (file->offset == iso9660->previous_offset - && file->size == iso9660->previous_size - && file->size > 0) { - archive_entry_set_hardlink(entry, - iso9660->previous_pathname.s); - archive_entry_unset_size(entry); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - release_file(iso9660, file); - return (ARCHIVE_OK); - } - - /* Except for the hardlink case above, if the offset of the - * next entry is before our current position, we can't seek - * backwards to extract it, so issue a warning. Note that - * this can only happen if this entry was added to the heap - * after we passed this offset, that is, only if the directory - * mentioning this entry is later than the body of the entry. - * Such layouts are very unusual; most ISO9660 writers lay out - * and record all directory information first, then store - * all file bodies. */ - /* TODO: Someday, libarchive's I/O core will support optional - * seeking. When that day comes, this code should attempt to - * seek and only return the error if the seek fails. That - * will give us support for whacky ISO images that require - * seeking while retaining the ability to read almost all ISO - * images in a streaming fashion. */ - if (file->offset < iso9660->current_position) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file @%x (%s) %jd < %jd", - file, - iso9660->pathname.s, - file->offset, iso9660->current_position); - iso9660->entry_bytes_remaining = 0; - iso9660->entry_sparse_offset = 0; - release_file(iso9660, file); - return (ARCHIVE_WARN); - } - - /* Initialize zisofs variables. */ - iso9660->entry_zisofs.pz = file->pz; - if (file->pz) { + struct iso9660 *iso9660; + struct file_info *file; + int r, rd_r = ARCHIVE_OK; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (!a->archive.archive_format) { + a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; + a->archive.archive_format_name = "ISO9660"; + } + + if (iso9660->current_position == 0) { + int64_t skipsize; + struct vd *vd; + const void *block; + char seenJoliet; + + vd = &(iso9660->primary); + if (!iso9660->opt_support_joliet) + iso9660->seenJoliet = 0; + if (iso9660->seenJoliet && + vd->location > iso9660->joliet.location) + /* This condition is unlikely; by way of caution. */ + vd = &(iso9660->joliet); + + skipsize = LOGICAL_BLOCK_SIZE * vd->location; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position = skipsize; + + block = __archive_read_ahead(a, vd->size, NULL); + if (block == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + + /* + * While reading Root Directory, flag seenJoliet + * must be zero to avoid converting special name + * 0x00(Current Directory) and next byte to UCS2. + */ + seenJoliet = iso9660->seenJoliet;/* Save flag. */ + iso9660->seenJoliet = 0; + file = parse_file_info(a, NULL, block); + if (file == NULL) + return (ARCHIVE_FATAL); + iso9660->seenJoliet = seenJoliet; + if (vd == &(iso9660->primary) && iso9660->seenRockridge + && iso9660->seenJoliet) + /* + * If iso image has RockRidge and Joliet, + * we use RockRidge Extensions. + */ + iso9660->seenJoliet = 0; + if (vd == &(iso9660->primary) && !iso9660->seenRockridge + && iso9660->seenJoliet) { + /* Switch reading data from primary to joliet. */ + vd = &(iso9660->joliet); + skipsize = LOGICAL_BLOCK_SIZE * vd->location; + skipsize -= iso9660->current_position; + skipsize = __archive_read_consume(a, skipsize); + if (skipsize < 0) + return ((int)skipsize); + iso9660->current_position += skipsize; + + block = __archive_read_ahead(a, vd->size, NULL); + if (block == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + iso9660->seenJoliet = 0; + file = parse_file_info(a, NULL, block); + if (file == NULL) + return (ARCHIVE_FATAL); + iso9660->seenJoliet = seenJoliet; + } + /* Store the root directory in the pending list. */ + if (add_entry(a, iso9660, file) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (iso9660->seenRockridge) { + a->archive.archive_format = + ARCHIVE_FORMAT_ISO9660_ROCKRIDGE; + a->archive.archive_format_name = + "ISO9660 with Rockridge extensions"; + } + } + + file = NULL;/* Eliminate a warning. */ + /* Get the next entry that appears after the current offset. */ + r = next_entry_seek(a, iso9660, &file); + if (r != ARCHIVE_OK) + return (r); + + if (iso9660->seenJoliet) { + /* + * Convert UTF-16BE of a filename to local locale MBS + * and store the result into a filename field. + */ + if (iso9660->sconv_utf16be == NULL) { + iso9660->sconv_utf16be = + archive_string_conversion_from_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_utf16be == NULL) + /* Coundn't allocate memory */ + return (ARCHIVE_FATAL); + } + if (iso9660->utf16be_path == NULL) { + iso9660->utf16be_path = malloc(UTF16_NAME_MAX); + if (iso9660->utf16be_path == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + } + if (iso9660->utf16be_previous_path == NULL) { + iso9660->utf16be_previous_path = malloc(UTF16_NAME_MAX); + if (iso9660->utf16be_previous_path == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + } + + iso9660->utf16be_path_len = 0; + if (build_pathname_utf16be(iso9660->utf16be_path, + UTF16_NAME_MAX, &(iso9660->utf16be_path_len), file) != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname is too long"); + } + + r = archive_entry_copy_pathname_l(entry, + (const char *)iso9660->utf16be_path, + iso9660->utf16be_path_len, + iso9660->sconv_utf16be); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "No memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name( + iso9660->sconv_utf16be)); + + rd_r = ARCHIVE_WARN; + } + } else { + archive_string_empty(&iso9660->pathname); + archive_entry_set_pathname(entry, + build_pathname(&iso9660->pathname, file)); + } + + iso9660->entry_bytes_remaining = file->size; + iso9660->entry_sparse_offset = 0; /* Offset for sparse-file-aware clients. */ + + if (file->offset + file->size > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File is beyond end-of-media: %s", + archive_entry_pathname(entry)); + iso9660->entry_bytes_remaining = 0; + iso9660->entry_sparse_offset = 0; + return (ARCHIVE_WARN); + } + + /* Set up the entry structure with information about this entry. */ + archive_entry_set_mode(entry, file->mode); + archive_entry_set_uid(entry, file->uid); + archive_entry_set_gid(entry, file->gid); + archive_entry_set_nlink(entry, file->nlinks); + if (file->birthtime_is_set) + archive_entry_set_birthtime(entry, file->birthtime, 0); + else + archive_entry_unset_birthtime(entry); + archive_entry_set_mtime(entry, file->mtime, 0); + archive_entry_set_ctime(entry, file->ctime, 0); + archive_entry_set_atime(entry, file->atime, 0); + /* N.B.: Rock Ridge supports 64-bit device numbers. */ + archive_entry_set_rdev(entry, (dev_t)file->rdev); + archive_entry_set_size(entry, iso9660->entry_bytes_remaining); + if (file->symlink.s != NULL) + archive_entry_copy_symlink(entry, file->symlink.s); + + /* Note: If the input isn't seekable, we can't rewind to + * return the same body again, so if the next entry refers to + * the same data, we have to return it as a hardlink to the + * original entry. */ + if (file->number != -1 && + file->number == iso9660->previous_number) { + if (iso9660->seenJoliet) { + r = archive_entry_copy_hardlink_l(entry, + (const char *)iso9660->utf16be_previous_path, + iso9660->utf16be_previous_path_len, + iso9660->sconv_utf16be); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "No memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name( + iso9660->sconv_utf16be)); + rd_r = ARCHIVE_WARN; + } + } else + archive_entry_set_hardlink(entry, + iso9660->previous_pathname.s); + archive_entry_unset_size(entry); + iso9660->entry_bytes_remaining = 0; + iso9660->entry_sparse_offset = 0; + return (rd_r); + } + + /* Except for the hardlink case above, if the offset of the + * next entry is before our current position, we can't seek + * backwards to extract it, so issue a warning. Note that + * this can only happen if this entry was added to the heap + * after we passed this offset, that is, only if the directory + * mentioning this entry is later than the body of the entry. + * Such layouts are very unusual; most ISO9660 writers lay out + * and record all directory information first, then store + * all file bodies. */ + /* TODO: Someday, libarchive's I/O core will support optional + * seeking. When that day comes, this code should attempt to + * seek and only return the error if the seek fails. That + * will give us support for whacky ISO images that require + * seeking while retaining the ability to read almost all ISO + * images in a streaming fashion. */ + if ((file->mode & AE_IFMT) != AE_IFDIR && + file->offset < iso9660->current_position) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order file @%jx (%s) %jd < %jd", + (intmax_t)file->number, + iso9660->pathname.s, + (intmax_t)file->offset, + (intmax_t)iso9660->current_position); + iso9660->entry_bytes_remaining = 0; + iso9660->entry_sparse_offset = 0; + return (ARCHIVE_WARN); + } + + /* Initialize zisofs variables. */ + iso9660->entry_zisofs.pz = file->pz; + if (file->pz) { #ifdef HAVE_ZLIB_H - struct zisofs *zisofs; - - zisofs = &iso9660->entry_zisofs; - zisofs->initialized = 0; - zisofs->pz_log2_bs = file->pz_log2_bs; - zisofs->pz_uncompressed_size = file->pz_uncompressed_size; - zisofs->pz_offset = 0; - zisofs->header_avail = 0; - zisofs->header_passed = 0; - zisofs->block_pointers_avail = 0; + struct zisofs *zisofs; + + zisofs = &iso9660->entry_zisofs; + zisofs->initialized = 0; + zisofs->pz_log2_bs = file->pz_log2_bs; + zisofs->pz_uncompressed_size = file->pz_uncompressed_size; + zisofs->pz_offset = 0; + zisofs->header_avail = 0; + zisofs->header_passed = 0; + zisofs->block_pointers_avail = 0; #endif - archive_entry_set_size(entry, file->pz_uncompressed_size); - } - - iso9660->previous_size = file->size; - iso9660->previous_offset = file->offset; - archive_strcpy(&iso9660->previous_pathname, iso9660->pathname.s); - - /* If this is a directory, read in all of the entries right now. */ - if (archive_entry_filetype(entry) == AE_IFDIR) { - while (iso9660->entry_bytes_remaining > 0) { - const void *block; - const unsigned char *p; - ssize_t step = iso9660->logical_block_size; - if (step > iso9660->entry_bytes_remaining) - step = iso9660->entry_bytes_remaining; - block = __archive_read_ahead(a, step, NULL); - if (block == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to read full block when scanning ISO9660 directory list"); - release_file(iso9660, file); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, step); - iso9660->current_position += step; - iso9660->entry_bytes_remaining -= step; - for (p = (const unsigned char *)block; - *p != 0 && p < (const unsigned char *)block + step; - p += *p) { - struct file_info *child; - - /* N.B.: these special directory identifiers - * are 8 bit "values" even on a - * Joliet CD with UCS-2 (16bit) encoding. - */ - - /* Skip '.' entry. */ - if (*(p + DR_name_len_offset) == 1 - && *(p + DR_name_offset) == '\0') - continue; - /* Skip '..' entry. */ - if (*(p + DR_name_len_offset) == 1 - && *(p + DR_name_offset) == '\001') - continue; - child = parse_file_info(a, file, p); - if (child == NULL) { - release_file(iso9660, file); - return (ARCHIVE_FATAL); - } - add_entry(iso9660, child); - } - } - } - - release_file(iso9660, file); - return (ARCHIVE_OK); + archive_entry_set_size(entry, file->pz_uncompressed_size); + } + + iso9660->previous_number = file->number; + if (iso9660->seenJoliet) { + memcpy(iso9660->utf16be_previous_path, iso9660->utf16be_path, + iso9660->utf16be_path_len); + iso9660->utf16be_previous_path_len = iso9660->utf16be_path_len; + } else + archive_strcpy( + &iso9660->previous_pathname, iso9660->pathname.s); + + /* Reset entry_bytes_remaining if the file is multi extent. */ + iso9660->entry_content = file->contents.first; + if (iso9660->entry_content != NULL) + iso9660->entry_bytes_remaining = iso9660->entry_content->size; + + if (archive_entry_filetype(entry) == AE_IFDIR) { + /* Overwrite nlinks by proper link number which is + * calculated from number of sub directories. */ + archive_entry_set_nlink(entry, 2 + file->subdirs); + /* Directory data has been read completely. */ + iso9660->entry_bytes_remaining = 0; + iso9660->entry_sparse_offset = 0; + } + + if (rd_r != ARCHIVE_OK) + return (rd_r); + return (ARCHIVE_OK); } static int archive_read_format_iso9660_read_data_skip(struct archive_read *a) { - /* Because read_next_header always does an explicit skip - * to the next entry, we don't need to do anything here. */ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); + /* Because read_next_header always does an explicit skip + * to the next entry, we don't need to do anything here. */ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); } #ifdef HAVE_ZLIB_H static int zisofs_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - struct iso9660 *iso9660; - struct zisofs *zisofs; - const unsigned char *p; - size_t avail; - ssize_t bytes_read; - size_t uncompressed_size; - int r; - - iso9660 = (struct iso9660 *)(a->format->data); - zisofs = &iso9660->entry_zisofs; - - p = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated zisofs file body"); - return (ARCHIVE_FATAL); - } - if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; - avail = bytes_read; - uncompressed_size = 0; - - if (!zisofs->initialized) { - size_t ceil, xsize; - - /* Allocate block pointers buffer. */ - ceil = (zisofs->pz_uncompressed_size + - (1UL << zisofs->pz_log2_bs) - 1) - >> zisofs->pz_log2_bs; - xsize = (ceil + 1) * 4; - if (zisofs->block_pointers_alloc < xsize) { - size_t alloc; - - if (zisofs->block_pointers != NULL) - free(zisofs->block_pointers); - alloc = ((xsize >> 10) + 1) << 10; - zisofs->block_pointers = malloc(alloc); - if (zisofs->block_pointers == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for zisofs decompression"); - return (ARCHIVE_FATAL); - } - zisofs->block_pointers_alloc = alloc; - } - zisofs->block_pointers_size = xsize; - - /* Allocate uncompressed data buffer. */ - xsize = 1UL << zisofs->pz_log2_bs; - if (zisofs->uncompressed_buffer_size < xsize) { - if (zisofs->uncompressed_buffer != NULL) - free(zisofs->uncompressed_buffer); - zisofs->uncompressed_buffer = malloc(xsize); - if (zisofs->uncompressed_buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for zisofs decompression"); - return (ARCHIVE_FATAL); - } - } - zisofs->uncompressed_buffer_size = xsize; - - /* - * Read the file header, and check the magic code of zisofs. - */ - if (zisofs->header_avail < sizeof(zisofs->header)) { - xsize = sizeof(zisofs->header) - zisofs->header_avail; - if (avail < xsize) - xsize = avail; - memcpy(zisofs->header + zisofs->header_avail, p, xsize); - zisofs->header_avail += xsize; - avail -= xsize; - p += xsize; - } - if (!zisofs->header_passed && - zisofs->header_avail == sizeof(zisofs->header)) { - int err = 0; - - if (memcmp(zisofs->header, zisofs_magic, - sizeof(zisofs_magic)) != 0) - err = 1; - if (archive_le32dec(zisofs->header + 8) - != zisofs->pz_uncompressed_size) - err = 1; - if (zisofs->header[12] != 4) - err = 1; - if (zisofs->header[13] != zisofs->pz_log2_bs) - err = 1; - if (err) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs file body"); - return (ARCHIVE_FATAL); - } - zisofs->header_passed = 1; - } - /* - * Read block pointers. - */ - if (zisofs->header_passed && - zisofs->block_pointers_avail < zisofs->block_pointers_size) { - xsize = zisofs->block_pointers_size - - zisofs->block_pointers_avail; - if (avail < xsize) - xsize = avail; - memcpy(zisofs->block_pointers - + zisofs->block_pointers_avail, p, xsize); - zisofs->block_pointers_avail += xsize; - avail -= xsize; - p += xsize; - if (zisofs->block_pointers_avail - == zisofs->block_pointers_size) { - /* We've got all block pointers and initialize - * related variables. */ - zisofs->block_off = 0; - zisofs->block_avail = 0; - /* Complete a initialization */ - zisofs->initialized = 1; - } - } - - if (!zisofs->initialized) - goto next_data; /* We need more datas. */ - } - - /* - * Get block offsets from block pointers. - */ - if (zisofs->block_avail == 0) { - uint32_t bst, bed; - - if (zisofs->block_off + 4 >= zisofs->block_pointers_size) { - /* There isn't a pair of offsets. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers"); - return (ARCHIVE_FATAL); - } - bst = archive_le32dec(zisofs->block_pointers + zisofs->block_off); - if (bst != zisofs->pz_offset + (bytes_read - avail)) { - /* TODO: Should we seek offset of current file by bst ? */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers(cannot seek)"); - return (ARCHIVE_FATAL); - } - bed = archive_le32dec( - zisofs->block_pointers + zisofs->block_off + 4); - if (bed < bst) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Illegal zisofs block pointers"); - return (ARCHIVE_FATAL); - } - zisofs->block_avail = bed - bst; - zisofs->block_off += 4; - - /* Initialize compression library for new block. */ - if (zisofs->stream_valid) - r = inflateReset(&zisofs->stream); - else - r = inflateInit(&zisofs->stream); - if (r != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Can't initialize zisofs decompression."); - return (ARCHIVE_FATAL); - } - zisofs->stream_valid = 1; - zisofs->stream.total_in = 0; - zisofs->stream.total_out = 0; - } - - /* - * Make uncompressed datas. - */ - if (zisofs->block_avail == 0) { - memset(zisofs->uncompressed_buffer, 0, - zisofs->uncompressed_buffer_size); - uncompressed_size = zisofs->uncompressed_buffer_size; - } else { - zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p; - if (avail > zisofs->block_avail) - zisofs->stream.avail_in = zisofs->block_avail; - else - zisofs->stream.avail_in = avail; - zisofs->stream.next_out = zisofs->uncompressed_buffer; - zisofs->stream.avail_out = zisofs->uncompressed_buffer_size; - - r = inflate(&zisofs->stream, 0); - switch (r) { - case Z_OK: /* Decompressor made some progress.*/ - case Z_STREAM_END: /* Found end of stream. */ - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "zisofs decompression failed (%d)", r); - return (ARCHIVE_FATAL); - } - uncompressed_size = - zisofs->uncompressed_buffer_size - zisofs->stream.avail_out; - avail -= zisofs->stream.next_in - p; - zisofs->block_avail -= zisofs->stream.next_in - p; - } + struct iso9660 *iso9660; + struct zisofs *zisofs; + const unsigned char *p; + size_t avail; + ssize_t bytes_read; + size_t uncompressed_size; + int r; + + iso9660 = (struct iso9660 *)(a->format->data); + zisofs = &iso9660->entry_zisofs; + + p = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated zisofs file body"); + return (ARCHIVE_FATAL); + } + if (bytes_read > iso9660->entry_bytes_remaining) + bytes_read = iso9660->entry_bytes_remaining; + avail = bytes_read; + uncompressed_size = 0; + + if (!zisofs->initialized) { + size_t ceil, xsize; + + /* Allocate block pointers buffer. */ + ceil = (zisofs->pz_uncompressed_size + + (((int64_t)1) << zisofs->pz_log2_bs) - 1) + >> zisofs->pz_log2_bs; + xsize = (ceil + 1) * 4; + if (zisofs->block_pointers_alloc < xsize) { + size_t alloc; + + if (zisofs->block_pointers != NULL) + free(zisofs->block_pointers); + alloc = ((xsize >> 10) + 1) << 10; + zisofs->block_pointers = malloc(alloc); + if (zisofs->block_pointers == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for zisofs decompression"); + return (ARCHIVE_FATAL); + } + zisofs->block_pointers_alloc = alloc; + } + zisofs->block_pointers_size = xsize; + + /* Allocate uncompressed data buffer. */ + xsize = 1UL << zisofs->pz_log2_bs; + if (zisofs->uncompressed_buffer_size < xsize) { + if (zisofs->uncompressed_buffer != NULL) + free(zisofs->uncompressed_buffer); + zisofs->uncompressed_buffer = malloc(xsize); + if (zisofs->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for zisofs decompression"); + return (ARCHIVE_FATAL); + } + } + zisofs->uncompressed_buffer_size = xsize; + + /* + * Read the file header, and check the magic code of zisofs. + */ + if (zisofs->header_avail < sizeof(zisofs->header)) { + xsize = sizeof(zisofs->header) - zisofs->header_avail; + if (avail < xsize) + xsize = avail; + memcpy(zisofs->header + zisofs->header_avail, p, xsize); + zisofs->header_avail += xsize; + avail -= xsize; + p += xsize; + } + if (!zisofs->header_passed && + zisofs->header_avail == sizeof(zisofs->header)) { + int err = 0; + + if (memcmp(zisofs->header, zisofs_magic, + sizeof(zisofs_magic)) != 0) + err = 1; + if (archive_le32dec(zisofs->header + 8) + != zisofs->pz_uncompressed_size) + err = 1; + if (zisofs->header[12] != 4) + err = 1; + if (zisofs->header[13] != zisofs->pz_log2_bs) + err = 1; + if (err) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs file body"); + return (ARCHIVE_FATAL); + } + zisofs->header_passed = 1; + } + /* + * Read block pointers. + */ + if (zisofs->header_passed && + zisofs->block_pointers_avail < zisofs->block_pointers_size) { + xsize = zisofs->block_pointers_size + - zisofs->block_pointers_avail; + if (avail < xsize) + xsize = avail; + memcpy(zisofs->block_pointers + + zisofs->block_pointers_avail, p, xsize); + zisofs->block_pointers_avail += xsize; + avail -= xsize; + p += xsize; + if (zisofs->block_pointers_avail + == zisofs->block_pointers_size) { + /* We've got all block pointers and initialize + * related variables. */ + zisofs->block_off = 0; + zisofs->block_avail = 0; + /* Complete a initialization */ + zisofs->initialized = 1; + } + } + + if (!zisofs->initialized) + goto next_data; /* We need more data. */ + } + + /* + * Get block offsets from block pointers. + */ + if (zisofs->block_avail == 0) { + uint32_t bst, bed; + + if (zisofs->block_off + 4 >= zisofs->block_pointers_size) { + /* There isn't a pair of offsets. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + bst = archive_le32dec( + zisofs->block_pointers + zisofs->block_off); + if (bst != zisofs->pz_offset + (bytes_read - avail)) { + /* TODO: Should we seek offset of current file + * by bst ? */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers(cannot seek)"); + return (ARCHIVE_FATAL); + } + bed = archive_le32dec( + zisofs->block_pointers + zisofs->block_off + 4); + if (bed < bst) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + zisofs->block_avail = bed - bst; + zisofs->block_off += 4; + + /* Initialize compression library for new block. */ + if (zisofs->stream_valid) + r = inflateReset(&zisofs->stream); + else + r = inflateInit(&zisofs->stream); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize zisofs decompression."); + return (ARCHIVE_FATAL); + } + zisofs->stream_valid = 1; + zisofs->stream.total_in = 0; + zisofs->stream.total_out = 0; + } + + /* + * Make uncompressed data. + */ + if (zisofs->block_avail == 0) { + memset(zisofs->uncompressed_buffer, 0, + zisofs->uncompressed_buffer_size); + uncompressed_size = zisofs->uncompressed_buffer_size; + } else { + zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p; + if (avail > zisofs->block_avail) + zisofs->stream.avail_in = zisofs->block_avail; + else + zisofs->stream.avail_in = avail; + zisofs->stream.next_out = zisofs->uncompressed_buffer; + zisofs->stream.avail_out = zisofs->uncompressed_buffer_size; + + r = inflate(&zisofs->stream, 0); + switch (r) { + case Z_OK: /* Decompressor made some progress.*/ + case Z_STREAM_END: /* Found end of stream. */ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zisofs decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + uncompressed_size = + zisofs->uncompressed_buffer_size - zisofs->stream.avail_out; + avail -= zisofs->stream.next_in - p; + zisofs->block_avail -= zisofs->stream.next_in - p; + } next_data: - bytes_read -= avail; - *buff = zisofs->uncompressed_buffer; - *size = uncompressed_size; - *offset = iso9660->entry_sparse_offset; - iso9660->entry_sparse_offset += uncompressed_size; - iso9660->entry_bytes_remaining -= bytes_read; - iso9660->current_position += bytes_read; - zisofs->pz_offset += bytes_read; - __archive_read_consume(a, bytes_read); - - return (ARCHIVE_OK); + bytes_read -= avail; + *buff = zisofs->uncompressed_buffer; + *size = uncompressed_size; + *offset = iso9660->entry_sparse_offset; + iso9660->entry_sparse_offset += uncompressed_size; + iso9660->entry_bytes_remaining -= bytes_read; + iso9660->current_position += bytes_read; + zisofs->pz_offset += bytes_read; + iso9660->entry_bytes_unconsumed += bytes_read; + + return (ARCHIVE_OK); } #else /* HAVE_ZLIB_H */ static int zisofs_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - (void)buff;/* UNUSED */ - (void)size;/* UNUSED */ - (void)offset;/* UNUSED */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "zisofs is not supported on this platform."); - return (ARCHIVE_FATAL); + (void)buff;/* UNUSED */ + (void)size;/* UNUSED */ + (void)offset;/* UNUSED */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "zisofs is not supported on this platform."); + return (ARCHIVE_FAILED); } #endif /* HAVE_ZLIB_H */ static int archive_read_format_iso9660_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - ssize_t bytes_read; - struct iso9660 *iso9660; - - iso9660 = (struct iso9660 *)(a->format->data); - if (iso9660->entry_bytes_remaining <= 0) { - *buff = NULL; - *size = 0; - *offset = iso9660->entry_sparse_offset; - return (ARCHIVE_EOF); - } - if (iso9660->entry_zisofs.pz) - return (zisofs_read_data(a, buff, size, offset)); - - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read == 0) - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated input file"); - if (*buff == NULL) - return (ARCHIVE_FATAL); - if (bytes_read > iso9660->entry_bytes_remaining) - bytes_read = iso9660->entry_bytes_remaining; - *size = bytes_read; - *offset = iso9660->entry_sparse_offset; - iso9660->entry_sparse_offset += bytes_read; - iso9660->entry_bytes_remaining -= bytes_read; - iso9660->current_position += bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); + ssize_t bytes_read; + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + if (iso9660->entry_bytes_unconsumed) { + __archive_read_consume(a, iso9660->entry_bytes_unconsumed); + iso9660->entry_bytes_unconsumed = 0; + } + + if (iso9660->entry_bytes_remaining <= 0) { + if (iso9660->entry_content != NULL) + iso9660->entry_content = iso9660->entry_content->next; + if (iso9660->entry_content == NULL) { + *buff = NULL; + *size = 0; + *offset = iso9660->entry_sparse_offset; + return (ARCHIVE_EOF); + } + /* Seek forward to the start of the entry. */ + if (iso9660->current_position < iso9660->entry_content->offset) { + int64_t step; + + step = iso9660->entry_content->offset - + iso9660->current_position; + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + iso9660->current_position = + iso9660->entry_content->offset; + } + if (iso9660->entry_content->offset < iso9660->current_position) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring out-of-order file (%s) %jd < %jd", + iso9660->pathname.s, + (intmax_t)iso9660->entry_content->offset, + (intmax_t)iso9660->current_position); + *buff = NULL; + *size = 0; + *offset = iso9660->entry_sparse_offset; + return (ARCHIVE_WARN); + } + iso9660->entry_bytes_remaining = iso9660->entry_content->size; + } + if (iso9660->entry_zisofs.pz) + return (zisofs_read_data(a, buff, size, offset)); + + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated input file"); + if (*buff == NULL) + return (ARCHIVE_FATAL); + if (bytes_read > iso9660->entry_bytes_remaining) + bytes_read = iso9660->entry_bytes_remaining; + *size = bytes_read; + *offset = iso9660->entry_sparse_offset; + iso9660->entry_sparse_offset += bytes_read; + iso9660->entry_bytes_remaining -= bytes_read; + iso9660->entry_bytes_unconsumed = bytes_read; + iso9660->current_position += bytes_read; + return (ARCHIVE_OK); } static int archive_read_format_iso9660_cleanup(struct archive_read *a) { - struct iso9660 *iso9660; - struct file_info *file; - int r = ARCHIVE_OK; - - iso9660 = (struct iso9660 *)(a->format->data); - while ((file = next_entry(iso9660)) != NULL) - release_file(iso9660, file); - archive_string_free(&iso9660->pathname); - archive_string_free(&iso9660->previous_pathname); - if (iso9660->pending_files) - free(iso9660->pending_files); + struct iso9660 *iso9660; + int r = ARCHIVE_OK; + + iso9660 = (struct iso9660 *)(a->format->data); + release_files(iso9660); + free(iso9660->read_ce_req.reqs); + archive_string_free(&iso9660->pathname); + archive_string_free(&iso9660->previous_pathname); + if (iso9660->pending_files.files) + free(iso9660->pending_files.files); #ifdef HAVE_ZLIB_H - free(iso9660->entry_zisofs.uncompressed_buffer); - free(iso9660->entry_zisofs.block_pointers); - if (iso9660->entry_zisofs.stream_valid) { - if (inflateEnd(&iso9660->entry_zisofs.stream) != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to clean up zlib decompressor"); - r = ARCHIVE_FATAL; - } - } + free(iso9660->entry_zisofs.uncompressed_buffer); + free(iso9660->entry_zisofs.block_pointers); + if (iso9660->entry_zisofs.stream_valid) { + if (inflateEnd(&iso9660->entry_zisofs.stream) != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + } #endif - free(iso9660); - (a->format->data) = NULL; - return (r); + free(iso9660->utf16be_path); + free(iso9660->utf16be_previous_path); + free(iso9660); + (a->format->data) = NULL; + return (r); } /* @@ -1210,438 +1720,715 @@ static struct file_info * parse_file_info(struct archive_read *a, struct file_info *parent, const unsigned char *isodirrec) { - struct iso9660 *iso9660; - struct file_info *file; - size_t name_len; - const unsigned char *rr_start, *rr_end; - const unsigned char *p; - size_t dr_len; - int32_t offset; - int flags; - - iso9660 = (struct iso9660 *)(a->format->data); - - dr_len = (size_t)isodirrec[DR_length_offset]; - name_len = (size_t)isodirrec[DR_name_len_offset]; - offset = archive_le32dec(isodirrec + DR_extent_offset); - /* Sanity check that dr_len needs at least 34. */ - if (dr_len < 34) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of directory record"); - return (NULL); - } - /* Sanity check that name_len doesn't exceed dr_len. */ - if (dr_len - 33 < name_len) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid length of file identifier"); - return (NULL); - } - /* Sanity check that offset doesn't exceed volume block. - * Don't check lower limit of offset; it's possibillty the offset - * has negative value when file type is symbolic link or - * file size is zero. As far as I know latest mkisofs do that. - */ - if (offset >= iso9660->volume_block) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid location of extent of file"); - return (NULL); - } - - /* Create a new file entry and copy data from the ISO dir record. */ - file = (struct file_info *)malloc(sizeof(*file)); - if (file == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for file entry"); - return (NULL); - } - memset(file, 0, sizeof(*file)); - file->parent = parent; - if (parent != NULL) - parent->refcount++; - file->offset = iso9660->logical_block_size * (uint64_t)offset; - file->size = toi(isodirrec + DR_size_offset, DR_size_size); - file->mtime = isodate7(isodirrec + DR_date_offset); - file->ctime = file->atime = file->mtime; - - p = isodirrec + DR_name_offset; - /* Rockridge extensions (if any) follow name. Compute this - * before fidgeting the name_len below. */ - rr_start = p + name_len + (name_len & 1 ? 0 : 1) + iso9660->suspOffset; - rr_end = isodirrec + isodirrec[DR_length_offset]; - - if (iso9660->seenJoliet) { - /* Joliet names are max 64 chars (128 bytes) according to spec, - * but genisoimage/mkisofs allows recording longer Joliet - * names which are 103 UCS2 characters(206 bytes) by their - * option '-joliet-long'. - */ - wchar_t wbuff[103+1], *wp; - const unsigned char *c; - - if (name_len > 206) - name_len = 206; - /* convert BE UTF-16 to wchar_t */ - for (c = p, wp = wbuff; - c < (p + name_len) && - wp < (wbuff + sizeof(wbuff)/sizeof(*wbuff) - 1); - c += 2) { - *wp++ = (((255 & (int)c[0]) << 8) | (255 & (int)c[1])); - } - *wp = L'\0'; - -#if 0 /* untested code, is it at all useful on Joliet? */ - /* trim trailing first version and dot from filename. - * - * Remember we where in UTF-16BE land! - * SEPARATOR 1 (.) and SEPARATOR 2 (;) are both - * 16 bits big endian characters on Joliet. - * - * TODO: sanitize filename? - * Joliet allows any UCS-2 char except: - * *, /, :, ;, ? and \. - */ - /* Chop off trailing ';1' from files. */ - if (*(wp-2) == ';' && *(wp-1) == '1') { - wp-=2; - *wp = L'\0'; - } - - /* Chop off trailing '.' from filenames. */ - if (*(wp-1) == '.') - *(--wp) = L'\0'; + struct iso9660 *iso9660; + struct file_info *file; + size_t name_len; + const unsigned char *rr_start, *rr_end; + const unsigned char *p; + size_t dr_len; + uint64_t fsize; + int32_t location; + int flags; + + iso9660 = (struct iso9660 *)(a->format->data); + + dr_len = (size_t)isodirrec[DR_length_offset]; + name_len = (size_t)isodirrec[DR_name_len_offset]; + location = archive_le32dec(isodirrec + DR_extent_offset); + fsize = toi(isodirrec + DR_size_offset, DR_size_size); + /* Sanity check that dr_len needs at least 34. */ + if (dr_len < 34) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid length of directory record"); + return (NULL); + } + /* Sanity check that name_len doesn't exceed dr_len. */ + if (dr_len - 33 < name_len || name_len == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid length of file identifier"); + return (NULL); + } + /* Sanity check that location doesn't exceed volume block. + * Don't check lower limit of location; it's possibility + * the location has negative value when file type is symbolic + * link or file size is zero. As far as I know latest mkisofs + * do that. + */ + if (location > 0 && + (location + ((fsize + iso9660->logical_block_size -1) + / iso9660->logical_block_size)) > iso9660->volume_block) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid location of extent of file"); + return (NULL); + } + /* Sanity check that location doesn't have a negative value + * when the file is not empty. it's too large. */ + if (fsize != 0 && location < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid location of extent of file"); + return (NULL); + } + + /* Create a new file entry and copy data from the ISO dir record. */ + file = (struct file_info *)calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for file entry"); + return (NULL); + } + file->parent = parent; + file->offset = iso9660->logical_block_size * (uint64_t)location; + file->size = fsize; + file->mtime = isodate7(isodirrec + DR_date_offset); + file->ctime = file->atime = file->mtime; + file->rede_files.first = NULL; + file->rede_files.last = &(file->rede_files.first); + + p = isodirrec + DR_name_offset; + /* Rockridge extensions (if any) follow name. Compute this + * before fidgeting the name_len below. */ + rr_start = p + name_len + (name_len & 1 ? 0 : 1); + rr_end = isodirrec + dr_len; + + if (iso9660->seenJoliet) { + /* Joliet names are max 64 chars (128 bytes) according to spec, + * but genisoimage/mkisofs allows recording longer Joliet + * names which are 103 UCS2 characters(206 bytes) by their + * option '-joliet-long'. + */ + if (name_len > 206) + name_len = 206; + name_len &= ~1; + + /* trim trailing first version and dot from filename. + * + * Remember we were in UTF-16BE land! + * SEPARATOR 1 (.) and SEPARATOR 2 (;) are both + * 16 bits big endian characters on Joliet. + * + * TODO: sanitize filename? + * Joliet allows any UCS-2 char except: + * *, /, :, ;, ? and \. + */ + /* Chop off trailing ';1' from files. */ + if (name_len > 4 && p[name_len-4] == 0 && p[name_len-3] == ';' + && p[name_len-2] == 0 && p[name_len-1] == '1') + name_len -= 4; +#if 0 /* XXX: this somehow manages to strip of single-character file extensions, like '.c'. */ + /* Chop off trailing '.' from filenames. */ + if (name_len > 2 && p[name_len-2] == 0 && p[name_len-1] == '.') + name_len -= 2; #endif - - /* store the result in the file name field. */ - archive_strappend_w_utf8(&file->name, wbuff); - } else { - /* Chop off trailing ';1' from files. */ - if (name_len > 2 && p[name_len - 2] == ';' && - p[name_len - 1] == '1') - name_len -= 2; - /* Chop off trailing '.' from filenames. */ - if (name_len > 1 && p[name_len - 1] == '.') - --name_len; - - archive_strncpy(&file->name, (const char *)p, name_len); - } - - flags = isodirrec[DR_flags_offset]; - if (flags & 0x02) - file->mode = AE_IFDIR | 0700; - else - file->mode = AE_IFREG | 0400; - - if (!iso9660->option_ignore_rockridge) - /* Rockridge extensions overwrite information from above. */ - parse_rockridge(iso9660, file, rr_start, rr_end); + if ((file->utf16be_name = malloc(name_len)) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for file name"); + return (NULL); + } + memcpy(file->utf16be_name, p, name_len); + file->utf16be_bytes = name_len; + } else { + /* Chop off trailing ';1' from files. */ + if (name_len > 2 && p[name_len - 2] == ';' && + p[name_len - 1] == '1') + name_len -= 2; + /* Chop off trailing '.' from filenames. */ + if (name_len > 1 && p[name_len - 1] == '.') + --name_len; + + archive_strncpy(&file->name, (const char *)p, name_len); + } + + flags = isodirrec[DR_flags_offset]; + if (flags & 0x02) + file->mode = AE_IFDIR | 0700; + else + file->mode = AE_IFREG | 0400; + if (flags & 0x80) + file->multi_extent = 1; + else + file->multi_extent = 0; + /* + * Use a location for the file number, which is treated as an inode + * number to find out hardlink target. If Rockridge extensions is + * being used, the file number will be overwritten by FILE SERIAL + * NUMBER of RRIP "PX" extension. + * Note: Old mkisofs did not record that FILE SERIAL NUMBER + * in ISO images. + * Note2: xorriso set 0 to the location of a symlink file. + */ + if (file->size == 0 && location >= 0) { + /* If file->size is zero, its location points wrong place, + * and so we should not use it for the file number. + * When the location has negative value, it can be used + * for the file number. + */ + file->number = -1; + /* Do not appear before any directory entries. */ + file->offset = -1; + } else + file->number = (int64_t)(uint32_t)location; + + /* Rockridge extensions overwrite information from above. */ + if (iso9660->opt_support_rockridge) { + if (parent == NULL && rr_end - rr_start >= 7) { + p = rr_start; + if (p[0] == 'S' && p[1] == 'P' + && p[2] == 7 && p[3] == 1 + && p[4] == 0xBE && p[5] == 0xEF) { + /* + * SP extension stores the suspOffset + * (Number of bytes to skip between + * filename and SUSP records.) + * It is mandatory by the SUSP standard + * (IEEE 1281). + * + * It allows SUSP to coexist with + * non-SUSP uses of the System + * Use Area by placing non-SUSP data + * before SUSP data. + * + * SP extension must be in the root + * directory entry, disable all SUSP + * processing if not found. + */ + iso9660->suspOffset = p[6]; + iso9660->seenSUSP = 1; + rr_start += 7; + } + } + if (iso9660->seenSUSP) { + int r; + + file->name_continues = 0; + file->symlink_continues = 0; + rr_start += iso9660->suspOffset; + r = parse_rockridge(a, file, rr_start, rr_end); + if (r != ARCHIVE_OK) { + free(file); + return (NULL); + } + } else + /* If there isn't SUSP, disable parsing + * rock ridge extensions. */ + iso9660->opt_support_rockridge = 0; + } + + file->nlinks = 1;/* Reset nlink. we'll calculate it later. */ + /* Tell file's parent how many children that parent has. */ + if (parent != NULL && (flags & 0x02)) + parent->subdirs++; + + if (iso9660->seenRockridge) { + if (parent != NULL && parent->parent == NULL && + (flags & 0x02) && iso9660->rr_moved == NULL && + (strcmp(file->name.s, "rr_moved") == 0 || + strcmp(file->name.s, ".rr_moved") == 0)) { + iso9660->rr_moved = file; + file->rr_moved = 1; + file->rr_moved_has_re_only = 1; + file->re = 0; + parent->subdirs--; + } else if (file->re) { + /* + * Sanity check: file's parent is rr_moved. + */ + if (parent == NULL || parent->rr_moved == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + return (NULL); + } + /* + * Sanity check: file does not have "CL" extension. + */ + if (file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE and CL"); + return (NULL); + } + /* + * Sanity check: The file type must be a directory. + */ + if ((flags & 0x02) == 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge RE"); + return (NULL); + } + } else if (parent != NULL && parent->rr_moved) + file->rr_moved_has_re_only = 0; + else if (parent != NULL && (flags & 0x02) && + (parent->re || parent->re_descendant)) + file->re_descendant = 1; + if (file->cl_offset) { + struct file_info *r; + + if (parent == NULL || parent->parent == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + /* + * Sanity check: The file type must be a regular file. + */ + if ((flags & 0x02) != 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + parent->subdirs++; + /* Overwrite an offset and a number of this "CL" entry + * to appear before other dirs. "+1" to those is to + * make sure to appear after "RE" entry which this + * "CL" entry should be connected with. */ + file->offset = file->number = file->cl_offset + 1; + + /* + * Sanity check: cl_offset does not point at its + * the parents or itself. + */ + for (r = parent; r; r = r->parent) { + if (r->offset == file->cl_offset) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + } + if (file->cl_offset == file->offset || + parent->rr_moved) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid Rockridge CL"); + return (NULL); + } + } + } #if DEBUG - /* DEBUGGING: Warn about attributes I don't yet fully support. */ - if ((flags & ~0x02) != 0) { - fprintf(stderr, "\n ** Unrecognized flag: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (toi(isodirrec + DR_volume_sequence_number_offset, 2) != 1) { - fprintf(stderr, "\n ** Unrecognized sequence number: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_file_unit_size_offset) != 0) { - fprintf(stderr, "\n ** Unexpected file unit size: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_interleave_offset) != 0) { - fprintf(stderr, "\n ** Unexpected interleave: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } else if (*(isodirrec + DR_ext_attr_length_offset) != 0) { - fprintf(stderr, "\n ** Unexpected extended attribute length: "); - dump_isodirrec(stderr, isodirrec); - fprintf(stderr, "\n"); - } + /* DEBUGGING: Warn about attributes I don't yet fully support. */ + if ((flags & ~0x02) != 0) { + fprintf(stderr, "\n ** Unrecognized flag: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (toi(isodirrec + DR_volume_sequence_number_offset, 2) != 1) { + fprintf(stderr, "\n ** Unrecognized sequence number: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_file_unit_size_offset) != 0) { + fprintf(stderr, "\n ** Unexpected file unit size: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_interleave_offset) != 0) { + fprintf(stderr, "\n ** Unexpected interleave: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } else if (*(isodirrec + DR_ext_attr_length_offset) != 0) { + fprintf(stderr, "\n ** Unexpected extended attribute length: "); + dump_isodirrec(stderr, isodirrec); + fprintf(stderr, "\n"); + } #endif - return (file); + register_file(iso9660, file); + return (file); } -static void -add_entry(struct iso9660 *iso9660, struct file_info *file) +static int +parse_rockridge(struct archive_read *a, struct file_info *file, + const unsigned char *p, const unsigned char *end) { - uint64_t file_offset, parent_offset; - int hole, parent; - - /* Expand our pending files list as necessary. */ - if (iso9660->pending_files_used >= iso9660->pending_files_allocated) { - struct file_info **new_pending_files; - int new_size = iso9660->pending_files_allocated * 2; - - if (iso9660->pending_files_allocated < 1024) - new_size = 1024; - /* Overflow might keep us from growing the list. */ - if (new_size <= iso9660->pending_files_allocated) - __archive_errx(1, "Out of memory"); - new_pending_files = (struct file_info **)malloc(new_size * sizeof(new_pending_files[0])); - if (new_pending_files == NULL) - __archive_errx(1, "Out of memory"); - memcpy(new_pending_files, iso9660->pending_files, - iso9660->pending_files_allocated * sizeof(new_pending_files[0])); - if (iso9660->pending_files != NULL) - free(iso9660->pending_files); - iso9660->pending_files = new_pending_files; - iso9660->pending_files_allocated = new_size; - } - - file_offset = file->offset + file->size; - - /* - * Start with hole at end, walk it up tree to find insertion point. - */ - hole = iso9660->pending_files_used++; - while (hole > 0) { - parent = (hole - 1)/2; - parent_offset = iso9660->pending_files[parent]->offset - + iso9660->pending_files[parent]->size; - if (file_offset >= parent_offset) { - iso9660->pending_files[hole] = file; - return; - } - /* Move parent into hole <==> move hole up tree. */ - iso9660->pending_files[hole] = iso9660->pending_files[parent]; - hole = parent; - } - iso9660->pending_files[0] = file; + struct iso9660 *iso9660; + + iso9660 = (struct iso9660 *)(a->format->data); + + while (p + 4 <= end /* Enough space for another entry. */ + && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ + && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ + && p[2] >= 4 /* Sanity-check length. */ + && p + p[2] <= end) { /* Sanity-check length. */ + const unsigned char *data = p + 4; + int data_length = p[2] - 4; + int version = p[3]; + + /* + * Yes, each 'if' here does test p[0] again. + * Otherwise, the fall-through handling to catch + * unsupported extensions doesn't work. + */ + switch(p[0]) { + case 'C': + if (p[0] == 'C' && p[1] == 'E') { + if (version == 1 && data_length == 24) { + /* + * CE extension comprises: + * 8 byte sector containing extension + * 8 byte offset w/in above sector + * 8 byte length of continuation + */ + int32_t location = + archive_le32dec(data); + file->ce_offset = + archive_le32dec(data+8); + file->ce_size = + archive_le32dec(data+16); + if (register_CE(a, location, file) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + break; + } + if (p[0] == 'C' && p[1] == 'L') { + if (version == 1 && data_length == 8) { + file->cl_offset = (uint64_t) + iso9660->logical_block_size * + (uint64_t)archive_le32dec(data); + iso9660->seenRockridge = 1; + } + break; + } + /* FALLTHROUGH */ + case 'N': + if (p[0] == 'N' && p[1] == 'M') { + if (version == 1) { + parse_rockridge_NM1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + break; + } + /* FALLTHROUGH */ + case 'P': + if (p[0] == 'P' && p[1] == 'D') { + /* + * PD extension is padding; + * contents are always ignored. + */ + break; + } + if (p[0] == 'P' && p[1] == 'L') { + /* + * PL extension won't appear; + * contents are always ignored. + */ + break; + } + if (p[0] == 'P' && p[1] == 'N') { + if (version == 1 && data_length == 16) { + file->rdev = toi(data,4); + file->rdev <<= 32; + file->rdev |= toi(data + 8, 4); + iso9660->seenRockridge = 1; + } + break; + } + if (p[0] == 'P' && p[1] == 'X') { + /* + * PX extension comprises: + * 8 bytes for mode, + * 8 bytes for nlinks, + * 8 bytes for uid, + * 8 bytes for gid, + * 8 bytes for inode. + */ + if (version == 1) { + if (data_length >= 8) + file->mode + = toi(data, 4); + if (data_length >= 16) + file->nlinks + = toi(data + 8, 4); + if (data_length >= 24) + file->uid + = toi(data + 16, 4); + if (data_length >= 32) + file->gid + = toi(data + 24, 4); + if (data_length >= 40) + file->number + = toi(data + 32, 4); + iso9660->seenRockridge = 1; + } + break; + } + /* FALLTHROUGH */ + case 'R': + if (p[0] == 'R' && p[1] == 'E' && version == 1) { + file->re = 1; + iso9660->seenRockridge = 1; + break; + } + if (p[0] == 'R' && p[1] == 'R' && version == 1) { + /* + * RR extension comprises: + * one byte flag value + * This extension is obsolete, + * so contents are always ignored. + */ + break; + } + /* FALLTHROUGH */ + case 'S': + if (p[0] == 'S' && p[1] == 'L') { + if (version == 1) { + parse_rockridge_SL1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + break; + } + if (p[0] == 'S' && p[1] == 'T' + && data_length == 0 && version == 1) { + /* + * ST extension marks end of this + * block of SUSP entries. + * + * It allows SUSP to coexist with + * non-SUSP uses of the System + * Use Area by placing non-SUSP data + * after SUSP data. + */ + iso9660->seenSUSP = 0; + iso9660->seenRockridge = 0; + return (ARCHIVE_OK); + } + case 'T': + if (p[0] == 'T' && p[1] == 'F') { + if (version == 1) { + parse_rockridge_TF1(file, + data, data_length); + iso9660->seenRockridge = 1; + } + break; + } + /* FALLTHROUGH */ + case 'Z': + if (p[0] == 'Z' && p[1] == 'F') { + if (version == 1) + parse_rockridge_ZF1(file, + data, data_length); + break; + } + /* FALLTHROUGH */ + default: + /* The FALLTHROUGHs above leave us here for + * any unsupported extension. */ + break; + } + + + + p += p[2]; + } + return (ARCHIVE_OK); } -static void -parse_rockridge(struct iso9660 *iso9660, struct file_info *file, - const unsigned char *p, const unsigned char *end) +static int +register_CE(struct archive_read *a, int32_t location, + struct file_info *file) { - (void)iso9660; /* UNUSED */ - file->name_continues = 0; - file->symlink_continues = 0; - - while (p + 4 < end /* Enough space for another entry. */ - && p[0] >= 'A' && p[0] <= 'Z' /* Sanity-check 1st char of name. */ - && p[1] >= 'A' && p[1] <= 'Z' /* Sanity-check 2nd char of name. */ - && p[2] >= 4 /* Sanity-check length. */ - && p + p[2] <= end) { /* Sanity-check length. */ - const unsigned char *data = p + 4; - int data_length = p[2] - 4; - int version = p[3]; - - /* - * Yes, each 'if' here does test p[0] again. - * Otherwise, the fall-through handling to catch - * unsupported extensions doesn't work. - */ - switch(p[0]) { - case 'C': - if (p[0] == 'C' && p[1] == 'E') { - if (version == 1 && data_length == 24) { - /* - * CE extension comprises: - * 8 byte sector containing extension - * 8 byte offset w/in above sector - * 8 byte length of continuation - */ - file->ce_offset = (uint64_t)toi(data, 4) - * iso9660->logical_block_size - + toi(data + 8, 4); - file->ce_size = toi(data + 16, 4); - /* If the result is rediculous, - * ignore it. */ - if (file->ce_offset + file->ce_size - > iso9660->volume_size) { - file->ce_offset = 0; - file->ce_size = 0; - } - } - break; - } - /* FALLTHROUGH */ - case 'N': - if (p[0] == 'N' && p[1] == 'M') { - if (version == 1) - parse_rockridge_NM1(file, - data, data_length); - break; - } - /* FALLTHROUGH */ - case 'P': - if (p[0] == 'P' && p[1] == 'D') { - /* - * PD extension is padding; - * contents are always ignored. - */ - break; - } - if (p[0] == 'P' && p[1] == 'N') { - if (version == 1 && data_length == 16) { - file->rdev = toi(data,4); - file->rdev <<= 32; - file->rdev |= toi(data + 8, 4); - } - break; - } - if (p[0] == 'P' && p[1] == 'X') { - /* - * PX extension comprises: - * 8 bytes for mode, - * 8 bytes for nlinks, - * 8 bytes for uid, - * 8 bytes for gid, - * 8 bytes for inode. - */ - if (version == 1) { - if (data_length >= 8) - file->mode - = toi(data, 4); - if (data_length >= 16) - file->nlinks - = toi(data + 8, 4); - if (data_length >= 24) - file->uid - = toi(data + 16, 4); - if (data_length >= 32) - file->gid - = toi(data + 24, 4); - if (data_length >= 40) - file->inode - = toi(data + 32, 4); - } - break; - } - /* FALLTHROUGH */ - case 'R': - if (p[0] == 'R' && p[1] == 'R' && version == 1) { - iso9660->seenRockridge = 1; - /* - * RR extension comprises: - * one byte flag value - */ - /* TODO: Handle RR extension. */ - break; - } - /* FALLTHROUGH */ - case 'S': - if (p[0] == 'S' && p[1] == 'L') { - if (version == 1) - parse_rockridge_SL1(file, - data, data_length); - break; - } - if (p[0] == 'S' && p[1] == 'P' - && version == 1 && data_length == 3 - && data[0] == (unsigned char)'\xbe' - && data[1] == (unsigned char)'\xef') { - /* - * SP extension stores the suspOffset - * (Number of bytes to skip between - * filename and SUSP records.) - * It is mandatory by the SUSP standard - * (IEEE 1281). - * - * It allows SUSP to coexist with - * non-SUSP uses of the System - * Use Area by placing non-SUSP data - * before SUSP data. - * - * TODO: Add a check for 'SP' in - * first directory entry, disable all SUSP - * processing if not found. - */ - iso9660->suspOffset = data[2]; - break; - } - if (p[0] == 'S' && p[1] == 'T' - && data_length == 0 && version == 1) { - /* - * ST extension marks end of this - * block of SUSP entries. - * - * It allows SUSP to coexist with - * non-SUSP uses of the System - * Use Area by placing non-SUSP data - * after SUSP data. - */ - return; - } - case 'T': - if (p[0] == 'T' && p[1] == 'F') { - if (version == 1) - parse_rockridge_TF1(file, - data, data_length); - break; - } - /* FALLTHROUGH */ - case 'Z': - if (p[0] == 'Z' && p[1] == 'F') { - if (version == 1) - parse_rockridge_ZF1(file, - data, data_length); - break; - } - /* FALLTHROUGH */ - default: - /* The FALLTHROUGHs above leave us here for - * any unsupported extension. */ -#if DEBUG - { - const unsigned char *t; - fprintf(stderr, "\nUnsupported RRIP extension for %s\n", file->name.s); - fprintf(stderr, " %c%c(%d):", p[0], p[1], data_length); - for (t = data; t < data + data_length && t < data + 16; t++) - fprintf(stderr, " %02x", *t); - fprintf(stderr, "\n"); - } -#endif - break; - } + struct iso9660 *iso9660; + struct read_ce_queue *heap; + struct read_ce_req *p; + uint64_t offset, parent_offset; + int hole, parent; + + iso9660 = (struct iso9660 *)(a->format->data); + offset = ((uint64_t)location) * (uint64_t)iso9660->logical_block_size; + if (((file->mode & AE_IFMT) == AE_IFREG && + offset >= file->offset) || + offset < iso9660->current_position || + (((uint64_t)file->ce_offset) + file->ce_size) + > iso9660->logical_block_size || + offset + file->ce_offset + file->ce_size + > iso9660->volume_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid parameter in SUSP \"CE\" extension"); + return (ARCHIVE_FATAL); + } + + /* Expand our CE list as necessary. */ + heap = &(iso9660->read_ce_req); + if (heap->cnt >= heap->allocated) { + int new_size; + + if (heap->allocated < 16) + new_size = 16; + else + new_size = heap->allocated * 2; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + p = malloc(new_size * sizeof(p[0])); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + if (heap->reqs != NULL) { + memcpy(p, heap->reqs, heap->cnt * sizeof(*p)); + free(heap->reqs); + } + heap->reqs = p; + heap->allocated = new_size; + } + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->cnt++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_offset = heap->reqs[parent].offset; + if (offset >= parent_offset) { + heap->reqs[hole].offset = offset; + heap->reqs[hole].file = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->reqs[hole] = heap->reqs[parent]; + hole = parent; + } + heap->reqs[0].offset = offset; + heap->reqs[0].file = file; + return (ARCHIVE_OK); +} +static void +next_CE(struct read_ce_queue *heap) +{ + uint64_t a_offset, b_offset, c_offset; + int a, b, c; + struct read_ce_req tmp; + + if (heap->cnt < 1) + return; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->reqs[0] = heap->reqs[--(heap->cnt)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its offset */ + a_offset = heap->reqs[a].offset; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->cnt) + return; + b_offset = heap->reqs[b].offset; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->cnt) { + c_offset = heap->reqs[c].offset; + if (c_offset < b_offset) { + b = c; + b_offset = c_offset; + } + } + if (a_offset <= b_offset) + return; + tmp = heap->reqs[a]; + heap->reqs[a] = heap->reqs[b]; + heap->reqs[b] = tmp; + a = b; + } +} - p += p[2]; - } +static int +read_CE(struct archive_read *a, struct iso9660 *iso9660) +{ + struct read_ce_queue *heap; + const unsigned char *b, *p, *end; + struct file_info *file; + size_t step; + int r; + + /* Read data which RRIP "CE" extension points. */ + heap = &(iso9660->read_ce_req); + step = iso9660->logical_block_size; + while (heap->cnt && + heap->reqs[0].offset == iso9660->current_position) { + b = __archive_read_ahead(a, step, NULL); + if (b == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to read full block when scanning " + "ISO9660 directory list"); + return (ARCHIVE_FATAL); + } + do { + file = heap->reqs[0].file; + if (file->ce_offset + file->ce_size > step) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed CE information"); + return (ARCHIVE_FATAL); + } + p = b + file->ce_offset; + end = p + file->ce_size; + next_CE(heap); + r = parse_rockridge(a, file, p, end); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } while (heap->cnt && + heap->reqs[0].offset == iso9660->current_position); + /* NOTE: Do not move this consume's code to fron of + * do-while loop. Registration of nested CE extension + * might cause error because of current position. */ + __archive_read_consume(a, step); + iso9660->current_position += step; + } + return (ARCHIVE_OK); } static void parse_rockridge_NM1(struct file_info *file, - const unsigned char *data, int data_length) + const unsigned char *data, int data_length) { - if (!file->name_continues) - archive_string_empty(&file->name); - file->name_continues = 0; - if (data_length < 1) - return; - /* - * NM version 1 extension comprises: - * 1 byte flag, value is one of: - * = 0: remainder is name - * = 1: remainder is name, next NM entry continues name - * = 2: "." - * = 4: ".." - * = 32: Implementation specific - * All other values are reserved. - */ - switch(data[0]) { - case 0: - if (data_length < 2) - return; - archive_strncat(&file->name, (const char *)data + 1, data_length - 1); - break; - case 1: - if (data_length < 2) - return; - archive_strncat(&file->name, (const char *)data + 1, data_length - 1); - file->name_continues = 1; - break; - case 2: - archive_strcat(&file->name, "."); - break; - case 4: - archive_strcat(&file->name, ".."); - break; - default: - return; - } + if (!file->name_continues) + archive_string_empty(&file->name); + file->name_continues = 0; + if (data_length < 1) + return; + /* + * NM version 1 extension comprises: + * 1 byte flag, value is one of: + * = 0: remainder is name + * = 1: remainder is name, next NM entry continues name + * = 2: "." + * = 4: ".." + * = 32: Implementation specific + * All other values are reserved. + */ + switch(data[0]) { + case 0: + if (data_length < 2) + return; + archive_strncat(&file->name, + (const char *)data + 1, data_length - 1); + break; + case 1: + if (data_length < 2) + return; + archive_strncat(&file->name, + (const char *)data + 1, data_length - 1); + file->name_continues = 1; + break; + case 2: + archive_strcat(&file->name, "."); + break; + case 4: + archive_strcat(&file->name, ".."); + break; + default: + return; + } } @@ -1649,164 +2436,163 @@ static void parse_rockridge_TF1(struct file_info *file, const unsigned char *data, int data_length) { - char flag; - /* - * TF extension comprises: - * one byte flag - * create time (optional) - * modify time (optional) - * access time (optional) - * attribute time (optional) - * Time format and presence of fields - * is controlled by flag bits. - */ - if (data_length < 1) - return; - flag = data[0]; - ++data; - --data_length; - if (flag & 0x80) { - /* Use 17-byte time format. */ - if ((flag & 1) && data_length >= 17) { - /* Create time. */ - file->birthtime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 2) && data_length >= 17) { - /* Modify time. */ - file->mtime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 4) && data_length >= 17) { - /* Access time. */ - file->atime = isodate17(data); - data += 17; - data_length -= 17; - } - if ((flag & 8) && data_length >= 17) { - /* Attribute change time. */ - file->ctime = isodate17(data); - data += 17; - data_length -= 17; - } - } else { - /* Use 7-byte time format. */ - if ((flag & 1) && data_length >= 7) { - /* Create time. */ - file->birthtime = isodate17(data); - data += 7; - data_length -= 7; - } - if ((flag & 2) && data_length >= 7) { - /* Modify time. */ - file->mtime = isodate7(data); - data += 7; - data_length -= 7; - } - if ((flag & 4) && data_length >= 7) { - /* Access time. */ - file->atime = isodate7(data); - data += 7; - data_length -= 7; - } - if ((flag & 8) && data_length >= 7) { - /* Attribute change time. */ - file->ctime = isodate7(data); - data += 7; - data_length -= 7; - } - } + char flag; + /* + * TF extension comprises: + * one byte flag + * create time (optional) + * modify time (optional) + * access time (optional) + * attribute time (optional) + * Time format and presence of fields + * is controlled by flag bits. + */ + if (data_length < 1) + return; + flag = data[0]; + ++data; + --data_length; + if (flag & 0x80) { + /* Use 17-byte time format. */ + if ((flag & 1) && data_length >= 17) { + /* Create time. */ + file->birthtime_is_set = 1; + file->birthtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 2) && data_length >= 17) { + /* Modify time. */ + file->mtime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 4) && data_length >= 17) { + /* Access time. */ + file->atime = isodate17(data); + data += 17; + data_length -= 17; + } + if ((flag & 8) && data_length >= 17) { + /* Attribute change time. */ + file->ctime = isodate17(data); + } + } else { + /* Use 7-byte time format. */ + if ((flag & 1) && data_length >= 7) { + /* Create time. */ + file->birthtime_is_set = 1; + file->birthtime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 2) && data_length >= 7) { + /* Modify time. */ + file->mtime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 4) && data_length >= 7) { + /* Access time. */ + file->atime = isodate7(data); + data += 7; + data_length -= 7; + } + if ((flag & 8) && data_length >= 7) { + /* Attribute change time. */ + file->ctime = isodate7(data); + } + } } static void parse_rockridge_SL1(struct file_info *file, const unsigned char *data, int data_length) { - const char *separator = ""; - - if (!file->symlink_continues || file->symlink.length < 1) - archive_string_empty(&file->symlink); - else if (file->symlink.s[file->symlink.length - 1] != '/') - separator = "/"; - file->symlink_continues = 0; - - /* - * Defined flag values: - * 0: This is the last SL record for this symbolic link - * 1: this symbolic link field continues in next SL entry - * All other values are reserved. - */ - if (data_length < 1) - return; - switch(*data) { - case 0: - break; - case 1: - file->symlink_continues = 1; - break; - default: - return; - } - ++data; /* Skip flag byte. */ - --data_length; - - /* - * SL extension body stores "components". - * Basically, this is a complicated way of storing - * a POSIX path. It also interferes with using - * symlinks for storing non-path data. - * - * Each component is 2 bytes (flag and length) - * possibly followed by name data. - */ - while (data_length >= 2) { - unsigned char flag = *data++; - unsigned char nlen = *data++; - data_length -= 2; - - archive_strcat(&file->symlink, separator); - separator = "/"; - - switch(flag) { - case 0: /* Usual case, this is text. */ - if (data_length < nlen) - return; - archive_strncat(&file->symlink, - (const char *)data, nlen); - break; - case 0x01: /* Text continues in next component. */ - if (data_length < nlen) - return; - archive_strncat(&file->symlink, - (const char *)data, nlen); - separator = ""; - break; - case 0x02: /* Current dir. */ - archive_strcat(&file->symlink, "."); - break; - case 0x04: /* Parent dir. */ - archive_strcat(&file->symlink, ".."); - break; - case 0x08: /* Root of filesystem. */ - archive_strcat(&file->symlink, "/"); - separator = ""; - break; - case 0x10: /* Undefined (historically "volume root" */ - archive_string_empty(&file->symlink); - archive_strcat(&file->symlink, "ROOT"); - break; - case 0x20: /* Undefined (historically "hostname") */ - archive_strcat(&file->symlink, "hostname"); - break; - default: - /* TODO: issue a warning ? */ - return; - } - data += nlen; - data_length -= nlen; - } + const char *separator = ""; + + if (!file->symlink_continues || file->symlink.length < 1) + archive_string_empty(&file->symlink); + else if (!file->symlink_continues && + file->symlink.s[file->symlink.length - 1] != '/') + separator = "/"; + file->symlink_continues = 0; + + /* + * Defined flag values: + * 0: This is the last SL record for this symbolic link + * 1: this symbolic link field continues in next SL entry + * All other values are reserved. + */ + if (data_length < 1) + return; + switch(*data) { + case 0: + break; + case 1: + file->symlink_continues = 1; + break; + default: + return; + } + ++data; /* Skip flag byte. */ + --data_length; + + /* + * SL extension body stores "components". + * Basically, this is a complicated way of storing + * a POSIX path. It also interferes with using + * symlinks for storing non-path data. + * + * Each component is 2 bytes (flag and length) + * possibly followed by name data. + */ + while (data_length >= 2) { + unsigned char flag = *data++; + unsigned char nlen = *data++; + data_length -= 2; + + archive_strcat(&file->symlink, separator); + separator = "/"; + + switch(flag) { + case 0: /* Usual case, this is text. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + break; + case 0x01: /* Text continues in next component. */ + if (data_length < nlen) + return; + archive_strncat(&file->symlink, + (const char *)data, nlen); + separator = ""; + break; + case 0x02: /* Current dir. */ + archive_strcat(&file->symlink, "."); + break; + case 0x04: /* Parent dir. */ + archive_strcat(&file->symlink, ".."); + break; + case 0x08: /* Root of filesystem. */ + archive_strcat(&file->symlink, "/"); + separator = ""; + break; + case 0x10: /* Undefined (historically "volume root" */ + archive_string_empty(&file->symlink); + archive_strcat(&file->symlink, "ROOT"); + break; + case 0x20: /* Undefined (historically "hostname") */ + archive_strcat(&file->symlink, "hostname"); + break; + default: + /* TODO: issue a warning ? */ + return; + } + data += nlen; + data_length -= nlen; + } } static void @@ -1814,263 +2600,614 @@ parse_rockridge_ZF1(struct file_info *file, const unsigned char *data, int data_length) { - if (data[0] == 0x70 && data[1] == 0x7a && data_length == 12) { - /* paged zlib */ - file->pz = 1; - file->pz_log2_bs = data[3]; - file->pz_uncompressed_size = archive_le32dec(&data[4]); - } + if (data[0] == 0x70 && data[1] == 0x7a && data_length == 12) { + /* paged zlib */ + file->pz = 1; + file->pz_log2_bs = data[3]; + file->pz_uncompressed_size = archive_le32dec(&data[4]); + } } +static void +register_file(struct iso9660 *iso9660, struct file_info *file) +{ + + file->use_next = iso9660->use_files; + iso9660->use_files = file; +} static void -release_file(struct iso9660 *iso9660, struct file_info *file) +release_files(struct iso9660 *iso9660) { - struct file_info *parent; - - if (file == NULL) - return; - - if (file->refcount == 0) { - parent = file->parent; - archive_string_free(&file->name); - archive_string_free(&file->symlink); - free(file); - if (parent != NULL) { - parent->refcount--; - release_file(iso9660, parent); - } - } + struct content *con, *connext; + struct file_info *file; + + file = iso9660->use_files; + while (file != NULL) { + struct file_info *next = file->use_next; + + archive_string_free(&file->name); + archive_string_free(&file->symlink); + free(file->utf16be_name); + con = file->contents.first; + while (con != NULL) { + connext = con->next; + free(con); + con = connext; + } + free(file); + file = next; + } } static int next_entry_seek(struct archive_read *a, struct iso9660 *iso9660, struct file_info **pfile) { - struct file_info *file; - uint64_t offset; - - *pfile = NULL; - for (;;) { - *pfile = file = next_entry(iso9660); - if (file == NULL) - return (ARCHIVE_EOF); - - /* CE area precedes actual file data? Ignore it. */ - if (file->ce_offset > file->offset) { - /* fprintf(stderr, " *** Discarding CE data.\n"); */ - file->ce_offset = 0; - file->ce_size = 0; - } - - /* Don't waste time seeking for zero-length bodies. */ - if (file->size == 0) { - file->offset = iso9660->current_position; - } - - /* If CE exists, find and read it now. */ - if (file->ce_offset > 0) - offset = file->ce_offset; - else - offset = file->offset; - - /* Seek forward to the start of the entry. */ - if (iso9660->current_position < offset) { - off_t step = offset - iso9660->current_position; - off_t bytes_read; - bytes_read = __archive_read_skip(a, step); - if (bytes_read < 0) - return (bytes_read); - iso9660->current_position = offset; - } - - /* We found body of file; handle it now. */ - if (offset == file->offset) - return (ARCHIVE_OK); - - /* Found CE? Process it and push the file back onto list. */ - if (offset == file->ce_offset) { - const void *p; - ssize_t size = file->ce_size; - const unsigned char *rr_start; - - file->ce_offset = 0; - file->ce_size = 0; - p = __archive_read_ahead(a, size, NULL); - if (p == NULL) - return (ARCHIVE_FATAL); - rr_start = (const unsigned char *)p; - parse_rockridge(iso9660, file, rr_start, - rr_start + size); - __archive_read_consume(a, size); - iso9660->current_position += size; - add_entry(iso9660, file); - } - } + struct file_info *file; + int r; + + r = next_cache_entry(a, iso9660, pfile); + if (r != ARCHIVE_OK) + return (r); + file = *pfile; + + /* Don't waste time seeking for zero-length bodies. */ + if (file->size == 0) + file->offset = iso9660->current_position; + + /* flush any remaining bytes from the last round to ensure + * we're positioned */ + if (iso9660->entry_bytes_unconsumed) { + __archive_read_consume(a, iso9660->entry_bytes_unconsumed); + iso9660->entry_bytes_unconsumed = 0; + } + + /* Seek forward to the start of the entry. */ + if (iso9660->current_position < file->offset) { + int64_t step; + + step = file->offset - iso9660->current_position; + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + iso9660->current_position = file->offset; + } + + /* We found body of file; handle it now. */ + return (ARCHIVE_OK); +} + +static int +next_cache_entry(struct archive_read *a, struct iso9660 *iso9660, + struct file_info **pfile) +{ + struct file_info *file; + struct { + struct file_info *first; + struct file_info **last; + } empty_files; + int64_t number; + int count; + + file = cache_get_entry(iso9660); + if (file != NULL) { + *pfile = file; + return (ARCHIVE_OK); + } + + for (;;) { + struct file_info *re, *d; + + *pfile = file = next_entry(iso9660); + if (file == NULL) { + /* + * If directory entries all which are descendant of + * rr_moved are stil remaning, expose their. + */ + if (iso9660->re_files.first != NULL && + iso9660->rr_moved != NULL && + iso9660->rr_moved->rr_moved_has_re_only) + /* Expose "rr_moved" entry. */ + cache_add_entry(iso9660, iso9660->rr_moved); + while ((re = re_get_entry(iso9660)) != NULL) { + /* Expose its descendant dirs. */ + while ((d = rede_get_entry(re)) != NULL) + cache_add_entry(iso9660, d); + } + if (iso9660->cache_files.first != NULL) + return (next_cache_entry(a, iso9660, pfile)); + return (ARCHIVE_EOF); + } + + if (file->cl_offset) { + struct file_info *first_re = NULL; + int nexted_re = 0; + + /* + * Find "RE" dir for the current file, which + * has "CL" flag. + */ + while ((re = re_get_entry(iso9660)) + != first_re) { + if (first_re == NULL) + first_re = re; + if (re->offset == file->cl_offset) { + re->parent->subdirs--; + re->parent = file->parent; + re->re = 0; + if (re->parent->re_descendant) { + nexted_re = 1; + re->re_descendant = 1; + if (rede_add_entry(re) < 0) + goto fatal_rr; + /* Move a list of descendants + * to a new ancestor. */ + while ((d = rede_get_entry( + re)) != NULL) + if (rede_add_entry(d) + < 0) + goto fatal_rr; + break; + } + /* Replace the current file + * with "RE" dir */ + *pfile = file = re; + /* Expose its descendant */ + while ((d = rede_get_entry( + file)) != NULL) + cache_add_entry( + iso9660, d); + break; + } else + re_add_entry(iso9660, re); + } + if (nexted_re) { + /* + * Do not expose this at this time + * because we have not gotten its full-path + * name yet. + */ + continue; + } + } else if ((file->mode & AE_IFMT) == AE_IFDIR) { + int r; + + /* Read file entries in this dir. */ + r = read_children(a, file); + if (r != ARCHIVE_OK) + return (r); + + /* + * Handle a special dir of Rockridge extensions, + * "rr_moved". + */ + if (file->rr_moved) { + /* + * If this has only the subdirectories which + * have "RE" flags, do not expose at this time. + */ + if (file->rr_moved_has_re_only) + continue; + /* Otherwise expose "rr_moved" entry. */ + } else if (file->re) { + /* + * Do not expose this at this time + * because we have not gotten its full-path + * name yet. + */ + re_add_entry(iso9660, file); + continue; + } else if (file->re_descendant) { + /* + * If the top level "RE" entry of this entry + * is not exposed, we, accordingly, should not + * expose this entry at this time because + * we cannot make its proper full-path name. + */ + if (rede_add_entry(file) == 0) + continue; + /* Otherwise we can expose this entry because + * it seems its top level "RE" has already been + * exposed. */ + } + } + break; + } + + if ((file->mode & AE_IFMT) != AE_IFREG || file->number == -1) + return (ARCHIVE_OK); + + count = 0; + number = file->number; + iso9660->cache_files.first = NULL; + iso9660->cache_files.last = &(iso9660->cache_files.first); + empty_files.first = NULL; + empty_files.last = &empty_files.first; + /* Collect files which has the same file serial number. + * Peek pending_files so that file which number is different + * is not put bak. */ + while (iso9660->pending_files.used > 0 && + (iso9660->pending_files.files[0]->number == -1 || + iso9660->pending_files.files[0]->number == number)) { + if (file->number == -1) { + /* This file has the same offset + * but it's wrong offset which empty files + * and symlink files have. + * NOTE: This wrong offse was recorded by + * old mkisofs utility. If ISO images is + * created by latest mkisofs, this does not + * happen. + */ + file->next = NULL; + *empty_files.last = file; + empty_files.last = &(file->next); + } else { + count++; + cache_add_entry(iso9660, file); + } + file = next_entry(iso9660); + } + + if (count == 0) { + *pfile = file; + return ((file == NULL)?ARCHIVE_EOF:ARCHIVE_OK); + } + if (file->number == -1) { + file->next = NULL; + *empty_files.last = file; + empty_files.last = &(file->next); + } else { + count++; + cache_add_entry(iso9660, file); + } + + if (count > 1) { + /* The count is the same as number of hardlink, + * so much so that each nlinks of files in cache_file + * is overwritten by value of the count. + */ + for (file = iso9660->cache_files.first; + file != NULL; file = file->next) + file->nlinks = count; + } + /* If there are empty files, that files are added + * to the tail of the cache_files. */ + if (empty_files.first != NULL) { + *iso9660->cache_files.last = empty_files.first; + iso9660->cache_files.last = empty_files.last; + } + *pfile = cache_get_entry(iso9660); + return ((*pfile == NULL)?ARCHIVE_EOF:ARCHIVE_OK); + +fatal_rr: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to connect 'CL' pointer to 'RE' rr_moved pointer of" + "Rockridge extensions"); + return (ARCHIVE_FATAL); +} + +static inline void +re_add_entry(struct iso9660 *iso9660, struct file_info *file) +{ + file->re_next = NULL; + *iso9660->re_files.last = file; + iso9660->re_files.last = &(file->re_next); +} + +static inline struct file_info * +re_get_entry(struct iso9660 *iso9660) +{ + struct file_info *file; + + if ((file = iso9660->re_files.first) != NULL) { + iso9660->re_files.first = file->re_next; + if (iso9660->re_files.first == NULL) + iso9660->re_files.last = + &(iso9660->re_files.first); + } + return (file); +} + +static inline int +rede_add_entry(struct file_info *file) +{ + struct file_info *re; + + /* + * Find "RE" entry. + */ + re = file->parent; + while (re != NULL && !re->re) + re = re->parent; + if (re == NULL) + return (-1); + + file->re_next = NULL; + *re->rede_files.last = file; + re->rede_files.last = &(file->re_next); + return (0); +} + +static inline struct file_info * +rede_get_entry(struct file_info *re) +{ + struct file_info *file; + + if ((file = re->rede_files.first) != NULL) { + re->rede_files.first = file->re_next; + if (re->rede_files.first == NULL) + re->rede_files.last = + &(re->rede_files.first); + } + return (file); +} + +static inline void +cache_add_entry(struct iso9660 *iso9660, struct file_info *file) +{ + file->next = NULL; + *iso9660->cache_files.last = file; + iso9660->cache_files.last = &(file->next); +} + +static inline struct file_info * +cache_get_entry(struct iso9660 *iso9660) +{ + struct file_info *file; + + if ((file = iso9660->cache_files.first) != NULL) { + iso9660->cache_files.first = file->next; + if (iso9660->cache_files.first == NULL) + iso9660->cache_files.last = + &(iso9660->cache_files.first); + } + return (file); +} + +static int +heap_add_entry(struct archive_read *a, struct heap_queue *heap, + struct file_info *file, uint64_t key) +{ + uint64_t file_key, parent_key; + int hole, parent; + + /* Expand our pending files list as necessary. */ + if (heap->used >= heap->allocated) { + struct file_info **new_pending_files; + int new_size = heap->allocated * 2; + + if (heap->allocated < 1024) + new_size = 1024; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + new_pending_files = (struct file_info **) + malloc(new_size * sizeof(new_pending_files[0])); + if (new_pending_files == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); + if (heap->files != NULL) + free(heap->files); + heap->files = new_pending_files; + heap->allocated = new_size; + } + + file_key = file->key = key; + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->used++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_key = heap->files[parent]->key; + if (file_key >= parent_key) { + heap->files[hole] = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->files[hole] = heap->files[parent]; + hole = parent; + } + heap->files[0] = file; + + return (ARCHIVE_OK); } static struct file_info * -next_entry(struct iso9660 *iso9660) +heap_get_entry(struct heap_queue *heap) { - uint64_t a_offset, b_offset, c_offset; - int a, b, c; - struct file_info *r, *tmp; - - if (iso9660->pending_files_used < 1) - return (NULL); - - /* - * The first file in the list is the earliest; we'll return this. - */ - r = iso9660->pending_files[0]; - - /* - * Move the last item in the heap to the root of the tree - */ - iso9660->pending_files[0] - = iso9660->pending_files[--iso9660->pending_files_used]; - - /* - * Rebalance the heap. - */ - a = 0; /* Starting element and its offset */ - a_offset = iso9660->pending_files[a]->offset - + iso9660->pending_files[a]->size; - for (;;) { - b = a + a + 1; /* First child */ - if (b >= iso9660->pending_files_used) - return (r); - b_offset = iso9660->pending_files[b]->offset - + iso9660->pending_files[b]->size; - c = b + 1; /* Use second child if it is smaller. */ - if (c < iso9660->pending_files_used) { - c_offset = iso9660->pending_files[c]->offset - + iso9660->pending_files[c]->size; - if (c_offset < b_offset) { - b = c; - b_offset = c_offset; - } - } - if (a_offset <= b_offset) - return (r); - tmp = iso9660->pending_files[a]; - iso9660->pending_files[a] = iso9660->pending_files[b]; - iso9660->pending_files[b] = tmp; - a = b; - } + uint64_t a_key, b_key, c_key; + int a, b, c; + struct file_info *r, *tmp; + + if (heap->used < 1) + return (NULL); + + /* + * The first file in the list is the earliest; we'll return this. + */ + r = heap->files[0]; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->files[0] = heap->files[--(heap->used)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its heap key */ + a_key = heap->files[a]->key; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->used) + return (r); + b_key = heap->files[b]->key; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->used) { + c_key = heap->files[c]->key; + if (c_key < b_key) { + b = c; + b_key = c_key; + } + } + if (a_key <= b_key) + return (r); + tmp = heap->files[a]; + heap->files[a] = heap->files[b]; + heap->files[b] = tmp; + a = b; + } } static unsigned int toi(const void *p, int n) { - const unsigned char *v = (const unsigned char *)p; - if (n > 1) - return v[0] + 256 * toi(v + 1, n - 1); - if (n == 1) - return v[0]; - return (0); + const unsigned char *v = (const unsigned char *)p; + if (n > 1) + return v[0] + 256 * toi(v + 1, n - 1); + if (n == 1) + return v[0]; + return (0); } static time_t isodate7(const unsigned char *v) { - struct tm tm; - int offset; - memset(&tm, 0, sizeof(tm)); - tm.tm_year = v[0]; - tm.tm_mon = v[1] - 1; - tm.tm_mday = v[2]; - tm.tm_hour = v[3]; - tm.tm_min = v[4]; - tm.tm_sec = v[5]; - /* v[6] is the signed timezone offset, in 1/4-hour increments. */ - offset = ((const signed char *)v)[6]; - if (offset > -48 && offset < 52) { - tm.tm_hour -= offset / 4; - tm.tm_min -= (offset % 4) * 15; - } - return (time_from_tm(&tm)); + struct tm tm; + int offset; + memset(&tm, 0, sizeof(tm)); + tm.tm_year = v[0]; + tm.tm_mon = v[1] - 1; + tm.tm_mday = v[2]; + tm.tm_hour = v[3]; + tm.tm_min = v[4]; + tm.tm_sec = v[5]; + /* v[6] is the signed timezone offset, in 1/4-hour increments. */ + offset = ((const signed char *)v)[6]; + if (offset > -48 && offset < 52) { + tm.tm_hour -= offset / 4; + tm.tm_min -= (offset % 4) * 15; + } + return (time_from_tm(&tm)); } static time_t isodate17(const unsigned char *v) { - struct tm tm; - int offset; - memset(&tm, 0, sizeof(tm)); - tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100 - + (v[2] - '0') * 10 + (v[3] - '0') - - 1900; - tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0'); - tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0'); - tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0'); - tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0'); - tm.tm_sec = (v[12] - '0') * 10 + (v[13] - '0'); - /* v[16] is the signed timezone offset, in 1/4-hour increments. */ - offset = ((const signed char *)v)[16]; - if (offset > -48 && offset < 52) { - tm.tm_hour -= offset / 4; - tm.tm_min -= (offset % 4) * 15; - } - return (time_from_tm(&tm)); + struct tm tm; + int offset; + memset(&tm, 0, sizeof(tm)); + tm.tm_year = (v[0] - '0') * 1000 + (v[1] - '0') * 100 + + (v[2] - '0') * 10 + (v[3] - '0') + - 1900; + tm.tm_mon = (v[4] - '0') * 10 + (v[5] - '0'); + tm.tm_mday = (v[6] - '0') * 10 + (v[7] - '0'); + tm.tm_hour = (v[8] - '0') * 10 + (v[9] - '0'); + tm.tm_min = (v[10] - '0') * 10 + (v[11] - '0'); + tm.tm_sec = (v[12] - '0') * 10 + (v[13] - '0'); + /* v[16] is the signed timezone offset, in 1/4-hour increments. */ + offset = ((const signed char *)v)[16]; + if (offset > -48 && offset < 52) { + tm.tm_hour -= offset / 4; + tm.tm_min -= (offset % 4) * 15; + } + return (time_from_tm(&tm)); } static time_t time_from_tm(struct tm *t) { #if HAVE_TIMEGM - /* Use platform timegm() if available. */ - return (timegm(t)); + /* Use platform timegm() if available. */ + return (timegm(t)); +#elif HAVE__MKGMTIME64 + return (_mkgmtime64(t)); #else - /* Else use direct calculation using POSIX assumptions. */ - /* First, fix up tm_yday based on the year/month/day. */ - mktime(t); - /* Then we can compute timegm() from first principles. */ - return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 - + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 - + ((t->tm_year - 69) / 4) * 86400 - - ((t->tm_year - 1) / 100) * 86400 - + ((t->tm_year + 299) / 400) * 86400); + /* Else use direct calculation using POSIX assumptions. */ + /* First, fix up tm_yday based on the year/month/day. */ + mktime(t); + /* Then we can compute timegm() from first principles. */ + return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 + + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 + + ((t->tm_year - 69) / 4) * 86400 - + ((t->tm_year - 1) / 100) * 86400 + + ((t->tm_year + 299) / 400) * 86400); #endif } static const char * build_pathname(struct archive_string *as, struct file_info *file) { - if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) { - build_pathname(as, file->parent); - archive_strcat(as, "/"); - } - if (archive_strlen(&file->name) == 0) - archive_strcat(as, "."); - else - archive_string_concat(as, &file->name); - return (as->s); + if (file->parent != NULL && archive_strlen(&file->parent->name) > 0) { + build_pathname(as, file->parent); + archive_strcat(as, "/"); + } + if (archive_strlen(&file->name) == 0) + archive_strcat(as, "."); + else + archive_string_concat(as, &file->name); + return (as->s); +} + +static int +build_pathname_utf16be(unsigned char *p, size_t max, size_t *len, + struct file_info *file) +{ + if (file->parent != NULL && file->parent->utf16be_bytes > 0) { + if (build_pathname_utf16be(p, max, len, file->parent) != 0) + return (-1); + p[*len] = 0; + p[*len + 1] = '/'; + *len += 2; + } + if (file->utf16be_bytes == 0) { + if (*len + 2 > max) + return (-1);/* Path is too long! */ + p[*len] = 0; + p[*len + 1] = '.'; + *len += 2; + } else { + if (*len + file->utf16be_bytes > max) + return (-1);/* Path is too long! */ + memcpy(p + *len, file->utf16be_name, file->utf16be_bytes); + *len += file->utf16be_bytes; + } + return (0); } #if DEBUG static void dump_isodirrec(FILE *out, const unsigned char *isodirrec) { - fprintf(out, " l %d,", - toi(isodirrec + DR_length_offset, DR_length_size)); - fprintf(out, " a %d,", - toi(isodirrec + DR_ext_attr_length_offset, DR_ext_attr_length_size)); - fprintf(out, " ext 0x%x,", - toi(isodirrec + DR_extent_offset, DR_extent_size)); - fprintf(out, " s %d,", - toi(isodirrec + DR_size_offset, DR_extent_size)); - fprintf(out, " f 0x%02x,", - toi(isodirrec + DR_flags_offset, DR_flags_size)); - fprintf(out, " u %d,", - toi(isodirrec + DR_file_unit_size_offset, DR_file_unit_size_size)); - fprintf(out, " ilv %d,", - toi(isodirrec + DR_interleave_offset, DR_interleave_size)); - fprintf(out, " seq %d,", - toi(isodirrec + DR_volume_sequence_number_offset, DR_volume_sequence_number_size)); - fprintf(out, " nl %d:", - toi(isodirrec + DR_name_len_offset, DR_name_len_size)); - fprintf(out, " `%.*s'", - toi(isodirrec + DR_name_len_offset, DR_name_len_size), isodirrec + DR_name_offset); + fprintf(out, " l %d,", + toi(isodirrec + DR_length_offset, DR_length_size)); + fprintf(out, " a %d,", + toi(isodirrec + DR_ext_attr_length_offset, DR_ext_attr_length_size)); + fprintf(out, " ext 0x%x,", + toi(isodirrec + DR_extent_offset, DR_extent_size)); + fprintf(out, " s %d,", + toi(isodirrec + DR_size_offset, DR_extent_size)); + fprintf(out, " f 0x%x,", + toi(isodirrec + DR_flags_offset, DR_flags_size)); + fprintf(out, " u %d,", + toi(isodirrec + DR_file_unit_size_offset, DR_file_unit_size_size)); + fprintf(out, " ilv %d,", + toi(isodirrec + DR_interleave_offset, DR_interleave_size)); + fprintf(out, " seq %d,", + toi(isodirrec + DR_volume_sequence_number_offset, DR_volume_sequence_number_size)); + fprintf(out, " nl %d:", + toi(isodirrec + DR_name_len_offset, DR_name_len_size)); + fprintf(out, " `%.*s'", + toi(isodirrec + DR_name_len_offset, DR_name_len_size), isodirrec + DR_name_offset); } #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c new file mode 100644 index 000000000..50256b161 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_lha.c @@ -0,0 +1,2745 @@ +/*- + * Copyright (c) 2008-2011 Michihiro NAKAJIMA + * 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" + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" +#include "archive_endian.h" + + +#define MAXMATCH 256 /* Maximum match length. */ +#define MINMATCH 3 /* Minimum match length. */ +/* + * Literal table format: + * +0 +256 +510 + * +---------------+-------------------------+ + * | literal code | match length | + * | 0 ... 255 | MINMATCH ... MAXMATCH | + * +---------------+-------------------------+ + * <--- LT_BITLEN_SIZE ---> + */ +/* Literal table size. */ +#define LT_BITLEN_SIZE (UCHAR_MAX + 1 + MAXMATCH - MINMATCH + 1) +/* Position table size. + * Note: this used for both position table and pre literal table.*/ +#define PT_BITLEN_SIZE (3 + 16) + +struct lzh_dec { + /* Decoding status. */ + int state; + + /* + * Window to see last 8Ki(lh5),32Ki(lh6),64Ki(lh7) bytes of decoded + * data. + */ + int w_size; + int w_mask; + /* Window buffer, which is a loop buffer. */ + unsigned char *w_buff; + /* The insert position to the window. */ + int w_pos; + /* The position where we can copy decoded code from the window. */ + int copy_pos; + /* The length how many bytes we can copy decoded code from + * the window. */ + int copy_len; + /* The remaining bytes that we have not copied decoded data from + * the window to an output buffer. */ + int w_remaining; + + /* + * Bit stream reader. + */ + struct lzh_br { +#define CACHE_TYPE uint64_t +#define CACHE_BITS (8 * sizeof(CACHE_TYPE)) + /* Cache buffer. */ + CACHE_TYPE cache_buffer; + /* Indicates how many bits avail in cache_buffer. */ + int cache_avail; + } br; + + /* + * Huffman coding. + */ + struct huffman { + int len_size; + int len_avail; + int len_bits; + int freq[17]; + unsigned char *bitlen; + + /* + * Use a index table. It's faster than searching a huffman + * coding tree, which is a binary tree. But a use of a large + * index table causes L1 cache read miss many times. + */ +#define HTBL_BITS 10 + int max_bits; + int shift_bits; + int tbl_bits; + int tree_used; + int tree_avail; + /* Direct access table. */ + uint16_t *tbl; + /* Binary tree table for extra bits over the direct access. */ + struct htree_t { + uint16_t left; + uint16_t right; + } *tree; + } lt, pt; + + int blocks_avail; + int pos_pt_len_size; + int pos_pt_len_bits; + int literal_pt_len_size; + int literal_pt_len_bits; + int reading_position; + int loop; + int error; +}; + +struct lzh_stream { + const unsigned char *next_in; + int64_t avail_in; + int64_t total_in; + unsigned char *next_out; + int64_t avail_out; + int64_t total_out; + struct lzh_dec *ds; +}; + +struct lha { + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_offset; + int64_t entry_bytes_remaining; + int64_t entry_unconsumed; + uint16_t entry_crc_calculated; + + size_t header_size; /* header size */ + unsigned char level; /* header level */ + char method[3]; /* compress type */ + int64_t compsize; /* compressed data size */ + int64_t origsize; /* original file size */ + int setflag; +#define BIRTHTIME_IS_SET 1 +#define ATIME_IS_SET 2 +#define UNIX_MODE_IS_SET 4 +#define CRC_IS_SET 8 + time_t birthtime; + long birthtime_tv_nsec; + time_t mtime; + long mtime_tv_nsec; + time_t atime; + long atime_tv_nsec; + mode_t mode; + int64_t uid; + int64_t gid; + struct archive_string uname; + struct archive_string gname; + uint16_t header_crc; + uint16_t crc; + struct archive_string_conv *sconv; + struct archive_string_conv *opt_sconv; + + struct archive_string dirname; + struct archive_string filename; + struct archive_wstring ws; + + unsigned char dos_attr; + + /* Flag to mark progress that an archive was read their first header.*/ + char found_first_header; + /* Flag to mark that indicates an empty directory. */ + char directory; + + /* Flags to mark progress of decompression. */ + char decompress_init; + char end_of_entry; + char end_of_entry_cleanup; + char entry_is_compressed; + + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; + + char format_name[64]; + + struct lzh_stream strm; +}; + +/* + * LHA header common member offset. + */ +#define H_METHOD_OFFSET 2 /* Compress type. */ +#define H_ATTR_OFFSET 19 /* DOS attribute. */ +#define H_LEVEL_OFFSET 20 /* Header Level. */ +#define H_SIZE 22 /* Minimum header size. */ + +static const uint16_t crc16tbl[256] = { + 0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241, + 0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440, + 0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40, + 0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841, + 0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40, + 0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41, + 0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641, + 0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040, + 0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240, + 0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441, + 0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41, + 0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840, + 0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41, + 0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40, + 0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640, + 0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041, + 0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240, + 0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441, + 0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41, + 0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840, + 0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41, + 0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40, + 0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640, + 0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041, + 0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241, + 0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440, + 0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40, + 0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841, + 0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40, + 0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41, + 0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641, + 0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040 +}; + +static int archive_read_format_lha_bid(struct archive_read *, int); +static int archive_read_format_lha_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_lha_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_lha_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_lha_read_data_skip(struct archive_read *); +static int archive_read_format_lha_cleanup(struct archive_read *); + +static void lha_replace_path_separator(struct lha *, + struct archive_entry *); +static int lha_read_file_header_0(struct archive_read *, struct lha *); +static int lha_read_file_header_1(struct archive_read *, struct lha *); +static int lha_read_file_header_2(struct archive_read *, struct lha *); +static int lha_read_file_header_3(struct archive_read *, struct lha *); +static int lha_read_file_extended_header(struct archive_read *, + struct lha *, uint16_t *, int, size_t, size_t *); +static size_t lha_check_header_format(const void *); +static int lha_skip_sfx(struct archive_read *); +static time_t lha_dos_time(const unsigned char *); +static time_t lha_win_time(uint64_t, long *); +static unsigned char lha_calcsum(unsigned char, const void *, + int, int); +static int lha_parse_linkname(struct archive_string *, + struct archive_string *); +static int lha_read_data_none(struct archive_read *, const void **, + size_t *, int64_t *); +static int lha_read_data_lzh(struct archive_read *, const void **, + size_t *, int64_t *); +static uint16_t lha_crc16(uint16_t, const void *, size_t); +static int lzh_decode_init(struct lzh_stream *, const char *); +static void lzh_decode_free(struct lzh_stream *); +static int lzh_decode(struct lzh_stream *, int); +static int lzh_br_fillup(struct lzh_stream *, struct lzh_br *); +static int lzh_huffman_init(struct huffman *, size_t, int); +static void lzh_huffman_free(struct huffman *); +static int lzh_read_pt_bitlen(struct lzh_stream *, int start, int end); +static int lzh_make_fake_table(struct huffman *, uint16_t); +static int lzh_make_huffman_table(struct huffman *); +static int inline lzh_decode_huffman(struct huffman *, unsigned); +static int lzh_decode_huffman_tree(struct huffman *, unsigned, int); + + +int +archive_read_support_format_lha(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct lha *lha; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_lha"); + + lha = (struct lha *)calloc(1, sizeof(*lha)); + if (lha == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate lha data"); + return (ARCHIVE_FATAL); + } + archive_string_init(&lha->ws); + + r = __archive_read_register_format(a, + lha, + "lha", + archive_read_format_lha_bid, + archive_read_format_lha_options, + archive_read_format_lha_read_header, + archive_read_format_lha_read_data, + archive_read_format_lha_read_data_skip, + archive_read_format_lha_cleanup); + + if (r != ARCHIVE_OK) + free(lha); + return (ARCHIVE_OK); +} + +static size_t +lha_check_header_format(const void *h) +{ + const unsigned char *p = h; + size_t next_skip_bytes; + + switch (p[H_METHOD_OFFSET+3]) { + /* + * "-lh0-" ... "-lh7-" "-lhd-" + * "-lzs-" "-lz5-" + */ + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + case 'd': + case 's': + next_skip_bytes = 4; + + /* b0 == 0 means the end of an LHa archive file. */ + if (p[0] == 0) + break; + if (p[H_METHOD_OFFSET] != '-' || p[H_METHOD_OFFSET+1] != 'l' + || p[H_METHOD_OFFSET+4] != '-') + break; + + if (p[H_METHOD_OFFSET+2] == 'h') { + /* "-lh?-" */ + if (p[H_METHOD_OFFSET+3] == 's') + break; + if (p[H_LEVEL_OFFSET] == 0) + return (0); + if (p[H_LEVEL_OFFSET] <= 3 && p[H_ATTR_OFFSET] == 0x20) + return (0); + } + if (p[H_METHOD_OFFSET+2] == 'z') { + /* LArc extensions: -lzs-,-lz4- and -lz5- */ + if (p[H_LEVEL_OFFSET] != 0) + break; + if (p[H_METHOD_OFFSET+3] == 's' + || p[H_METHOD_OFFSET+3] == '4' + || p[H_METHOD_OFFSET+3] == '5') + return (0); + } + break; + case 'h': next_skip_bytes = 1; break; + case 'z': next_skip_bytes = 1; break; + case 'l': next_skip_bytes = 2; break; + case '-': next_skip_bytes = 3; break; + default : next_skip_bytes = 4; break; + } + + return (next_skip_bytes); +} + +static int +archive_read_format_lha_bid(struct archive_read *a, int best_bid) +{ + const char *p; + const void *buff; + ssize_t bytes_avail, offset, window; + size_t next; + + /* If there's already a better bid than we can ever + make, don't bother testing. */ + if (best_bid > 30) + return (-1); + + if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL) + return (-1); + + if (lha_check_header_format(p) == 0) + return (30); + + if (p[0] == 'M' && p[1] == 'Z') { + /* PE file */ + offset = 0; + window = 4096; + while (offset < (1024 * 20)) { + buff = __archive_read_ahead(a, offset + window, + &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < (H_SIZE + 3)) + return (0); + continue; + } + p = (const char *)buff + offset; + while (p + H_SIZE < (const char *)buff + bytes_avail) { + if ((next = lha_check_header_format(p)) == 0) + return (30); + p += next; + } + offset = p - (const char *)buff; + } + } + return (0); +} + +static int +archive_read_format_lha_options(struct archive_read *a, + const char *key, const char *val) +{ + struct lha *lha; + int ret = ARCHIVE_FAILED; + + lha = (struct lha *)(a->format->data); + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "lha: hdrcharset option needs a character-set name"); + else { + lha->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (lha->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "lha: unknown keyword ``%s''", key); + + return (ret); +} + +static int +lha_skip_sfx(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t next, skip; + ssize_t bytes, window; + + window = 4096; + for (;;) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < (H_SIZE + 3)) + goto fatal; + continue; + } + if (bytes < H_SIZE) + goto fatal; + p = h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the lha header. + */ + while (p + H_SIZE < q) { + if ((next = lha_check_header_format(p)) == 0) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + return (ARCHIVE_OK); + } + p += next; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out LHa header"); + return (ARCHIVE_FATAL); +} + +static int +truncated_error(struct archive_read *a) +{ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_lha_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + struct archive_string linkname; + struct archive_string pathname; + struct lha *lha; + const unsigned char *p; + const char *signature; + int err; + + a->archive.archive_format = ARCHIVE_FORMAT_LHA; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "lha"; + + lha = (struct lha *)(a->format->data); + lha->decompress_init = 0; + lha->end_of_entry = 0; + lha->end_of_entry_cleanup = 0; + lha->entry_unconsumed = 0; + + if ((p = __archive_read_ahead(a, H_SIZE, NULL)) == NULL) { + /* + * LHa archiver added 0 to the tail of its archive file as + * the mark of the end of the archive. + */ + signature = __archive_read_ahead(a, sizeof(signature[0]), NULL); + if (signature == NULL || signature[0] == 0) + return (ARCHIVE_EOF); + return (truncated_error(a)); + } + + signature = (const char *)p; + if (lha->found_first_header == 0 && + signature[0] == 'M' && signature[1] == 'Z') { + /* This is an executable? Must be self-extracting... */ + err = lha_skip_sfx(a); + if (err < ARCHIVE_WARN) + return (err); + + if ((p = __archive_read_ahead(a, sizeof(*p), NULL)) == NULL) + return (truncated_error(a)); + signature = (const char *)p; + } + /* signature[0] == 0 means the end of an LHa archive file. */ + if (signature[0] == 0) + return (ARCHIVE_EOF); + + /* + * Check the header format and method type. + */ + if (lha_check_header_format(p) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad LHa file"); + return (ARCHIVE_FATAL); + } + + /* We've found the first header. */ + lha->found_first_header = 1; + /* Set a default value and common data */ + lha->header_size = 0; + lha->level = p[H_LEVEL_OFFSET]; + lha->method[0] = p[H_METHOD_OFFSET+1]; + lha->method[1] = p[H_METHOD_OFFSET+2]; + lha->method[2] = p[H_METHOD_OFFSET+3]; + if (memcmp(lha->method, "lhd", 3) == 0) + lha->directory = 1; + else + lha->directory = 0; + if (memcmp(lha->method, "lh0", 3) == 0 || + memcmp(lha->method, "lz4", 3) == 0) + lha->entry_is_compressed = 0; + else + lha->entry_is_compressed = 1; + + lha->compsize = 0; + lha->origsize = 0; + lha->setflag = 0; + lha->birthtime = 0; + lha->birthtime_tv_nsec = 0; + lha->mtime = 0; + lha->mtime_tv_nsec = 0; + lha->atime = 0; + lha->atime_tv_nsec = 0; + lha->mode = (lha->directory)? 0777 : 0666; + lha->uid = 0; + lha->gid = 0; + archive_string_empty(&lha->dirname); + archive_string_empty(&lha->filename); + lha->dos_attr = 0; + if (lha->opt_sconv != NULL) + lha->sconv = lha->opt_sconv; + else + lha->sconv = NULL; + + switch (p[H_LEVEL_OFFSET]) { + case 0: + err = lha_read_file_header_0(a, lha); + break; + case 1: + err = lha_read_file_header_1(a, lha); + break; + case 2: + err = lha_read_file_header_2(a, lha); + break; + case 3: + err = lha_read_file_header_3(a, lha); + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported LHa header level %d", p[H_LEVEL_OFFSET]); + err = ARCHIVE_FATAL; + break; + } + if (err < ARCHIVE_WARN) + return (err); + + + if (!lha->directory && archive_strlen(&lha->filename) == 0) + /* The filename has not been set */ + return (truncated_error(a)); + + /* + * Make a pathname from a dirname and a filename. + */ + archive_string_concat(&lha->dirname, &lha->filename); + archive_string_init(&pathname); + archive_string_init(&linkname); + archive_string_copy(&pathname, &lha->dirname); + + if ((lha->mode & AE_IFMT) == AE_IFLNK) { + /* + * Extract the symlink-name if it's included in the pathname. + */ + if (!lha_parse_linkname(&linkname, &pathname)) { + /* We couldn't get the symlink-name. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown symlink-name"); + archive_string_free(&pathname); + archive_string_free(&linkname); + return (ARCHIVE_FAILED); + } + } else { + /* + * Make sure a file-type is set. + * The mode has been overridden if it is in the extended data. + */ + lha->mode = (lha->mode & ~AE_IFMT) | + ((lha->directory)? AE_IFDIR: AE_IFREG); + } + if ((lha->setflag & UNIX_MODE_IS_SET) == 0 && + (lha->dos_attr & 1) != 0) + lha->mode &= ~(0222);/* read only. */ + + /* + * Set basic file parameters. + */ + if (archive_entry_copy_pathname_l(entry, pathname.s, + pathname.length, lha->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(lha->sconv)); + err = ARCHIVE_WARN; + } + archive_string_free(&pathname); + if (archive_strlen(&linkname) > 0) { + if (archive_entry_copy_symlink_l(entry, linkname.s, + linkname.length, lha->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(lha->sconv)); + err = ARCHIVE_WARN; + } + } else + archive_entry_set_symlink(entry, NULL); + archive_string_free(&linkname); + /* + * When a header level is 0, there is a possibilty that + * a pathname and a symlink has '\' character, a directory + * separator in DOS/Windows. So we should convert it to '/'. + */ + if (p[H_LEVEL_OFFSET] == 0) + lha_replace_path_separator(lha, entry); + + archive_entry_set_mode(entry, lha->mode); + archive_entry_set_uid(entry, lha->uid); + archive_entry_set_gid(entry, lha->gid); + if (archive_strlen(&lha->uname) > 0) + archive_entry_set_uname(entry, lha->uname.s); + if (archive_strlen(&lha->gname) > 0) + archive_entry_set_gname(entry, lha->gname.s); + if (lha->setflag & BIRTHTIME_IS_SET) { + archive_entry_set_birthtime(entry, lha->birthtime, + lha->birthtime_tv_nsec); + archive_entry_set_ctime(entry, lha->birthtime, + lha->birthtime_tv_nsec); + } else { + archive_entry_unset_birthtime(entry); + archive_entry_unset_ctime(entry); + } + archive_entry_set_mtime(entry, lha->mtime, lha->mtime_tv_nsec); + if (lha->setflag & ATIME_IS_SET) + archive_entry_set_atime(entry, lha->atime, + lha->atime_tv_nsec); + else + archive_entry_unset_atime(entry); + if (lha->directory || archive_entry_symlink(entry) != NULL) + archive_entry_unset_size(entry); + else + archive_entry_set_size(entry, lha->origsize); + + /* + * Prepare variables used to read a file content. + */ + lha->entry_bytes_remaining = lha->compsize; + lha->entry_offset = 0; + lha->entry_crc_calculated = 0; + + /* + * This file does not have a content. + */ + if (lha->directory || lha->compsize == 0) + lha->end_of_entry = 1; + + sprintf(lha->format_name, "lha -%c%c%c-", + lha->method[0], lha->method[1], lha->method[2]); + a->archive.archive_format_name = lha->format_name; + + return (err); +} + +/* + * Replace a DOS path separator '\' by a character '/'. + * Some multi-byte character set have a character '\' in its second byte. + */ +static void +lha_replace_path_separator(struct lha *lha, struct archive_entry *entry) +{ + const wchar_t *wp; + size_t i; + + if ((wp = archive_entry_pathname_w(entry)) != NULL) { + archive_wstrcpy(&(lha->ws), wp); + for (i = 0; i < archive_strlen(&(lha->ws)); i++) { + if (lha->ws.s[i] == L'\\') + lha->ws.s[i] = L'/'; + } + archive_entry_copy_pathname_w(entry, lha->ws.s); + } + + if ((wp = archive_entry_symlink_w(entry)) != NULL) { + archive_wstrcpy(&(lha->ws), wp); + for (i = 0; i < archive_strlen(&(lha->ws)); i++) { + if (lha->ws.s[i] == L'\\') + lha->ws.s[i] = L'/'; + } + archive_entry_copy_symlink_w(entry, lha->ws.s); + } +} + +/* + * Header 0 format + * + * +0 +1 +2 +7 +11 + * +---------------+----------+----------------+-------------------+ + * |header size(*1)|header sum|compression type|compressed size(*2)| + * +---------------+----------+----------------+-------------------+ + * <---------------------(*1)----------* + * + * +11 +15 +17 +19 +20 +21 + * +-----------------+---------+---------+--------------+----------------+ + * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=0)| + * +-----------------+---------+---------+--------------+----------------+ + * *--------------------------------(*1)---------------------------------* + * + * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+2+(*4) + * +---------------+---------+----------+----------------+------------------+ + * |name length(*3)|file name|file CRC16|extra header(*4)| compressed data | + * +---------------+---------+----------+----------------+------------------+ + * <--(*3)-> <------(*2)------> + * *----------------------(*1)--------------------------> + * + */ +#define H0_HEADER_SIZE_OFFSET 0 +#define H0_HEADER_SUM_OFFSET 1 +#define H0_COMP_SIZE_OFFSET 7 +#define H0_ORIG_SIZE_OFFSET 11 +#define H0_DOS_TIME_OFFSET 15 +#define H0_NAME_LEN_OFFSET 21 +#define H0_FILE_NAME_OFFSET 22 +#define H0_FIXED_SIZE 24 +static int +lha_read_file_header_0(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + int extdsize, namelen; + unsigned char headersum, sum_calculated; + + if ((p = __archive_read_ahead(a, H0_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + lha->header_size = p[H0_HEADER_SIZE_OFFSET] + 2; + headersum = p[H0_HEADER_SUM_OFFSET]; + lha->compsize = archive_le32dec(p + H0_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H0_ORIG_SIZE_OFFSET); + lha->mtime = lha_dos_time(p + H0_DOS_TIME_OFFSET); + namelen = p[H0_NAME_LEN_OFFSET]; + extdsize = (int)lha->header_size - H0_FIXED_SIZE - namelen; + if ((namelen > 221 || extdsize < 0) && extdsize != -2) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); + } + if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL) + return (truncated_error(a)); + + archive_strncpy(&lha->filename, p + H0_FILE_NAME_OFFSET, namelen); + /* When extdsize == -2, A CRC16 value is not present in the header. */ + if (extdsize >= 0) { + lha->crc = archive_le16dec(p + H0_FILE_NAME_OFFSET + namelen); + lha->setflag |= CRC_IS_SET; + } + sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2); + + /* Read an extended header */ + if (extdsize > 0) { + /* This extended data is set by 'LHa for UNIX' only. + * Maybe fixed size. + */ + p += H0_FILE_NAME_OFFSET + namelen + 2; + if (p[0] == 'U' && extdsize == 12) { + /* p[1] is a minor version. */ + lha->mtime = archive_le32dec(&p[2]); + lha->mode = archive_le16dec(&p[6]); + lha->uid = archive_le16dec(&p[8]); + lha->gid = archive_le16dec(&p[10]); + lha->setflag |= UNIX_MODE_IS_SET; + } + } + __archive_read_consume(a, lha->header_size); + + if (sum_calculated != headersum) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LHa header sum error"); + return (ARCHIVE_FATAL); + } + + return (ARCHIVE_OK); +} + +/* + * Header 1 format + * + * +0 +1 +2 +7 +11 + * +---------------+----------+----------------+-------------+ + * |header size(*1)|header sum|compression type|skip size(*2)| + * +---------------+----------+----------------+-------------+ + * <---------------(*1)----------* + * + * +11 +15 +17 +19 +20 +21 + * +-----------------+---------+---------+--------------+----------------+ + * |uncompressed size|time(DOS)|date(DOS)|attribute(DOS)|header level(=1)| + * +-----------------+---------+---------+--------------+----------------+ + * *-------------------------------(*1)----------------------------------* + * + * +21 +22 +22+(*3) +22+(*3)+2 +22+(*3)+3 +22+(*3)+3+(*4) + * +---------------+---------+----------+-----------+-----------+ + * |name length(*3)|file name|file CRC16| creator |padding(*4)| + * +---------------+---------+----------+-----------+-----------+ + * <--(*3)-> + * *----------------------------(*1)----------------------------* + * + * +22+(*3)+3+(*4) +22+(*3)+3+(*4)+2 +22+(*3)+3+(*4)+2+(*5) + * +----------------+---------------------+------------------------+ + * |next header size| extended header(*5) | compressed data | + * +----------------+---------------------+------------------------+ + * *------(*1)-----> <--------------------(*2)--------------------> + */ +#define H1_HEADER_SIZE_OFFSET 0 +#define H1_HEADER_SUM_OFFSET 1 +#define H1_COMP_SIZE_OFFSET 7 +#define H1_ORIG_SIZE_OFFSET 11 +#define H1_DOS_TIME_OFFSET 15 +#define H1_NAME_LEN_OFFSET 21 +#define H1_FILE_NAME_OFFSET 22 +#define H1_FIXED_SIZE 27 +static int +lha_read_file_header_1(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int i, err, err2; + int namelen, padding; + unsigned char headersum, sum_calculated; + + err = ARCHIVE_OK; + + if ((p = __archive_read_ahead(a, H1_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + lha->header_size = p[H1_HEADER_SIZE_OFFSET] + 2; + headersum = p[H1_HEADER_SUM_OFFSET]; + /* Note: An extended header size is included in a compsize. */ + lha->compsize = archive_le32dec(p + H1_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H1_ORIG_SIZE_OFFSET); + lha->mtime = lha_dos_time(p + H1_DOS_TIME_OFFSET); + namelen = p[H1_NAME_LEN_OFFSET]; + /* Calculate a padding size. The result will be normally 0 only(?) */ + padding = ((int)lha->header_size) - H1_FIXED_SIZE - namelen; + + if (namelen > 230 || padding < 0) + goto invalid; + + if ((p = __archive_read_ahead(a, lha->header_size, NULL)) == NULL) + return (truncated_error(a)); + + for (i = 0; i < namelen; i++) { + if (p[i + H1_FILE_NAME_OFFSET] == 0xff) + goto invalid;/* Invalid filename. */ + } + archive_strncpy(&lha->filename, p + H1_FILE_NAME_OFFSET, namelen); + lha->crc = archive_le16dec(p + H1_FILE_NAME_OFFSET + namelen); + lha->setflag |= CRC_IS_SET; + + sum_calculated = lha_calcsum(0, p, 2, lha->header_size - 2); + /* Consume used bytes but not include `next header size' data + * since it will be consumed in lha_read_file_extended_header(). */ + __archive_read_consume(a, lha->header_size - 2); + + /* Read extended headers */ + err2 = lha_read_file_extended_header(a, lha, NULL, 2, + lha->compsize + 2, &extdsize); + if (err2 < ARCHIVE_WARN) + return (err2); + if (err2 < err) + err = err2; + /* Get a real compressed file size. */ + lha->compsize -= extdsize - 2; + + if (sum_calculated != headersum) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "LHa header sum error"); + return (ARCHIVE_FATAL); + } + return (err); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); +} + +/* + * Header 2 format + * + * +0 +2 +7 +11 +15 + * +---------------+----------------+-------------------+-----------------+ + * |header size(*1)|compression type|compressed size(*2)|uncompressed size| + * +---------------+----------------+-------------------+-----------------+ + * <--------------------------------(*1)---------------------------------* + * + * +15 +19 +20 +21 +23 +24 + * +-----------------+------------+----------------+----------+-----------+ + * |data/time(time_t)| 0x20 fixed |header level(=2)|file CRC16| creator | + * +-----------------+------------+----------------+----------+-----------+ + * *---------------------------------(*1)---------------------------------* + * + * +24 +26 +26+(*3) +26+(*3)+(*4) + * +----------------+-------------------+-------------+-------------------+ + * |next header size|extended header(*3)| padding(*4) | compressed data | + * +----------------+-------------------+-------------+-------------------+ + * *--------------------------(*1)-------------------> <------(*2)-------> + * + */ +#define H2_HEADER_SIZE_OFFSET 0 +#define H2_COMP_SIZE_OFFSET 7 +#define H2_ORIG_SIZE_OFFSET 11 +#define H2_TIME_OFFSET 15 +#define H2_CRC_OFFSET 21 +#define H2_FIXED_SIZE 24 +static int +lha_read_file_header_2(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int err, padding; + uint16_t header_crc; + + if ((p = __archive_read_ahead(a, H2_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + lha->header_size =archive_le16dec(p + H2_HEADER_SIZE_OFFSET); + lha->compsize = archive_le32dec(p + H2_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H2_ORIG_SIZE_OFFSET); + lha->mtime = archive_le32dec(p + H2_TIME_OFFSET); + lha->crc = archive_le16dec(p + H2_CRC_OFFSET); + lha->setflag |= CRC_IS_SET; + + if (lha->header_size < H2_FIXED_SIZE) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header size"); + return (ARCHIVE_FATAL); + } + + header_crc = lha_crc16(0, p, H2_FIXED_SIZE); + __archive_read_consume(a, H2_FIXED_SIZE); + + /* Read extended headers */ + err = lha_read_file_extended_header(a, lha, &header_crc, 2, + lha->header_size - H2_FIXED_SIZE, &extdsize); + if (err < ARCHIVE_WARN) + return (err); + + /* Calculate a padding size. The result will be normally 0 or 1. */ + padding = (int)lha->header_size - (int)(H2_FIXED_SIZE + extdsize); + if (padding > 0) { + if ((p = __archive_read_ahead(a, padding, NULL)) == NULL) + return (truncated_error(a)); + header_crc = lha_crc16(header_crc, p, padding); + __archive_read_consume(a, padding); + } + + if (header_crc != lha->header_crc) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "LHa header CRC error"); + return (ARCHIVE_FATAL); + } + return (err); +} + +/* + * Header 3 format + * + * +0 +2 +7 +11 +15 + * +------------+----------------+-------------------+-----------------+ + * | 0x04 fixed |compression type|compressed size(*2)|uncompressed size| + * +------------+----------------+-------------------+-----------------+ + * <-------------------------------(*1)-------------------------------* + * + * +15 +19 +20 +21 +23 +24 + * +-----------------+------------+----------------+----------+-----------+ + * |date/time(time_t)| 0x20 fixed |header level(=3)|file CRC16| creator | + * +-----------------+------------+----------------+----------+-----------+ + * *--------------------------------(*1)----------------------------------* + * + * +24 +28 +32 +32+(*3) + * +---------------+----------------+-------------------+-----------------+ + * |header size(*1)|next header size|extended header(*3)| compressed data | + * +---------------+----------------+-------------------+-----------------+ + * *------------------------(*1)-----------------------> <------(*2)-----> + * + */ +#define H3_FIELD_LEN_OFFSET 0 +#define H3_COMP_SIZE_OFFSET 7 +#define H3_ORIG_SIZE_OFFSET 11 +#define H3_TIME_OFFSET 15 +#define H3_CRC_OFFSET 21 +#define H3_HEADER_SIZE_OFFSET 24 +#define H3_FIXED_SIZE 28 +static int +lha_read_file_header_3(struct archive_read *a, struct lha *lha) +{ + const unsigned char *p; + size_t extdsize; + int err; + uint16_t header_crc; + + if ((p = __archive_read_ahead(a, H3_FIXED_SIZE, NULL)) == NULL) + return (truncated_error(a)); + + if (archive_le16dec(p + H3_FIELD_LEN_OFFSET) != 4) + goto invalid; + lha->header_size =archive_le32dec(p + H3_HEADER_SIZE_OFFSET); + lha->compsize = archive_le32dec(p + H3_COMP_SIZE_OFFSET); + lha->origsize = archive_le32dec(p + H3_ORIG_SIZE_OFFSET); + lha->mtime = archive_le32dec(p + H3_TIME_OFFSET); + lha->crc = archive_le16dec(p + H3_CRC_OFFSET); + lha->setflag |= CRC_IS_SET; + + if (lha->header_size < H3_FIXED_SIZE + 4) + goto invalid; + header_crc = lha_crc16(0, p, H3_FIXED_SIZE); + __archive_read_consume(a, H3_FIXED_SIZE); + + /* Read extended headers */ + err = lha_read_file_extended_header(a, lha, &header_crc, 4, + lha->header_size - H3_FIXED_SIZE, &extdsize); + if (err < ARCHIVE_WARN) + return (err); + + if (header_crc != lha->header_crc) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "LHa header CRC error"); + return (ARCHIVE_FATAL); + } + return (err); +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid LHa header"); + return (ARCHIVE_FATAL); +} + +/* + * Extended header format + * + * +0 +2 +3 -- used in header 1 and 2 + * +0 +4 +5 -- used in header 3 + * +--------------+---------+-------------------+--------------+-- + * |ex-header size|header id| data |ex-header size| ....... + * +--------------+---------+-------------------+--------------+-- + * <-------------( ex-header size)------------> <-- next extended header --* + * + * If the ex-header size is zero, it is the make of the end of extended + * headers. + * + */ +static int +lha_read_file_extended_header(struct archive_read *a, struct lha *lha, + uint16_t *crc, int sizefield_length, size_t limitsize, size_t *total_size) +{ + const void *h; + const unsigned char *extdheader; + size_t extdsize; + size_t datasize; + unsigned int i; + unsigned char extdtype; + +#define EXT_HEADER_CRC 0x00 /* Header CRC and information*/ +#define EXT_FILENAME 0x01 /* Filename */ +#define EXT_DIRECTORY 0x02 /* Directory name */ +#define EXT_DOS_ATTR 0x40 /* MS-DOS attribute */ +#define EXT_TIMESTAMP 0x41 /* Windows time stamp */ +#define EXT_FILESIZE 0x42 /* Large file size */ +#define EXT_TIMEZONE 0x43 /* Time zone */ +#define EXT_UTF16_FILENAME 0x44 /* UTF-16 filename */ +#define EXT_UTF16_DIRECTORY 0x45 /* UTF-16 directory name */ +#define EXT_CODEPAGE 0x46 /* Codepage */ +#define EXT_UNIX_MODE 0x50 /* File permission */ +#define EXT_UNIX_GID_UID 0x51 /* gid,uid */ +#define EXT_UNIX_GNAME 0x52 /* Group name */ +#define EXT_UNIX_UNAME 0x53 /* User name */ +#define EXT_UNIX_MTIME 0x54 /* Modified time */ +#define EXT_OS2_NEW_ATTR 0x7f /* new attribute(OS/2 only) */ +#define EXT_NEW_ATTR 0xff /* new attribute */ + + *total_size = sizefield_length; + + for (;;) { + /* Read an extended header size. */ + if ((h = + __archive_read_ahead(a, sizefield_length, NULL)) == NULL) + return (truncated_error(a)); + /* Check if the size is the zero indicates the end of the + * extended header. */ + if (sizefield_length == sizeof(uint16_t)) + extdsize = archive_le16dec(h); + else + extdsize = archive_le32dec(h); + if (extdsize == 0) { + /* End of extended header */ + if (crc != NULL) + *crc = lha_crc16(*crc, h, sizefield_length); + __archive_read_consume(a, sizefield_length); + return (ARCHIVE_OK); + } + + /* Sanity check to the extended header size. */ + if (((uint64_t)*total_size + extdsize) > + (uint64_t)limitsize || + extdsize <= (size_t)sizefield_length) + goto invalid; + + /* Read the extended header. */ + if ((h = __archive_read_ahead(a, extdsize, NULL)) == NULL) + return (truncated_error(a)); + *total_size += extdsize; + + extdheader = (const unsigned char *)h; + /* Get the extended header type. */ + extdtype = extdheader[sizefield_length]; + /* Calculate an extended data size. */ + datasize = extdsize - (1 + sizefield_length); + /* Skip an extended header size field and type field. */ + extdheader += sizefield_length + 1; + + if (crc != NULL && extdtype != EXT_HEADER_CRC) + *crc = lha_crc16(*crc, h, extdsize); + switch (extdtype) { + case EXT_HEADER_CRC: + /* We only use a header CRC. Following data will not + * be used. */ + if (datasize >= 2) { + lha->header_crc = archive_le16dec(extdheader); + if (crc != NULL) { + static const char zeros[2] = {0, 0}; + *crc = lha_crc16(*crc, h, + extdsize - datasize); + /* CRC value itself as zero */ + *crc = lha_crc16(*crc, zeros, 2); + *crc = lha_crc16(*crc, + extdheader+2, datasize - 2); + } + } + break; + case EXT_FILENAME: + if (datasize == 0) { + /* maybe directory header */ + archive_string_empty(&lha->filename); + break; + } + archive_strncpy(&lha->filename, + (const char *)extdheader, datasize); + break; + case EXT_DIRECTORY: + if (datasize == 0) + /* no directory name data. exit this case. */ + break; + + archive_strncpy(&lha->dirname, + (const char *)extdheader, datasize); + /* + * Convert directory delimiter from 0xFF + * to '/' for local system. + */ + for (i = 0; i < lha->dirname.length; i++) { + if ((unsigned char)lha->dirname.s[i] == 0xFF) + lha->dirname.s[i] = '/'; + } + /* Is last character directory separator? */ + if (lha->dirname.s[lha->dirname.length-1] != '/') + /* invalid directory data */ + goto invalid; + break; + case EXT_DOS_ATTR: + if (datasize == 2) + lha->dos_attr = (unsigned char) + (archive_le16dec(extdheader) & 0xff); + break; + case EXT_TIMESTAMP: + if (datasize == (sizeof(uint64_t) * 3)) { + lha->birthtime = lha_win_time( + archive_le64dec(extdheader), + &lha->birthtime_tv_nsec); + extdheader += sizeof(uint64_t); + lha->mtime = lha_win_time( + archive_le64dec(extdheader), + &lha->mtime_tv_nsec); + extdheader += sizeof(uint64_t); + lha->atime = lha_win_time( + archive_le64dec(extdheader), + &lha->atime_tv_nsec); + lha->setflag |= BIRTHTIME_IS_SET | + ATIME_IS_SET; + } + break; + case EXT_FILESIZE: + if (datasize == sizeof(uint64_t) * 2) { + lha->compsize = archive_le64dec(extdheader); + extdheader += sizeof(uint64_t); + lha->origsize = archive_le64dec(extdheader); + } + break; + case EXT_CODEPAGE: + /* Get an archived filename charset from codepage. + * This overwrites the charset specified by + * hdrcharset option. */ + if (datasize == sizeof(uint32_t)) { + struct archive_string cp; + const char *charset; + + archive_string_init(&cp); + switch (archive_le32dec(extdheader)) { + case 65001: /* UTF-8 */ + charset = "UTF-8"; + break; + default: + archive_string_sprintf(&cp, "CP%d", + (int)archive_le32dec(extdheader)); + charset = cp.s; + break; + } + lha->sconv = + archive_string_conversion_from_charset( + &(a->archive), charset, 1); + archive_string_free(&cp); + if (lha->sconv == NULL) + return (ARCHIVE_FATAL); + } + break; + case EXT_UNIX_MODE: + if (datasize == sizeof(uint16_t)) { + lha->mode = archive_le16dec(extdheader); + lha->setflag |= UNIX_MODE_IS_SET; + } + break; + case EXT_UNIX_GID_UID: + if (datasize == (sizeof(uint16_t) * 2)) { + lha->gid = archive_le16dec(extdheader); + lha->uid = archive_le16dec(extdheader+2); + } + break; + case EXT_UNIX_GNAME: + if (datasize > 0) + archive_strncpy(&lha->gname, + (const char *)extdheader, datasize); + break; + case EXT_UNIX_UNAME: + if (datasize > 0) + archive_strncpy(&lha->uname, + (const char *)extdheader, datasize); + break; + case EXT_UNIX_MTIME: + if (datasize == sizeof(uint32_t)) + lha->mtime = archive_le32dec(extdheader); + break; + case EXT_OS2_NEW_ATTR: + /* This extended header is OS/2 depend. */ + if (datasize == 16) { + lha->dos_attr = (unsigned char) + (archive_le16dec(extdheader) & 0xff); + lha->mode = archive_le16dec(extdheader+2); + lha->gid = archive_le16dec(extdheader+4); + lha->uid = archive_le16dec(extdheader+6); + lha->birthtime = archive_le32dec(extdheader+8); + lha->atime = archive_le32dec(extdheader+12); + lha->setflag |= UNIX_MODE_IS_SET + | BIRTHTIME_IS_SET | ATIME_IS_SET; + } + break; + case EXT_NEW_ATTR: + if (datasize == 20) { + lha->mode = (mode_t)archive_le32dec(extdheader); + lha->gid = archive_le32dec(extdheader+4); + lha->uid = archive_le32dec(extdheader+8); + lha->birthtime = archive_le32dec(extdheader+12); + lha->atime = archive_le32dec(extdheader+16); + lha->setflag |= UNIX_MODE_IS_SET + | BIRTHTIME_IS_SET | ATIME_IS_SET; + } + break; + case EXT_TIMEZONE: /* Not supported */ + case EXT_UTF16_FILENAME: /* Not supported */ + case EXT_UTF16_DIRECTORY: /* Not supported */ + default: + break; + } + + __archive_read_consume(a, extdsize); + } +invalid: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid extended LHa header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_lha_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + int r; + + if (lha->entry_unconsumed) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, lha->entry_unconsumed); + lha->entry_unconsumed = 0; + } + if (lha->end_of_entry) { + if (!lha->end_of_entry_cleanup) { + if ((lha->setflag & CRC_IS_SET) && + lha->crc != lha->entry_crc_calculated) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "LHa data CRC error"); + return (ARCHIVE_WARN); + } + + /* End-of-entry cleanup done. */ + lha->end_of_entry_cleanup = 1; + } + *offset = lha->entry_offset; + *size = 0; + *buff = NULL; + return (ARCHIVE_EOF); + } + + if (lha->entry_is_compressed) + r = lha_read_data_lzh(a, buff, size, offset); + else + /* No compression. */ + r = lha_read_data_none(a, buff, size, offset); + return (r); +} + +/* + * Read a file content in no compression. + * + * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets + * lha->end_of_entry if it consumes all of the data. + */ +static int +lha_read_data_none(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + ssize_t bytes_avail; + + if (lha->entry_bytes_remaining == 0) { + *buff = NULL; + *size = 0; + *offset = lha->entry_offset; + lha->end_of_entry = 1; + return (ARCHIVE_OK); + } + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + *buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa file data"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > lha->entry_bytes_remaining) + bytes_avail = lha->entry_bytes_remaining; + lha->entry_crc_calculated = + lha_crc16(lha->entry_crc_calculated, *buff, bytes_avail); + *size = bytes_avail; + *offset = lha->entry_offset; + lha->entry_offset += bytes_avail; + lha->entry_bytes_remaining -= bytes_avail; + if (lha->entry_bytes_remaining == 0) + lha->end_of_entry = 1; + lha->entry_unconsumed = bytes_avail; + return (ARCHIVE_OK); +} + +/* + * Read a file content in LZHUFF encoding. + * + * Returns ARCHIVE_OK if successful, returns ARCHIVE_WARN if compression is + * unsupported, ARCHIVE_FATAL otherwise, sets lha->end_of_entry if it consumes + * all of the data. + */ +static int +lha_read_data_lzh(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct lha *lha = (struct lha *)(a->format->data); + ssize_t bytes_avail; + int r; + + /* If the buffer hasn't been allocated, allocate it now. */ + if (lha->uncompressed_buffer == NULL) { + lha->uncompressed_buffer_size = 64 * 1024; + lha->uncompressed_buffer + = (unsigned char *)malloc(lha->uncompressed_buffer_size); + if (lha->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for lzh decompression"); + return (ARCHIVE_FATAL); + } + } + + /* If we haven't yet read any data, initialize the decompressor. */ + if (!lha->decompress_init) { + r = lzh_decode_init(&(lha->strm), lha->method); + switch (r) { + case ARCHIVE_OK: + break; + case ARCHIVE_FAILED: + /* Unsupported compression. */ + *buff = NULL; + *size = 0; + *offset = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported lzh compression method -%c%c%c-", + lha->method[0], lha->method[1], lha->method[2]); + /* We know compressed size; just skip it. */ + archive_read_format_lha_read_data_skip(a); + return (ARCHIVE_WARN); + default: + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory " + "for lzh decompression"); + return (ARCHIVE_FATAL); + } + /* We've initialized decompression for this stream. */ + lha->decompress_init = 1; + lha->strm.avail_out = 0; + lha->strm.total_out = 0; + } + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + lha->strm.next_in = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated LHa file body"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > lha->entry_bytes_remaining) + bytes_avail = lha->entry_bytes_remaining; + + lha->strm.avail_in = bytes_avail; + lha->strm.total_in = 0; + if (lha->strm.avail_out == 0) { + lha->strm.next_out = lha->uncompressed_buffer; + lha->strm.avail_out = lha->uncompressed_buffer_size; + } + + r = lzh_decode(&(lha->strm), bytes_avail == lha->entry_bytes_remaining); + switch (r) { + case ARCHIVE_OK: + break; + case ARCHIVE_EOF: + lha->end_of_entry = 1; + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Bad lzh data"); + return (ARCHIVE_FAILED); + } + lha->entry_unconsumed = lha->strm.total_in; + lha->entry_bytes_remaining -= lha->strm.total_in; + + if (lha->strm.avail_out == 0 || lha->end_of_entry) { + *offset = lha->entry_offset; + *size = lha->strm.next_out - lha->uncompressed_buffer; + *buff = lha->uncompressed_buffer; + lha->entry_crc_calculated = + lha_crc16(lha->entry_crc_calculated, *buff, *size); + lha->entry_offset += *size; + } else { + *offset = lha->entry_offset; + *size = 0; + *buff = NULL; + } + return (ARCHIVE_OK); +} + +/* + * Skip a file content. + */ +static int +archive_read_format_lha_read_data_skip(struct archive_read *a) +{ + struct lha *lha; + off_t bytes_skipped; + + lha = (struct lha *)(a->format->data); + + if (lha->entry_unconsumed) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, lha->entry_unconsumed); + lha->entry_unconsumed = 0; + } + + /* if we've already read to end of data, we're done. */ + if (lha->end_of_entry_cleanup) + return (ARCHIVE_OK); + + /* + * If the length is at the beginning, we can skip the + * compressed data much more quickly. + */ + bytes_skipped = __archive_read_consume(a, lha->entry_bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + + /* This entry is finished and done. */ + lha->end_of_entry_cleanup = lha->end_of_entry = 1; + return (ARCHIVE_OK); +} + +static int +archive_read_format_lha_cleanup(struct archive_read *a) +{ + struct lha *lha = (struct lha *)(a->format->data); + + lzh_decode_free(&(lha->strm)); + free(lha->uncompressed_buffer); + archive_string_free(&(lha->dirname)); + archive_string_free(&(lha->filename)); + archive_string_free(&(lha->uname)); + archive_string_free(&(lha->gname)); + archive_wstring_free(&(lha->ws)); + free(lha); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +/* + * 'LHa for UNIX' utility has archived a symbolic-link name after + * a pathname with '|' character. + * This function extracts the symbolic-link name from the pathname. + * + * example. + * 1. a symbolic-name is 'aaa/bb/cc' + * 2. a filename is 'xxx/bbb' + * then a archived pathname is 'xxx/bbb|aaa/bb/cc' + */ +static int +lha_parse_linkname(struct archive_string *linkname, + struct archive_string *pathname) +{ + char * linkptr; + int symlen; + + linkptr = strchr(pathname->s, '|'); + if (linkptr != NULL) { + symlen = strlen(linkptr + 1); + archive_strncpy(linkname, linkptr+1, symlen); + + *linkptr = 0; + pathname->length = strlen(pathname->s); + + return (1); + } + return (0); +} + +/* Convert an MSDOS-style date/time into Unix-style time. */ +static time_t +lha_dos_time(const unsigned char *p) +{ + int msTime, msDate; + struct tm ts; + + msTime = archive_le16dec(p); + msDate = archive_le16dec(p+2); + + memset(&ts, 0, sizeof(ts)); + ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ + ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ + ts.tm_mday = msDate & 0x1f; /* Day of month. */ + ts.tm_hour = (msTime >> 11) & 0x1f; + ts.tm_min = (msTime >> 5) & 0x3f; + ts.tm_sec = (msTime << 1) & 0x3e; + ts.tm_isdst = -1; + return (mktime(&ts)); +} + +/* Convert an MS-Windows-style date/time into Unix-style time. */ +static time_t +lha_win_time(uint64_t wintime, long *ns) +{ +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) + + if (wintime >= EPOC_TIME) { + wintime -= EPOC_TIME; /* 1970-01-01 00:00:00 (UTC) */ + if (ns != NULL) + *ns = (long)(wintime % 10000000) * 100; + return (wintime / 10000000); + } else { + if (ns != NULL) + *ns = 0; + return (0); + } +} + +static unsigned char +lha_calcsum(unsigned char sum, const void *pp, int offset, int size) +{ + unsigned char const *p = (unsigned char const *)pp; + + p += offset; + while (--size >= 0) + sum += *p++; + return (sum); +} + +#define CRC16(crc, v) do { \ + (crc) = crc16tbl[((crc) ^ v) & 0xFF] ^ ((crc) >> 8); \ +} while (0) + +static uint16_t +lha_crc16(uint16_t crc, const void *pp, size_t len) +{ + const unsigned char *buff = (const unsigned char *)pp; + + while (len >= 8) { + CRC16(crc, *buff++); CRC16(crc, *buff++); + CRC16(crc, *buff++); CRC16(crc, *buff++); + CRC16(crc, *buff++); CRC16(crc, *buff++); + CRC16(crc, *buff++); CRC16(crc, *buff++); + len -= 8; + } + switch (len) { + case 7: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 6: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 5: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 4: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 3: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 2: + CRC16(crc, *buff++); + /* FALL THROUGH */ + case 1: + CRC16(crc, *buff); + /* FALL THROUGH */ + case 0: + break; + } + return (crc); +} + + +/* + * Initialize LZHUF decoder. + * + * Returns ARCHIVE_OK if initialization was successful. + * Returns ARCHIVE_FAILED if method is unsupported. + * Returns ARCHIVE_FATAL if initialization failed; memory allocation + * error occurred. + */ +static int +lzh_decode_init(struct lzh_stream *strm, const char *method) +{ + struct lzh_dec *ds; + int w_bits, w_size; + + if (strm->ds == NULL) { + strm->ds = calloc(1, sizeof(*strm->ds)); + if (strm->ds == NULL) + return (ARCHIVE_FATAL); + } + ds = strm->ds; + ds->error = ARCHIVE_FAILED; + if (method == NULL || method[0] != 'l' || method[1] != 'h') + return (ARCHIVE_FAILED); + switch (method[2]) { + case '5': + w_bits = 13;/* 8KiB for window */ + break; + case '6': + w_bits = 15;/* 32KiB for window */ + break; + case '7': + w_bits = 16;/* 64KiB for window */ + break; + default: + return (ARCHIVE_FAILED);/* Not supported. */ + } + ds->error = ARCHIVE_FATAL; + w_size = ds->w_size; + ds->w_size = 1U << w_bits; + ds->w_mask = ds->w_size -1; + if (ds->w_buff == NULL || w_size != ds->w_size) { + free(ds->w_buff); + ds->w_buff = malloc(ds->w_size); + if (ds->w_buff == NULL) + return (ARCHIVE_FATAL); + } + memset(ds->w_buff, 0x20, ds->w_size); + ds->w_pos = 0; + ds->w_remaining = 0; + ds->state = 0; + ds->pos_pt_len_size = w_bits + 1; + ds->pos_pt_len_bits = (w_bits == 15 || w_bits == 16)? 5: 4; + ds->literal_pt_len_size = PT_BITLEN_SIZE; + ds->literal_pt_len_bits = 5; + ds->br.cache_buffer = 0; + ds->br.cache_avail = 0; + + if (lzh_huffman_init(&(ds->lt), LT_BITLEN_SIZE, 16) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + ds->lt.len_bits = 9; + if (lzh_huffman_init(&(ds->pt), PT_BITLEN_SIZE, 16) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + ds->error = 0; + + return (ARCHIVE_OK); +} + +/* + * Release LZHUF decoder. + */ +static void +lzh_decode_free(struct lzh_stream *strm) +{ + + if (strm->ds == NULL) + return; + free(strm->ds->w_buff); + lzh_huffman_free(&(strm->ds->lt)); + lzh_huffman_free(&(strm->ds->pt)); + free(strm->ds); + strm->ds = NULL; +} + +/* + * Bit stream reader. + */ +/* Check that the cache buffer has enough bits. */ +#define lzh_br_has(br, n) ((br)->cache_avail >= n) +/* Get compressed data by bit. */ +#define lzh_br_bits(br, n) \ + (((uint16_t)((br)->cache_buffer >> \ + ((br)->cache_avail - (n)))) & cache_masks[n]) +#define lzh_br_bits_forced(br, n) \ + (((uint16_t)((br)->cache_buffer << \ + ((n) - (br)->cache_avail))) & cache_masks[n]) +/* Read ahead to make sure the cache buffer has enough compressed data we + * will use. + * True : completed, there is enough data in the cache buffer. + * False : we met that strm->next_in is empty, we have to get following + * bytes. */ +#define lzh_br_read_ahead_0(strm, br, n) \ + (lzh_br_has(br, (n)) || lzh_br_fillup(strm, br)) +/* True : the cache buffer has some bits as much as we need. + * False : there are no enough bits in the cache buffer to be used, + * we have to get following bytes if we could. */ +#define lzh_br_read_ahead(strm, br, n) \ + (lzh_br_read_ahead_0((strm), (br), (n)) || lzh_br_has((br), (n))) + +/* Notify how many bits we consumed. */ +#define lzh_br_consume(br, n) ((br)->cache_avail -= (n)) +#define lzh_br_unconsume(br, n) ((br)->cache_avail += (n)) + +static const uint16_t cache_masks[] = { + 0x0000, 0x0001, 0x0003, 0x0007, + 0x000F, 0x001F, 0x003F, 0x007F, + 0x00FF, 0x01FF, 0x03FF, 0x07FF, + 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, + 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF +}; + +/* + * Shift away used bits in the cache data and fill it up with following bits. + * Call this when cache buffer does not have enough bits you need. + * + * Returns 1 if the cache buffer is full. + * Returns 0 if the cache buffer is not full; input buffer is empty. + */ +static int +lzh_br_fillup(struct lzh_stream *strm, struct lzh_br *br) +{ + int n = CACHE_BITS - br->cache_avail; + + for (;;) { + switch (n >> 3) { + case 8: + if (strm->avail_in >= 8) { + br->cache_buffer = + ((uint64_t)strm->next_in[0]) << 56 | + ((uint64_t)strm->next_in[1]) << 48 | + ((uint64_t)strm->next_in[2]) << 40 | + ((uint64_t)strm->next_in[3]) << 32 | + ((uint32_t)strm->next_in[4]) << 24 | + ((uint32_t)strm->next_in[5]) << 16 | + ((uint32_t)strm->next_in[6]) << 8 | + (uint32_t)strm->next_in[7]; + strm->next_in += 8; + strm->avail_in -= 8; + br->cache_avail += 8 * 8; + return (1); + } + break; + case 7: + if (strm->avail_in >= 7) { + br->cache_buffer = + (br->cache_buffer << 56) | + ((uint64_t)strm->next_in[0]) << 48 | + ((uint64_t)strm->next_in[1]) << 40 | + ((uint64_t)strm->next_in[2]) << 32 | + ((uint32_t)strm->next_in[3]) << 24 | + ((uint32_t)strm->next_in[4]) << 16 | + ((uint32_t)strm->next_in[5]) << 8 | + (uint32_t)strm->next_in[6]; + strm->next_in += 7; + strm->avail_in -= 7; + br->cache_avail += 7 * 8; + return (1); + } + break; + case 6: + if (strm->avail_in >= 6) { + br->cache_buffer = + (br->cache_buffer << 48) | + ((uint64_t)strm->next_in[0]) << 40 | + ((uint64_t)strm->next_in[1]) << 32 | + ((uint32_t)strm->next_in[2]) << 24 | + ((uint32_t)strm->next_in[3]) << 16 | + ((uint32_t)strm->next_in[4]) << 8 | + (uint32_t)strm->next_in[5]; + strm->next_in += 6; + strm->avail_in -= 6; + br->cache_avail += 6 * 8; + return (1); + } + break; + case 0: + /* We have enough compressed data in + * the cache buffer.*/ + return (1); + default: + break; + } + if (strm->avail_in == 0) { + /* There is not enough compressed data to fill up the + * cache buffer. */ + return (0); + } + br->cache_buffer = + (br->cache_buffer << 8) | *strm->next_in++; + strm->avail_in--; + br->cache_avail += 8; + n -= 8; + } +} + +/* + * Decode LZHUF. + * + * 1. Returns ARCHIVE_OK if output buffer or input buffer are empty. + * Please set available buffer and call this function again. + * 2. Returns ARCHIVE_EOF if decompression has been completed. + * 3. Returns ARCHIVE_FAILED if an error occurred; compressed data + * is broken or you do not set 'last' flag properly. + * 4. 'last' flag is very important, you must set 1 to the flag if there + * is no input data. The lha compressed data format does not provide how + * to know the compressed data is really finished. + * Note: lha command utility check if the total size of output bytes is + * reached the uncompressed size recorded in its header. it does not mind + * that the decoding process is properly finished. + * GNU ZIP can decompress another compressed file made by SCO LZH compress. + * it handles EOF as null to fill read buffer with zero until the decoding + * process meet 2 bytes of zeros at reading a size of a next chunk, so the + * zeros are treated as the mark of the end of the data although the zeros + * is dummy, not the file data. + */ +static int lzh_read_blocks(struct lzh_stream *, int); +static int lzh_decode_blocks(struct lzh_stream *, int); +#define ST_RD_BLOCK 0 +#define ST_RD_PT_1 1 +#define ST_RD_PT_2 2 +#define ST_RD_PT_3 3 +#define ST_RD_PT_4 4 +#define ST_RD_LITERAL_1 5 +#define ST_RD_LITERAL_2 6 +#define ST_RD_LITERAL_3 7 +#define ST_RD_POS_DATA_1 8 +#define ST_GET_LITERAL 9 +#define ST_GET_POS_1 10 +#define ST_GET_POS_2 11 +#define ST_COPY_DATA 12 + +static int +lzh_decode(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + int64_t avail_in; + int r; + + if (ds->error) + return (ds->error); + + avail_in = strm->avail_in; + do { + if (ds->state < ST_GET_LITERAL) + r = lzh_read_blocks(strm, last); + else + r = lzh_decode_blocks(strm, last); + } while (r == 100); + strm->total_in += avail_in - strm->avail_in; + return (r); +} + +static int +lzh_copy_from_window(struct lzh_stream *strm, struct lzh_dec *ds) +{ + size_t copy_bytes; + + if (ds->w_remaining == 0 && ds->w_pos > 0) { + if (ds->w_pos - ds->copy_pos <= strm->avail_out) + copy_bytes = ds->w_pos - ds->copy_pos; + else + copy_bytes = strm->avail_out; + memcpy(strm->next_out, + ds->w_buff + ds->copy_pos, copy_bytes); + ds->copy_pos += copy_bytes; + } else { + if (ds->w_remaining <= strm->avail_out) + copy_bytes = ds->w_remaining; + else + copy_bytes = strm->avail_out; + memcpy(strm->next_out, + ds->w_buff + ds->w_size - ds->w_remaining, copy_bytes); + ds->w_remaining -= copy_bytes; + } + strm->next_out += copy_bytes; + strm->avail_out -= copy_bytes; + strm->total_out += copy_bytes; + if (strm->avail_out == 0) + return (0); + else + return (1); +} + +static int +lzh_read_blocks(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br *br = &(ds->br); + int c = 0, i; + unsigned rbits; + + for (;;) { + switch (ds->state) { + case ST_RD_BLOCK: + /* + * Read a block number indicates how many blocks + * we will handle. The block is composed of a + * literal and a match, sometimes a literal only + * in particular, there are no reference data at + * the beginning of the decompression. + */ + if (!lzh_br_read_ahead_0(strm, br, 16)) { + if (!last) + /* We need following data. */ + return (ARCHIVE_OK); + if (lzh_br_has(br, 8)) { + /* + * It seems there are extra bits. + * 1. Compressed data is broken. + * 2. `last' flag does not properly + * set. + */ + goto failed; + } + if (ds->w_pos > 0) { + if (!lzh_copy_from_window(strm, ds)) + return (ARCHIVE_OK); + } + /* End of compressed data; we have completely + * handled all compressed data. */ + return (ARCHIVE_EOF); + } + ds->blocks_avail = lzh_br_bits(br, 16); + if (ds->blocks_avail == 0) + goto failed; + lzh_br_consume(br, 16); + /* + * Read a literal table compressed in huffman + * coding. + */ + ds->pt.len_size = ds->literal_pt_len_size; + ds->pt.len_bits = ds->literal_pt_len_bits; + ds->reading_position = 0; + /* FALL THROUGH */ + case ST_RD_PT_1: + /* Note: ST_RD_PT_1, ST_RD_PT_2 and ST_RD_PT_4 are + * used in reading both a literal table and a + * position table. */ + if (!lzh_br_read_ahead(strm, br, ds->pt.len_bits)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_PT_1; + return (ARCHIVE_OK); + } + ds->pt.len_avail = lzh_br_bits(br, ds->pt.len_bits); + lzh_br_consume(br, ds->pt.len_bits); + /* FALL THROUGH */ + case ST_RD_PT_2: + if (ds->pt.len_avail == 0) { + /* There is no bitlen. */ + if (!lzh_br_read_ahead(strm, br, + ds->pt.len_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->state = ST_RD_PT_2; + return (ARCHIVE_OK); + } + if (!lzh_make_fake_table(&(ds->pt), + lzh_br_bits(br, ds->pt.len_bits))) + goto failed;/* Invalid data. */ + lzh_br_consume(br, ds->pt.len_bits); + if (ds->reading_position) + ds->state = ST_GET_LITERAL; + else + ds->state = ST_RD_LITERAL_1; + break; + } else if (ds->pt.len_avail > ds->pt.len_size) + goto failed;/* Invalid data. */ + ds->loop = 0; + memset(ds->pt.freq, 0, sizeof(ds->pt.freq)); + if (ds->pt.len_avail < 3 || + ds->pt.len_size == ds->pos_pt_len_size) { + ds->state = ST_RD_PT_4; + break; + } + /* FALL THROUGH */ + case ST_RD_PT_3: + ds->loop = lzh_read_pt_bitlen(strm, ds->loop, 3); + if (ds->loop < 3) { + if (ds->loop < 0 || last) + goto failed;/* Invalid data. */ + /* Not completed, get following data. */ + ds->state = ST_RD_PT_3; + return (ARCHIVE_OK); + } + /* There are some null in bitlen of the literal. */ + if (!lzh_br_read_ahead(strm, br, 2)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_PT_3; + return (ARCHIVE_OK); + } + c = lzh_br_bits(br, 2); + lzh_br_consume(br, 2); + if (c > ds->pt.len_avail - 3) + goto failed;/* Invalid data. */ + for (i = 3; c-- > 0 ;) + ds->pt.bitlen[i++] = 0; + ds->loop = i; + /* FALL THROUGH */ + case ST_RD_PT_4: + ds->loop = lzh_read_pt_bitlen(strm, ds->loop, + ds->pt.len_avail); + if (ds->loop < ds->pt.len_avail) { + if (ds->loop < 0 || last) + goto failed;/* Invalid data. */ + /* Not completed, get following data. */ + ds->state = ST_RD_PT_4; + return (ARCHIVE_OK); + } + if (!lzh_make_huffman_table(&(ds->pt))) + goto failed;/* Invalid data */ + if (ds->reading_position) { + ds->state = ST_GET_LITERAL; + break; + } + /* FALL THROUGH */ + case ST_RD_LITERAL_1: + if (!lzh_br_read_ahead(strm, br, ds->lt.len_bits)) { + if (last) + goto failed;/* Truncated data. */ + ds->state = ST_RD_LITERAL_1; + return (ARCHIVE_OK); + } + ds->lt.len_avail = lzh_br_bits(br, ds->lt.len_bits); + lzh_br_consume(br, ds->lt.len_bits); + /* FALL THROUGH */ + case ST_RD_LITERAL_2: + if (ds->lt.len_avail == 0) { + /* There is no bitlen. */ + if (!lzh_br_read_ahead(strm, br, + ds->lt.len_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->state = ST_RD_LITERAL_2; + return (ARCHIVE_OK); + } + if (!lzh_make_fake_table(&(ds->lt), + lzh_br_bits(br, ds->lt.len_bits))) + goto failed;/* Invalid data */ + lzh_br_consume(br, ds->lt.len_bits); + ds->state = ST_RD_POS_DATA_1; + break; + } else if (ds->lt.len_avail > ds->lt.len_size) + goto failed;/* Invalid data */ + ds->loop = 0; + memset(ds->lt.freq, 0, sizeof(ds->lt.freq)); + /* FALL THROUGH */ + case ST_RD_LITERAL_3: + i = ds->loop; + while (i < ds->lt.len_avail) { + if (!lzh_br_read_ahead(strm, br, + ds->pt.max_bits)) { + if (last) + goto failed;/* Truncated data.*/ + ds->loop = i; + ds->state = ST_RD_LITERAL_3; + return (ARCHIVE_OK); + } + rbits = lzh_br_bits(br, ds->pt.max_bits); + c = lzh_decode_huffman(&(ds->pt), rbits); + if (c > 2) { + /* Note: 'c' will never be more than + * eighteen since it's limited by + * PT_BITLEN_SIZE, which is being set + * to ds->pt.len_size through + * ds->literal_pt_len_size. */ + lzh_br_consume(br, ds->pt.bitlen[c]); + c -= 2; + ds->lt.freq[c]++; + ds->lt.bitlen[i++] = c; + } else if (c == 0) { + lzh_br_consume(br, ds->pt.bitlen[c]); + ds->lt.bitlen[i++] = 0; + } else { + /* c == 1 or c == 2 */ + int n = (c == 1)?4:9; + if (!lzh_br_read_ahead(strm, br, + ds->pt.bitlen[c] + n)) { + if (last) /* Truncated data. */ + goto failed; + ds->loop = i; + ds->state = ST_RD_LITERAL_3; + return (ARCHIVE_OK); + } + lzh_br_consume(br, ds->pt.bitlen[c]); + c = lzh_br_bits(br, n); + lzh_br_consume(br, n); + c += (n == 4)?3:20; + if (i + c > ds->lt.len_avail) + goto failed;/* Invalid data */ + memset(&(ds->lt.bitlen[i]), 0, c); + i += c; + } + } + if (i > ds->lt.len_avail || + !lzh_make_huffman_table(&(ds->lt))) + goto failed;/* Invalid data */ + /* FALL THROUGH */ + case ST_RD_POS_DATA_1: + /* + * Read a position table compressed in huffman + * coding. + */ + ds->pt.len_size = ds->pos_pt_len_size; + ds->pt.len_bits = ds->pos_pt_len_bits; + ds->reading_position = 1; + ds->state = ST_RD_PT_1; + break; + case ST_GET_LITERAL: + return (100); + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +} + +static int +lzh_decode_blocks(struct lzh_stream *strm, int last) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br bre = ds->br; + struct huffman *lt = &(ds->lt); + struct huffman *pt = &(ds->pt); + unsigned char *w_buff = ds->w_buff; + unsigned char *lt_bitlen = lt->bitlen; + unsigned char *pt_bitlen = pt->bitlen; + int blocks_avail = ds->blocks_avail, c = 0; + int copy_len = ds->copy_len, copy_pos = ds->copy_pos; + int w_pos = ds->w_pos, w_mask = ds->w_mask, w_size = ds->w_size; + int lt_max_bits = lt->max_bits, pt_max_bits = pt->max_bits; + int state = ds->state; + + if (ds->w_remaining > 0) { + if (!lzh_copy_from_window(strm, ds)) + goto next_data; + } + for (;;) { + switch (state) { + case ST_GET_LITERAL: + for (;;) { + if (blocks_avail == 0) { + /* We have decoded all blocks. + * Let's handle next blocks. */ + ds->state = ST_RD_BLOCK; + ds->br = bre; + ds->blocks_avail = 0; + ds->w_pos = w_pos; + ds->copy_pos = 0; + return (100); + } + + /* lzh_br_read_ahead() always try to fill the + * cache buffer up. In specific situation we + * are close to the end of the data, the cache + * buffer will not be full and thus we have to + * determine if the cache buffer has some bits + * as much as we need after lzh_br_read_ahead() + * failed. */ + if (!lzh_br_read_ahead(strm, &bre, + lt_max_bits)) { + if (!last) + goto next_data; + /* Remaining bits are less than + * maximum bits(lt.max_bits) but maybe + * it still remains as much as we need, + * so we should try to use it with + * dummy bits. */ + c = lzh_decode_huffman(lt, + lzh_br_bits_forced(&bre, + lt_max_bits)); + lzh_br_consume(&bre, lt_bitlen[c]); + if (!lzh_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + c = lzh_decode_huffman(lt, + lzh_br_bits(&bre, lt_max_bits)); + lzh_br_consume(&bre, lt_bitlen[c]); + } + blocks_avail--; + if (c > UCHAR_MAX) + /* Current block is a match data. */ + break; + /* + * 'c' is exactly a literal code. + */ + /* Save a decoded code to reference it + * afterward. */ + w_buff[w_pos] = c; + if (++w_pos >= w_size) { + w_pos = 0; + ds->w_remaining = w_size; + if (!lzh_copy_from_window(strm, ds)) + goto next_data; + } + } + /* 'c' is the length of a match pattern we have + * already extracted, which has be stored in + * window(ds->w_buff). */ + copy_len = c - (UCHAR_MAX + 1) + MINMATCH; + /* FALL THROUGH */ + case ST_GET_POS_1: + /* + * Get a reference position. + */ + if (!lzh_br_read_ahead(strm, &bre, pt_max_bits)) { + if (!last) { + state = ST_GET_POS_1; + ds->copy_len = copy_len; + goto next_data; + } + copy_pos = lzh_decode_huffman(pt, + lzh_br_bits_forced(&bre, pt_max_bits)); + lzh_br_consume(&bre, pt_bitlen[copy_pos]); + if (!lzh_br_has(&bre, 0)) + goto failed;/* Over read. */ + } else { + copy_pos = lzh_decode_huffman(pt, + lzh_br_bits(&bre, pt_max_bits)); + lzh_br_consume(&bre, pt_bitlen[copy_pos]); + } + /* FALL THROUGH */ + case ST_GET_POS_2: + if (copy_pos > 1) { + /* We need an additional adjustment number to + * the position. */ + int p = copy_pos - 1; + if (!lzh_br_read_ahead(strm, &bre, p)) { + if (last) + goto failed;/* Truncated data.*/ + state = ST_GET_POS_2; + ds->copy_len = copy_len; + ds->copy_pos = copy_pos; + goto next_data; + } + copy_pos = (1 << p) + lzh_br_bits(&bre, p); + lzh_br_consume(&bre, p); + } + /* The position is actually a distance from the last + * code we had extracted and thus we have to convert + * it to a position of the window. */ + copy_pos = (w_pos - copy_pos - 1) & w_mask; + /* FALL THROUGH */ + case ST_COPY_DATA: + /* + * Copy `copy_len' bytes as extracted data from + * the window into the output buffer. + */ + for (;;) { + int l; + + l = copy_len; + if (copy_pos > w_pos) { + if (l > w_size - copy_pos) + l = w_size - copy_pos; + } else { + if (l > w_size - w_pos) + l = w_size - w_pos; + } + if ((copy_pos + l < w_pos) + || (w_pos + l < copy_pos)) { + /* No overlap. */ + memcpy(w_buff + w_pos, + w_buff + copy_pos, l); + } else { + const unsigned char *s; + unsigned char *d; + int li; + + d = w_buff + w_pos; + s = w_buff + copy_pos; + for (li = 0; li < l; li++) + d[li] = s[li]; + } + w_pos = (w_pos + l) & w_mask; + if (w_pos == 0) { + ds->w_remaining = w_size; + if (!lzh_copy_from_window(strm, ds)) { + if (copy_len <= l) + state = ST_GET_LITERAL; + else { + state = ST_COPY_DATA; + ds->copy_len = + copy_len - l; + ds->copy_pos = + (copy_pos + l) + & w_mask; + } + goto next_data; + } + } + if (copy_len <= l) + /* A copy of current pattern ended. */ + break; + copy_len -= l; + copy_pos = (copy_pos + l) & w_mask; + } + state = ST_GET_LITERAL; + break; + } + } +failed: + return (ds->error = ARCHIVE_FAILED); +next_data: + ds->br = bre; + ds->blocks_avail = blocks_avail; + ds->state = state; + ds->w_pos = w_pos; + return (ARCHIVE_OK); +} + +static int +lzh_huffman_init(struct huffman *hf, size_t len_size, int tbl_bits) +{ + int bits; + + if (hf->bitlen == NULL) { + hf->bitlen = malloc(len_size * sizeof(hf->bitlen[0])); + if (hf->bitlen == NULL) + return (ARCHIVE_FATAL); + } + if (hf->tbl == NULL) { + if (tbl_bits < HTBL_BITS) + bits = tbl_bits; + else + bits = HTBL_BITS; + hf->tbl = malloc((1 << bits) * sizeof(hf->tbl[0])); + if (hf->tbl == NULL) + return (ARCHIVE_FATAL); + } + if (hf->tree == NULL && tbl_bits > HTBL_BITS) { + hf->tree_avail = 1 << (tbl_bits - HTBL_BITS + 4); + hf->tree = malloc(hf->tree_avail * sizeof(hf->tree[0])); + if (hf->tree == NULL) + return (ARCHIVE_FATAL); + } + hf->len_size = len_size; + hf->tbl_bits = tbl_bits; + return (ARCHIVE_OK); +} + +static void +lzh_huffman_free(struct huffman *hf) +{ + free(hf->bitlen); + free(hf->tbl); + free(hf->tree); +} + +static int +lzh_read_pt_bitlen(struct lzh_stream *strm, int start, int end) +{ + struct lzh_dec *ds = strm->ds; + struct lzh_br * br = &(ds->br); + int c, i; + + for (i = start; i < end;) { + /* + * bit pattern the number we need + * 000 -> 0 + * 001 -> 1 + * 010 -> 2 + * ... + * 110 -> 6 + * 1110 -> 7 + * 11110 -> 8 + * ... + * 1111111111110 -> 16 + */ + if (!lzh_br_read_ahead(strm, br, 3)) + return (i); + if ((c = lzh_br_bits(br, 3)) == 7) { + int d; + if (!lzh_br_read_ahead(strm, br, 13)) + return (i); + d = lzh_br_bits(br, 13); + while (d & 0x200) { + c++; + d <<= 1; + } + if (c > 16) + return (-1);/* Invalid data. */ + lzh_br_consume(br, c - 3); + } else + lzh_br_consume(br, 3); + ds->pt.bitlen[i++] = c; + ds->pt.freq[c]++; + } + return (i); +} + +static int +lzh_make_fake_table(struct huffman *hf, uint16_t c) +{ + if (c >= hf->len_size) + return (0); + hf->tbl[0] = c; + hf->max_bits = 0; + hf->shift_bits = 0; + hf->bitlen[hf->tbl[0]] = 0; + return (1); +} + +/* + * Make a huffman coding table. + */ +static int +lzh_make_huffman_table(struct huffman *hf) +{ + uint16_t *tbl; + const unsigned char *bitlen; + int bitptn[17], weight[17]; + int i, maxbits = 0, ptn, tbl_size, w; + int diffbits, len_avail; + + /* + * Initialize bit patterns. + */ + ptn = 0; + for (i = 1, w = 1 << 15; i <= 16; i++, w >>= 1) { + bitptn[i] = ptn; + weight[i] = w; + if (hf->freq[i]) { + ptn += hf->freq[i] * w; + maxbits = i; + } + } + if (ptn != 0x10000 || maxbits > hf->tbl_bits) + return (0);/* Invalid */ + + hf->max_bits = maxbits; + + /* + * Cut out extra bits which we won't house in the table. + * This preparation reduces the same calculation in the for-loop + * making the table. + */ + if (maxbits < 16) { + int ebits = 16 - maxbits; + for (i = 1; i <= maxbits; i++) { + bitptn[i] >>= ebits; + weight[i] >>= ebits; + } + } + if (maxbits > HTBL_BITS) { + int htbl_max; + uint16_t *p; + + diffbits = maxbits - HTBL_BITS; + for (i = 1; i <= HTBL_BITS; i++) { + bitptn[i] >>= diffbits; + weight[i] >>= diffbits; + } + htbl_max = bitptn[HTBL_BITS] + + weight[HTBL_BITS] * hf->freq[HTBL_BITS]; + p = &(hf->tbl[htbl_max]); + while (p < &hf->tbl[1U<shift_bits = diffbits; + + /* + * Make the table. + */ + tbl_size = 1 << HTBL_BITS; + tbl = hf->tbl; + bitlen = hf->bitlen; + len_avail = hf->len_avail; + hf->tree_used = 0; + for (i = 0; i < len_avail; i++) { + uint16_t *p; + int len, cnt; + uint16_t bit; + int extlen; + struct htree_t *ht; + + if (bitlen[i] == 0) + continue; + /* Get a bit pattern */ + len = bitlen[i]; + ptn = bitptn[len]; + cnt = weight[len]; + if (len <= HTBL_BITS) { + /* Calculate next bit pattern */ + if ((bitptn[len] = ptn + cnt) > tbl_size) + return (0);/* Invalid */ + /* Update the table */ + p = &(tbl[ptn]); + while (--cnt >= 0) + p[cnt] = (uint16_t)i; + continue; + } + + /* + * A bit length is too big to be housed to a direct table, + * so we use a tree model for its extra bits. + */ + bitptn[len] = ptn + cnt; + bit = 1U << (diffbits -1); + extlen = len - HTBL_BITS; + + p = &(tbl[ptn >> diffbits]); + if (*p == 0) { + *p = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + if (*p < len_avail || + *p >= (len_avail + hf->tree_used)) + return (0);/* Invalid */ + ht = &(hf->tree[*p - len_avail]); + } + while (--extlen > 0) { + if (ptn & bit) { + if (ht->left < len_avail) { + ht->left = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->left - len_avail]); + } + } else { + if (ht->right < len_avail) { + ht->right = len_avail + hf->tree_used; + ht = &(hf->tree[hf->tree_used++]); + if (hf->tree_used > hf->tree_avail) + return (0);/* Invalid */ + ht->left = 0; + ht->right = 0; + } else { + ht = &(hf->tree[ht->right - len_avail]); + } + } + bit >>= 1; + } + if (ptn & bit) { + if (ht->left != 0) + return (0);/* Invalid */ + ht->left = (uint16_t)i; + } else { + if (ht->right != 0) + return (0);/* Invalid */ + ht->right = (uint16_t)i; + } + } + return (1); +} + +static int +lzh_decode_huffman_tree(struct huffman *hf, unsigned rbits, int c) +{ + struct htree_t *ht; + int extlen; + + ht = hf->tree; + extlen = hf->shift_bits; + while (c >= hf->len_avail) { + c -= hf->len_avail; + if (extlen-- <= 0 || c >= hf->tree_used) + return (0); + if (rbits & (1U << extlen)) + c = ht[c].left; + else + c = ht[c].right; + } + return (c); +} + +static inline int +lzh_decode_huffman(struct huffman *hf, unsigned rbits) +{ + int c; + /* + * At first search an index table for a bit pattern. + * If it fails, search a huffman tree for. + */ + c = hf->tbl[rbits >> hf->shift_bits]; + if (c < hf->len_avail) + return (c); + /* This bit pattern needs to be found out at a huffman tree. */ + return (lzh_decode_huffman_tree(hf, rbits, c)); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c index 2faf3cafe..6ac7db807 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_mtree.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle * Copyright (c) 2008 Joerg Sonnenberger + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +26,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_mtree.c,v 1.11 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_mtree.c 201165 2009-12-29 05:52:13Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -52,152 +53,570 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_mtree.c,v 1.1 #include "archive_string.h" #ifndef O_BINARY -#define O_BINARY 0 +#define O_BINARY 0 #endif -#define MTREE_HAS_DEVICE 0x0001 -#define MTREE_HAS_FFLAGS 0x0002 -#define MTREE_HAS_GID 0x0004 -#define MTREE_HAS_GNAME 0x0008 -#define MTREE_HAS_MTIME 0x0010 -#define MTREE_HAS_NLINK 0x0020 -#define MTREE_HAS_PERM 0x0040 -#define MTREE_HAS_SIZE 0x0080 -#define MTREE_HAS_TYPE 0x0100 -#define MTREE_HAS_UID 0x0200 -#define MTREE_HAS_UNAME 0x0400 +#define MTREE_HAS_DEVICE 0x0001 +#define MTREE_HAS_FFLAGS 0x0002 +#define MTREE_HAS_GID 0x0004 +#define MTREE_HAS_GNAME 0x0008 +#define MTREE_HAS_MTIME 0x0010 +#define MTREE_HAS_NLINK 0x0020 +#define MTREE_HAS_PERM 0x0040 +#define MTREE_HAS_SIZE 0x0080 +#define MTREE_HAS_TYPE 0x0100 +#define MTREE_HAS_UID 0x0200 +#define MTREE_HAS_UNAME 0x0400 -#define MTREE_HAS_OPTIONAL 0x0800 +#define MTREE_HAS_OPTIONAL 0x0800 struct mtree_option { - struct mtree_option *next; - char *value; + struct mtree_option *next; + char *value; }; struct mtree_entry { - struct mtree_entry *next; - struct mtree_option *options; - char *name; - char full; - char used; + struct mtree_entry *next; + struct mtree_option *options; + char *name; + char full; + char used; }; struct mtree { - struct archive_string line; - size_t buffsize; - char *buff; - off_t offset; - int fd; - int filetype; - int archive_format; - const char *archive_format_name; - struct mtree_entry *entries; - struct mtree_entry *this_entry; - struct archive_string current_dir; - struct archive_string contents_name; - - struct archive_entry_linkresolver *resolver; - - off_t cur_size, cur_offset; + struct archive_string line; + size_t buffsize; + char *buff; + int64_t offset; + int fd; + int archive_format; + const char *archive_format_name; + struct mtree_entry *entries; + struct mtree_entry *this_entry; + struct archive_string current_dir; + struct archive_string contents_name; + + struct archive_entry_linkresolver *resolver; + + int64_t cur_size; }; -static int cleanup(struct archive_read *); -static int mtree_bid(struct archive_read *); -static int parse_file(struct archive_read *, struct archive_entry *, - struct mtree *, struct mtree_entry *, int *); -static void parse_escapes(char *, struct mtree_entry *); -static int parse_line(struct archive_read *, struct archive_entry *, - struct mtree *, struct mtree_entry *, int *); -static int parse_keyword(struct archive_read *, struct mtree *, - struct archive_entry *, struct mtree_option *, int *); -static int read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t); -static int skip(struct archive_read *a); -static int read_header(struct archive_read *, - struct archive_entry *); -static int64_t mtree_atol10(char **); -static int64_t mtree_atol8(char **); -static int64_t mtree_atol(char **); +static int cleanup(struct archive_read *); +static int mtree_bid(struct archive_read *, int); +static int parse_file(struct archive_read *, struct archive_entry *, + struct mtree *, struct mtree_entry *, int *); +static void parse_escapes(char *, struct mtree_entry *); +static int parse_line(struct archive_read *, struct archive_entry *, + struct mtree *, struct mtree_entry *, int *); +static int parse_keyword(struct archive_read *, struct mtree *, + struct archive_entry *, struct mtree_option *, int *); +static int read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset); +static ssize_t readline(struct archive_read *, struct mtree *, char **, ssize_t); +static int skip(struct archive_read *a); +static int read_header(struct archive_read *, + struct archive_entry *); +static int64_t mtree_atol10(char **); +static int64_t mtree_atol8(char **); +static int64_t mtree_atol(char **); + +/* + * There's no standard for TIME_T_MAX/TIME_T_MIN. So we compute them + * here. TODO: Move this to configure time, but be careful + * about cross-compile environments. + */ +static int64_t +get_time_t_max(void) +{ +#if defined(TIME_T_MAX) + return TIME_T_MAX; +#else + static time_t t; + time_t a; + if (t == 0) { + a = 1; + while (a > t) { + t = a; + a = a * 2 + 1; + } + } + return t; +#endif +} + +static int64_t +get_time_t_min(void) +{ +#if defined(TIME_T_MIN) + return TIME_T_MIN; +#else + /* 't' will hold the minimum value, which will be zero (if + * time_t is unsigned) or -2^n (if time_t is signed). */ + static int computed; + static time_t t; + time_t a; + if (computed == 0) { + a = (time_t)-1; + while (a < t) { + t = a; + a = a * 2; + } + computed = 1; + } + return t; +#endif +} static void free_options(struct mtree_option *head) { - struct mtree_option *next; + struct mtree_option *next; - for (; head != NULL; head = next) { - next = head->next; - free(head->value); - free(head); - } + for (; head != NULL; head = next) { + next = head->next; + free(head->value); + free(head); + } } int archive_read_support_format_mtree(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - struct mtree *mtree; - int r; - - mtree = (struct mtree *)malloc(sizeof(*mtree)); - if (mtree == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate mtree data"); - return (ARCHIVE_FATAL); - } - memset(mtree, 0, sizeof(*mtree)); - mtree->fd = -1; - - r = __archive_read_register_format(a, mtree, "mtree", - mtree_bid, NULL, read_header, read_data, skip, cleanup); - - if (r != ARCHIVE_OK) - free(mtree); - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + struct mtree *mtree; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_mtree"); + + mtree = (struct mtree *)malloc(sizeof(*mtree)); + if (mtree == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate mtree data"); + return (ARCHIVE_FATAL); + } + memset(mtree, 0, sizeof(*mtree)); + mtree->fd = -1; + + r = __archive_read_register_format(a, mtree, "mtree", + mtree_bid, NULL, read_header, read_data, skip, cleanup); + + if (r != ARCHIVE_OK) + free(mtree); + return (ARCHIVE_OK); } static int cleanup(struct archive_read *a) { - struct mtree *mtree; - struct mtree_entry *p, *q; - - mtree = (struct mtree *)(a->format->data); - - p = mtree->entries; - while (p != NULL) { - q = p->next; - free(p->name); - free_options(p->options); - free(p); - p = q; - } - archive_string_free(&mtree->line); - archive_string_free(&mtree->current_dir); - archive_string_free(&mtree->contents_name); - archive_entry_linkresolver_free(mtree->resolver); - - free(mtree->buff); - free(mtree); - (a->format->data) = NULL; - return (ARCHIVE_OK); + struct mtree *mtree; + struct mtree_entry *p, *q; + + mtree = (struct mtree *)(a->format->data); + + p = mtree->entries; + while (p != NULL) { + q = p->next; + free(p->name); + free_options(p->options); + free(p); + p = q; + } + archive_string_free(&mtree->line); + archive_string_free(&mtree->current_dir); + archive_string_free(&mtree->contents_name); + archive_entry_linkresolver_free(mtree->resolver); + + free(mtree->buff); + free(mtree); + (a->format->data) = NULL; + return (ARCHIVE_OK); } +static ssize_t +get_line_size(const char *b, ssize_t avail, ssize_t *nlsize) +{ + ssize_t len; + + len = 0; + while (len < avail) { + switch (*b) { + case '\0':/* Non-ascii character or control character. */ + if (nlsize != NULL) + *nlsize = 0; + return (-1); + case '\r': + if (avail-len > 1 && b[1] == '\n') { + if (nlsize != NULL) + *nlsize = 2; + return (len+2); + } + /* FALL THROUGH */ + case '\n': + if (nlsize != NULL) + *nlsize = 1; + return (len+1); + default: + b++; + len++; + break; + } + } + if (nlsize != NULL) + *nlsize = 0; + return (avail); +} +static ssize_t +next_line(struct archive_read *a, + const char **b, ssize_t *avail, ssize_t *ravail, ssize_t *nl) +{ + ssize_t len; + int quit; + + quit = 0; + if (*avail == 0) { + *nl = 0; + len = 0; + } else + len = get_line_size(*b, *avail, nl); + /* + * Read bytes more while it does not reach the end of line. + */ + while (*nl == 0 && len == *avail && !quit) { + ssize_t diff = *ravail - *avail; + size_t nbytes_req = (*ravail+1023) & ~1023U; + ssize_t tested; + + /* Increase reading bytes if it is not enough to at least + * new two lines. */ + if (nbytes_req < (size_t)*ravail + 160) + nbytes_req <<= 1; + + *b = __archive_read_ahead(a, nbytes_req, avail); + if (*b == NULL) { + if (*ravail >= *avail) + return (0); + /* Reading bytes reaches the end of file. */ + *b = __archive_read_ahead(a, *avail, avail); + quit = 1; + } + *ravail = *avail; + *b += diff; + *avail -= diff; + tested = len;/* Skip some bytes we already determinated. */ + len = get_line_size(*b, *avail, nl); + if (len >= 0) + len += tested; + } + return (len); +} + +/* + * Compare characters with a mtree keyword. + * Returns the length of a mtree keyword if matched. + * Returns 0 if not matched. + */ +int +bid_keycmp(const char *p, const char *key, ssize_t len) +{ + int match_len = 0; + + while (len > 0 && *p && *key) { + if (*p == *key) { + --len; + ++p; + ++key; + ++match_len; + continue; + } + return (0);/* Not match */ + } + if (*key != '\0') + return (0);/* Not match */ + + /* A following character should be specified characters */ + if (p[0] == '=' || p[0] == ' ' || p[0] == '\t' || + p[0] == '\n' || p[0] == '\r' || + (p[0] == '\\' && (p[1] == '\n' || p[1] == '\r'))) + return (match_len); + return (0);/* Not match */ +} + +/* + * Test whether the characters 'p' has is mtree keyword. + * Returns the length of a detected keyword. + * Returns 0 if any keywords were not found. + */ +static ssize_t +bid_keyword(const char *p, ssize_t len) +{ + static const char *keys_c[] = { + "content", "contents", "cksum", NULL + }; + static const char *keys_df[] = { + "device", "flags", NULL + }; + static const char *keys_g[] = { + "gid", "gname", NULL + }; + static const char *keys_il[] = { + "ignore", "link", NULL + }; + static const char *keys_m[] = { + "md5", "md5digest", "mode", NULL + }; + static const char *keys_no[] = { + "nlink", "optional", NULL + }; + static const char *keys_r[] = { + "rmd160", "rmd160digest", NULL + }; + static const char *keys_s[] = { + "sha1", "sha1digest", + "sha256", "sha256digest", + "sha384", "sha384digest", + "sha512", "sha512digest", + "size", NULL + }; + static const char *keys_t[] = { + "tags", "time", "type", NULL + }; + static const char *keys_u[] = { + "uid", "uname", NULL + }; + const char **keys; + int i; + + switch (*p) { + case 'c': keys = keys_c; break; + case 'd': case 'f': keys = keys_df; break; + case 'g': keys = keys_g; break; + case 'i': case 'l': keys = keys_il; break; + case 'm': keys = keys_m; break; + case 'n': case 'o': keys = keys_no; break; + case 'r': keys = keys_r; break; + case 's': keys = keys_s; break; + case 't': keys = keys_t; break; + case 'u': keys = keys_u; break; + default: return (0);/* Unknown key */ + } + + for (i = 0; keys[i] != NULL; i++) { + int l = bid_keycmp(p, keys[i], len); + if (l > 0) + return (l); + } + return (0);/* Unkown key */ +} + +/* + * Test whether there is a set of mtree keywords. + * Returns the number of keyword. + * Returns -1 if we got incorrect sequence. + * This function expects a set of "keyword=value". + * When "unset" is specified, expects a set of "keyword". + */ static int -mtree_bid(struct archive_read *a) +bid_keyword_list(const char *p, ssize_t len, int unset) { - const char *signature = "#mtree"; - const char *p; + int l; + int keycnt = 0; + + while (len > 0 && *p) { + int blank = 0; + + /* Test whether there are blank characters in the line. */ + while (len >0 && (*p == ' ' || *p == '\t')) { + ++p; + --len; + blank = 1; + } + if (*p == '\n' || *p == '\r') + break; + if (p[0] == '\\' && (p[1] == '\n' || p[1] == '\r')) + break; + if (!blank) /* No blank character. */ + return (-1); + + if (unset) { + l = bid_keycmp(p, "all", len); + if (l > 0) + return (1); + } + /* Test whether there is a correct key in the line. */ + l = bid_keyword(p, len); + if (l == 0) + return (-1);/* Unknown keyword was found. */ + p += l; + len -= l; + keycnt++; + + /* Skip value */ + if (*p == '=') { + int value = 0; + ++p; + --len; + while (len > 0 && *p != ' ' && *p != '\t') { + ++p; + --len; + value = 1; + } + /* A keyword should have a its value unless + * "/unset" operation. */ + if (!unset && value == 0) + return (-1); + } + } + return (keycnt); +} - /* Now let's look at the actual header and see if it matches. */ - p = __archive_read_ahead(a, strlen(signature), NULL); - if (p == NULL) - return (-1); +static int +bid_entry(const char *p, ssize_t len) +{ + int f = 0; + static const unsigned char safe_char[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 00 - 0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 10 - 1F */ + /* !"$%&'()*+,-./ EXCLUSION:( )(#) */ + 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 20 - 2F */ + /* 0123456789:;<>? EXCLUSION:(=) */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, /* 30 - 3F */ + /* @ABCDEFGHIJKLMNO */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 40 - 4F */ + /* PQRSTUVWXYZ[\]^_ */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 50 - 5F */ + /* `abcdefghijklmno */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 60 - 6F */ + /* pqrstuvwxyz{|}~ */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, /* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* B0 - BF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* C0 - CF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* D0 - DF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* E0 - EF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* F0 - FF */ + }; + + /* + * Skip the path-name which is quoted. + */ + while (len > 0 && *p != ' ' && *p != '\t') { + if (!safe_char[*(const unsigned char *)p]) + return (-1); + ++p; + --len; + ++f; + } + /* If a path-name was not found, returns error. */ + if (f == 0) + return (-1); + + return (bid_keyword_list(p, len, 0)); +} - if (strncmp(p, signature, strlen(signature)) == 0) - return (8 * strlen(signature)); - return (0); +#define MAX_BID_ENTRY 3 + +static int +mtree_bid(struct archive_read *a, int best_bid) +{ + const char *signature = "#mtree"; + const char *p; + ssize_t avail, ravail; + ssize_t len, nl; + int detected_bytes = 0, entry_cnt = 0, multiline = 0; + + (void)best_bid; /* UNUSED */ + + /* Now let's look at the actual header and see if it matches. */ + p = __archive_read_ahead(a, strlen(signature), &avail); + if (p == NULL) + return (-1); + + if (memcmp(p, signature, strlen(signature)) == 0) + return (8 * (int)strlen(signature)); + + /* + * There is not a mtree signature. Let's try to detect mtree format. + */ + ravail = avail; + for (;;) { + len = next_line(a, &p, &avail, &ravail, &nl); + /* The terminal character of the line should be + * a new line character, '\r\n' or '\n'. */ + if (len <= 0 || nl == 0) + break; + if (!multiline) { + /* Leading whitespace is never significant, + * ignore it. */ + while (len > 0 && (*p == ' ' || *p == '\t')) { + ++p; + --avail; + --len; + } + /* Skip comment or empty line. */ + if (p[0] == '#' || p[0] == '\n' || p[0] == '\r') { + p += len; + avail -= len; + continue; + } + } else { + /* A continuance line; the terminal + * character of previous line was '\' character. */ + if (bid_keyword_list(p, len, 0) <= 0) + break; + if (multiline == 1) + detected_bytes += len; + if (p[len-nl-1] != '\\') { + if (multiline == 1 && + ++entry_cnt >= MAX_BID_ENTRY) + break; + multiline = 0; + } + p += len; + avail -= len; + continue; + } + if (p[0] != '/') { + if (bid_entry(p, len) >= 0) { + detected_bytes += len; + if (p[len-nl-1] == '\\') + /* This line continues. */ + multiline = 1; + else { + /* We've got plenty of correct lines + * to assume that this file is a mtree + * format. */ + if (++entry_cnt >= MAX_BID_ENTRY) + break; + } + } else + break; + } else if (strncmp(p, "/set", 4) == 0) { + if (bid_keyword_list(p+4, len-4, 0) <= 0) + break; + /* This line continues. */ + if (p[len-nl-1] == '\\') + multiline = 2; + } else if (strncmp(p, "/unset", 6) == 0) { + if (bid_keyword_list(p+6, len-6, 1) <= 0) + break; + /* This line continues. */ + if (p[len-nl-1] == '\\') + multiline = 2; + } else + break; + + /* Test next line. */ + p += len; + avail -= len; + } + if (entry_cnt >= MAX_BID_ENTRY || (entry_cnt > 0 && len == 0)) + return (32); + + return (0); } /* @@ -215,106 +634,106 @@ static int add_option(struct archive_read *a, struct mtree_option **global, const char *value, size_t len) { - struct mtree_option *option; - - if ((option = malloc(sizeof(*option))) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - if ((option->value = malloc(len + 1)) == NULL) { - free(option); - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - memcpy(option->value, value, len); - option->value[len] = '\0'; - option->next = *global; - *global = option; - return (ARCHIVE_OK); + struct mtree_option *opt; + + if ((opt = malloc(sizeof(*opt))) == NULL) { + archive_set_error(&a->archive, errno, "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + if ((opt->value = malloc(len + 1)) == NULL) { + free(opt); + archive_set_error(&a->archive, errno, "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + memcpy(opt->value, value, len); + opt->value[len] = '\0'; + opt->next = *global; + *global = opt; + return (ARCHIVE_OK); } static void remove_option(struct mtree_option **global, const char *value, size_t len) { - struct mtree_option *iter, *last; - - last = NULL; - for (iter = *global; iter != NULL; last = iter, iter = iter->next) { - if (strncmp(iter->value, value, len) == 0 && - (iter->value[len] == '\0' || - iter->value[len] == '=')) - break; - } - if (iter == NULL) - return; - if (last == NULL) - *global = iter->next; - else - last->next = iter->next; - - free(iter->value); - free(iter); + struct mtree_option *iter, *last; + + last = NULL; + for (iter = *global; iter != NULL; last = iter, iter = iter->next) { + if (strncmp(iter->value, value, len) == 0 && + (iter->value[len] == '\0' || + iter->value[len] == '=')) + break; + } + if (iter == NULL) + return; + if (last == NULL) + *global = iter->next; + else + last->next = iter->next; + + free(iter->value); + free(iter); } static int process_global_set(struct archive_read *a, struct mtree_option **global, const char *line) { - const char *next, *eq; - size_t len; - int r; - - line += 4; - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - next = line + strcspn(line, " \t\r\n"); - eq = strchr(line, '='); - if (eq > next) - len = next - line; - else - len = eq - line; - - remove_option(global, line, len); - r = add_option(a, global, line, next - line); - if (r != ARCHIVE_OK) - return (r); - line = next; - } + const char *next, *eq; + size_t len; + int r; + + line += 4; + for (;;) { + next = line + strspn(line, " \t\r\n"); + if (*next == '\0') + return (ARCHIVE_OK); + line = next; + next = line + strcspn(line, " \t\r\n"); + eq = strchr(line, '='); + if (eq > next) + len = next - line; + else + len = eq - line; + + remove_option(global, line, len); + r = add_option(a, global, line, next - line); + if (r != ARCHIVE_OK) + return (r); + line = next; + } } static int process_global_unset(struct archive_read *a, struct mtree_option **global, const char *line) { - const char *next; - size_t len; - - line += 6; - if (strchr(line, '=') != NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "/unset shall not contain `='"); - return ARCHIVE_FATAL; - } - - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - len = strcspn(line, " \t\r\n"); - - if (len == 3 && strncmp(line, "all", 3) == 0) { - free_options(*global); - *global = NULL; - } else { - remove_option(global, line, len); - } - - line += len; - } + const char *next; + size_t len; + + line += 6; + if (strchr(line, '=') != NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "/unset shall not contain `='"); + return ARCHIVE_FATAL; + } + + for (;;) { + next = line + strspn(line, " \t\r\n"); + if (*next == '\0') + return (ARCHIVE_OK); + line = next; + len = strcspn(line, " \t\r\n"); + + if (len == 3 && strncmp(line, "all", 3) == 0) { + free_options(*global); + *global = NULL; + } else { + remove_option(global, line, len); + } + + line += len; + } } static int @@ -322,129 +741,128 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, struct mtree_option **global, const char *line, struct mtree_entry **last_entry) { - struct mtree_entry *entry; - struct mtree_option *iter; - const char *next, *eq; - size_t len; - int r; - - if ((entry = malloc(sizeof(*entry))) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - entry->next = NULL; - entry->options = NULL; - entry->name = NULL; - entry->used = 0; - entry->full = 0; - - /* Add this entry to list. */ - if (*last_entry == NULL) - mtree->entries = entry; - else - (*last_entry)->next = entry; - *last_entry = entry; - - len = strcspn(line, " \t\r\n"); - if ((entry->name = malloc(len + 1)) == NULL) { - archive_set_error(&a->archive, errno, "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - - memcpy(entry->name, line, len); - entry->name[len] = '\0'; - parse_escapes(entry->name, entry); - - line += len; - for (iter = *global; iter != NULL; iter = iter->next) { - r = add_option(a, &entry->options, iter->value, - strlen(iter->value)); - if (r != ARCHIVE_OK) - return (r); - } - - for (;;) { - next = line + strspn(line, " \t\r\n"); - if (*next == '\0') - return (ARCHIVE_OK); - line = next; - next = line + strcspn(line, " \t\r\n"); - eq = strchr(line, '='); - if (eq > next) - len = next - line; - else - len = eq - line; - - remove_option(&entry->options, line, len); - r = add_option(a, &entry->options, line, next - line); - if (r != ARCHIVE_OK) - return (r); - line = next; - } + struct mtree_entry *entry; + struct mtree_option *iter; + const char *next, *eq; + size_t len; + int r; + + if ((entry = malloc(sizeof(*entry))) == NULL) { + archive_set_error(&a->archive, errno, "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + entry->next = NULL; + entry->options = NULL; + entry->name = NULL; + entry->used = 0; + entry->full = 0; + + /* Add this entry to list. */ + if (*last_entry == NULL) + mtree->entries = entry; + else + (*last_entry)->next = entry; + *last_entry = entry; + + len = strcspn(line, " \t\r\n"); + if ((entry->name = malloc(len + 1)) == NULL) { + archive_set_error(&a->archive, errno, "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + + memcpy(entry->name, line, len); + entry->name[len] = '\0'; + parse_escapes(entry->name, entry); + + line += len; + for (iter = *global; iter != NULL; iter = iter->next) { + r = add_option(a, &entry->options, iter->value, + strlen(iter->value)); + if (r != ARCHIVE_OK) + return (r); + } + + for (;;) { + next = line + strspn(line, " \t\r\n"); + if (*next == '\0') + return (ARCHIVE_OK); + line = next; + next = line + strcspn(line, " \t\r\n"); + eq = strchr(line, '='); + if (eq == NULL || eq > next) + len = next - line; + else + len = eq - line; + + remove_option(&entry->options, line, len); + r = add_option(a, &entry->options, line, next - line); + if (r != ARCHIVE_OK) + return (r); + line = next; + } } static int read_mtree(struct archive_read *a, struct mtree *mtree) { - ssize_t len; - uintmax_t counter; - char *p; - struct mtree_option *global; - struct mtree_entry *last_entry; - int r; - - mtree->archive_format = ARCHIVE_FORMAT_MTREE; - mtree->archive_format_name = "mtree"; - - global = NULL; - last_entry = NULL; - r = ARCHIVE_OK; - - for (counter = 1; ; ++counter) { - len = readline(a, mtree, &p, 256); - if (len == 0) { - mtree->this_entry = mtree->entries; - free_options(global); - return (ARCHIVE_OK); - } - if (len < 0) { - free_options(global); - return (len); - } - /* Leading whitespace is never significant, ignore it. */ - while (*p == ' ' || *p == '\t') { - ++p; - --len; - } - /* Skip content lines and blank lines. */ - if (*p == '#') - continue; - if (*p == '\r' || *p == '\n' || *p == '\0') - continue; - if (*p != '/') { - r = process_add_entry(a, mtree, &global, p, - &last_entry); - } else if (strncmp(p, "/set", 4) == 0) { - if (p[4] != ' ' && p[4] != '\t') - break; - r = process_global_set(a, &global, p); - } else if (strncmp(p, "/unset", 6) == 0) { - if (p[6] != ' ' && p[6] != '\t') - break; - r = process_global_unset(a, &global, p); - } else - break; - - if (r != ARCHIVE_OK) { - free_options(global); - return r; - } - } - - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't parse line %ju", counter); - free_options(global); - return (ARCHIVE_FATAL); + ssize_t len; + uintmax_t counter; + char *p; + struct mtree_option *global; + struct mtree_entry *last_entry; + int r; + + mtree->archive_format = ARCHIVE_FORMAT_MTREE; + mtree->archive_format_name = "mtree"; + + global = NULL; + last_entry = NULL; + + for (counter = 1; ; ++counter) { + len = readline(a, mtree, &p, 65536); + if (len == 0) { + mtree->this_entry = mtree->entries; + free_options(global); + return (ARCHIVE_OK); + } + if (len < 0) { + free_options(global); + return (len); + } + /* Leading whitespace is never significant, ignore it. */ + while (*p == ' ' || *p == '\t') { + ++p; + --len; + } + /* Skip content lines and blank lines. */ + if (*p == '#') + continue; + if (*p == '\r' || *p == '\n' || *p == '\0') + continue; + if (*p != '/') { + r = process_add_entry(a, mtree, &global, p, + &last_entry); + } else if (strncmp(p, "/set", 4) == 0) { + if (p[4] != ' ' && p[4] != '\t') + break; + r = process_global_set(a, &global, p); + } else if (strncmp(p, "/unset", 6) == 0) { + if (p[6] != ' ' && p[6] != '\t') + break; + r = process_global_unset(a, &global, p); + } else + break; + + if (r != ARCHIVE_OK) { + free_options(global); + return r; + } + } + + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't parse line %ju", counter); + free_options(global); + return (ARCHIVE_FATAL); } /* @@ -454,56 +872,56 @@ read_mtree(struct archive_read *a, struct mtree *mtree) static int read_header(struct archive_read *a, struct archive_entry *entry) { - struct mtree *mtree; - char *p; - int r, use_next; - - mtree = (struct mtree *)(a->format->data); - - if (mtree->fd >= 0) { - close(mtree->fd); - mtree->fd = -1; - } - - if (mtree->entries == NULL) { - mtree->resolver = archive_entry_linkresolver_new(); - if (mtree->resolver == NULL) - return ARCHIVE_FATAL; - archive_entry_linkresolver_set_strategy(mtree->resolver, - ARCHIVE_FORMAT_MTREE); - r = read_mtree(a, mtree); - if (r != ARCHIVE_OK) - return (r); - } - - a->archive.archive_format = mtree->archive_format; - a->archive.archive_format_name = mtree->archive_format_name; - - for (;;) { - if (mtree->this_entry == NULL) - return (ARCHIVE_EOF); - if (strcmp(mtree->this_entry->name, "..") == 0) { - mtree->this_entry->used = 1; - if (archive_strlen(&mtree->current_dir) > 0) { - /* Roll back current path. */ - p = mtree->current_dir.s - + mtree->current_dir.length - 1; - while (p >= mtree->current_dir.s && *p != '/') - --p; - if (p >= mtree->current_dir.s) - --p; - mtree->current_dir.length - = p - mtree->current_dir.s + 1; - } - } - if (!mtree->this_entry->used) { - use_next = 0; - r = parse_file(a, entry, mtree, mtree->this_entry, &use_next); - if (use_next == 0) - return (r); - } - mtree->this_entry = mtree->this_entry->next; - } + struct mtree *mtree; + char *p; + int r, use_next; + + mtree = (struct mtree *)(a->format->data); + + if (mtree->fd >= 0) { + close(mtree->fd); + mtree->fd = -1; + } + + if (mtree->entries == NULL) { + mtree->resolver = archive_entry_linkresolver_new(); + if (mtree->resolver == NULL) + return ARCHIVE_FATAL; + archive_entry_linkresolver_set_strategy(mtree->resolver, + ARCHIVE_FORMAT_MTREE); + r = read_mtree(a, mtree); + if (r != ARCHIVE_OK) + return (r); + } + + a->archive.archive_format = mtree->archive_format; + a->archive.archive_format_name = mtree->archive_format_name; + + for (;;) { + if (mtree->this_entry == NULL) + return (ARCHIVE_EOF); + if (strcmp(mtree->this_entry->name, "..") == 0) { + mtree->this_entry->used = 1; + if (archive_strlen(&mtree->current_dir) > 0) { + /* Roll back current path. */ + p = mtree->current_dir.s + + mtree->current_dir.length - 1; + while (p >= mtree->current_dir.s && *p != '/') + --p; + if (p >= mtree->current_dir.s) + --p; + mtree->current_dir.length + = p - mtree->current_dir.s + 1; + } + } + if (!mtree->this_entry->used) { + use_next = 0; + r = parse_file(a, entry, mtree, mtree->this_entry, &use_next); + if (use_next == 0) + return (r); + } + mtree->this_entry = mtree->this_entry->next; + } } /* @@ -515,205 +933,215 @@ static int parse_file(struct archive_read *a, struct archive_entry *entry, struct mtree *mtree, struct mtree_entry *mentry, int *use_next) { - const char *path; - struct stat st_storage, *st; - struct mtree_entry *mp; - struct archive_entry *sparse_entry; - int r = ARCHIVE_OK, r1, parsed_kws, mismatched_type; - - mentry->used = 1; - - /* Initialize reasonable defaults. */ - mtree->filetype = AE_IFREG; - archive_entry_set_size(entry, 0); - - /* Parse options from this line. */ - parsed_kws = 0; - r = parse_line(a, entry, mtree, mentry, &parsed_kws); - - if (mentry->full) { - archive_entry_copy_pathname(entry, mentry->name); - /* - * "Full" entries are allowed to have multiple lines - * and those lines aren't required to be adjacent. We - * don't support multiple lines for "relative" entries - * nor do we make any attempt to merge data from - * separate "relative" and "full" entries. (Merging - * "relative" and "full" entries would require dealing - * with pathname canonicalization, which is a very - * tricky subject.) - */ - for (mp = mentry->next; mp != NULL; mp = mp->next) { - if (mp->full && !mp->used - && strcmp(mentry->name, mp->name) == 0) { - /* Later lines override earlier ones. */ - mp->used = 1; - r1 = parse_line(a, entry, mtree, mp, - &parsed_kws); - if (r1 < r) - r = r1; - } - } - } else { - /* - * Relative entries require us to construct - * the full path and possibly update the - * current directory. - */ - size_t n = archive_strlen(&mtree->current_dir); - if (n > 0) - archive_strcat(&mtree->current_dir, "/"); - archive_strcat(&mtree->current_dir, mentry->name); - archive_entry_copy_pathname(entry, mtree->current_dir.s); - if (archive_entry_filetype(entry) != AE_IFDIR) - mtree->current_dir.length = n; - } - - /* - * Try to open and stat the file to get the real size - * and other file info. It would be nice to avoid - * this here so that getting a listing of an mtree - * wouldn't require opening every referenced contents - * file. But then we wouldn't know the actual - * contents size, so I don't see a really viable way - * around this. (Also, we may want to someday pull - * other unspecified info from the contents file on - * disk.) - */ - mtree->fd = -1; - if (archive_strlen(&mtree->contents_name) > 0) - path = mtree->contents_name.s; - else - path = archive_entry_pathname(entry); - - if (archive_entry_filetype(entry) == AE_IFREG || - archive_entry_filetype(entry) == AE_IFDIR) { - mtree->fd = open(path, O_RDONLY | O_BINARY); - if (mtree->fd == -1 && - (errno != ENOENT || - archive_strlen(&mtree->contents_name) > 0)) { - archive_set_error(&a->archive, errno, - "Can't open %s", path); - r = ARCHIVE_WARN; - } - } - - st = &st_storage; - if (mtree->fd >= 0) { - if (fstat(mtree->fd, st) == -1) { - archive_set_error(&a->archive, errno, - "Could not fstat %s", path); - r = ARCHIVE_WARN; - /* If we can't stat it, don't keep it open. */ - close(mtree->fd); - mtree->fd = -1; - st = NULL; - } - } else if (lstat(path, st) == -1) { - st = NULL; - } - - /* - * If there is a contents file on disk, use that size; - * otherwise leave it as-is (it might have been set from - * the mtree size= keyword). - */ - if (st != NULL) { - mismatched_type = 0; - if ((st->st_mode & S_IFMT) == S_IFREG && - archive_entry_filetype(entry) != AE_IFREG) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFLNK && - archive_entry_filetype(entry) != AE_IFLNK) - mismatched_type = 1; - if ((st->st_mode & S_IFSOCK) == S_IFSOCK && - archive_entry_filetype(entry) != AE_IFSOCK) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFCHR && - archive_entry_filetype(entry) != AE_IFCHR) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFBLK && - archive_entry_filetype(entry) != AE_IFBLK) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFDIR && - archive_entry_filetype(entry) != AE_IFDIR) - mismatched_type = 1; - if ((st->st_mode & S_IFMT) == S_IFIFO && - archive_entry_filetype(entry) != AE_IFIFO) - mismatched_type = 1; - - if (mismatched_type) { - if ((parsed_kws & MTREE_HAS_OPTIONAL) == 0) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "mtree specification has different type for %s", - archive_entry_pathname(entry)); - r = ARCHIVE_WARN; - } else { - *use_next = 1; - } - /* Don't hold a non-regular file open. */ - if (mtree->fd >= 0) - close(mtree->fd); - mtree->fd = -1; - st = NULL; - return r; - } - } - - if (st != NULL) { - if ((parsed_kws & MTREE_HAS_DEVICE) == 0 && - (archive_entry_filetype(entry) == AE_IFCHR || - archive_entry_filetype(entry) == AE_IFBLK)) - archive_entry_set_rdev(entry, st->st_rdev); - if ((parsed_kws & (MTREE_HAS_GID | MTREE_HAS_GNAME)) == 0) - archive_entry_set_gid(entry, st->st_gid); - if ((parsed_kws & (MTREE_HAS_UID | MTREE_HAS_UNAME)) == 0) - archive_entry_set_uid(entry, st->st_uid); - if ((parsed_kws & MTREE_HAS_MTIME) == 0) { + const char *path; + struct stat st_storage, *st; + struct mtree_entry *mp; + struct archive_entry *sparse_entry; + int r = ARCHIVE_OK, r1, parsed_kws; + + mentry->used = 1; + + /* Initialize reasonable defaults. */ + archive_entry_set_filetype(entry, AE_IFREG); + archive_entry_set_size(entry, 0); + archive_string_empty(&mtree->contents_name); + + /* Parse options from this line. */ + parsed_kws = 0; + r = parse_line(a, entry, mtree, mentry, &parsed_kws); + + if (mentry->full) { + archive_entry_copy_pathname(entry, mentry->name); + /* + * "Full" entries are allowed to have multiple lines + * and those lines aren't required to be adjacent. We + * don't support multiple lines for "relative" entries + * nor do we make any attempt to merge data from + * separate "relative" and "full" entries. (Merging + * "relative" and "full" entries would require dealing + * with pathname canonicalization, which is a very + * tricky subject.) + */ + for (mp = mentry->next; mp != NULL; mp = mp->next) { + if (mp->full && !mp->used + && strcmp(mentry->name, mp->name) == 0) { + /* Later lines override earlier ones. */ + mp->used = 1; + r1 = parse_line(a, entry, mtree, mp, + &parsed_kws); + if (r1 < r) + r = r1; + } + } + } else { + /* + * Relative entries require us to construct + * the full path and possibly update the + * current directory. + */ + size_t n = archive_strlen(&mtree->current_dir); + if (n > 0) + archive_strcat(&mtree->current_dir, "/"); + archive_strcat(&mtree->current_dir, mentry->name); + archive_entry_copy_pathname(entry, mtree->current_dir.s); + if (archive_entry_filetype(entry) != AE_IFDIR) + mtree->current_dir.length = n; + } + + /* + * Try to open and stat the file to get the real size + * and other file info. It would be nice to avoid + * this here so that getting a listing of an mtree + * wouldn't require opening every referenced contents + * file. But then we wouldn't know the actual + * contents size, so I don't see a really viable way + * around this. (Also, we may want to someday pull + * other unspecified info from the contents file on + * disk.) + */ + mtree->fd = -1; + if (archive_strlen(&mtree->contents_name) > 0) + path = mtree->contents_name.s; + else + path = archive_entry_pathname(entry); + + if (archive_entry_filetype(entry) == AE_IFREG || + archive_entry_filetype(entry) == AE_IFDIR) { + mtree->fd = open(path, O_RDONLY | O_BINARY); + if (mtree->fd == -1 && + (errno != ENOENT || + archive_strlen(&mtree->contents_name) > 0)) { + archive_set_error(&a->archive, errno, + "Can't open %s", path); + r = ARCHIVE_WARN; + } + } + + st = &st_storage; + if (mtree->fd >= 0) { + if (fstat(mtree->fd, st) == -1) { + archive_set_error(&a->archive, errno, + "Could not fstat %s", path); + r = ARCHIVE_WARN; + /* If we can't stat it, don't keep it open. */ + close(mtree->fd); + mtree->fd = -1; + st = NULL; + } + } else if (lstat(path, st) == -1) { + st = NULL; + } + + /* + * Check for a mismatch between the type in the specification and + * the type of the contents object on disk. + */ + if (st != NULL) { + if ( + ((st->st_mode & S_IFMT) == S_IFREG && + archive_entry_filetype(entry) == AE_IFREG) +#ifdef S_IFLNK + || ((st->st_mode & S_IFMT) == S_IFLNK && + archive_entry_filetype(entry) == AE_IFLNK) +#endif +#ifdef S_IFSOCK + || ((st->st_mode & S_IFSOCK) == S_IFSOCK && + archive_entry_filetype(entry) == AE_IFSOCK) +#endif +#ifdef S_IFCHR + || ((st->st_mode & S_IFMT) == S_IFCHR && + archive_entry_filetype(entry) == AE_IFCHR) +#endif +#ifdef S_IFBLK + || ((st->st_mode & S_IFMT) == S_IFBLK && + archive_entry_filetype(entry) == AE_IFBLK) +#endif + || ((st->st_mode & S_IFMT) == S_IFDIR && + archive_entry_filetype(entry) == AE_IFDIR) +#ifdef S_IFIFO + || ((st->st_mode & S_IFMT) == S_IFIFO && + archive_entry_filetype(entry) == AE_IFIFO) +#endif + ) { + /* Types match. */ + } else { + /* Types don't match; bail out gracefully. */ + if (mtree->fd >= 0) + close(mtree->fd); + mtree->fd = -1; + if (parsed_kws & MTREE_HAS_OPTIONAL) { + /* It's not an error for an optional entry + to not match disk. */ + *use_next = 1; + } else if (r == ARCHIVE_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "mtree specification has different type for %s", + archive_entry_pathname(entry)); + r = ARCHIVE_WARN; + } + return r; + } + } + + /* + * If there is a contents file on disk, pick some of the metadata + * from that file. For most of these, we only set it from the contents + * if it wasn't already parsed from the specification. + */ + if (st != NULL) { + if ((parsed_kws & MTREE_HAS_DEVICE) == 0 && + (archive_entry_filetype(entry) == AE_IFCHR || + archive_entry_filetype(entry) == AE_IFBLK)) + archive_entry_set_rdev(entry, st->st_rdev); + if ((parsed_kws & (MTREE_HAS_GID | MTREE_HAS_GNAME)) == 0) + archive_entry_set_gid(entry, st->st_gid); + if ((parsed_kws & (MTREE_HAS_UID | MTREE_HAS_UNAME)) == 0) + archive_entry_set_uid(entry, st->st_uid); + if ((parsed_kws & MTREE_HAS_MTIME) == 0) { #if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtimespec.tv_nsec); + archive_entry_set_mtime(entry, st->st_mtime, + st->st_mtimespec.tv_nsec); #elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtim.tv_nsec); + archive_entry_set_mtime(entry, st->st_mtime, + st->st_mtim.tv_nsec); #elif HAVE_STRUCT_STAT_ST_MTIME_N - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtime_n); + archive_entry_set_mtime(entry, st->st_mtime, + st->st_mtime_n); #elif HAVE_STRUCT_STAT_ST_UMTIME - archive_entry_set_mtime(entry, st->st_mtime, - st->st_umtime*1000); + archive_entry_set_mtime(entry, st->st_mtime, + st->st_umtime*1000); #elif HAVE_STRUCT_STAT_ST_MTIME_USEC - archive_entry_set_mtime(entry, st->st_mtime, - st->st_mtime_usec*1000); + archive_entry_set_mtime(entry, st->st_mtime, + st->st_mtime_usec*1000); #else - archive_entry_set_mtime(entry, st->st_mtime, 0); + archive_entry_set_mtime(entry, st->st_mtime, 0); #endif - } - if ((parsed_kws & MTREE_HAS_NLINK) == 0) - archive_entry_set_nlink(entry, st->st_nlink); - if ((parsed_kws & MTREE_HAS_PERM) == 0) - archive_entry_set_perm(entry, st->st_mode); - if ((parsed_kws & MTREE_HAS_SIZE) == 0) - archive_entry_set_size(entry, st->st_size); - archive_entry_set_ino(entry, st->st_ino); - archive_entry_set_dev(entry, st->st_dev); - - archive_entry_linkify(mtree->resolver, &entry, &sparse_entry); - } else if (parsed_kws & MTREE_HAS_OPTIONAL) { - /* - * Couldn't open the entry, stat it or the on-disk type - * didn't match. If this entry is optional, just ignore it - * and read the next header entry. - */ - *use_next = 1; - return ARCHIVE_OK; - } - - mtree->cur_size = archive_entry_size(entry); - mtree->offset = 0; - - return r; + } + if ((parsed_kws & MTREE_HAS_NLINK) == 0) + archive_entry_set_nlink(entry, st->st_nlink); + if ((parsed_kws & MTREE_HAS_PERM) == 0) + archive_entry_set_perm(entry, st->st_mode); + if ((parsed_kws & MTREE_HAS_SIZE) == 0) + archive_entry_set_size(entry, st->st_size); + archive_entry_set_ino(entry, st->st_ino); + archive_entry_set_dev(entry, st->st_dev); + + archive_entry_linkify(mtree->resolver, &entry, &sparse_entry); + } else if (parsed_kws & MTREE_HAS_OPTIONAL) { + /* + * Couldn't open the entry, stat it or the on-disk type + * didn't match. If this entry is optional, just ignore it + * and read the next header entry. + */ + *use_next = 1; + return ARCHIVE_OK; + } + + mtree->cur_size = archive_entry_size(entry); + mtree->offset = 0; + + return r; } /* @@ -723,20 +1151,20 @@ static int parse_line(struct archive_read *a, struct archive_entry *entry, struct mtree *mtree, struct mtree_entry *mp, int *parsed_kws) { - struct mtree_option *iter; - int r = ARCHIVE_OK, r1; - - for (iter = mp->options; iter != NULL; iter = iter->next) { - r1 = parse_keyword(a, mtree, entry, iter, parsed_kws); - if (r1 < r) - r = r1; - } - if ((*parsed_kws & MTREE_HAS_TYPE) == 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Missing type keyword in mtree specification"); - return (ARCHIVE_WARN); - } - return (r); + struct mtree_option *iter; + int r = ARCHIVE_OK, r1; + + for (iter = mp->options; iter != NULL; iter = iter->next) { + r1 = parse_keyword(a, mtree, entry, iter, parsed_kws); + if (r1 < r) + r = r1; + } + if (r == ARCHIVE_OK && (*parsed_kws & MTREE_HAS_TYPE) == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Missing type keyword in mtree specification"); + return (ARCHIVE_WARN); + } + return (r); } /* @@ -750,24 +1178,24 @@ parse_line(struct archive_read *a, struct archive_entry *entry, static int parse_device(struct archive *a, struct archive_entry *entry, char *val) { - char *comma1, *comma2; - - comma1 = strchr(val, ','); - if (comma1 == NULL) { - archive_entry_set_dev(entry, mtree_atol10(&val)); - return (ARCHIVE_OK); - } - ++comma1; - comma2 = strchr(comma1, ','); - if (comma2 == NULL) { - archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT, - "Malformed device attribute"); - return (ARCHIVE_WARN); - } - ++comma2; - archive_entry_set_rdevmajor(entry, mtree_atol(&comma1)); - archive_entry_set_rdevminor(entry, mtree_atol(&comma2)); - return (ARCHIVE_OK); + char *comma1, *comma2; + + comma1 = strchr(val, ','); + if (comma1 == NULL) { + archive_entry_set_dev(entry, mtree_atol10(&val)); + return (ARCHIVE_OK); + } + ++comma1; + comma2 = strchr(comma1, ','); + if (comma2 == NULL) { + archive_set_error(a, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed device attribute"); + return (ARCHIVE_WARN); + } + ++comma2; + archive_entry_set_rdevmajor(entry, mtree_atol(&comma1)); + archive_entry_set_rdevminor(entry, mtree_atol(&comma2)); + return (ARCHIVE_OK); } /* @@ -775,256 +1203,265 @@ parse_device(struct archive *a, struct archive_entry *entry, char *val) */ static int parse_keyword(struct archive_read *a, struct mtree *mtree, - struct archive_entry *entry, struct mtree_option *option, int *parsed_kws) + struct archive_entry *entry, struct mtree_option *opt, int *parsed_kws) { - char *val, *key; - - key = option->value; - - if (*key == '\0') - return (ARCHIVE_OK); - - if (strcmp(key, "optional") == 0) { - *parsed_kws |= MTREE_HAS_OPTIONAL; - return (ARCHIVE_OK); - } - if (strcmp(key, "ignore") == 0) { - /* - * The mtree processing is not recursive, so - * recursion will only happen for explicitly listed - * entries. - */ - return (ARCHIVE_OK); - } - - val = strchr(key, '='); - if (val == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Malformed attribute \"%s\" (%d)", key, key[0]); - return (ARCHIVE_WARN); - } - - *val = '\0'; - ++val; - - switch (key[0]) { - case 'c': - if (strcmp(key, "content") == 0 - || strcmp(key, "contents") == 0) { - parse_escapes(val, NULL); - archive_strcpy(&mtree->contents_name, val); - break; - } - if (strcmp(key, "cksum") == 0) - break; - case 'd': - if (strcmp(key, "device") == 0) { - *parsed_kws |= MTREE_HAS_DEVICE; - return parse_device(&a->archive, entry, val); - } - case 'f': - if (strcmp(key, "flags") == 0) { - *parsed_kws |= MTREE_HAS_FFLAGS; - archive_entry_copy_fflags_text(entry, val); - break; - } - case 'g': - if (strcmp(key, "gid") == 0) { - *parsed_kws |= MTREE_HAS_GID; - archive_entry_set_gid(entry, mtree_atol10(&val)); - break; - } - if (strcmp(key, "gname") == 0) { - *parsed_kws |= MTREE_HAS_GNAME; - archive_entry_copy_gname(entry, val); - break; - } - case 'l': - if (strcmp(key, "link") == 0) { - archive_entry_copy_symlink(entry, val); - break; - } - case 'm': - if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) - break; - if (strcmp(key, "mode") == 0) { - if (val[0] >= '0' && val[0] <= '9') { - *parsed_kws |= MTREE_HAS_PERM; - archive_entry_set_perm(entry, - mtree_atol8(&val)); - } else { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Symbolic mode \"%s\" unsupported", val); - return ARCHIVE_WARN; - } - break; - } - case 'n': - if (strcmp(key, "nlink") == 0) { - *parsed_kws |= MTREE_HAS_NLINK; - archive_entry_set_nlink(entry, mtree_atol10(&val)); - break; - } - case 'r': - if (strcmp(key, "rmd160") == 0 || - strcmp(key, "rmd160digest") == 0) - break; - case 's': - if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0) - break; - if (strcmp(key, "sha256") == 0 || - strcmp(key, "sha256digest") == 0) - break; - if (strcmp(key, "sha384") == 0 || - strcmp(key, "sha384digest") == 0) - break; - if (strcmp(key, "sha512") == 0 || - strcmp(key, "sha512digest") == 0) - break; - if (strcmp(key, "size") == 0) { - archive_entry_set_size(entry, mtree_atol10(&val)); - break; - } - case 't': - if (strcmp(key, "tags") == 0) { - /* - * Comma delimited list of tags. - * Ignore the tags for now, but the interface - * should be extended to allow inclusion/exclusion. - */ - break; - } - if (strcmp(key, "time") == 0) { - time_t m; - long ns; - - *parsed_kws |= MTREE_HAS_MTIME; - m = (time_t)mtree_atol10(&val); - if (*val == '.') { - ++val; - ns = (long)mtree_atol10(&val); - } else - ns = 0; - archive_entry_set_mtime(entry, m, ns); - break; - } - if (strcmp(key, "type") == 0) { - *parsed_kws |= MTREE_HAS_TYPE; - switch (val[0]) { - case 'b': - if (strcmp(val, "block") == 0) { - mtree->filetype = AE_IFBLK; - break; - } - case 'c': - if (strcmp(val, "char") == 0) { - mtree->filetype = AE_IFCHR; - break; - } - case 'd': - if (strcmp(val, "dir") == 0) { - mtree->filetype = AE_IFDIR; - break; - } - case 'f': - if (strcmp(val, "fifo") == 0) { - mtree->filetype = AE_IFIFO; - break; - } - if (strcmp(val, "file") == 0) { - mtree->filetype = AE_IFREG; - break; - } - case 'l': - if (strcmp(val, "link") == 0) { - mtree->filetype = AE_IFLNK; - break; - } - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized file type \"%s\"", val); - return (ARCHIVE_WARN); - } - archive_entry_set_filetype(entry, mtree->filetype); - break; - } - case 'u': - if (strcmp(key, "uid") == 0) { - *parsed_kws |= MTREE_HAS_UID; - archive_entry_set_uid(entry, mtree_atol10(&val)); - break; - } - if (strcmp(key, "uname") == 0) { - *parsed_kws |= MTREE_HAS_UNAME; - archive_entry_copy_uname(entry, val); - break; - } - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unrecognized key %s=%s", key, val); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); + char *val, *key; + + key = opt->value; + + if (*key == '\0') + return (ARCHIVE_OK); + + if (strcmp(key, "optional") == 0) { + *parsed_kws |= MTREE_HAS_OPTIONAL; + return (ARCHIVE_OK); + } + if (strcmp(key, "ignore") == 0) { + /* + * The mtree processing is not recursive, so + * recursion will only happen for explicitly listed + * entries. + */ + return (ARCHIVE_OK); + } + + val = strchr(key, '='); + if (val == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Malformed attribute \"%s\" (%d)", key, key[0]); + return (ARCHIVE_WARN); + } + + *val = '\0'; + ++val; + + switch (key[0]) { + case 'c': + if (strcmp(key, "content") == 0 + || strcmp(key, "contents") == 0) { + parse_escapes(val, NULL); + archive_strcpy(&mtree->contents_name, val); + break; + } + if (strcmp(key, "cksum") == 0) + break; + case 'd': + if (strcmp(key, "device") == 0) { + *parsed_kws |= MTREE_HAS_DEVICE; + return parse_device(&a->archive, entry, val); + } + case 'f': + if (strcmp(key, "flags") == 0) { + *parsed_kws |= MTREE_HAS_FFLAGS; + archive_entry_copy_fflags_text(entry, val); + break; + } + case 'g': + if (strcmp(key, "gid") == 0) { + *parsed_kws |= MTREE_HAS_GID; + archive_entry_set_gid(entry, mtree_atol10(&val)); + break; + } + if (strcmp(key, "gname") == 0) { + *parsed_kws |= MTREE_HAS_GNAME; + archive_entry_copy_gname(entry, val); + break; + } + case 'l': + if (strcmp(key, "link") == 0) { + archive_entry_copy_symlink(entry, val); + break; + } + case 'm': + if (strcmp(key, "md5") == 0 || strcmp(key, "md5digest") == 0) + break; + if (strcmp(key, "mode") == 0) { + if (val[0] >= '0' && val[0] <= '9') { + *parsed_kws |= MTREE_HAS_PERM; + archive_entry_set_perm(entry, + mtree_atol8(&val)); + } else { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Symbolic mode \"%s\" unsupported", val); + return ARCHIVE_WARN; + } + break; + } + case 'n': + if (strcmp(key, "nlink") == 0) { + *parsed_kws |= MTREE_HAS_NLINK; + archive_entry_set_nlink(entry, mtree_atol10(&val)); + break; + } + case 'r': + if (strcmp(key, "rmd160") == 0 || + strcmp(key, "rmd160digest") == 0) + break; + case 's': + if (strcmp(key, "sha1") == 0 || strcmp(key, "sha1digest") == 0) + break; + if (strcmp(key, "sha256") == 0 || + strcmp(key, "sha256digest") == 0) + break; + if (strcmp(key, "sha384") == 0 || + strcmp(key, "sha384digest") == 0) + break; + if (strcmp(key, "sha512") == 0 || + strcmp(key, "sha512digest") == 0) + break; + if (strcmp(key, "size") == 0) { + archive_entry_set_size(entry, mtree_atol10(&val)); + break; + } + case 't': + if (strcmp(key, "tags") == 0) { + /* + * Comma delimited list of tags. + * Ignore the tags for now, but the interface + * should be extended to allow inclusion/exclusion. + */ + break; + } + if (strcmp(key, "time") == 0) { + int64_t m; + int64_t my_time_t_max = get_time_t_max(); + int64_t my_time_t_min = get_time_t_min(); + long ns; + + *parsed_kws |= MTREE_HAS_MTIME; + m = mtree_atol10(&val); + /* Replicate an old mtree bug: + * 123456789.1 represents 123456789 + * seconds and 1 nanosecond. */ + if (*val == '.') { + ++val; + ns = (long)mtree_atol10(&val); + } else + ns = 0; + if (m > my_time_t_max) + m = my_time_t_max; + else if (m < my_time_t_min) + m = my_time_t_min; + archive_entry_set_mtime(entry, (time_t)m, ns); + break; + } + if (strcmp(key, "type") == 0) { + switch (val[0]) { + case 'b': + if (strcmp(val, "block") == 0) { + archive_entry_set_filetype(entry, AE_IFBLK); + break; + } + case 'c': + if (strcmp(val, "char") == 0) { + archive_entry_set_filetype(entry, AE_IFCHR); + break; + } + case 'd': + if (strcmp(val, "dir") == 0) { + archive_entry_set_filetype(entry, AE_IFDIR); + break; + } + case 'f': + if (strcmp(val, "fifo") == 0) { + archive_entry_set_filetype(entry, AE_IFIFO); + break; + } + if (strcmp(val, "file") == 0) { + archive_entry_set_filetype(entry, AE_IFREG); + break; + } + case 'l': + if (strcmp(val, "link") == 0) { + archive_entry_set_filetype(entry, AE_IFLNK); + break; + } + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unrecognized file type \"%s\"; assuming \"file\"", val); + archive_entry_set_filetype(entry, AE_IFREG); + return (ARCHIVE_WARN); + } + *parsed_kws |= MTREE_HAS_TYPE; + break; + } + case 'u': + if (strcmp(key, "uid") == 0) { + *parsed_kws |= MTREE_HAS_UID; + archive_entry_set_uid(entry, mtree_atol10(&val)); + break; + } + if (strcmp(key, "uname") == 0) { + *parsed_kws |= MTREE_HAS_UNAME; + archive_entry_copy_uname(entry, val); + break; + } + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unrecognized key %s=%s", key, val); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); } static int -read_data(struct archive_read *a, const void **buff, size_t *size, off_t *offset) +read_data(struct archive_read *a, const void **buff, size_t *size, int64_t *offset) { - size_t bytes_to_read; - ssize_t bytes_read; - struct mtree *mtree; - - mtree = (struct mtree *)(a->format->data); - if (mtree->fd < 0) { - *buff = NULL; - *offset = 0; - *size = 0; - return (ARCHIVE_EOF); - } - if (mtree->buff == NULL) { - mtree->buffsize = 64 * 1024; - mtree->buff = malloc(mtree->buffsize); - if (mtree->buff == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate memory"); - return (ARCHIVE_FATAL); - } - } - - *buff = mtree->buff; - *offset = mtree->offset; - if ((off_t)mtree->buffsize > mtree->cur_size - mtree->offset) - bytes_to_read = mtree->cur_size - mtree->offset; - else - bytes_to_read = mtree->buffsize; - bytes_read = read(mtree->fd, mtree->buff, bytes_to_read); - if (bytes_read < 0) { - archive_set_error(&a->archive, errno, "Can't read"); - return (ARCHIVE_WARN); - } - if (bytes_read == 0) { - *size = 0; - return (ARCHIVE_EOF); - } - mtree->offset += bytes_read; - *size = bytes_read; - return (ARCHIVE_OK); + size_t bytes_to_read; + ssize_t bytes_read; + struct mtree *mtree; + + mtree = (struct mtree *)(a->format->data); + if (mtree->fd < 0) { + *buff = NULL; + *offset = 0; + *size = 0; + return (ARCHIVE_EOF); + } + if (mtree->buff == NULL) { + mtree->buffsize = 64 * 1024; + mtree->buff = malloc(mtree->buffsize); + if (mtree->buff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + } + + *buff = mtree->buff; + *offset = mtree->offset; + if ((int64_t)mtree->buffsize > mtree->cur_size - mtree->offset) + bytes_to_read = mtree->cur_size - mtree->offset; + else + bytes_to_read = mtree->buffsize; + bytes_read = read(mtree->fd, mtree->buff, bytes_to_read); + if (bytes_read < 0) { + archive_set_error(&a->archive, errno, "Can't read"); + return (ARCHIVE_WARN); + } + if (bytes_read == 0) { + *size = 0; + return (ARCHIVE_EOF); + } + mtree->offset += bytes_read; + *size = bytes_read; + return (ARCHIVE_OK); } /* Skip does nothing except possibly close the contents file. */ static int skip(struct archive_read *a) { - struct mtree *mtree; - - mtree = (struct mtree *)(a->format->data); - if (mtree->fd >= 0) { - close(mtree->fd); - mtree->fd = -1; - } - return (ARCHIVE_OK); + struct mtree *mtree; + + mtree = (struct mtree *)(a->format->data); + if (mtree->fd >= 0) { + close(mtree->fd); + mtree->fd = -1; + } + return (ARCHIVE_OK); } /* @@ -1034,77 +1471,73 @@ skip(struct archive_read *a) static void parse_escapes(char *src, struct mtree_entry *mentry) { - char *dest = src; - char c; - - /* - * The current directory is somewhat special, it should be archived - * only once as it will confuse extraction otherwise. - */ - if (strcmp(src, ".") == 0) - mentry->full = 1; - - while (*src != '\0') { - c = *src++; - if (c == '/' && mentry != NULL) - mentry->full = 1; - if (c == '\\') { - switch (src[0]) { - case '0': - if (src[1] < '0' || src[1] > '7') { - c = 0; - ++src; - break; - } - /* FALLTHROUGH */ - case '1': - case '2': - case '3': - if (src[1] >= '0' && src[1] <= '7' && - src[2] >= '0' && src[2] <= '7') { - c = (src[0] - '0') << 6; - c |= (src[1] - '0') << 3; - c |= (src[2] - '0'); - src += 3; - } - break; - case 'a': - c = '\a'; - ++src; - break; - case 'b': - c = '\b'; - ++src; - break; - case 'f': - c = '\f'; - ++src; - break; - case 'n': - c = '\n'; - ++src; - break; - case 'r': - c = '\r'; - ++src; - break; - case 's': - c = ' '; - ++src; - break; - case 't': - c = '\t'; - ++src; - break; - case 'v': - c = '\v'; - ++src; - break; - } - } - *dest++ = c; - } - *dest = '\0'; + char *dest = src; + char c; + + if (mentry != NULL && strcmp(src, ".") == 0) + mentry->full = 1; + + while (*src != '\0') { + c = *src++; + if (c == '/' && mentry != NULL) + mentry->full = 1; + if (c == '\\') { + switch (src[0]) { + case '0': + if (src[1] < '0' || src[1] > '7') { + c = 0; + ++src; + break; + } + /* FALLTHROUGH */ + case '1': + case '2': + case '3': + if (src[1] >= '0' && src[1] <= '7' && + src[2] >= '0' && src[2] <= '7') { + c = (src[0] - '0') << 6; + c |= (src[1] - '0') << 3; + c |= (src[2] - '0'); + src += 3; + } + break; + case 'a': + c = '\a'; + ++src; + break; + case 'b': + c = '\b'; + ++src; + break; + case 'f': + c = '\f'; + ++src; + break; + case 'n': + c = '\n'; + ++src; + break; + case 'r': + c = '\r'; + ++src; + break; + case 's': + c = ' '; + ++src; + break; + case 't': + c = '\t'; + ++src; + break; + case 'v': + c = '\v'; + ++src; + break; + } + } + *dest++ = c; + } + *dest = '\0'; } /* @@ -1115,24 +1548,24 @@ parse_escapes(char *src, struct mtree_entry *mentry) static int64_t mtree_atol8(char **p) { - int64_t l, limit, last_digit_limit; - int digit, base; - - base = 8; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (l); + int64_t l, limit, last_digit_limit; + int digit, base; + + base = 8; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + + l = 0; + digit = **p - '0'; + while (digit >= 0 && digit < base) { + if (l>limit || (l == limit && digit > last_digit_limit)) { + l = INT64_MAX; /* Truncate on overflow. */ + break; + } + l = (l * base) + digit; + digit = *++(*p) - '0'; + } + return (l); } /* @@ -1143,30 +1576,45 @@ mtree_atol8(char **p) static int64_t mtree_atol10(char **p) { - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - - l = 0; - digit = **p - '0'; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++(*p) - '0'; - } - return (sign < 0) ? -l : l; + int64_t l, limit, last_digit_limit; + int base, digit, sign; + + base = 10; + + if (**p == '-') { + sign = -1; + limit = ((uint64_t)(INT64_MAX) + 1) / base; + last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base; + ++(*p); + } else { + sign = 1; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + } + + l = 0; + digit = **p - '0'; + while (digit >= 0 && digit < base) { + if (l > limit || (l == limit && digit > last_digit_limit)) + return (sign < 0) ? INT64_MIN : INT64_MAX; + l = (l * base) + digit; + digit = *++(*p) - '0'; + } + return (sign < 0) ? -l : l; +} + +/* Parse a hex digit. */ +static int +parsehex(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'a' && c <= 'f') + return c - 'a'; + else if (c >= 'A' && c <= 'F') + return c - 'A'; + else + return -1; } /* @@ -1177,56 +1625,43 @@ mtree_atol10(char **p) static int64_t mtree_atol16(char **p) { - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 16; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - if (**p == '-') { - sign = -1; - ++(*p); - } else - sign = 1; - - l = 0; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - while (digit >= 0 && digit < base) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - if (**p >= '0' && **p <= '9') - digit = **p - '0'; - else if (**p >= 'a' && **p <= 'f') - digit = **p - 'a' + 10; - else if (**p >= 'A' && **p <= 'F') - digit = **p - 'A' + 10; - else - digit = -1; - } - return (sign < 0) ? -l : l; + int64_t l, limit, last_digit_limit; + int base, digit, sign; + + base = 16; + + if (**p == '-') { + sign = -1; + limit = ((uint64_t)(INT64_MAX) + 1) / base; + last_digit_limit = ((uint64_t)(INT64_MAX) + 1) % base; + ++(*p); + } else { + sign = 1; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + } + + l = 0; + digit = parsehex(**p); + while (digit >= 0 && digit < base) { + if (l > limit || (l == limit && digit > last_digit_limit)) + return (sign < 0) ? INT64_MIN : INT64_MAX; + l = (l * base) + digit; + digit = parsehex(*++(*p)); + } + return (sign < 0) ? -l : l; } static int64_t mtree_atol(char **p) { - if (**p != '0') - return mtree_atol10(p); - if ((*p)[1] == 'x' || (*p)[1] == 'X') { - *p += 2; - return mtree_atol16(p); - } - return mtree_atol8(p); + if (**p != '0') + return mtree_atol10(p); + if ((*p)[1] == 'x' || (*p)[1] == 'X') { + *p += 2; + return mtree_atol16(p); + } + return mtree_atol8(p); } /* @@ -1237,73 +1672,73 @@ mtree_atol(char **p) static ssize_t readline(struct archive_read *a, struct mtree *mtree, char **start, ssize_t limit) { - ssize_t bytes_read; - ssize_t total_size = 0; - ssize_t find_off = 0; - const void *t; - const char *s; - void *p; - char *u; - - /* Accumulate line in a line buffer. */ - for (;;) { - /* Read some more. */ - t = __archive_read_ahead(a, 1, &bytes_read); - if (t == NULL) - return (0); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n', trim the read. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - } - if (total_size + bytes_read + 1 > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&mtree->line, - total_size + bytes_read + 1) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate working buffer"); - return (ARCHIVE_FATAL); - } - memcpy(mtree->line.s + total_size, t, bytes_read); - __archive_read_consume(a, bytes_read); - total_size += bytes_read; - /* Null terminate. */ - mtree->line.s[total_size] = '\0'; - /* If we found an unescaped '\n', clean up and return. */ - for (u = mtree->line.s + find_off; *u; ++u) { - if (u[0] == '\n') { - *start = mtree->line.s; - return total_size; - } - if (u[0] == '#') { - if (p == NULL) - break; - *start = mtree->line.s; - return total_size; - } - if (u[0] != '\\') - continue; - if (u[1] == '\\') { - ++u; - continue; - } - if (u[1] == '\n') { - memmove(u, u + 1, - total_size - (u - mtree->line.s) + 1); - --total_size; - ++u; - break; - } - if (u[1] == '\0') - break; - } - find_off = u - mtree->line.s; - } + ssize_t bytes_read; + ssize_t total_size = 0; + ssize_t find_off = 0; + const void *t; + const char *s; + void *p; + char *u; + + /* Accumulate line in a line buffer. */ + for (;;) { + /* Read some more. */ + t = __archive_read_ahead(a, 1, &bytes_read); + if (t == NULL) + return (0); + if (bytes_read < 0) + return (ARCHIVE_FATAL); + s = t; /* Start of line? */ + p = memchr(t, '\n', bytes_read); + /* If we found '\n', trim the read. */ + if (p != NULL) { + bytes_read = 1 + ((const char *)p) - s; + } + if (total_size + bytes_read + 1 > limit) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Line too long"); + return (ARCHIVE_FATAL); + } + if (archive_string_ensure(&mtree->line, + total_size + bytes_read + 1) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate working buffer"); + return (ARCHIVE_FATAL); + } + memcpy(mtree->line.s + total_size, t, bytes_read); + __archive_read_consume(a, bytes_read); + total_size += bytes_read; + /* Null terminate. */ + mtree->line.s[total_size] = '\0'; + /* If we found an unescaped '\n', clean up and return. */ + for (u = mtree->line.s + find_off; *u; ++u) { + if (u[0] == '\n') { + *start = mtree->line.s; + return total_size; + } + if (u[0] == '#') { + if (p == NULL) + break; + *start = mtree->line.s; + return total_size; + } + if (u[0] != '\\') + continue; + if (u[1] == '\\') { + ++u; + continue; + } + if (u[1] == '\n') { + memmove(u, u + 1, + total_size - (u - mtree->line.s) + 1); + --total_size; + ++u; + break; + } + if (u[1] == '\0') + break; + } + find_off = u - mtree->line.s; + } } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c new file mode 100644 index 000000000..d5a8d86ee --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_rar.c @@ -0,0 +1,2574 @@ +/*- +* Copyright (c) 2003-2007 Tim Kientzle +* Copyright (c) 2011 Andres Mejia +* 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" + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#include +#ifdef HAVE_ZLIB_H +#include /* crc32 */ +#endif + +#include "archive.h" +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_read_private.h" + +/* RAR signature, also known as the mark header */ +#define RAR_SIGNATURE "\x52\x61\x72\x21\x1A\x07\x00" + +/* Header types */ +#define MARK_HEAD 0x72 +#define MAIN_HEAD 0x73 +#define FILE_HEAD 0x74 +#define COMM_HEAD 0x75 +#define AV_HEAD 0x76 +#define SUB_HEAD 0x77 +#define PROTECT_HEAD 0x78 +#define SIGN_HEAD 0x79 +#define NEWSUB_HEAD 0x7a +#define ENDARC_HEAD 0x7b + +/* Main Header Flags */ +#define MHD_VOLUME 0x0001 +#define MHD_COMMENT 0x0002 +#define MHD_LOCK 0x0004 +#define MHD_SOLID 0x0008 +#define MHD_NEWNUMBERING 0x0010 +#define MHD_AV 0x0020 +#define MHD_PROTECT 0x0040 +#define MHD_PASSWORD 0x0080 +#define MHD_FIRSTVOLUME 0x0100 +#define MHD_ENCRYPTVER 0x0200 + +/* Flags common to all headers */ +#define HD_MARKDELETION 0x4000 +#define HD_ADD_SIZE_PRESENT 0x8000 + +/* File Header Flags */ +#define FHD_SPLIT_BEFORE 0x0001 +#define FHD_SPLIT_AFTER 0x0002 +#define FHD_PASSWORD 0x0004 +#define FHD_COMMENT 0x0008 +#define FHD_SOLID 0x0010 +#define FHD_LARGE 0x0100 +#define FHD_UNICODE 0x0200 +#define FHD_SALT 0x0400 +#define FHD_VERSION 0x0800 +#define FHD_EXTTIME 0x1000 +#define FHD_EXTFLAGS 0x2000 + +/* File dictionary sizes */ +#define DICTIONARY_SIZE_64 0x00 +#define DICTIONARY_SIZE_128 0x20 +#define DICTIONARY_SIZE_256 0x40 +#define DICTIONARY_SIZE_512 0x60 +#define DICTIONARY_SIZE_1024 0x80 +#define DICTIONARY_SIZE_2048 0xA0 +#define DICTIONARY_SIZE_4096 0xC0 +#define FILE_IS_DIRECTORY 0xE0 +#define DICTIONARY_MASK FILE_IS_DIRECTORY + +/* OS Flags */ +#define OS_MSDOS 0 +#define OS_OS2 1 +#define OS_WIN32 2 +#define OS_UNIX 3 +#define OS_MAC_OS 4 +#define OS_BEOS 5 + +/* Compression Methods */ +#define COMPRESS_METHOD_STORE 0x30 +/* LZSS */ +#define COMPRESS_METHOD_FASTEST 0x31 +#define COMPRESS_METHOD_FAST 0x32 +#define COMPRESS_METHOD_NORMAL 0x33 +/* PPMd Variant H */ +#define COMPRESS_METHOD_GOOD 0x34 +#define COMPRESS_METHOD_BEST 0x35 + +#define CRC_POLYNOMIAL 0xEDB88320 + +#define NS_UNIT 10000000 + +#define DICTIONARY_MAX_SIZE 0x400000 + +#define MAINCODE_SIZE 299 +#define OFFSETCODE_SIZE 60 +#define LOWOFFSETCODE_SIZE 17 +#define LENGTHCODE_SIZE 28 +#define HUFFMAN_TABLE_SIZE \ + MAINCODE_SIZE + OFFSETCODE_SIZE + LOWOFFSETCODE_SIZE + LENGTHCODE_SIZE + +#define MAX_SYMBOL_LENGTH 0xF +#define MAX_SYMBOLS 20 + +/* + * Considering L1,L2 cache miss and a calling of write sytem-call, + * the best size of the output buffer(uncompressed buffer) is 128K. + * If the structure of extracting process is changed, this value + * might be researched again. + */ +#define UNP_BUFFER_SIZE (128 * 1024) + +/* Define this here for non-Windows platforms */ +#if !((defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)) +#define FILE_ATTRIBUTE_DIRECTORY 0x10 +#endif + +/* Fields common to all headers */ +struct rar_header +{ + char crc[2]; + char type; + char flags[2]; + char size[2]; +}; + +/* Fields common to all file headers */ +struct rar_file_header +{ + char pack_size[4]; + char unp_size[4]; + char host_os; + char file_crc[4]; + char file_time[4]; + char unp_ver; + char method; + char name_size[2]; + char file_attr[4]; +}; + +struct huffman_tree_node +{ + int branches[2]; +}; + +struct huffman_table_entry +{ + unsigned int length; + int value; +}; + +struct huffman_code +{ + struct huffman_tree_node *tree; + int numentries; + int minlength; + int maxlength; + int tablesize; + struct huffman_table_entry *table; +}; + +struct lzss +{ + unsigned char *window; + int mask; + int64_t position; +}; + +struct rar +{ + /* Entries from main RAR header */ + unsigned main_flags; + unsigned long file_crc; + char reserved1[2]; + char reserved2[4]; + char encryptver; + + /* File header entries */ + char compression_method; + unsigned file_flags; + int64_t packed_size; + int64_t unp_size; + time_t mtime; + long mnsec; + mode_t mode; + char *filename; + size_t filename_allocated; + + /* File header optional entries */ + char salt[8]; + time_t atime; + long ansec; + time_t ctime; + long cnsec; + time_t arctime; + long arcnsec; + + /* Fields to help with tracking decompression of files. */ + int64_t bytes_unconsumed; + int64_t bytes_remaining; + int64_t bytes_uncopied; + int64_t offset; + int64_t offset_outgoing; + char valid; + unsigned int unp_offset; + unsigned int unp_buffer_size; + unsigned char *unp_buffer; + unsigned int dictionary_size; + char start_new_block; + char entry_eof; + unsigned long crc_calculated; + int found_first_header; + + /* LZSS members */ + struct huffman_code maincode; + struct huffman_code offsetcode; + struct huffman_code lowoffsetcode; + struct huffman_code lengthcode; + unsigned char lengthtable[HUFFMAN_TABLE_SIZE]; + struct lzss lzss; + char output_last_match; + unsigned int lastlength; + unsigned int lastoffset; + unsigned int oldoffset[4]; + unsigned int lastlowoffset; + unsigned int numlowoffsetrepeats; + int64_t filterstart; + char start_new_table; + + /* PPMd Variant H members */ + char ppmd_valid; + char ppmd_eod; + char is_ppmd_block; + int ppmd_escape; + CPpmd7 ppmd7_context; + CPpmd7z_RangeDec range_dec; + IByteIn bytein; + + /* + * String conversion object. + */ + int init_default_conversion; + struct archive_string_conv *sconv_default; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_utf8; + struct archive_string_conv *sconv_utf16be; + + /* + * Bit stream reader. + */ + struct rar_br { +#define CACHE_TYPE uint64_t +#define CACHE_BITS (8 * sizeof(CACHE_TYPE)) + /* Cache buffer. */ + CACHE_TYPE cache_buffer; + /* Indicates how many bits avail in cache_buffer. */ + int cache_avail; + ssize_t avail_in; + const unsigned char *next_in; + } br; +}; + +static int archive_read_format_rar_bid(struct archive_read *, int); +static int archive_read_format_rar_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_rar_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_rar_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_rar_read_data_skip(struct archive_read *a); +static int archive_read_format_rar_cleanup(struct archive_read *); + +/* Support functions */ +static int read_header(struct archive_read *, struct archive_entry *, char); +static time_t get_time(int time); +static int read_exttime(const char *, struct rar *, const char *); +static int read_symlink_stored(struct archive_read *, struct archive_entry *, + struct archive_string_conv *); +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 *); +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 *); +static int read_next_symbol(struct archive_read *, struct huffman_code *); +static int create_code(struct archive_read *, struct huffman_code *, + unsigned char *, int, char); +static int add_value(struct archive_read *, struct huffman_code *, int, int, + int); +static int new_node(struct huffman_code *); +static int make_table(struct archive_read *, struct huffman_code *); +static int make_table_recurse(struct archive_read *, struct huffman_code *, int, + struct huffman_table_entry *, int, int); +static int64_t expand(struct archive_read *, int64_t); +static int copy_from_lzss_window(struct archive_read *, const void **, + int64_t, int); + +/* + * Bit stream reader. + */ +/* Check that the cache buffer has enough bits. */ +#define rar_br_has(br, n) ((br)->cache_avail >= n) +/* Get compressed data by bit. */ +#define rar_br_bits(br, n) \ + (((uint32_t)((br)->cache_buffer >> \ + ((br)->cache_avail - (n)))) & cache_masks[n]) +#define rar_br_bits_forced(br, n) \ + (((uint32_t)((br)->cache_buffer << \ + ((n) - (br)->cache_avail))) & cache_masks[n]) +/* Read ahead to make sure the cache buffer has enough compressed data we + * will use. + * True : completed, there is enough data in the cache buffer. + * False : there is no data in the stream. */ +#define rar_br_read_ahead(a, br, n) \ + ((rar_br_has(br, (n)) || rar_br_fillup(a, br)) || rar_br_has(br, (n))) +/* Notify how many bits we consumed. */ +#define rar_br_consume(br, n) ((br)->cache_avail -= (n)) +#define rar_br_consume_unalined_bits(br) ((br)->cache_avail &= ~7) + +static const uint32_t cache_masks[] = { + 0x00000000, 0x00000001, 0x00000003, 0x00000007, + 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F, + 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF, + 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF, + 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF, + 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF, + 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF, + 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF +}; + +/* + * Shift away used bits in the cache data and fill it up with following bits. + * Call this when cache buffer does not have enough bits you need. + * + * Returns 1 if the cache buffer is full. + * Returns 0 if the cache buffer is not full; input buffer is empty. + */ +static int +rar_br_fillup(struct archive_read *a, struct rar_br *br) +{ + struct rar *rar = (struct rar *)(a->format->data); + int n = CACHE_BITS - br->cache_avail; + + for (;;) { + switch (n >> 3) { + case 8: + if (br->avail_in >= 8) { + br->cache_buffer = + ((uint64_t)br->next_in[0]) << 56 | + ((uint64_t)br->next_in[1]) << 48 | + ((uint64_t)br->next_in[2]) << 40 | + ((uint64_t)br->next_in[3]) << 32 | + ((uint32_t)br->next_in[4]) << 24 | + ((uint32_t)br->next_in[5]) << 16 | + ((uint32_t)br->next_in[6]) << 8 | + (uint32_t)br->next_in[7]; + br->next_in += 8; + br->avail_in -= 8; + br->cache_avail += 8 * 8; + rar->bytes_unconsumed += 8; + rar->bytes_remaining -= 8; + return (1); + } + break; + case 7: + if (br->avail_in >= 7) { + br->cache_buffer = + (br->cache_buffer << 56) | + ((uint64_t)br->next_in[0]) << 48 | + ((uint64_t)br->next_in[1]) << 40 | + ((uint64_t)br->next_in[2]) << 32 | + ((uint32_t)br->next_in[3]) << 24 | + ((uint32_t)br->next_in[4]) << 16 | + ((uint32_t)br->next_in[5]) << 8 | + (uint32_t)br->next_in[6]; + br->next_in += 7; + br->avail_in -= 7; + br->cache_avail += 7 * 8; + rar->bytes_unconsumed += 7; + rar->bytes_remaining -= 7; + return (1); + } + break; + case 6: + if (br->avail_in >= 6) { + br->cache_buffer = + (br->cache_buffer << 48) | + ((uint64_t)br->next_in[0]) << 40 | + ((uint64_t)br->next_in[1]) << 32 | + ((uint32_t)br->next_in[2]) << 24 | + ((uint32_t)br->next_in[3]) << 16 | + ((uint32_t)br->next_in[4]) << 8 | + (uint32_t)br->next_in[5]; + br->next_in += 6; + br->avail_in -= 6; + br->cache_avail += 6 * 8; + rar->bytes_unconsumed += 6; + rar->bytes_remaining -= 6; + return (1); + } + break; + case 0: + /* We have enough compressed data in + * the cache buffer.*/ + return (1); + default: + break; + } + if (br->avail_in <= 0) { + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor + * actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + br->next_in = __archive_read_ahead(a, 1, &(br->avail_in)); + if (br->next_in == NULL) + return (0); + if (br->avail_in > rar->bytes_remaining) + br->avail_in = rar->bytes_remaining; + if (br->avail_in == 0) + return (0); + } + br->cache_buffer = + (br->cache_buffer << 8) | *br->next_in++; + br->avail_in--; + br->cache_avail += 8; + n -= 8; + rar->bytes_unconsumed++; + rar->bytes_remaining--; + } +} + +static int +rar_br_preparation(struct archive_read *a, struct rar_br *br) +{ + struct rar *rar = (struct rar *)(a->format->data); + + if (rar->bytes_remaining > 0) { + br->next_in = __archive_read_ahead(a, 1, &(br->avail_in)); + if (br->next_in == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + if (br->avail_in > rar->bytes_remaining) + br->avail_in = rar->bytes_remaining; + if (br->cache_avail == 0) + (void)rar_br_fillup(a, br); + } + return (ARCHIVE_OK); +} + +/* Find last bit set */ +static inline int +rar_fls(unsigned int word) +{ + word |= (word >> 1); + word |= (word >> 2); + word |= (word >> 4); + word |= (word >> 8); + word |= (word >> 16); + return word - (word >> 1); +} + +/* LZSS functions */ +static inline int64_t +lzss_position(struct lzss *lzss) +{ + return lzss->position; +} + +static inline int +lzss_mask(struct lzss *lzss) +{ + return lzss->mask; +} + +static inline int +lzss_size(struct lzss *lzss) +{ + return lzss->mask + 1; +} + +static inline int +lzss_offset_for_position(struct lzss *lzss, int64_t pos) +{ + return pos & lzss->mask; +} + +static inline unsigned char * +lzss_pointer_for_position(struct lzss *lzss, int64_t pos) +{ + return &lzss->window[lzss_offset_for_position(lzss, pos)]; +} + +static inline int +lzss_current_offset(struct lzss *lzss) +{ + return lzss_offset_for_position(lzss, lzss->position); +} + +static inline uint8_t * +lzss_current_pointer(struct lzss *lzss) +{ + return lzss_pointer_for_position(lzss, lzss->position); +} + +static inline void +lzss_emit_literal(struct rar *rar, uint8_t literal) +{ + *lzss_current_pointer(&rar->lzss) = literal; + rar->lzss.position++; +} + +static inline void +lzss_emit_match(struct rar *rar, int offset, int length) +{ + int dstoffs = lzss_current_offset(&rar->lzss); + int srcoffs = (dstoffs - offset) & lzss_mask(&rar->lzss); + int l, li, remaining; + unsigned char *d, *s; + + remaining = length; + while (remaining > 0) { + l = remaining; + if (dstoffs > srcoffs) { + if (l > lzss_size(&rar->lzss) - dstoffs) + l = lzss_size(&rar->lzss) - dstoffs; + } else { + if (l > lzss_size(&rar->lzss) - srcoffs) + l = lzss_size(&rar->lzss) - srcoffs; + } + d = &(rar->lzss.window[dstoffs]); + s = &(rar->lzss.window[srcoffs]); + if ((dstoffs + l < srcoffs) || (srcoffs + l < dstoffs)) + memcpy(d, s, l); + else { + for (li = 0; li < l; li++) + d[li] = s[li]; + } + remaining -= l; + dstoffs = (dstoffs + l) & lzss_mask(&(rar->lzss)); + srcoffs = (srcoffs + l) & lzss_mask(&(rar->lzss)); + } + rar->lzss.position += length; +} + +static void * +ppmd_alloc(void *p, size_t size) +{ + (void)p; + return malloc(size); +} +static void +ppmd_free(void *p, void *address) +{ + (void)p; + free(address); +} +static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; + +static Byte +ppmd_read(void *p) +{ + struct archive_read *a = ((IByteIn*)p)->a; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + Byte b; + if (!rar_br_read_ahead(a, br, 8)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return 0; + } + b = rar_br_bits(br, 8); + rar_br_consume(br, 8); + return b; +} + +int +archive_read_support_format_rar(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct rar *rar; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, ARCHIVE_STATE_NEW, + "archive_read_support_format_rar"); + + rar = (struct rar *)malloc(sizeof(*rar)); + if (rar == NULL) + { + archive_set_error(&a->archive, ENOMEM, "Can't allocate rar data"); + return (ARCHIVE_FATAL); + } + memset(rar, 0, sizeof(*rar)); + + r = __archive_read_register_format(a, + rar, + "rar", + archive_read_format_rar_bid, + archive_read_format_rar_options, + archive_read_format_rar_read_header, + archive_read_format_rar_read_data, + archive_read_format_rar_read_data_skip, + archive_read_format_rar_cleanup); + + if (r != ARCHIVE_OK) + free(rar); + return (r); +} + +static int +archive_read_format_rar_bid(struct archive_read *a, int best_bid) +{ + const char *p; + + /* If there's already a bid > 30, we'll never win. */ + if (best_bid > 30) + return (-1); + + if ((p = __archive_read_ahead(a, 7, NULL)) == NULL) + return (-1); + + if (memcmp(p, RAR_SIGNATURE, 7) == 0) + return (30); + + if ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0) { + /* This is a PE file */ + ssize_t offset = 0x10000; + ssize_t window = 4096; + ssize_t bytes_avail; + while (offset + window <= (1024 * 128)) { + const char *buff = __archive_read_ahead(a, offset + window, &bytes_avail); + if (buff == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + return (0); + continue; + } + p = buff + offset; + while (p + 7 < buff + bytes_avail) { + if (memcmp(p, RAR_SIGNATURE, 7) == 0) + return (30); + p += 0x10; + } + offset = p - buff; + } + } + return (0); +} + +static int +skip_sfx(struct archive_read *a) +{ + const void *h; + const char *p, *q; + size_t skip, total; + ssize_t bytes, window; + + total = 0; + window = 4096; + while (total + window <= (1024 * 128)) { + h = __archive_read_ahead(a, window, &bytes); + if (h == NULL) { + /* Remaining bytes are less than window. */ + window >>= 1; + if (window < 0x40) + goto fatal; + continue; + } + if (bytes < 0x40) + goto fatal; + p = h; + q = p + bytes; + + /* + * Scan ahead until we find something that looks + * like the RAR header. + */ + while (p + 7 < q) { + if (memcmp(p, RAR_SIGNATURE, 7) == 0) { + skip = p - (const char *)h; + __archive_read_consume(a, skip); + return (ARCHIVE_OK); + } + p += 0x10; + } + skip = p - (const char *)h; + __archive_read_consume(a, skip); + total += skip; + } +fatal: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Couldn't find out RAR header"); + return (ARCHIVE_FATAL); +} + +static int +archive_read_format_rar_options(struct archive_read *a, + const char *key, const char *val) +{ + struct rar *rar; + int ret = ARCHIVE_FAILED; + + rar = (struct rar *)(a->format->data); + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "rar: hdrcharset option needs a character-set name"); + else { + rar->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (rar->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "rar: unknown keyword ``%s''", key); + + return (ret); +} + +static int +archive_read_format_rar_read_header(struct archive_read *a, + struct archive_entry *entry) +{ + const void *h; + const char *p; + struct rar *rar; + size_t skip; + char head_type; + int ret; + unsigned flags; + + a->archive.archive_format = ARCHIVE_FORMAT_RAR; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "RAR"; + + rar = (struct rar *)(a->format->data); + + /* RAR files can be generated without EOF headers, so return ARCHIVE_EOF if + * this fails. + */ + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_EOF); + + p = h; + if (rar->found_first_header == 0 && + ((p[0] == 'M' && p[1] == 'Z') || memcmp(p, "\x7F\x45LF", 4) == 0)) { + /* This is an executable ? Must be self-extracting... */ + ret = skip_sfx(a); + if (ret < ARCHIVE_WARN) + return (ret); + } + rar->found_first_header = 1; + + while (1) + { + unsigned long crc32_val; + + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + + head_type = p[2]; + switch(head_type) + { + case MARK_HEAD: + if (memcmp(p, RAR_SIGNATURE, 7) != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid marker header"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, 7); + break; + + case MAIN_HEAD: + rar->main_flags = archive_le16dec(p + 3); + skip = archive_le16dec(p + 5); + if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + if ((h = __archive_read_ahead(a, skip, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + memcpy(rar->reserved1, p + 7, sizeof(rar->reserved1)); + memcpy(rar->reserved2, p + 7 + sizeof(rar->reserved1), + sizeof(rar->reserved2)); + if (rar->main_flags & MHD_ENCRYPTVER) { + if (skip < 7 + sizeof(rar->reserved1) + sizeof(rar->reserved2)+1) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + rar->encryptver = *(p + 7 + sizeof(rar->reserved1) + + sizeof(rar->reserved2)); + } + + if (rar->main_flags & MHD_VOLUME || + rar->main_flags & MHD_FIRSTVOLUME) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR volume support unavailable."); + return (ARCHIVE_FATAL); + } + if (rar->main_flags & MHD_PASSWORD) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR encryption support unavailable."); + return (ARCHIVE_FATAL); + } + + crc32_val = crc32(0, (const unsigned char *)p + 2, skip - 2); + if ((crc32_val & 0xffff) != archive_le16dec(p)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, skip); + break; + + case FILE_HEAD: + return read_header(a, entry, head_type); + + case COMM_HEAD: + case AV_HEAD: + case SUB_HEAD: + case PROTECT_HEAD: + case SIGN_HEAD: + flags = archive_le16dec(p + 3); + skip = archive_le16dec(p + 5); + if (skip < 7) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + if (skip > 7) { + if ((h = __archive_read_ahead(a, skip, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + } + if (flags & HD_ADD_SIZE_PRESENT) + { + if (skip < 7 + 4) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + skip += archive_le32dec(p + 7); + if ((h = __archive_read_ahead(a, skip, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + } + + crc32_val = crc32(0, (const unsigned char *)p + 2, skip - 2); + if ((crc32_val & 0xffff) != archive_le16dec(p)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + __archive_read_consume(a, skip); + break; + + case NEWSUB_HEAD: + if ((ret = read_header(a, entry, head_type)) < ARCHIVE_WARN) + return ret; + break; + + case ENDARC_HEAD: + return (ARCHIVE_EOF); + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file"); + return (ARCHIVE_FATAL); + } + } +} + +static int +archive_read_format_rar_read_data(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset) +{ + struct rar *rar = (struct rar *)(a->format->data); + int ret; + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + + if (rar->entry_eof) { + *buff = NULL; + *size = 0; + *offset = rar->offset; + return (ARCHIVE_EOF); + } + + switch (rar->compression_method) + { + case COMPRESS_METHOD_STORE: + ret = read_data_stored(a, buff, size, offset); + break; + + case COMPRESS_METHOD_FASTEST: + case COMPRESS_METHOD_FAST: + case COMPRESS_METHOD_NORMAL: + case COMPRESS_METHOD_GOOD: + case COMPRESS_METHOD_BEST: + ret = read_data_compressed(a, buff, size, offset); + if (ret != ARCHIVE_OK && ret != ARCHIVE_WARN) + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + break; + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported compression method for RAR file."); + ret = ARCHIVE_FATAL; + break; + } + return (ret); +} + +static int +archive_read_format_rar_read_data_skip(struct archive_read *a) +{ + struct rar *rar; + int64_t bytes_skipped; + + rar = (struct rar *)(a->format->data); + + if (rar->bytes_unconsumed > 0) { + /* Consume as much as the decompressor actually used. */ + __archive_read_consume(a, rar->bytes_unconsumed); + rar->bytes_unconsumed = 0; + } + + if (rar->bytes_remaining > 0) { + bytes_skipped = __archive_read_consume(a, rar->bytes_remaining); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static int +archive_read_format_rar_cleanup(struct archive_read *a) +{ + struct rar *rar; + + rar = (struct rar *)(a->format->data); + free_codes(a); + free(rar->filename); + free(rar->unp_buffer); + free(rar->lzss.window); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + free(rar); + (a->format->data) = NULL; + return (ARCHIVE_OK); +} + +static int +read_header(struct archive_read *a, struct archive_entry *entry, + char head_type) +{ + const void *h; + const char *p, *endp; + struct rar *rar; + struct rar_header rar_header; + struct rar_file_header file_header; + int64_t header_size; + unsigned filename_size, end; + char *filename; + char *strp; + char packed_size[8]; + char unp_size[8]; + int time; + struct archive_string_conv *sconv, *fn_sconv; + unsigned long crc32_val; + int ret = (ARCHIVE_OK), ret2; + + rar = (struct rar *)(a->format->data); + + /* Setup a string conversion object for non-rar-unicode filenames. */ + sconv = rar->opt_sconv; + if (sconv == NULL) { + if (!rar->init_default_conversion) { + rar->sconv_default = + archive_string_default_conversion_for_read( + &(a->archive)); + rar->init_default_conversion = 1; + } + sconv = rar->sconv_default; + } + + + if ((h = __archive_read_ahead(a, 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + memcpy(&rar_header, p, sizeof(rar_header)); + rar->file_flags = archive_le16dec(rar_header.flags); + header_size = archive_le16dec(rar_header.size); + if (header_size < sizeof(file_header) + 7) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + crc32_val = crc32(0, (const unsigned char *)p + 2, 7 - 2); + __archive_read_consume(a, 7); + + if (!(rar->file_flags & FHD_SOLID)) + { + rar->compression_method = 0; + rar->packed_size = 0; + rar->unp_size = 0; + rar->mtime = 0; + rar->ctime = 0; + rar->atime = 0; + rar->arctime = 0; + rar->mode = 0; + memset(&rar->salt, 0, sizeof(rar->salt)); + rar->atime = 0; + rar->ansec = 0; + rar->ctime = 0; + rar->cnsec = 0; + rar->mtime = 0; + rar->mnsec = 0; + rar->arctime = 0; + rar->arcnsec = 0; + } + else + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR solid archive support unavailable."); + return (ARCHIVE_FATAL); + } + + if ((h = __archive_read_ahead(a, header_size - 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + + /* File Header CRC check. */ + crc32_val = crc32(crc32_val, h, header_size - 7); + if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Header CRC error"); + return (ARCHIVE_FATAL); + } + /* If no CRC error, Go on parsing File Header. */ + p = h; + endp = p + header_size - 7; + memcpy(&file_header, p, sizeof(file_header)); + p += sizeof(file_header); + + rar->compression_method = file_header.method; + + time = archive_le32dec(file_header.file_time); + rar->mtime = get_time(time); + + rar->file_crc = archive_le32dec(file_header.file_crc); + + if (rar->file_flags & FHD_PASSWORD) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "RAR encryption support unavailable."); + return (ARCHIVE_FATAL); + } + + if (rar->file_flags & FHD_LARGE) + { + memcpy(packed_size, file_header.pack_size, 4); + memcpy(packed_size + 4, p, 4); /* High pack size */ + p += 4; + memcpy(unp_size, file_header.unp_size, 4); + memcpy(unp_size + 4, p, 4); /* High unpack size */ + p += 4; + rar->packed_size = archive_le64dec(&packed_size); + rar->unp_size = archive_le64dec(&unp_size); + } + else + { + rar->packed_size = archive_le32dec(file_header.pack_size); + rar->unp_size = archive_le32dec(file_header.unp_size); + } + + /* TODO: Need to use CRC check for these kind of cases. + * For now, check if sizes are not < 0. + */ + if (rar->packed_size < 0 || rar->unp_size < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid sizes specified."); + return (ARCHIVE_FATAL); + } + + /* TODO: RARv3 subblocks contain comments. For now the complete block is + * consumed at the end. + */ + if (head_type == NEWSUB_HEAD) { + size_t distance = p - (const char *)h; + header_size += rar->packed_size; + /* Make sure we have the extended data. */ + if ((h = __archive_read_ahead(a, header_size - 7, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + endp = p + header_size - 7; + p += distance; + } + + filename_size = archive_le16dec(file_header.name_size); + if (p + filename_size > endp) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid filename size"); + return (ARCHIVE_FATAL); + } + if (rar->filename_allocated < filename_size+2) { + rar->filename = realloc(rar->filename, filename_size+2); + if (rar->filename == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory."); + return (ARCHIVE_FATAL); + } + } + filename = rar->filename; + memcpy(filename, p, filename_size); + filename[filename_size] = '\0'; + if (rar->file_flags & FHD_UNICODE) + { + if (filename_size != strlen(filename)) + { + unsigned char highbyte, flagbits, flagbyte, length, offset; + + end = filename_size; + filename_size = 0; + offset = strlen(filename) + 1; + highbyte = *(p + offset++); + flagbits = 0; + flagbyte = 0; + while (offset < end && filename_size < end) + { + if (!flagbits) + { + flagbyte = *(p + offset++); + flagbits = 8; + } + + flagbits -= 2; + switch((flagbyte >> flagbits) & 3) + { + case 0: + filename[filename_size++] = '\0'; + filename[filename_size++] = *(p + offset++); + break; + case 1: + filename[filename_size++] = highbyte; + filename[filename_size++] = *(p + offset++); + break; + case 2: + filename[filename_size++] = *(p + offset + 1); + filename[filename_size++] = *(p + offset); + offset += 2; + break; + case 3: + { + length = *(p + offset++); + while (length) + { + if (filename_size >= end) + break; + filename[filename_size++] = *(p + offset); + length--; + } + } + break; + } + } + if (filename_size >= end) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid filename"); + return (ARCHIVE_FATAL); + } + filename[filename_size++] = '\0'; + filename[filename_size++] = '\0'; + + /* Decoded unicode form is UTF-16BE, so we have to update a string + * conversion object for it. */ + if (rar->sconv_utf16be == NULL) { + rar->sconv_utf16be = archive_string_conversion_from_charset( + &a->archive, "UTF-16BE", 1); + if (rar->sconv_utf16be == NULL) + return (ARCHIVE_FATAL); + } + fn_sconv = rar->sconv_utf16be; + + strp = filename; + while (memcmp(strp, "\x00\x00", 2)) + { + if (!memcmp(strp, "\x00\\", 2)) + *(strp + 1) = '/'; + strp += 2; + } + p += offset; + } else { + /* + * If FHD_UNICODE is set but no unicode data, this file name form + * is UTF-8, so we have to update a string conversion object for + * it accordingly. + */ + if (rar->sconv_utf8 == NULL) { + rar->sconv_utf8 = archive_string_conversion_from_charset( + &a->archive, "UTF-8", 1); + if (rar->sconv_utf8 == NULL) + return (ARCHIVE_FATAL); + } + fn_sconv = rar->sconv_utf8; + while ((strp = strchr(filename, '\\')) != NULL) + *strp = '/'; + p += filename_size; + } + } + else + { + fn_sconv = sconv; + while ((strp = strchr(filename, '\\')) != NULL) + *strp = '/'; + p += filename_size; + } + + if (rar->file_flags & FHD_SALT) + { + if (p + 8 > endp) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + memcpy(rar->salt, p, 8); + p += 8; + } + + if (rar->file_flags & FHD_EXTTIME) { + if (read_exttime(p, rar, endp) < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header size"); + return (ARCHIVE_FATAL); + } + } + + __archive_read_consume(a, header_size - 7); + + switch(file_header.host_os) + { + case OS_MSDOS: + case OS_OS2: + case OS_WIN32: + rar->mode = archive_le32dec(file_header.file_attr); + if (rar->mode & FILE_ATTRIBUTE_DIRECTORY) + rar->mode = AE_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else + rar->mode = AE_IFREG; + rar->mode |= S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + break; + + case OS_UNIX: + case OS_MAC_OS: + case OS_BEOS: + rar->mode = archive_le32dec(file_header.file_attr); + break; + + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unknown file attributes from RAR file's host OS"); + return (ARCHIVE_FATAL); + } + + rar->bytes_remaining = rar->packed_size; + rar->bytes_uncopied = rar->bytes_unconsumed = 0; + rar->lzss.position = rar->dictionary_size = rar->offset = 0; + rar->offset_outgoing = 0; + rar->br.cache_avail = 0; + rar->br.avail_in = 0; + rar->crc_calculated = 0; + rar->entry_eof = 0; + rar->valid = 1; + rar->is_ppmd_block = 0; + rar->start_new_table = 1; + free(rar->unp_buffer); + rar->unp_buffer = NULL; + rar->unp_offset = 0; + rar->unp_buffer_size = UNP_BUFFER_SIZE; + memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + rar->ppmd_valid = rar->ppmd_eod = 0; + + /* Don't set any archive entries for non-file header types */ + if (head_type == NEWSUB_HEAD) + return ret; + + archive_entry_set_mtime(entry, rar->mtime, rar->mnsec); + archive_entry_set_ctime(entry, rar->ctime, rar->cnsec); + archive_entry_set_atime(entry, rar->atime, rar->ansec); + archive_entry_set_size(entry, rar->unp_size); + archive_entry_set_mode(entry, rar->mode); + + if (archive_entry_copy_pathname_l(entry, filename, filename_size, fn_sconv)) + { + if (errno == ENOMEM) + { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(fn_sconv)); + ret = (ARCHIVE_WARN); + } + + if (((rar->mode) & AE_IFMT) == AE_IFLNK) + { + /* Make sure a symbolic-link file does not have its body. */ + rar->bytes_remaining = 0; + archive_entry_set_size(entry, 0); + + /* Read a symbolic-link name. */ + if ((ret2 = read_symlink_stored(a, entry, sconv)) < (ARCHIVE_WARN)) + return ret2; + if (ret > ret2) + ret = ret2; + } + + if (rar->bytes_remaining == 0) + rar->entry_eof = 1; + + return ret; +} + +static time_t +get_time(int time) +{ + struct tm tm; + tm.tm_sec = 2 * (time & 0x1f); + tm.tm_min = (time >> 5) & 0x3f; + tm.tm_hour = (time >> 11) & 0x1f; + tm.tm_mday = (time >> 16) & 0x1f; + tm.tm_mon = ((time >> 21) & 0x0f) - 1; + tm.tm_year = ((time >> 25) & 0x7f) + 80; + tm.tm_isdst = -1; + return mktime(&tm); +} + +static int +read_exttime(const char *p, struct rar *rar, const char *endp) +{ + unsigned rmode, flags, rem, j, count; + int time, i; + struct tm *tm; + time_t t; + long nsec; + + if (p + 2 > endp) + return (-1); + flags = archive_le16dec(p); + p += 2; + + for (i = 3; i >= 0; i--) + { + t = 0; + if (i == 3) + t = rar->mtime; + rmode = flags >> i * 4; + if (rmode & 8) + { + if (!t) + { + if (p + 4 > endp) + return (-1); + time = archive_le32dec(p); + t = get_time(time); + p += 4; + } + rem = 0; + count = rmode & 3; + if (p + count > endp) + return (-1); + for (j = 0; j < count; j++) + { + rem = ((*p) << 16) | (rem >> 8); + p++; + } + tm = localtime(&t); + nsec = tm->tm_sec + rem / NS_UNIT; + if (rmode & 4) + { + tm->tm_sec++; + t = mktime(tm); + } + if (i == 3) + { + rar->mtime = t; + rar->mnsec = nsec; + } + else if (i == 2) + { + rar->ctime = t; + rar->cnsec = nsec; + } + else if (i == 1) + { + rar->atime = t; + rar->ansec = nsec; + } + else + { + rar->arctime = t; + rar->arcnsec = nsec; + } + } + } + return (0); +} + +static int +read_symlink_stored(struct archive_read *a, struct archive_entry *entry, + struct archive_string_conv *sconv) +{ + const void *h; + const char *p; + struct rar *rar; + int ret = (ARCHIVE_OK); + + rar = (struct rar *)(a->format->data); + if ((h = __archive_read_ahead(a, rar->packed_size, NULL)) == NULL) + return (ARCHIVE_FATAL); + p = h; + + if (archive_entry_copy_symlink_l(entry, p, rar->packed_size, sconv)) + { + if (errno == ENOMEM) + { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for link"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "link cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + ret = (ARCHIVE_WARN); + } + __archive_read_consume(a, rar->packed_size); + return ret; +} + +static int +read_data_stored(struct archive_read *a, const void **buff, size_t *size, + int64_t *offset) +{ + struct rar *rar; + ssize_t bytes_avail; + + rar = (struct rar *)(a->format->data); + if (rar->bytes_remaining == 0) + { + *buff = NULL; + *size = 0; + *offset = rar->offset; + if (rar->file_crc != rar->crc_calculated) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "File CRC error"); + return (ARCHIVE_FATAL); + } + rar->entry_eof = 1; + return (ARCHIVE_EOF); + } + + *buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > rar->bytes_remaining) + bytes_avail = rar->bytes_remaining; + + *size = bytes_avail; + *offset = rar->offset; + rar->offset += bytes_avail; + rar->bytes_remaining -= bytes_avail; + rar->bytes_unconsumed = bytes_avail; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, bytes_avail); + return (ARCHIVE_OK); +} + +static int +read_data_compressed(struct archive_read *a, const void **buff, size_t *size, + int64_t *offset) +{ + struct rar *rar; + int64_t start, end, actualend; + size_t bs; + int ret = (ARCHIVE_OK), sym, code, lzss_offset, length, i; + + rar = (struct rar *)(a->format->data); + + do { + if (!rar->valid) + return (ARCHIVE_FATAL); + if (rar->ppmd_eod || + (rar->dictionary_size && rar->offset >= rar->unp_size)) + { + if (rar->unp_offset > 0) { + /* + * We have unprocessed extracted data. write it out. + */ + *buff = rar->unp_buffer; + *size = rar->unp_offset; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, *size); + rar->unp_offset = 0; + return (ARCHIVE_OK); + } + *buff = NULL; + *size = 0; + *offset = rar->offset; + if (rar->file_crc != rar->crc_calculated) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "File CRC error"); + return (ARCHIVE_FATAL); + } + rar->entry_eof = 1; + return (ARCHIVE_EOF); + } + + if (!rar->is_ppmd_block && rar->dictionary_size && rar->bytes_uncopied > 0) + { + if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) + bs = rar->unp_buffer_size - rar->unp_offset; + else + bs = rar->bytes_uncopied; + ret = copy_from_lzss_window(a, buff, rar->offset, bs); + if (ret != ARCHIVE_OK) + return (ret); + rar->offset += bs; + rar->bytes_uncopied -= bs; + if (*buff != NULL) { + rar->unp_offset = 0; + *size = rar->unp_buffer_size; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, *size); + return (ret); + } + continue; + } + + if (!rar->br.next_in && + (ret = rar_br_preparation(a, &(rar->br))) < ARCHIVE_WARN) + return (ret); + if (rar->start_new_table && ((ret = parse_codes(a)) < (ARCHIVE_WARN))) + return (ret); + + if (rar->is_ppmd_block) + { + if ((sym = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + if(sym != rar->ppmd_escape) + { + lzss_emit_literal(rar, sym); + rar->bytes_uncopied++; + } + else + { + if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + + switch(code) + { + case 0: + rar->start_new_table = 1; + return read_data_compressed(a, buff, size, offset); + + case 2: + rar->ppmd_eod = 1;/* End Of ppmd Data. */ + continue; + + case 3: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Parsing filters is unsupported."); + return (ARCHIVE_FAILED); + + case 4: + lzss_offset = 0; + for (i = 2; i >= 0; i--) + { + if ((code = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_offset |= code << (i * 8); + } + if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_emit_match(rar, lzss_offset + 2, length + 32); + rar->bytes_uncopied += length + 32; + break; + + case 5: + if ((length = __archive_ppmd7_functions.Ppmd7_DecodeSymbol( + &rar->ppmd7_context, &rar->range_dec.p)) < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid symbol"); + return (ARCHIVE_FATAL); + } + lzss_emit_match(rar, 1, length + 4); + rar->bytes_uncopied += length + 4; + break; + + default: + lzss_emit_literal(rar, sym); + rar->bytes_uncopied++; + } + } + } + else + { + start = rar->offset; + end = start + rar->dictionary_size; + rar->filterstart = INT64_MAX; + + if ((actualend = expand(a, end)) < 0) + return ((int)actualend); + + rar->bytes_uncopied = actualend - start; + if (rar->bytes_uncopied == 0) { + /* Broken RAR files cause this case. + * NOTE: If this case were possible on a normal RAR file + * we would find out where it was actually bad and + * what we would do to solve it. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Internal error extracting RAR file"); + return (ARCHIVE_FATAL); + } + } + if (rar->bytes_uncopied > (rar->unp_buffer_size - rar->unp_offset)) + bs = rar->unp_buffer_size - rar->unp_offset; + else + bs = rar->bytes_uncopied; + ret = copy_from_lzss_window(a, buff, rar->offset, bs); + if (ret != ARCHIVE_OK) + return (ret); + rar->offset += bs; + rar->bytes_uncopied -= bs; + /* + * If *buff is NULL, it means unp_buffer is not full. + * So we have to continue extracting a RAR file. + */ + } while (*buff == NULL); + + rar->unp_offset = 0; + *size = rar->unp_buffer_size; + *offset = rar->offset_outgoing; + rar->offset_outgoing += *size; + /* Calculate File CRC. */ + rar->crc_calculated = crc32(rar->crc_calculated, *buff, *size); + return ret; +} + +static int +parse_codes(struct archive_read *a) +{ + int i, j, val, n, r; + unsigned char bitlengths[MAX_SYMBOLS], zerocount, ppmd_flags; + unsigned int maxorder; + struct huffman_code precode; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + + free_codes(a); + + /* Skip to the next byte */ + rar_br_consume_unalined_bits(br); + + /* PPMd block flag */ + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + if ((rar->is_ppmd_block = rar_br_bits(br, 1)) != 0) + { + rar_br_consume(br, 1); + if (!rar_br_read_ahead(a, br, 7)) + goto truncated_data; + ppmd_flags = rar_br_bits(br, 7); + rar_br_consume(br, 7); + + /* Memory is allocated in MB */ + if (ppmd_flags & 0x20) + { + if (!rar_br_read_ahead(a, br, 8)) + goto truncated_data; + rar->dictionary_size = (rar_br_bits(br, 8) + 1) << 20; + rar_br_consume(br, 8); + } + + if (ppmd_flags & 0x40) + { + if (!rar_br_read_ahead(a, br, 8)) + goto truncated_data; + rar->ppmd_escape = rar->ppmd7_context.InitEsc = rar_br_bits(br, 8); + rar_br_consume(br, 8); + } + else + rar->ppmd_escape = 2; + + if (ppmd_flags & 0x20) + { + maxorder = (ppmd_flags & 0x1F) + 1; + if(maxorder > 16) + maxorder = 16 + (maxorder - 16) * 3; + + if (maxorder == 1) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + return (ARCHIVE_FATAL); + } + + /* Make sure ppmd7_contest is freed before Ppmd7_Construct + * because reading a broken file cause this abnormal sequence. */ + __archive_ppmd7_functions.Ppmd7_Free(&rar->ppmd7_context, &g_szalloc); + + rar->bytein.a = a; + rar->bytein.Read = &ppmd_read; + __archive_ppmd7_functions.PpmdRAR_RangeDec_CreateVTable(&rar->range_dec); + rar->range_dec.Stream = &rar->bytein; + __archive_ppmd7_functions.Ppmd7_Construct(&rar->ppmd7_context); + + if (!__archive_ppmd7_functions.Ppmd7_Alloc(&rar->ppmd7_context, + rar->dictionary_size, &g_szalloc)) + { + archive_set_error(&a->archive, ENOMEM, + "Out of memory"); + return (ARCHIVE_FATAL); + } + if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unable to initialize PPMd range decoder"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init(&rar->ppmd7_context, maxorder); + rar->ppmd_valid = 1; + } + else + { + if (!rar->ppmd_valid) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid PPMd sequence"); + return (ARCHIVE_FATAL); + } + if (!__archive_ppmd7_functions.PpmdRAR_RangeDec_Init(&rar->range_dec)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unable to initialize PPMd range decoder"); + return (ARCHIVE_FATAL); + } + } + } + else + { + rar_br_consume(br, 1); + + /* Keep existing table flag */ + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + if (!rar_br_bits(br, 1)) + memset(rar->lengthtable, 0, sizeof(rar->lengthtable)); + rar_br_consume(br, 1); + + memset(&bitlengths, 0, sizeof(bitlengths)); + for (i = 0; i < MAX_SYMBOLS;) + { + if (!rar_br_read_ahead(a, br, 4)) + goto truncated_data; + bitlengths[i++] = rar_br_bits(br, 4); + rar_br_consume(br, 4); + if (bitlengths[i-1] == 0xF) + { + if (!rar_br_read_ahead(a, br, 4)) + goto truncated_data; + zerocount = rar_br_bits(br, 4); + rar_br_consume(br, 4); + if (zerocount) + { + i--; + for (j = 0; j < zerocount + 2 && i < MAX_SYMBOLS; j++) + bitlengths[i++] = 0; + } + } + } + + memset(&precode, 0, sizeof(precode)); + r = create_code(a, &precode, bitlengths, MAX_SYMBOLS, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) { + free(precode.tree); + free(precode.table); + return (r); + } + + for (i = 0; i < HUFFMAN_TABLE_SIZE;) + { + if ((val = read_next_symbol(a, &precode)) < 0) { + free(precode.tree); + free(precode.table); + return (ARCHIVE_FATAL); + } + if (val < 16) + { + rar->lengthtable[i] = (rar->lengthtable[i] + val) & 0xF; + i++; + } + else if (val < 18) + { + if (i == 0) + { + free(precode.tree); + free(precode.table); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Internal error extracting RAR file."); + return (ARCHIVE_FATAL); + } + + if(val == 16) { + if (!rar_br_read_ahead(a, br, 3)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 3) + 3; + rar_br_consume(br, 3); + } else { + if (!rar_br_read_ahead(a, br, 7)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 7) + 11; + rar_br_consume(br, 7); + } + + for (j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++) + { + rar->lengthtable[i] = rar->lengthtable[i-1]; + i++; + } + } + else + { + if(val == 18) { + if (!rar_br_read_ahead(a, br, 3)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 3) + 3; + rar_br_consume(br, 3); + } else { + if (!rar_br_read_ahead(a, br, 7)) { + free(precode.tree); + free(precode.table); + goto truncated_data; + } + n = rar_br_bits(br, 7) + 11; + rar_br_consume(br, 7); + } + + for(j = 0; j < n && i < HUFFMAN_TABLE_SIZE; j++) + rar->lengthtable[i++] = 0; + } + } + free(precode.tree); + free(precode.table); + + r = create_code(a, &rar->maincode, &rar->lengthtable[0], MAINCODE_SIZE, + MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->offsetcode, &rar->lengthtable[MAINCODE_SIZE], + OFFSETCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->lowoffsetcode, + &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE], + LOWOFFSETCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + r = create_code(a, &rar->lengthcode, + &rar->lengthtable[MAINCODE_SIZE + OFFSETCODE_SIZE + + LOWOFFSETCODE_SIZE], LENGTHCODE_SIZE, MAX_SYMBOL_LENGTH); + if (r != ARCHIVE_OK) + return (r); + } + + if (!rar->dictionary_size || !rar->lzss.window) + { + /* Seems as though dictionary sizes are not used. Even so, minimize + * memory usage as much as possible. + */ + if (rar->unp_size >= DICTIONARY_MAX_SIZE) + rar->dictionary_size = DICTIONARY_MAX_SIZE; + else + rar->dictionary_size = rar_fls(rar->unp_size) << 1; + rar->lzss.window = (unsigned char *)realloc(rar->lzss.window, + rar->dictionary_size); + if (rar->lzss.window == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for uncompressed data."); + return (ARCHIVE_FATAL); + } + memset(rar->lzss.window, 0, rar->dictionary_size); + rar->lzss.mask = rar->dictionary_size - 1; + } + + rar->start_new_table = 0; + return (ARCHIVE_OK); +truncated_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return (ARCHIVE_FATAL); +} + +static void +free_codes(struct archive_read *a) +{ + struct rar *rar = (struct rar *)(a->format->data); + free(rar->maincode.tree); + free(rar->offsetcode.tree); + free(rar->lowoffsetcode.tree); + free(rar->lengthcode.tree); + free(rar->maincode.table); + free(rar->offsetcode.table); + free(rar->lowoffsetcode.table); + free(rar->lengthcode.table); + memset(&rar->maincode, 0, sizeof(rar->maincode)); + memset(&rar->offsetcode, 0, sizeof(rar->offsetcode)); + memset(&rar->lowoffsetcode, 0, sizeof(rar->lowoffsetcode)); + memset(&rar->lengthcode, 0, sizeof(rar->lengthcode)); +} + + +static int +read_next_symbol(struct archive_read *a, struct huffman_code *code) +{ + unsigned char bit; + unsigned int bits; + int length, value, node; + struct rar *rar; + struct rar_br *br; + + if (!code->table) + { + if (make_table(a, code) != (ARCHIVE_OK)) + return -1; + } + + rar = (struct rar *)(a->format->data); + br = &(rar->br); + + /* Look ahead (peek) at bits */ + if (!rar_br_read_ahead(a, br, code->tablesize)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return -1; + } + bits = rar_br_bits(br, code->tablesize); + + length = code->table[bits].length; + value = code->table[bits].value; + + if (length < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid prefix code in bitstream"); + return -1; + } + + if (length <= code->tablesize) + { + /* Skip length bits */ + rar_br_consume(br, length); + return value; + } + + /* Skip tablesize bits */ + rar_br_consume(br, code->tablesize); + + node = value; + while (!(code->tree[node].branches[0] == + code->tree[node].branches[1])) + { + if (!rar_br_read_ahead(a, br, 1)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return -1; + } + bit = rar_br_bits(br, 1); + rar_br_consume(br, 1); + + if (code->tree[node].branches[bit] < 0) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid prefix code in bitstream"); + return -1; + } + node = code->tree[node].branches[bit]; + } + + return code->tree[node].branches[0]; +} + +static int +create_code(struct archive_read *a, struct huffman_code *code, + unsigned char *lengths, int numsymbols, char maxlength) +{ + int i, j, codebits = 0, symbolsleft = numsymbols; + + if (new_node(code) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + code->numentries = 1; + code->minlength = INT_MAX; + code->maxlength = INT_MIN; + codebits = 0; + for(i = 1; i <= maxlength; i++) + { + for(j = 0; j < numsymbols; j++) + { + if (lengths[j] != i) continue; + if (add_value(a, code, j, codebits, i) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + codebits++; + if (--symbolsleft <= 0) { break; break; } + } + codebits <<= 1; + } + return (ARCHIVE_OK); +} + +static int +add_value(struct archive_read *a, struct huffman_code *code, int value, + int codebits, int length) +{ + int repeatpos, lastnode, bitpos, bit, repeatnode, nextnode; + + free(code->table); + code->table = NULL; + + if(length > code->maxlength) + code->maxlength = length; + if(length < code->minlength) + code->minlength = length; + + repeatpos = -1; + if (repeatpos == 0 || (repeatpos >= 0 + && (((codebits >> (repeatpos - 1)) & 3) == 0 + || ((codebits >> (repeatpos - 1)) & 3) == 3))) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid repeat position"); + return (ARCHIVE_FATAL); + } + + lastnode = 0; + for (bitpos = length - 1; bitpos >= 0; bitpos--) + { + bit = (codebits >> bitpos) & 1; + + /* Leaf node check */ + if (code->tree[lastnode].branches[0] == + code->tree[lastnode].branches[1]) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Prefix found"); + return (ARCHIVE_FATAL); + } + + if (bitpos == repeatpos) + { + /* Open branch check */ + if (!(code->tree[lastnode].branches[bit] < 0)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid repeating code"); + return (ARCHIVE_FATAL); + } + + if ((repeatnode = new_node(code)) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + if ((nextnode = new_node(code)) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + + /* Set branches */ + code->tree[lastnode].branches[bit] = repeatnode; + code->tree[repeatnode].branches[bit] = repeatnode; + code->tree[repeatnode].branches[bit^1] = nextnode; + lastnode = nextnode; + + bitpos++; /* terminating bit already handled, skip it */ + } + else + { + /* Open branch check */ + if (code->tree[lastnode].branches[bit] < 0) + { + if (new_node(code) < 0) { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for node data."); + return (ARCHIVE_FATAL); + } + code->tree[lastnode].branches[bit] = code->numentries++; + } + + /* set to branch */ + lastnode = code->tree[lastnode].branches[bit]; + } + } + + if (!(code->tree[lastnode].branches[0] == -1 + && code->tree[lastnode].branches[1] == -2)) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Prefix found"); + return (ARCHIVE_FATAL); + } + + /* Set leaf value */ + code->tree[lastnode].branches[0] = value; + code->tree[lastnode].branches[1] = value; + + return (ARCHIVE_OK); +} + +static int +new_node(struct huffman_code *code) +{ + code->tree = (struct huffman_tree_node *)realloc(code->tree, + (code->numentries + 1) * sizeof(*code->tree)); + if (code->tree == NULL) + return (-1); + code->tree[code->numentries].branches[0] = -1; + code->tree[code->numentries].branches[1] = -2; + return 1; +} + +static int +make_table(struct archive_read *a, struct huffman_code *code) +{ + if (code->maxlength < code->minlength || code->maxlength > 10) + code->tablesize = 10; + else + code->tablesize = code->maxlength; + + code->table = + (struct huffman_table_entry *)malloc(sizeof(*code->table) + * (1 << code->tablesize)); + + return make_table_recurse(a, code, 0, code->table, 0, code->tablesize); +} + +static int +make_table_recurse(struct archive_read *a, struct huffman_code *code, int node, + struct huffman_table_entry *table, int depth, + int maxdepth) +{ + int currtablesize, i, ret = (ARCHIVE_OK); + + if (!code->tree) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Huffman tree was not created."); + return (ARCHIVE_FATAL); + } + if (node < 0 || node >= code->numentries) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid location to Huffman tree specified."); + return (ARCHIVE_FATAL); + } + + currtablesize = 1 << (maxdepth - depth); + + if (code->tree[node].branches[0] == + code->tree[node].branches[1]) + { + for(i = 0; i < currtablesize; i++) + { + table[i].length = depth; + table[i].value = code->tree[node].branches[0]; + } + } + else if (node < 0) + { + for(i = 0; i < currtablesize; i++) + table[i].length = -1; + } + else + { + if(depth == maxdepth) + { + table[0].length = maxdepth + 1; + table[0].value = node; + } + else + { + ret |= make_table_recurse(a, code, code->tree[node].branches[0], table, + depth + 1, maxdepth); + ret |= make_table_recurse(a, code, code->tree[node].branches[1], + table + currtablesize / 2, depth + 1, maxdepth); + } + } + return ret; +} + +static int64_t +expand(struct archive_read *a, int64_t end) +{ + static const unsigned char lengthbases[] = + { 0, 1, 2, 3, 4, 5, 6, + 7, 8, 10, 12, 14, 16, 20, + 24, 28, 32, 40, 48, 56, 64, + 80, 96, 112, 128, 160, 192, 224 }; + static const unsigned char lengthbits[] = + { 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 2, 2, + 2, 2, 3, 3, 3, 3, 4, + 4, 4, 4, 5, 5, 5, 5 }; + static const unsigned int offsetbases[] = + { 0, 1, 2, 3, 4, 6, + 8, 12, 16, 24, 32, 48, + 64, 96, 128, 192, 256, 384, + 512, 768, 1024, 1536, 2048, 3072, + 4096, 6144, 8192, 12288, 16384, 24576, + 32768, 49152, 65536, 98304, 131072, 196608, + 262144, 327680, 393216, 458752, 524288, 589824, + 655360, 720896, 786432, 851968, 917504, 983040, + 1048576, 1310720, 1572864, 1835008, 2097152, 2359296, + 2621440, 2883584, 3145728, 3407872, 3670016, 3932160 }; + static const unsigned char offsetbits[] = + { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, + 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18 }; + static const unsigned char shortbases[] = + { 0, 4, 8, 16, 32, 64, 128, 192 }; + static const unsigned char shortbits[] = + { 2, 2, 3, 4, 5, 6, 6, 6 }; + + int symbol, offs, len, offsindex, lensymbol, i, offssymbol, lowoffsetsymbol; + unsigned char newfile; + struct rar *rar = (struct rar *)(a->format->data); + struct rar_br *br = &(rar->br); + + if (rar->filterstart < end) + end = rar->filterstart; + + while (1) + { + if (rar->output_last_match && + lzss_position(&rar->lzss) + rar->lastlength <= end) + { + lzss_emit_match(rar, rar->lastoffset, rar->lastlength); + rar->output_last_match = 0; + } + + if(rar->is_ppmd_block || rar->output_last_match || + lzss_position(&rar->lzss) >= end) + return lzss_position(&rar->lzss); + + if ((symbol = read_next_symbol(a, &rar->maincode)) < 0) + return (ARCHIVE_FATAL); + rar->output_last_match = 0; + + if (symbol < 256) + { + lzss_emit_literal(rar, symbol); + continue; + } + else if (symbol == 256) + { + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + newfile = !rar_br_bits(br, 1); + rar_br_consume(br, 1); + + if(newfile) + { + rar->start_new_block = 1; + if (!rar_br_read_ahead(a, br, 1)) + goto truncated_data; + rar->start_new_table = rar_br_bits(br, 1); + rar_br_consume(br, 1); + return lzss_position(&rar->lzss); + } + else + { + if (parse_codes(a) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + continue; + } + } + else if(symbol==257) + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Parsing filters is unsupported."); + return (ARCHIVE_FAILED); + } + else if(symbol==258) + { + if(rar->lastlength == 0) + continue; + + offs = rar->lastoffset; + len = rar->lastlength; + } + else if (symbol <= 262) + { + offsindex = symbol - 259; + offs = rar->oldoffset[offsindex]; + + if ((lensymbol = read_next_symbol(a, &rar->lengthcode)) < 0) + goto bad_data; + if (lensymbol > sizeof(lengthbases)/sizeof(lengthbases[0])) + goto bad_data; + if (lensymbol > sizeof(lengthbits)/sizeof(lengthbits[0])) + goto bad_data; + len = lengthbases[lensymbol] + 2; + if (lengthbits[lensymbol] > 0) { + if (!rar_br_read_ahead(a, br, lengthbits[lensymbol])) + goto truncated_data; + len += rar_br_bits(br, lengthbits[lensymbol]); + rar_br_consume(br, lengthbits[lensymbol]); + } + + for (i = offsindex; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + else if(symbol<=270) + { + offs = shortbases[symbol-263] + 1; + if(shortbits[symbol-263] > 0) { + if (!rar_br_read_ahead(a, br, shortbits[symbol-263])) + goto truncated_data; + offs += rar_br_bits(br, shortbits[symbol-263]); + rar_br_consume(br, shortbits[symbol-263]); + } + + len = 2; + + for(i = 3; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + else + { + if (symbol-271 > sizeof(lengthbases)/sizeof(lengthbases[0])) + goto bad_data; + if (symbol-271 > sizeof(lengthbits)/sizeof(lengthbits[0])) + goto bad_data; + len = lengthbases[symbol-271]+3; + if(lengthbits[symbol-271] > 0) { + if (!rar_br_read_ahead(a, br, lengthbits[symbol-271])) + goto truncated_data; + len += rar_br_bits(br, lengthbits[symbol-271]); + rar_br_consume(br, lengthbits[symbol-271]); + } + + if ((offssymbol = read_next_symbol(a, &rar->offsetcode)) < 0) + goto bad_data; + if (offssymbol > sizeof(offsetbases)/sizeof(offsetbases[0])) + goto bad_data; + if (offssymbol > sizeof(offsetbits)/sizeof(offsetbits[0])) + goto bad_data; + offs = offsetbases[offssymbol]+1; + if(offsetbits[offssymbol] > 0) + { + if(offssymbol > 9) + { + if(offsetbits[offssymbol] > 4) { + if (!rar_br_read_ahead(a, br, offsetbits[offssymbol] - 4)) + goto truncated_data; + offs += rar_br_bits(br, offsetbits[offssymbol] - 4) << 4; + rar_br_consume(br, offsetbits[offssymbol] - 4); + } + + if(rar->numlowoffsetrepeats > 0) + { + rar->numlowoffsetrepeats--; + offs += rar->lastlowoffset; + } + else + { + if ((lowoffsetsymbol = + read_next_symbol(a, &rar->lowoffsetcode)) < 0) + return (ARCHIVE_FATAL); + if(lowoffsetsymbol == 16) + { + rar->numlowoffsetrepeats = 15; + offs += rar->lastlowoffset; + } + else + { + offs += lowoffsetsymbol; + rar->lastlowoffset = lowoffsetsymbol; + } + } + } + else { + if (!rar_br_read_ahead(a, br, offsetbits[offssymbol])) + goto truncated_data; + offs += rar_br_bits(br, offsetbits[offssymbol]); + rar_br_consume(br, offsetbits[offssymbol]); + } + } + + if (offs >= 0x40000) + len++; + if (offs >= 0x2000) + len++; + + for(i = 3; i > 0; i--) + rar->oldoffset[i] = rar->oldoffset[i-1]; + rar->oldoffset[0] = offs; + } + + rar->lastoffset = offs; + rar->lastlength = len; + rar->output_last_match = 1; + } +truncated_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated RAR file data"); + rar->valid = 0; + return (ARCHIVE_FATAL); +bad_data: + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file data"); + return (ARCHIVE_FATAL); +} + +static int +copy_from_lzss_window(struct archive_read *a, const void **buffer, + int64_t startpos, int length) +{ + int windowoffs, firstpart; + struct rar *rar = (struct rar *)(a->format->data); + + if (!rar->unp_buffer) + { + if ((rar->unp_buffer = malloc(rar->unp_buffer_size)) == NULL) + { + archive_set_error(&a->archive, ENOMEM, + "Unable to allocate memory for uncompressed data."); + return (ARCHIVE_FATAL); + } + } + + windowoffs = lzss_offset_for_position(&rar->lzss, startpos); + if(windowoffs + length <= lzss_size(&rar->lzss)) + memcpy(&rar->unp_buffer[rar->unp_offset], &rar->lzss.window[windowoffs], + length); + else + { + firstpart = lzss_size(&rar->lzss) - windowoffs; + if (firstpart < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Bad RAR file data"); + return (ARCHIVE_FATAL); + } + if (firstpart < length) { + memcpy(&rar->unp_buffer[rar->unp_offset], + &rar->lzss.window[windowoffs], firstpart); + memcpy(&rar->unp_buffer[rar->unp_offset + firstpart], + &rar->lzss.window[0], length - firstpart); + } else + memcpy(&rar->unp_buffer[rar->unp_offset], + &rar->lzss.window[windowoffs], length); + } + rar->unp_offset += length; + if (rar->unp_offset >= rar->unp_buffer_size) + *buffer = rar->unp_buffer; + else + *buffer = NULL; + return (ARCHIVE_OK); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c index 9d0b6445c..df2c00c96 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_raw.c @@ -23,7 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_raw.c 201107 2009-12-28 03:25:33Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -39,44 +39,48 @@ __FBSDID("$FreeBSD$"); #include "archive_read_private.h" struct raw_info { - int64_t offset; /* Current position in the file. */ - int end_of_file; + int64_t offset; /* Current position in the file. */ + int64_t unconsumed; + int end_of_file; }; -static int archive_read_format_raw_bid(struct archive_read *); -static int archive_read_format_raw_cleanup(struct archive_read *); -static int archive_read_format_raw_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_raw_read_data_skip(struct archive_read *); -static int archive_read_format_raw_read_header(struct archive_read *, - struct archive_entry *); +static int archive_read_format_raw_bid(struct archive_read *, int); +static int archive_read_format_raw_cleanup(struct archive_read *); +static int archive_read_format_raw_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_raw_read_data_skip(struct archive_read *); +static int archive_read_format_raw_read_header(struct archive_read *, + struct archive_entry *); int archive_read_support_format_raw(struct archive *_a) { - struct raw_info *info; - struct archive_read *a = (struct archive_read *)_a; - int r; - - info = (struct raw_info *)calloc(1, sizeof(*info)); - if (info == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate raw_info data"); - return (ARCHIVE_FATAL); - } - - r = __archive_read_register_format(a, - info, - "raw", - archive_read_format_raw_bid, - NULL, - archive_read_format_raw_read_header, - archive_read_format_raw_read_data, - archive_read_format_raw_read_data_skip, - archive_read_format_raw_cleanup); - if (r != ARCHIVE_OK) - free(info); - return (r); + struct raw_info *info; + struct archive_read *a = (struct archive_read *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_raw"); + + info = (struct raw_info *)calloc(1, sizeof(*info)); + if (info == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate raw_info data"); + return (ARCHIVE_FATAL); + } + + r = __archive_read_register_format(a, + info, + "raw", + archive_read_format_raw_bid, + NULL, + archive_read_format_raw_read_header, + archive_read_format_raw_read_data, + archive_read_format_raw_read_data_skip, + archive_read_format_raw_cleanup); + if (r != ARCHIVE_OK) + free(info); + return (r); } /* @@ -87,13 +91,11 @@ archive_read_support_format_raw(struct archive *_a) * include "raw" as part of support_format_all(). */ static int -archive_read_format_raw_bid(struct archive_read *a) +archive_read_format_raw_bid(struct archive_read *a, int best_bid) { - const char *p; - - if ((p = __archive_read_ahead(a, 1, NULL)) == NULL) - return (-1); - return (1); + if (best_bid < 1 && __archive_read_ahead(a, 1, NULL) != NULL) + return (1); + return (-1); } /* @@ -103,84 +105,83 @@ static int archive_read_format_raw_read_header(struct archive_read *a, struct archive_entry *entry) { - struct raw_info *info; - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - - a->archive.archive_format = ARCHIVE_FORMAT_RAW; - a->archive.archive_format_name = "Raw data"; - archive_entry_set_pathname(entry, "data"); - /* XXX should we set mode to mimic a regular file? XXX */ - /* I'm deliberately leaving most fields unset here. */ - return (ARCHIVE_OK); + struct raw_info *info; + + info = (struct raw_info *)(a->format->data); + if (info->end_of_file) + return (ARCHIVE_EOF); + + a->archive.archive_format = ARCHIVE_FORMAT_RAW; + a->archive.archive_format_name = "raw"; + archive_entry_set_pathname(entry, "data"); + archive_entry_set_filetype(entry, AE_IFREG); + archive_entry_set_perm(entry, 0644); + /* I'm deliberately leaving most fields unset here. */ + return (ARCHIVE_OK); } static int archive_read_format_raw_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - struct raw_info *info; - ssize_t avail; - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - - /* Get whatever bytes are immediately available. */ - *buff = __archive_read_ahead(a, 1, &avail); - if (avail > 0) { - /* Consume and return the bytes we just read */ - __archive_read_consume(a, avail); - *size = avail; - *offset = info->offset; - info->offset += *size; - return (ARCHIVE_OK); - } else if (0 == avail) { - /* Record and return end-of-file. */ - info->end_of_file = 1; - *size = 0; - *offset = info->offset; - return (ARCHIVE_EOF); - } else { - /* Record and return an error. */ - *size = 0; - *offset = info->offset; - return (avail); - } + struct raw_info *info; + ssize_t avail; + + info = (struct raw_info *)(a->format->data); + + /* Consume the bytes we read last time. */ + if (info->unconsumed) { + __archive_read_consume(a, info->unconsumed); + info->unconsumed = 0; + } + + if (info->end_of_file) + return (ARCHIVE_EOF); + + /* Get whatever bytes are immediately available. */ + *buff = __archive_read_ahead(a, 1, &avail); + if (avail > 0) { + /* Return the bytes we just read */ + *size = avail; + *offset = info->offset; + info->offset += *size; + info->unconsumed = avail; + return (ARCHIVE_OK); + } else if (0 == avail) { + /* Record and return end-of-file. */ + info->end_of_file = 1; + *size = 0; + *offset = info->offset; + return (ARCHIVE_EOF); + } else { + /* Record and return an error. */ + *size = 0; + *offset = info->offset; + return (avail); + } } static int archive_read_format_raw_read_data_skip(struct archive_read *a) { - struct raw_info *info; - off_t bytes_skipped; - int64_t request = 1024 * 1024 * 1024UL; /* Skip 1 GB at a time. */ - - info = (struct raw_info *)(a->format->data); - if (info->end_of_file) - return (ARCHIVE_EOF); - info->end_of_file = 1; - - for (;;) { - bytes_skipped = __archive_read_skip_lenient(a, request); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - if (bytes_skipped < request) - return (ARCHIVE_OK); - /* We skipped all the bytes we asked for. There might - * be more, so try again. */ - } + struct raw_info *info = (struct raw_info *)(a->format->data); + + /* Consume the bytes we read last time. */ + if (info->unconsumed) { + __archive_read_consume(a, info->unconsumed); + info->unconsumed = 0; + } + info->end_of_file = 1; + return (ARCHIVE_OK); } static int archive_read_format_raw_cleanup(struct archive_read *a) { - struct raw_info *info; + struct raw_info *info; - info = (struct raw_info *)(a->format->data); - free(info); - a->format->data = NULL; - return (ARCHIVE_OK); + info = (struct raw_info *)(a->format->data); + free(info); + a->format->data = NULL; + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c index 873dfe130..89a1d4f2a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_tar.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,13 +25,12 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_tar.c,v 1.72 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_tar.c 201161 2009-12-29 05:44:39Z kientzle $"); #ifdef HAVE_ERRNO_H #include #endif #include -/* #include */ /* See archive_platform.h */ #ifdef HAVE_STDLIB_H #include #endif @@ -38,37 +38,10 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_tar.c,v 1.72 #include #endif -/* Obtain suitable wide-character manipulation functions. */ -#ifdef HAVE_WCHAR_H -#include -#else -/* Good enough for equality testing, which is all we need. */ -static int wcscmp(const wchar_t *s1, const wchar_t *s2) -{ - int diff = *s1 - *s2; - while (*s1 && diff == 0) - diff = (int)*++s1 - (int)*++s2; - return diff; -} -/* Good enough for equality testing, which is all we need. */ -static int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) -{ - int diff = *s1 - *s2; - while (*s1 && diff == 0 && n-- > 0) - diff = (int)*++s1 - (int)*++s2; - return diff; -} -static size_t wcslen(const wchar_t *s) -{ - const wchar_t *p = s; - while (*p) - p++; - return p - s; -} -#endif - #include "archive.h" +#include "archive_acl_private.h" /* For ACL parsing routines. */ #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_read_private.h" @@ -78,292 +51,369 @@ static size_t wcslen(const wchar_t *s) * Layout of POSIX 'ustar' tar header. */ struct archive_entry_header_ustar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; /* "old format" header ends here */ - char magic[6]; /* For POSIX: "ustar\0" */ - char version[2]; /* For POSIX: "00" */ - char uname[32]; - char gname[32]; - char rdevmajor[8]; - char rdevminor[8]; - char prefix[155]; + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char checksum[8]; + char typeflag[1]; + char linkname[100]; /* "old format" header ends here */ + char magic[6]; /* For POSIX: "ustar\0" */ + char version[2]; /* For POSIX: "00" */ + char uname[32]; + char gname[32]; + char rdevmajor[8]; + char rdevminor[8]; + char prefix[155]; }; /* * Structure of GNU tar header */ struct gnu_sparse { - char offset[12]; - char numbytes[12]; + char offset[12]; + char numbytes[12]; }; struct archive_entry_header_gnutar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[8]; /* "ustar \0" (note blank/blank/null at end) */ - char uname[32]; - char gname[32]; - char rdevmajor[8]; - char rdevminor[8]; - char atime[12]; - char ctime[12]; - char offset[12]; - char longnames[4]; - char unused[1]; - struct gnu_sparse sparse[4]; - char isextended[1]; - char realsize[12]; - /* - * Old GNU format doesn't use POSIX 'prefix' field; they use - * the 'L' (longname) entry instead. - */ + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char checksum[8]; + char typeflag[1]; + char linkname[100]; + char magic[8]; /* "ustar \0" (note blank/blank/null at end) */ + char uname[32]; + char gname[32]; + char rdevmajor[8]; + char rdevminor[8]; + char atime[12]; + char ctime[12]; + char offset[12]; + char longnames[4]; + char unused[1]; + struct gnu_sparse sparse[4]; + char isextended[1]; + char realsize[12]; + /* + * Old GNU format doesn't use POSIX 'prefix' field; they use + * the 'L' (longname) entry instead. + */ }; /* * Data specific to this format. */ struct sparse_block { - struct sparse_block *next; - off_t offset; - off_t remaining; + struct sparse_block *next; + int64_t offset; + int64_t remaining; + int hole; }; struct tar { - struct archive_string acl_text; - struct archive_string entry_pathname; - /* For "GNU.sparse.name" and other similar path extensions. */ - struct archive_string entry_pathname_override; - struct archive_string entry_linkpath; - struct archive_string entry_uname; - struct archive_string entry_gname; - struct archive_string longlink; - struct archive_string longname; - struct archive_string pax_header; - struct archive_string pax_global; - struct archive_string line; - int pax_hdrcharset_binary; - wchar_t *pax_entry; - size_t pax_entry_length; - int header_recursion_depth; - int64_t entry_bytes_remaining; - int64_t entry_offset; - int64_t entry_padding; - int64_t realsize; - struct sparse_block *sparse_list; - struct sparse_block *sparse_last; - int64_t sparse_offset; - int64_t sparse_numbytes; - int sparse_gnu_major; - int sparse_gnu_minor; - char sparse_gnu_pending; + struct archive_string acl_text; + struct archive_string entry_pathname; + /* For "GNU.sparse.name" and other similar path extensions. */ + struct archive_string entry_pathname_override; + struct archive_string entry_linkpath; + struct archive_string entry_uname; + struct archive_string entry_gname; + struct archive_string longlink; + struct archive_string longname; + struct archive_string pax_header; + struct archive_string pax_global; + struct archive_string line; + int pax_hdrcharset_binary; + int header_recursion_depth; + int64_t entry_bytes_remaining; + int64_t entry_offset; + int64_t entry_padding; + int64_t entry_bytes_unconsumed; + int64_t realsize; + struct sparse_block *sparse_list; + struct sparse_block *sparse_last; + int64_t sparse_offset; + int64_t sparse_numbytes; + int sparse_gnu_major; + int sparse_gnu_minor; + char sparse_gnu_pending; + + struct archive_string localname; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv; + struct archive_string_conv *sconv_acl; + struct archive_string_conv *sconv_default; + int init_default_conversion; + int compat_2x; }; -static ssize_t UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n); -static int archive_block_is_null(const unsigned char *p); -static char *base64_decode(const char *, size_t, size_t *); -static void gnu_add_sparse_entry(struct tar *, - off_t offset, off_t remaining); -static void gnu_clear_sparse_list(struct tar *); -static int gnu_sparse_old_read(struct archive_read *, struct tar *, - const struct archive_entry_header_gnutar *header); -static void gnu_sparse_old_parse(struct tar *, - const struct gnu_sparse *sparse, int length); -static int gnu_sparse_01_parse(struct tar *, const char *); -static ssize_t gnu_sparse_10_read(struct archive_read *, struct tar *); -static int header_Solaris_ACL(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_common(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_old_tar(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_pax_extensions(struct archive_read *, struct tar *, - struct archive_entry *, const void *); -static int header_pax_global(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_longlink(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_longname(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_volume(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_ustar(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int header_gnutar(struct archive_read *, struct tar *, - struct archive_entry *, const void *h); -static int archive_read_format_tar_bid(struct archive_read *); -static int archive_read_format_tar_cleanup(struct archive_read *); -static int archive_read_format_tar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset); -static int archive_read_format_tar_skip(struct archive_read *a); -static int archive_read_format_tar_read_header(struct archive_read *, - struct archive_entry *); -static int checksum(struct archive_read *, const void *); -static int pax_attribute(struct tar *, struct archive_entry *, - char *key, char *value); -static int pax_header(struct archive_read *, struct tar *, - struct archive_entry *, char *attr); -static void pax_time(const char *, int64_t *sec, long *nanos); -static ssize_t readline(struct archive_read *, struct tar *, const char **, - ssize_t limit); -static int read_body_to_string(struct archive_read *, struct tar *, - struct archive_string *, const void *h); -static int64_t tar_atol(const char *, unsigned); -static int64_t tar_atol10(const char *, unsigned); -static int64_t tar_atol256(const char *, unsigned); -static int64_t tar_atol8(const char *, unsigned); -static int tar_read_header(struct archive_read *, struct tar *, - struct archive_entry *); -static int tohex(int c); -static char *url_decode(const char *); -static wchar_t *utf8_decode(struct tar *, const char *, size_t length); +static int archive_block_is_null(const char *p); +static char *base64_decode(const char *, size_t, size_t *); +static int gnu_add_sparse_entry(struct archive_read *, struct tar *, + int64_t offset, int64_t remaining); + +static void gnu_clear_sparse_list(struct tar *); +static int gnu_sparse_old_read(struct archive_read *, struct tar *, + const struct archive_entry_header_gnutar *header, size_t *); +static int gnu_sparse_old_parse(struct archive_read *, struct tar *, + const struct gnu_sparse *sparse, int length); +static int gnu_sparse_01_parse(struct archive_read *, struct tar *, + const char *); +static ssize_t gnu_sparse_10_read(struct archive_read *, struct tar *, + size_t *); +static int header_Solaris_ACL(struct archive_read *, struct tar *, + struct archive_entry *, const void *, size_t *); +static int header_common(struct archive_read *, struct tar *, + struct archive_entry *, const void *); +static int header_old_tar(struct archive_read *, struct tar *, + struct archive_entry *, const void *); +static int header_pax_extensions(struct archive_read *, struct tar *, + struct archive_entry *, const void *, size_t *); +static int header_pax_global(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int header_longlink(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int header_longname(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int read_mac_metadata_blob(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int header_volume(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int header_ustar(struct archive_read *, struct tar *, + struct archive_entry *, const void *h); +static int header_gnutar(struct archive_read *, struct tar *, + struct archive_entry *, const void *h, size_t *); +static int archive_read_format_tar_bid(struct archive_read *, int); +static int archive_read_format_tar_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_tar_cleanup(struct archive_read *); +static int archive_read_format_tar_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset); +static int archive_read_format_tar_skip(struct archive_read *a); +static int archive_read_format_tar_read_header(struct archive_read *, + struct archive_entry *); +static int checksum(struct archive_read *, const void *); +static int pax_attribute(struct archive_read *, struct tar *, + struct archive_entry *, char *key, char *value); +static int pax_header(struct archive_read *, struct tar *, + struct archive_entry *, char *attr); +static void pax_time(const char *, int64_t *sec, long *nanos); +static ssize_t readline(struct archive_read *, struct tar *, const char **, + ssize_t limit, size_t *); +static int read_body_to_string(struct archive_read *, struct tar *, + struct archive_string *, const void *h, size_t *); +static int solaris_sparse_parse(struct archive_read *, struct tar *, + struct archive_entry *, const char *); +static int64_t tar_atol(const char *, unsigned); +static int64_t tar_atol10(const char *, unsigned); +static int64_t tar_atol256(const char *, unsigned); +static int64_t tar_atol8(const char *, unsigned); +static int tar_read_header(struct archive_read *, struct tar *, + struct archive_entry *, size_t *); +static int tohex(int c); +static char *url_decode(const char *); +static void tar_flush_unconsumed(struct archive_read *, size_t *); + int archive_read_support_format_gnutar(struct archive *a) { - return (archive_read_support_format_tar(a)); + archive_check_magic(a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_gnutar"); + return (archive_read_support_format_tar(a)); } int archive_read_support_format_tar(struct archive *_a) { - struct archive_read *a = (struct archive_read *)_a; - struct tar *tar; - int r; - - tar = (struct tar *)malloc(sizeof(*tar)); - if (tar == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate tar data"); - return (ARCHIVE_FATAL); - } - memset(tar, 0, sizeof(*tar)); - - r = __archive_read_register_format(a, tar, "tar", - archive_read_format_tar_bid, - NULL, - archive_read_format_tar_read_header, - archive_read_format_tar_read_data, - archive_read_format_tar_skip, - archive_read_format_tar_cleanup); - - if (r != ARCHIVE_OK) - free(tar); - return (ARCHIVE_OK); + struct archive_read *a = (struct archive_read *)_a; + struct tar *tar; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_tar"); + + tar = (struct tar *)calloc(1, sizeof(*tar)); + if (tar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate tar data"); + return (ARCHIVE_FATAL); + } + + r = __archive_read_register_format(a, tar, "tar", + archive_read_format_tar_bid, + archive_read_format_tar_options, + archive_read_format_tar_read_header, + archive_read_format_tar_read_data, + archive_read_format_tar_skip, + archive_read_format_tar_cleanup); + + if (r != ARCHIVE_OK) + free(tar); + return (ARCHIVE_OK); } static int archive_read_format_tar_cleanup(struct archive_read *a) { - struct tar *tar; - - tar = (struct tar *)(a->format->data); - gnu_clear_sparse_list(tar); - archive_string_free(&tar->acl_text); - archive_string_free(&tar->entry_pathname); - archive_string_free(&tar->entry_pathname_override); - archive_string_free(&tar->entry_linkpath); - archive_string_free(&tar->entry_uname); - archive_string_free(&tar->entry_gname); - archive_string_free(&tar->line); - archive_string_free(&tar->pax_global); - archive_string_free(&tar->pax_header); - archive_string_free(&tar->longname); - archive_string_free(&tar->longlink); - free(tar->pax_entry); - free(tar); - (a->format->data) = NULL; - return (ARCHIVE_OK); + struct tar *tar; + + tar = (struct tar *)(a->format->data); + gnu_clear_sparse_list(tar); + archive_string_free(&tar->acl_text); + archive_string_free(&tar->entry_pathname); + archive_string_free(&tar->entry_pathname_override); + archive_string_free(&tar->entry_linkpath); + archive_string_free(&tar->entry_uname); + archive_string_free(&tar->entry_gname); + archive_string_free(&tar->line); + archive_string_free(&tar->pax_global); + archive_string_free(&tar->pax_header); + archive_string_free(&tar->longname); + archive_string_free(&tar->longlink); + archive_string_free(&tar->localname); + free(tar); + (a->format->data) = NULL; + return (ARCHIVE_OK); } static int -archive_read_format_tar_bid(struct archive_read *a) +archive_read_format_tar_bid(struct archive_read *a, int best_bid) +{ + int bid; + const char *h; + const struct archive_entry_header_ustar *header; + + (void)best_bid; /* UNUSED */ + + bid = 0; + + /* Now let's look at the actual header and see if it matches. */ + h = __archive_read_ahead(a, 512, NULL); + if (h == NULL) + return (-1); + + /* If it's an end-of-archive mark, we can handle it. */ + if (h[0] == 0 && archive_block_is_null(h)) { + /* + * Usually, I bid the number of bits verified, but + * in this case, 4096 seems excessive so I picked 10 as + * an arbitrary but reasonable-seeming value. + */ + return (10); + } + + /* If it's not an end-of-archive mark, it must have a valid checksum.*/ + if (!checksum(a, h)) + return (0); + bid += 48; /* Checksum is usually 6 octal digits. */ + + header = (const struct archive_entry_header_ustar *)h; + + /* Recognize POSIX formats. */ + if ((memcmp(header->magic, "ustar\0", 6) == 0) + && (memcmp(header->version, "00", 2) == 0)) + bid += 56; + + /* Recognize GNU tar format. */ + if ((memcmp(header->magic, "ustar ", 6) == 0) + && (memcmp(header->version, " \0", 2) == 0)) + bid += 56; + + /* Type flag must be null, digit or A-Z, a-z. */ + if (header->typeflag[0] != 0 && + !( header->typeflag[0] >= '0' && header->typeflag[0] <= '9') && + !( header->typeflag[0] >= 'A' && header->typeflag[0] <= 'Z') && + !( header->typeflag[0] >= 'a' && header->typeflag[0] <= 'z') ) + return (0); + bid += 2; /* 6 bits of variation in an 8-bit field leaves 2 bits. */ + + /* Sanity check: Look at first byte of mode field. */ + switch (255 & (unsigned)header->mode[0]) { + case 0: case 255: + /* Base-256 value: No further verification possible! */ + break; + case ' ': /* Not recommended, but not illegal, either. */ + break; + case '0': case '1': case '2': case '3': + case '4': case '5': case '6': case '7': + /* Octal Value. */ + /* TODO: Check format of remainder of this field. */ + break; + default: + /* Not a valid mode; bail out here. */ + return (0); + } + /* TODO: Sanity test uid/gid/size/mtime/rdevmajor/rdevminor fields. */ + + return (bid); +} + +static int +archive_read_format_tar_options(struct archive_read *a, + const char *key, const char *val) +{ + struct tar *tar; + int ret = ARCHIVE_FAILED; + + tar = (struct tar *)(a->format->data); + if (strcmp(key, "compat-2x") == 0) { + /* Handle UTF-8 filnames as libarchive 2.x */ + tar->compat_2x = (val != NULL)?1:0; + tar->init_default_conversion = tar->compat_2x; + ret = ARCHIVE_OK; + } else if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "tar: hdrcharset option needs a character-set name"); + else { + tar->opt_sconv = + archive_string_conversion_from_charset( + &a->archive, val, 0); + if (tar->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "tar: unknown keyword ``%s''", key); + + return (ret); +} + +/* utility function- this exists to centralize the logic of tracking + * how much unconsumed data we have floating around, and to consume + * anything outstanding since we're going to do read_aheads + */ +static void +tar_flush_unconsumed(struct archive_read *a, size_t *unconsumed) { - int bid; - const void *h; - const struct archive_entry_header_ustar *header; - - bid = 0; - - /* Now let's look at the actual header and see if it matches. */ - h = __archive_read_ahead(a, 512, NULL); - if (h == NULL) - return (-1); - - /* If it's an end-of-archive mark, we can handle it. */ - if ((*(const char *)h) == 0 - && archive_block_is_null((const unsigned char *)h)) { - /* - * Usually, I bid the number of bits verified, but - * in this case, 4096 seems excessive so I picked 10 as - * an arbitrary but reasonable-seeming value. - */ - return (10); - } - - /* If it's not an end-of-archive mark, it must have a valid checksum.*/ - if (!checksum(a, h)) - return (0); - bid += 48; /* Checksum is usually 6 octal digits. */ - - header = (const struct archive_entry_header_ustar *)h; - - /* Recognize POSIX formats. */ - if ((memcmp(header->magic, "ustar\0", 6) == 0) - &&(memcmp(header->version, "00", 2)==0)) - bid += 56; - - /* Recognize GNU tar format. */ - if ((memcmp(header->magic, "ustar ", 6) == 0) - &&(memcmp(header->version, " \0", 2)==0)) - bid += 56; - - /* Type flag must be null, digit or A-Z, a-z. */ - if (header->typeflag[0] != 0 && - !( header->typeflag[0] >= '0' && header->typeflag[0] <= '9') && - !( header->typeflag[0] >= 'A' && header->typeflag[0] <= 'Z') && - !( header->typeflag[0] >= 'a' && header->typeflag[0] <= 'z') ) - return (0); - bid += 2; /* 6 bits of variation in an 8-bit field leaves 2 bits. */ - - /* Sanity check: Look at first byte of mode field. */ - switch (255 & (unsigned)header->mode[0]) { - case 0: case 255: - /* Base-256 value: No further verification possible! */ - break; - case ' ': /* Not recommended, but not illegal, either. */ - break; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - /* Octal Value. */ - /* TODO: Check format of remainder of this field. */ - break; - default: - /* Not a valid mode; bail out here. */ - return (0); - } - /* TODO: Sanity test uid/gid/size/mtime/rdevmajor/rdevminor fields. */ - - return (bid); + if (*unconsumed) { +/* + void *data = (void *)__archive_read_ahead(a, *unconsumed, NULL); + * this block of code is to poison claimed unconsumed space, ensuring + * things break if it is in use still. + * currently it WILL break things, so enable it only for debugging this issue + if (data) { + memset(data, 0xff, *unconsumed); + } +*/ + __archive_read_consume(a, *unconsumed); + *unconsumed = 0; + } } /* - * The function invoked by archive_read_header(). This + * The function invoked by archive_read_next_header(). This * just sets up a few things and then calls the internal * tar_read_header() function below. */ @@ -371,166 +421,184 @@ static int archive_read_format_tar_read_header(struct archive_read *a, struct archive_entry *entry) { - /* - * When converting tar archives to cpio archives, it is - * essential that each distinct file have a distinct inode - * number. To simplify this, we keep a static count here to - * assign fake dev/inode numbers to each tar entry. Note that - * pax format archives may overwrite this with something more - * useful. - * - * Ideally, we would track every file read from the archive so - * that we could assign the same dev/ino pair to hardlinks, - * but the memory required to store a complete lookup table is - * probably not worthwhile just to support the relatively - * obscure tar->cpio conversion case. - */ - static int default_inode; - static int default_dev; - struct tar *tar; - struct sparse_block *sp; - const char *p; - int r; - size_t l; - - /* Assign default device/inode values. */ - archive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */ - archive_entry_set_ino(entry, ++default_inode); /* Don't use zero. */ - /* Limit generated st_ino number to 16 bits. */ - if (default_inode >= 0xffff) { - ++default_dev; - default_inode = 0; - } - - tar = (struct tar *)(a->format->data); - tar->entry_offset = 0; - while (tar->sparse_list != NULL) { - sp = tar->sparse_list; - tar->sparse_list = sp->next; - free(sp); - } - tar->sparse_last = NULL; - tar->realsize = -1; /* Mark this as "unset" */ - - r = tar_read_header(a, tar, entry); - - /* - * "non-sparse" files are really just sparse files with - * a single block. - */ - if (tar->sparse_list == NULL) - gnu_add_sparse_entry(tar, 0, tar->entry_bytes_remaining); - - if (r == ARCHIVE_OK) { - /* - * "Regular" entry with trailing '/' is really - * directory: This is needed for certain old tar - * variants and even for some broken newer ones. - */ - p = archive_entry_pathname(entry); - l = strlen(p); - if (archive_entry_filetype(entry) == AE_IFREG - && p[l-1] == '/') - archive_entry_set_filetype(entry, AE_IFDIR); - } - return (r); + /* + * When converting tar archives to cpio archives, it is + * essential that each distinct file have a distinct inode + * number. To simplify this, we keep a static count here to + * assign fake dev/inode numbers to each tar entry. Note that + * pax format archives may overwrite this with something more + * useful. + * + * Ideally, we would track every file read from the archive so + * that we could assign the same dev/ino pair to hardlinks, + * but the memory required to store a complete lookup table is + * probably not worthwhile just to support the relatively + * obscure tar->cpio conversion case. + */ + static int default_inode; + static int default_dev; + struct tar *tar; + const char *p; + int r; + size_t l, unconsumed = 0; + + /* Assign default device/inode values. */ + archive_entry_set_dev(entry, 1 + default_dev); /* Don't use zero. */ + archive_entry_set_ino(entry, ++default_inode); /* Don't use zero. */ + /* Limit generated st_ino number to 16 bits. */ + if (default_inode >= 0xffff) { + ++default_dev; + default_inode = 0; + } + + tar = (struct tar *)(a->format->data); + tar->entry_offset = 0; + gnu_clear_sparse_list(tar); + tar->realsize = -1; /* Mark this as "unset" */ + + /* Setup default string conversion. */ + tar->sconv = tar->opt_sconv; + if (tar->sconv == NULL) { + if (!tar->init_default_conversion) { + tar->sconv_default = + archive_string_default_conversion_for_read(&(a->archive)); + tar->init_default_conversion = 1; + } + tar->sconv = tar->sconv_default; + } + + r = tar_read_header(a, tar, entry, &unconsumed); + + tar_flush_unconsumed(a, &unconsumed); + + /* + * "non-sparse" files are really just sparse files with + * a single block. + */ + if (tar->sparse_list == NULL) { + if (gnu_add_sparse_entry(a, tar, 0, tar->entry_bytes_remaining) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + struct sparse_block *sb; + + for (sb = tar->sparse_list; sb != NULL; sb = sb->next) { + if (!sb->hole) + archive_entry_sparse_add_entry(entry, + sb->offset, sb->remaining); + } + } + + if (r == ARCHIVE_OK) { + /* + * "Regular" entry with trailing '/' is really + * directory: This is needed for certain old tar + * variants and even for some broken newer ones. + */ + const wchar_t *wp; + wp = archive_entry_pathname_w(entry); + if (wp != NULL) { + l = wcslen(wp); + if (archive_entry_filetype(entry) == AE_IFREG + && wp[l-1] == L'/') + archive_entry_set_filetype(entry, AE_IFDIR); + } else { + p = archive_entry_pathname(entry); + if (p == NULL) + return (ARCHIVE_FAILED); + l = strlen(p); + if (archive_entry_filetype(entry) == AE_IFREG + && p[l-1] == '/') + archive_entry_set_filetype(entry, AE_IFDIR); + } + } + return (r); } static int archive_read_format_tar_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - ssize_t bytes_read; - struct tar *tar; - struct sparse_block *p; - - tar = (struct tar *)(a->format->data); - - if (tar->sparse_gnu_pending) { - if (tar->sparse_gnu_major == 1 && tar->sparse_gnu_minor == 0) { - tar->sparse_gnu_pending = 0; - /* Read initial sparse map. */ - bytes_read = gnu_sparse_10_read(a, tar); - tar->entry_bytes_remaining -= bytes_read; - if (bytes_read < 0) - return (bytes_read); - } else { - *size = 0; - *offset = 0; - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unrecognized GNU sparse file format"); - return (ARCHIVE_WARN); - } - tar->sparse_gnu_pending = 0; - } - - /* Remove exhausted entries from sparse list. */ - while (tar->sparse_list != NULL && - tar->sparse_list->remaining == 0) { - p = tar->sparse_list; - tar->sparse_list = p->next; - free(p); - } - - /* If we're at end of file, return EOF. */ - if (tar->sparse_list == NULL || tar->entry_bytes_remaining == 0) { - if (__archive_read_skip(a, tar->entry_padding) < 0) - return (ARCHIVE_FATAL); - tar->entry_padding = 0; - *buff = NULL; - *size = 0; - *offset = tar->realsize; - return (ARCHIVE_EOF); - } - - *buff = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (*buff == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Truncated tar archive"); - return (ARCHIVE_FATAL); - } - if (bytes_read > tar->entry_bytes_remaining) - bytes_read = tar->entry_bytes_remaining; - /* Don't read more than is available in the - * current sparse block. */ - if (tar->sparse_list->remaining < bytes_read) - bytes_read = tar->sparse_list->remaining; - *size = bytes_read; - *offset = tar->sparse_list->offset; - tar->sparse_list->remaining -= bytes_read; - tar->sparse_list->offset += bytes_read; - tar->entry_bytes_remaining -= bytes_read; - __archive_read_consume(a, bytes_read); - return (ARCHIVE_OK); + ssize_t bytes_read; + struct tar *tar; + struct sparse_block *p; + + tar = (struct tar *)(a->format->data); + +skip_hole: + /* Remove exhausted entries from sparse list. */ + while (tar->sparse_list != NULL && + tar->sparse_list->remaining == 0) { + p = tar->sparse_list; + tar->sparse_list = p->next; + free(p); + } + + if (tar->entry_bytes_unconsumed) { + __archive_read_consume(a, tar->entry_bytes_unconsumed); + tar->entry_bytes_unconsumed = 0; + } + + /* If we're at end of file, return EOF. */ + if (tar->sparse_list == NULL || tar->entry_bytes_remaining == 0) { + if (__archive_read_consume(a, tar->entry_padding) < 0) + return (ARCHIVE_FATAL); + tar->entry_padding = 0; + *buff = NULL; + *size = 0; + *offset = tar->realsize; + return (ARCHIVE_EOF); + } + + *buff = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read < 0) + return (ARCHIVE_FATAL); + if (*buff == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated tar archive"); + return (ARCHIVE_FATAL); + } + if (bytes_read > tar->entry_bytes_remaining) + bytes_read = tar->entry_bytes_remaining; + /* Don't read more than is available in the + * current sparse block. */ + if (tar->sparse_list->remaining < bytes_read) + bytes_read = tar->sparse_list->remaining; + *size = bytes_read; + *offset = tar->sparse_list->offset; + tar->sparse_list->remaining -= bytes_read; + tar->sparse_list->offset += bytes_read; + tar->entry_bytes_remaining -= bytes_read; + tar->entry_bytes_unconsumed = bytes_read; + + if (tar->sparse_list->hole) + goto skip_hole; + + return (ARCHIVE_OK); } static int archive_read_format_tar_skip(struct archive_read *a) { - int64_t bytes_skipped; - struct tar* tar; + int64_t bytes_skipped; + struct tar* tar; - tar = (struct tar *)(a->format->data); + tar = (struct tar *)(a->format->data); - /* - * Compression layer skip functions are required to either skip the - * length requested or fail, so we can rely upon the entire entry - * plus padding being skipped. - */ - bytes_skipped = __archive_read_skip(a, - tar->entry_bytes_remaining + tar->entry_padding); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); + bytes_skipped = __archive_read_consume(a, + tar->entry_bytes_remaining + tar->entry_padding + + tar->entry_bytes_unconsumed); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); - tar->entry_bytes_remaining = 0; - tar->entry_padding = 0; + tar->entry_bytes_remaining = 0; + tar->entry_bytes_unconsumed = 0; + tar->entry_padding = 0; - /* Free the sparse list. */ - gnu_clear_sparse_list(tar); + /* Free the sparse list. */ + gnu_clear_sparse_list(tar); - return (ARCHIVE_OK); + return (ARCHIVE_OK); } /* @@ -539,126 +607,163 @@ archive_read_format_tar_skip(struct archive_read *a) */ static int tar_read_header(struct archive_read *a, struct tar *tar, - struct archive_entry *entry) + struct archive_entry *entry, size_t *unconsumed) { - ssize_t bytes; - int err; - const void *h; - const struct archive_entry_header_ustar *header; - - /* Read 512-byte header record */ - h = __archive_read_ahead(a, 512, &bytes); - if (bytes < 0) - return (bytes); - if (bytes < 512) { /* Short read or EOF. */ - /* Try requesting just one byte and see what happens. */ - h = __archive_read_ahead(a, 1, &bytes); - if (bytes == 0) { - /* - * The archive ends at a 512-byte boundary but - * without a proper end-of-archive marker. - * Yes, there are tar writers that do this; - * hold our nose and accept it. - */ - return (ARCHIVE_EOF); - } - /* Archive ends with a partial block; this is bad. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated tar archive"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, 512); - - - /* Check for end-of-archive mark. */ - if (((*(const char *)h)==0) && archive_block_is_null((const unsigned char *)h)) { - /* Try to consume a second all-null record, as well. */ - h = __archive_read_ahead(a, 512, NULL); - if (h != NULL) - __archive_read_consume(a, 512); - archive_set_error(&a->archive, 0, NULL); - if (a->archive.archive_format_name == NULL) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR; - a->archive.archive_format_name = "tar"; - } - return (ARCHIVE_EOF); - } - - /* - * Note: If the checksum fails and we return ARCHIVE_RETRY, - * then the client is likely to just retry. This is a very - * crude way to search for the next valid header! - * - * TODO: Improve this by implementing a real header scan. - */ - if (!checksum(a, h)) { - archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); - return (ARCHIVE_RETRY); /* Retryable: Invalid header */ - } - - if (++tar->header_recursion_depth > 32) { - archive_set_error(&a->archive, EINVAL, "Too many special headers"); - return (ARCHIVE_WARN); - } - - /* Determine the format variant. */ - header = (const struct archive_entry_header_ustar *)h; - switch(header->typeflag[0]) { - case 'A': /* Solaris tar ACL */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "Solaris tar"; - err = header_Solaris_ACL(a, tar, entry, h); - break; - case 'g': /* POSIX-standard 'g' header. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange format"; - err = header_pax_global(a, tar, entry, h); - break; - case 'K': /* Long link name (GNU tar, others) */ - err = header_longlink(a, tar, entry, h); - break; - case 'L': /* Long filename (GNU tar, others) */ - err = header_longname(a, tar, entry, h); - break; - case 'V': /* GNU volume header */ - err = header_volume(a, tar, entry, h); - break; - case 'X': /* Used by SUN tar; same as 'x'. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = - "POSIX pax interchange format (Sun variant)"; - err = header_pax_extensions(a, tar, entry, h); - break; - case 'x': /* POSIX-standard 'x' header. */ - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange format"; - err = header_pax_extensions(a, tar, entry, h); - break; - default: - if (memcmp(header->magic, "ustar \0", 8) == 0) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR; - a->archive.archive_format_name = "GNU tar format"; - err = header_gnutar(a, tar, entry, h); - } else if (memcmp(header->magic, "ustar", 5) == 0) { - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { - a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; - a->archive.archive_format_name = "POSIX ustar format"; - } - err = header_ustar(a, tar, entry, h); - } else { - a->archive.archive_format = ARCHIVE_FORMAT_TAR; - a->archive.archive_format_name = "tar (non-POSIX)"; - err = header_old_tar(a, tar, entry, h); - } - } - --tar->header_recursion_depth; - /* We return warnings or success as-is. Anything else is fatal. */ - if (err == ARCHIVE_WARN || err == ARCHIVE_OK) - return (err); - if (err == ARCHIVE_EOF) - /* EOF when recursively reading a header is bad. */ - archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); - return (ARCHIVE_FATAL); + ssize_t bytes; + int err; + const char *h; + const struct archive_entry_header_ustar *header; + + tar_flush_unconsumed(a, unconsumed); + + /* Read 512-byte header record */ + h = __archive_read_ahead(a, 512, &bytes); + if (bytes < 0) + return (bytes); + if (bytes == 0) { /* EOF at a block boundary. */ + /* Some writers do omit the block of nulls. */ + return (ARCHIVE_EOF); + } + if (bytes < 512) { /* Short block at EOF; this is bad. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated tar archive"); + return (ARCHIVE_FATAL); + } + *unconsumed = 512; + + /* Check for end-of-archive mark. */ + if (h[0] == 0 && archive_block_is_null(h)) { + /* Try to consume a second all-null record, as well. */ + tar_flush_unconsumed(a, unconsumed); + h = __archive_read_ahead(a, 512, NULL); + if (h != NULL) + __archive_read_consume(a, 512); + archive_clear_error(&a->archive); + if (a->archive.archive_format_name == NULL) { + a->archive.archive_format = ARCHIVE_FORMAT_TAR; + a->archive.archive_format_name = "tar"; + } + return (ARCHIVE_EOF); + } + + /* + * Note: If the checksum fails and we return ARCHIVE_RETRY, + * then the client is likely to just retry. This is a very + * crude way to search for the next valid header! + * + * TODO: Improve this by implementing a real header scan. + */ + if (!checksum(a, h)) { + tar_flush_unconsumed(a, unconsumed); + archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); + return (ARCHIVE_RETRY); /* Retryable: Invalid header */ + } + + if (++tar->header_recursion_depth > 32) { + tar_flush_unconsumed(a, unconsumed); + archive_set_error(&a->archive, EINVAL, "Too many special headers"); + return (ARCHIVE_WARN); + } + + /* Determine the format variant. */ + header = (const struct archive_entry_header_ustar *)h; + + switch(header->typeflag[0]) { + case 'A': /* Solaris tar ACL */ + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; + a->archive.archive_format_name = "Solaris tar"; + err = header_Solaris_ACL(a, tar, entry, h, unconsumed); + break; + case 'g': /* POSIX-standard 'g' header. */ + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; + a->archive.archive_format_name = "POSIX pax interchange format"; + err = header_pax_global(a, tar, entry, h, unconsumed); + break; + case 'K': /* Long link name (GNU tar, others) */ + err = header_longlink(a, tar, entry, h, unconsumed); + break; + case 'L': /* Long filename (GNU tar, others) */ + err = header_longname(a, tar, entry, h, unconsumed); + break; + case 'V': /* GNU volume header */ + err = header_volume(a, tar, entry, h, unconsumed); + break; + case 'X': /* Used by SUN tar; same as 'x'. */ + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; + a->archive.archive_format_name = + "POSIX pax interchange format (Sun variant)"; + err = header_pax_extensions(a, tar, entry, h, unconsumed); + break; + case 'x': /* POSIX-standard 'x' header. */ + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; + a->archive.archive_format_name = "POSIX pax interchange format"; + err = header_pax_extensions(a, tar, entry, h, unconsumed); + break; + default: + if (memcmp(header->magic, "ustar \0", 8) == 0) { + a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR; + a->archive.archive_format_name = "GNU tar format"; + err = header_gnutar(a, tar, entry, h, unconsumed); + } else if (memcmp(header->magic, "ustar", 5) == 0) { + if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { + a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; + a->archive.archive_format_name = "POSIX ustar format"; + } + err = header_ustar(a, tar, entry, h); + } else { + a->archive.archive_format = ARCHIVE_FORMAT_TAR; + a->archive.archive_format_name = "tar (non-POSIX)"; + err = header_old_tar(a, tar, entry, h); + } + } + if (err == ARCHIVE_FATAL) + return (err); + + tar_flush_unconsumed(a, unconsumed); + + h = NULL; + header = NULL; + + --tar->header_recursion_depth; + /* Yuck. Apple's design here ends up storing long pathname + * extensions for both the AppleDouble extension entry and the + * regular entry. + */ + /* TODO: Should this be disabled on non-Mac platforms? */ + if ((err == ARCHIVE_WARN || err == ARCHIVE_OK) && + tar->header_recursion_depth == 0) { + int err2 = read_mac_metadata_blob(a, tar, entry, h, unconsumed); + if (err2 < err) + err = err2; + } + + /* We return warnings or success as-is. Anything else is fatal. */ + if (err == ARCHIVE_WARN || err == ARCHIVE_OK) { + if (tar->sparse_gnu_pending) { + if (tar->sparse_gnu_major == 1 && + tar->sparse_gnu_minor == 0) { + ssize_t bytes_read; + + tar->sparse_gnu_pending = 0; + /* Read initial sparse map. */ + bytes_read = gnu_sparse_10_read(a, tar, unconsumed); + tar->entry_bytes_remaining -= bytes_read; + if (bytes_read < 0) + return (bytes_read); + } else { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Unrecognized GNU sparse file format"); + return (ARCHIVE_WARN); + } + tar->sparse_gnu_pending = 0; + } + return (err); + } + if (err == ARCHIVE_EOF) + /* EOF when recursively reading a header is bad. */ + archive_set_error(&a->archive, EINVAL, "Damaged tar archive"); + return (ARCHIVE_FATAL); } /* @@ -667,59 +772,59 @@ tar_read_header(struct archive_read *a, struct tar *tar, static int checksum(struct archive_read *a, const void *h) { - const unsigned char *bytes; - const struct archive_entry_header_ustar *header; - int check, i, sum; - - (void)a; /* UNUSED */ - bytes = (const unsigned char *)h; - header = (const struct archive_entry_header_ustar *)h; - - /* - * Test the checksum. Note that POSIX specifies _unsigned_ - * bytes for this calculation. - */ - sum = tar_atol(header->checksum, sizeof(header->checksum)); - check = 0; - for (i = 0; i < 148; i++) - check += (unsigned char)bytes[i]; - for (; i < 156; i++) - check += 32; - for (; i < 512; i++) - check += (unsigned char)bytes[i]; - if (sum == check) - return (1); - - /* - * Repeat test with _signed_ bytes, just in case this archive - * was created by an old BSD, Solaris, or HP-UX tar with a - * broken checksum calculation. - */ - check = 0; - for (i = 0; i < 148; i++) - check += (signed char)bytes[i]; - for (; i < 156; i++) - check += 32; - for (; i < 512; i++) - check += (signed char)bytes[i]; - if (sum == check) - return (1); - - return (0); + const unsigned char *bytes; + const struct archive_entry_header_ustar *header; + int check, i, sum; + + (void)a; /* UNUSED */ + bytes = (const unsigned char *)h; + header = (const struct archive_entry_header_ustar *)h; + + /* + * Test the checksum. Note that POSIX specifies _unsigned_ + * bytes for this calculation. + */ + sum = tar_atol(header->checksum, sizeof(header->checksum)); + check = 0; + for (i = 0; i < 148; i++) + check += (unsigned char)bytes[i]; + for (; i < 156; i++) + check += 32; + for (; i < 512; i++) + check += (unsigned char)bytes[i]; + if (sum == check) + return (1); + + /* + * Repeat test with _signed_ bytes, just in case this archive + * was created by an old BSD, Solaris, or HP-UX tar with a + * broken checksum calculation. + */ + check = 0; + for (i = 0; i < 148; i++) + check += (signed char)bytes[i]; + for (; i < 156; i++) + check += 32; + for (; i < 512; i++) + check += (signed char)bytes[i]; + if (sum == check) + return (1); + + return (0); } /* * Return true if this block contains only nulls. */ static int -archive_block_is_null(const unsigned char *p) +archive_block_is_null(const char *p) { - unsigned i; + unsigned i; - for (i = 0; i < 512; i++) - if (*p++) - return (0); - return (1); + for (i = 0; i < 512; i++) + if (*p++) + return (0); + return (1); } /* @@ -727,92 +832,99 @@ archive_block_is_null(const unsigned char *p) */ static int header_Solaris_ACL(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - const struct archive_entry_header_ustar *header; - size_t size; - int err; - int64_t type; - char *acl, *p; - wchar_t *wp; - - /* - * read_body_to_string adds a NUL terminator, but we need a little - * more to make sure that we don't overrun acl_text later. - */ - header = (const struct archive_entry_header_ustar *)h; - size = tar_atol(header->size, sizeof(header->size)); - err = read_body_to_string(a, tar, &(tar->acl_text), h); - if (err != ARCHIVE_OK) - return (err); - /* Recursively read next header */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - - /* TODO: Examine the first characters to see if this - * is an AIX ACL descriptor. We'll likely never support - * them, but it would be polite to recognize and warn when - * we do see them. */ - - /* Leading octal number indicates ACL type and number of entries. */ - p = acl = tar->acl_text.s; - type = 0; - while (*p != '\0' && p < acl + size) { - if (*p < '0' || *p > '7') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (invalid digit)"); - return(ARCHIVE_WARN); - } - type <<= 3; - type += *p - '0'; - if (type > 077777777) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (count too large)"); - return (ARCHIVE_WARN); - } - p++; - } -#ifdef __hpux - switch ((int)type & ~0777777) { -#else - switch (type & ~0777777) { -#endif - case 01000000: - /* POSIX.1e ACL */ - break; - case 03000000: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Solaris NFSv4 ACLs not supported"); - return (ARCHIVE_WARN); - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (unsupported type %o)", - (int)type); - return (ARCHIVE_WARN); - } - p++; - - if (p >= acl + size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (body overflow)"); - return(ARCHIVE_WARN); - } - - /* ACL text is null-terminated; find the end. */ - size -= (p - acl); - acl = p; - - while (*p != '\0' && p < acl + size) - p++; - - wp = utf8_decode(tar, acl, p - acl); - err = __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - if (err != ARCHIVE_OK) - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed Solaris ACL attribute (unparsable)"); - return (err); + const struct archive_entry_header_ustar *header; + size_t size; + int err; + int64_t type; + char *acl, *p; + + /* + * read_body_to_string adds a NUL terminator, but we need a little + * more to make sure that we don't overrun acl_text later. + */ + header = (const struct archive_entry_header_ustar *)h; + size = tar_atol(header->size, sizeof(header->size)); + err = read_body_to_string(a, tar, &(tar->acl_text), h, unconsumed); + if (err != ARCHIVE_OK) + return (err); + + /* Recursively read next header */ + err = tar_read_header(a, tar, entry, unconsumed); + if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) + return (err); + + /* TODO: Examine the first characters to see if this + * is an AIX ACL descriptor. We'll likely never support + * them, but it would be polite to recognize and warn when + * we do see them. */ + + /* Leading octal number indicates ACL type and number of entries. */ + p = acl = tar->acl_text.s; + type = 0; + while (*p != '\0' && p < acl + size) { + if (*p < '0' || *p > '7') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed Solaris ACL attribute (invalid digit)"); + return(ARCHIVE_WARN); + } + type <<= 3; + type += *p - '0'; + if (type > 077777777) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed Solaris ACL attribute (count too large)"); + return (ARCHIVE_WARN); + } + p++; + } + switch ((int)type & ~0777777) { + case 01000000: + /* POSIX.1e ACL */ + break; + case 03000000: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Solaris NFSv4 ACLs not supported"); + return (ARCHIVE_WARN); + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed Solaris ACL attribute (unsupported type %o)", + (int)type); + return (ARCHIVE_WARN); + } + p++; + + if (p >= acl + size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed Solaris ACL attribute (body overflow)"); + return(ARCHIVE_WARN); + } + + /* ACL text is null-terminated; find the end. */ + size -= (p - acl); + acl = p; + + while (*p != '\0' && p < acl + size) + p++; + + if (tar->sconv_acl == NULL) { + tar->sconv_acl = archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (tar->sconv_acl == NULL) + return (ARCHIVE_FATAL); + } + archive_strncpy(&(tar->localname), acl, p - acl); + err = archive_acl_parse_l(archive_entry_acl(entry), + tar->localname.s, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, tar->sconv_acl); + if (err != ARCHIVE_OK) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for ACL"); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Malformed Solaris ACL attribute (unparsable)"); + } + return (err); } /* @@ -820,19 +932,34 @@ header_Solaris_ACL(struct archive_read *a, struct tar *tar, */ static int header_longlink(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - int err; - - err = read_body_to_string(a, tar, &(tar->longlink), h); - if (err != ARCHIVE_OK) - return (err); - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - /* Set symlink if symlink already set, else hardlink. */ - archive_entry_copy_link(entry, tar->longlink.s); - return (ARCHIVE_OK); + int err; + + err = read_body_to_string(a, tar, &(tar->longlink), h, unconsumed); + if (err != ARCHIVE_OK) + return (err); + err = tar_read_header(a, tar, entry, unconsumed); + if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) + return (err); + /* Set symlink if symlink already set, else hardlink. */ + archive_entry_copy_link(entry, tar->longlink.s); + return (ARCHIVE_OK); +} + +static int +set_conversion_failed_error(struct archive_read *a, + struct archive_string_conv *sconv, const char *name) +{ + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for %s", name); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "%s can't be converted from %s to current locale.", + name, archive_string_conversion_charset_name(sconv)); + return (ARCHIVE_WARN); } /* @@ -840,19 +967,21 @@ header_longlink(struct archive_read *a, struct tar *tar, */ static int header_longname(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - int err; - - err = read_body_to_string(a, tar, &(tar->longname), h); - if (err != ARCHIVE_OK) - return (err); - /* Read and parse "real" header, then override name. */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - archive_entry_copy_pathname(entry, tar->longname.s); - return (ARCHIVE_OK); + int err; + + err = read_body_to_string(a, tar, &(tar->longname), h, unconsumed); + if (err != ARCHIVE_OK) + return (err); + /* Read and parse "real" header, then override name. */ + err = tar_read_header(a, tar, entry, unconsumed); + if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) + return (err); + if (archive_entry_copy_pathname_l(entry, tar->longname.s, + archive_strlen(&(tar->longname)), tar->sconv) != 0) + err = set_conversion_failed_error(a, tar->sconv, "Pathname"); + return (err); } @@ -861,12 +990,12 @@ header_longname(struct archive_read *a, struct tar *tar, */ static int header_volume(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - (void)h; + (void)h; - /* Just skip this and read the next header. */ - return (tar_read_header(a, tar, entry)); + /* Just skip this and read the next header. */ + return (tar_read_header(a, tar, entry, unconsumed)); } /* @@ -874,37 +1003,41 @@ header_volume(struct archive_read *a, struct tar *tar, */ static int read_body_to_string(struct archive_read *a, struct tar *tar, - struct archive_string *as, const void *h) + struct archive_string *as, const void *h, size_t *unconsumed) { - off_t size, padded_size; - const struct archive_entry_header_ustar *header; - const void *src; - - (void)tar; /* UNUSED */ - header = (const struct archive_entry_header_ustar *)h; - size = tar_atol(header->size, sizeof(header->size)); - if ((size > 1048576) || (size < 0)) { - archive_set_error(&a->archive, EINVAL, - "Special header too large"); - return (ARCHIVE_FATAL); - } - - /* Fail if we can't make our buffer big enough. */ - if (archive_string_ensure(as, size+1) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory"); - return (ARCHIVE_FATAL); - } - - /* Read the body into the string. */ - padded_size = (size + 511) & ~ 511; - src = __archive_read_ahead(a, padded_size, NULL); - if (src == NULL) - return (ARCHIVE_FATAL); - memcpy(as->s, src, size); - __archive_read_consume(a, padded_size); - as->s[size] = '\0'; - return (ARCHIVE_OK); + int64_t size; + const struct archive_entry_header_ustar *header; + const void *src; + + (void)tar; /* UNUSED */ + header = (const struct archive_entry_header_ustar *)h; + size = tar_atol(header->size, sizeof(header->size)); + if ((size > 1048576) || (size < 0)) { + archive_set_error(&a->archive, EINVAL, + "Special header too large"); + return (ARCHIVE_FATAL); + } + + /* Fail if we can't make our buffer big enough. */ + if (archive_string_ensure(as, size+1) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory"); + return (ARCHIVE_FATAL); + } + + tar_flush_unconsumed(a, unconsumed); + + /* Read the body into the string. */ + *unconsumed = (size + 511) & ~ 511; + src = __archive_read_ahead(a, *unconsumed, NULL); + if (src == NULL) { + *unconsumed = 0; + return (ARCHIVE_FATAL); + } + memcpy(as->s, src, size); + as->s[size] = '\0'; + as->length = size; + return (ARCHIVE_OK); } /* @@ -921,153 +1054,170 @@ static int header_common(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - const struct archive_entry_header_ustar *header; - char tartype; - - (void)a; /* UNUSED */ - - header = (const struct archive_entry_header_ustar *)h; - if (header->linkname[0]) - archive_strncpy(&(tar->entry_linkpath), header->linkname, - sizeof(header->linkname)); - else - archive_string_empty(&(tar->entry_linkpath)); - - /* Parse out the numeric fields (all are octal) */ - archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); - archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); - archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); - tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); - tar->realsize = tar->entry_bytes_remaining; - archive_entry_set_size(entry, tar->entry_bytes_remaining); - archive_entry_set_mtime(entry, tar_atol(header->mtime, sizeof(header->mtime)), 0); - - /* Handle the tar type flag appropriately. */ - tartype = header->typeflag[0]; - - switch (tartype) { - case '1': /* Hard link */ - archive_entry_copy_hardlink(entry, tar->entry_linkpath.s); - /* - * The following may seem odd, but: Technically, tar - * does not store the file type for a "hard link" - * entry, only the fact that it is a hard link. So, I - * leave the type zero normally. But, pax interchange - * format allows hard links to have data, which - * implies that the underlying entry is a regular - * file. - */ - if (archive_entry_size(entry) > 0) - archive_entry_set_filetype(entry, AE_IFREG); - - /* - * A tricky point: Traditionally, tar readers have - * ignored the size field when reading hardlink - * entries, and some writers put non-zero sizes even - * though the body is empty. POSIX blessed this - * convention in the 1988 standard, but broke with - * this tradition in 2001 by permitting hardlink - * entries to store valid bodies in pax interchange - * format, but not in ustar format. Since there is no - * hard and fast way to distinguish pax interchange - * from earlier archives (the 'x' and 'g' entries are - * optional, after all), we need a heuristic. - */ - if (archive_entry_size(entry) == 0) { - /* If the size is already zero, we're done. */ - } else if (a->archive.archive_format - == ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { - /* Definitely pax extended; must obey hardlink size. */ - } else if (a->archive.archive_format == ARCHIVE_FORMAT_TAR - || a->archive.archive_format == ARCHIVE_FORMAT_TAR_GNUTAR) - { - /* Old-style or GNU tar: we must ignore the size. */ - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - } else if (archive_read_format_tar_bid(a) > 50) { - /* - * We don't know if it's pax: If the bid - * function sees a valid ustar header - * immediately following, then let's ignore - * the hardlink size. - */ - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - } - /* - * TODO: There are still two cases I'd like to handle: - * = a ustar non-pax archive with a hardlink entry at - * end-of-archive. (Look for block of nulls following?) - * = a pax archive that has not seen any pax headers - * and has an entry which is a hardlink entry storing - * a body containing an uncompressed tar archive. - * The first is worth addressing; I don't see any reliable - * way to deal with the second possibility. - */ - break; - case '2': /* Symlink */ - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - archive_entry_copy_symlink(entry, tar->entry_linkpath.s); - break; - case '3': /* Character device */ - archive_entry_set_filetype(entry, AE_IFCHR); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '4': /* Block device */ - archive_entry_set_filetype(entry, AE_IFBLK); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '5': /* Dir */ - archive_entry_set_filetype(entry, AE_IFDIR); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case '6': /* FIFO device */ - archive_entry_set_filetype(entry, AE_IFIFO); - archive_entry_set_size(entry, 0); - tar->entry_bytes_remaining = 0; - break; - case 'D': /* GNU incremental directory type */ - /* - * No special handling is actually required here. - * It might be nice someday to preprocess the file list and - * provide it to the client, though. - */ - archive_entry_set_filetype(entry, AE_IFDIR); - break; - case 'M': /* GNU "Multi-volume" (remainder of file from last archive)*/ - /* - * As far as I can tell, this is just like a regular file - * entry, except that the contents should be _appended_ to - * the indicated file at the indicated offset. This may - * require some API work to fully support. - */ - break; - case 'N': /* Old GNU "long filename" entry. */ - /* The body of this entry is a script for renaming - * previously-extracted entries. Ugh. It will never - * be supported by libarchive. */ - archive_entry_set_filetype(entry, AE_IFREG); - break; - case 'S': /* GNU sparse files */ - /* - * Sparse files are really just regular files with - * sparse information in the extended area. - */ - /* FALLTHROUGH */ - default: /* Regular file and non-standard types */ - /* - * Per POSIX: non-recognized types should always be - * treated as regular files. - */ - archive_entry_set_filetype(entry, AE_IFREG); - break; - } - return (0); + const struct archive_entry_header_ustar *header; + char tartype; + int err = ARCHIVE_OK; + + header = (const struct archive_entry_header_ustar *)h; + if (header->linkname[0]) + archive_strncpy(&(tar->entry_linkpath), + header->linkname, sizeof(header->linkname)); + else + archive_string_empty(&(tar->entry_linkpath)); + + /* Parse out the numeric fields (all are octal) */ + archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); + archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); + archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); + tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); + if (tar->entry_bytes_remaining < 0) { + tar->entry_bytes_remaining = 0; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Tar entry has negative size?"); + err = ARCHIVE_WARN; + } + tar->realsize = tar->entry_bytes_remaining; + archive_entry_set_size(entry, tar->entry_bytes_remaining); + archive_entry_set_mtime(entry, tar_atol(header->mtime, sizeof(header->mtime)), 0); + + /* Handle the tar type flag appropriately. */ + tartype = header->typeflag[0]; + + switch (tartype) { + case '1': /* Hard link */ + if (archive_entry_copy_hardlink_l(entry, tar->entry_linkpath.s, + archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, + "Linkname"); + if (err == ARCHIVE_FATAL) + return (err); + } + /* + * The following may seem odd, but: Technically, tar + * does not store the file type for a "hard link" + * entry, only the fact that it is a hard link. So, I + * leave the type zero normally. But, pax interchange + * format allows hard links to have data, which + * implies that the underlying entry is a regular + * file. + */ + if (archive_entry_size(entry) > 0) + archive_entry_set_filetype(entry, AE_IFREG); + + /* + * A tricky point: Traditionally, tar readers have + * ignored the size field when reading hardlink + * entries, and some writers put non-zero sizes even + * though the body is empty. POSIX blessed this + * convention in the 1988 standard, but broke with + * this tradition in 2001 by permitting hardlink + * entries to store valid bodies in pax interchange + * format, but not in ustar format. Since there is no + * hard and fast way to distinguish pax interchange + * from earlier archives (the 'x' and 'g' entries are + * optional, after all), we need a heuristic. + */ + if (archive_entry_size(entry) == 0) { + /* If the size is already zero, we're done. */ + } else if (a->archive.archive_format + == ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE) { + /* Definitely pax extended; must obey hardlink size. */ + } else if (a->archive.archive_format == ARCHIVE_FORMAT_TAR + || a->archive.archive_format == ARCHIVE_FORMAT_TAR_GNUTAR) + { + /* Old-style or GNU tar: we must ignore the size. */ + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + } else if (archive_read_format_tar_bid(a, 50) > 50) { + /* + * We don't know if it's pax: If the bid + * function sees a valid ustar header + * immediately following, then let's ignore + * the hardlink size. + */ + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + } + /* + * TODO: There are still two cases I'd like to handle: + * = a ustar non-pax archive with a hardlink entry at + * end-of-archive. (Look for block of nulls following?) + * = a pax archive that has not seen any pax headers + * and has an entry which is a hardlink entry storing + * a body containing an uncompressed tar archive. + * The first is worth addressing; I don't see any reliable + * way to deal with the second possibility. + */ + break; + case '2': /* Symlink */ + archive_entry_set_filetype(entry, AE_IFLNK); + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + if (archive_entry_copy_symlink_l(entry, tar->entry_linkpath.s, + archive_strlen(&(tar->entry_linkpath)), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, + "Linkname"); + if (err == ARCHIVE_FATAL) + return (err); + } + break; + case '3': /* Character device */ + archive_entry_set_filetype(entry, AE_IFCHR); + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + break; + case '4': /* Block device */ + archive_entry_set_filetype(entry, AE_IFBLK); + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + break; + case '5': /* Dir */ + archive_entry_set_filetype(entry, AE_IFDIR); + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + break; + case '6': /* FIFO device */ + archive_entry_set_filetype(entry, AE_IFIFO); + archive_entry_set_size(entry, 0); + tar->entry_bytes_remaining = 0; + break; + case 'D': /* GNU incremental directory type */ + /* + * No special handling is actually required here. + * It might be nice someday to preprocess the file list and + * provide it to the client, though. + */ + archive_entry_set_filetype(entry, AE_IFDIR); + break; + case 'M': /* GNU "Multi-volume" (remainder of file from last archive)*/ + /* + * As far as I can tell, this is just like a regular file + * entry, except that the contents should be _appended_ to + * the indicated file at the indicated offset. This may + * require some API work to fully support. + */ + break; + case 'N': /* Old GNU "long filename" entry. */ + /* The body of this entry is a script for renaming + * previously-extracted entries. Ugh. It will never + * be supported by libarchive. */ + archive_entry_set_filetype(entry, AE_IFREG); + break; + case 'S': /* GNU sparse files */ + /* + * Sparse files are really just regular files with + * sparse information in the extended area. + */ + /* FALLTHROUGH */ + default: /* Regular file and non-standard types */ + /* + * Per POSIX: non-recognized types should always be + * treated as regular files. + */ + archive_entry_set_filetype(entry, AE_IFREG); + break; + } + return (err); } /* @@ -1077,18 +1227,96 @@ static int header_old_tar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - const struct archive_entry_header_ustar *header; - - /* Copy filename over (to ensure null termination). */ - header = (const struct archive_entry_header_ustar *)h; - archive_strncpy(&(tar->entry_pathname), header->name, sizeof(header->name)); - archive_entry_copy_pathname(entry, tar->entry_pathname.s); - - /* Grab rest of common fields */ - header_common(a, tar, entry, h); + const struct archive_entry_header_ustar *header; + int err = ARCHIVE_OK, err2; + + /* Copy filename over (to ensure null termination). */ + header = (const struct archive_entry_header_ustar *)h; + if (archive_entry_copy_pathname_l(entry, + header->name, sizeof(header->name), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Pathname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + /* Grab rest of common fields */ + err2 = header_common(a, tar, entry, h); + if (err > err2) + err = err2; + + tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); + return (err); +} - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (0); +/* + * Read a Mac AppleDouble-encoded blob of file metadata, + * if there is one. + */ +static int +read_mac_metadata_blob(struct archive_read *a, struct tar *tar, + struct archive_entry *entry, const void *h, size_t *unconsumed) +{ + int64_t size; + const void *data; + const char *p, *name; + const wchar_t *wp, *wname; + + (void)h; /* UNUSED */ + + wname = wp = archive_entry_pathname_w(entry); + if (wp != NULL) { + /* Find the last path element. */ + for (; *wp != L'\0'; ++wp) { + if (wp[0] == '/' && wp[1] != L'\0') + wname = wp + 1; + } + /* + * If last path element starts with "._", then + * this is a Mac extension. + */ + if (wname[0] != L'.' || wname[1] != L'_' || wname[2] == L'\0') + return ARCHIVE_OK; + } else { + /* Find the last path element. */ + name = p = archive_entry_pathname(entry); + if (p == NULL) + return (ARCHIVE_FAILED); + for (; *p != '\0'; ++p) { + if (p[0] == '/' && p[1] != '\0') + name = p + 1; + } + /* + * If last path element starts with "._", then + * this is a Mac extension. + */ + if (name[0] != '.' || name[1] != '_' || name[2] == '\0') + return ARCHIVE_OK; + } + + /* Read the body as a Mac OS metadata blob. */ + size = archive_entry_size(entry); + + /* + * TODO: Look beyond the body here to peek at the next header. + * If it's a regular header (not an extension header) + * that has the wrong name, just return the current + * entry as-is, without consuming the body here. + * That would reduce the risk of us mis-identifying + * an ordinary file that just happened to have + * a name starting with "._". + * + * Q: Is the above idea really possible? Even + * when there are GNU or pax extension entries? + */ + data = __archive_read_ahead(a, size, NULL); + if (data == NULL) { + *unconsumed = 0; + return (ARCHIVE_FATAL); + } + archive_entry_copy_mac_metadata(entry, data, size); + *unconsumed = (size + 511) & ~ 511; + tar_flush_unconsumed(a, unconsumed); + return (tar_read_header(a, tar, entry, unconsumed)); } /* @@ -1096,46 +1324,46 @@ header_old_tar(struct archive_read *a, struct tar *tar, */ static int header_pax_global(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - int err; + int err; - err = read_body_to_string(a, tar, &(tar->pax_global), h); - if (err != ARCHIVE_OK) - return (err); - err = tar_read_header(a, tar, entry); - return (err); + err = read_body_to_string(a, tar, &(tar->pax_global), h, unconsumed); + if (err != ARCHIVE_OK) + return (err); + err = tar_read_header(a, tar, entry, unconsumed); + return (err); } static int header_pax_extensions(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - int err, err2; - - err = read_body_to_string(a, tar, &(tar->pax_header), h); - if (err != ARCHIVE_OK) - return (err); - - /* Parse the next header. */ - err = tar_read_header(a, tar, entry); - if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) - return (err); - - /* - * TODO: Parse global/default options into 'entry' struct here - * before handling file-specific options. - * - * This design (parse standard header, then overwrite with pax - * extended attribute data) usually works well, but isn't ideal; - * it would be better to parse the pax extended attributes first - * and then skip any fields in the standard header that were - * defined in the pax header. - */ - err2 = pax_header(a, tar, entry, tar->pax_header.s); - err = err_combine(err, err2); - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (err); + int err, err2; + + err = read_body_to_string(a, tar, &(tar->pax_header), h, unconsumed); + if (err != ARCHIVE_OK) + return (err); + + /* Parse the next header. */ + err = tar_read_header(a, tar, entry, unconsumed); + if ((err != ARCHIVE_OK) && (err != ARCHIVE_WARN)) + return (err); + + /* + * TODO: Parse global/default options into 'entry' struct here + * before handling file-specific options. + * + * This design (parse standard header, then overwrite with pax + * extended attribute data) usually works well, but isn't ideal; + * it would be better to parse the pax extended attributes first + * and then skip any fields in the standard header that were + * defined in the pax header. + */ + err2 = pax_header(a, tar, entry, tar->pax_header.s); + err = err_combine(err, err2); + tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); + return (err); } @@ -1147,46 +1375,62 @@ static int header_ustar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { - const struct archive_entry_header_ustar *header; - struct archive_string *as; - - header = (const struct archive_entry_header_ustar *)h; - - /* Copy name into an internal buffer to ensure null-termination. */ - as = &(tar->entry_pathname); - if (header->prefix[0]) { - archive_strncpy(as, header->prefix, sizeof(header->prefix)); - if (as->s[archive_strlen(as) - 1] != '/') - archive_strappend_char(as, '/'); - archive_strncat(as, header->name, sizeof(header->name)); - } else - archive_strncpy(as, header->name, sizeof(header->name)); - - archive_entry_copy_pathname(entry, as->s); - - /* Handle rest of common fields. */ - header_common(a, tar, entry, h); - - /* Handle POSIX ustar fields. */ - archive_strncpy(&(tar->entry_uname), header->uname, - sizeof(header->uname)); - archive_entry_copy_uname(entry, tar->entry_uname.s); - - archive_strncpy(&(tar->entry_gname), header->gname, - sizeof(header->gname)); - archive_entry_copy_gname(entry, tar->entry_gname.s); - - /* Parse out device numbers only for char and block specials. */ - if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, - tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, - tar_atol(header->rdevminor, sizeof(header->rdevminor))); - } - - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - - return (0); + const struct archive_entry_header_ustar *header; + struct archive_string *as; + int err = ARCHIVE_OK, r; + + header = (const struct archive_entry_header_ustar *)h; + + /* Copy name into an internal buffer to ensure null-termination. */ + as = &(tar->entry_pathname); + if (header->prefix[0]) { + archive_strncpy(as, header->prefix, sizeof(header->prefix)); + if (as->s[archive_strlen(as) - 1] != '/') + archive_strappend_char(as, '/'); + archive_strncat(as, header->name, sizeof(header->name)); + } else { + archive_strncpy(as, header->name, sizeof(header->name)); + } + if (archive_entry_copy_pathname_l(entry, as->s, archive_strlen(as), + tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Pathname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + /* Handle rest of common fields. */ + r = header_common(a, tar, entry, h); + if (r == ARCHIVE_FATAL) + return (r); + if (r < err) + err = r; + + /* Handle POSIX ustar fields. */ + if (archive_entry_copy_uname_l(entry, + header->uname, sizeof(header->uname), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Uname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + if (archive_entry_copy_gname_l(entry, + header->gname, sizeof(header->gname), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Gname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + /* Parse out device numbers only for char and block specials. */ + if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { + archive_entry_set_rdevmajor(entry, + tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); + archive_entry_set_rdevminor(entry, + tar_atol(header->rdevminor, sizeof(header->rdevminor))); + } + + tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); + + return (err); } @@ -1199,190 +1443,201 @@ static int pax_header(struct archive_read *a, struct tar *tar, struct archive_entry *entry, char *attr) { - size_t attr_length, l, line_length; - char *line, *p; - char *key, *value; - int err, err2; - - attr_length = strlen(attr); - tar->pax_hdrcharset_binary = 0; - archive_string_empty(&(tar->entry_gname)); - archive_string_empty(&(tar->entry_linkpath)); - archive_string_empty(&(tar->entry_pathname)); - archive_string_empty(&(tar->entry_pathname_override)); - archive_string_empty(&(tar->entry_uname)); - err = ARCHIVE_OK; - while (attr_length > 0) { - /* Parse decimal length field at start of line. */ - line_length = 0; - l = attr_length; - line = p = attr; /* Record start of line. */ - while (l>0) { - if (*p == ' ') { - p++; - l--; - break; - } - if (*p < '0' || *p > '9') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring malformed pax extended attributes"); - return (ARCHIVE_WARN); - } - line_length *= 10; - line_length += *p - '0'; - if (line_length > 999999) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Rejecting pax extended attribute > 1MB"); - return (ARCHIVE_WARN); - } - p++; - l--; - } - - /* - * Parsed length must be no bigger than available data, - * at least 1, and the last character of the line must - * be '\n'. - */ - if (line_length > attr_length - || line_length < 1 - || attr[line_length - 1] != '\n') - { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring malformed pax extended attribute"); - return (ARCHIVE_WARN); - } - - /* Null-terminate the line. */ - attr[line_length - 1] = '\0'; - - /* Find end of key and null terminate it. */ - key = p; - if (key[0] == '=') - return (-1); - while (*p && *p != '=') - ++p; - if (*p == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid pax extended attributes"); - return (ARCHIVE_WARN); - } - *p = '\0'; - - /* Identify null-terminated 'value' portion. */ - value = p + 1; - - /* Identify this attribute and set it in the entry. */ - err2 = pax_attribute(tar, entry, key, value); - err = err_combine(err, err2); - - /* Skip to next line */ - attr += line_length; - attr_length -= line_length; - } - if (archive_strlen(&(tar->entry_gname)) > 0) { - value = tar->entry_gname.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_gname(entry, value); - else { - if (!archive_entry_update_gname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Gname in pax header can't " - "be converted to current locale."); - } - } - } - if (archive_strlen(&(tar->entry_linkpath)) > 0) { - value = tar->entry_linkpath.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_link(entry, value); - else { - if (!archive_entry_update_link_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Linkname in pax header can't " - "be converted to current locale."); - } - } - } - /* - * Some extensions (such as the GNU sparse file extensions) - * deliberately store a synthetic name under the regular 'path' - * attribute and the real file name under a different attribute. - * Since we're supposed to not care about the order, we - * have no choice but to store all of the various filenames - * we find and figure it all out afterwards. This is the - * figuring out part. - */ - value = NULL; - if (archive_strlen(&(tar->entry_pathname_override)) > 0) - value = tar->entry_pathname_override.s; - else if (archive_strlen(&(tar->entry_pathname)) > 0) - value = tar->entry_pathname.s; - if (value != NULL) { - if (tar->pax_hdrcharset_binary) - archive_entry_copy_pathname(entry, value); - else { - if (!archive_entry_update_pathname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Pathname in pax header can't be " - "converted to current locale."); - } - } - } - if (archive_strlen(&(tar->entry_uname)) > 0) { - value = tar->entry_uname.s; - if (tar->pax_hdrcharset_binary) - archive_entry_copy_uname(entry, value); - else { - if (!archive_entry_update_uname_utf8(entry, value)) { - err = ARCHIVE_WARN; - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Uname in pax header can't " - "be converted to current locale."); - } - } - } - return (err); + size_t attr_length, l, line_length; + char *p; + char *key, *value; + struct archive_string *as; + struct archive_string_conv *sconv; + int err, err2; + + attr_length = strlen(attr); + tar->pax_hdrcharset_binary = 0; + archive_string_empty(&(tar->entry_gname)); + archive_string_empty(&(tar->entry_linkpath)); + archive_string_empty(&(tar->entry_pathname)); + archive_string_empty(&(tar->entry_pathname_override)); + archive_string_empty(&(tar->entry_uname)); + err = ARCHIVE_OK; + while (attr_length > 0) { + /* Parse decimal length field at start of line. */ + line_length = 0; + l = attr_length; + p = attr; /* Record start of line. */ + while (l>0) { + if (*p == ' ') { + p++; + l--; + break; + } + if (*p < '0' || *p > '9') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring malformed pax extended attributes"); + return (ARCHIVE_WARN); + } + line_length *= 10; + line_length += *p - '0'; + if (line_length > 999999) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Rejecting pax extended attribute > 1MB"); + return (ARCHIVE_WARN); + } + p++; + l--; + } + + /* + * Parsed length must be no bigger than available data, + * at least 1, and the last character of the line must + * be '\n'. + */ + if (line_length > attr_length + || line_length < 1 + || attr[line_length - 1] != '\n') + { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignoring malformed pax extended attribute"); + return (ARCHIVE_WARN); + } + + /* Null-terminate the line. */ + attr[line_length - 1] = '\0'; + + /* Find end of key and null terminate it. */ + key = p; + if (key[0] == '=') + return (-1); + while (*p && *p != '=') + ++p; + if (*p == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid pax extended attributes"); + return (ARCHIVE_WARN); + } + *p = '\0'; + + /* Identify null-terminated 'value' portion. */ + value = p + 1; + + /* Identify this attribute and set it in the entry. */ + err2 = pax_attribute(a, tar, entry, key, value); + if (err2 == ARCHIVE_FATAL) + return (err2); + err = err_combine(err, err2); + + /* Skip to next line */ + attr += line_length; + attr_length -= line_length; + } + + /* + * PAX format uses UTF-8 as default charset for its metadata + * unless hdrcharset=BINARY is present in its header. + * We apply the charset specified by the hdrcharset option only + * when the hdrcharset attribute(in PAX header) is BINARY because + * we respect the charset described in PAX header and BINARY also + * means that metadata(filename,uname and gname) character-set + * is unknown. + */ + if (tar->pax_hdrcharset_binary) + sconv = tar->opt_sconv; + else { + sconv = archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (sconv == NULL) + return (ARCHIVE_FATAL); + if (tar->compat_2x) + archive_string_conversion_set_opt(sconv, + SCONV_SET_OPT_UTF8_LIBARCHIVE2X); + } + + if (archive_strlen(&(tar->entry_gname)) > 0) { + if (archive_entry_copy_gname_l(entry, tar->entry_gname.s, + archive_strlen(&(tar->entry_gname)), sconv) != 0) { + err = set_conversion_failed_error(a, sconv, "Gname"); + if (err == ARCHIVE_FATAL) + return (err); + /* Use a converted an original name. */ + archive_entry_copy_gname(entry, tar->entry_gname.s); + } + } + if (archive_strlen(&(tar->entry_linkpath)) > 0) { + if (archive_entry_copy_link_l(entry, tar->entry_linkpath.s, + archive_strlen(&(tar->entry_linkpath)), sconv) != 0) { + err = set_conversion_failed_error(a, sconv, "Linkname"); + if (err == ARCHIVE_FATAL) + return (err); + /* Use a converted an original name. */ + archive_entry_copy_link(entry, tar->entry_linkpath.s); + } + } + /* + * Some extensions (such as the GNU sparse file extensions) + * deliberately store a synthetic name under the regular 'path' + * attribute and the real file name under a different attribute. + * Since we're supposed to not care about the order, we + * have no choice but to store all of the various filenames + * we find and figure it all out afterwards. This is the + * figuring out part. + */ + as = NULL; + if (archive_strlen(&(tar->entry_pathname_override)) > 0) + as = &(tar->entry_pathname_override); + else if (archive_strlen(&(tar->entry_pathname)) > 0) + as = &(tar->entry_pathname); + if (as != NULL) { + if (archive_entry_copy_pathname_l(entry, as->s, + archive_strlen(as), sconv) != 0) { + err = set_conversion_failed_error(a, sconv, "Pathname"); + if (err == ARCHIVE_FATAL) + return (err); + /* Use a converted an original name. */ + archive_entry_copy_pathname(entry, as->s); + } + } + if (archive_strlen(&(tar->entry_uname)) > 0) { + if (archive_entry_copy_uname_l(entry, tar->entry_uname.s, + archive_strlen(&(tar->entry_uname)), sconv) != 0) { + err = set_conversion_failed_error(a, sconv, "Uname"); + if (err == ARCHIVE_FATAL) + return (err); + /* Use a converted an original name. */ + archive_entry_copy_uname(entry, tar->entry_uname.s); + } + } + return (err); } static int pax_attribute_xattr(struct archive_entry *entry, - char *name, char *value) + char *name, char *value) { - char *name_decoded; - void *value_decoded; - size_t value_len; + char *name_decoded; + void *value_decoded; + size_t value_len; - if (strlen(name) < 18 || (strncmp(name, "LIBARCHIVE.xattr.", 17)) != 0) - return 3; + if (strlen(name) < 18 || (memcmp(name, "LIBARCHIVE.xattr.", 17)) != 0) + return 3; - name += 17; + name += 17; - /* URL-decode name */ - name_decoded = url_decode(name); - if (name_decoded == NULL) - return 2; + /* URL-decode name */ + name_decoded = url_decode(name); + if (name_decoded == NULL) + return 2; - /* Base-64 decode value */ - value_decoded = base64_decode(value, strlen(value), &value_len); - if (value_decoded == NULL) { - free(name_decoded); - return 1; - } + /* Base-64 decode value */ + value_decoded = base64_decode(value, strlen(value), &value_len); + if (value_decoded == NULL) { + free(name_decoded); + return 1; + } - archive_entry_xattr_add_entry(entry, name_decoded, - value_decoded, value_len); + archive_entry_xattr_add_entry(entry, name_decoded, + value_decoded, value_len); - free(name_decoded); - free(value_decoded); - return 0; + free(name_decoded); + free(value_decoded); + return 0; } /* @@ -1399,212 +1654,263 @@ pax_attribute_xattr(struct archive_entry *entry, * any of them look useful. */ static int -pax_attribute(struct tar *tar, struct archive_entry *entry, - char *key, char *value) +pax_attribute(struct archive_read *a, struct tar *tar, + struct archive_entry *entry, char *key, char *value) { - int64_t s; - long n; - wchar_t *wp; - - switch (key[0]) { - case 'G': - /* GNU "0.0" sparse pax format. */ - if (strcmp(key, "GNU.sparse.numblocks") == 0) { - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - tar->sparse_gnu_major = 0; - tar->sparse_gnu_minor = 0; - } - if (strcmp(key, "GNU.sparse.offset") == 0) { - tar->sparse_offset = tar_atol10(value, strlen(value)); - if (tar->sparse_numbytes != -1) { - gnu_add_sparse_entry(tar, - tar->sparse_offset, tar->sparse_numbytes); - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - } - } - if (strcmp(key, "GNU.sparse.numbytes") == 0) { - tar->sparse_numbytes = tar_atol10(value, strlen(value)); - if (tar->sparse_numbytes != -1) { - gnu_add_sparse_entry(tar, - tar->sparse_offset, tar->sparse_numbytes); - tar->sparse_offset = -1; - tar->sparse_numbytes = -1; - } - } - if (strcmp(key, "GNU.sparse.size") == 0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - - /* GNU "0.1" sparse pax format. */ - if (strcmp(key, "GNU.sparse.map") == 0) { - tar->sparse_gnu_major = 0; - tar->sparse_gnu_minor = 1; - if (gnu_sparse_01_parse(tar, value) != ARCHIVE_OK) - return (ARCHIVE_WARN); - } - - /* GNU "1.0" sparse pax format */ - if (strcmp(key, "GNU.sparse.major") == 0) { - tar->sparse_gnu_major = tar_atol10(value, strlen(value)); - tar->sparse_gnu_pending = 1; - } - if (strcmp(key, "GNU.sparse.minor") == 0) { - tar->sparse_gnu_minor = tar_atol10(value, strlen(value)); - tar->sparse_gnu_pending = 1; - } - if (strcmp(key, "GNU.sparse.name") == 0) { - /* - * The real filename; when storing sparse - * files, GNU tar puts a synthesized name into - * the regular 'path' attribute in an attempt - * to limit confusion. ;-) - */ - archive_strcpy(&(tar->entry_pathname_override), value); - } - if (strcmp(key, "GNU.sparse.realsize") == 0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - break; - case 'L': - /* Our extensions */ + int64_t s; + long n; + int err = ARCHIVE_OK, r; + + switch (key[0]) { + case 'G': + /* GNU "0.0" sparse pax format. */ + if (strcmp(key, "GNU.sparse.numblocks") == 0) { + tar->sparse_offset = -1; + tar->sparse_numbytes = -1; + tar->sparse_gnu_major = 0; + tar->sparse_gnu_minor = 0; + } + if (strcmp(key, "GNU.sparse.offset") == 0) { + tar->sparse_offset = tar_atol10(value, strlen(value)); + if (tar->sparse_numbytes != -1) { + if (gnu_add_sparse_entry(a, tar, + tar->sparse_offset, tar->sparse_numbytes) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + tar->sparse_offset = -1; + tar->sparse_numbytes = -1; + } + } + if (strcmp(key, "GNU.sparse.numbytes") == 0) { + tar->sparse_numbytes = tar_atol10(value, strlen(value)); + if (tar->sparse_numbytes != -1) { + if (gnu_add_sparse_entry(a, tar, + tar->sparse_offset, tar->sparse_numbytes) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + tar->sparse_offset = -1; + tar->sparse_numbytes = -1; + } + } + if (strcmp(key, "GNU.sparse.size") == 0) { + tar->realsize = tar_atol10(value, strlen(value)); + archive_entry_set_size(entry, tar->realsize); + } + + /* GNU "0.1" sparse pax format. */ + if (strcmp(key, "GNU.sparse.map") == 0) { + tar->sparse_gnu_major = 0; + tar->sparse_gnu_minor = 1; + if (gnu_sparse_01_parse(a, tar, value) != ARCHIVE_OK) + return (ARCHIVE_WARN); + } + + /* GNU "1.0" sparse pax format */ + if (strcmp(key, "GNU.sparse.major") == 0) { + tar->sparse_gnu_major = tar_atol10(value, strlen(value)); + tar->sparse_gnu_pending = 1; + } + if (strcmp(key, "GNU.sparse.minor") == 0) { + tar->sparse_gnu_minor = tar_atol10(value, strlen(value)); + tar->sparse_gnu_pending = 1; + } + if (strcmp(key, "GNU.sparse.name") == 0) { + /* + * The real filename; when storing sparse + * files, GNU tar puts a synthesized name into + * the regular 'path' attribute in an attempt + * to limit confusion. ;-) + */ + archive_strcpy(&(tar->entry_pathname_override), value); + } + if (strcmp(key, "GNU.sparse.realsize") == 0) { + tar->realsize = tar_atol10(value, strlen(value)); + archive_entry_set_size(entry, tar->realsize); + } + break; + case 'L': + /* Our extensions */ /* TODO: Handle arbitrary extended attributes... */ /* - if (strcmp(key, "LIBARCHIVE.xxxxxxx")==0) - archive_entry_set_xxxxxx(entry, value); + if (strcmp(key, "LIBARCHIVE.xxxxxxx") == 0) + archive_entry_set_xxxxxx(entry, value); */ - if (strcmp(key, "LIBARCHIVE.creationtime")==0) { - pax_time(value, &s, &n); - archive_entry_set_birthtime(entry, s, n); - } - if (strncmp(key, "LIBARCHIVE.xattr.", 17)==0) - pax_attribute_xattr(entry, key, value); - break; - case 'S': - /* We support some keys used by the "star" archiver */ - if (strcmp(key, "SCHILY.acl.access")==0) { - wp = utf8_decode(tar, value, strlen(value)); - /* TODO: if (wp == NULL) */ - __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - } else if (strcmp(key, "SCHILY.acl.default")==0) { - wp = utf8_decode(tar, value, strlen(value)); - /* TODO: if (wp == NULL) */ - __archive_entry_acl_parse_w(entry, wp, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT); - } else if (strcmp(key, "SCHILY.devmajor")==0) { - archive_entry_set_rdevmajor(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.devminor")==0) { - archive_entry_set_rdevminor(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.fflags")==0) { - archive_entry_copy_fflags_text(entry, value); - } else if (strcmp(key, "SCHILY.dev")==0) { - archive_entry_set_dev(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.ino")==0) { - archive_entry_set_ino(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.nlink")==0) { - archive_entry_set_nlink(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "SCHILY.realsize")==0) { - tar->realsize = tar_atol10(value, strlen(value)); - archive_entry_set_size(entry, tar->realsize); - } - break; - case 'a': - if (strcmp(key, "atime")==0) { - pax_time(value, &s, &n); - archive_entry_set_atime(entry, s, n); - } - break; - case 'c': - if (strcmp(key, "ctime")==0) { - pax_time(value, &s, &n); - archive_entry_set_ctime(entry, s, n); - } else if (strcmp(key, "charset")==0) { - /* TODO: Publish charset information in entry. */ - } else if (strcmp(key, "comment")==0) { - /* TODO: Publish comment in entry. */ - } - break; - case 'g': - if (strcmp(key, "gid")==0) { - archive_entry_set_gid(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "gname")==0) { - archive_strcpy(&(tar->entry_gname), value); - } - break; - case 'h': - if (strcmp(key, "hdrcharset") == 0) { - if (strcmp(value, "BINARY") == 0) - tar->pax_hdrcharset_binary = 1; - else if (strcmp(value, "ISO-IR 10646 2000 UTF-8") == 0) - tar->pax_hdrcharset_binary = 0; - else { - /* TODO: Warn about unsupported hdrcharset */ - } - } - break; - case 'l': - /* pax interchange doesn't distinguish hardlink vs. symlink. */ - if (strcmp(key, "linkpath")==0) { - archive_strcpy(&(tar->entry_linkpath), value); - } - break; - case 'm': - if (strcmp(key, "mtime")==0) { - pax_time(value, &s, &n); - archive_entry_set_mtime(entry, s, n); - } - break; - case 'p': - if (strcmp(key, "path")==0) { - archive_strcpy(&(tar->entry_pathname), value); - } - break; - case 'r': - /* POSIX has reserved 'realtime.*' */ - break; - case 's': - /* POSIX has reserved 'security.*' */ - /* Someday: if (strcmp(key, "security.acl")==0) { ... } */ - if (strcmp(key, "size")==0) { - /* "size" is the size of the data in the entry. */ - tar->entry_bytes_remaining - = tar_atol10(value, strlen(value)); - /* - * But, "size" is not necessarily the size of - * the file on disk; if this is a sparse file, - * the disk size may have already been set from - * GNU.sparse.realsize or GNU.sparse.size or - * an old GNU header field or SCHILY.realsize - * or .... - */ - if (tar->realsize < 0) { - archive_entry_set_size(entry, - tar->entry_bytes_remaining); - tar->realsize - = tar->entry_bytes_remaining; - } - } - break; - case 'u': - if (strcmp(key, "uid")==0) { - archive_entry_set_uid(entry, - tar_atol10(value, strlen(value))); - } else if (strcmp(key, "uname")==0) { - archive_strcpy(&(tar->entry_uname), value); - } - break; - } - return (0); + if (strcmp(key, "LIBARCHIVE.creationtime") == 0) { + pax_time(value, &s, &n); + archive_entry_set_birthtime(entry, s, n); + } + if (memcmp(key, "LIBARCHIVE.xattr.", 17) == 0) + pax_attribute_xattr(entry, key, value); + break; + case 'S': + /* We support some keys used by the "star" archiver */ + if (strcmp(key, "SCHILY.acl.access") == 0) { + if (tar->sconv_acl == NULL) { + tar->sconv_acl = + archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (tar->sconv_acl == NULL) + return (ARCHIVE_FATAL); + } + + r = archive_acl_parse_l(archive_entry_acl(entry), + value, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, + tar->sconv_acl); + if (r != ARCHIVE_OK) { + err = r; + if (err == ARCHIVE_FATAL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for " + "SCHILY.acl.access"); + return (err); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Parse error: SCHILY.acl.access"); + } + } else if (strcmp(key, "SCHILY.acl.default") == 0) { + if (tar->sconv_acl == NULL) { + tar->sconv_acl = + archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (tar->sconv_acl == NULL) + return (ARCHIVE_FATAL); + } + + r = archive_acl_parse_l(archive_entry_acl(entry), + value, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, + tar->sconv_acl); + if (r != ARCHIVE_OK) { + err = r; + if (err == ARCHIVE_FATAL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for " + "SCHILY.acl.default"); + return (err); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Parse error: SCHILY.acl.default"); + } + } else if (strcmp(key, "SCHILY.devmajor") == 0) { + archive_entry_set_rdevmajor(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "SCHILY.devminor") == 0) { + archive_entry_set_rdevminor(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "SCHILY.fflags") == 0) { + archive_entry_copy_fflags_text(entry, value); + } else if (strcmp(key, "SCHILY.dev") == 0) { + archive_entry_set_dev(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "SCHILY.ino") == 0) { + archive_entry_set_ino(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "SCHILY.nlink") == 0) { + archive_entry_set_nlink(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "SCHILY.realsize") == 0) { + tar->realsize = tar_atol10(value, strlen(value)); + archive_entry_set_size(entry, tar->realsize); + } else if (strcmp(key, "SUN.holesdata") == 0) { + /* A Solaris extension for sparse. */ + r = solaris_sparse_parse(a, tar, entry, value); + if (r < err) { + if (r == ARCHIVE_FATAL) + return (r); + err = r; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Parse error: SUN.holesdata"); + } + } + break; + case 'a': + if (strcmp(key, "atime") == 0) { + pax_time(value, &s, &n); + archive_entry_set_atime(entry, s, n); + } + break; + case 'c': + if (strcmp(key, "ctime") == 0) { + pax_time(value, &s, &n); + archive_entry_set_ctime(entry, s, n); + } else if (strcmp(key, "charset") == 0) { + /* TODO: Publish charset information in entry. */ + } else if (strcmp(key, "comment") == 0) { + /* TODO: Publish comment in entry. */ + } + break; + case 'g': + if (strcmp(key, "gid") == 0) { + archive_entry_set_gid(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "gname") == 0) { + archive_strcpy(&(tar->entry_gname), value); + } + break; + case 'h': + if (strcmp(key, "hdrcharset") == 0) { + if (strcmp(value, "BINARY") == 0) + /* Binary mode. */ + tar->pax_hdrcharset_binary = 1; + else if (strcmp(value, "ISO-IR 10646 2000 UTF-8") == 0) + tar->pax_hdrcharset_binary = 0; + } + break; + case 'l': + /* pax interchange doesn't distinguish hardlink vs. symlink. */ + if (strcmp(key, "linkpath") == 0) { + archive_strcpy(&(tar->entry_linkpath), value); + } + break; + case 'm': + if (strcmp(key, "mtime") == 0) { + pax_time(value, &s, &n); + archive_entry_set_mtime(entry, s, n); + } + break; + case 'p': + if (strcmp(key, "path") == 0) { + archive_strcpy(&(tar->entry_pathname), value); + } + break; + case 'r': + /* POSIX has reserved 'realtime.*' */ + break; + case 's': + /* POSIX has reserved 'security.*' */ + /* Someday: if (strcmp(key, "security.acl") == 0) { ... } */ + if (strcmp(key, "size") == 0) { + /* "size" is the size of the data in the entry. */ + tar->entry_bytes_remaining + = tar_atol10(value, strlen(value)); + /* + * But, "size" is not necessarily the size of + * the file on disk; if this is a sparse file, + * the disk size may have already been set from + * GNU.sparse.realsize or GNU.sparse.size or + * an old GNU header field or SCHILY.realsize + * or .... + */ + if (tar->realsize < 0) { + archive_entry_set_size(entry, + tar->entry_bytes_remaining); + tar->realsize + = tar->entry_bytes_remaining; + } + } + break; + case 'u': + if (strcmp(key, "uid") == 0) { + archive_entry_set_uid(entry, + tar_atol10(value, strlen(value))); + } else if (strcmp(key, "uname") == 0) { + archive_strcpy(&(tar->entry_uname), value); + } + break; + } + return (err); } @@ -1615,48 +1921,48 @@ pax_attribute(struct tar *tar, struct archive_entry *entry, static void pax_time(const char *p, int64_t *ps, long *pn) { - char digit; - int64_t s; - unsigned long l; - int sign; - int64_t limit, last_digit_limit; - - limit = INT64_MAX / 10; - last_digit_limit = INT64_MAX % 10; - - s = 0; - sign = 1; - if (*p == '-') { - sign = -1; - p++; - } - while (*p >= '0' && *p <= '9') { - digit = *p - '0'; - if (s > limit || - (s == limit && digit > last_digit_limit)) { - s = INT64_MAX; - break; - } - s = (s * 10) + digit; - ++p; - } - - *ps = s * sign; - - /* Calculate nanoseconds. */ - *pn = 0; - - if (*p != '.') - return; - - l = 100000000UL; - do { - ++p; - if (*p >= '0' && *p <= '9') - *pn += (*p - '0') * l; - else - break; - } while (l /= 10); + char digit; + int64_t s; + unsigned long l; + int sign; + int64_t limit, last_digit_limit; + + limit = INT64_MAX / 10; + last_digit_limit = INT64_MAX % 10; + + s = 0; + sign = 1; + if (*p == '-') { + sign = -1; + p++; + } + while (*p >= '0' && *p <= '9') { + digit = *p - '0'; + if (s > limit || + (s == limit && digit > last_digit_limit)) { + s = INT64_MAX; + break; + } + s = (s * 10) + digit; + ++p; + } + + *ps = s * sign; + + /* Calculate nanoseconds. */ + *pn = 0; + + if (*p != '.') + return; + + l = 100000000UL; + do { + ++p; + if (*p >= '0' && *p <= '9') + *pn += (*p - '0') * l; + else + break; + } while (l /= 10); } /* @@ -1664,101 +1970,121 @@ pax_time(const char *p, int64_t *ps, long *pn) */ static int header_gnutar(struct archive_read *a, struct tar *tar, - struct archive_entry *entry, const void *h) + struct archive_entry *entry, const void *h, size_t *unconsumed) { - const struct archive_entry_header_gnutar *header; - - (void)a; - - /* - * GNU header is like POSIX ustar, except 'prefix' is - * replaced with some other fields. This also means the - * filename is stored as in old-style archives. - */ - - /* Grab fields common to all tar variants. */ - header_common(a, tar, entry, h); - - /* Copy filename over (to ensure null termination). */ - header = (const struct archive_entry_header_gnutar *)h; - archive_strncpy(&(tar->entry_pathname), header->name, - sizeof(header->name)); - archive_entry_copy_pathname(entry, tar->entry_pathname.s); - - /* Fields common to ustar and GNU */ - /* XXX Can the following be factored out since it's common - * to ustar and gnu tar? Is it okay to move it down into - * header_common, perhaps? */ - archive_strncpy(&(tar->entry_uname), - header->uname, sizeof(header->uname)); - archive_entry_copy_uname(entry, tar->entry_uname.s); - - archive_strncpy(&(tar->entry_gname), - header->gname, sizeof(header->gname)); - archive_entry_copy_gname(entry, tar->entry_gname.s); - - /* Parse out device numbers only for char and block specials */ - if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { - archive_entry_set_rdevmajor(entry, - tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); - archive_entry_set_rdevminor(entry, - tar_atol(header->rdevminor, sizeof(header->rdevminor))); - } else - archive_entry_set_rdev(entry, 0); - - tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - - /* Grab GNU-specific fields. */ - archive_entry_set_atime(entry, - tar_atol(header->atime, sizeof(header->atime)), 0); - archive_entry_set_ctime(entry, - tar_atol(header->ctime, sizeof(header->ctime)), 0); - if (header->realsize[0] != 0) { - tar->realsize - = tar_atol(header->realsize, sizeof(header->realsize)); - archive_entry_set_size(entry, tar->realsize); - } - - if (header->sparse[0].offset[0] != 0) { - gnu_sparse_old_read(a, tar, header); - } else { - if (header->isextended[0] != 0) { - /* XXX WTF? XXX */ - } - } - - return (0); + const struct archive_entry_header_gnutar *header; + int64_t t; + int err = ARCHIVE_OK; + + /* + * GNU header is like POSIX ustar, except 'prefix' is + * replaced with some other fields. This also means the + * filename is stored as in old-style archives. + */ + + /* Grab fields common to all tar variants. */ + err = header_common(a, tar, entry, h); + if (err == ARCHIVE_FATAL) + return (err); + + /* Copy filename over (to ensure null termination). */ + header = (const struct archive_entry_header_gnutar *)h; + if (archive_entry_copy_pathname_l(entry, + header->name, sizeof(header->name), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Pathname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + /* Fields common to ustar and GNU */ + /* XXX Can the following be factored out since it's common + * to ustar and gnu tar? Is it okay to move it down into + * header_common, perhaps? */ + if (archive_entry_copy_uname_l(entry, + header->uname, sizeof(header->uname), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Uname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + if (archive_entry_copy_gname_l(entry, + header->gname, sizeof(header->gname), tar->sconv) != 0) { + err = set_conversion_failed_error(a, tar->sconv, "Gname"); + if (err == ARCHIVE_FATAL) + return (err); + } + + /* Parse out device numbers only for char and block specials */ + if (header->typeflag[0] == '3' || header->typeflag[0] == '4') { + archive_entry_set_rdevmajor(entry, + tar_atol(header->rdevmajor, sizeof(header->rdevmajor))); + archive_entry_set_rdevminor(entry, + tar_atol(header->rdevminor, sizeof(header->rdevminor))); + } else + archive_entry_set_rdev(entry, 0); + + tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); + + /* Grab GNU-specific fields. */ + t = tar_atol(header->atime, sizeof(header->atime)); + if (t > 0) + archive_entry_set_atime(entry, t, 0); + t = tar_atol(header->ctime, sizeof(header->ctime)); + if (t > 0) + archive_entry_set_ctime(entry, t, 0); + + if (header->realsize[0] != 0) { + tar->realsize + = tar_atol(header->realsize, sizeof(header->realsize)); + archive_entry_set_size(entry, tar->realsize); + } + + if (header->sparse[0].offset[0] != 0) { + if (gnu_sparse_old_read(a, tar, header, unconsumed) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + if (header->isextended[0] != 0) { + /* XXX WTF? XXX */ + } + } + + return (err); } -static void -gnu_add_sparse_entry(struct tar *tar, off_t offset, off_t remaining) +static int +gnu_add_sparse_entry(struct archive_read *a, struct tar *tar, + int64_t offset, int64_t remaining) { - struct sparse_block *p; - - p = (struct sparse_block *)malloc(sizeof(*p)); - if (p == NULL) - __archive_errx(1, "Out of memory"); - memset(p, 0, sizeof(*p)); - if (tar->sparse_last != NULL) - tar->sparse_last->next = p; - else - tar->sparse_list = p; - tar->sparse_last = p; - p->offset = offset; - p->remaining = remaining; + struct sparse_block *p; + + p = (struct sparse_block *)malloc(sizeof(*p)); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + memset(p, 0, sizeof(*p)); + if (tar->sparse_last != NULL) + tar->sparse_last->next = p; + else + tar->sparse_list = p; + tar->sparse_last = p; + p->offset = offset; + p->remaining = remaining; + return (ARCHIVE_OK); } static void gnu_clear_sparse_list(struct tar *tar) { - struct sparse_block *p; - - while (tar->sparse_list != NULL) { - p = tar->sparse_list; - tar->sparse_list = p->next; - free(p); - } - tar->sparse_last = NULL; + struct sparse_block *p; + + while (tar->sparse_list != NULL) { + p = tar->sparse_list; + tar->sparse_list = p->next; + free(p); + } + tar->sparse_last = NULL; } /* @@ -1775,51 +2101,57 @@ gnu_clear_sparse_list(struct tar *tar) static int gnu_sparse_old_read(struct archive_read *a, struct tar *tar, - const struct archive_entry_header_gnutar *header) + const struct archive_entry_header_gnutar *header, size_t *unconsumed) { - ssize_t bytes_read; - const void *data; - struct extended { - struct gnu_sparse sparse[21]; - char isextended[1]; - char padding[7]; - }; - const struct extended *ext; - - gnu_sparse_old_parse(tar, header->sparse, 4); - if (header->isextended[0] == 0) - return (ARCHIVE_OK); - - do { - data = __archive_read_ahead(a, 512, &bytes_read); - if (bytes_read < 0) - return (ARCHIVE_FATAL); - if (bytes_read < 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated tar archive " - "detected while reading sparse file data"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, 512); - ext = (const struct extended *)data; - gnu_sparse_old_parse(tar, ext->sparse, 21); - } while (ext->isextended[0] != 0); - if (tar->sparse_list != NULL) - tar->entry_offset = tar->sparse_list->offset; - return (ARCHIVE_OK); + ssize_t bytes_read; + const void *data; + struct extended { + struct gnu_sparse sparse[21]; + char isextended[1]; + char padding[7]; + }; + const struct extended *ext; + + if (gnu_sparse_old_parse(a, tar, header->sparse, 4) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (header->isextended[0] == 0) + return (ARCHIVE_OK); + + do { + tar_flush_unconsumed(a, unconsumed); + data = __archive_read_ahead(a, 512, &bytes_read); + if (bytes_read < 0) + return (ARCHIVE_FATAL); + if (bytes_read < 512) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated tar archive " + "detected while reading sparse file data"); + return (ARCHIVE_FATAL); + } + *unconsumed = 512; + ext = (const struct extended *)data; + if (gnu_sparse_old_parse(a, tar, ext->sparse, 21) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } while (ext->isextended[0] != 0); + if (tar->sparse_list != NULL) + tar->entry_offset = tar->sparse_list->offset; + return (ARCHIVE_OK); } -static void -gnu_sparse_old_parse(struct tar *tar, +static int +gnu_sparse_old_parse(struct archive_read *a, struct tar *tar, const struct gnu_sparse *sparse, int length) { - while (length > 0 && sparse->offset[0] != 0) { - gnu_add_sparse_entry(tar, - tar_atol(sparse->offset, sizeof(sparse->offset)), - tar_atol(sparse->numbytes, sizeof(sparse->numbytes))); - sparse++; - length--; - } + while (length > 0 && sparse->offset[0] != 0) { + if (gnu_add_sparse_entry(a, tar, + tar_atol(sparse->offset, sizeof(sparse->offset)), + tar_atol(sparse->numbytes, sizeof(sparse->numbytes))) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + sparse++; + length--; + } + return (ARCHIVE_OK); } /* @@ -1828,7 +2160,7 @@ gnu_sparse_old_parse(struct tar *tar, * Beginning with GNU tar 1.15, sparse files are stored using * information in the pax extended header. The GNU tar maintainers * have gone through a number of variations in the process of working - * out this scheme; furtunately, they're all numbered. + * out this scheme; fortunately, they're all numbered. * * Sparse format 0.0 uses attribute GNU.sparse.numblocks to store the * number of blocks, and GNU.sparse.offset/GNU.sparse.numbytes to @@ -1849,33 +2181,35 @@ gnu_sparse_old_parse(struct tar *tar, */ static int -gnu_sparse_01_parse(struct tar *tar, const char *p) +gnu_sparse_01_parse(struct archive_read *a, struct tar *tar, const char *p) { - const char *e; - off_t offset = -1, size = -1; - - for (;;) { - e = p; - while (*e != '\0' && *e != ',') { - if (*e < '0' || *e > '9') - return (ARCHIVE_WARN); - e++; - } - if (offset < 0) { - offset = tar_atol10(p, e - p); - if (offset < 0) - return (ARCHIVE_WARN); - } else { - size = tar_atol10(p, e - p); - if (size < 0) - return (ARCHIVE_WARN); - gnu_add_sparse_entry(tar, offset, size); - offset = -1; - } - if (*e == '\0') - return (ARCHIVE_OK); - p = e + 1; - } + const char *e; + int64_t offset = -1, size = -1; + + for (;;) { + e = p; + while (*e != '\0' && *e != ',') { + if (*e < '0' || *e > '9') + return (ARCHIVE_WARN); + e++; + } + if (offset < 0) { + offset = tar_atol10(p, e - p); + if (offset < 0) + return (ARCHIVE_WARN); + } else { + size = tar_atol10(p, e - p); + if (size < 0) + return (ARCHIVE_WARN); + if (gnu_add_sparse_entry(a, tar, offset, size) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + offset = -1; + } + if (*e == '\0') + return (ARCHIVE_OK); + p = e + 1; + } } /* @@ -1903,44 +2237,44 @@ gnu_sparse_01_parse(struct tar *tar, const char *p) */ static int64_t gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, - ssize_t *remaining) + int64_t *remaining, size_t *unconsumed) { - int64_t l, limit, last_digit_limit; - const char *p; - ssize_t bytes_read; - int base, digit; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - /* - * Skip any lines starting with '#'; GNU tar specs - * don't require this, but they should. - */ - do { - bytes_read = readline(a, tar, &p, tar_min(*remaining, 100)); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - *remaining -= bytes_read; - } while (p[0] == '#'); - - l = 0; - while (bytes_read > 0) { - if (*p == '\n') - return (l); - if (*p < '0' || *p >= '0' + base) - return (ARCHIVE_WARN); - digit = *p - '0'; - if (l > limit || (l == limit && digit > last_digit_limit)) - l = INT64_MAX; /* Truncate on overflow. */ - else - l = (l * base) + digit; - p++; - bytes_read--; - } - /* TODO: Error message. */ - return (ARCHIVE_WARN); + int64_t l, limit, last_digit_limit; + const char *p; + ssize_t bytes_read; + int base, digit; + + base = 10; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + + /* + * Skip any lines starting with '#'; GNU tar specs + * don't require this, but they should. + */ + do { + bytes_read = readline(a, tar, &p, tar_min(*remaining, 100), unconsumed); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + *remaining -= bytes_read; + } while (p[0] == '#'); + + l = 0; + while (bytes_read > 0) { + if (*p == '\n') + return (l); + if (*p < '0' || *p >= '0' + base) + return (ARCHIVE_WARN); + digit = *p - '0'; + if (l > limit || (l == limit && digit > last_digit_limit)) + l = INT64_MAX; /* Truncate on overflow. */ + else + l = (l * base) + digit; + p++; + bytes_read--; + } + /* TODO: Error message. */ + return (ARCHIVE_WARN); } /* @@ -1948,39 +2282,84 @@ gnu_sparse_10_atol(struct archive_read *a, struct tar *tar, * that was read. */ static ssize_t -gnu_sparse_10_read(struct archive_read *a, struct tar *tar) +gnu_sparse_10_read(struct archive_read *a, struct tar *tar, size_t *unconsumed) +{ + ssize_t bytes_read; + int entries; + int64_t offset, size, to_skip, remaining; + + /* Clear out the existing sparse list. */ + gnu_clear_sparse_list(tar); + + remaining = tar->entry_bytes_remaining; + + /* Parse entries. */ + entries = gnu_sparse_10_atol(a, tar, &remaining, unconsumed); + if (entries < 0) + return (ARCHIVE_FATAL); + /* Parse the individual entries. */ + while (entries-- > 0) { + /* Parse offset/size */ + offset = gnu_sparse_10_atol(a, tar, &remaining, unconsumed); + if (offset < 0) + return (ARCHIVE_FATAL); + size = gnu_sparse_10_atol(a, tar, &remaining, unconsumed); + if (size < 0) + return (ARCHIVE_FATAL); + /* Add a new sparse entry. */ + if (gnu_add_sparse_entry(a, tar, offset, size) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + /* Skip rest of block... */ + tar_flush_unconsumed(a, unconsumed); + bytes_read = tar->entry_bytes_remaining - remaining; + to_skip = 0x1ff & -bytes_read; + if (to_skip != __archive_read_consume(a, to_skip)) + return (ARCHIVE_FATAL); + return (bytes_read + to_skip); +} + +/* + * Solaris pax extension for a sparse file. This is recorded with the + * data and hole pairs. The way recording sparse infomation by Solaris' + * pax simply indicates where data and sparse are, so the stored contents + * consist of both data and hole. + */ +static int +solaris_sparse_parse(struct archive_read *a, struct tar *tar, + struct archive_entry *entry, const char *p) { - ssize_t remaining, bytes_read; - int entries; - off_t offset, size, to_skip; - - /* Clear out the existing sparse list. */ - gnu_clear_sparse_list(tar); - - remaining = tar->entry_bytes_remaining; - - /* Parse entries. */ - entries = gnu_sparse_10_atol(a, tar, &remaining); - if (entries < 0) - return (ARCHIVE_FATAL); - /* Parse the individual entries. */ - while (entries-- > 0) { - /* Parse offset/size */ - offset = gnu_sparse_10_atol(a, tar, &remaining); - if (offset < 0) - return (ARCHIVE_FATAL); - size = gnu_sparse_10_atol(a, tar, &remaining); - if (size < 0) - return (ARCHIVE_FATAL); - /* Add a new sparse entry. */ - gnu_add_sparse_entry(tar, offset, size); - } - /* Skip rest of block... */ - bytes_read = tar->entry_bytes_remaining - remaining; - to_skip = 0x1ff & -bytes_read; - if (to_skip != __archive_read_skip(a, to_skip)) - return (ARCHIVE_FATAL); - return (bytes_read + to_skip); + const char *e; + int64_t start, end; + int hole = 1; + + end = 0; + if (*p == ' ') + p++; + else + return (ARCHIVE_WARN); + for (;;) { + e = p; + while (*e != '\0' && *e != ' ') { + if (*e < '0' || *e > '9') + return (ARCHIVE_WARN); + e++; + } + start = end; + end = tar_atol10(p, e - p); + if (end < 0) + return (ARCHIVE_WARN); + if (start < end) { + if (gnu_add_sparse_entry(a, tar, start, + end - start) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + tar->sparse_last->hole = hole; + } + if (*e == '\0') + return (ARCHIVE_OK); + p = e + 1; + hole = hole == 0; + } } /*- @@ -2003,13 +2382,13 @@ gnu_sparse_10_read(struct archive_read *a, struct tar *tar) static int64_t tar_atol(const char *p, unsigned char_cnt) { - /* - * Technically, GNU tar considers a field to be in base-256 - * only if the first byte is 0xff or 0x80. - */ - if (*p & 0x80) - return (tar_atol256(p, char_cnt)); - return (tar_atol8(p, char_cnt)); + /* + * Technically, GNU tar considers a field to be in base-256 + * only if the first byte is 0xff or 0x80. + */ + if (*p & 0x80) + return (tar_atol256(p, char_cnt)); + return (tar_atol8(p, char_cnt)); } /* @@ -2020,32 +2399,32 @@ tar_atol(const char *p, unsigned char_cnt) static int64_t tar_atol8(const char *p, unsigned char_cnt) { - int64_t l, limit, last_digit_limit; - int digit, sign, base; - - base = 8; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l>limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; + int64_t l, limit, last_digit_limit; + int digit, sign, base; + + base = 8; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + + while (*p == ' ' || *p == '\t') + p++; + if (*p == '-') { + sign = -1; + p++; + } else + sign = 1; + + l = 0; + digit = *p - '0'; + while (digit >= 0 && digit < base && char_cnt-- > 0) { + if (l>limit || (l == limit && digit > last_digit_limit)) { + l = INT64_MAX; /* Truncate on overflow. */ + break; + } + l = (l * base) + digit; + digit = *++p - '0'; + } + return (sign < 0) ? -l : l; } /* @@ -2056,32 +2435,32 @@ tar_atol8(const char *p, unsigned char_cnt) static int64_t tar_atol10(const char *p, unsigned char_cnt) { - int64_t l, limit, last_digit_limit; - int base, digit, sign; - - base = 10; - limit = INT64_MAX / base; - last_digit_limit = INT64_MAX % base; - - while (*p == ' ' || *p == '\t') - p++; - if (*p == '-') { - sign = -1; - p++; - } else - sign = 1; - - l = 0; - digit = *p - '0'; - while (digit >= 0 && digit < base && char_cnt-- > 0) { - if (l > limit || (l == limit && digit > last_digit_limit)) { - l = INT64_MAX; /* Truncate on overflow. */ - break; - } - l = (l * base) + digit; - digit = *++p - '0'; - } - return (sign < 0) ? -l : l; + int64_t l, limit, last_digit_limit; + int base, digit, sign; + + base = 10; + limit = INT64_MAX / base; + last_digit_limit = INT64_MAX % base; + + while (*p == ' ' || *p == '\t') + p++; + if (*p == '-') { + sign = -1; + p++; + } else + sign = 1; + + l = 0; + digit = *p - '0'; + while (digit >= 0 && digit < base && char_cnt-- > 0) { + if (l > limit || (l == limit && digit > last_digit_limit)) { + l = INT64_MAX; /* Truncate on overflow. */ + break; + } + l = (l * base) + digit; + digit = *++p - '0'; + } + return (sign < 0) ? -l : l; } /* @@ -2092,29 +2471,29 @@ tar_atol10(const char *p, unsigned char_cnt) static int64_t tar_atol256(const char *_p, unsigned char_cnt) { - int64_t l, upper_limit, lower_limit; - const unsigned char *p = (const unsigned char *)_p; - - upper_limit = INT64_MAX / 256; - lower_limit = INT64_MIN / 256; - - /* Pad with 1 or 0 bits, depending on sign. */ - if ((0x40 & *p) == 0x40) - l = (int64_t)-1; - else - l = 0; - l = (l << 6) | (0x3f & *p++); - while (--char_cnt > 0) { - if (l > upper_limit) { - l = INT64_MAX; /* Truncate on overflow */ - break; - } else if (l < lower_limit) { - l = INT64_MIN; - break; - } - l = (l << 8) | (0xff & (int64_t)*p++); - } - return (l); + int64_t l, upper_limit, lower_limit; + const unsigned char *p = (const unsigned char *)_p; + + upper_limit = INT64_MAX / 256; + lower_limit = INT64_MIN / 256; + + /* Pad with 1 or 0 bits, depending on sign. */ + if ((0x40 & *p) == 0x40) + l = (int64_t)-1; + else + l = 0; + l = (l << 6) | (0x3f & *p++); + while (--char_cnt > 0) { + if (l > upper_limit) { + l = INT64_MAX; /* Truncate on overflow */ + break; + } else if (l < lower_limit) { + l = INT64_MIN; + break; + } + l = (l << 8) | (0xff & (int64_t)*p++); + } + return (l); } /* @@ -2125,179 +2504,70 @@ tar_atol256(const char *_p, unsigned char_cnt) */ static ssize_t readline(struct archive_read *a, struct tar *tar, const char **start, - ssize_t limit) + ssize_t limit, size_t *unconsumed) { - ssize_t bytes_read; - ssize_t total_size = 0; - const void *t; - const char *s; - void *p; - - t = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n' in the read buffer, return pointer to that. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - if (bytes_read > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - __archive_read_consume(a, bytes_read); - *start = s; - return (bytes_read); - } - /* Otherwise, we need to accumulate in a line buffer. */ - for (;;) { - if (total_size + bytes_read > limit) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Line too long"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate working buffer"); - return (ARCHIVE_FATAL); - } - memcpy(tar->line.s + total_size, t, bytes_read); - __archive_read_consume(a, bytes_read); - total_size += bytes_read; - /* If we found '\n', clean up and return. */ - if (p != NULL) { - *start = tar->line.s; - return (total_size); - } - /* Read some more. */ - t = __archive_read_ahead(a, 1, &bytes_read); - if (bytes_read <= 0) - return (ARCHIVE_FATAL); - s = t; /* Start of line? */ - p = memchr(t, '\n', bytes_read); - /* If we found '\n', trim the read. */ - if (p != NULL) { - bytes_read = 1 + ((const char *)p) - s; - } - } + ssize_t bytes_read; + ssize_t total_size = 0; + const void *t; + const char *s; + void *p; + + tar_flush_unconsumed(a, unconsumed); + + t = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + s = t; /* Start of line? */ + p = memchr(t, '\n', bytes_read); + /* If we found '\n' in the read buffer, return pointer to that. */ + if (p != NULL) { + bytes_read = 1 + ((const char *)p) - s; + if (bytes_read > limit) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Line too long"); + return (ARCHIVE_FATAL); + } + *unconsumed = bytes_read; + *start = s; + return (bytes_read); + } + *unconsumed = bytes_read; + /* Otherwise, we need to accumulate in a line buffer. */ + for (;;) { + if (total_size + bytes_read > limit) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Line too long"); + return (ARCHIVE_FATAL); + } + if (archive_string_ensure(&tar->line, total_size + bytes_read) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate working buffer"); + return (ARCHIVE_FATAL); + } + memcpy(tar->line.s + total_size, t, bytes_read); + tar_flush_unconsumed(a, unconsumed); + total_size += bytes_read; + /* If we found '\n', clean up and return. */ + if (p != NULL) { + *start = tar->line.s; + return (total_size); + } + /* Read some more. */ + t = __archive_read_ahead(a, 1, &bytes_read); + if (bytes_read <= 0) + return (ARCHIVE_FATAL); + s = t; /* Start of line? */ + p = memchr(t, '\n', bytes_read); + /* If we found '\n', trim the read. */ + if (p != NULL) { + bytes_read = 1 + ((const char *)p) - s; + } + *unconsumed = bytes_read; + } } -static wchar_t * -utf8_decode(struct tar *tar, const char *src, size_t length) -{ - wchar_t *dest; - ssize_t n; - - /* Ensure pax_entry buffer is big enough. */ - if (tar->pax_entry_length <= length) { - wchar_t *old_entry = tar->pax_entry; - - if (tar->pax_entry_length <= 0) - tar->pax_entry_length = 1024; - while (tar->pax_entry_length <= length + 1) - tar->pax_entry_length *= 2; - - old_entry = tar->pax_entry; - tar->pax_entry = (wchar_t *)realloc(tar->pax_entry, - tar->pax_entry_length * sizeof(wchar_t)); - if (tar->pax_entry == NULL) { - free(old_entry); - /* TODO: Handle this error. */ - return (NULL); - } - } - - dest = tar->pax_entry; - while (length > 0) { - n = UTF8_mbrtowc(dest, src, length); - if (n < 0) - return (NULL); - if (n == 0) - break; - dest++; - src += n; - length -= n; - } - *dest++ = L'\0'; - return (tar->pax_entry); -} - -/* - * Copied and simplified from FreeBSD libc/locale. - */ -static ssize_t -UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n) -{ - int ch, i, len, mask; - unsigned long wch; - - if (s == NULL || n == 0 || pwc == NULL) - return (0); - - /* - * Determine the number of octets that make up this character from - * the first octet, and a mask that extracts the interesting bits of - * the first octet. - */ - ch = (unsigned char)*s; - if ((ch & 0x80) == 0) { - mask = 0x7f; - len = 1; - } else if ((ch & 0xe0) == 0xc0) { - mask = 0x1f; - len = 2; - } else if ((ch & 0xf0) == 0xe0) { - mask = 0x0f; - len = 3; - } else if ((ch & 0xf8) == 0xf0) { - mask = 0x07; - len = 4; - } else { - /* Invalid first byte. */ - return (-1); - } - - if (n < (size_t)len) { - /* Valid first byte but truncated. */ - return (-2); - } - - /* - * Decode the octet sequence representing the character in chunks - * of 6 bits, most significant first. - */ - wch = (unsigned char)*s++ & mask; - i = len; - while (--i != 0) { - if ((*s & 0xc0) != 0x80) { - /* Invalid intermediate byte; consume one byte and - * emit '?' */ - *pwc = '?'; - return (1); - } - wch <<= 6; - wch |= *s++ & 0x3f; - } - - /* Assign the value to the output; out-of-range values - * just get truncated. */ - *pwc = (wchar_t)wch; -#ifdef WCHAR_MAX - /* - * If platform has WCHAR_MAX, we can do something - * more sensible with out-of-range values. - */ - if (wch >= WCHAR_MAX) - *pwc = '?'; -#endif - /* Return number of bytes input consumed: 0 for end-of-string. */ - return (wch == L'\0' ? 0 : len); -} - - /* * base64_decode - Base64 decode * @@ -2310,113 +2580,113 @@ UTF8_mbrtowc(wchar_t *pwc, const char *s, size_t n) static char * base64_decode(const char *s, size_t len, size_t *out_len) { - static const unsigned char digits[64] = { - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N', - 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b', - 'c','d','e','f','g','h','i','j','k','l','m','n','o','p', - 'q','r','s','t','u','v','w','x','y','z','0','1','2','3', - '4','5','6','7','8','9','+','/' }; - static unsigned char decode_table[128]; - char *out, *d; - const unsigned char *src = (const unsigned char *)s; - - /* If the decode table is not yet initialized, prepare it. */ - if (decode_table[digits[1]] != 1) { - size_t i; - memset(decode_table, 0xff, sizeof(decode_table)); - for (i = 0; i < sizeof(digits); i++) - decode_table[digits[i]] = i; - } - - /* Allocate enough space to hold the entire output. */ - /* Note that we may not use all of this... */ - out = (char *)malloc(len - len / 4 + 1); - if (out == NULL) { - *out_len = 0; - return (NULL); - } - d = out; - - while (len > 0) { - /* Collect the next group of (up to) four characters. */ - int v = 0; - int group_size = 0; - while (group_size < 4 && len > 0) { - /* '=' or '_' padding indicates final group. */ - if (*src == '=' || *src == '_') { - len = 0; - break; - } - /* Skip illegal characters (including line breaks) */ - if (*src > 127 || *src < 32 - || decode_table[*src] == 0xff) { - len--; - src++; - continue; - } - v <<= 6; - v |= decode_table[*src++]; - len --; - group_size++; - } - /* Align a short group properly. */ - v <<= 6 * (4 - group_size); - /* Unpack the group we just collected. */ - switch (group_size) { - case 4: d[2] = v & 0xff; - /* FALLTHROUGH */ - case 3: d[1] = (v >> 8) & 0xff; - /* FALLTHROUGH */ - case 2: d[0] = (v >> 16) & 0xff; - break; - case 1: /* this is invalid! */ - break; - } - d += group_size * 3 / 4; - } - - *out_len = d - out; - return (out); + static const unsigned char digits[64] = { + 'A','B','C','D','E','F','G','H','I','J','K','L','M','N', + 'O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b', + 'c','d','e','f','g','h','i','j','k','l','m','n','o','p', + 'q','r','s','t','u','v','w','x','y','z','0','1','2','3', + '4','5','6','7','8','9','+','/' }; + static unsigned char decode_table[128]; + char *out, *d; + const unsigned char *src = (const unsigned char *)s; + + /* If the decode table is not yet initialized, prepare it. */ + if (decode_table[digits[1]] != 1) { + unsigned i; + memset(decode_table, 0xff, sizeof(decode_table)); + for (i = 0; i < sizeof(digits); i++) + decode_table[digits[i]] = i; + } + + /* Allocate enough space to hold the entire output. */ + /* Note that we may not use all of this... */ + out = (char *)malloc(len - len / 4 + 1); + if (out == NULL) { + *out_len = 0; + return (NULL); + } + d = out; + + while (len > 0) { + /* Collect the next group of (up to) four characters. */ + int v = 0; + int group_size = 0; + while (group_size < 4 && len > 0) { + /* '=' or '_' padding indicates final group. */ + if (*src == '=' || *src == '_') { + len = 0; + break; + } + /* Skip illegal characters (including line breaks) */ + if (*src > 127 || *src < 32 + || decode_table[*src] == 0xff) { + len--; + src++; + continue; + } + v <<= 6; + v |= decode_table[*src++]; + len --; + group_size++; + } + /* Align a short group properly. */ + v <<= 6 * (4 - group_size); + /* Unpack the group we just collected. */ + switch (group_size) { + case 4: d[2] = v & 0xff; + /* FALLTHROUGH */ + case 3: d[1] = (v >> 8) & 0xff; + /* FALLTHROUGH */ + case 2: d[0] = (v >> 16) & 0xff; + break; + case 1: /* this is invalid! */ + break; + } + d += group_size * 3 / 4; + } + + *out_len = d - out; + return (out); } static char * url_decode(const char *in) { - char *out, *d; - const char *s; - - out = (char *)malloc(strlen(in) + 1); - if (out == NULL) - return (NULL); - for (s = in, d = out; *s != '\0'; ) { - if (s[0] == '%' && s[1] != '\0' && s[2] != '\0') { - /* Try to convert % escape */ - int digit1 = tohex(s[1]); - int digit2 = tohex(s[2]); - if (digit1 >= 0 && digit2 >= 0) { - /* Looks good, consume three chars */ - s += 3; - /* Convert output */ - *d++ = ((digit1 << 4) | digit2); - continue; - } - /* Else fall through and treat '%' as normal char */ - } - *d++ = *s++; - } - *d = '\0'; - return (out); + char *out, *d; + const char *s; + + out = (char *)malloc(strlen(in) + 1); + if (out == NULL) + return (NULL); + for (s = in, d = out; *s != '\0'; ) { + if (s[0] == '%' && s[1] != '\0' && s[2] != '\0') { + /* Try to convert % escape */ + int digit1 = tohex(s[1]); + int digit2 = tohex(s[2]); + if (digit1 >= 0 && digit2 >= 0) { + /* Looks good, consume three chars */ + s += 3; + /* Convert output */ + *d++ = ((digit1 << 4) | digit2); + continue; + } + /* Else fall through and treat '%' as normal char */ + } + *d++ = *s++; + } + *d = '\0'; + return (out); } static int tohex(int c) { - if (c >= '0' && c <= '9') - return (c - '0'); - else if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - else if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); - else - return (-1); + if (c >= '0' && c <= '9') + return (c - '0'); + else if (c >= 'A' && c <= 'F') + return (c - 'A' + 10); + else if (c >= 'a' && c <= 'f') + return (c - 'a' + 10); + else + return (-1); } diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c new file mode 100644 index 000000000..0834e6fc3 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_xar.c @@ -0,0 +1,3324 @@ +/*- + * Copyright (c) 2009 Michihiro NAKAJIMA + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#if HAVE_LIBXML_XMLREADER_H +#include +#elif HAVE_BSDXML_H +#include +#elif HAVE_EXPAT_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#if HAVE_LZMA_H +#include +#elif HAVE_LZMADEC_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_crypto_private.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_read_private.h" + +#if (!defined(HAVE_LIBXML_XMLREADER_H) && \ + !defined(HAVE_BSDXML_H) && !defined(HAVE_EXPAT_H)) ||\ + !defined(HAVE_ZLIB_H) || \ + !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1) +/* + * xar needs several external libraries. + * o libxml2 or expat --- XML parser + * o openssl or MD5/SHA1 hash function + * o zlib + * o bzlib2 (option) + * o liblzma (option) + */ +int +archive_read_support_format_xar(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_xar"); + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Xar not supported on this platform"); + return (ARCHIVE_WARN); +} + +#else /* Support xar format */ + +/* #define DEBUG 1 */ +/* #define DEBUG_PRINT_TOC 1 */ +#if DEBUG_PRINT_TOC +#define PRINT_TOC(d, outbytes) do { \ + unsigned char *x = (unsigned char *)(uintptr_t)d; \ + unsigned char c = x[outbytes-1]; \ + x[outbytes - 1] = 0; \ + fprintf(stderr, "%s", x); \ + fprintf(stderr, "%c", c); \ + x[outbytes - 1] = c; \ +} while (0) +#else +#define PRINT_TOC(d, outbytes) +#endif + +#define HEADER_MAGIC 0x78617221 +#define HEADER_SIZE 28 +#define HEADER_VERSION 1 +#define CKSUM_NONE 0 +#define CKSUM_SHA1 1 +#define CKSUM_MD5 2 + +#define MD5_SIZE 16 +#define SHA1_SIZE 20 +#define MAX_SUM_SIZE 20 + +enum enctype { + NONE, + GZIP, + BZIP2, + LZMA, + XZ, +}; + +struct chksumval { + int alg; + size_t len; + unsigned char val[MAX_SUM_SIZE]; +}; + +struct chksumwork { + int alg; +#ifdef ARCHIVE_HAS_MD5 + archive_md5_ctx md5ctx; +#endif +#ifdef ARCHIVE_HAS_SHA1 + archive_sha1_ctx sha1ctx; +#endif +}; + +struct xattr { + struct xattr *next; + struct archive_string name; + uint64_t id; + uint64_t length; + uint64_t offset; + uint64_t size; + enum enctype encoding; + struct chksumval a_sum; + struct chksumval e_sum; + struct archive_string fstype; +}; + +struct xar_file { + struct xar_file *next; + struct xar_file *hdnext; + struct xar_file *parent; + int subdirs; + + unsigned int has; +#define HAS_DATA 0x00001 +#define HAS_PATHNAME 0x00002 +#define HAS_SYMLINK 0x00004 +#define HAS_TIME 0x00008 +#define HAS_UID 0x00010 +#define HAS_GID 0x00020 +#define HAS_MODE 0x00040 +#define HAS_TYPE 0x00080 +#define HAS_DEV 0x00100 +#define HAS_DEVMAJOR 0x00200 +#define HAS_DEVMINOR 0x00400 +#define HAS_INO 0x00800 +#define HAS_FFLAGS 0x01000 +#define HAS_XATTR 0x02000 +#define HAS_ACL 0x04000 + + uint64_t id; + uint64_t length; + uint64_t offset; + uint64_t size; + enum enctype encoding; + struct chksumval a_sum; + struct chksumval e_sum; + struct archive_string pathname; + struct archive_string symlink; + time_t ctime; + time_t mtime; + time_t atime; + struct archive_string uname; + uid_t uid; + struct archive_string gname; + gid_t gid; + mode_t mode; + dev_t dev; + dev_t devmajor; + dev_t devminor; + int64_t ino64; + struct archive_string fflags_text; + unsigned int link; + unsigned int nlink; + struct archive_string hardlink; + struct xattr *xattr_list; +}; + +struct hdlink { + struct hdlink *next; + + unsigned int id; + int cnt; + struct xar_file *files; +}; + +struct heap_queue { + struct xar_file **files; + int allocated; + int used; +}; + +enum xmlstatus { + INIT, + XAR, + TOC, + TOC_CREATION_TIME, + TOC_CHECKSUM, + TOC_CHECKSUM_OFFSET, + TOC_CHECKSUM_SIZE, + TOC_FILE, + FILE_DATA, + FILE_DATA_LENGTH, + FILE_DATA_OFFSET, + FILE_DATA_SIZE, + FILE_DATA_ENCODING, + FILE_DATA_A_CHECKSUM, + FILE_DATA_E_CHECKSUM, + FILE_DATA_CONTENT, + FILE_EA, + FILE_EA_LENGTH, + FILE_EA_OFFSET, + FILE_EA_SIZE, + FILE_EA_ENCODING, + FILE_EA_A_CHECKSUM, + FILE_EA_E_CHECKSUM, + FILE_EA_NAME, + FILE_EA_FSTYPE, + FILE_CTIME, + FILE_MTIME, + FILE_ATIME, + FILE_GROUP, + FILE_GID, + FILE_USER, + FILE_UID, + FILE_MODE, + FILE_DEVICE, + FILE_DEVICE_MAJOR, + FILE_DEVICE_MINOR, + FILE_DEVICENO, + FILE_INODE, + FILE_LINK, + FILE_TYPE, + FILE_NAME, + FILE_ACL, + FILE_ACL_DEFAULT, + FILE_ACL_ACCESS, + FILE_ACL_APPLEEXTENDED, + /* BSD file flags. */ + FILE_FLAGS, + FILE_FLAGS_USER_NODUMP, + FILE_FLAGS_USER_IMMUTABLE, + FILE_FLAGS_USER_APPEND, + FILE_FLAGS_USER_OPAQUE, + FILE_FLAGS_USER_NOUNLINK, + FILE_FLAGS_SYS_ARCHIVED, + FILE_FLAGS_SYS_IMMUTABLE, + FILE_FLAGS_SYS_APPEND, + FILE_FLAGS_SYS_NOUNLINK, + FILE_FLAGS_SYS_SNAPSHOT, + /* Linux file flags. */ + FILE_EXT2, + FILE_EXT2_SecureDeletion, + FILE_EXT2_Undelete, + FILE_EXT2_Compress, + FILE_EXT2_Synchronous, + FILE_EXT2_Immutable, + FILE_EXT2_AppendOnly, + FILE_EXT2_NoDump, + FILE_EXT2_NoAtime, + FILE_EXT2_CompDirty, + FILE_EXT2_CompBlock, + FILE_EXT2_NoCompBlock, + FILE_EXT2_CompError, + FILE_EXT2_BTree, + FILE_EXT2_HashIndexed, + FILE_EXT2_iMagic, + FILE_EXT2_Journaled, + FILE_EXT2_NoTail, + FILE_EXT2_DirSync, + FILE_EXT2_TopDir, + FILE_EXT2_Reserved, + UNKNOWN, +}; + +struct unknown_tag { + struct unknown_tag *next; + struct archive_string name; +}; + +struct xar { + uint64_t offset; /* Current position in the file. */ + int64_t total; + uint64_t h_base; + int end_of_file; +#define OUTBUFF_SIZE (1024 * 64) + unsigned char *outbuff; + + enum xmlstatus xmlsts; + enum xmlstatus xmlsts_unknown; + struct unknown_tag *unknowntags; + int base64text; + + /* + * TOC + */ + uint64_t toc_remaining; + uint64_t toc_total; + uint64_t toc_chksum_offset; + uint64_t toc_chksum_size; + + /* + * For Decoding data. + */ + enum enctype rd_encoding; + z_stream stream; + int stream_valid; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + bz_stream bzstream; + int bzstream_valid; +#endif +#if HAVE_LZMA_H && HAVE_LIBLZMA + lzma_stream lzstream; + int lzstream_valid; +#elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC + lzmadec_stream lzstream; + int lzstream_valid; +#endif + /* + * For Checksum data. + */ + struct chksumwork a_sumwrk; + struct chksumwork e_sumwrk; + + struct xar_file *file; /* current reading file. */ + struct xattr *xattr; /* current reading extended attribute. */ + struct heap_queue file_queue; + struct xar_file *hdlink_orgs; + struct hdlink *hdlink_list; + + int entry_init; + uint64_t entry_total; + uint64_t entry_remaining; + size_t entry_unconsumed; + uint64_t entry_size; + enum enctype entry_encoding; + struct chksumval entry_a_sum; + struct chksumval entry_e_sum; + + struct archive_string_conv *sconv; +}; + +struct xmlattr { + struct xmlattr *next; + char *name; + char *value; +}; + +struct xmlattr_list { + struct xmlattr *first; + struct xmlattr **last; +}; + +static int xar_bid(struct archive_read *, int); +static int xar_read_header(struct archive_read *, + struct archive_entry *); +static int xar_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int xar_read_data_skip(struct archive_read *); +static int xar_cleanup(struct archive_read *); +static int move_reading_point(struct archive_read *, uint64_t); +static int rd_contents_init(struct archive_read *, + enum enctype, int, int); +static int rd_contents(struct archive_read *, const void **, + size_t *, size_t *, uint64_t); +static uint64_t atol10(const char *, size_t); +static int64_t atol8(const char *, size_t); +static size_t atohex(unsigned char *, size_t, const char *, size_t); +static time_t parse_time(const char *p, size_t n); +static int heap_add_entry(struct archive_read *a, + struct heap_queue *, struct xar_file *); +static struct xar_file *heap_get_entry(struct heap_queue *); +static int add_link(struct archive_read *, + struct xar *, struct xar_file *); +static void checksum_init(struct archive_read *, int, int); +static void checksum_update(struct archive_read *, const void *, + size_t, const void *, size_t); +static int checksum_final(struct archive_read *, const void *, + size_t, const void *, size_t); +static int decompression_init(struct archive_read *, enum enctype); +static int decompress(struct archive_read *, const void **, + size_t *, const void *, size_t *); +static int decompression_cleanup(struct archive_read *); +static void xmlattr_cleanup(struct xmlattr_list *); +static int file_new(struct archive_read *, + struct xar *, struct xmlattr_list *); +static void file_free(struct xar_file *); +static int xattr_new(struct archive_read *, + struct xar *, struct xmlattr_list *); +static void xattr_free(struct xattr *); +static int getencoding(struct xmlattr_list *); +static int getsumalgorithm(struct xmlattr_list *); +static int unknowntag_start(struct archive_read *, + struct xar *, const char *); +static void unknowntag_end(struct xar *, const char *); +static int xml_start(struct archive_read *, + const char *, struct xmlattr_list *); +static void xml_end(void *, const char *); +static void xml_data(void *, const char *, int); +static int xml_parse_file_flags(struct xar *, const char *); +static int xml_parse_file_ext2(struct xar *, const char *); +#if defined(HAVE_LIBXML_XMLREADER_H) +static int xml2_xmlattr_setup(struct archive_read *, + struct xmlattr_list *, xmlTextReaderPtr); +static int xml2_read_cb(void *, char *, int); +static int xml2_close_cb(void *); +static void xml2_error_hdr(void *, const char *, xmlParserSeverities, + xmlTextReaderLocatorPtr); +static int xml2_read_toc(struct archive_read *); +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) +struct expat_userData { + int state; + struct archive_read *archive; +}; +static int expat_xmlattr_setup(struct archive_read *, + struct xmlattr_list *, const XML_Char **); +static void expat_start_cb(void *, const XML_Char *, const XML_Char **); +static void expat_end_cb(void *, const XML_Char *); +static void expat_data_cb(void *, const XML_Char *, int); +static int expat_read_toc(struct archive_read *); +#endif + +int +archive_read_support_format_xar(struct archive *_a) +{ + struct xar *xar; + struct archive_read *a = (struct archive_read *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_xar"); + + xar = (struct xar *)calloc(1, sizeof(*xar)); + if (xar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate xar data"); + return (ARCHIVE_FATAL); + } + + r = __archive_read_register_format(a, + xar, + "xar", + xar_bid, + NULL, + xar_read_header, + xar_read_data, + xar_read_data_skip, + xar_cleanup); + if (r != ARCHIVE_OK) + free(xar); + return (r); +} + +static int +xar_bid(struct archive_read *a, int best_bid) +{ + const unsigned char *b; + int bid; + + (void)best_bid; /* UNUSED */ + + b = __archive_read_ahead(a, HEADER_SIZE, NULL); + if (b == NULL) + return (-1); + + bid = 0; + /* + * Verify magic code + */ + if (archive_be32dec(b) != HEADER_MAGIC) + return (0); + bid += 32; + /* + * Verify header size + */ + if (archive_be16dec(b+4) != HEADER_SIZE) + return (0); + bid += 16; + /* + * Verify header version + */ + if (archive_be16dec(b+6) != HEADER_VERSION) + return (0); + bid += 16; + /* + * Verify type of checksum + */ + switch (archive_be32dec(b+24)) { + case CKSUM_NONE: + case CKSUM_SHA1: + case CKSUM_MD5: + bid += 32; + break; + default: + return (0); + } + + return (bid); +} + +static int +read_toc(struct archive_read *a) +{ + struct xar *xar; + struct xar_file *file; + const unsigned char *b; + uint64_t toc_compressed_size; + uint64_t toc_uncompressed_size; + uint32_t toc_chksum_alg; + ssize_t bytes; + int r; + + xar = (struct xar *)(a->format->data); + + /* + * Read xar header. + */ + b = __archive_read_ahead(a, HEADER_SIZE, &bytes); + if (bytes < 0) + return ((int)bytes); + if (bytes < HEADER_SIZE) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated archive header"); + return (ARCHIVE_FATAL); + } + + if (archive_be32dec(b) != HEADER_MAGIC) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid header magic"); + return (ARCHIVE_FATAL); + } + if (archive_be16dec(b+6) != HEADER_VERSION) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported header version(%d)", + archive_be16dec(b+6)); + return (ARCHIVE_FATAL); + } + toc_compressed_size = archive_be64dec(b+8); + xar->toc_remaining = toc_compressed_size; + toc_uncompressed_size = archive_be64dec(b+16); + toc_chksum_alg = archive_be32dec(b+24); + __archive_read_consume(a, HEADER_SIZE); + xar->offset += HEADER_SIZE; + xar->toc_total = 0; + + /* + * Read TOC(Table of Contents). + */ + /* Initialize reading contents. */ + r = move_reading_point(a, HEADER_SIZE); + if (r != ARCHIVE_OK) + return (r); + r = rd_contents_init(a, GZIP, toc_chksum_alg, CKSUM_NONE); + if (r != ARCHIVE_OK) + return (r); + +#ifdef HAVE_LIBXML_XMLREADER_H + r = xml2_read_toc(a); +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) + r = expat_read_toc(a); +#endif + if (r != ARCHIVE_OK) + return (r); + + /* Set 'The HEAP' base. */ + xar->h_base = xar->offset; + if (xar->toc_total != toc_uncompressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "TOC uncompressed size error"); + return (ARCHIVE_FATAL); + } + + /* + * Checksum TOC + */ + if (toc_chksum_alg != CKSUM_NONE) { + r = move_reading_point(a, xar->toc_chksum_offset); + if (r != ARCHIVE_OK) + return (r); + b = __archive_read_ahead(a, xar->toc_chksum_size, &bytes); + if (bytes < 0) + return ((int)bytes); + if ((uint64_t)bytes < xar->toc_chksum_size) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated archive file"); + return (ARCHIVE_FATAL); + } + r = checksum_final(a, b, xar->toc_chksum_size, NULL, 0); + __archive_read_consume(a, xar->toc_chksum_size); + xar->offset += xar->toc_chksum_size; + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* + * Connect hardlinked files. + */ + for (file = xar->hdlink_orgs; file != NULL; file = file->hdnext) { + struct hdlink **hdlink; + + for (hdlink = &(xar->hdlink_list); *hdlink != NULL; + hdlink = &((*hdlink)->next)) { + if ((*hdlink)->id == file->id) { + struct hdlink *hltmp; + struct xar_file *f2; + int nlink = (*hdlink)->cnt + 1; + + file->nlink = nlink; + for (f2 = (*hdlink)->files; f2 != NULL; + f2 = f2->hdnext) { + f2->nlink = nlink; + archive_string_copy( + &(f2->hardlink), &(file->pathname)); + } + /* Remove resolved files from hdlist_list. */ + hltmp = *hdlink; + *hdlink = hltmp->next; + free(hltmp); + break; + } + } + } + a->archive.archive_format = ARCHIVE_FORMAT_XAR; + a->archive.archive_format_name = "xar"; + + return (ARCHIVE_OK); +} + +static int +xar_read_header(struct archive_read *a, struct archive_entry *entry) +{ + struct xar *xar; + struct xar_file *file; + struct xattr *xattr; + int r; + + xar = (struct xar *)(a->format->data); + r = ARCHIVE_OK; + + if (xar->offset == 0) { + /* Create a character conversion object. */ + if (xar->sconv == NULL) { + xar->sconv = archive_string_conversion_from_charset( + &(a->archive), "UTF-8", 1); + if (xar->sconv == NULL) + return (ARCHIVE_FATAL); + } + + /* Read TOC. */ + r = read_toc(a); + if (r != ARCHIVE_OK) + return (r); + } + + for (;;) { + file = xar->file = heap_get_entry(&(xar->file_queue)); + if (file == NULL) { + xar->end_of_file = 1; + return (ARCHIVE_EOF); + } + if ((file->mode & AE_IFMT) != AE_IFDIR) + break; + if (file->has != (HAS_PATHNAME | HAS_TYPE)) + break; + /* + * If a file type is a directory and it does not have + * any metadata, do not export. + */ + file_free(file); + } + archive_entry_set_atime(entry, file->atime, 0); + archive_entry_set_ctime(entry, file->ctime, 0); + archive_entry_set_mtime(entry, file->mtime, 0); + archive_entry_set_gid(entry, file->gid); + if (file->gname.length > 0 && + archive_entry_copy_gname_l(entry, file->gname.s, + archive_strlen(&(file->gname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Gname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + archive_entry_set_uid(entry, file->uid); + if (file->uname.length > 0 && + archive_entry_copy_uname_l(entry, file->uname.s, + archive_strlen(&(file->uname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Uname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + archive_entry_set_mode(entry, file->mode); + if (archive_entry_copy_pathname_l(entry, file->pathname.s, + archive_strlen(&(file->pathname)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + + + if (file->symlink.length > 0 && + archive_entry_copy_symlink_l(entry, file->symlink.s, + archive_strlen(&(file->symlink)), xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Linkname cannot be converted from %s to current locale.", + archive_string_conversion_charset_name(xar->sconv)); + r = ARCHIVE_WARN; + } + /* Set proper nlink. */ + if ((file->mode & AE_IFMT) == AE_IFDIR) + archive_entry_set_nlink(entry, file->subdirs + 2); + else + archive_entry_set_nlink(entry, file->nlink); + archive_entry_set_size(entry, file->size); + if (archive_strlen(&(file->hardlink)) > 0) + archive_entry_set_hardlink(entry, file->hardlink.s); + archive_entry_set_ino64(entry, file->ino64); + if (file->has & HAS_DEV) + archive_entry_set_dev(entry, file->dev); + if (file->has & HAS_DEVMAJOR) + archive_entry_set_devmajor(entry, file->devmajor); + if (file->has & HAS_DEVMINOR) + archive_entry_set_devminor(entry, file->devminor); + if (archive_strlen(&(file->fflags_text)) > 0) + archive_entry_copy_fflags_text(entry, file->fflags_text.s); + + xar->entry_init = 1; + xar->entry_total = 0; + xar->entry_remaining = file->length; + xar->entry_size = file->size; + xar->entry_encoding = file->encoding; + xar->entry_a_sum = file->a_sum; + xar->entry_e_sum = file->e_sum; + /* + * Read extended attributes. + */ + xattr = file->xattr_list; + while (xattr != NULL) { + const void *d; + size_t outbytes, used; + + r = move_reading_point(a, xattr->offset); + if (r != ARCHIVE_OK) + break; + r = rd_contents_init(a, xattr->encoding, + xattr->a_sum.alg, xattr->e_sum.alg); + if (r != ARCHIVE_OK) + break; + d = NULL; + r = rd_contents(a, &d, &outbytes, &used, xattr->length); + if (r != ARCHIVE_OK) + break; + if (outbytes != xattr->size) { + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompressed size error"); + r = ARCHIVE_FATAL; + break; + } + r = checksum_final(a, + xattr->a_sum.val, xattr->a_sum.len, + xattr->e_sum.val, xattr->e_sum.len); + if (r != ARCHIVE_OK) + break; + archive_entry_xattr_add_entry(entry, + xattr->name.s, d, outbytes); + xattr = xattr->next; + } + if (r != ARCHIVE_OK) { + file_free(file); + return (r); + } + + if (xar->entry_remaining > 0) + /* Move reading point to the beginning of current + * file contents. */ + r = move_reading_point(a, file->offset); + else + r = ARCHIVE_OK; + + file_free(file); + return (r); +} + +static int +xar_read_data(struct archive_read *a, + const void **buff, size_t *size, int64_t *offset) +{ + struct xar *xar; + size_t used; + int r; + + xar = (struct xar *)(a->format->data); + + if (xar->entry_unconsumed) { + __archive_read_consume(a, xar->entry_unconsumed); + xar->entry_unconsumed = 0; + } + + if (xar->end_of_file || xar->entry_remaining <= 0) { + r = ARCHIVE_EOF; + goto abort_read_data; + } + + if (xar->entry_init) { + r = rd_contents_init(a, xar->entry_encoding, + xar->entry_a_sum.alg, xar->entry_e_sum.alg); + if (r != ARCHIVE_OK) { + xar->entry_remaining = 0; + return (r); + } + xar->entry_init = 0; + } + + *buff = NULL; + r = rd_contents(a, buff, size, &used, xar->entry_remaining); + if (r != ARCHIVE_OK) + goto abort_read_data; + + *offset = xar->entry_total; + xar->entry_total += *size; + xar->total += *size; + xar->offset += used; + xar->entry_remaining -= used; + xar->entry_unconsumed = used; + + if (xar->entry_remaining == 0) { + if (xar->entry_total != xar->entry_size) { + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Decompressed size error"); + r = ARCHIVE_FATAL; + goto abort_read_data; + } + r = checksum_final(a, + xar->entry_a_sum.val, xar->entry_a_sum.len, + xar->entry_e_sum.val, xar->entry_e_sum.len); + if (r != ARCHIVE_OK) + goto abort_read_data; + } + + return (ARCHIVE_OK); +abort_read_data: + *buff = NULL; + *size = 0; + *offset = xar->total; + return (r); +} + +static int +xar_read_data_skip(struct archive_read *a) +{ + struct xar *xar; + int64_t bytes_skipped; + + xar = (struct xar *)(a->format->data); + if (xar->end_of_file) + return (ARCHIVE_EOF); + bytes_skipped = __archive_read_consume(a, xar->entry_remaining + + xar->entry_unconsumed); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + xar->offset += bytes_skipped; + xar->entry_unconsumed = 0; + return (ARCHIVE_OK); +} + +static int +xar_cleanup(struct archive_read *a) +{ + struct xar *xar; + struct hdlink *hdlink; + int i; + int r; + + xar = (struct xar *)(a->format->data); + r = decompression_cleanup(a); + hdlink = xar->hdlink_list; + while (hdlink != NULL) { + struct hdlink *next = hdlink->next; + + free(hdlink); + hdlink = next; + } + for (i = 0; i < xar->file_queue.used; i++) + file_free(xar->file_queue.files[i]); + while (xar->unknowntags != NULL) { + struct unknown_tag *tag; + + tag = xar->unknowntags; + xar->unknowntags = tag->next; + archive_string_free(&(tag->name)); + free(tag); + } + free(xar->outbuff); + free(xar); + a->format->data = NULL; + return (r); +} + +static int +move_reading_point(struct archive_read *a, uint64_t offset) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + if (xar->offset - xar->h_base != offset) { + /* Seek forward to the start of file contents. */ + int64_t step; + + step = offset - (xar->offset - xar->h_base); + if (step > 0) { + step = __archive_read_consume(a, step); + if (step < 0) + return ((int)step); + xar->offset += step; + } else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Cannot seek."); + return (ARCHIVE_FAILED); + } + } + return (ARCHIVE_OK); +} + +static int +rd_contents_init(struct archive_read *a, enum enctype encoding, + int a_sum_alg, int e_sum_alg) +{ + int r; + + /* Init decompress library. */ + if ((r = decompression_init(a, encoding)) != ARCHIVE_OK) + return (r); + /* Init checksum library. */ + checksum_init(a, a_sum_alg, e_sum_alg); + return (ARCHIVE_OK); +} + +static int +rd_contents(struct archive_read *a, const void **buff, size_t *size, + size_t *used, uint64_t remaining) +{ + const unsigned char *b; + ssize_t bytes; + + /* Get whatever bytes are immediately available. */ + b = __archive_read_ahead(a, 1, &bytes); + if (bytes < 0) + return ((int)bytes); + if (bytes == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated archive file"); + return (ARCHIVE_FATAL); + } + if ((uint64_t)bytes > remaining) + bytes = (ssize_t)remaining; + + /* + * Decompress contents of file. + */ + *used = bytes; + if (decompress(a, buff, size, b, used) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* + * Update checksum of a compressed data and a extracted data. + */ + checksum_update(a, b, *used, *buff, *size); + + return (ARCHIVE_OK); +} + +/* + * Note that this implementation does not (and should not!) obey + * locale settings; you cannot simply substitute strtol here, since + * it does obey locale. + */ + +static uint64_t +atol10(const char *p, size_t char_cnt) +{ + uint64_t l; + int digit; + + l = 0; + digit = *p - '0'; + while (digit >= 0 && digit < 10 && char_cnt-- > 0) { + l = (l * 10) + digit; + digit = *++p - '0'; + } + return (l); +} + +static int64_t +atol8(const char *p, size_t char_cnt) +{ + int64_t l; + int digit; + + l = 0; + while (char_cnt-- > 0) { + if (*p >= '0' && *p <= '7') + digit = *p - '0'; + else + break; + p++; + l <<= 3; + l |= digit; + } + return (l); +} + +static size_t +atohex(unsigned char *b, size_t bsize, const char *p, size_t psize) +{ + size_t fbsize = bsize; + + while (bsize && psize > 1) { + unsigned char x; + + if (p[0] >= 'a' && p[0] <= 'z') + x = (p[0] - 'a' + 0x0a) << 4; + else if (p[0] >= 'A' && p[0] <= 'Z') + x = (p[0] - 'A' + 0x0a) << 4; + else if (p[0] >= '0' && p[0] <= '9') + x = (p[0] - '0') << 4; + else + return (-1); + if (p[1] >= 'a' && p[1] <= 'z') + x |= p[1] - 'a' + 0x0a; + else if (p[1] >= 'A' && p[1] <= 'Z') + x |= p[1] - 'A' + 0x0a; + else if (p[1] >= '0' && p[1] <= '9') + x |= p[1] - '0'; + else + return (-1); + + *b++ = x; + bsize--; + p += 2; + psize -= 2; + } + return (fbsize - bsize); +} + +static time_t +time_from_tm(struct tm *t) +{ +#if HAVE_TIMEGM + /* Use platform timegm() if available. */ + return (timegm(t)); +#elif HAVE__MKGMTIME64 + return (_mkgmtime64(t)); +#else + /* Else use direct calculation using POSIX assumptions. */ + /* First, fix up tm_yday based on the year/month/day. */ + mktime(t); + /* Then we can compute timegm() from first principles. */ + return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600 + + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000 + + ((t->tm_year - 69) / 4) * 86400 - + ((t->tm_year - 1) / 100) * 86400 + + ((t->tm_year + 299) / 400) * 86400); +#endif +} + +static time_t +parse_time(const char *p, size_t n) +{ + struct tm tm; + time_t t = 0; + int64_t data; + + memset(&tm, 0, sizeof(tm)); + if (n != 20) + return (t); + data = atol10(p, 4); + if (data < 1900) + return (t); + tm.tm_year = (int)data - 1900; + p += 4; + if (*p++ != '-') + return (t); + data = atol10(p, 2); + if (data < 1 || data > 12) + return (t); + tm.tm_mon = (int)data -1; + p += 2; + if (*p++ != '-') + return (t); + data = atol10(p, 2); + if (data < 1 || data > 31) + return (t); + tm.tm_mday = (int)data; + p += 2; + if (*p++ != 'T') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 23) + return (t); + tm.tm_hour = (int)data; + p += 2; + if (*p++ != ':') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 59) + return (t); + tm.tm_min = (int)data; + p += 2; + if (*p++ != ':') + return (t); + data = atol10(p, 2); + if (data < 0 || data > 60) + return (t); + tm.tm_sec = (int)data; +#if 0 + p += 2; + if (*p != 'Z') + return (t); +#endif + + t = time_from_tm(&tm); + + return (t); +} + +static int +heap_add_entry(struct archive_read *a, + struct heap_queue *heap, struct xar_file *file) +{ + uint64_t file_id, parent_id; + int hole, parent; + + /* Expand our pending files list as necessary. */ + if (heap->used >= heap->allocated) { + struct xar_file **new_pending_files; + int new_size = heap->allocated * 2; + + if (heap->allocated < 1024) + new_size = 1024; + /* Overflow might keep us from growing the list. */ + if (new_size <= heap->allocated) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + new_pending_files = (struct xar_file **) + malloc(new_size * sizeof(new_pending_files[0])); + if (new_pending_files == NULL) { + archive_set_error(&a->archive, + ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + memcpy(new_pending_files, heap->files, + heap->allocated * sizeof(new_pending_files[0])); + if (heap->files != NULL) + free(heap->files); + heap->files = new_pending_files; + heap->allocated = new_size; + } + + file_id = file->id; + + /* + * Start with hole at end, walk it up tree to find insertion point. + */ + hole = heap->used++; + while (hole > 0) { + parent = (hole - 1)/2; + parent_id = heap->files[parent]->id; + if (file_id >= parent_id) { + heap->files[hole] = file; + return (ARCHIVE_OK); + } + /* Move parent into hole <==> move hole up tree. */ + heap->files[hole] = heap->files[parent]; + hole = parent; + } + heap->files[0] = file; + + return (ARCHIVE_OK); +} + +static struct xar_file * +heap_get_entry(struct heap_queue *heap) +{ + uint64_t a_id, b_id, c_id; + int a, b, c; + struct xar_file *r, *tmp; + + if (heap->used < 1) + return (NULL); + + /* + * The first file in the list is the earliest; we'll return this. + */ + r = heap->files[0]; + + /* + * Move the last item in the heap to the root of the tree + */ + heap->files[0] = heap->files[--(heap->used)]; + + /* + * Rebalance the heap. + */ + a = 0; /* Starting element and its heap key */ + a_id = heap->files[a]->id; + for (;;) { + b = a + a + 1; /* First child */ + if (b >= heap->used) + return (r); + b_id = heap->files[b]->id; + c = b + 1; /* Use second child if it is smaller. */ + if (c < heap->used) { + c_id = heap->files[c]->id; + if (c_id < b_id) { + b = c; + b_id = c_id; + } + } + if (a_id <= b_id) + return (r); + tmp = heap->files[a]; + heap->files[a] = heap->files[b]; + heap->files[b] = tmp; + a = b; + } +} + +static int +add_link(struct archive_read *a, struct xar *xar, struct xar_file *file) +{ + struct hdlink *hdlink; + + for (hdlink = xar->hdlink_list; hdlink != NULL; hdlink = hdlink->next) { + if (hdlink->id == file->link) { + file->hdnext = hdlink->files; + hdlink->cnt++; + hdlink->files = file; + return (ARCHIVE_OK); + } + } + hdlink = malloc(sizeof(*hdlink)); + if (hdlink == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + file->hdnext = NULL; + hdlink->id = file->link; + hdlink->cnt = 1; + hdlink->files = file; + hdlink->next = xar->hdlink_list; + xar->hdlink_list = hdlink; + return (ARCHIVE_OK); +} + +static void +_checksum_init(struct chksumwork *sumwrk, int sum_alg) +{ + sumwrk->alg = sum_alg; + switch (sum_alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_init(&(sumwrk->sha1ctx)); + break; + case CKSUM_MD5: + archive_md5_init(&(sumwrk->md5ctx)); + break; + } +} + +static void +_checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size) +{ + + switch (sumwrk->alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_update(&(sumwrk->sha1ctx), buff, size); + break; + case CKSUM_MD5: + archive_md5_update(&(sumwrk->md5ctx), buff, size); + break; + } +} + +static int +_checksum_final(struct chksumwork *sumwrk, const void *val, size_t len) +{ + unsigned char sum[MAX_SUM_SIZE]; + int r = ARCHIVE_OK; + + switch (sumwrk->alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_final(&(sumwrk->sha1ctx), sum); + if (len != SHA1_SIZE || + memcmp(val, sum, SHA1_SIZE) != 0) + r = ARCHIVE_FAILED; + break; + case CKSUM_MD5: + archive_md5_final(&(sumwrk->md5ctx), sum); + if (len != MD5_SIZE || + memcmp(val, sum, MD5_SIZE) != 0) + r = ARCHIVE_FAILED; + break; + } + return (r); +} + +static void +checksum_init(struct archive_read *a, int a_sum_alg, int e_sum_alg) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + _checksum_init(&(xar->a_sumwrk), a_sum_alg); + _checksum_init(&(xar->e_sumwrk), e_sum_alg); +} + +static void +checksum_update(struct archive_read *a, const void *abuff, size_t asize, + const void *ebuff, size_t esize) +{ + struct xar *xar; + + xar = (struct xar *)(a->format->data); + _checksum_update(&(xar->a_sumwrk), abuff, asize); + _checksum_update(&(xar->e_sumwrk), ebuff, esize); +} + +static int +checksum_final(struct archive_read *a, const void *a_sum_val, + size_t a_sum_len, const void *e_sum_val, size_t e_sum_len) +{ + struct xar *xar; + int r; + + xar = (struct xar *)(a->format->data); + r = _checksum_final(&(xar->a_sumwrk), a_sum_val, a_sum_len); + if (r == ARCHIVE_OK) + r = _checksum_final(&(xar->e_sumwrk), e_sum_val, e_sum_len); + if (r != ARCHIVE_OK) + archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, + "Sumcheck error"); + return (r); +} + +static int +decompression_init(struct archive_read *a, enum enctype encoding) +{ + struct xar *xar; + const char *detail; + int r; + + xar = (struct xar *)(a->format->data); + xar->rd_encoding = encoding; + switch (encoding) { + case NONE: + break; + case GZIP: + if (xar->stream_valid) + r = inflateReset(&(xar->stream)); + else + r = inflateInit(&(xar->stream)); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't initialize zlib stream."); + return (ARCHIVE_FATAL); + } + xar->stream_valid = 1; + xar->stream.total_in = 0; + xar->stream.total_out = 0; + break; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case BZIP2: + if (xar->bzstream_valid) { + BZ2_bzDecompressEnd(&(xar->bzstream)); + xar->bzstream_valid = 0; + } + r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 0); + if (r == BZ_MEM_ERROR) + r = BZ2_bzDecompressInit(&(xar->bzstream), 0, 1); + if (r != BZ_OK) { + int err = ARCHIVE_ERRNO_MISC; + detail = NULL; + switch (r) { + case BZ_PARAM_ERROR: + detail = "invalid setup parameter"; + break; + case BZ_MEM_ERROR: + err = ENOMEM; + detail = "out of memory"; + break; + case BZ_CONFIG_ERROR: + detail = "mis-compiled library"; + break; + } + archive_set_error(&a->archive, err, + "Internal error initializing decompressor: %s", + detail == NULL ? "??" : detail); + xar->bzstream_valid = 0; + return (ARCHIVE_FATAL); + } + xar->bzstream_valid = 1; + xar->bzstream.total_in_lo32 = 0; + xar->bzstream.total_in_hi32 = 0; + xar->bzstream.total_out_lo32 = 0; + xar->bzstream.total_out_hi32 = 0; + break; +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) +#if LZMA_VERSION_MAJOR >= 5 +/* Effectively disable the limiter. */ +#define LZMA_MEMLIMIT UINT64_MAX +#else +/* NOTE: This needs to check memory size which running system has. */ +#define LZMA_MEMLIMIT (1U << 30) +#endif + case XZ: + case LZMA: + if (xar->lzstream_valid) { + lzma_end(&(xar->lzstream)); + xar->lzstream_valid = 0; + } + if (xar->entry_encoding == XZ) + r = lzma_stream_decoder(&(xar->lzstream), + LZMA_MEMLIMIT,/* memlimit */ + LZMA_CONCATENATED); + else + r = lzma_alone_decoder(&(xar->lzstream), + LZMA_MEMLIMIT);/* memlimit */ + if (r != LZMA_OK) { + switch (r) { + case LZMA_MEM_ERROR: + archive_set_error(&a->archive, + ENOMEM, + "Internal error initializing " + "compression library: " + "Cannot allocate memory"); + break; + case LZMA_OPTIONS_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: " + "Invalid or unsupported options"); + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "lzma library"); + break; + } + return (ARCHIVE_FATAL); + } + xar->lzstream_valid = 1; + xar->lzstream.total_in = 0; + xar->lzstream.total_out = 0; + break; +#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC) + case LZMA: + if (xar->lzstream_valid) + lzmadec_end(&(xar->lzstream)); + r = lzmadec_init(&(xar->lzstream)); + if (r != LZMADEC_OK) { + switch (r) { + case LZMADEC_HEADER_ERROR: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: " + "invalid header"); + break; + case LZMADEC_MEM_ERROR: + archive_set_error(&a->archive, + ENOMEM, + "Internal error initializing " + "compression library: " + "out of memory"); + break; + } + return (ARCHIVE_FATAL); + } + xar->lzstream_valid = 1; + xar->lzstream.total_in = 0; + xar->lzstream.total_out = 0; + break; +#endif + /* + * Unsupported compression. + */ + default: +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) + case BZIP2: +#endif +#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) +#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC) + case LZMA: +#endif + case XZ: +#endif + switch (xar->entry_encoding) { + case BZIP2: detail = "bzip2"; break; + case LZMA: detail = "lzma"; break; + case XZ: detail = "xz"; break; + default: detail = "??"; break; + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s compression not supported on this platform", + detail); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); +} + +static int +decompress(struct archive_read *a, const void **buff, size_t *outbytes, + const void *b, size_t *used) +{ + struct xar *xar; + void *outbuff; + size_t avail_in, avail_out; + int r; + + xar = (struct xar *)(a->format->data); + avail_in = *used; + outbuff = (void *)(uintptr_t)*buff; + if (outbuff == NULL) { + if (xar->outbuff == NULL) { + xar->outbuff = malloc(OUTBUFF_SIZE); + if (xar->outbuff == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for out buffer"); + return (ARCHIVE_FATAL); + } + } + outbuff = xar->outbuff; + *buff = outbuff; + avail_out = OUTBUFF_SIZE; + } else + avail_out = *outbytes; + switch (xar->rd_encoding) { + case GZIP: + xar->stream.next_in = (Bytef *)(uintptr_t)b; + xar->stream.avail_in = avail_in; + xar->stream.next_out = (unsigned char *)outbuff; + xar->stream.avail_out = avail_out; + r = inflate(&(xar->stream), 0); + switch (r) { + case Z_OK: /* Decompressor made some progress.*/ + case Z_STREAM_END: /* Found end of stream. */ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "File decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->stream.avail_in; + *outbytes = avail_out - xar->stream.avail_out; + break; +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + case BZIP2: + xar->bzstream.next_in = (char *)(uintptr_t)b; + xar->bzstream.avail_in = avail_in; + xar->bzstream.next_out = (char *)outbuff; + xar->bzstream.avail_out = avail_out; + r = BZ2_bzDecompress(&(xar->bzstream)); + switch (r) { + case BZ_STREAM_END: /* Found end of stream. */ + switch (BZ2_bzDecompressEnd(&(xar->bzstream))) { + case BZ_OK: + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up decompressor"); + return (ARCHIVE_FATAL); + } + xar->bzstream_valid = 0; + /* FALLTHROUGH */ + case BZ_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "bzip decompression failed"); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->bzstream.avail_in; + *outbytes = avail_out - xar->bzstream.avail_out; + break; +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + case LZMA: + case XZ: + xar->lzstream.next_in = b; + xar->lzstream.avail_in = avail_in; + xar->lzstream.next_out = (unsigned char *)outbuff; + xar->lzstream.avail_out = avail_out; + r = lzma_code(&(xar->lzstream), LZMA_RUN); + switch (r) { + case LZMA_STREAM_END: /* Found end of stream. */ + lzma_end(&(xar->lzstream)); + xar->lzstream_valid = 0; + /* FALLTHROUGH */ + case LZMA_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "%s decompression failed(%d)", + (xar->entry_encoding == XZ)?"xz":"lzma", + r); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->lzstream.avail_in; + *outbytes = avail_out - xar->lzstream.avail_out; + break; +#elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC) + case LZMA: + xar->lzstream.next_in = (unsigned char *)(uintptr_t)b; + xar->lzstream.avail_in = avail_in; + xar->lzstream.next_out = (unsigned char *)outbuff; + xar->lzstream.avail_out = avail_out; + r = lzmadec_decode(&(xar->lzstream), 0); + switch (r) { + case LZMADEC_STREAM_END: /* Found end of stream. */ + switch (lzmadec_end(&(xar->lzstream))) { + case LZMADEC_OK: + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Failed to clean up lzmadec decompressor"); + return (ARCHIVE_FATAL); + } + xar->lzstream_valid = 0; + /* FALLTHROUGH */ + case LZMADEC_OK: /* Decompressor made some progress. */ + break; + default: + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "lzmadec decompression failed(%d)", + r); + return (ARCHIVE_FATAL); + } + *used = avail_in - xar->lzstream.avail_in; + *outbytes = avail_out - xar->lzstream.avail_out; + break; +#endif +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) + case BZIP2: +#endif +#if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA) +#if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC) + case LZMA: +#endif + case XZ: +#endif + case NONE: + default: + if (outbuff == xar->outbuff) { + *buff = b; + *used = avail_in; + *outbytes = avail_in; + } else { + if (avail_out > avail_in) + avail_out = avail_in; + memcpy(outbuff, b, avail_out); + *used = avail_out; + *outbytes = avail_out; + } + break; + } + return (ARCHIVE_OK); +} + +static int +decompression_cleanup(struct archive_read *a) +{ + struct xar *xar; + int r; + + xar = (struct xar *)(a->format->data); + r = ARCHIVE_OK; + if (xar->stream_valid) { + if (inflateEnd(&(xar->stream)) != Z_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up zlib decompressor"); + r = ARCHIVE_FATAL; + } + } +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + if (xar->bzstream_valid) { + if (BZ2_bzDecompressEnd(&(xar->bzstream)) != BZ_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up bzip2 decompressor"); + r = ARCHIVE_FATAL; + } + } +#endif +#if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + if (xar->lzstream_valid) + lzma_end(&(xar->lzstream)); +#elif defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA) + if (xar->lzstream_valid) { + if (lzmadec_end(&(xar->lzstream)) != LZMADEC_OK) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Failed to clean up lzmadec decompressor"); + r = ARCHIVE_FATAL; + } + } +#endif + return (r); +} + +static void +xmlattr_cleanup(struct xmlattr_list *list) +{ + struct xmlattr *attr, *next; + + attr = list->first; + while (attr != NULL) { + next = attr->next; + free(attr->name); + free(attr->value); + free(attr); + attr = next; + } + list->first = NULL; + list->last = &(list->first); +} + +static int +file_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list) +{ + struct xar_file *file; + struct xmlattr *attr; + + file = calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + file->parent = xar->file; + file->mode = 0777 | AE_IFREG; + file->atime = time(NULL); + file->mtime = time(NULL); + xar->file = file; + xar->xattr = NULL; + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "id") == 0) + file->id = atol10(attr->value, strlen(attr->value)); + } + file->nlink = 1; + if (heap_add_entry(a, &(xar->file_queue), file) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + +static void +file_free(struct xar_file *file) +{ + struct xattr *xattr; + + archive_string_free(&(file->pathname)); + archive_string_free(&(file->symlink)); + archive_string_free(&(file->uname)); + archive_string_free(&(file->gname)); + archive_string_free(&(file->hardlink)); + xattr = file->xattr_list; + while (xattr != NULL) { + struct xattr *next; + + next = xattr->next; + xattr_free(xattr); + xattr = next; + } + + free(file); +} + +static int +xattr_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list) +{ + struct xattr *xattr, **nx; + struct xmlattr *attr; + + xattr = calloc(1, sizeof(*xattr)); + if (xattr == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + xar->xattr = xattr; + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "id") == 0) + xattr->id = atol10(attr->value, strlen(attr->value)); + } + /* Chain to xattr list. */ + for (nx = &(xar->file->xattr_list); + *nx != NULL; nx = &((*nx)->next)) { + if (xattr->id < (*nx)->id) + break; + } + xattr->next = *nx; + *nx = xattr; + + return (ARCHIVE_OK); +} + +static void +xattr_free(struct xattr *xattr) +{ + archive_string_free(&(xattr->name)); + free(xattr); +} + +static int +getencoding(struct xmlattr_list *list) +{ + struct xmlattr *attr; + enum enctype encoding = NONE; + + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "style") == 0) { + if (strcmp(attr->value, "application/octet-stream") == 0) + encoding = NONE; + else if (strcmp(attr->value, "application/x-gzip") == 0) + encoding = GZIP; + else if (strcmp(attr->value, "application/x-bzip2") == 0) + encoding = BZIP2; + else if (strcmp(attr->value, "application/x-lzma") == 0) + encoding = LZMA; + else if (strcmp(attr->value, "application/x-xz") == 0) + encoding = XZ; + } + } + return (encoding); +} + +static int +getsumalgorithm(struct xmlattr_list *list) +{ + struct xmlattr *attr; + int alg = CKSUM_NONE; + + for (attr = list->first; attr != NULL; attr = attr->next) { + if (strcmp(attr->name, "style") == 0) { + const char *v = attr->value; + if ((v[0] == 'S' || v[0] == 's') && + (v[1] == 'H' || v[1] == 'h') && + (v[2] == 'A' || v[2] == 'a') && + v[3] == '1' && v[4] == '\0') + alg = CKSUM_SHA1; + if ((v[0] == 'M' || v[0] == 'm') && + (v[1] == 'D' || v[1] == 'd') && + v[2] == '5' && v[3] == '\0') + alg = CKSUM_MD5; + } + } + return (alg); +} + +static int +unknowntag_start(struct archive_read *a, struct xar *xar, const char *name) +{ + struct unknown_tag *tag; + +#if DEBUG + fprintf(stderr, "unknowntag_start:%s\n", name); +#endif + tag = malloc(sizeof(*tag)); + if (tag == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + tag->next = xar->unknowntags; + archive_string_init(&(tag->name)); + archive_strcpy(&(tag->name), name); + if (xar->unknowntags == NULL) { + xar->xmlsts_unknown = xar->xmlsts; + xar->xmlsts = UNKNOWN; + } + xar->unknowntags = tag; + return (ARCHIVE_OK); +} + +static void +unknowntag_end(struct xar *xar, const char *name) +{ + struct unknown_tag *tag; + +#if DEBUG + fprintf(stderr, "unknowntag_end:%s\n", name); +#endif + tag = xar->unknowntags; + if (tag == NULL || name == NULL) + return; + if (strcmp(tag->name.s, name) == 0) { + xar->unknowntags = tag->next; + archive_string_free(&(tag->name)); + free(tag); + if (xar->unknowntags == NULL) + xar->xmlsts = xar->xmlsts_unknown; + } +} + +static int +xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list) +{ + struct xar *xar; + struct xmlattr *attr; + + xar = (struct xar *)(a->format->data); + +#if DEBUG + fprintf(stderr, "xml_sta:[%s]\n", name); + for (attr = list->first; attr != NULL; attr = attr->next) + fprintf(stderr, " attr:\"%s\"=\"%s\"\n", + attr->name, attr->value); +#endif + xar->base64text = 0; + switch (xar->xmlsts) { + case INIT: + if (strcmp(name, "xar") == 0) + xar->xmlsts = XAR; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case XAR: + if (strcmp(name, "toc") == 0) + xar->xmlsts = TOC; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC: + if (strcmp(name, "creation-time") == 0) + xar->xmlsts = TOC_CREATION_TIME; + else if (strcmp(name, "checksum") == 0) + xar->xmlsts = TOC_CHECKSUM; + else if (strcmp(name, "file") == 0) { + if (file_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + xar->xmlsts = TOC_FILE; + } + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_CHECKSUM: + if (strcmp(name, "offset") == 0) + xar->xmlsts = TOC_CHECKSUM_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = TOC_CHECKSUM_SIZE; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_FILE: + if (strcmp(name, "file") == 0) { + if (file_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + else if (strcmp(name, "data") == 0) + xar->xmlsts = FILE_DATA; + else if (strcmp(name, "ea") == 0) { + if (xattr_new(a, xar, list) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + xar->xmlsts = FILE_EA; + } + else if (strcmp(name, "ctime") == 0) + xar->xmlsts = FILE_CTIME; + else if (strcmp(name, "mtime") == 0) + xar->xmlsts = FILE_MTIME; + else if (strcmp(name, "atime") == 0) + xar->xmlsts = FILE_ATIME; + else if (strcmp(name, "group") == 0) + xar->xmlsts = FILE_GROUP; + else if (strcmp(name, "gid") == 0) + xar->xmlsts = FILE_GID; + else if (strcmp(name, "user") == 0) + xar->xmlsts = FILE_USER; + else if (strcmp(name, "uid") == 0) + xar->xmlsts = FILE_UID; + else if (strcmp(name, "mode") == 0) + xar->xmlsts = FILE_MODE; + else if (strcmp(name, "device") == 0) + xar->xmlsts = FILE_DEVICE; + else if (strcmp(name, "deviceno") == 0) + xar->xmlsts = FILE_DEVICENO; + else if (strcmp(name, "inode") == 0) + xar->xmlsts = FILE_INODE; + else if (strcmp(name, "link") == 0) + xar->xmlsts = FILE_LINK; + else if (strcmp(name, "type") == 0) { + xar->xmlsts = FILE_TYPE; + for (attr = list->first; attr != NULL; + attr = attr->next) { + if (strcmp(attr->name, "link") != 0) + continue; + if (strcmp(attr->value, "original") == 0) { + xar->file->hdnext = xar->hdlink_orgs; + xar->hdlink_orgs = xar->file; + } else { + xar->file->link = atol10(attr->value, + strlen(attr->value)); + if (xar->file->link > 0) + if (add_link(a, xar, xar->file) != ARCHIVE_OK) { + return (ARCHIVE_FATAL); + }; + } + } + } + else if (strcmp(name, "name") == 0) { + xar->xmlsts = FILE_NAME; + for (attr = list->first; attr != NULL; + attr = attr->next) { + if (strcmp(attr->name, "enctype") == 0 && + strcmp(attr->value, "base64") == 0) + xar->base64text = 1; + } + } + else if (strcmp(name, "acl") == 0) + xar->xmlsts = FILE_ACL; + else if (strcmp(name, "flags") == 0) + xar->xmlsts = FILE_FLAGS; + else if (strcmp(name, "ext2") == 0) + xar->xmlsts = FILE_EXT2; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DATA: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_DATA_LENGTH; + else if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_DATA_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_DATA_SIZE; + else if (strcmp(name, "encoding") == 0) { + xar->xmlsts = FILE_DATA_ENCODING; + xar->file->encoding = getencoding(list); + } + else if (strcmp(name, "archived-checksum") == 0) { + xar->xmlsts = FILE_DATA_A_CHECKSUM; + xar->file->a_sum.alg = getsumalgorithm(list); + } + else if (strcmp(name, "extracted-checksum") == 0) { + xar->xmlsts = FILE_DATA_E_CHECKSUM; + xar->file->e_sum.alg = getsumalgorithm(list); + } + else if (strcmp(name, "content") == 0) + xar->xmlsts = FILE_DATA_CONTENT; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DEVICE: + if (strcmp(name, "major") == 0) + xar->xmlsts = FILE_DEVICE_MAJOR; + else if (strcmp(name, "minor") == 0) + xar->xmlsts = FILE_DEVICE_MINOR; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_DATA_CONTENT: + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_EA: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_EA_LENGTH; + else if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_EA_OFFSET; + else if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_EA_SIZE; + else if (strcmp(name, "encoding") == 0) { + xar->xmlsts = FILE_EA_ENCODING; + xar->xattr->encoding = getencoding(list); + } else if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_EA_A_CHECKSUM; + else if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_EA_E_CHECKSUM; + else if (strcmp(name, "name") == 0) + xar->xmlsts = FILE_EA_NAME; + else if (strcmp(name, "fstype") == 0) + xar->xmlsts = FILE_EA_FSTYPE; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_ACL: + if (strcmp(name, "appleextended") == 0) + xar->xmlsts = FILE_ACL_APPLEEXTENDED; + if (strcmp(name, "default") == 0) + xar->xmlsts = FILE_ACL_DEFAULT; + else if (strcmp(name, "access") == 0) + xar->xmlsts = FILE_ACL_ACCESS; + else + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_FLAGS: + if (!xml_parse_file_flags(xar, name)) + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case FILE_EXT2: + if (!xml_parse_file_ext2(xar, name)) + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + case TOC_CREATION_TIME: + case TOC_CHECKSUM_OFFSET: + case TOC_CHECKSUM_SIZE: + case FILE_DATA_LENGTH: + case FILE_DATA_OFFSET: + case FILE_DATA_SIZE: + case FILE_DATA_ENCODING: + case FILE_DATA_A_CHECKSUM: + case FILE_DATA_E_CHECKSUM: + case FILE_EA_LENGTH: + case FILE_EA_OFFSET: + case FILE_EA_SIZE: + case FILE_EA_ENCODING: + case FILE_EA_A_CHECKSUM: + case FILE_EA_E_CHECKSUM: + case FILE_EA_NAME: + case FILE_EA_FSTYPE: + case FILE_CTIME: + case FILE_MTIME: + case FILE_ATIME: + case FILE_GROUP: + case FILE_GID: + case FILE_USER: + case FILE_UID: + case FILE_INODE: + case FILE_DEVICE_MAJOR: + case FILE_DEVICE_MINOR: + case FILE_DEVICENO: + case FILE_MODE: + case FILE_TYPE: + case FILE_LINK: + case FILE_NAME: + case FILE_ACL_DEFAULT: + case FILE_ACL_ACCESS: + case FILE_ACL_APPLEEXTENDED: + case FILE_FLAGS_USER_NODUMP: + case FILE_FLAGS_USER_IMMUTABLE: + case FILE_FLAGS_USER_APPEND: + case FILE_FLAGS_USER_OPAQUE: + case FILE_FLAGS_USER_NOUNLINK: + case FILE_FLAGS_SYS_ARCHIVED: + case FILE_FLAGS_SYS_IMMUTABLE: + case FILE_FLAGS_SYS_APPEND: + case FILE_FLAGS_SYS_NOUNLINK: + case FILE_FLAGS_SYS_SNAPSHOT: + case FILE_EXT2_SecureDeletion: + case FILE_EXT2_Undelete: + case FILE_EXT2_Compress: + case FILE_EXT2_Synchronous: + case FILE_EXT2_Immutable: + case FILE_EXT2_AppendOnly: + case FILE_EXT2_NoDump: + case FILE_EXT2_NoAtime: + case FILE_EXT2_CompDirty: + case FILE_EXT2_CompBlock: + case FILE_EXT2_NoCompBlock: + case FILE_EXT2_CompError: + case FILE_EXT2_BTree: + case FILE_EXT2_HashIndexed: + case FILE_EXT2_iMagic: + case FILE_EXT2_Journaled: + case FILE_EXT2_NoTail: + case FILE_EXT2_DirSync: + case FILE_EXT2_TopDir: + case FILE_EXT2_Reserved: + case UNKNOWN: + if (unknowntag_start(a, xar, name) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + break; + } + return (ARCHIVE_OK); +} + +static void +xml_end(void *userData, const char *name) +{ + struct archive_read *a; + struct xar *xar; + + a = (struct archive_read *)userData; + xar = (struct xar *)(a->format->data); + +#if DEBUG + fprintf(stderr, "xml_end:[%s]\n", name); +#endif + switch (xar->xmlsts) { + case INIT: + break; + case XAR: + if (strcmp(name, "xar") == 0) + xar->xmlsts = INIT; + break; + case TOC: + if (strcmp(name, "toc") == 0) + xar->xmlsts = XAR; + break; + case TOC_CREATION_TIME: + if (strcmp(name, "creation-time") == 0) + xar->xmlsts = TOC; + break; + case TOC_CHECKSUM: + if (strcmp(name, "checksum") == 0) + xar->xmlsts = TOC; + break; + case TOC_CHECKSUM_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = TOC_CHECKSUM; + break; + case TOC_CHECKSUM_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = TOC_CHECKSUM; + break; + case TOC_FILE: + if (strcmp(name, "file") == 0) { + if (xar->file->parent != NULL && + ((xar->file->mode & AE_IFMT) == AE_IFDIR)) + xar->file->parent->subdirs++; + xar->file = xar->file->parent; + if (xar->file == NULL) + xar->xmlsts = TOC; + } + break; + case FILE_DATA: + if (strcmp(name, "data") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DATA_LENGTH: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_ENCODING: + if (strcmp(name, "encoding") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_A_CHECKSUM: + if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_E_CHECKSUM: + if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_DATA_CONTENT: + if (strcmp(name, "content") == 0) + xar->xmlsts = FILE_DATA; + break; + case FILE_EA: + if (strcmp(name, "ea") == 0) { + xar->xmlsts = TOC_FILE; + xar->xattr = NULL; + } + break; + case FILE_EA_LENGTH: + if (strcmp(name, "length") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_OFFSET: + if (strcmp(name, "offset") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_SIZE: + if (strcmp(name, "size") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_ENCODING: + if (strcmp(name, "encoding") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_A_CHECKSUM: + if (strcmp(name, "archived-checksum") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_E_CHECKSUM: + if (strcmp(name, "extracted-checksum") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_NAME: + if (strcmp(name, "name") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_EA_FSTYPE: + if (strcmp(name, "fstype") == 0) + xar->xmlsts = FILE_EA; + break; + case FILE_CTIME: + if (strcmp(name, "ctime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_MTIME: + if (strcmp(name, "mtime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ATIME: + if (strcmp(name, "atime") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_GROUP: + if (strcmp(name, "group") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_GID: + if (strcmp(name, "gid") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_USER: + if (strcmp(name, "user") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_UID: + if (strcmp(name, "uid") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_MODE: + if (strcmp(name, "mode") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DEVICE: + if (strcmp(name, "device") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_DEVICE_MAJOR: + if (strcmp(name, "major") == 0) + xar->xmlsts = FILE_DEVICE; + break; + case FILE_DEVICE_MINOR: + if (strcmp(name, "minor") == 0) + xar->xmlsts = FILE_DEVICE; + break; + case FILE_DEVICENO: + if (strcmp(name, "deviceno") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_INODE: + if (strcmp(name, "inode") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_LINK: + if (strcmp(name, "link") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_TYPE: + if (strcmp(name, "type") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_NAME: + if (strcmp(name, "name") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ACL: + if (strcmp(name, "acl") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_ACL_DEFAULT: + if (strcmp(name, "default") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_ACL_ACCESS: + if (strcmp(name, "access") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_ACL_APPLEEXTENDED: + if (strcmp(name, "appleextended") == 0) + xar->xmlsts = FILE_ACL; + break; + case FILE_FLAGS: + if (strcmp(name, "flags") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_FLAGS_USER_NODUMP: + if (strcmp(name, "UserNoDump") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_IMMUTABLE: + if (strcmp(name, "UserImmutable") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_APPEND: + if (strcmp(name, "UserAppend") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_OPAQUE: + if (strcmp(name, "UserOpaque") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_USER_NOUNLINK: + if (strcmp(name, "UserNoUnlink") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_ARCHIVED: + if (strcmp(name, "SystemArchived") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_IMMUTABLE: + if (strcmp(name, "SystemImmutable") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_APPEND: + if (strcmp(name, "SystemAppend") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_NOUNLINK: + if (strcmp(name, "SystemNoUnlink") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_FLAGS_SYS_SNAPSHOT: + if (strcmp(name, "SystemSnapshot") == 0) + xar->xmlsts = FILE_FLAGS; + break; + case FILE_EXT2: + if (strcmp(name, "ext2") == 0) + xar->xmlsts = TOC_FILE; + break; + case FILE_EXT2_SecureDeletion: + if (strcmp(name, "SecureDeletion") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Undelete: + if (strcmp(name, "Undelete") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Compress: + if (strcmp(name, "Compress") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Synchronous: + if (strcmp(name, "Synchronous") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Immutable: + if (strcmp(name, "Immutable") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_AppendOnly: + if (strcmp(name, "AppendOnly") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoDump: + if (strcmp(name, "NoDump") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoAtime: + if (strcmp(name, "NoAtime") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompDirty: + if (strcmp(name, "CompDirty") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompBlock: + if (strcmp(name, "CompBlock") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoCompBlock: + if (strcmp(name, "NoCompBlock") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_CompError: + if (strcmp(name, "CompError") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_BTree: + if (strcmp(name, "BTree") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_HashIndexed: + if (strcmp(name, "HashIndexed") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_iMagic: + if (strcmp(name, "iMagic") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Journaled: + if (strcmp(name, "Journaled") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_NoTail: + if (strcmp(name, "NoTail") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_DirSync: + if (strcmp(name, "DirSync") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_TopDir: + if (strcmp(name, "TopDir") == 0) + xar->xmlsts = FILE_EXT2; + break; + case FILE_EXT2_Reserved: + if (strcmp(name, "Reserved") == 0) + xar->xmlsts = FILE_EXT2; + break; + case UNKNOWN: + unknowntag_end(xar, name); + break; + } +} + +static const int base64[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 00 - 0F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 10 - 1F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 62, -1, -1, -1, 63, /* 20 - 2F */ + 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, -1, -1, -1, -1, -1, -1, /* 30 - 3F */ + -1, 0, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, /* 40 - 4F */ + 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, -1, -1, -1, -1, -1, /* 50 - 5F */ + -1, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, /* 60 - 6F */ + 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, -1, -1, -1, -1, -1, /* 70 - 7F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 80 - 8F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* 90 - 9F */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* A0 - AF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* B0 - BF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* C0 - CF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* D0 - DF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* E0 - EF */ + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, /* F0 - FF */ +}; + +static void +strappend_base64(struct xar *xar, + struct archive_string *as, const char *s, size_t l) +{ + unsigned char buff[256]; + unsigned char *out; + const unsigned char *b; + size_t len; + + len = 0; + out = buff; + b = (const unsigned char *)s; + while (l > 0) { + int n = 0; + + if (l > 0) { + if (base64[b[0]] < 0 || base64[b[1]] < 0) + break; + n = base64[*b++] << 18; + n |= base64[*b++] << 12; + *out++ = n >> 16; + len++; + l -= 2; + } + if (l > 0) { + if (base64[*b] < 0) + break; + n |= base64[*b++] << 6; + *out++ = (n >> 8) & 0xFF; + len++; + --l; + } + if (l > 0) { + if (base64[*b] < 0) + break; + n |= base64[*b++]; + *out++ = n & 0xFF; + len++; + --l; + } + if (len+3 >= sizeof(buff)) { + archive_strncat(as, (const char *)buff, len); + len = 0; + out = buff; + } + } + if (len > 0) + archive_strncat(as, (const char *)buff, len); +} + +static void +xml_data(void *userData, const char *s, int len) +{ + struct archive_read *a; + struct xar *xar; + + a = (struct archive_read *)userData; + xar = (struct xar *)(a->format->data); + +#if DEBUG + { + char buff[1024]; + if (len > sizeof(buff)-1) + len = sizeof(buff)-1; + memcpy(buff, s, len); + buff[len] = 0; + fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff); + } +#endif + switch (xar->xmlsts) { + case TOC_CHECKSUM_OFFSET: + xar->toc_chksum_offset = atol10(s, len); + break; + case TOC_CHECKSUM_SIZE: + xar->toc_chksum_size = atol10(s, len); + break; + default: + break; + } + if (xar->file == NULL) + return; + + switch (xar->xmlsts) { + case FILE_NAME: + if (xar->file->parent != NULL) { + archive_string_concat(&(xar->file->pathname), + &(xar->file->parent->pathname)); + archive_strappend_char(&(xar->file->pathname), '/'); + } + xar->file->has |= HAS_PATHNAME; + if (xar->base64text) { + strappend_base64(xar, + &(xar->file->pathname), s, len); + } else + archive_strncat(&(xar->file->pathname), s, len); + break; + case FILE_LINK: + xar->file->has |= HAS_SYMLINK; + archive_strncpy(&(xar->file->symlink), s, len); + break; + case FILE_TYPE: + if (strncmp("file", s, len) == 0 || + strncmp("hardlink", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFREG; + if (strncmp("directory", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFDIR; + if (strncmp("symlink", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFLNK; + if (strncmp("character special", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFCHR; + if (strncmp("block special", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFBLK; + if (strncmp("socket", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFSOCK; + if (strncmp("fifo", s, len) == 0) + xar->file->mode = + (xar->file->mode & ~AE_IFMT) | AE_IFIFO; + xar->file->has |= HAS_TYPE; + break; + case FILE_INODE: + xar->file->has |= HAS_INO; + xar->file->ino64 = atol10(s, len); + break; + case FILE_DEVICE_MAJOR: + xar->file->has |= HAS_DEVMAJOR; + xar->file->devmajor = (dev_t)atol10(s, len); + break; + case FILE_DEVICE_MINOR: + xar->file->has |= HAS_DEVMINOR; + xar->file->devminor = (dev_t)atol10(s, len); + break; + case FILE_DEVICENO: + xar->file->has |= HAS_DEV; + xar->file->dev = (dev_t)atol10(s, len); + break; + case FILE_MODE: + xar->file->has |= HAS_MODE; + xar->file->mode = + (xar->file->mode & AE_IFMT) | + (atol8(s, len) & ~AE_IFMT); + break; + case FILE_GROUP: + xar->file->has |= HAS_GID; + archive_strncpy(&(xar->file->gname), s, len); + break; + case FILE_GID: + xar->file->has |= HAS_GID; + xar->file->gid = atol10(s, len); + break; + case FILE_USER: + xar->file->has |= HAS_UID; + archive_strncpy(&(xar->file->uname), s, len); + break; + case FILE_UID: + xar->file->has |= HAS_UID; + xar->file->uid = atol10(s, len); + break; + case FILE_CTIME: + xar->file->has |= HAS_TIME; + xar->file->ctime = parse_time(s, len); + break; + case FILE_MTIME: + xar->file->has |= HAS_TIME; + xar->file->mtime = parse_time(s, len); + break; + case FILE_ATIME: + xar->file->has |= HAS_TIME; + xar->file->atime = parse_time(s, len); + break; + case FILE_DATA_LENGTH: + xar->file->has |= HAS_DATA; + xar->file->length = atol10(s, len); + break; + case FILE_DATA_OFFSET: + xar->file->has |= HAS_DATA; + xar->file->offset = atol10(s, len); + break; + case FILE_DATA_SIZE: + xar->file->has |= HAS_DATA; + xar->file->size = atol10(s, len); + break; + case FILE_DATA_A_CHECKSUM: + xar->file->a_sum.len = atohex(xar->file->a_sum.val, + sizeof(xar->file->a_sum.val), s, len); + break; + case FILE_DATA_E_CHECKSUM: + xar->file->e_sum.len = atohex(xar->file->e_sum.val, + sizeof(xar->file->e_sum.val), s, len); + break; + case FILE_EA_LENGTH: + xar->file->has |= HAS_XATTR; + xar->xattr->length = atol10(s, len); + break; + case FILE_EA_OFFSET: + xar->file->has |= HAS_XATTR; + xar->xattr->offset = atol10(s, len); + break; + case FILE_EA_SIZE: + xar->file->has |= HAS_XATTR; + xar->xattr->size = atol10(s, len); + break; + case FILE_EA_A_CHECKSUM: + xar->file->has |= HAS_XATTR; + xar->xattr->a_sum.len = atohex(xar->xattr->a_sum.val, + sizeof(xar->xattr->a_sum.val), s, len); + break; + case FILE_EA_E_CHECKSUM: + xar->file->has |= HAS_XATTR; + xar->xattr->e_sum.len = atohex(xar->xattr->e_sum.val, + sizeof(xar->xattr->e_sum.val), s, len); + break; + case FILE_EA_NAME: + xar->file->has |= HAS_XATTR; + archive_strncpy(&(xar->xattr->name), s, len); + break; + case FILE_EA_FSTYPE: + xar->file->has |= HAS_XATTR; + archive_strncpy(&(xar->xattr->fstype), s, len); + break; + break; + case FILE_ACL_DEFAULT: + case FILE_ACL_ACCESS: + case FILE_ACL_APPLEEXTENDED: + xar->file->has |= HAS_ACL; + /* TODO */ + break; + case INIT: + case XAR: + case TOC: + case TOC_CREATION_TIME: + case TOC_CHECKSUM: + case TOC_CHECKSUM_OFFSET: + case TOC_CHECKSUM_SIZE: + case TOC_FILE: + case FILE_DATA: + case FILE_DATA_ENCODING: + case FILE_DATA_CONTENT: + case FILE_DEVICE: + case FILE_EA: + case FILE_EA_ENCODING: + case FILE_ACL: + case FILE_FLAGS: + case FILE_FLAGS_USER_NODUMP: + case FILE_FLAGS_USER_IMMUTABLE: + case FILE_FLAGS_USER_APPEND: + case FILE_FLAGS_USER_OPAQUE: + case FILE_FLAGS_USER_NOUNLINK: + case FILE_FLAGS_SYS_ARCHIVED: + case FILE_FLAGS_SYS_IMMUTABLE: + case FILE_FLAGS_SYS_APPEND: + case FILE_FLAGS_SYS_NOUNLINK: + case FILE_FLAGS_SYS_SNAPSHOT: + case FILE_EXT2: + case FILE_EXT2_SecureDeletion: + case FILE_EXT2_Undelete: + case FILE_EXT2_Compress: + case FILE_EXT2_Synchronous: + case FILE_EXT2_Immutable: + case FILE_EXT2_AppendOnly: + case FILE_EXT2_NoDump: + case FILE_EXT2_NoAtime: + case FILE_EXT2_CompDirty: + case FILE_EXT2_CompBlock: + case FILE_EXT2_NoCompBlock: + case FILE_EXT2_CompError: + case FILE_EXT2_BTree: + case FILE_EXT2_HashIndexed: + case FILE_EXT2_iMagic: + case FILE_EXT2_Journaled: + case FILE_EXT2_NoTail: + case FILE_EXT2_DirSync: + case FILE_EXT2_TopDir: + case FILE_EXT2_Reserved: + case UNKNOWN: + break; + } +} + +/* + * BSD file flags. + */ +static int +xml_parse_file_flags(struct xar *xar, const char *name) +{ + const char *flag = NULL; + + if (strcmp(name, "UserNoDump") == 0) { + xar->xmlsts = FILE_FLAGS_USER_NODUMP; + flag = "nodump"; + } + else if (strcmp(name, "UserImmutable") == 0) { + xar->xmlsts = FILE_FLAGS_USER_IMMUTABLE; + flag = "uimmutable"; + } + else if (strcmp(name, "UserAppend") == 0) { + xar->xmlsts = FILE_FLAGS_USER_APPEND; + flag = "uappend"; + } + else if (strcmp(name, "UserOpaque") == 0) { + xar->xmlsts = FILE_FLAGS_USER_OPAQUE; + flag = "opaque"; + } + else if (strcmp(name, "UserNoUnlink") == 0) { + xar->xmlsts = FILE_FLAGS_USER_NOUNLINK; + flag = "nouunlink"; + } + else if (strcmp(name, "SystemArchived") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_ARCHIVED; + flag = "archived"; + } + else if (strcmp(name, "SystemImmutable") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_IMMUTABLE; + flag = "simmutable"; + } + else if (strcmp(name, "SystemAppend") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_APPEND; + flag = "sappend"; + } + else if (strcmp(name, "SystemNoUnlink") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_NOUNLINK; + flag = "nosunlink"; + } + else if (strcmp(name, "SystemSnapshot") == 0) { + xar->xmlsts = FILE_FLAGS_SYS_SNAPSHOT; + flag = "snapshot"; + } + + if (flag == NULL) + return (0); + xar->file->has |= HAS_FFLAGS; + if (archive_strlen(&(xar->file->fflags_text)) > 0) + archive_strappend_char(&(xar->file->fflags_text), ','); + archive_strcat(&(xar->file->fflags_text), flag); + return (1); +} + +/* + * Linux file flags. + */ +static int +xml_parse_file_ext2(struct xar *xar, const char *name) +{ + const char *flag = NULL; + + if (strcmp(name, "SecureDeletion") == 0) { + xar->xmlsts = FILE_EXT2_SecureDeletion; + flag = "securedeletion"; + } + else if (strcmp(name, "Undelete") == 0) { + xar->xmlsts = FILE_EXT2_Undelete; + flag = "nouunlink"; + } + else if (strcmp(name, "Compress") == 0) { + xar->xmlsts = FILE_EXT2_Compress; + flag = "compress"; + } + else if (strcmp(name, "Synchronous") == 0) { + xar->xmlsts = FILE_EXT2_Synchronous; + flag = "sync"; + } + else if (strcmp(name, "Immutable") == 0) { + xar->xmlsts = FILE_EXT2_Immutable; + flag = "simmutable"; + } + else if (strcmp(name, "AppendOnly") == 0) { + xar->xmlsts = FILE_EXT2_AppendOnly; + flag = "sappend"; + } + else if (strcmp(name, "NoDump") == 0) { + xar->xmlsts = FILE_EXT2_NoDump; + flag = "nodump"; + } + else if (strcmp(name, "NoAtime") == 0) { + xar->xmlsts = FILE_EXT2_NoAtime; + flag = "noatime"; + } + else if (strcmp(name, "CompDirty") == 0) { + xar->xmlsts = FILE_EXT2_CompDirty; + flag = "compdirty"; + } + else if (strcmp(name, "CompBlock") == 0) { + xar->xmlsts = FILE_EXT2_CompBlock; + flag = "comprblk"; + } + else if (strcmp(name, "NoCompBlock") == 0) { + xar->xmlsts = FILE_EXT2_NoCompBlock; + flag = "nocomprblk"; + } + else if (strcmp(name, "CompError") == 0) { + xar->xmlsts = FILE_EXT2_CompError; + flag = "comperr"; + } + else if (strcmp(name, "BTree") == 0) { + xar->xmlsts = FILE_EXT2_BTree; + flag = "btree"; + } + else if (strcmp(name, "HashIndexed") == 0) { + xar->xmlsts = FILE_EXT2_HashIndexed; + flag = "hashidx"; + } + else if (strcmp(name, "iMagic") == 0) { + xar->xmlsts = FILE_EXT2_iMagic; + flag = "imagic"; + } + else if (strcmp(name, "Journaled") == 0) { + xar->xmlsts = FILE_EXT2_Journaled; + flag = "journal"; + } + else if (strcmp(name, "NoTail") == 0) { + xar->xmlsts = FILE_EXT2_NoTail; + flag = "notail"; + } + else if (strcmp(name, "DirSync") == 0) { + xar->xmlsts = FILE_EXT2_DirSync; + flag = "dirsync"; + } + else if (strcmp(name, "TopDir") == 0) { + xar->xmlsts = FILE_EXT2_TopDir; + flag = "topdir"; + } + else if (strcmp(name, "Reserved") == 0) { + xar->xmlsts = FILE_EXT2_Reserved; + flag = "reserved"; + } + + if (flag == NULL) + return (0); + if (archive_strlen(&(xar->file->fflags_text)) > 0) + archive_strappend_char(&(xar->file->fflags_text), ','); + archive_strcat(&(xar->file->fflags_text), flag); + return (1); +} + +#ifdef HAVE_LIBXML_XMLREADER_H + +static int +xml2_xmlattr_setup(struct archive_read *a, + struct xmlattr_list *list, xmlTextReaderPtr reader) +{ + struct xmlattr *attr; + int r; + + list->first = NULL; + list->last = &(list->first); + r = xmlTextReaderMoveToFirstAttribute(reader); + while (r == 1) { + attr = malloc(sizeof*(attr)); + if (attr == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->name = strdup( + (const char *)xmlTextReaderConstLocalName(reader)); + if (attr->name == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->value = strdup( + (const char *)xmlTextReaderConstValue(reader)); + if (attr->value == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->next = NULL; + *list->last = attr; + list->last = &(attr->next); + r = xmlTextReaderMoveToNextAttribute(reader); + } + return (r); +} + +static int +xml2_read_cb(void *context, char *buffer, int len) +{ + struct archive_read *a; + struct xar *xar; + const void *d; + size_t outbytes; + size_t used; + int r; + + a = (struct archive_read *)context; + xar = (struct xar *)(a->format->data); + + if (xar->toc_remaining <= 0) + return (0); + d = buffer; + outbytes = len; + r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); + if (r != ARCHIVE_OK) + return (r); + __archive_read_consume(a, used); + xar->toc_remaining -= used; + xar->offset += used; + xar->toc_total += outbytes; + PRINT_TOC(buffer, len); + + return ((int)outbytes); +} + +static int +xml2_close_cb(void *context) +{ + + (void)context; /* UNUSED */ + return (0); +} + +static void +xml2_error_hdr(void *arg, const char *msg, xmlParserSeverities severity, + xmlTextReaderLocatorPtr locator) +{ + struct archive_read *a; + + (void)locator; /* UNUSED */ + a = (struct archive_read *)arg; + switch (severity) { + case XML_PARSER_SEVERITY_VALIDITY_WARNING: + case XML_PARSER_SEVERITY_WARNING: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing error: %s", msg); + break; + case XML_PARSER_SEVERITY_VALIDITY_ERROR: + case XML_PARSER_SEVERITY_ERROR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing error: %s", msg); + break; + } +} + +static int +xml2_read_toc(struct archive_read *a) +{ + xmlTextReaderPtr reader; + struct xmlattr_list list; + int r; + + reader = xmlReaderForIO(xml2_read_cb, xml2_close_cb, a, NULL, NULL, 0); + if (reader == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for xml parser"); + return (ARCHIVE_FATAL); + } + xmlTextReaderSetErrorHandler(reader, xml2_error_hdr, a); + + while ((r = xmlTextReaderRead(reader)) == 1) { + const char *name, *value; + int type, empty; + + type = xmlTextReaderNodeType(reader); + name = (const char *)xmlTextReaderConstLocalName(reader); + switch (type) { + case XML_READER_TYPE_ELEMENT: + empty = xmlTextReaderIsEmptyElement(reader); + r = xml2_xmlattr_setup(a, &list, reader); + if (r != ARCHIVE_OK) + return (r); + r = xml_start(a, name, &list); + xmlattr_cleanup(&list); + if (r != ARCHIVE_OK) + return (r); + if (empty) + xml_end(a, name); + break; + case XML_READER_TYPE_END_ELEMENT: + xml_end(a, name); + break; + case XML_READER_TYPE_TEXT: + value = (const char *)xmlTextReaderConstValue(reader); + xml_data(a, value, strlen(value)); + break; + case XML_READER_TYPE_SIGNIFICANT_WHITESPACE: + default: + break; + } + if (r < 0) + break; + } + xmlFreeTextReader(reader); + xmlCleanupParser(); + + return ((r == 0)?ARCHIVE_OK:ARCHIVE_FATAL); +} + +#elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) + +static int +expat_xmlattr_setup(struct archive_read *a, + struct xmlattr_list *list, const XML_Char **atts) +{ + struct xmlattr *attr; + char *name, *value; + + list->first = NULL; + list->last = &(list->first); + if (atts == NULL) + return (ARCHIVE_OK); + while (atts[0] != NULL && atts[1] != NULL) { + attr = malloc(sizeof*(attr)); + name = strdup(atts[0]); + value = strdup(atts[1]); + if (attr == NULL || name == NULL || value == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + attr->name = name; + attr->value = value; + attr->next = NULL; + *list->last = attr; + list->last = &(attr->next); + atts += 2; + } + return (ARCHIVE_OK); +} + +static void +expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + struct archive_read *a = ud->archive; + struct xmlattr_list list; + int r; + + r = expat_xmlattr_setup(a, &list, atts); + if (r == ARCHIVE_OK) + r = xml_start(a, (const char *)name, &list); + xmlattr_cleanup(&list); + ud->state = r; +} + +static void +expat_end_cb(void *userData, const XML_Char *name) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + + xml_end(ud->archive, (const char *)name); +} + +static void +expat_data_cb(void *userData, const XML_Char *s, int len) +{ + struct expat_userData *ud = (struct expat_userData *)userData; + + xml_data(ud->archive, s, len); +} + +static int +expat_read_toc(struct archive_read *a) +{ + struct xar *xar; + XML_Parser parser; + struct expat_userData ud; + + ud.state = ARCHIVE_OK; + ud.archive = a; + + xar = (struct xar *)(a->format->data); + + /* Initialize XML Parser library. */ + parser = XML_ParserCreate(NULL); + if (parser == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Couldn't allocate memory for xml parser"); + return (ARCHIVE_FATAL); + } + XML_SetUserData(parser, &ud); + XML_SetElementHandler(parser, expat_start_cb, expat_end_cb); + XML_SetCharacterDataHandler(parser, expat_data_cb); + xar->xmlsts = INIT; + + while (xar->toc_remaining && ud.state == ARCHIVE_OK) { + enum XML_Status xr; + const void *d; + size_t outbytes; + size_t used; + int r; + + d = NULL; + r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining); + if (r != ARCHIVE_OK) + return (r); + xar->toc_remaining -= used; + xar->offset += used; + xar->toc_total += outbytes; + PRINT_TOC(d, outbytes); + + xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0); + __archive_read_consume(a, used); + if (xr == XML_STATUS_ERROR) { + XML_ParserFree(parser); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "XML Parsing failed"); + return (ARCHIVE_FATAL); + } + } + XML_ParserFree(parser); + return (ud.state); +} +#endif /* defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) */ + +#endif /* Support xar format */ diff --git a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c index 31b68c6db..d15080263 100644 --- a/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_read_support_format_zip.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2004 Tim Kientzle + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,22 +25,21 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_zip.c,v 1.28 2008/12/06 06:45:15 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_zip.c 201102 2009-12-28 03:11:36Z kientzle $"); #ifdef HAVE_ERRNO_H #include #endif -#include #ifdef HAVE_STDLIB_H #include #endif -#include #ifdef HAVE_ZLIB_H #include #endif #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_read_private.h" #include "archive_endian.h" @@ -48,856 +48,1219 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_read_support_format_zip.c,v 1.28 #include "archive_crc32.h" #endif +struct zip_entry { + int64_t local_header_offset; + int64_t compressed_size; + int64_t uncompressed_size; + int64_t gid; + int64_t uid; + struct archive_entry *entry; + time_t mtime; + time_t atime; + time_t ctime; + uint32_t crc32; + uint16_t mode; + uint16_t flags; + char compression; + char system; +}; + struct zip { - /* entry_bytes_remaining is the number of bytes we expect. */ - int64_t entry_bytes_remaining; - int64_t entry_offset; - - /* These count the number of bytes actually read for the entry. */ - int64_t entry_compressed_bytes_read; - int64_t entry_uncompressed_bytes_read; - - /* Running CRC32 of the decompressed data */ - unsigned long entry_crc32; - - unsigned version; - unsigned system; - unsigned flags; - unsigned compression; - const char * compression_name; - time_t mtime; - time_t ctime; - time_t atime; - mode_t mode; - uid_t uid; - gid_t gid; - - /* Flags to mark progress of decompression. */ - char decompress_init; - char end_of_entry; - - unsigned long crc32; - ssize_t filename_length; - ssize_t extra_length; - int64_t uncompressed_size; - int64_t compressed_size; - - unsigned char *uncompressed_buffer; - size_t uncompressed_buffer_size; + /* Structural information about the archive. */ + int64_t central_directory_offset; + size_t central_directory_size; + size_t central_directory_entries; + char have_central_directory; + + /* List of entries (seekable Zip only) */ + size_t entries_remaining; + struct zip_entry *zip_entries; + struct zip_entry *entry; + + size_t unconsumed; + + /* entry_bytes_remaining is the number of bytes we expect. */ + int64_t entry_bytes_remaining; + + /* These count the number of bytes actually read for the entry. */ + int64_t entry_compressed_bytes_read; + int64_t entry_uncompressed_bytes_read; + + /* Running CRC32 of the decompressed data */ + unsigned long entry_crc32; + + /* Flags to mark progress of decompression. */ + char decompress_init; + char end_of_entry; + + ssize_t filename_length; + ssize_t extra_length; + + unsigned char *uncompressed_buffer; + size_t uncompressed_buffer_size; #ifdef HAVE_ZLIB_H - z_stream stream; - char stream_valid; + z_stream stream; + char stream_valid; #endif - struct archive_string pathname; - struct archive_string extra; - char format_name[64]; + struct archive_string extra; + struct archive_string_conv *sconv; + struct archive_string_conv *sconv_default; + struct archive_string_conv *sconv_utf8; + int init_default_conversion; + char format_name[64]; }; -#define ZIP_LENGTH_AT_END 8 - -struct zip_file_header { - char signature[4]; - char version[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; -}; +#define ZIP_LENGTH_AT_END 8 +#define ZIP_ENCRYPTED (1<<0) +#define ZIP_STRONG_ENCRYPTED (1<<6) +#define ZIP_UTF8_NAME (1<<11) + +static int archive_read_format_zip_streamable_bid(struct archive_read *, int); +static int archive_read_format_zip_seekable_bid(struct archive_read *, int); +static int archive_read_format_zip_options(struct archive_read *, + const char *, const char *); +static int archive_read_format_zip_cleanup(struct archive_read *); +static int archive_read_format_zip_read_data(struct archive_read *, + const void **, size_t *, int64_t *); +static int archive_read_format_zip_read_data_skip(struct archive_read *a); +static int archive_read_format_zip_seekable_read_header(struct archive_read *, + struct archive_entry *); +static int archive_read_format_zip_streamable_read_header(struct archive_read *, + struct archive_entry *); +#ifdef HAVE_ZLIB_H +static int zip_read_data_deflate(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset); +#endif +static int zip_read_data_none(struct archive_read *a, const void **buff, + size_t *size, int64_t *offset); +static int zip_read_local_file_header(struct archive_read *a, + struct archive_entry *entry, struct zip *); +static time_t zip_time(const char *); +static const char *compression_name(int compression); +static void process_extra(const char *, size_t, struct zip_entry *); -static const char *compression_names[] = { - "uncompressed", - "shrinking", - "reduced-1", - "reduced-2", - "reduced-3", - "reduced-4", - "imploded", - "reserved", - "deflation" -}; +int +archive_read_support_format_zip_streamable(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_zip"); + + zip = (struct zip *)malloc(sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + memset(zip, 0, sizeof(*zip)); + + r = __archive_read_register_format(a, + zip, + "zip", + archive_read_format_zip_streamable_bid, + archive_read_format_zip_options, + archive_read_format_zip_streamable_read_header, + archive_read_format_zip_read_data, + archive_read_format_zip_read_data_skip, + archive_read_format_zip_cleanup); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} -static int archive_read_format_zip_bid(struct archive_read *); -static int archive_read_format_zip_cleanup(struct archive_read *); -static int archive_read_format_zip_read_data(struct archive_read *, - const void **, size_t *, off_t *); -static int archive_read_format_zip_read_data_skip(struct archive_read *a); -static int archive_read_format_zip_read_header(struct archive_read *, - struct archive_entry *); -static int zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset); -static int zip_read_data_none(struct archive_read *a, const void **buff, - size_t *size, off_t *offset); -static int zip_read_file_header(struct archive_read *a, - struct archive_entry *entry, struct zip *zip); -static time_t zip_time(const char *); -static void process_extra(const void* extra, struct zip* zip); +int +archive_read_support_format_zip_seekable(struct archive *_a) +{ + struct archive_read *a = (struct archive_read *)_a; + struct zip *zip; + int r; + + archive_check_magic(_a, ARCHIVE_READ_MAGIC, + ARCHIVE_STATE_NEW, "archive_read_support_format_zip_seekable"); + + zip = (struct zip *)malloc(sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + memset(zip, 0, sizeof(*zip)); + + r = __archive_read_register_format(a, + zip, + "zip", + archive_read_format_zip_seekable_bid, + archive_read_format_zip_options, + archive_read_format_zip_seekable_read_header, + archive_read_format_zip_read_data, + archive_read_format_zip_read_data_skip, + archive_read_format_zip_cleanup); + + if (r != ARCHIVE_OK) + free(zip); + return (ARCHIVE_OK); +} int -archive_read_support_format_zip(struct archive *_a) +archive_read_support_format_zip(struct archive *a) +{ + int r; + r = archive_read_support_format_zip_streamable(a); + if (r != ARCHIVE_OK) + return r; + return (archive_read_support_format_zip_seekable(a)); +} + +/* + * TODO: This is a performance sink because it forces + * the read core to drop buffered data from the start + * of file, which will then have to be re-read again + * if this bidder loses. + * + * Consider passing in the winning bid value to subsequent + * bidders so that this bidder in particular can avoid + * seeking if it knows it's going to lose anyway. + */ +static int +archive_read_format_zip_seekable_bid(struct archive_read *a, int best_bid) { - struct archive_read *a = (struct archive_read *)_a; - struct zip *zip; - int r; - - zip = (struct zip *)malloc(sizeof(*zip)); - if (zip == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); - return (ARCHIVE_FATAL); - } - memset(zip, 0, sizeof(*zip)); - - r = __archive_read_register_format(a, - zip, - "zip", - archive_read_format_zip_bid, - NULL, - archive_read_format_zip_read_header, - archive_read_format_zip_read_data, - archive_read_format_zip_read_data_skip, - archive_read_format_zip_cleanup); - - if (r != ARCHIVE_OK) - free(zip); - return (ARCHIVE_OK); + struct zip *zip = (struct zip *)a->format->data; + int64_t filesize; + const char *p; + + /* If someone has already bid more than 32, then avoid + trashing the look-ahead buffers with a seek. */ + if (best_bid > 32) + return (-1); + + filesize = __archive_read_seek(a, -22, SEEK_END); + /* If we can't seek, then we can't bid. */ + if (filesize <= 0) + return 0; + + /* TODO: More robust search for end of central directory record. */ + if ((p = __archive_read_ahead(a, 22, NULL)) == NULL) + return 0; + /* First four bytes are signature for end of central directory + record. Four zero bytes ensure this isn't a multi-volume + Zip file (which we don't yet support). */ + if (memcmp(p, "PK\005\006\000\000\000\000", 8) != 0) + return 0; + + /* Since we've already done the hard work of finding the + end of central directory record, let's save the important + information. */ + zip->central_directory_entries = archive_le16dec(p + 10); + zip->central_directory_size = archive_le32dec(p + 12); + zip->central_directory_offset = archive_le32dec(p + 16); + + /* Just one volume, so central dir must all be on this volume. */ + if (zip->central_directory_entries != archive_le16dec(p + 8)) + return 0; + /* Central directory can't extend beyond end of this file. */ + if (zip->central_directory_offset + zip->central_directory_size > filesize) + return 0; + + /* This is just a tiny bit higher than the maximum returned by + the streaming Zip bidder. This ensures that the more accurate + seeking Zip parser wins whenever seek is available. */ + return 32; } +static int +slurp_central_directory(struct archive_read *a, struct zip *zip) +{ + unsigned i; + + __archive_read_seek(a, zip->central_directory_offset, SEEK_SET); + + zip->zip_entries = calloc(zip->central_directory_entries, sizeof(struct zip_entry)); + for (i = 0; i < zip->central_directory_entries; ++i) { + struct zip_entry *zip_entry = &zip->zip_entries[i]; + size_t filename_length, extra_length, comment_length; + uint32_t external_attributes; + const char *p; + + if ((p = __archive_read_ahead(a, 46, NULL)) == NULL) + return ARCHIVE_FATAL; + if (memcmp(p, "PK\001\002", 4) != 0) { + archive_set_error(&a->archive, + -1, "Invalid central directory signature"); + return ARCHIVE_FATAL; + } + zip->have_central_directory = 1; + /* version = p[4]; */ + zip_entry->system = p[5]; + /* version_required = archive_le16dec(p + 6); */ + zip_entry->flags = archive_le16dec(p + 8); + zip_entry->compression = archive_le16dec(p + 10); + zip_entry->mtime = zip_time(p + 12); + zip_entry->crc32 = archive_le32dec(p + 16); + zip_entry->compressed_size = archive_le32dec(p + 20); + zip_entry->uncompressed_size = archive_le32dec(p + 24); + filename_length = archive_le16dec(p + 28); + extra_length = archive_le16dec(p + 30); + comment_length = archive_le16dec(p + 32); + /* disk_start = archive_le16dec(p + 34); */ /* Better be zero. */ + /* internal_attributes = archive_le16dec(p + 36); */ /* text bit */ + external_attributes = archive_le32dec(p + 38); + zip_entry->local_header_offset = archive_le32dec(p + 42); + + if (zip_entry->system == 3) { + zip_entry->mode = external_attributes >> 16; + } else { + zip_entry->mode = AE_IFREG | 0777; + } + + /* Do we need to parse filename here? */ + /* Or can we wait until we read the local header? */ + __archive_read_consume(a, + 46 + filename_length + extra_length + comment_length); + } + + /* TODO: Sort zip entries. */ + + return ARCHIVE_OK; +} static int -archive_read_format_zip_bid(struct archive_read *a) +archive_read_format_zip_seekable_read_header(struct archive_read *a, + struct archive_entry *entry) { - const char *p; - const void *buff; - ssize_t bytes_avail, offset; - - if ((p = __archive_read_ahead(a, 4, NULL)) == NULL) - return (-1); - - /* - * Bid of 30 here is: 16 bits for "PK", - * next 16-bit field has four options (-2 bits). - * 16 + 16-2 = 30. - */ - if (p[0] == 'P' && p[1] == 'K') { - if ((p[2] == '\001' && p[3] == '\002') - || (p[2] == '\003' && p[3] == '\004') - || (p[2] == '\005' && p[3] == '\006') - || (p[2] == '\007' && p[3] == '\010') - || (p[2] == '0' && p[3] == '0')) - return (30); - } - - /* - * Attempt to handle self-extracting archives - * by noting a PE header and searching forward - * up to 128k for a 'PK\003\004' marker. - */ - if (p[0] == 'M' && p[1] == 'Z') { - /* - * TODO: Optimize by initializing 'offset' to an - * estimate of the likely start of the archive data - * based on values in the PE header. Note that we - * don't need to be exact, but we mustn't skip too - * far. The search below will compensate if we - * undershoot. - */ - offset = 0; - while (offset < 124000) { - /* Get 4k of data beyond where we stopped. */ - buff = __archive_read_ahead(a, offset + 4096, - &bytes_avail); - if (bytes_avail < offset + 1) - break; - p = (const char *)buff + offset; - while (p + 9 < (const char *)buff + bytes_avail) { - if (p[0] == 'P' && p[1] == 'K' /* signature */ - && p[2] == 3 && p[3] == 4 /* File entry */ - && p[8] == 8 /* compression == deflate */ - && p[9] == 0 /* High byte of compression */ - ) - { - return (30); - } - ++p; - } - offset = p - (const char *)buff; - } - } - - return (0); + struct zip *zip = (struct zip *)a->format->data; + int r; + + a->archive.archive_format = ARCHIVE_FORMAT_ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "ZIP"; + + if (zip->zip_entries == NULL) { + r = slurp_central_directory(a, zip); + zip->entries_remaining = zip->central_directory_entries; + if (r != ARCHIVE_OK) + return r; + zip->entry = zip->zip_entries; + } else { + ++zip->entry; + } + + if (zip->entries_remaining <= 0) + return ARCHIVE_EOF; + --zip->entries_remaining; + + /* TODO: If entries are sorted by offset within the file, we + should be able to skip here instead of seeking. Skipping is + typically faster (easier for I/O layer to optimize). */ + __archive_read_seek(a, zip->entry->local_header_offset, SEEK_SET); + zip->unconsumed = 0; + r = zip_read_local_file_header(a, entry, zip); + if (r != ARCHIVE_OK) + return r; + if ((zip->entry->mode & AE_IFMT) == AE_IFLNK) { + const void *p; + size_t linkname_length = archive_entry_size(entry); + + archive_entry_set_size(entry, 0); + p = __archive_read_ahead(a, linkname_length, NULL); + if (p == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Truncated Zip file"); + return ARCHIVE_FATAL; + } + + if (archive_entry_copy_symlink_l(entry, p, linkname_length, + NULL) != 0) { + /* NOTE: If the last argument is NULL, this will + * fail only by memeory allocation failure. */ + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Symlink"); + return (ARCHIVE_FATAL); + } + /* TODO: handle character-set issues? */ + } + return ARCHIVE_OK; } -/* - * Search forward for a "PK\003\004" file header. This handles the - * case of self-extracting archives, where there is an executable - * prepended to the ZIP archive. - */ static int -skip_sfx(struct archive_read *a) +archive_read_format_zip_streamable_bid(struct archive_read *a, int best_bid) { - const void *h; - const char *p, *q; - size_t skip; - ssize_t bytes; - - /* - * TODO: We should be able to skip forward by a bunch - * by lifting some values from the PE header. We don't - * need to be exact (we're still going to search forward - * to find the header), but it will speed things up and - * reduce the chance of a false positive. - */ - for (;;) { - h = __archive_read_ahead(a, 4, &bytes); - if (bytes < 4) - return (ARCHIVE_FATAL); - p = h; - q = p + bytes; - - /* - * Scan ahead until we find something that looks - * like the zip header. - */ - while (p + 4 < q) { - switch (p[3]) { - case '\004': - /* TODO: Additional verification here. */ - if (memcmp("PK\003\004", p, 4) == 0) { - skip = p - (const char *)h; - __archive_read_consume(a, skip); - return (ARCHIVE_OK); - } - p += 4; - break; - case '\003': p += 1; break; - case 'K': p += 2; break; - case 'P': p += 3; break; - default: p += 4; break; - } - } - skip = p - (const char *)h; - __archive_read_consume(a, skip); - } + const char *p; + + (void)best_bid; /* UNUSED */ + + if ((p = __archive_read_ahead(a, 4, NULL)) == NULL) + return (-1); + + /* + * Bid of 30 here is: 16 bits for "PK", + * next 16-bit field has four options (-2 bits). + * 16 + 16-2 = 30. + */ + if (p[0] == 'P' && p[1] == 'K') { + if ((p[2] == '\001' && p[3] == '\002') + || (p[2] == '\003' && p[3] == '\004') + || (p[2] == '\005' && p[3] == '\006') + || (p[2] == '\007' && p[3] == '\010') + || (p[2] == '0' && p[3] == '0')) + return (30); + } + + return (0); } static int -archive_read_format_zip_read_header(struct archive_read *a, +archive_read_format_zip_options(struct archive_read *a, + const char *key, const char *val) +{ + struct zip *zip; + int ret = ARCHIVE_FAILED; + + zip = (struct zip *)(a->format->data); + if (strcmp(key, "compat-2x") == 0) { + /* Handle filnames as libarchive 2.x */ + zip->init_default_conversion = (val != NULL) ? 1 : 0; + ret = ARCHIVE_OK; + } else if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zip: hdrcharset option needs a character-set name"); + else { + zip->sconv = archive_string_conversion_from_charset( + &a->archive, val, 0); + if (zip->sconv != NULL) { + if (strcmp(val, "UTF-8") == 0) + zip->sconv_utf8 = zip->sconv; + ret = ARCHIVE_OK; + } else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zip: unknown keyword ``%s''", key); + + return (ret); +} + +static int +archive_read_format_zip_streamable_read_header(struct archive_read *a, struct archive_entry *entry) { - const void *h; - const char *signature; - struct zip *zip; - int r = ARCHIVE_OK, r1; - - a->archive.archive_format = ARCHIVE_FORMAT_ZIP; - if (a->archive.archive_format_name == NULL) - a->archive.archive_format_name = "ZIP"; - - zip = (struct zip *)(a->format->data); - zip->decompress_init = 0; - zip->end_of_entry = 0; - zip->entry_uncompressed_bytes_read = 0; - zip->entry_compressed_bytes_read = 0; - zip->entry_crc32 = crc32(0, NULL, 0); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - - signature = (const char *)h; - if (signature[0] == 'M' && signature[1] == 'Z') { - /* This is an executable? Must be self-extracting... */ - r = skip_sfx(a); - if (r < ARCHIVE_WARN) - return (r); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - signature = (const char *)h; - } - - if (signature[0] != 'P' || signature[1] != 'K') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Bad ZIP file"); - return (ARCHIVE_FATAL); - } - - /* - * "PK00" signature is used for "split" archives that - * only have a single segment. This means we can just - * skip the PK00; the first real file header should follow. - */ - if (signature[2] == '0' && signature[3] == '0') { - __archive_read_consume(a, 4); - if ((h = __archive_read_ahead(a, 4, NULL)) == NULL) - return (ARCHIVE_FATAL); - signature = (const char *)h; - if (signature[0] != 'P' || signature[1] != 'K') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Bad ZIP file"); - return (ARCHIVE_FATAL); - } - } - - if (signature[2] == '\001' && signature[3] == '\002') { - /* Beginning of central directory. */ - return (ARCHIVE_EOF); - } - - if (signature[2] == '\003' && signature[3] == '\004') { - /* Regular file entry. */ - r1 = zip_read_file_header(a, entry, zip); - if (r1 != ARCHIVE_OK) - return (r1); - return (r); - } - - if (signature[2] == '\005' && signature[3] == '\006') { - /* End-of-archive record. */ - return (ARCHIVE_EOF); - } - - if (signature[2] == '\007' && signature[3] == '\010') { - /* - * We should never encounter this record here; - * see ZIP_LENGTH_AT_END handling below for details. - */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Bad ZIP file: Unexpected end-of-entry record"); - return (ARCHIVE_FATAL); - } - - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Damaged ZIP file or unsupported format variant (%d,%d)", - signature[2], signature[3]); - return (ARCHIVE_FATAL); + struct zip *zip; + + a->archive.archive_format = ARCHIVE_FORMAT_ZIP; + if (a->archive.archive_format_name == NULL) + a->archive.archive_format_name = "ZIP"; + + zip = (struct zip *)(a->format->data); + + /* Make sure we have a zip_entry structure to use. */ + if (zip->zip_entries == NULL) { + zip->zip_entries = malloc(sizeof(struct zip_entry)); + if (zip->zip_entries == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return ARCHIVE_FATAL; + } + } + zip->entry = zip->zip_entries; + memset(zip->entry, 0, sizeof(struct zip_entry)); + + /* Search ahead for the next local file header. */ + __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + for (;;) { + int64_t skipped = 0; + const char *p, *end; + ssize_t bytes; + + p = __archive_read_ahead(a, 4, &bytes); + if (p == NULL) + return (ARCHIVE_FATAL); + end = p + bytes; + + while (p + 4 <= end) { + if (p[0] == 'P' && p[1] == 'K') { + if (p[2] == '\001' && p[3] == '\002') + /* Beginning of central directory. */ + return (ARCHIVE_EOF); + + if (p[2] == '\003' && p[3] == '\004') { + /* Regular file entry. */ + __archive_read_consume(a, skipped); + return zip_read_local_file_header(a, entry, zip); + } + + if (p[2] == '\005' && p[3] == '\006') + /* End of central directory. */ + return (ARCHIVE_EOF); + } + ++p; + ++skipped; + } + __archive_read_consume(a, skipped); + } } +/* + * Assumes file pointer is at beginning of local file header. + */ static int -zip_read_file_header(struct archive_read *a, struct archive_entry *entry, +zip_read_local_file_header(struct archive_read *a, struct archive_entry *entry, struct zip *zip) { - const struct zip_file_header *p; - const void *h; - - if ((p = __archive_read_ahead(a, sizeof *p, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - - zip->version = p->version[0]; - zip->system = p->version[1]; - zip->flags = archive_le16dec(p->flags); - zip->compression = archive_le16dec(p->compression); - if (zip->compression < - sizeof(compression_names)/sizeof(compression_names[0])) - zip->compression_name = compression_names[zip->compression]; - else - zip->compression_name = "??"; - zip->mtime = zip_time(p->timedate); - zip->ctime = 0; - zip->atime = 0; - zip->mode = 0; - zip->uid = 0; - zip->gid = 0; - zip->crc32 = archive_le32dec(p->crc32); - zip->filename_length = archive_le16dec(p->filename_length); - zip->extra_length = archive_le16dec(p->extra_length); - zip->uncompressed_size = archive_le32dec(p->uncompressed_size); - zip->compressed_size = archive_le32dec(p->compressed_size); - - __archive_read_consume(a, sizeof(struct zip_file_header)); - - - /* Read the filename. */ - if ((h = __archive_read_ahead(a, zip->filename_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - if (archive_string_ensure(&zip->pathname, zip->filename_length) == NULL) - __archive_errx(1, "Out of memory"); - archive_strncpy(&zip->pathname, h, zip->filename_length); - __archive_read_consume(a, zip->filename_length); - archive_entry_set_pathname(entry, zip->pathname.s); - - if (zip->pathname.s[archive_strlen(&zip->pathname) - 1] == '/') - zip->mode = AE_IFDIR | 0777; - else - zip->mode = AE_IFREG | 0777; - - /* Read the extra data. */ - if ((h = __archive_read_ahead(a, zip->extra_length, NULL)) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file header"); - return (ARCHIVE_FATAL); - } - process_extra(h, zip); - __archive_read_consume(a, zip->extra_length); - - /* Populate some additional entry fields: */ - archive_entry_set_mode(entry, zip->mode); - archive_entry_set_uid(entry, zip->uid); - archive_entry_set_gid(entry, zip->gid); - archive_entry_set_mtime(entry, zip->mtime, 0); - archive_entry_set_ctime(entry, zip->ctime, 0); - archive_entry_set_atime(entry, zip->atime, 0); - /* Set the size only if it's meaningful. */ - if (0 == (zip->flags & ZIP_LENGTH_AT_END)) - archive_entry_set_size(entry, zip->uncompressed_size); - - zip->entry_bytes_remaining = zip->compressed_size; - zip->entry_offset = 0; - - /* If there's no body, force read_data() to return EOF immediately. */ - if (0 == (zip->flags & ZIP_LENGTH_AT_END) - && zip->entry_bytes_remaining < 1) - zip->end_of_entry = 1; - - /* Set up a more descriptive format name. */ - sprintf(zip->format_name, "ZIP %d.%d (%s)", - zip->version / 10, zip->version % 10, - zip->compression_name); - a->archive.archive_format_name = zip->format_name; - - return (ARCHIVE_OK); + const char *p; + const void *h; + const wchar_t *wp; + const char *cp; + size_t len, filename_length, extra_length; + struct archive_string_conv *sconv; + struct zip_entry *zip_entry = zip->entry; + uint32_t local_crc32; + int64_t compressed_size, uncompressed_size; + int ret = ARCHIVE_OK; + char version; + + zip->decompress_init = 0; + zip->end_of_entry = 0; + zip->entry_uncompressed_bytes_read = 0; + zip->entry_compressed_bytes_read = 0; + zip->entry_crc32 = crc32(0, NULL, 0); + + /* Setup default conversion. */ + if (zip->sconv == NULL && !zip->init_default_conversion) { + zip->sconv_default = + archive_string_default_conversion_for_read(&(a->archive)); + zip->init_default_conversion = 1; + } + + if ((p = __archive_read_ahead(a, 30, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + + if (memcmp(p, "PK\003\004", 4) != 0) { + archive_set_error(&a->archive, -1, "Damaged Zip archive"); + return ARCHIVE_FATAL; + } + version = p[4]; + zip_entry->system = p[5]; + zip_entry->flags = archive_le16dec(p + 6); + zip_entry->compression = archive_le16dec(p + 8); + zip_entry->mtime = zip_time(p + 10); + local_crc32 = archive_le32dec(p + 14); + compressed_size = archive_le32dec(p + 18); + uncompressed_size = archive_le32dec(p + 22); + filename_length = archive_le16dec(p + 26); + extra_length = archive_le16dec(p + 28); + + __archive_read_consume(a, 30); + + if (zip->have_central_directory) { + /* If we read the central dir entry, we must have size information + as well, so ignore the length-at-end flag. */ + zip_entry->flags &= ~ZIP_LENGTH_AT_END; + /* If we have values from both the local file header + and the central directory, warn about mismatches + which might indicate a damaged file. But some + writers always put zero in the local header; don't + bother warning about that. */ + if (local_crc32 != 0 && local_crc32 != zip_entry->crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent CRC32 values"); + ret = ARCHIVE_WARN; + } + if (compressed_size != 0 + && compressed_size != zip_entry->compressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent compressed size"); + ret = ARCHIVE_WARN; + } + if (uncompressed_size != 0 + && uncompressed_size != zip_entry->uncompressed_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Inconsistent uncompressed size"); + ret = ARCHIVE_WARN; + } + } else { + /* If we don't have the CD info, use whatever we do have. */ + zip_entry->crc32 = local_crc32; + zip_entry->compressed_size = compressed_size; + zip_entry->uncompressed_size = uncompressed_size; + } + + /* Read the filename. */ + if ((h = __archive_read_ahead(a, filename_length, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + if (zip_entry->flags & ZIP_UTF8_NAME) { + /* The filename is stored to be UTF-8. */ + if (zip->sconv_utf8 == NULL) { + zip->sconv_utf8 = + archive_string_conversion_from_charset( + &a->archive, "UTF-8", 1); + if (zip->sconv_utf8 == NULL) + return (ARCHIVE_FATAL); + } + sconv = zip->sconv_utf8; + } else if (zip->sconv != NULL) + sconv = zip->sconv; + else + sconv = zip->sconv_default; + + if (archive_entry_copy_pathname_l(entry, + h, filename_length, sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Pathname cannot be converted " + "from %s to current locale.", + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + __archive_read_consume(a, filename_length); + + if (zip_entry->mode == 0) { + /* Especially in streaming mode, we can end up + here without having seen any mode information. + Guess from the filename. */ + wp = archive_entry_pathname_w(entry); + if (wp != NULL) { + len = wcslen(wp); + if (len > 0 && wp[len - 1] == L'/') + zip_entry->mode = AE_IFDIR | 0777; + else + zip_entry->mode = AE_IFREG | 0777; + } else { + cp = archive_entry_pathname(entry); + len = (cp != NULL)?strlen(cp):0; + if (len > 0 && cp[len - 1] == '/') + zip_entry->mode = AE_IFDIR | 0777; + else + zip_entry->mode = AE_IFREG | 0777; + } + } + + /* Read the extra data. */ + if ((h = __archive_read_ahead(a, extra_length, NULL)) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file header"); + return (ARCHIVE_FATAL); + } + process_extra(h, extra_length, zip_entry); + __archive_read_consume(a, extra_length); + + /* Populate some additional entry fields: */ + archive_entry_set_mode(entry, zip_entry->mode); + archive_entry_set_uid(entry, zip_entry->uid); + archive_entry_set_gid(entry, zip_entry->gid); + archive_entry_set_mtime(entry, zip_entry->mtime, 0); + archive_entry_set_ctime(entry, zip_entry->ctime, 0); + archive_entry_set_atime(entry, zip_entry->atime, 0); + /* Set the size only if it's meaningful. */ + if (0 == (zip_entry->flags & ZIP_LENGTH_AT_END)) + archive_entry_set_size(entry, zip_entry->uncompressed_size); + + zip->entry_bytes_remaining = zip_entry->compressed_size; + + /* If there's no body, force read_data() to return EOF immediately. */ + if (0 == (zip_entry->flags & ZIP_LENGTH_AT_END) + && zip->entry_bytes_remaining < 1) + zip->end_of_entry = 1; + + /* Set up a more descriptive format name. */ + sprintf(zip->format_name, "ZIP %d.%d (%s)", + version / 10, version % 10, + compression_name(zip->entry->compression)); + a->archive.archive_format_name = zip->format_name; + + return (ret); +} + +static const char * +compression_name(int compression) +{ + static const char *compression_names[] = { + "uncompressed", + "shrinking", + "reduced-1", + "reduced-2", + "reduced-3", + "reduced-4", + "imploded", + "reserved", + "deflation" + }; + + if (compression < + sizeof(compression_names)/sizeof(compression_names[0])) + return compression_names[compression]; + else + return "??"; } /* Convert an MSDOS-style date/time into Unix-style time. */ static time_t zip_time(const char *p) { - int msTime, msDate; - struct tm ts; - - msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]); - msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]); - - memset(&ts, 0, sizeof(ts)); - ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ - ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ - ts.tm_mday = msDate & 0x1f; /* Day of month. */ - ts.tm_hour = (msTime >> 11) & 0x1f; - ts.tm_min = (msTime >> 5) & 0x3f; - ts.tm_sec = (msTime << 1) & 0x3e; - ts.tm_isdst = -1; - return mktime(&ts); + int msTime, msDate; + struct tm ts; + + msTime = (0xff & (unsigned)p[0]) + 256 * (0xff & (unsigned)p[1]); + msDate = (0xff & (unsigned)p[2]) + 256 * (0xff & (unsigned)p[3]); + + memset(&ts, 0, sizeof(ts)); + ts.tm_year = ((msDate >> 9) & 0x7f) + 80; /* Years since 1900. */ + ts.tm_mon = ((msDate >> 5) & 0x0f) - 1; /* Month number. */ + ts.tm_mday = msDate & 0x1f; /* Day of month. */ + ts.tm_hour = (msTime >> 11) & 0x1f; + ts.tm_min = (msTime >> 5) & 0x3f; + ts.tm_sec = (msTime << 1) & 0x3e; + ts.tm_isdst = -1; + return mktime(&ts); } static int archive_read_format_zip_read_data(struct archive_read *a, - const void **buff, size_t *size, off_t *offset) + const void **buff, size_t *size, int64_t *offset) { - int r; - struct zip *zip; - - zip = (struct zip *)(a->format->data); - - /* - * If we hit end-of-entry last time, clean up and return - * ARCHIVE_EOF this time. - */ - if (zip->end_of_entry) { - *offset = zip->entry_uncompressed_bytes_read; - *size = 0; - *buff = NULL; - return (ARCHIVE_EOF); - } - - switch(zip->compression) { - case 0: /* No compression. */ - r = zip_read_data_none(a, buff, size, offset); - break; - case 8: /* Deflate compression. */ - r = zip_read_data_deflate(a, buff, size, offset); - break; - default: /* Unsupported compression. */ - *buff = NULL; - *size = 0; - *offset = 0; - /* Return a warning. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Unsupported ZIP compression method (%s)", - zip->compression_name); - if (zip->flags & ZIP_LENGTH_AT_END) { - /* - * ZIP_LENGTH_AT_END requires us to - * decompress the entry in order to - * skip it, but we don't know this - * compression method, so we give up. - */ - r = ARCHIVE_FATAL; - } else { - /* We can't decompress this entry, but we will - * be able to skip() it and try the next entry. */ - r = ARCHIVE_WARN; - } - break; - } - if (r != ARCHIVE_OK) - return (r); - /* Update checksum */ - if (*size) - zip->entry_crc32 = crc32(zip->entry_crc32, *buff, *size); - /* If we hit the end, swallow any end-of-data marker. */ - if (zip->end_of_entry) { - if (zip->flags & ZIP_LENGTH_AT_END) { - const char *p; - - if ((p = __archive_read_ahead(a, 16, NULL)) == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP end-of-file record"); - return (ARCHIVE_FATAL); - } - zip->crc32 = archive_le32dec(p + 4); - zip->compressed_size = archive_le32dec(p + 8); - zip->uncompressed_size = archive_le32dec(p + 12); - __archive_read_consume(a, 16); - } - /* Check file size, CRC against these values. */ - if (zip->compressed_size != zip->entry_compressed_bytes_read) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP compressed data is wrong size"); - return (ARCHIVE_WARN); - } - /* Size field only stores the lower 32 bits of the actual size. */ - if ((zip->uncompressed_size & UINT32_MAX) - != (zip->entry_uncompressed_bytes_read & UINT32_MAX)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP uncompressed data is wrong size"); - return (ARCHIVE_WARN); - } - /* Check computed CRC against header */ - if (zip->crc32 != zip->entry_crc32) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP bad CRC: 0x%lx should be 0x%lx", - zip->entry_crc32, zip->crc32); - return (ARCHIVE_WARN); - } - } - - /* Return EOF immediately if this is a non-regular file. */ - if (AE_IFREG != (zip->mode & AE_IFMT)) - return (ARCHIVE_EOF); - return (ARCHIVE_OK); + int r; + struct zip *zip = (struct zip *)(a->format->data); + + *offset = zip->entry_uncompressed_bytes_read; + *size = 0; + *buff = NULL; + + /* If we hit end-of-entry last time, return ARCHIVE_EOF. */ + if (zip->end_of_entry) + return (ARCHIVE_EOF); + + /* Return EOF immediately if this is a non-regular file. */ + if (AE_IFREG != (zip->entry->mode & AE_IFMT)) + return (ARCHIVE_EOF); + + if (zip->entry->flags & (ZIP_ENCRYPTED | ZIP_STRONG_ENCRYPTED)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Encrypted file is unsupported"); + return (ARCHIVE_FAILED); + } + + __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + + switch(zip->entry->compression) { + case 0: /* No compression. */ + r = zip_read_data_none(a, buff, size, offset); + break; +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ + r = zip_read_data_deflate(a, buff, size, offset); + break; +#endif + default: /* Unsupported compression. */ + /* Return a warning. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Unsupported ZIP compression method (%s)", + compression_name(zip->entry->compression)); + /* We can't decompress this entry, but we will + * be able to skip() it and try the next entry. */ + return (ARCHIVE_FAILED); + break; + } + if (r != ARCHIVE_OK) + return (r); + /* Update checksum */ + if (*size) + zip->entry_crc32 = crc32(zip->entry_crc32, *buff, *size); + /* If we hit the end, swallow any end-of-data marker. */ + if (zip->end_of_entry) { + /* Check file size, CRC against these values. */ + if (zip->entry->compressed_size != zip->entry_compressed_bytes_read) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP compressed data is wrong size (read %jd, expected %jd)", + (intmax_t)zip->entry_compressed_bytes_read, + (intmax_t)zip->entry->compressed_size); + return (ARCHIVE_WARN); + } + /* Size field only stores the lower 32 bits of the actual + * size. */ + if ((zip->entry->uncompressed_size & UINT32_MAX) + != (zip->entry_uncompressed_bytes_read & UINT32_MAX)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP uncompressed data is wrong size (read %jd, expected %jd)", + (intmax_t)zip->entry_uncompressed_bytes_read, + (intmax_t)zip->entry->uncompressed_size); + return (ARCHIVE_WARN); + } + /* Check computed CRC against header */ + if (zip->entry->crc32 != zip->entry_crc32) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP bad CRC: 0x%lx should be 0x%lx", + (unsigned long)zip->entry_crc32, + (unsigned long)zip->entry->crc32); + return (ARCHIVE_WARN); + } + } + + return (ARCHIVE_OK); } /* - * Read "uncompressed" data. According to the current specification, - * if ZIP_LENGTH_AT_END is specified, then the size fields in the - * initial file header are supposed to be set to zero. This would, of - * course, make it impossible for us to read the archive, since we - * couldn't determine the end of the file data. Info-ZIP seems to - * include the real size fields both before and after the data in this - * case (the CRC only appears afterwards), so this works as you would - * expect. + * Read "uncompressed" data. There are three cases: + * 1) We know the size of the data. This is always true for the + * seeking reader (we've examined the Central Directory already). + * 2) ZIP_LENGTH_AT_END was set, but only the CRC was deferred. + * Info-ZIP seems to do this; we know the size but have to grab + * the CRC from the data descriptor afterwards. + * 3) We're streaming and ZIP_LENGTH_AT_END was specified and + * we have no size information. In this case, we can do pretty + * well by watching for the data descriptor record. The data + * descriptor is 16 bytes and includes a computed CRC that should + * provide a strong check. + * + * TODO: Technically, the PK\007\010 signature is optional. + * In the original spec, the data descriptor contained CRC + * and size fields but had no leading signature. In practice, + * newer writers seem to provide the signature pretty consistently, + * but we might need to do something more complex here if + * we want to handle older archives that lack that signature. * * Returns ARCHIVE_OK if successful, ARCHIVE_FATAL otherwise, sets * zip->end_of_entry if it consumes all of the data. */ static int -zip_read_data_none(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) +zip_read_data_none(struct archive_read *a, const void **_buff, + size_t *size, int64_t *offset) { - struct zip *zip; - ssize_t bytes_avail; - - zip = (struct zip *)(a->format->data); - - if (zip->entry_bytes_remaining == 0) { - *buff = NULL; - *size = 0; - *offset = zip->entry_offset; - zip->end_of_entry = 1; - return (ARCHIVE_OK); - } - /* - * Note: '1' here is a performance optimization. - * Recall that the decompression layer returns a count of - * available bytes; asking for more than that forces the - * decompressor to combine reads by copying data. - */ - *buff = __archive_read_ahead(a, 1, &bytes_avail); - if (bytes_avail <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file data"); - return (ARCHIVE_FATAL); - } - if (bytes_avail > zip->entry_bytes_remaining) - bytes_avail = zip->entry_bytes_remaining; - __archive_read_consume(a, bytes_avail); - *size = bytes_avail; - *offset = zip->entry_offset; - zip->entry_offset += *size; - zip->entry_bytes_remaining -= *size; - zip->entry_uncompressed_bytes_read += *size; - zip->entry_compressed_bytes_read += *size; - return (ARCHIVE_OK); + struct zip *zip; + const char *buff; + ssize_t bytes_avail; + + zip = (struct zip *)(a->format->data); + + if (zip->entry->flags & ZIP_LENGTH_AT_END) { + const char *p; + + /* Grab at least 16 bytes. */ + buff = __archive_read_ahead(a, 16, &bytes_avail); + if (bytes_avail < 16) { + /* Zip archives have end-of-archive markers + that are longer than this, so a failure to get at + least 16 bytes really does indicate a truncated + file. */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + /* Check for a complete PK\007\010 signature. */ + p = buff; + if (p[0] == 'P' && p[1] == 'K' + && p[2] == '\007' && p[3] == '\010' + && archive_le32dec(p + 4) == zip->entry_crc32 + && archive_le32dec(p + 8) == zip->entry_compressed_bytes_read + && archive_le32dec(p + 12) == zip->entry_uncompressed_bytes_read) { + zip->entry->crc32 = archive_le32dec(p + 4); + zip->entry->compressed_size = archive_le32dec(p + 8); + zip->entry->uncompressed_size = archive_le32dec(p + 12); + zip->end_of_entry = 1; + zip->unconsumed = 16; + return (ARCHIVE_OK); + } + /* If not at EOF, ensure we consume at least one byte. */ + ++p; + + /* Scan forward until we see where a PK\007\010 signature might be. */ + /* Return bytes up until that point. On the next call, the code + above will verify the data descriptor. */ + while (p < buff + bytes_avail - 4) { + if (p[3] == 'P') { p += 3; } + else if (p[3] == 'K') { p += 2; } + else if (p[3] == '\007') { p += 1; } + else if (p[3] == '\010' && p[2] == '\007' + && p[1] == 'K' && p[0] == 'P') { + break; + } else { p += 4; } + } + bytes_avail = p - buff; + } else { + if (zip->entry_bytes_remaining == 0) { + zip->end_of_entry = 1; + return (ARCHIVE_OK); + } + /* Grab a bunch of bytes. */ + buff = __archive_read_ahead(a, 1, &bytes_avail); + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + if (bytes_avail > zip->entry_bytes_remaining) + bytes_avail = zip->entry_bytes_remaining; + } + *size = bytes_avail; + zip->entry_bytes_remaining -= bytes_avail; + zip->entry_uncompressed_bytes_read += bytes_avail; + zip->entry_compressed_bytes_read += bytes_avail; + zip->unconsumed += bytes_avail; + *_buff = buff; + return (ARCHIVE_OK); } #ifdef HAVE_ZLIB_H static int zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) + size_t *size, int64_t *offset) { - struct zip *zip; - ssize_t bytes_avail; - const void *compressed_buff; - int r; - - zip = (struct zip *)(a->format->data); - - /* If the buffer hasn't been allocated, allocate it now. */ - if (zip->uncompressed_buffer == NULL) { - zip->uncompressed_buffer_size = 32 * 1024; - zip->uncompressed_buffer - = (unsigned char *)malloc(zip->uncompressed_buffer_size); - if (zip->uncompressed_buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "No memory for ZIP decompression"); - return (ARCHIVE_FATAL); - } - } - - /* If we haven't yet read any data, initialize the decompressor. */ - if (!zip->decompress_init) { - if (zip->stream_valid) - r = inflateReset(&zip->stream); - else - r = inflateInit2(&zip->stream, - -15 /* Don't check for zlib header */); - if (r != Z_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Can't initialize ZIP decompression."); - return (ARCHIVE_FATAL); - } - /* Stream structure has been set up. */ - zip->stream_valid = 1; - /* We've initialized decompression for this stream. */ - zip->decompress_init = 1; - } - - /* - * Note: '1' here is a performance optimization. - * Recall that the decompression layer returns a count of - * available bytes; asking for more than that forces the - * decompressor to combine reads by copying data. - */ - compressed_buff = __archive_read_ahead(a, 1, &bytes_avail); - if (bytes_avail <= 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Truncated ZIP file body"); - return (ARCHIVE_FATAL); - } - - /* - * A bug in zlib.h: stream.next_in should be marked 'const' - * but isn't (the library never alters data through the - * next_in pointer, only reads it). The result: this ugly - * cast to remove 'const'. - */ - zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff; - zip->stream.avail_in = bytes_avail; - zip->stream.total_in = 0; - zip->stream.next_out = zip->uncompressed_buffer; - zip->stream.avail_out = zip->uncompressed_buffer_size; - zip->stream.total_out = 0; - - r = inflate(&zip->stream, 0); - switch (r) { - case Z_OK: - break; - case Z_STREAM_END: - zip->end_of_entry = 1; - break; - case Z_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Out of memory for ZIP decompression"); - return (ARCHIVE_FATAL); - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP decompression failed (%d)", r); - return (ARCHIVE_FATAL); - } - - /* Consume as much as the compressor actually used. */ - bytes_avail = zip->stream.total_in; - __archive_read_consume(a, bytes_avail); - zip->entry_bytes_remaining -= bytes_avail; - zip->entry_compressed_bytes_read += bytes_avail; - - *offset = zip->entry_offset; - *size = zip->stream.total_out; - zip->entry_uncompressed_bytes_read += *size; - *buff = zip->uncompressed_buffer; - zip->entry_offset += *size; - return (ARCHIVE_OK); -} -#else -static int -zip_read_data_deflate(struct archive_read *a, const void **buff, - size_t *size, off_t *offset) -{ - *buff = NULL; - *size = 0; - *offset = 0; - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "libarchive compiled without deflate support (no libz)"); - return (ARCHIVE_FATAL); + struct zip *zip; + ssize_t bytes_avail; + const void *compressed_buff; + int r; + + zip = (struct zip *)(a->format->data); + + /* If the buffer hasn't been allocated, allocate it now. */ + if (zip->uncompressed_buffer == NULL) { + zip->uncompressed_buffer_size = 256 * 1024; + zip->uncompressed_buffer + = (unsigned char *)malloc(zip->uncompressed_buffer_size); + if (zip->uncompressed_buffer == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for ZIP decompression"); + return (ARCHIVE_FATAL); + } + } + + /* If we haven't yet read any data, initialize the decompressor. */ + if (!zip->decompress_init) { + if (zip->stream_valid) + r = inflateReset(&zip->stream); + else + r = inflateInit2(&zip->stream, + -15 /* Don't check for zlib header */); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize ZIP decompression."); + return (ARCHIVE_FATAL); + } + /* Stream structure has been set up. */ + zip->stream_valid = 1; + /* We've initialized decompression for this stream. */ + zip->decompress_init = 1; + } + + /* + * Note: '1' here is a performance optimization. + * Recall that the decompression layer returns a count of + * available bytes; asking for more than that forces the + * decompressor to combine reads by copying data. + */ + compressed_buff = __archive_read_ahead(a, 1, &bytes_avail); + if (0 == (zip->entry->flags & ZIP_LENGTH_AT_END) + && bytes_avail > zip->entry_bytes_remaining) { + bytes_avail = zip->entry_bytes_remaining; + } + if (bytes_avail <= 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file body"); + return (ARCHIVE_FATAL); + } + + /* + * A bug in zlib.h: stream.next_in should be marked 'const' + * but isn't (the library never alters data through the + * next_in pointer, only reads it). The result: this ugly + * cast to remove 'const'. + */ + zip->stream.next_in = (Bytef *)(uintptr_t)(const void *)compressed_buff; + zip->stream.avail_in = bytes_avail; + zip->stream.total_in = 0; + zip->stream.next_out = zip->uncompressed_buffer; + zip->stream.avail_out = zip->uncompressed_buffer_size; + zip->stream.total_out = 0; + + r = inflate(&zip->stream, 0); + switch (r) { + case Z_OK: + break; + case Z_STREAM_END: + zip->end_of_entry = 1; + break; + case Z_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Out of memory for ZIP decompression"); + return (ARCHIVE_FATAL); + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "ZIP decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + + /* Consume as much as the compressor actually used. */ + bytes_avail = zip->stream.total_in; + __archive_read_consume(a, bytes_avail); + zip->entry_bytes_remaining -= bytes_avail; + zip->entry_compressed_bytes_read += bytes_avail; + + *size = zip->stream.total_out; + zip->entry_uncompressed_bytes_read += zip->stream.total_out; + *buff = zip->uncompressed_buffer; + + if (zip->end_of_entry && (zip->entry->flags & ZIP_LENGTH_AT_END)) { + const char *p; + + if (NULL == (p = __archive_read_ahead(a, 16, NULL))) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP end-of-file record"); + return (ARCHIVE_FATAL); + } + /* Consume the optional PK\007\010 marker. */ + if (p[0] == 'P' && p[1] == 'K' && p[2] == '\007' && p[3] == '\010') { + zip->entry->crc32 = archive_le32dec(p + 4); + zip->entry->compressed_size = archive_le32dec(p + 8); + zip->entry->uncompressed_size = archive_le32dec(p + 12); + zip->unconsumed = 16; + } + } + + return (ARCHIVE_OK); } #endif static int archive_read_format_zip_read_data_skip(struct archive_read *a) { - struct zip *zip; - const void *buff = NULL; - off_t bytes_skipped; - - zip = (struct zip *)(a->format->data); - - /* If we've already read to end of data, we're done. */ - if (zip->end_of_entry) - return (ARCHIVE_OK); - - /* - * If the length is at the end, we have no choice but - * to decompress all the data to find the end marker. - */ - if (zip->flags & ZIP_LENGTH_AT_END) { - size_t size; - off_t offset; - int r; - do { - r = archive_read_format_zip_read_data(a, &buff, - &size, &offset); - } while (r == ARCHIVE_OK); - return (r); - } - - /* - * If the length is at the beginning, we can skip the - * compressed data much more quickly. - */ - bytes_skipped = __archive_read_skip(a, zip->entry_bytes_remaining); - if (bytes_skipped < 0) - return (ARCHIVE_FATAL); - - /* This entry is finished and done. */ - zip->end_of_entry = 1; - return (ARCHIVE_OK); + struct zip *zip; + + zip = (struct zip *)(a->format->data); + + /* If we've already read to end of data, we're done. */ + if (zip->end_of_entry) + return (ARCHIVE_OK); + /* If we're seeking, we're done. */ + if (zip->have_central_directory) + return (ARCHIVE_OK); + + /* So we know we're streaming... */ + if (0 == (zip->entry->flags & ZIP_LENGTH_AT_END)) { + /* We know the compressed length, so we can just skip. */ + int64_t bytes_skipped = __archive_read_consume(a, + zip->entry_bytes_remaining + zip->unconsumed); + if (bytes_skipped < 0) + return (ARCHIVE_FATAL); + zip->unconsumed = 0; + return (ARCHIVE_OK); + } + + /* We're streaming and we don't know the length. */ + /* If the body is compressed and we know the format, we can + * find an exact end-of-entry by decompressing it. */ + switch (zip->entry->compression) { +#ifdef HAVE_ZLIB_H + case 8: /* Deflate compression. */ + while (!zip->end_of_entry) { + int64_t offset = 0; + const void *buff = NULL; + size_t size = 0; + int r; + r = zip_read_data_deflate(a, &buff, &size, &offset); + if (r != ARCHIVE_OK) + return (r); + } + break; +#endif + default: /* Uncompressed or unknown. */ + /* Scan for a PK\007\010 signature. */ + __archive_read_consume(a, zip->unconsumed); + zip->unconsumed = 0; + for (;;) { + const char *p, *buff; + ssize_t bytes_avail; + buff = __archive_read_ahead(a, 16, &bytes_avail); + if (bytes_avail < 16) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Truncated ZIP file data"); + return (ARCHIVE_FATAL); + } + p = buff; + while (p < buff + bytes_avail - 16) { + if (p[3] == 'P') { p += 3; } + else if (p[3] == 'K') { p += 2; } + else if (p[3] == '\007') { p += 1; } + else if (p[3] == '\010' && p[2] == '\007' + && p[1] == 'K' && p[0] == 'P') { + __archive_read_consume(a, p - buff + 16); + return ARCHIVE_OK; + } else { p += 4; } + } + __archive_read_consume(a, p - buff); + } + } + return ARCHIVE_OK; } static int archive_read_format_zip_cleanup(struct archive_read *a) { - struct zip *zip; + struct zip *zip; - zip = (struct zip *)(a->format->data); + zip = (struct zip *)(a->format->data); #ifdef HAVE_ZLIB_H - if (zip->stream_valid) - inflateEnd(&zip->stream); + if (zip->stream_valid) + inflateEnd(&zip->stream); #endif - free(zip->uncompressed_buffer); - archive_string_free(&(zip->pathname)); - archive_string_free(&(zip->extra)); - free(zip); - (a->format->data) = NULL; - return (ARCHIVE_OK); + free(zip->zip_entries); + free(zip->uncompressed_buffer); + archive_string_free(&(zip->extra)); + free(zip); + (a->format->data) = NULL; + return (ARCHIVE_OK); } /* * The extra data is stored as a list of - * id1+size1+data1 + id2+size2+data2 ... + * id1+size1+data1 + id2+size2+data2 ... * triplets. id and size are 2 bytes each. */ static void -process_extra(const void* extra, struct zip* zip) +process_extra(const char *p, size_t extra_length, struct zip_entry* zip_entry) { - int offset = 0; - const char *p = (const char *)extra; - while (offset < zip->extra_length - 4) - { - unsigned short headerid = archive_le16dec(p + offset); - unsigned short datasize = archive_le16dec(p + offset + 2); - offset += 4; - if (offset + datasize > zip->extra_length) - break; + unsigned offset = 0; + + while (offset < extra_length - 4) + { + unsigned short headerid = archive_le16dec(p + offset); + unsigned short datasize = archive_le16dec(p + offset + 2); + offset += 4; + if (offset + datasize > extra_length) + break; #ifdef DEBUG - fprintf(stderr, "Header id 0x%04x, length %d\n", - headerid, datasize); + fprintf(stderr, "Header id 0x%x, length %d\n", + headerid, datasize); #endif - switch (headerid) { - case 0x0001: - /* Zip64 extended information extra field. */ - if (datasize >= 8) - zip->uncompressed_size = archive_le64dec(p + offset); - if (datasize >= 16) - zip->compressed_size = archive_le64dec(p + offset + 8); - break; - case 0x5455: - { - /* Extended time field "UT". */ - int flags = p[offset]; - offset++; - datasize--; - /* Flag bits indicate which dates are present. */ - if (flags & 0x01) - { + switch (headerid) { + case 0x0001: + /* Zip64 extended information extra field. */ + if (datasize >= 8) + zip_entry->uncompressed_size = + archive_le64dec(p + offset); + if (datasize >= 16) + zip_entry->compressed_size = + archive_le64dec(p + offset + 8); + break; + case 0x5455: + { + /* Extended time field "UT". */ + int flags = p[offset]; + offset++; + datasize--; + /* Flag bits indicate which dates are present. */ + if (flags & 0x01) + { #ifdef DEBUG - fprintf(stderr, "mtime: %lld -> %d\n", - (long long)zip->mtime, - archive_le32dec(p + offset)); + fprintf(stderr, "mtime: %lld -> %d\n", + (long long)zip_entry->mtime, + archive_le32dec(p + offset)); #endif - if (datasize < 4) - break; - zip->mtime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - if (flags & 0x02) - { - if (datasize < 4) - break; - zip->atime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - if (flags & 0x04) - { - if (datasize < 4) - break; - zip->ctime = archive_le32dec(p + offset); - offset += 4; - datasize -= 4; - } - break; - } - case 0x7855: - /* Info-ZIP Unix Extra Field (type 2) "Ux". */ + if (datasize < 4) + break; + zip_entry->mtime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + if (flags & 0x02) + { + if (datasize < 4) + break; + zip_entry->atime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + if (flags & 0x04) + { + if (datasize < 4) + break; + zip_entry->ctime = archive_le32dec(p + offset); + offset += 4; + datasize -= 4; + } + break; + } + case 0x5855: + { + /* Info-ZIP Unix Extra Field (old version) "UX". */ + if (datasize >= 8) { + zip_entry->atime = archive_le32dec(p + offset); + zip_entry->mtime = archive_le32dec(p + offset + 4); + } + if (datasize >= 12) { + zip_entry->uid = archive_le16dec(p + offset + 8); + zip_entry->gid = archive_le16dec(p + offset + 10); + } + break; + } + case 0x7855: + /* Info-ZIP Unix Extra Field (type 2) "Ux". */ #ifdef DEBUG - fprintf(stderr, "uid %d gid %d\n", - archive_le16dec(p + offset), - archive_le16dec(p + offset + 2)); + fprintf(stderr, "uid %d gid %d\n", + archive_le16dec(p + offset), + archive_le16dec(p + offset + 2)); #endif - if (datasize >= 2) - zip->uid = archive_le16dec(p + offset); - if (datasize >= 4) - zip->gid = archive_le16dec(p + offset + 2); - break; - default: - break; - } - offset += datasize; - } + if (datasize >= 2) + zip_entry->uid = archive_le16dec(p + offset); + if (datasize >= 4) + zip_entry->gid = archive_le16dec(p + offset + 2); + break; + case 0x7875: + { + /* Info-Zip Unix Extra Field (type 3) "ux". */ + int uidsize = 0, gidsize = 0; + + if (datasize >= 1 && p[offset] == 1) {/* version=1 */ + if (datasize >= 4) { + /* get a uid size. */ + uidsize = p[offset+1]; + if (uidsize == 2) + zip_entry->uid = archive_le16dec( + p + offset + 2); + else if (uidsize == 4 && datasize >= 6) + zip_entry->uid = archive_le32dec( + p + offset + 2); + } + if (datasize >= (2 + uidsize + 3)) { + /* get a gid size. */ + gidsize = p[offset+2+uidsize]; + if (gidsize == 2) + zip_entry->gid = archive_le16dec( + p+offset+2+uidsize+1); + else if (gidsize == 4 && + datasize >= (2 + uidsize + 5)) + zip_entry->gid = archive_le32dec( + p+offset+2+uidsize+1); + } + } + break; + } + default: + break; + } + offset += datasize; + } #ifdef DEBUG - if (offset != zip->extra_length) - { - fprintf(stderr, - "Extra data field contents do not match reported size!"); - } + if (offset != extra_length) + { + fprintf(stderr, + "Extra data field contents do not match reported size!\n"); + } #endif } diff --git a/Utilities/cmlibarchive/libarchive/archive_string.c b/Utilities/cmlibarchive/libarchive/archive_string.c index 8da0541c6..cbfad2c5b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.c +++ b/Utilities/cmlibarchive/libarchive/archive_string.c @@ -1,5 +1,6 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,18 +23,31 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 /* mbstate_t define on some hpux */ -#endif #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_string.c,v 1.17 2008/12/06 05:56:43 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_string.c 201095 2009-12-28 02:33:22Z kientzle $"); /* * Basic resizable string support, to simplify manipulating arbitrary-sized * strings while minimizing heap activity. + * + * In particular, the buffer used by a string object is only grown, it + * never shrinks, so you can clear and reuse the same string object + * without incurring additional memory allocations. */ +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_ICONV_H +#include +#endif +#ifdef HAVE_LANGINFO_H +#include +#endif +#ifdef HAVE_LOCALCHARSET_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -45,414 +59,4179 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_string.c,v 1.17 2008/12/06 05:56: #endif #if defined(_WIN32) && !defined(__CYGWIN__) #include +#include +#endif +#if defined(__APPLE__) +#include #endif +#include "archive_endian.h" #include "archive_private.h" #include "archive_string.h" +#include "archive_string_composition.h" -struct archive_string * -__archive_string_append(struct archive_string *as, const char *p, size_t s) +#if !defined(HAVE_WMEMCPY) && !defined(wmemcpy) +#define wmemcpy(a,b,i) (wchar_t *)memcpy((a), (b), (i) * sizeof(wchar_t)) +#endif + +struct archive_string_conv { + struct archive_string_conv *next; + char *from_charset; + char *to_charset; + unsigned from_cp; + unsigned to_cp; + /* Set 1 if from_charset and to_charset are the same. */ + int same; + int flag; +#define SCONV_TO_CHARSET 1 /* MBS is being converted to specified + * charset. */ +#define SCONV_FROM_CHARSET (1<<1) /* MBS is being converted from + * specified charset. */ +#define SCONV_BEST_EFFORT (1<<2) /* Copy at least ASCII code. */ +#define SCONV_WIN_CP (1<<3) /* Use Windows API for converting + * MBS. */ +#define SCONV_UTF8_LIBARCHIVE_2 (1<<4) /* Incorrect UTF-8 made by libarchive + * 2.x in the wrong assumption. */ +#define SCONV_NORMALIZATION_C (1<<6) /* Need normalization to be Form C. + * Before UTF-8 characters are actually + * processed. */ +#define SCONV_NORMALIZATION_D (1<<7) /* Need normalization to be Form D. + * Before UTF-8 characters are actually + * processed. + * Currently this only for MAC OS X. */ +#define SCONV_TO_UTF8 (1<<8) /* "to charset" side is UTF-8. */ +#define SCONV_FROM_UTF8 (1<<9) /* "from charset" side is UTF-8. */ +#define SCONV_TO_UTF16BE (1<<10) /* "to charset" side is UTF-16BE. */ +#define SCONV_FROM_UTF16BE (1<<11) /* "from charset" side is UTF-16BE. */ +#define SCONV_TO_UTF16LE (1<<12) /* "to charset" side is UTF-16LE. */ +#define SCONV_FROM_UTF16LE (1<<13) /* "from charset" side is UTF-16LE. */ +#define SCONV_TO_UTF16 (SCONV_TO_UTF16BE | SCONV_TO_UTF16LE) +#define SCONV_FROM_UTF16 (SCONV_FROM_UTF16BE | SCONV_FROM_UTF16LE) + +#if HAVE_ICONV + iconv_t cd; + iconv_t cd_w;/* Use at archive_mstring on + * Windows. */ +#endif + /* A temporary buffer for normalization. */ + struct archive_string utftmp; +#if defined(__APPLE__) + UnicodeToTextInfo uniInfo; + struct archive_string utf16nfc; + struct archive_string utf16nfd; +#endif + int (*converter[2])(struct archive_string *, const void *, size_t, + struct archive_string_conv *); + int nconverter; +}; + +#define CP_C_LOCALE 0 /* "C" locale only for this file. */ +#define CP_UTF16LE 1200 +#define CP_UTF16BE 1201 + +#define IS_HIGH_SURROGATE_LA(uc) ((uc) >= 0xD800 && (uc) <= 0xDBFF) +#define IS_LOW_SURROGATE_LA(uc) ((uc) >= 0xDC00 && (uc) <= 0xDFFF) +#define IS_SURROGATE_PAIR_LA(uc) ((uc) >= 0xD800 && (uc) <= 0xDFFF) +#define UNICODE_MAX 0x10FFFF +#define UNICODE_R_CHAR 0xFFFD /* Replacement character. */ +/* Set U+FFFD(Replacement character) in UTF-8. */ +#define UTF8_SET_R_CHAR(outp) do { \ + (outp)[0] = 0xef; \ + (outp)[1] = 0xbf; \ + (outp)[2] = 0xbd; \ +} while (0) +#define UTF8_R_CHAR_SIZE 3 + +static struct archive_string_conv *find_sconv_object(struct archive *, + const char *, const char *); +static void add_sconv_object(struct archive *, struct archive_string_conv *); +static struct archive_string_conv *create_sconv_object(const char *, + const char *, unsigned, int); +static void free_sconv_object(struct archive_string_conv *); +static struct archive_string_conv *get_sconv_object(struct archive *, + const char *, const char *, int); +static unsigned make_codepage_from_charset(const char *); +static unsigned get_current_codepage(void); +static unsigned get_current_oemcp(void); +static size_t mbsnbytes(const void *, size_t); +static size_t utf16nbytes(const void *, size_t); +#if defined(_WIN32) && !defined(__CYGWIN__) +static int archive_wstring_append_from_mbs_in_codepage( + struct archive_wstring *, const char *, size_t, + struct archive_string_conv *); +static int archive_string_append_from_wcs_in_codepage(struct archive_string *, + const wchar_t *, size_t, struct archive_string_conv *); +static int is_big_endian(void); +static int strncat_in_codepage(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int win_strncat_from_utf16be(struct archive_string *, const void *, size_t, + struct archive_string_conv *); +static int win_strncat_from_utf16le(struct archive_string *, const void *, size_t, + struct archive_string_conv *); +static int win_strncat_to_utf16be(struct archive_string *, const void *, size_t, + struct archive_string_conv *); +static int win_strncat_to_utf16le(struct archive_string *, const void *, size_t, + struct archive_string_conv *); +#endif +static int best_effort_strncat_from_utf16be(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int best_effort_strncat_from_utf16le(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int best_effort_strncat_to_utf16be(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int best_effort_strncat_to_utf16le(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +#if defined(HAVE_ICONV) +static int iconv_strncat_in_locale(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +#endif +static int best_effort_strncat_in_locale(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int _utf8_to_unicode(uint32_t *, const char *, size_t); +static int utf8_to_unicode(uint32_t *, const char *, size_t); +static inline uint32_t combine_surrogate_pair(uint32_t, uint32_t); +static int cesu8_to_unicode(uint32_t *, const char *, size_t); +static size_t unicode_to_utf8(char *, size_t, uint32_t); +static int utf16_to_unicode(uint32_t *, const char *, size_t, int); +static size_t unicode_to_utf16be(char *, size_t, uint32_t); +static size_t unicode_to_utf16le(char *, size_t, uint32_t); +static int strncat_from_utf8_libarchive2(struct archive_string *, + const void *, size_t, struct archive_string_conv *); +static int strncat_from_utf8_to_utf8(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +static int archive_string_normalize_C(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +#if defined(__APPLE__) +static int archive_string_normalize_D(struct archive_string *, const void *, + size_t, struct archive_string_conv *); +#endif +static int archive_string_append_unicode(struct archive_string *, + const void *, size_t, struct archive_string_conv *); + +static struct archive_string * +archive_string_append(struct archive_string *as, const char *p, size_t s) +{ + if (archive_string_ensure(as, as->length + s + 1) == NULL) + return (NULL); + memcpy(as->s + as->length, p, s); + as->length += s; + as->s[as->length] = 0; + return (as); +} + +static struct archive_wstring * +archive_wstring_append(struct archive_wstring *as, const wchar_t *p, size_t s) { - if (__archive_string_ensure(as, as->length + s + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(as->s + as->length, p, s); - as->s[as->length + s] = 0; - as->length += s; - return (as); + if (archive_wstring_ensure(as, as->length + s + 1) == NULL) + return (NULL); + wmemcpy(as->s + as->length, p, s); + as->length += s; + as->s[as->length] = 0; + return (as); } void -__archive_string_copy(struct archive_string *dest, struct archive_string *src) +archive_string_concat(struct archive_string *dest, struct archive_string *src) { - if (src->length == 0) - dest->length = 0; - else { - if (__archive_string_ensure(dest, src->length + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(dest->s, src->s, src->length); - dest->length = src->length; - dest->s[dest->length] = 0; - } + if (archive_string_append(dest, src->s, src->length) == NULL) + __archive_errx(1, "Out of memory"); } void -__archive_string_concat(struct archive_string *dest, struct archive_string *src) +archive_wstring_concat(struct archive_wstring *dest, struct archive_wstring *src) { - if (src->length > 0) { - if (__archive_string_ensure(dest, dest->length + src->length + 1) == NULL) - __archive_errx(1, "Out of memory"); - memcpy(dest->s + dest->length, src->s, src->length); - dest->length += src->length; - dest->s[dest->length] = 0; - } + if (archive_wstring_append(dest, src->s, src->length) == NULL) + __archive_errx(1, "Out of memory"); } void -__archive_string_free(struct archive_string *as) +archive_string_free(struct archive_string *as) { - as->length = 0; - as->buffer_length = 0; - if (as->s != NULL) { - free(as->s); - as->s = NULL; - } + as->length = 0; + as->buffer_length = 0; + free(as->s); + as->s = NULL; +} + +void +archive_wstring_free(struct archive_wstring *as) +{ + as->length = 0; + as->buffer_length = 0; + free(as->s); + as->s = NULL; +} + +struct archive_wstring * +archive_wstring_ensure(struct archive_wstring *as, size_t s) +{ + return (struct archive_wstring *) + archive_string_ensure((struct archive_string *)as, + s * sizeof(wchar_t)); } /* Returns NULL on any allocation failure. */ struct archive_string * -__archive_string_ensure(struct archive_string *as, size_t s) -{ - /* If buffer is already big enough, don't reallocate. */ - if (as->s && (s <= as->buffer_length)) - return (as); - - /* - * Growing the buffer at least exponentially ensures that - * append operations are always linear in the number of - * characters appended. Using a smaller growth rate for - * larger buffers reduces memory waste somewhat at the cost of - * a larger constant factor. - */ - if (as->buffer_length < 32) - /* Start with a minimum 32-character buffer. */ - as->buffer_length = 32; - else if (as->buffer_length < 8192) - /* Buffers under 8k are doubled for speed. */ - as->buffer_length += as->buffer_length; - else { - /* Buffers 8k and over grow by at least 25% each time. */ - size_t old_length = as->buffer_length; - as->buffer_length += as->buffer_length / 4; - /* Be safe: If size wraps, release buffer and return NULL. */ - if (as->buffer_length < old_length) { - free(as->s); - as->s = NULL; - return (NULL); - } - } - /* - * The computation above is a lower limit to how much we'll - * grow the buffer. In any case, we have to grow it enough to - * hold the request. - */ - if (as->buffer_length < s) - as->buffer_length = s; - /* Now we can reallocate the buffer. */ - as->s = (char *)realloc(as->s, as->buffer_length); - if (as->s == NULL) - return (NULL); - return (as); +archive_string_ensure(struct archive_string *as, size_t s) +{ + char *p; + size_t new_length; + + /* If buffer is already big enough, don't reallocate. */ + if (as->s && (s <= as->buffer_length)) + return (as); + + /* + * Growing the buffer at least exponentially ensures that + * append operations are always linear in the number of + * characters appended. Using a smaller growth rate for + * larger buffers reduces memory waste somewhat at the cost of + * a larger constant factor. + */ + if (as->buffer_length < 32) + /* Start with a minimum 32-character buffer. */ + new_length = 32; + else if (as->buffer_length < 8192) + /* Buffers under 8k are doubled for speed. */ + new_length = as->buffer_length + as->buffer_length; + else { + /* Buffers 8k and over grow by at least 25% each time. */ + new_length = as->buffer_length + as->buffer_length / 4; + /* Be safe: If size wraps, fail. */ + if (new_length < as->buffer_length) { + /* On failure, wipe the string and return NULL. */ + archive_string_free(as); + errno = ENOMEM;/* Make sure errno has ENOMEM. */ + return (NULL); + } + } + /* + * The computation above is a lower limit to how much we'll + * grow the buffer. In any case, we have to grow it enough to + * hold the request. + */ + if (new_length < s) + new_length = s; + /* Now we can reallocate the buffer. */ + p = (char *)realloc(as->s, new_length); + if (p == NULL) { + /* On failure, wipe the string and return NULL. */ + archive_string_free(as); + errno = ENOMEM;/* Make sure errno has ENOMEM. */ + return (NULL); + } + + as->s = p; + as->buffer_length = new_length; + return (as); } +/* + * TODO: See if there's a way to avoid scanning + * the source string twice. Then test to see + * if it actually helps (remember that we're almost + * always called with pretty short arguments, so + * such an optimization might not help). + */ struct archive_string * -__archive_strncat(struct archive_string *as, const void *_p, size_t n) +archive_strncat(struct archive_string *as, const void *_p, size_t n) +{ + size_t s; + const char *p, *pp; + + p = (const char *)_p; + + /* Like strlen(p), except won't examine positions beyond p[n]. */ + s = 0; + pp = p; + while (s < n && *pp) { + pp++; + s++; + } + if ((as = archive_string_append(as, p, s)) == NULL) + __archive_errx(1, "Out of memory"); + return (as); +} + +struct archive_wstring * +archive_wstrncat(struct archive_wstring *as, const wchar_t *p, size_t n) { - size_t s; - const char *p, *pp; + size_t s; + const wchar_t *pp; + + /* Like strlen(p), except won't examine positions beyond p[n]. */ + s = 0; + pp = p; + while (s < n && *pp) { + pp++; + s++; + } + if ((as = archive_wstring_append(as, p, s)) == NULL) + __archive_errx(1, "Out of memory"); + return (as); +} - p = (const char *)_p; +struct archive_string * +archive_strcat(struct archive_string *as, const void *p) +{ + /* strcat is just strncat without an effective limit. + * Assert that we'll never get called with a source + * string over 16MB. + * TODO: Review all uses of strcat in the source + * and try to replace them with strncat(). + */ + return archive_strncat(as, p, 0x1000000); +} - /* Like strlen(p), except won't examine positions beyond p[n]. */ - s = 0; - pp = p; - while (*pp && s < n) { - pp++; - s++; - } - return (__archive_string_append(as, p, s)); +struct archive_wstring * +archive_wstrcat(struct archive_wstring *as, const wchar_t *p) +{ + /* Ditto. */ + return archive_wstrncat(as, p, 0x1000000); } struct archive_string * -__archive_strappend_char(struct archive_string *as, char c) +archive_strappend_char(struct archive_string *as, char c) { - return (__archive_string_append(as, &c, 1)); + if ((as = archive_string_append(as, &c, 1)) == NULL) + __archive_errx(1, "Out of memory"); + return (as); +} + +struct archive_wstring * +archive_wstrappend_wchar(struct archive_wstring *as, wchar_t c) +{ + if ((as = archive_wstring_append(as, &c, 1)) == NULL) + __archive_errx(1, "Out of memory"); + return (as); } /* - * Translates a wide character string into UTF-8 and appends - * to the archive_string. Note: returns NULL if conversion fails, - * but still leaves a best-effort conversion in the argument as. + * Get the "current character set" name to use with iconv. + * On FreeBSD, the empty character set name "" chooses + * the correct character encoding for the current locale, + * so this isn't necessary. + * But iconv on Mac OS 10.6 doesn't seem to handle this correctly; + * on that system, we have to explicitly call nl_langinfo() + * to get the right name. Not sure about other platforms. + * + * NOTE: GNU libiconv does not recognize the character-set name + * which some platform nl_langinfo(CODESET) returns, so we should + * use locale_charset() instead of nl_langinfo(CODESET) for GNU libiconv. */ -struct archive_string * -__archive_strappend_w_utf8(struct archive_string *as, const wchar_t *w) -{ - char *p; - unsigned wc; - char buff[256]; - struct archive_string *return_val = as; - - /* - * Convert one wide char at a time into 'buff', whenever that - * fills, append it to the string. - */ - p = buff; - while (*w != L'\0') { - /* Flush the buffer when we have <=16 bytes free. */ - /* (No encoding has a single character >16 bytes.) */ - if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - 16)) { - *p = '\0'; - archive_strcat(as, buff); - p = buff; - } - wc = *w++; - /* If this is a surrogate pair, assemble the full code point.*/ - /* Note: wc must not be wchar_t here, because the full code - * point can be more than 16 bits! */ - if (wc >= 0xD800 && wc <= 0xDBff - && *w >= 0xDC00 && *w <= 0xDFFF) { - wc -= 0xD800; - wc *= 0x400; - wc += (*w - 0xDC00); - wc += 0x10000; - ++w; - } - /* Translate code point to UTF8 */ - if (wc <= 0x7f) { - *p++ = (char)wc; - } else if (wc <= 0x7ff) { - *p++ = 0xc0 | ((wc >> 6) & 0x1f); - *p++ = 0x80 | (wc & 0x3f); - } else if (wc <= 0xffff) { - *p++ = 0xe0 | ((wc >> 12) & 0x0f); - *p++ = 0x80 | ((wc >> 6) & 0x3f); - *p++ = 0x80 | (wc & 0x3f); - } else if (wc <= 0x1fffff) { - *p++ = 0xf0 | ((wc >> 18) & 0x07); - *p++ = 0x80 | ((wc >> 12) & 0x3f); - *p++ = 0x80 | ((wc >> 6) & 0x3f); - *p++ = 0x80 | (wc & 0x3f); - } else { - /* Unicode has no codes larger than 0x1fffff. */ - /* TODO: use \uXXXX escape here instead of ? */ - *p++ = '?'; - return_val = NULL; - } - } - *p = '\0'; - archive_strcat(as, buff); - return (return_val); -} - -static int -utf8_to_unicode(int *pwc, const char *s, size_t n) -{ - int ch; - - /* - * Decode 1-4 bytes depending on the value of the first byte. - */ - ch = (unsigned char)*s; - if (ch == 0) { - return (0); /* Standard: return 0 for end-of-string. */ - } - if ((ch & 0x80) == 0) { - *pwc = ch & 0x7f; - return (1); - } - if ((ch & 0xe0) == 0xc0) { - if (n < 2) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f); - return (2); - } - if ((ch & 0xf0) == 0xe0) { - if (n < 3) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - if ((s[2] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x0f) << 12) - | ((s[1] & 0x3f) << 6) - | (s[2] & 0x3f); - return (3); - } - if ((ch & 0xf8) == 0xf0) { - if (n < 4) - return (-1); - if ((s[1] & 0xc0) != 0x80) return (-1); - if ((s[2] & 0xc0) != 0x80) return (-1); - if ((s[3] & 0xc0) != 0x80) return (-1); - *pwc = ((ch & 0x07) << 18) - | ((s[1] & 0x3f) << 12) - | ((s[2] & 0x3f) << 6) - | (s[3] & 0x3f); - return (4); - } - /* Invalid first byte. */ - return (-1); -} - -/* - * Return a wide-character Unicode string by converting this archive_string - * from UTF-8. We assume that systems with 16-bit wchar_t always use - * UTF16 and systems with 32-bit wchar_t can accept UCS4. - */ -wchar_t * -__archive_string_utf8_w(struct archive_string *as) -{ - wchar_t *ws, *dest; - int wc, wc2;/* Must be large enough for a 21-bit Unicode code point. */ - const char *src; - int n; - int err; - - ws = (wchar_t *)malloc((as->length + 1) * sizeof(wchar_t)); - if (ws == NULL) - __archive_errx(1, "Out of memory"); - err = 0; - dest = ws; - src = as->s; - while (*src != '\0') { - n = utf8_to_unicode(&wc, src, 8); - if (n == 0) - break; - if (n < 0) { - free(ws); - return (NULL); - } - src += n; - if (wc >= 0xDC00 && wc <= 0xDBFF) { - /* This is a leading surrogate; some idiot - * has translated UTF16 to UTF8 without combining - * surrogates; rebuild the full code point before - * continuing. */ - n = utf8_to_unicode(&wc2, src, 8); - if (n < 0) { - free(ws); - return (NULL); - } - if (n == 0) /* Ignore the leading surrogate */ - break; - if (wc2 < 0xDC00 || wc2 > 0xDFFF) { - /* If the second character isn't a - * trailing surrogate, then someone - * has really screwed up and this is - * invalid. */ - free(ws); - return (NULL); - } else { - src += n; - wc -= 0xD800; - wc *= 0x400; - wc += wc2 - 0xDC00; - wc += 0x10000; - } - } - if ((sizeof(wchar_t) < 4) && (wc > 0xffff)) { - /* We have a code point that won't fit into a - * wchar_t; convert it to a surrogate pair. */ - wc -= 0x10000; - *dest++ = ((wc >> 10) & 0x3ff) + 0xD800; - *dest++ = (wc & 0x3ff) + 0xDC00; - } else - *dest++ = wc; - } - *dest++ = L'\0'; - return (ws); +static const char * +default_iconv_charset(const char *charset) { + if (charset != NULL && charset[0] != '\0') + return charset; +#if HAVE_LOCALE_CHARSET && !defined(__APPLE__) + /* locale_charset() is broken on Mac OS */ + return locale_charset(); +#elif HAVE_NL_LANGINFO + return nl_langinfo(CODESET); +#else + return ""; +#endif } #if defined(_WIN32) && !defined(__CYGWIN__) /* - * Translates a wide character string into current locale character set - * and appends to the archive_string. Note: returns NULL if conversion - * fails. + * Convert MBS to WCS. + * Note: returns -1 if conversion fails. + */ +int +archive_wstring_append_from_mbs(struct archive_wstring *dest, + const char *p, size_t len) +{ + int r = archive_wstring_append_from_mbs_in_codepage(dest, p, len, NULL); + if (r != 0 && errno == ENOMEM) + __archive_errx(1, "No memory"); + return (r); +} + +static int +archive_wstring_append_from_mbs_in_codepage(struct archive_wstring *dest, + const char *s, size_t length, struct archive_string_conv *sc) +{ + int count, ret = 0; + UINT from_cp; + + if (sc != NULL) + from_cp = sc->from_cp; + else + from_cp = get_current_codepage(); + + if (from_cp == CP_C_LOCALE) { + /* + * "C" locale special process. + */ + wchar_t *ws; + const unsigned char *mp; + + if (NULL == archive_wstring_ensure(dest, + dest->length + length + 1)) + return (-1); + + ws = dest->s + dest->length; + mp = (const unsigned char *)s; + count = 0; + while (count < (int)length && *mp) { + *ws++ = (wchar_t)*mp++; + count++; + } + } else if (sc != NULL && (sc->flag & SCONV_NORMALIZATION_C)) { + /* + * Normalize UTF-8 and UTF-16BE and convert it directly + * to UTF-16 as wchar_t. + */ + struct archive_string u16; + int saved_flag = sc->flag;/* save current flag. */ + + if (is_big_endian()) + sc->flag |= SCONV_TO_UTF16BE; + else + sc->flag |= SCONV_TO_UTF16LE; + + if (sc->flag & SCONV_FROM_UTF16) { + /* + * UTF-16BE/LE NFD ===> UTF-16 NFC + */ + count = utf16nbytes(s, length); + } else { + /* + * UTF-8 NFD ===> UTF-16 NFC + */ + count = mbsnbytes(s, length); + } + u16.s = (char *)dest->s; + u16.length = dest->length << 1;; + u16.buffer_length = dest->buffer_length; + ret = archive_string_normalize_C(&u16, s, count, sc); + dest->s = (wchar_t *)u16.s; + dest->length = u16.length >> 1; + dest->buffer_length = u16.buffer_length; + sc->flag = saved_flag;/* restore the saved flag. */ + return (ret); + } else if (sc != NULL && (sc->flag & SCONV_FROM_UTF16)) { + count = utf16nbytes(s, length); + count >>= 1; /* to be WCS length */ + /* Allocate memory for WCS. */ + if (NULL == archive_wstring_ensure(dest, + dest->length + count + 1)) + return (-1); + wmemcpy(dest->s + dest->length, (wchar_t *)s, count); + if ((sc->flag & SCONV_FROM_UTF16BE) && !is_big_endian()) { + uint16_t *u16 = (uint16_t *)(dest->s + dest->length); + int b; + for (b = 0; b < count; b++) { + uint16_t val = archive_le16dec(u16+b); + archive_be16enc(u16+b, val); + } + } else if ((sc->flag & SCONV_FROM_UTF16LE) && is_big_endian()) { + uint16_t *u16 = (uint16_t *)(dest->s + dest->length); + int b; + for (b = 0; b < count; b++) { + uint16_t val = archive_be16dec(u16+b); + archive_le16enc(u16+b, val); + } + } + } else { + DWORD mbflag; + + if (sc == NULL) + mbflag = 0; + else if (sc->flag & SCONV_FROM_CHARSET) { + /* Do not trust the length which comes from + * an archive file. */ + length = mbsnbytes(s, length); + mbflag = 0; + } else + mbflag = MB_PRECOMPOSED; + + if (length == 0) { + /* + * We do not need to convert any characters but make + * sure `dest' has a valid buffer(no NULL pointer). + */ + if (NULL == archive_wstring_ensure(dest, + dest->length + 1)) + return (-1); + dest->s[dest->length] = L'\0'; + return (0); + } + + /* + * Count how many bytes are needed for WCS. + */ + count = MultiByteToWideChar(from_cp, + mbflag, s, length, NULL, 0); + if (count == 0) { + if (dest->s == NULL) { + if (NULL == archive_wstring_ensure(dest, + dest->length + 1)) + return (-1); + } + dest->s[dest->length] = L'\0'; + return (-1); + } + /* Allocate memory for WCS. */ + if (NULL == archive_wstring_ensure(dest, + dest->length + count + 1)) + return (-1); + /* Convert MBS to WCS. */ + count = MultiByteToWideChar(from_cp, + mbflag, s, length, dest->s + dest->length, count); + if (count == 0) + ret = -1; + } + dest->length += count; + dest->s[dest->length] = L'\0'; + return (ret); +} + +#elif defined(HAVE_MBSNRTOWCS) + +/* + * Convert MBS to WCS. + * Note: returns -1 if conversion fails. + */ +int +archive_wstring_append_from_mbs(struct archive_wstring *dest, + const char *p, size_t len) +{ + size_t r; + /* + * No single byte will be more than one wide character, + * so this length estimate will always be big enough. + */ + size_t wcs_length = len; + size_t mbs_length = len; + const char *mbs = p; + wchar_t *wcs; + mbstate_t shift_state; + + memset(&shift_state, 0, sizeof(shift_state)); + if (NULL == archive_wstring_ensure(dest, dest->length + wcs_length + 1)) + __archive_errx(1, + "No memory for archive_wstring_append_from_mbs()"); + wcs = dest->s + dest->length; + r = mbsnrtowcs(wcs, &mbs, mbs_length, wcs_length, &shift_state); + if (r != (size_t)-1) { + dest->length += r; + dest->s[dest->length] = L'\0'; + return (0); + } + dest->s[dest->length] = L'\0'; + return (-1); +} + +#else + +/* + * Convert MBS to WCS. + * Note: returns -1 if conversion fails. + */ +int +archive_wstring_append_from_mbs(struct archive_wstring *dest, + const char *p, size_t len) +{ + size_t r; + /* + * No single byte will be more than one wide character, + * so this length estimate will always be big enough. + */ + size_t wcs_length = len; + size_t mbs_length = len; + const char *mbs = p; + wchar_t *wcs; +#if HAVE_MBRTOWC + mbstate_t shift_state; + + memset(&shift_state, 0, sizeof(shift_state)); +#endif + if (NULL == archive_wstring_ensure(dest, dest->length + wcs_length + 1)) + __archive_errx(1, + "No memory for archive_wstring_append_from_mbs()"); + wcs = dest->s + dest->length; + /* + * We cannot use mbsrtowcs/mbstowcs here because those may convert + * extra MBS when strlen(p) > len and one wide character consis of + * multi bytes. + */ + while (wcs_length > 0 && *mbs && mbs_length > 0) { +#if HAVE_MBRTOWC + r = mbrtowc(wcs, mbs, wcs_length, &shift_state); +#else + r = mbtowc(wcs, mbs, wcs_length); +#endif + if (r == (size_t)-1 || r == (size_t)-2) { + dest->s[dest->length] = L'\0'; + return (-1); + } + if (r == 0 || r > mbs_length) + break; + wcs++; + wcs_length--; + mbs += r; + mbs_length -= r; + } + dest->length = wcs - dest->s; + dest->s[dest->length] = L'\0'; + return (0); +} + +#endif + +#if defined(_WIN32) && !defined(__CYGWIN__) + +/* + * WCS ==> MBS. + * Note: returns -1 if conversion fails. * * Win32 builds use WideCharToMultiByte from the Windows API. * (Maybe Cygwin should too? WideCharToMultiByte will know a * lot more about local character encodings than the wcrtomb() * wrapper is going to know.) */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w) -{ - char *p; - int l, wl; - BOOL useDefaultChar = FALSE; - - wl = (int)wcslen(w); - l = wl * 4 + 4; - p = malloc(l); - if (p == NULL) - __archive_errx(1, "Out of memory"); - /* To check a useDefaultChar is to simulate error handling of - * the my_wcstombs() which is running on non Windows system with - * wctomb(). - * And to set NULL for last argument is necessary when a codepage - * is not CP_ACP(current locale). - */ - l = WideCharToMultiByte(CP_ACP, 0, w, wl, p, l, NULL, &useDefaultChar); - if (l == 0) { - free(p); - return (NULL); - } - __archive_string_append(as, p, l); - free(p); - return (as); +int +archive_string_append_from_wcs(struct archive_string *as, + const wchar_t *w, size_t len) +{ + int r = archive_string_append_from_wcs_in_codepage(as, w, len, NULL); + if (r != 0 && errno == ENOMEM) + __archive_errx(1, "No memory"); + return (r); } -#else +static int +archive_string_append_from_wcs_in_codepage(struct archive_string *as, + const wchar_t *ws, size_t len, struct archive_string_conv *sc) +{ + BOOL defchar_used, *dp; + int count, ret = 0; + UINT to_cp; + int wslen = (int)len; + + if (sc != NULL) + to_cp = sc->to_cp; + else + to_cp = get_current_codepage(); + + if (to_cp == CP_C_LOCALE) { + /* + * "C" locale special process. + */ + const wchar_t *wp = ws; + char *p; + + if (NULL == archive_string_ensure(as, + as->length + wslen +1)) + return (-1); + p = as->s + as->length; + count = 0; + defchar_used = 0; + while (count < wslen && *wp) { + if (*wp > 255) { + *p++ = '?'; + wp++; + defchar_used = 1; + } else + *p++ = (char)*wp++; + count++; + } + } else if (sc != NULL && (sc->flag & SCONV_TO_UTF16)) { + uint16_t *u16; + + if (NULL == + archive_string_ensure(as, as->length + len * 2 + 2)) + return (-1); + u16 = (uint16_t *)(as->s + as->length); + count = 0; + defchar_used = 0; + if (sc->flag & SCONV_TO_UTF16BE) { + while (count < (int)len && *ws) { + archive_be16enc(u16+count, *ws); + ws++; + count++; + } + } else { + while (count < (int)len && *ws) { + archive_le16enc(u16+count, *ws); + ws++; + count++; + } + } + count <<= 1; /* to be byte size */ + } else { + /* Make sure the MBS buffer has plenty to set. */ + if (NULL == + archive_string_ensure(as, as->length + len * 2 + 1)) + return (-1); + do { + defchar_used = 0; + if (to_cp == CP_UTF8 || sc == NULL) + dp = NULL; + else + dp = &defchar_used; + count = WideCharToMultiByte(to_cp, 0, ws, wslen, + as->s + as->length, as->buffer_length-1, NULL, dp); + if (count == 0 && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + /* Expand the MBS buffer and retry. */ + if (NULL == archive_string_ensure(as, + as->buffer_length + len)) + return (-1); + continue; + } + if (count == 0) + ret = -1; + } while (0); + } + as->length += count; + as->s[as->length] = '\0'; + return (defchar_used?-1:ret); +} + +#elif defined(HAVE_WCSNRTOMBS) /* * Translates a wide character string into current locale character set - * and appends to the archive_string. Note: returns NULL if conversion + * and appends to the archive_string. Note: returns -1 if conversion * fails. - * - * Non-Windows uses ISO C wcrtomb() or wctomb() to perform the conversion - * one character at a time. If a non-Windows platform doesn't have - * either of these, fall back to the built-in UTF8 conversion. */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *as, const wchar_t *w) +int +archive_string_append_from_wcs(struct archive_string *as, + const wchar_t *w, size_t len) { -#if !defined(HAVE_WCTOMB) && !defined(HAVE_WCRTOMB) - /* If there's no built-in locale support, fall back to UTF8 always. */ - return __archive_strappend_w_utf8(as, w); -#else - /* We cannot use the standard wcstombs() here because it - * cannot tell us how big the output buffer should be. So - * I've built a loop around wcrtomb() or wctomb() that - * converts a character at a time and resizes the string as - * needed. We prefer wcrtomb() when it's available because - * it's thread-safe. */ - int n; - char *p; - char buff[256]; + mbstate_t shift_state; + size_t r, ndest, nwc; + char *dest; + const wchar_t *wp, *wpp; + int ret_val = 0; + + wp = w; + nwc = len; + ndest = len * 2; + /* Initialize the shift state. */ + memset(&shift_state, 0, sizeof(shift_state)); + while (nwc > 0) { + /* Allocate buffer for MBS. */ + if (archive_string_ensure(as, as->length + ndest + 1) == NULL) + __archive_errx(1, "Out of memory"); + + dest = as->s + as->length; + wpp = wp; + r = wcsnrtombs(dest, &wp, nwc, + as->buffer_length - as->length -1, + &shift_state); + if (r == (size_t)-1) { + if (errno == EILSEQ) { + /* Retry conversion just for safe WCS. */ + size_t xwc = wp - wpp; + wp = wpp; + r = wcsnrtombs(dest, &wp, xwc, + as->buffer_length - as->length -1, + &shift_state); + if (r == (size_t)-1) + /* This would not happen. */ + return (-1); + as->length += r; + nwc -= wp - wpp; + /* Skip an illegal wide char. */ + as->s[as->length++] = '?'; + wp++; + nwc--; + ret_val = -1; + continue; + } else { + ret_val = -1; + break; + } + } + as->length += r; + if (wp == NULL || (wp - wpp) >= nwc) + break; + /* Get a remaining WCS lenth. */ + nwc -= wp - wpp; + } + /* All wide characters are translated to MBS. */ + as->s[as->length] = '\0'; + return (ret_val); +} + +#elif defined(HAVE_WCTOMB) || defined(HAVE_WCRTOMB) + +/* + * Translates a wide character string into current locale character set + * and appends to the archive_string. Note: returns -1 if conversion + * fails. + */ +int +archive_string_append_from_wcs(struct archive_string *as, + const wchar_t *w, size_t len) +{ + /* We cannot use the standard wcstombs() here because it + * cannot tell us how big the output buffer should be. So + * I've built a loop around wcrtomb() or wctomb() that + * converts a character at a time and resizes the string as + * needed. We prefer wcrtomb() when it's available because + * it's thread-safe. */ + int n, ret_val = 0; + char *p; + char *end; #if HAVE_WCRTOMB - mbstate_t shift_state; + mbstate_t shift_state; - memset(&shift_state, 0, sizeof(shift_state)); + memset(&shift_state, 0, sizeof(shift_state)); #else - /* Clear the shift state before starting. */ - wctomb(NULL, L'\0'); -#endif - - /* - * Convert one wide char at a time into 'buff', whenever that - * fills, append it to the string. - */ - p = buff; - while (*w != L'\0') { - /* Flush the buffer when we have <=16 bytes free. */ - /* (No encoding has a single character >16 bytes.) */ - if ((size_t)(p - buff) >= (size_t)(sizeof(buff) - MB_CUR_MAX)) { - *p = '\0'; - archive_strcat(as, buff); - p = buff; - } + /* Clear the shift state before starting. */ + wctomb(NULL, L'\0'); +#endif + /* + * Allocate buffer for MBS. + * We need this allocation here since it is possible that + * as->s is still NULL. + */ + if (archive_string_ensure(as, as->length + len + 1) == NULL) + __archive_errx(1, "Out of memory"); + + p = as->s + as->length; + end = as->s + as->buffer_length - MB_CUR_MAX -1; + while (*w != L'\0' && len > 0) { + if (p >= end) { + as->length = p - as->s; + as->s[as->length] = '\0'; + /* Re-allocate buffer for MBS. */ + if (archive_string_ensure(as, + as->length + len * 2 + 1) == NULL) + __archive_errx(1, "Out of memory"); + p = as->s + as->length; + end = as->s + as->buffer_length - MB_CUR_MAX -1; + } #if HAVE_WCRTOMB - n = wcrtomb(p, *w++, &shift_state); + n = wcrtomb(p, *w++, &shift_state); #else - n = wctomb(p, *w++); + n = wctomb(p, *w++); +#endif + if (n == -1) { + if (errno == EILSEQ) { + /* Skip an illegal wide char. */ + *p++ = '?'; + ret_val = -1; + } else { + ret_val = -1; + break; + } + } else + p += n; + len--; + } + as->length = p - as->s; + as->s[as->length] = '\0'; + return (ret_val); +} + +#else /* HAVE_WCTOMB || HAVE_WCRTOMB */ + +/* + * TODO: Test if __STDC_ISO_10646__ is defined. + * Non-Windows uses ISO C wcrtomb() or wctomb() to perform the conversion + * one character at a time. If a non-Windows platform doesn't have + * either of these, fall back to the built-in UTF8 conversion. + */ +int +archive_string_append_from_wcs(struct archive_string *as, + const wchar_t *w, size_t len) +{ + (void)as;/* UNUSED */ + (void)w;/* UNUSED */ + (void)len;/* UNUSED */ + return (-1); +} + +#endif /* HAVE_WCTOMB || HAVE_WCRTOMB */ + +/* + * Find a string conversion object by a pair of 'from' charset name + * and 'to' charset name from an archive object. + * Return NULL if not found. + */ +static struct archive_string_conv * +find_sconv_object(struct archive *a, const char *fc, const char *tc) +{ + struct archive_string_conv *sc; + + if (a == NULL) + return (NULL); + + for (sc = a->sconv; sc != NULL; sc = sc->next) { + if (strcmp(sc->from_charset, fc) == 0 && + strcmp(sc->to_charset, tc) == 0) + break; + } + return (sc); +} + +/* + * Register a string object to an archive object. + */ +static void +add_sconv_object(struct archive *a, struct archive_string_conv *sc) +{ + struct archive_string_conv **psc; + + /* Add a new sconv to sconv list. */ + psc = &(a->sconv); + while (*psc != NULL) + psc = &((*psc)->next); + *psc = sc; +} + +#if defined(__APPLE__) + +static int +createUniInfo(struct archive_string_conv *sconv) +{ + UnicodeMapping map; + OSStatus err; + + map.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, + kUnicodeNoSubset, kUnicode16BitFormat); + map.otherEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, + kUnicodeHFSPlusDecompVariant, kUnicode16BitFormat); + map.mappingVersion = kUnicodeUseLatestMapping; + + sconv->uniInfo = NULL; + err = CreateUnicodeToTextInfo(&map, &(sconv->uniInfo)); + return ((err == noErr)? 0: -1); +} + +#endif /* __APPLE__ */ + +static void +add_converter(struct archive_string_conv *sc, int (*converter) + (struct archive_string *, const void *, size_t, + struct archive_string_conv *)) +{ + if (sc == NULL || sc->nconverter >= 2) + __archive_errx(1, "Programing error"); + sc->converter[sc->nconverter++] = converter; +} + +static void +setup_converter(struct archive_string_conv *sc) +{ + + /* Reset. */ + sc->nconverter = 0; + + /* + * Perform special sequence for the incorrect UTF-8 filenames + * made by libarchive2.x. + */ + if (sc->flag & SCONV_UTF8_LIBARCHIVE_2) { + add_converter(sc, strncat_from_utf8_libarchive2); + return; + } + + /* + * Convert a string to UTF-16BE/LE. + */ + if (sc->flag & SCONV_TO_UTF16) { + /* + * If the current locale is UTF-8, we can translate + * a UTF-8 string into a UTF-16BE string. + */ + if (sc->flag & SCONV_FROM_UTF8) { + add_converter(sc, archive_string_append_unicode); + return; + } + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (sc->flag & SCONV_WIN_CP) { + if (sc->flag & SCONV_TO_UTF16BE) + add_converter(sc, win_strncat_to_utf16be); + else + add_converter(sc, win_strncat_to_utf16le); + return; + } +#endif + +#if defined(HAVE_ICONV) + if (sc->cd != (iconv_t)-1) { + add_converter(sc, iconv_strncat_in_locale); + return; + } +#endif + + if (sc->flag & SCONV_BEST_EFFORT) { + if (sc->flag & SCONV_TO_UTF16BE) + add_converter(sc, best_effort_strncat_to_utf16be); + else + add_converter(sc, best_effort_strncat_to_utf16le); + } else + /* Make sure we have no converter. */ + sc->nconverter = 0; + return; + } + + /* + * Convert a string from UTF-16BE/LE. + */ + if (sc->flag & SCONV_FROM_UTF16) { + /* + * At least we should normalize a UTF-16BE string. + */ +#if defined(__APPLE__) + if (sc->flag & SCONV_NORMALIZATION_D) + add_converter(sc,archive_string_normalize_D); + else +#endif + if (sc->flag & SCONV_NORMALIZATION_C) + add_converter(sc, archive_string_normalize_C); + + if (sc->flag & SCONV_TO_UTF8) { + /* + * If the current locale is UTF-8, we can translate + * a UTF-16BE/LE string into a UTF-8 string directly. + */ + if (!(sc->flag & + (SCONV_NORMALIZATION_D |SCONV_NORMALIZATION_C))) + add_converter(sc, + archive_string_append_unicode); + return; + } + +#if defined(_WIN32) && !defined(__CYGWIN__) + if (sc->flag & SCONV_WIN_CP) { + if (sc->flag & SCONV_FROM_UTF16BE) + add_converter(sc, win_strncat_from_utf16be); + else + add_converter(sc, win_strncat_from_utf16le); + return; + } +#endif + +#if defined(HAVE_ICONV) + if (sc->cd != (iconv_t)-1) { + add_converter(sc, iconv_strncat_in_locale); + return; + } +#endif + + if ((sc->flag & (SCONV_BEST_EFFORT | SCONV_FROM_UTF16BE)) + == (SCONV_BEST_EFFORT | SCONV_FROM_UTF16BE)) + add_converter(sc, best_effort_strncat_from_utf16be); + else if ((sc->flag & (SCONV_BEST_EFFORT | SCONV_FROM_UTF16LE)) + == (SCONV_BEST_EFFORT | SCONV_FROM_UTF16LE)) + add_converter(sc, best_effort_strncat_from_utf16le); + else + /* Make sure we have no converter. */ + sc->nconverter = 0; + return; + } + + if (sc->flag & SCONV_FROM_UTF8) { + /* + * At least we should normalize a UTF-8 string. + */ +#if defined(__APPLE__) + if (sc->flag & SCONV_NORMALIZATION_D) + add_converter(sc,archive_string_normalize_D); + else +#endif + if (sc->flag & SCONV_NORMALIZATION_C) + add_converter(sc, archive_string_normalize_C); + + /* + * Copy UTF-8 string with a check of CESU-8. + * Apparently, iconv does not check surrogate pairs in UTF-8 + * when both from-charset and to-charset are UTF-8, and then + * we use our UTF-8 copy code. + */ + if (sc->flag & SCONV_TO_UTF8) { + /* + * If the current locale is UTF-8, we can translate + * a UTF-16BE string into a UTF-8 string directly. + */ + if (!(sc->flag & + (SCONV_NORMALIZATION_D |SCONV_NORMALIZATION_C))) + add_converter(sc, strncat_from_utf8_to_utf8); + return; + } + } + +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * On Windows we can use Windows API for a string conversion. + */ + if (sc->flag & SCONV_WIN_CP) { + add_converter(sc, strncat_in_codepage); + return; + } +#endif + +#if HAVE_ICONV + if (sc->cd != (iconv_t)-1) { + add_converter(sc, iconv_strncat_in_locale); + return; + } +#endif + + /* + * Try conversion in the best effort or no conversion. + */ + if ((sc->flag & SCONV_BEST_EFFORT) || sc->same) + add_converter(sc, best_effort_strncat_in_locale); + else + /* Make sure we have no converter. */ + sc->nconverter = 0; +} + +/* + * Return canonicalized charset-name but this supports just UTF-8, UTF-16BE + * and CP932 which are referenced in create_sconv_object(). + */ +static const char * +canonical_charset_name(const char *charset) +{ + char cs[16]; + char *p; + const char *s; + + if (charset == NULL || charset[0] == '\0' + || strlen(charset) > 15) + return (charset); + + /* Copy name to uppercase. */ + p = cs; + s = charset; + while (*s) { + char c = *s++; + if (c >= 'a' && c <= 'z') + c -= 'a' - 'A'; + *p++ = c; + } + *p++ = '\0'; + + if (strcmp(cs, "UTF-8") == 0 || + strcmp(cs, "UTF8") == 0) + return ("UTF-8"); + if (strcmp(cs, "UTF-16BE") == 0 || + strcmp(cs, "UTF16BE") == 0) + return ("UTF-16BE"); + if (strcmp(cs, "UTF-16LE") == 0 || + strcmp(cs, "UTF16LE") == 0) + return ("UTF-16LE"); + if (strcmp(cs, "CP932") == 0) + return ("CP932"); + return (charset); +} + +/* + * Create a string conversion object. + */ +static struct archive_string_conv * +create_sconv_object(const char *fc, const char *tc, + unsigned current_codepage, int flag) +{ + struct archive_string_conv *sc; + + sc = calloc(1, sizeof(*sc)); + if (sc == NULL) + return (NULL); + sc->next = NULL; + sc->from_charset = strdup(fc); + if (sc->from_charset == NULL) { + free(sc); + return (NULL); + } + sc->to_charset = strdup(tc); + if (sc->to_charset == NULL) { + free(sc); + free(sc->from_charset); + return (NULL); + } + archive_string_init(&sc->utftmp); +#if defined(__APPLE__) + archive_string_init(&sc->utf16nfc); + archive_string_init(&sc->utf16nfd); +#endif + + if (flag & SCONV_TO_CHARSET) { + /* + * Convert characters from the current locale charset to + * a specified charset. + */ + sc->from_cp = current_codepage; + sc->to_cp = make_codepage_from_charset(tc); +#if defined(_WIN32) && !defined(__CYGWIN__) + if (IsValidCodePage(sc->to_cp)) + flag |= SCONV_WIN_CP; +#endif + } else if (flag & SCONV_FROM_CHARSET) { + /* + * Convert characters from a specified charset to + * the current locale charset. + */ + sc->to_cp = current_codepage; + sc->from_cp = make_codepage_from_charset(fc); +#if defined(_WIN32) && !defined(__CYGWIN__) + if (IsValidCodePage(sc->from_cp)) + flag |= SCONV_WIN_CP; +#endif + } + + /* + * Check if "from charset" and "to charset" are the same. + */ + if (strcmp(fc, tc) == 0 || + (sc->from_cp != -1 && sc->from_cp == sc->to_cp)) + sc->same = 1; + else + sc->same = 0; + + /* + * Mark if "from charset" or "to charset" are UTF-8 or UTF-16BE/LE. + */ + if (strcmp(tc, "UTF-8") == 0) + flag |= SCONV_TO_UTF8; + else if (strcmp(tc, "UTF-16BE") == 0) + flag |= SCONV_TO_UTF16BE; + else if (strcmp(tc, "UTF-16LE") == 0) + flag |= SCONV_TO_UTF16LE; + if (strcmp(fc, "UTF-8") == 0) + flag |= SCONV_FROM_UTF8; + else if (strcmp(fc, "UTF-16BE") == 0) + flag |= SCONV_FROM_UTF16BE; + else if (strcmp(fc, "UTF-16LE") == 0) + flag |= SCONV_FROM_UTF16LE; +#if defined(_WIN32) && !defined(__CYGWIN__) + if (sc->to_cp == CP_UTF8) + flag |= SCONV_TO_UTF8; + else if (sc->to_cp == CP_UTF16BE) + flag |= SCONV_TO_UTF16BE | SCONV_WIN_CP; + else if (sc->to_cp == CP_UTF16LE) + flag |= SCONV_TO_UTF16LE | SCONV_WIN_CP; + if (sc->from_cp == CP_UTF8) + flag |= SCONV_FROM_UTF8; + else if (sc->from_cp == CP_UTF16BE) + flag |= SCONV_FROM_UTF16BE | SCONV_WIN_CP; + else if (sc->from_cp == CP_UTF16LE) + flag |= SCONV_FROM_UTF16LE | SCONV_WIN_CP; +#endif + + /* + * Set a flag for Unicode NFD. Usually iconv cannot correctly + * handle it. So we have to translate NFD characters to NFC ones + * ourselves before iconv handles. Another reason is to prevent + * that the same sight of two filenames, one is NFC and other + * is NFD, would be in its directory. + * On Mac OS X, although its filesystem layer automatically + * convert filenames to NFD, it would be useful for filename + * comparing to find out the same filenames that we normalize + * that to be NFD ourselves. + */ + if ((flag & SCONV_FROM_CHARSET) && + (flag & (SCONV_FROM_UTF16 | SCONV_FROM_UTF8))) { +#if defined(__APPLE__) + if (flag & SCONV_TO_UTF8) { + if (createUniInfo(sc) == 0) + flag |= SCONV_NORMALIZATION_D; + } else +#endif + flag |= SCONV_NORMALIZATION_C; + } + +#if defined(HAVE_ICONV) + sc->cd_w = (iconv_t)-1; + /* + * Create an iconv object. + */ + if (((flag & (SCONV_TO_UTF8 | SCONV_TO_UTF16)) && + (flag & (SCONV_FROM_UTF8 | SCONV_FROM_UTF16))) || + (flag & SCONV_WIN_CP)) { + /* This case we won't use iconv. */ + sc->cd = (iconv_t)-1; +#if defined(__APPLE__) + } else if ((flag & SCONV_FROM_CHARSET) && (flag & SCONV_TO_UTF8)) { + /* + * In case reading an archive file. + * Translate non-Unicode filenames in an archive file to + * UTF-8-MAC filenames. + */ + sc->cd = iconv_open("UTF-8-MAC", fc); + if (sc->cd == (iconv_t)-1) { + if ((sc->flag & SCONV_BEST_EFFORT) && + strcmp(fc, "CP932") == 0) { + sc->cd = iconv_open("UTF-8-MAC", "SJIS"); + if (sc->cd == (iconv_t)-1) { + sc->cd = iconv_open(tc, fc); + if (sc->cd == (iconv_t)-1) + sc->cd = iconv_open(tc, "SJIS"); + } + } else + sc->cd = iconv_open(tc, fc); + } + } else if ((flag & SCONV_TO_CHARSET) && (flag & SCONV_FROM_UTF8)) { + /* + * In case writing an archive file. + * Translate UTF-8-MAC filenames in HFS Plus to non-Unicode + * filenames. + */ + sc->cd = iconv_open(tc, "UTF-8-MAC"); + if (sc->cd == (iconv_t)-1) { + if ((sc->flag & SCONV_BEST_EFFORT) && + strcmp(tc, "CP932") == 0) { + sc->cd = iconv_open("SJIS", "UTF-8-MAC"); + if (sc->cd == (iconv_t)-1) { + sc->cd = iconv_open(tc, fc); + if (sc->cd == (iconv_t)-1) + sc->cd = iconv_open("SJIS", fc); + } + } else + sc->cd = iconv_open(tc, fc); + } +#endif + } else { + sc->cd = iconv_open(tc, fc); + if (sc->cd == (iconv_t)-1 && (sc->flag & SCONV_BEST_EFFORT)) { + /* + * Unfortunaly, all of iconv implements do support + * "CP932" character-set, so we should use "SJIS" + * instead if iconv_open failed. + */ + if (strcmp(tc, "CP932") == 0) + sc->cd = iconv_open("SJIS", fc); + else if (strcmp(fc, "CP932") == 0) + sc->cd = iconv_open(tc, "SJIS"); + } +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * archive_mstring on Windows directly convert multi-bytes + * into archive_wstring in order not to depend on locale + * so that you can do a I18N programing. This will be + * used only in archive_mstring_copy_mbs_len_l so far. + */ + if (flag & SCONV_FROM_CHARSET) { + sc->cd_w = iconv_open("UTF-8", fc); + if (sc->cd_w == (iconv_t)-1 && + (sc->flag & SCONV_BEST_EFFORT)) { + if (strcmp(fc, "CP932") == 0) + sc->cd_w = iconv_open("UTF-8", "SJIS"); + } + } +#endif /* _WIN32 && !__CYGWIN__ */ + } +#endif /* HAVE_ICONV */ + + sc->flag = flag; + + /* + * Setup converters. + */ + setup_converter(sc); + + return (sc); +} + +/* + * Free a string conversion object. + */ +static void +free_sconv_object(struct archive_string_conv *sc) +{ + free(sc->from_charset); + free(sc->to_charset); + archive_string_free(&sc->utftmp); +#if HAVE_ICONV + if (sc->cd != (iconv_t)-1) + iconv_close(sc->cd); + if (sc->cd_w != (iconv_t)-1) + iconv_close(sc->cd_w); #endif - if (n == -1) - return (NULL); - p += n; - } - *p = '\0'; - archive_strcat(as, buff); - return (as); +#if defined(__APPLE__) + archive_string_free(&sc->utf16nfc); + archive_string_free(&sc->utf16nfd); + if (sc->uniInfo != NULL) + DisposeUnicodeToTextInfo(&(sc->uniInfo)); #endif + free(sc); +} + +#if defined(_WIN32) && !defined(__CYGWIN__) +static unsigned +my_atoi(const char *p) +{ + unsigned cp; + + cp = 0; + while (*p) { + if (*p >= '0' && *p <= '9') + cp = cp * 10 + (*p - '0'); + else + return (-1); + p++; + } + return (cp); +} + +/* + * Translate Charset name (as used by iconv) into CodePage (as used by Windows) + * Return -1 if failed. + * + * Note: This translation code may be insufficient. + */ +static struct charset { + const char *name; + unsigned cp; +} charsets[] = { + /* MUST BE SORTED! */ + {"ASCII", 1252}, + {"ASMO-708", 708}, + {"BIG5", 950}, + {"CHINESE", 936}, + {"CP367", 1252}, + {"CP819", 1252}, + {"CP1025", 21025}, + {"DOS-720", 720}, + {"DOS-862", 862}, + {"EUC-CN", 51936}, + {"EUC-JP", 51932}, + {"EUC-KR", 949}, + {"EUCCN", 51936}, + {"EUCJP", 51932}, + {"EUCKR", 949}, + {"GB18030", 54936}, + {"GB2312", 936}, + {"HEBREW", 1255}, + {"HZ-GB-2312", 52936}, + {"IBM273", 20273}, + {"IBM277", 20277}, + {"IBM278", 20278}, + {"IBM280", 20280}, + {"IBM284", 20284}, + {"IBM285", 20285}, + {"IBM290", 20290}, + {"IBM297", 20297}, + {"IBM367", 1252}, + {"IBM420", 20420}, + {"IBM423", 20423}, + {"IBM424", 20424}, + {"IBM819", 1252}, + {"IBM871", 20871}, + {"IBM880", 20880}, + {"IBM905", 20905}, + {"IBM924", 20924}, + {"ISO-8859-1", 28591}, + {"ISO-8859-13", 28603}, + {"ISO-8859-15", 28605}, + {"ISO-8859-2", 28592}, + {"ISO-8859-3", 28593}, + {"ISO-8859-4", 28594}, + {"ISO-8859-5", 28595}, + {"ISO-8859-6", 28596}, + {"ISO-8859-7", 28597}, + {"ISO-8859-8", 28598}, + {"ISO-8859-9", 28599}, + {"ISO8859-1", 28591}, + {"ISO8859-13", 28603}, + {"ISO8859-15", 28605}, + {"ISO8859-2", 28592}, + {"ISO8859-3", 28593}, + {"ISO8859-4", 28594}, + {"ISO8859-5", 28595}, + {"ISO8859-6", 28596}, + {"ISO8859-7", 28597}, + {"ISO8859-8", 28598}, + {"ISO8859-9", 28599}, + {"JOHAB", 1361}, + {"KOI8-R", 20866}, + {"KOI8-U", 21866}, + {"KS_C_5601-1987", 949}, + {"LATIN1", 1252}, + {"LATIN2", 28592}, + {"MACINTOSH", 10000}, + {"SHIFT-JIS", 932}, + {"SHIFT_JIS", 932}, + {"SJIS", 932}, + {"US", 1252}, + {"US-ASCII", 1252}, + {"UTF-16", 1200}, + {"UTF-16BE", 1201}, + {"UTF-16LE", 1200}, + {"UTF-8", CP_UTF8}, + {"X-EUROPA", 29001}, + {"X-MAC-ARABIC", 10004}, + {"X-MAC-CE", 10029}, + {"X-MAC-CHINESEIMP", 10008}, + {"X-MAC-CHINESETRAD", 10002}, + {"X-MAC-CROATIAN", 10082}, + {"X-MAC-CYRILLIC", 10007}, + {"X-MAC-GREEK", 10006}, + {"X-MAC-HEBREW", 10005}, + {"X-MAC-ICELANDIC", 10079}, + {"X-MAC-JAPANESE", 10001}, + {"X-MAC-KOREAN", 10003}, + {"X-MAC-ROMANIAN", 10010}, + {"X-MAC-THAI", 10021}, + {"X-MAC-TURKISH", 10081}, + {"X-MAC-UKRAINIAN", 10017}, +}; +static unsigned +make_codepage_from_charset(const char *charset) +{ + char cs[16]; + char *p; + unsigned cp; + int a, b; + + if (charset == NULL || strlen(charset) > 15) + return -1; + + /* Copy name to uppercase. */ + p = cs; + while (*charset) { + char c = *charset++; + if (c >= 'a' && c <= 'z') + c -= 'a' - 'A'; + *p++ = c; + } + *p++ = '\0'; + cp = -1; + + /* Look it up in the table first, so that we can easily + * override CP367, which we map to 1252 instead of 367. */ + a = 0; + b = sizeof(charsets)/sizeof(charsets[0]); + while (b > a) { + int c = (b + a) / 2; + int r = strcmp(charsets[c].name, cs); + if (r < 0) + a = c + 1; + else if (r > 0) + b = c; + else + return charsets[c].cp; + } + + /* If it's not in the table, try to parse it. */ + switch (*cs) { + case 'C': + if (cs[1] == 'P' && cs[2] >= '0' && cs[2] <= '9') { + cp = my_atoi(cs + 2); + } else if (strcmp(cs, "CP_ACP") == 0) + cp = get_current_codepage(); + else if (strcmp(cs, "CP_OEMCP") == 0) + cp = get_current_oemcp(); + break; + case 'I': + if (cs[1] == 'B' && cs[2] == 'M' && + cs[3] >= '0' && cs[3] <= '9') { + cp = my_atoi(cs + 3); + } + break; + case 'W': + if (strncmp(cs, "WINDOWS-", 8) == 0) { + cp = my_atoi(cs + 8); + if (cp != 874 && (cp < 1250 || cp > 1258)) + cp = -1;/* This may invalid code. */ + } + break; + } + return (cp); +} + +/* + * Return ANSI Code Page of current locale set by setlocale(). + */ +static unsigned +get_current_codepage() +{ + char *locale, *p; + unsigned cp; + + locale = setlocale(LC_CTYPE, NULL); + if (locale == NULL) + return (GetACP()); + if (locale[0] == 'C' && locale[1] == '\0') + return (CP_C_LOCALE); + p = strrchr(locale, '.'); + if (p == NULL) + return (GetACP()); + cp = my_atoi(p+1); + if (cp <= 0) + return (GetACP()); + return (cp); } -#endif /* _WIN32 && ! __CYGWIN__ */ +/* + * Translation table between Locale Name and ACP/OEMCP. + */ +static struct { + unsigned acp; + unsigned ocp; + const char *locale; +} acp_ocp_map[] = { + { 950, 950, "Chinese_Taiwan" }, + { 936, 936, "Chinese_People's Republic of China" }, + { 950, 950, "Chinese_Taiwan" }, + { 1250, 852, "Czech_Czech Republic" }, + { 1252, 850, "Danish_Denmark" }, + { 1252, 850, "Dutch_Netherlands" }, + { 1252, 850, "Dutch_Belgium" }, + { 1252, 437, "English_United States" }, + { 1252, 850, "English_Australia" }, + { 1252, 850, "English_Canada" }, + { 1252, 850, "English_New Zealand" }, + { 1252, 850, "English_United Kingdom" }, + { 1252, 437, "English_United States" }, + { 1252, 850, "Finnish_Finland" }, + { 1252, 850, "French_France" }, + { 1252, 850, "French_Belgium" }, + { 1252, 850, "French_Canada" }, + { 1252, 850, "French_Switzerland" }, + { 1252, 850, "German_Germany" }, + { 1252, 850, "German_Austria" }, + { 1252, 850, "German_Switzerland" }, + { 1253, 737, "Greek_Greece" }, + { 1250, 852, "Hungarian_Hungary" }, + { 1252, 850, "Icelandic_Iceland" }, + { 1252, 850, "Italian_Italy" }, + { 1252, 850, "Italian_Switzerland" }, + { 932, 932, "Japanese_Japan" }, + { 949, 949, "Korean_Korea" }, + { 1252, 850, "Norwegian (BokmOl)_Norway" }, + { 1252, 850, "Norwegian (BokmOl)_Norway" }, + { 1252, 850, "Norwegian-Nynorsk_Norway" }, + { 1250, 852, "Polish_Poland" }, + { 1252, 850, "Portuguese_Portugal" }, + { 1252, 850, "Portuguese_Brazil" }, + { 1251, 866, "Russian_Russia" }, + { 1250, 852, "Slovak_Slovakia" }, + { 1252, 850, "Spanish_Spain" }, + { 1252, 850, "Spanish_Mexico" }, + { 1252, 850, "Spanish_Spain" }, + { 1252, 850, "Swedish_Sweden" }, + { 1254, 857, "Turkish_Turkey" }, + { 0, 0, NULL} +}; + +/* + * Return OEM Code Page of current locale set by setlocale(). + */ +static unsigned +get_current_oemcp() +{ + int i; + char *locale, *p; + size_t len; + + locale = setlocale(LC_CTYPE, NULL); + if (locale == NULL) + return (GetOEMCP()); + if (locale[0] == 'C' && locale[1] == '\0') + return (CP_C_LOCALE); + + p = strrchr(locale, '.'); + if (p == NULL) + return (GetOEMCP()); + len = p - locale; + for (i = 0; acp_ocp_map[i].acp; i++) { + if (strncmp(acp_ocp_map[i].locale, locale, len) == 0) + return (acp_ocp_map[i].ocp); + } + return (GetOEMCP()); +} +#else + +/* + * POSIX platform does not use CodePage. + */ + +static unsigned +get_current_codepage() +{ + return (-1);/* Unknown */ +} +static unsigned +make_codepage_from_charset(const char *charset) +{ + (void)charset; /* UNUSED */ + return (-1);/* Unknown */ +} +static unsigned +get_current_oemcp() +{ + return (-1);/* Unknown */ +} + +#endif /* defined(_WIN32) && !defined(__CYGWIN__) */ + +/* + * Return a string conversion object. + */ +static struct archive_string_conv * +get_sconv_object(struct archive *a, const char *fc, const char *tc, int flag) +{ + struct archive_string_conv *sc; + unsigned current_codepage; + + /* Check if we have made the sconv object. */ + sc = find_sconv_object(a, fc, tc); + if (sc != NULL) + return (sc); + + if (a == NULL) + current_codepage = get_current_codepage(); + else + current_codepage = a->current_codepage; + + sc = create_sconv_object(canonical_charset_name(fc), + canonical_charset_name(tc), current_codepage, flag); + if (sc == NULL) { + if (a != NULL) + archive_set_error(a, ENOMEM, + "Could not allocate memory for " + "a string conversion object"); + return (NULL); + } + + /* + * If there is no converter for current string conversion object, + * we cannot handle this conversion. + */ + if (sc->nconverter == 0) { + if (a != NULL) { +#if HAVE_ICONV + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "iconv_open failed : Cannot handle ``%s''", + (flag & SCONV_TO_CHARSET)?tc:fc); +#else + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "A character-set conversion not fully supported " + "on this platform"); +#endif + } + /* Failed; free a sconv object. */ + free_sconv_object(sc); + return (NULL); + } + + /* + * Success! + */ + if (a != NULL) + add_sconv_object(a, sc); + return (sc); +} + +static const char * +get_current_charset(struct archive *a) +{ + const char *cur_charset; + + if (a == NULL) + cur_charset = default_iconv_charset(""); + else { + cur_charset = default_iconv_charset(a->current_code); + if (a->current_code == NULL) { + a->current_code = strdup(cur_charset); + a->current_codepage = get_current_codepage(); + a->current_oemcp = get_current_oemcp(); + } + } + return (cur_charset); +} + +/* + * Make and Return a string conversion object. + * Return NULL if the platform does not support the specified conversion + * and best_effort is 0. + * If best_effort is set, A string conversion object must be returned + * unless memory allocation for the object fails, but the conversion + * might fail when non-ASCII code is found. + */ +struct archive_string_conv * +archive_string_conversion_to_charset(struct archive *a, const char *charset, + int best_effort) +{ + int flag = SCONV_TO_CHARSET; + + if (best_effort) + flag |= SCONV_BEST_EFFORT; + return (get_sconv_object(a, get_current_charset(a), charset, flag)); +} + +struct archive_string_conv * +archive_string_conversion_from_charset(struct archive *a, const char *charset, + int best_effort) +{ + int flag = SCONV_FROM_CHARSET; + + if (best_effort) + flag |= SCONV_BEST_EFFORT; + return (get_sconv_object(a, charset, get_current_charset(a), flag)); +} + +/* + * archive_string_default_conversion_*_archive() are provided for Windows + * platform because other archiver application use CP_OEMCP for + * MultiByteToWideChar() and WideCharToMultiByte() for the filenames + * in tar or zip files. But mbstowcs/wcstombs(CRT) usually use CP_ACP + * unless you use setlocale(LC_ALL, ".OCP")(specify CP_OEMCP). + * So we should make a string conversion between CP_ACP and CP_OEMCP + * for compatibillty. + */ +#if defined(_WIN32) && !defined(__CYGWIN__) +struct archive_string_conv * +archive_string_default_conversion_for_read(struct archive *a) +{ + const char *cur_charset = get_current_charset(a); + char oemcp[16]; + + /* NOTE: a check of cur_charset is unneeded but we need + * that get_current_charset() has been surely called at + * this time whatever C compiler optimized. */ + if (cur_charset != NULL && + (a->current_codepage == CP_C_LOCALE || + a->current_codepage == a->current_oemcp)) + return (NULL);/* no conversion. */ + + _snprintf(oemcp, sizeof(oemcp)-1, "CP%d", a->current_oemcp); + /* Make sure a null termination must be set. */ + oemcp[sizeof(oemcp)-1] = '\0'; + return (get_sconv_object(a, oemcp, cur_charset, + SCONV_FROM_CHARSET)); +} + +struct archive_string_conv * +archive_string_default_conversion_for_write(struct archive *a) +{ + const char *cur_charset = get_current_charset(a); + char oemcp[16]; + + /* NOTE: a check of cur_charset is unneeded but we need + * that get_current_charset() has been surely called at + * this time whatever C compiler optimized. */ + if (cur_charset != NULL && + (a->current_codepage == CP_C_LOCALE || + a->current_codepage == a->current_oemcp)) + return (NULL);/* no conversion. */ + + _snprintf(oemcp, sizeof(oemcp)-1, "CP%d", a->current_oemcp); + /* Make sure a null termination must be set. */ + oemcp[sizeof(oemcp)-1] = '\0'; + return (get_sconv_object(a, cur_charset, oemcp, + SCONV_TO_CHARSET)); +} +#else +struct archive_string_conv * +archive_string_default_conversion_for_read(struct archive *a) +{ + (void)a; /* UNUSED */ + return (NULL); +} + +struct archive_string_conv * +archive_string_default_conversion_for_write(struct archive *a) +{ + (void)a; /* UNUSED */ + return (NULL); +} +#endif + +/* + * Dispose of all character conversion objects in the archive object. + */ +void +archive_string_conversion_free(struct archive *a) +{ + struct archive_string_conv *sc; + struct archive_string_conv *sc_next; + + for (sc = a->sconv; sc != NULL; sc = sc_next) { + sc_next = sc->next; + free_sconv_object(sc); + } + a->sconv = NULL; + free(a->current_code); + a->current_code = NULL; +} + +/* + * Return a conversion charset name. + */ +const char * +archive_string_conversion_charset_name(struct archive_string_conv *sc) +{ + if (sc->flag & SCONV_TO_CHARSET) + return (sc->to_charset); + else + return (sc->from_charset); +} + +/* + * Change the behavior of a string conversion. + */ +void +archive_string_conversion_set_opt(struct archive_string_conv *sc, int opt) +{ + switch (opt) { + /* + * A filename in UTF-8 was made with libarchive 2.x in a wrong + * assumption that wchar_t was Unicode. + * This option enables simulating the assumption in order to read + * that filname correctly. + */ + case SCONV_SET_OPT_UTF8_LIBARCHIVE2X: +#if (defined(_WIN32) && !defined(__CYGWIN__)) \ + || defined(__STDC_ISO_10646__) || defined(__APPLE__) + /* + * Nothing to do for it since wchar_t on these platforms + * is really Unicode. + */ + (void)sc; /* UNUSED */ +#else + if ((sc->flag & SCONV_UTF8_LIBARCHIVE_2) == 0) { + sc->flag |= SCONV_UTF8_LIBARCHIVE_2; + /* Re-setup string converters. */ + setup_converter(sc); + } +#endif + break; + default: + break; + } +} + +/* + * + * Copy one archive_string to another in locale conversion. + * + * archive_strncpy_in_locale(); + * archive_strcpy_in_locale(); + * + */ + +static size_t +mbsnbytes(const void *_p, size_t n) +{ + size_t s; + const char *p, *pp; + + if (_p == NULL) + return (0); + p = (const char *)_p; + + /* Like strlen(p), except won't examine positions beyond p[n]. */ + s = 0; + pp = p; + while (s < n && *pp) { + pp++; + s++; + } + return (s); +} + +static size_t +utf16nbytes(const void *_p, size_t n) +{ + size_t s; + const char *p, *pp; + + if (_p == NULL) + return (0); + p = (const char *)_p; + + /* Like strlen(p), except won't examine positions beyond p[n]. */ + s = 0; + pp = p; + n >>= 1; + while (s < n && (pp[0] || pp[1])) { + pp += 2; + s++; + } + return (s<<1); +} + +int +archive_strncpy_in_locale(struct archive_string *as, const void *_p, size_t n, + struct archive_string_conv *sc) +{ + as->length = 0; + return (archive_strncat_in_locale(as, _p, n, sc)); +} + +int +archive_strncat_in_locale(struct archive_string *as, const void *_p, size_t n, + struct archive_string_conv *sc) +{ + const void *s; + size_t length; + int i, r = 0, r2; + + /* We must allocate memory even if there is no data for conversion + * or copy. This simulates archive_string_append behavior. */ + if (_p == NULL || n == 0) { + int tn = 1; + if (sc != NULL && (sc->flag & SCONV_TO_UTF16)) + tn = 2; + if (archive_string_ensure(as, as->length + tn) == NULL) + return (-1); + as->s[as->length] = 0; + if (tn == 2) + as->s[as->length+1] = 0; + return (0); + } + + /* + * If sc is NULL, we just make a copy. + */ + if (sc == NULL) { + length = mbsnbytes(_p, n); + if (archive_string_append(as, _p, length) == NULL) + return (-1);/* No memory */ + return (0); + } + + if (sc->flag & SCONV_FROM_UTF16) + length = utf16nbytes(_p, n); + else + length = mbsnbytes(_p, n); + s = _p; + i = 0; + if (sc->nconverter > 1) { + sc->utftmp.length = 0; + r2 = sc->converter[0](&(sc->utftmp), s, length, sc); + if (r2 != 0 && errno == ENOMEM) + return (r2); + if (r > r2) + r = r2; + s = sc->utftmp.s; + length = sc->utftmp.length; + ++i; + } + r2 = sc->converter[i](as, s, length, sc); + if (r > r2) + r = r2; + return (r); +} + +#if HAVE_ICONV + +/* + * Return -1 if conversion failes. + */ +static int +iconv_strncat_in_locale(struct archive_string *as, const void *_p, + size_t length, struct archive_string_conv *sc) +{ + ICONV_CONST char *inp; + size_t remaining; + iconv_t cd; + char *outp; + size_t avail, bs; + int return_value = 0; /* success */ + int to_size, from_size; + + if (sc->flag & SCONV_TO_UTF16) + to_size = 2; + else + to_size = 1; + if (sc->flag & SCONV_FROM_UTF16) + from_size = 2; + else + from_size = 1; + + if (archive_string_ensure(as, as->length + length*2+to_size) == NULL) + return (-1); + + cd = sc->cd; + inp = (char *)(uintptr_t)_p; + remaining = length; + outp = as->s + as->length; + avail = as->buffer_length - as->length - to_size; + while (remaining >= (size_t)from_size) { + size_t result = iconv(cd, &inp, &remaining, &outp, &avail); + + if (result != (size_t)-1) + break; /* Conversion completed. */ + + if (errno == EILSEQ || errno == EINVAL) { + /* + * If an output charset is UTF-8 or UTF-16BE/LE, + * unknown character should be U+FFFD + * (replacement character). + */ + if (sc->flag & (SCONV_TO_UTF8 | SCONV_TO_UTF16)) { + size_t rbytes; + if (sc->flag & SCONV_TO_UTF8) + rbytes = UTF8_R_CHAR_SIZE; + else + rbytes = 2; + + if (avail < rbytes) { + as->length = outp - as->s; + bs = as->buffer_length + + (remaining * to_size) + rbytes; + if (NULL == + archive_string_ensure(as, bs)) + return (-1); + outp = as->s + as->length; + avail = as->buffer_length + - as->length - to_size; + } + if (sc->flag & SCONV_TO_UTF8) + UTF8_SET_R_CHAR(outp); + else if (sc->flag & SCONV_TO_UTF16BE) + archive_be16enc(outp, UNICODE_R_CHAR); + else + archive_le16enc(outp, UNICODE_R_CHAR); + outp += rbytes; + avail -= rbytes; + } else { + /* Skip the illegal input bytes. */ + *outp++ = '?'; + avail--; + } + inp += from_size; + remaining -= from_size; + return_value = -1; /* failure */ + } else { + /* E2BIG no output buffer, + * Increase an output buffer. */ + as->length = outp - as->s; + bs = as->buffer_length + remaining * 2; + if (NULL == archive_string_ensure(as, bs)) + return (-1); + outp = as->s + as->length; + avail = as->buffer_length - as->length - to_size; + } + } + as->length = outp - as->s; + as->s[as->length] = 0; + if (to_size == 2) + as->s[as->length+1] = 0; + return (return_value); +} + +#endif /* HAVE_ICONV */ + + +#if defined(_WIN32) && !defined(__CYGWIN__) + +/* + * Translate a string from a some CodePage to an another CodePage by + * Windows APIs, and copy the result. Return -1 if conversion failes. + */ +static int +strncat_in_codepage(struct archive_string *as, + const void *_p, size_t length, struct archive_string_conv *sc) +{ + const char *s = (const char *)_p; + struct archive_wstring aws; + size_t l; + int r, saved_flag; + + archive_string_init(&aws); + saved_flag = sc->flag; + sc->flag &= ~(SCONV_NORMALIZATION_D | SCONV_NORMALIZATION_C); + r = archive_wstring_append_from_mbs_in_codepage(&aws, s, length, sc); + sc->flag = saved_flag; + if (r != 0) { + archive_wstring_free(&aws); + if (errno != ENOMEM) + archive_string_append(as, s, length); + return (-1); + } + + l = as->length; + r = archive_string_append_from_wcs_in_codepage( + as, aws.s, aws.length, sc); + if (r != 0 && errno != ENOMEM && l == as->length) + archive_string_append(as, s, length); + archive_wstring_free(&aws); + return (r); +} + +/* + * Test whether MBS ==> WCS is okay. + */ +static int +invalid_mbs(const void *_p, size_t n, struct archive_string_conv *sc) +{ + const char *p = (const char *)_p; + unsigned codepage; + DWORD mbflag = MB_ERR_INVALID_CHARS; + + if (sc->flag & SCONV_FROM_CHARSET) + codepage = sc->to_cp; + else + codepage = sc->from_cp; + + if (codepage == CP_C_LOCALE) + return (0); + if (codepage != CP_UTF8) + mbflag |= MB_PRECOMPOSED; + + if (MultiByteToWideChar(codepage, mbflag, p, n, NULL, 0) == 0) + return (-1); /* Invalid */ + return (0); /* Okay */ +} + +#else + +/* + * Test whether MBS ==> WCS is okay. + */ +static int +invalid_mbs(const void *_p, size_t n, struct archive_string_conv *sc) +{ + const char *p = (const char *)_p; + size_t r; + +#if HAVE_MBRTOWC + mbstate_t shift_state; + + memset(&shift_state, 0, sizeof(shift_state)); +#else + /* Clear the shift state before starting. */ + mbtowc(NULL, NULL, 0); +#endif + while (n) { + wchar_t wc; + +#if HAVE_MBRTOWC + r = mbrtowc(&wc, p, n, &shift_state); +#else + r = mbtowc(&wc, p, n); +#endif + if (r == (size_t)-1 || r == (size_t)-2) + return (-1);/* Invalid. */ + if (r == 0) + break; + p += r; + n -= r; + } + (void)sc; /* UNUSED */ + return (0); /* All Okey. */ +} + +#endif /* defined(_WIN32) && !defined(__CYGWIN__) */ + +/* + * Basically returns -1 because we cannot make a conversion of charset + * without iconv but in some cases this would return 0. + * Returns 0 if all copied characters are ASCII. + * Returns 0 if both from-locale and to-locale are the same and those + * can be WCS with no error. + */ +static int +best_effort_strncat_in_locale(struct archive_string *as, const void *_p, + size_t length, struct archive_string_conv *sc) +{ + size_t remaining; + char *outp; + const char *inp; + size_t avail; + int return_value = 0; /* success */ + + /* + * If both from-locale and to-locale is the same, this makes a copy. + * And then this checks all copied MBS can be WCS if so returns 0. + */ + if (sc->same) { + if (archive_string_append(as, _p, length) == NULL) + return (-1);/* No memory */ + return (invalid_mbs(_p, length, sc)); + } + + /* + * If a character is ASCII, this just copies it. If not, this + * assigns '?' charater instead but in UTF-8 locale this assigns + * byte sequence 0xEF 0xBD 0xBD, which are code point U+FFFD, + * a Replacement Character in Unicode. + */ + if (archive_string_ensure(as, as->length + length + 1) == NULL) + return (-1); + + remaining = length; + inp = (const char *)_p; + outp = as->s + as->length; + avail = as->buffer_length - as->length -1; + while (*inp && remaining > 0) { + if (*inp < 0 && (sc->flag & SCONV_TO_UTF8)) { + if (avail < UTF8_R_CHAR_SIZE) { + as->length = outp - as->s; + if (NULL == archive_string_ensure(as, + as->buffer_length + remaining + + UTF8_R_CHAR_SIZE)) + return (-1); + outp = as->s + as->length; + avail = as->buffer_length - as->length -1; + } + /* + * When coping a string in UTF-8, unknown character + * should be U+FFFD (replacement character). + */ + UTF8_SET_R_CHAR(outp); + outp += UTF8_R_CHAR_SIZE; + avail -= UTF8_R_CHAR_SIZE; + inp++; + remaining--; + return_value = -1; + } else if (*inp < 0) { + *outp++ = '?'; + inp++; + remaining--; + return_value = -1; + } else { + *outp++ = *inp++; + remaining--; + } + } + as->length = outp - as->s; + as->s[as->length] = '\0'; + return (return_value); +} + + +/* + * Unicode conversion functions. + * - UTF-8 <===> UTF-8 in removing surrogate pairs. + * - UTF-8 NFD ===> UTF-8 NFC in removing surrogate pairs. + * - UTF-8 made by libarchive 2.x ===> UTF-8. + * - UTF-16BE <===> UTF-8. + * + */ + +/* + * Utility to convert a single UTF-8 sequence. + * + * Usually return used bytes, return used byte in negative value when + * a unicode character is replaced with U+FFFD. + * See also http://unicode.org/review/pr-121.html Public Review Issue #121 + * Recommended Practice for Replacement Characters. + */ +static int +_utf8_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + static const char utf8_count[256] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 00 - 0F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 10 - 1F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20 - 2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30 - 3F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40 - 4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 50 - 5F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60 - 6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 70 - 7F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 80 - 8F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 90 - 9F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* A0 - AF */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* B0 - BF */ + 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* C0 - CF */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,/* D0 - DF */ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,/* E0 - EF */ + 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* F0 - FF */ + }; + int ch, i; + int cnt; + uint32_t wc; + + /* Sanity check. */ + if (n == 0) + return (0); + /* + * Decode 1-4 bytes depending on the value of the first byte. + */ + ch = (unsigned char)*s; + if (ch == 0) + return (0); /* Standard: return 0 for end-of-string. */ + cnt = utf8_count[ch]; + + /* Invalide sequence or there are not plenty bytes. */ + if ((int)n < cnt) { + cnt = n; + for (i = 1; i < cnt; i++) { + if ((s[i] & 0xc0) != 0x80) { + cnt = i; + break; + } + } + goto invalid_sequence; + } + + /* Make a Unicode code point from a single UTF-8 sequence. */ + switch (cnt) { + case 1: /* 1 byte sequence. */ + *pwc = ch & 0x7f; + return (cnt); + case 2: /* 2 bytes sequence. */ + if ((s[1] & 0xc0) != 0x80) { + cnt = 1; + goto invalid_sequence; + } + *pwc = ((ch & 0x1f) << 6) | (s[1] & 0x3f); + return (cnt); + case 3: /* 3 bytes sequence. */ + if ((s[1] & 0xc0) != 0x80) { + cnt = 1; + goto invalid_sequence; + } + if ((s[2] & 0xc0) != 0x80) { + cnt = 2; + goto invalid_sequence; + } + wc = ((ch & 0x0f) << 12) + | ((s[1] & 0x3f) << 6) + | (s[2] & 0x3f); + if (wc < 0x800) + goto invalid_sequence;/* Overlong sequence. */ + break; + case 4: /* 4 bytes sequence. */ + if ((s[1] & 0xc0) != 0x80) { + cnt = 1; + goto invalid_sequence; + } + if ((s[2] & 0xc0) != 0x80) { + cnt = 2; + goto invalid_sequence; + } + if ((s[3] & 0xc0) != 0x80) { + cnt = 3; + goto invalid_sequence; + } + wc = ((ch & 0x07) << 18) + | ((s[1] & 0x3f) << 12) + | ((s[2] & 0x3f) << 6) + | (s[3] & 0x3f); + if (wc < 0x10000) + goto invalid_sequence;/* Overlong sequence. */ + break; + default: /* Others are all invalid sequence. */ + if (ch == 0xc0 || ch == 0xc1) + cnt = 2; + else if (ch >= 0xf5 && ch <= 0xf7) + cnt = 4; + else if (ch >= 0xf8 && ch <= 0xfb) + cnt = 5; + else if (ch == 0xfc || ch == 0xfd) + cnt = 6; + else + cnt = 1; + if ((int)n < cnt) + cnt = n; + for (i = 1; i < cnt; i++) { + if ((s[i] & 0xc0) != 0x80) { + cnt = i; + break; + } + } + goto invalid_sequence; + } + + /* The code point larger than 0x10FFFF is not leagal + * Unicode values. */ + if (wc > UNICODE_MAX) + goto invalid_sequence; + /* Correctly gets a Unicode, returns used bytes. */ + *pwc = wc; + return (cnt); +invalid_sequence: + *pwc = UNICODE_R_CHAR;/* set the Replacement Character instead. */ + return (cnt * -1); +} + +static int +utf8_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + int cnt; + + cnt = _utf8_to_unicode(pwc, s, n); + /* Any of Surrogate pair is not leagal Unicode values. */ + if (cnt == 3 && IS_SURROGATE_PAIR_LA(*pwc)) + return (-3); + return (cnt); +} + +static inline uint32_t +combine_surrogate_pair(uint32_t uc, uint32_t uc2) +{ + uc -= 0xD800; + uc *= 0x400; + uc += uc2 - 0xDC00; + uc += 0x10000; + return (uc); +} + +/* + * Convert a single UTF-8/CESU-8 sequence to a Unicode code point in + * removing surrogate pairs. + * + * CESU-8: The Compatibility Encoding Scheme for UTF-16. + * + * Usually return used bytes, return used byte in negative value when + * a unicode character is replaced with U+FFFD. + */ +static int +cesu8_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + uint32_t wc, wc2; + int cnt; + + cnt = _utf8_to_unicode(&wc, s, n); + if (cnt == 3 && IS_HIGH_SURROGATE_LA(wc)) { + if (n - 3 < 3) { + /* Invalid byte sequence. */ + goto invalid_sequence; + } + cnt = _utf8_to_unicode(&wc2, s+3, n-3); + if (cnt != 3 || !IS_LOW_SURROGATE_LA(wc2)) { + /* Invalid byte sequence. */ + goto invalid_sequence; + } + wc = combine_surrogate_pair(wc, wc2); + cnt = 6; + } else if (cnt == 3 && IS_LOW_SURROGATE_LA(wc)) { + /* Invalid byte sequence. */ + goto invalid_sequence; + } + *pwc = wc; + return (cnt); +invalid_sequence: + *pwc = UNICODE_R_CHAR;/* set the Replacement Character instead. */ + if (cnt > 0) + cnt *= -1; + return (cnt); +} + +/* + * Convert a Unicode code point to a single UTF-8 sequence. + * + * NOTE:This function does not check if the Unicode is leagal or not. + * Please you definitely check it before calling this. + */ +static size_t +unicode_to_utf8(char *p, size_t remaining, uint32_t uc) +{ + char *_p = p; + + /* Translate code point to UTF8 */ + if (uc <= 0x7f) { + if (remaining == 0) + return (0); + *p++ = (char)uc; + } else if (uc <= 0x7ff) { + if (remaining < 2) + return (0); + *p++ = 0xc0 | ((uc >> 6) & 0x1f); + *p++ = 0x80 | (uc & 0x3f); + } else if (uc <= 0xffff) { + if (remaining < 3) + return (0); + *p++ = 0xe0 | ((uc >> 12) & 0x0f); + *p++ = 0x80 | ((uc >> 6) & 0x3f); + *p++ = 0x80 | (uc & 0x3f); + } else if (uc <= UNICODE_MAX) { + if (remaining < 4) + return (0); + *p++ = 0xf0 | ((uc >> 18) & 0x07); + *p++ = 0x80 | ((uc >> 12) & 0x3f); + *p++ = 0x80 | ((uc >> 6) & 0x3f); + *p++ = 0x80 | (uc & 0x3f); + } else { + /* + * Undescribed code point should be U+FFFD + * (replacement character). + */ + if (remaining < UTF8_R_CHAR_SIZE) + return (0); + UTF8_SET_R_CHAR(p); + p += UTF8_R_CHAR_SIZE; + } + return (p - _p); +} + +static int +utf16be_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + return (utf16_to_unicode(pwc, s, n, 1)); +} + +static int +utf16le_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + return (utf16_to_unicode(pwc, s, n, 0)); +} + +static int +utf16_to_unicode(uint32_t *pwc, const char *s, size_t n, int be) +{ + const char *utf16 = s; + unsigned uc; + + if (n == 0) + return (0); + if (n == 1) { + /* set the Replacement Character instead. */ + *pwc = UNICODE_R_CHAR; + return (-1); + } + + if (be) + uc = archive_be16dec(utf16); + else + uc = archive_le16dec(utf16); + utf16 += 2; + + /* If this is a surrogate pair, assemble the full code point.*/ + if (IS_HIGH_SURROGATE_LA(uc)) { + unsigned uc2; + + if (n >= 4) { + if (be) + uc2 = archive_be16dec(utf16); + else + uc2 = archive_le16dec(utf16); + } else + uc2 = 0; + if (IS_LOW_SURROGATE_LA(uc2)) { + uc = combine_surrogate_pair(uc, uc2); + utf16 += 2; + } else { + /* Undescribed code point should be U+FFFD + * (replacement character). */ + *pwc = UNICODE_R_CHAR; + return (-2); + } + } + + /* + * Surrogate pair values(0xd800 through 0xdfff) are only + * used by UTF-16, so, after above culculation, the code + * must not be surrogate values, and Unicode has no codes + * larger than 0x10ffff. Thus, those are not leagal Unicode + * values. + */ + if (IS_SURROGATE_PAIR_LA(uc) || uc > UNICODE_MAX) { + /* Undescribed code point should be U+FFFD + * (replacement character). */ + *pwc = UNICODE_R_CHAR; + return (((int)(utf16 - s)) * -1); + } + *pwc = uc; + return ((int)(utf16 - s)); +} + +static size_t +unicode_to_utf16be(char *p, size_t remaining, uint32_t uc) +{ + char *utf16 = p; + + if (uc > 0xffff) { + /* We have a code point that won't fit into a + * wchar_t; convert it to a surrogate pair. */ + if (remaining < 4) + return (0); + uc -= 0x10000; + archive_be16enc(utf16, ((uc >> 10) & 0x3ff) + 0xD800); + archive_be16enc(utf16+2, (uc & 0x3ff) + 0xDC00); + return (4); + } else { + if (remaining < 2) + return (0); + archive_be16enc(utf16, uc); + return (2); + } +} + +static size_t +unicode_to_utf16le(char *p, size_t remaining, uint32_t uc) +{ + char *utf16 = p; + + if (uc > 0xffff) { + /* We have a code point that won't fit into a + * wchar_t; convert it to a surrogate pair. */ + if (remaining < 4) + return (0); + uc -= 0x10000; + archive_le16enc(utf16, ((uc >> 10) & 0x3ff) + 0xD800); + archive_le16enc(utf16+2, (uc & 0x3ff) + 0xDC00); + return (4); + } else { + if (remaining < 2) + return (0); + archive_le16enc(utf16, uc); + return (2); + } +} + +/* + * Copy UTF-8 string in checking surrogate pair. + * If any surrogate pair are found, it would be canonicalized. + */ +static int +strncat_from_utf8_to_utf8(struct archive_string *as, const void *_p, size_t len, + struct archive_string_conv *sc) +{ + const char *s; + char *p, *endp; + int n, ret = 0; + + (void)sc; /* UNUSED */ + + if (archive_string_ensure(as, as->length + len + 1) == NULL) + return (-1); + + s = (const char *)_p; + p = as->s + as->length; + endp = as->s + as->buffer_length -1; + do { + uint32_t uc; + const char *ss = s; + size_t w; + + /* + * Forward byte sequence until a conversion of that is needed. + */ + while ((n = utf8_to_unicode(&uc, s, len)) > 0) { + s += n; + len -= n; + } + if (ss < s) { + if (p + (s - ss) > endp) { + as->length = p - as->s; + if (archive_string_ensure(as, + as->buffer_length + len + 1) == NULL) + return (-1); + p = as->s + as->length; + endp = as->s + as->buffer_length -1; + } + + memcpy(p, ss, s - ss); + p += s - ss; + } + + /* + * If n is negative, current byte sequence needs a replacement. + */ + if (n < 0) { + if (n == -3 && IS_SURROGATE_PAIR_LA(uc)) { + /* Current byte sequence may be CESU-8. */ + n = cesu8_to_unicode(&uc, s, len); + } + if (n < 0) { + ret = -1; + n *= -1;/* Use a replaced unicode character. */ + } + + /* Rebuild UTF-8 byte sequence. */ + while ((w = unicode_to_utf8(p, endp - p, uc)) == 0) { + as->length = p - as->s; + if (archive_string_ensure(as, + as->buffer_length + len + 1) == NULL) + return (-1); + p = as->s + as->length; + endp = as->s + as->buffer_length -1; + } + p += w; + s += n; + len -= n; + } + } while (n > 0); + as->length = p - as->s; + as->s[as->length] = '\0'; + return (ret); +} + +static int +archive_string_append_unicode(struct archive_string *as, const void *_p, + size_t len, struct archive_string_conv *sc) +{ + const char *s; + char *p, *endp; + uint32_t uc; + size_t w; + int n, ret = 0, ts, tm; + int (*parse)(uint32_t *, const char *, size_t); + size_t (*unparse)(char *, size_t, uint32_t); + + if (sc->flag & SCONV_TO_UTF16BE) { + unparse = unicode_to_utf16be; + ts = 2; + } else if (sc->flag & SCONV_TO_UTF16LE) { + unparse = unicode_to_utf16le; + ts = 2; + } else if (sc->flag & SCONV_TO_UTF8) { + unparse = unicode_to_utf8; + ts = 1; + } else { + /* + * This case is going to be converted to another + * character-set through iconv. + */ + if (sc->flag & SCONV_FROM_UTF16BE) { + unparse = unicode_to_utf16be; + ts = 2; + } else if (sc->flag & SCONV_FROM_UTF16LE) { + unparse = unicode_to_utf16le; + ts = 2; + } else { + unparse = unicode_to_utf8; + ts = 1; + } + } + + if (sc->flag & SCONV_FROM_UTF16BE) { + parse = utf16be_to_unicode; + tm = 1; + } else if (sc->flag & SCONV_FROM_UTF16LE) { + parse = utf16le_to_unicode; + tm = 1; + } else { + parse = cesu8_to_unicode; + tm = ts; + } + + if (archive_string_ensure(as, as->length + len * tm + ts) == NULL) + return (-1); + + s = (const char *)_p; + p = as->s + as->length; + endp = as->s + as->buffer_length - ts; + while ((n = parse(&uc, s, len)) != 0) { + if (n < 0) { + /* Use a replaced unicode character. */ + n *= -1; + ret = -1; + } + s += n; + len -= n; + while ((w = unparse(p, endp - p, uc)) == 0) { + /* There is not enough output buffer so + * we have to expand it. */ + as->length = p - as->s; + if (archive_string_ensure(as, + as->buffer_length + len * tm + ts) == NULL) + return (-1); + p = as->s + as->length; + endp = as->s + as->buffer_length - ts; + } + p += w; + } + as->length = p - as->s; + as->s[as->length] = '\0'; + if (ts == 2) + as->s[as->length+1] = '\0'; + return (ret); +} + +/* + * Following Constants for Hangul compositions this information comes from + * Unicode Standard Annex #15 http://unicode.org/reports/tr15/ + */ +#define HC_SBASE 0xAC00 +#define HC_LBASE 0x1100 +#define HC_VBASE 0x1161 +#define HC_TBASE 0x11A7 +#define HC_LCOUNT 19 +#define HC_VCOUNT 21 +#define HC_TCOUNT 28 +#define HC_NCOUNT (HC_VCOUNT * HC_TCOUNT) +#define HC_SCOUNT (HC_LCOUNT * HC_NCOUNT) + +static uint32_t +get_nfc(uint32_t uc, uint32_t uc2) +{ + int t, b; + + t = 0; + b = sizeof(u_composition_table)/sizeof(u_composition_table[0]) -1; + while (b >= t) { + int m = (t + b) / 2; + if (u_composition_table[m].cp1 < uc) + t = m + 1; + else if (u_composition_table[m].cp1 > uc) + b = m - 1; + else if (u_composition_table[m].cp2 < uc2) + t = m + 1; + else if (u_composition_table[m].cp2 > uc2) + b = m - 1; + else + return (u_composition_table[m].nfc); + } + return (0); +} + +#define FDC_MAX 10 /* The maximum number of Following Decomposable + * Characters. */ + +/* + * Update first code point. + */ +#define UPDATE_UC(new_uc) do { \ + uc = new_uc; \ + ucptr = NULL; \ +} while (0) + +/* + * Replace first code point with second code point. + */ +#define REPLACE_UC_WITH_UC2() do { \ + uc = uc2; \ + ucptr = uc2ptr; \ + n = n2; \ +} while (0) + +#define EXPAND_BUFFER() do { \ + as->length = p - as->s; \ + if (archive_string_ensure(as, \ + as->buffer_length + len * tm + ts) == NULL)\ + return (-1); \ + p = as->s + as->length; \ + endp = as->s + as->buffer_length - ts; \ +} while (0) + +#define UNPARSE(p, endp, uc) do { \ + while ((w = unparse(p, (endp) - (p), uc)) == 0) {\ + EXPAND_BUFFER(); \ + } \ + p += w; \ +} while (0) + +/* + * Write first code point. + * If the code point has not be changed from its original code, + * this just copies it from its original buffer pointer. + * If not, this converts it to UTF-8 byte sequence and copies it. + */ +#define WRITE_UC() do { \ + if (ucptr) { \ + if (p + n > endp) \ + EXPAND_BUFFER(); \ + switch (n) { \ + case 4: \ + *p++ = *ucptr++; \ + /* FALL THROUGH */ \ + case 3: \ + *p++ = *ucptr++; \ + /* FALL THROUGH */ \ + case 2: \ + *p++ = *ucptr++; \ + /* FALL THROUGH */ \ + case 1: \ + *p++ = *ucptr; \ + break; \ + } \ + ucptr = NULL; \ + } else { \ + UNPARSE(p, endp, uc); \ + } \ +} while (0) + +/* + * Collect following decomposable code points. + */ +#define COLLECT_CPS(start) do { \ + int _i; \ + for (_i = start; _i < FDC_MAX ; _i++) { \ + nx = parse(&ucx[_i], s, len); \ + if (nx <= 0) \ + break; \ + cx = CCC(ucx[_i]); \ + if (cl >= cx && cl != 228 && cx != 228)\ + break; \ + s += nx; \ + len -= nx; \ + cl = cx; \ + ccx[_i] = cx; \ + } \ + if (_i >= FDC_MAX) { \ + ret = -1; \ + ucx_size = FDC_MAX; \ + } else \ + ucx_size = _i; \ +} while (0) + +/* + * Normalize UTF-8/UTF-16BE characters to Form C and copy the result. + * + * TODO: Convert composition exclusions,which are never converted + * from NFC,NFD,NFKC and NFKD, to Form C. + */ +static int +archive_string_normalize_C(struct archive_string *as, const void *_p, + size_t len, struct archive_string_conv *sc) +{ + const char *s = (const char *)_p; + char *p, *endp; + uint32_t uc, uc2; + size_t w; + int always_replace, n, n2, ret = 0, spair, ts, tm; + int (*parse)(uint32_t *, const char *, size_t); + size_t (*unparse)(char *, size_t, uint32_t); + + always_replace = 1; + ts = 1;/* text size. */ + if (sc->flag & SCONV_TO_UTF16BE) { + unparse = unicode_to_utf16be; + ts = 2; + if (sc->flag & SCONV_FROM_UTF16BE) + always_replace = 0; + } else if (sc->flag & SCONV_TO_UTF16LE) { + unparse = unicode_to_utf16le; + ts = 2; + if (sc->flag & SCONV_FROM_UTF16LE) + always_replace = 0; + } else if (sc->flag & SCONV_TO_UTF8) { + unparse = unicode_to_utf8; + if (sc->flag & SCONV_FROM_UTF8) + always_replace = 0; + } else { + /* + * This case is going to be converted to another + * character-set through iconv. + */ + always_replace = 0; + if (sc->flag & SCONV_FROM_UTF16BE) { + unparse = unicode_to_utf16be; + ts = 2; + } else if (sc->flag & SCONV_FROM_UTF16LE) { + unparse = unicode_to_utf16le; + ts = 2; + } else { + unparse = unicode_to_utf8; + } + } + + if (sc->flag & SCONV_FROM_UTF16BE) { + parse = utf16be_to_unicode; + tm = 1; + spair = 4;/* surrogate pair size in UTF-16. */ + } else if (sc->flag & SCONV_FROM_UTF16LE) { + parse = utf16le_to_unicode; + tm = 1; + spair = 4;/* surrogate pair size in UTF-16. */ + } else { + parse = cesu8_to_unicode; + tm = ts; + spair = 6;/* surrogate pair size in UTF-8. */ + } + + if (archive_string_ensure(as, as->length + len * tm + ts) == NULL) + return (-1); + + p = as->s + as->length; + endp = as->s + as->buffer_length - ts; + while ((n = parse(&uc, s, len)) != 0) { + const char *ucptr, *uc2ptr; + + if (n < 0) { + /* Use a replaced unicode character. */ + UNPARSE(p, endp, uc); + s += n*-1; + len -= n*-1; + ret = -1; + continue; + } else if (n == spair || always_replace) + /* uc is converted from a surrogate pair. + * this should be treated as a changed code. */ + ucptr = NULL; + else + ucptr = s; + s += n; + len -= n; + + /* Read second code point. */ + while ((n2 = parse(&uc2, s, len)) > 0) { + uint32_t ucx[FDC_MAX]; + int ccx[FDC_MAX]; + int cl, cx, i, nx, ucx_size; + int LIndex,SIndex; + uint32_t nfc; + + if (n2 == spair || always_replace) + /* uc2 is converted from a surrogate pair. + * this should be treated as a changed code. */ + uc2ptr = NULL; + else + uc2ptr = s; + s += n2; + len -= n2; + + /* + * If current second code point is out of decomposable + * code points, finding compositions is unneeded. + */ + if (!IS_DECOMPOSABLE_BLOCK(uc2)) { + WRITE_UC(); + REPLACE_UC_WITH_UC2(); + continue; + } + + /* + * Try to combine current code points. + */ + /* + * We have to combine Hangul characters according to + * http://uniicode.org/reports/tr15/#Hangul + */ + if (0 <= (LIndex = uc - HC_LBASE) && + LIndex < HC_LCOUNT) { + /* + * Hangul Composition. + * 1. Two current code points are L and V. + */ + int VIndex = uc2 - HC_VBASE; + if (0 <= VIndex && VIndex < HC_VCOUNT) { + /* Make syllable of form LV. */ + UPDATE_UC(HC_SBASE + + (LIndex * HC_VCOUNT + VIndex) * + HC_TCOUNT); + } else { + WRITE_UC(); + REPLACE_UC_WITH_UC2(); + } + continue; + } else if (0 <= (SIndex = uc - HC_SBASE) && + SIndex < HC_SCOUNT && (SIndex % HC_TCOUNT) == 0) { + /* + * Hangul Composition. + * 2. Two current code points are LV and T. + */ + int TIndex = uc2 - HC_TBASE; + if (0 < TIndex && TIndex < HC_TCOUNT) { + /* Make syllable of form LVT. */ + UPDATE_UC(uc + TIndex); + } else { + WRITE_UC(); + REPLACE_UC_WITH_UC2(); + } + continue; + } else if ((nfc = get_nfc(uc, uc2)) != 0) { + /* A composition to current code points + * is found. */ + UPDATE_UC(nfc); + continue; + } else if ((cl = CCC(uc2)) == 0) { + /* Clearly 'uc2' the second code point is not + * a decomposable code. */ + WRITE_UC(); + REPLACE_UC_WITH_UC2(); + continue; + } + + /* + * Collect following decomposable code points. + */ + cx = 0; + ucx[0] = uc2; + ccx[0] = cl; + COLLECT_CPS(1); + + /* + * Find a composed code in the collected code points. + */ + i = 1; + while (i < ucx_size) { + int j; + + if ((nfc = get_nfc(uc, ucx[i])) == 0) { + i++; + continue; + } + + /* + * nfc is composed of uc and ucx[i]. + */ + UPDATE_UC(nfc); + + /* + * Remove ucx[i] by shifting + * follwoing code points. + */ + for (j = i; j+1 < ucx_size; j++) { + ucx[j] = ucx[j+1]; + ccx[j] = ccx[j+1]; + } + ucx_size --; + + /* + * Collect following code points blocked + * by ucx[i] the removed code point. + */ + if (ucx_size > 0 && i == ucx_size && + nx > 0 && cx == cl) { + cl = ccx[ucx_size-1]; + COLLECT_CPS(ucx_size); + } + /* + * Restart finding a composed code with + * the updated uc from the top of the + * collected code points. + */ + i = 0; + } + + /* + * Apparently the current code points are not + * decomposed characters or already composed. + */ + WRITE_UC(); + for (i = 0; i < ucx_size; i++) + UNPARSE(p, endp, ucx[i]); + + /* + * Flush out remaining canonical combining characters. + */ + if (nx > 0 && cx == cl && len > 0) { + while ((nx = parse(&ucx[0], s, len)) + > 0) { + cx = CCC(ucx[0]); + if (cl > cx) + break; + s += nx; + len -= nx; + cl = cx; + UNPARSE(p, endp, ucx[0]); + } + } + break; + } + if (n2 < 0) { + WRITE_UC(); + /* Use a replaced unicode character. */ + UNPARSE(p, endp, uc2); + s += n2*-1; + len -= n2*-1; + ret = -1; + continue; + } else if (n2 == 0) { + WRITE_UC(); + break; + } + } + as->length = p - as->s; + as->s[as->length] = '\0'; + if (ts == 2) + as->s[as->length+1] = '\0'; + return (ret); +} + +#if defined(__APPLE__) + +/* + * Normalize UTF-8 characters to Form D and copy the result. + */ +static int +archive_string_normalize_D(struct archive_string *as, const void *_p, + size_t len, struct archive_string_conv *sc) +{ + const UniChar *inp; + char *outp; + size_t newsize; + ByteCount inCount, outCount; + ByteCount inAvail, outAvail; + OSStatus err; + int ret, saved_flag; + + /* + * Convert the current string to UTF-16LE for normalization. + * The character-set of the current string must be UTF-16BE or + * UTF-8. + */ + archive_string_empty(&(sc->utf16nfc)); + saved_flag = sc->flag;/* save a flag. */ + sc->flag &= ~(SCONV_TO_UTF16BE | SCONV_TO_UTF8); + sc->flag |= SCONV_TO_UTF16LE; + ret = archive_string_append_unicode(&(sc->utf16nfc), _p, len, sc); + sc->flag = saved_flag;/* restore the saved flag */ + if (archive_strlen(&(sc->utf16nfc)) == 0) { + if (archive_string_ensure(as, as->length + 1) == NULL) + return (-1); + return (ret); + } + + /* + * Normalize an NFC string to be an NFD(HFS Plus version). + */ + newsize = sc->utf16nfc.length + 2; + if (archive_string_ensure(&(sc->utf16nfd), newsize) == NULL) + return (-1); + + inp = (UniChar *)sc->utf16nfc.s; + inAvail = archive_strlen(&(sc->utf16nfc)); + sc->utf16nfd.length = 0; + outp = sc->utf16nfd.s; + outAvail = sc->utf16nfd.buffer_length -2; + + do { + /* Reinitialize all state information. */ + if (ResetUnicodeToTextInfo(sc->uniInfo) != noErr) + goto return_no_changed_data; + + inCount = outCount = 0; + err = ConvertFromUnicodeToText(sc->uniInfo, + inAvail, inp, + kUnicodeDefaultDirectionMask, 0, NULL, NULL, NULL, + outAvail, &inCount, &outCount, outp); + + if (err == noErr) { + sc->utf16nfd.length = outCount; + sc->utf16nfd.s[sc->utf16nfd.length] = 0; + sc->utf16nfd.s[sc->utf16nfd.length+1] = 0; + } else if (err == kTECOutputBufferFullStatus) { + newsize = inAvail - inCount; + if (newsize > inAvail) + newsize = inAvail; + newsize += sc->utf16nfd.buffer_length + 2; + if (archive_string_ensure(&(sc->utf16nfd), newsize) + == NULL) + return (-1); + outp = sc->utf16nfd.s; + outAvail = sc->utf16nfd.buffer_length -2; + } else + goto return_no_changed_data; + } while (err == kTECOutputBufferFullStatus); + + /* + * If there is a next-step conversion, we should convert + * a UTF-16LE(NFD) string back to the original Unicode type. + */ + saved_flag = sc->flag;/* save a flag. */ + if (!(sc->flag & + (SCONV_TO_UTF16BE | SCONV_TO_UTF16LE | SCONV_TO_UTF8))) { + /* + * This case is going to be converted to another + * character-set through iconv. + */ + if (sc->flag & SCONV_FROM_UTF16BE) + sc->flag |= SCONV_TO_UTF16BE; + else if (sc->flag & SCONV_FROM_UTF16LE) + sc->flag |= SCONV_TO_UTF16LE; + else + sc->flag |= SCONV_TO_UTF8; + } + sc->flag &= ~(SCONV_FROM_UTF16BE | SCONV_FROM_UTF8); + sc->flag |= SCONV_FROM_UTF16LE; + if (archive_string_append_unicode(as, sc->utf16nfd.s, + sc->utf16nfd.length, sc) != 0) + ret = -1; + sc->flag = saved_flag;/* restore the saved flag */ + return (ret); + +return_no_changed_data: + /* + * Something conversion error happend, so we return a no normalized + * string with an error. + */ + (void)archive_string_append_unicode(as, _p, len, sc); + return (-1); +} + +#endif /* __APPLE__ */ + +/* + * libarchive 2.x made incorrect UTF-8 strings in the wrong assumuption + * that WCS is Unicode. it is true for servel platforms but some are false. + * And then people who did not use UTF-8 locale on the non Unicode WCS + * platform and made a tar file with libarchive(mostly bsdtar) 2.x. Those + * now cannot get right filename from libarchive 3.x and later since we + * fixed the wrong assumption and it is incompatible to older its versions. + * So we provide special option, "compat-2x.x", for resolving it. + * That option enable the string conversion of libarchive 2.x. + * + * Translates the wrong UTF-8 string made by libarchive 2.x into current + * locale character set and appends to the archive_string. + * Note: returns -1 if conversion fails. + */ +static int +strncat_from_utf8_libarchive2(struct archive_string *as, + const void *_p, size_t len, struct archive_string_conv *sc) +{ + const char *s; + int n; + char *p; + char *end; + uint32_t unicode; +#if HAVE_WCRTOMB + mbstate_t shift_state; + + memset(&shift_state, 0, sizeof(shift_state)); +#else + /* Clear the shift state before starting. */ + wctomb(NULL, L'\0'); +#endif + (void)sc; /* UNUSED */ + /* + * Allocate buffer for MBS. + * We need this allocation here since it is possible that + * as->s is still NULL. + */ + if (archive_string_ensure(as, as->length + len + 1) == NULL) + return (-1); + + s = (const char *)_p; + p = as->s + as->length; + end = as->s + as->buffer_length - MB_CUR_MAX -1; + while ((n = _utf8_to_unicode(&unicode, s, len)) != 0) { + wchar_t wc; + + if (p >= end) { + as->length = p - as->s; + /* Re-allocate buffer for MBS. */ + if (archive_string_ensure(as, + as->length + len * 2 + 1) == NULL) + return (-1); + p = as->s + as->length; + end = as->s + as->buffer_length - MB_CUR_MAX -1; + } + + /* + * As libarchie 2.x, translates the UTF-8 characters into + * wide-characters in the assumption that WCS is Unicode. + */ + if (n < 0) { + n *= -1; + wc = L'?'; + } else + wc = (wchar_t)unicode; + + s += n; + len -= n; + /* + * Translates the wide-character into the current locale MBS. + */ +#if HAVE_WCRTOMB + n = wcrtomb(p, wc, &shift_state); +#else + n = wctomb(p, wc); +#endif + if (n == -1) + return (-1); + p += n; + } + as->length = p - as->s; + as->s[as->length] = '\0'; + return (0); +} + + +/* + * Conversion functions between current locale dependent MBS and UTF-16BE. + * strncat_from_utf16be() : UTF-16BE --> MBS + * strncat_to_utf16be() : MBS --> UTF16BE + */ + +#if defined(_WIN32) && !defined(__CYGWIN__) + +/* + * Convert a UTF-16BE/LE string to current locale and copy the result. + * Return -1 if conversion failes. + */ +static int +win_strncat_from_utf16(struct archive_string *as, const void *_p, size_t bytes, + struct archive_string_conv *sc, int be) +{ + struct archive_string tmp; + const char *u16; + int ll; + BOOL defchar; + char *mbs; + size_t mbs_size, b; + int ret = 0; + + bytes &= ~1; + if (archive_string_ensure(as, as->length + bytes +1) == NULL) + return (-1); + + mbs = as->s + as->length; + mbs_size = as->buffer_length - as->length -1; + + if (sc->to_cp == CP_C_LOCALE) { + /* + * "C" locale special process. + */ + u16 = _p; + ll = 0; + for (b = 0; b < bytes; b += 2) { + uint16_t val; + if (be) + val = archive_be16dec(u16+b); + else + val = archive_le16dec(u16+b); + if (val > 255) { + *mbs++ = '?'; + ret = -1; + } else + *mbs++ = (char)(val&0xff); + ll++; + } + as->length += ll; + as->s[as->length] = '\0'; + return (ret); + } + + archive_string_init(&tmp); + if (be) { + if (is_big_endian()) { + u16 = _p; + } else { + if (archive_string_ensure(&tmp, bytes+2) == NULL) + return (-1); + memcpy(tmp.s, _p, bytes); + for (b = 0; b < bytes; b += 2) { + uint16_t val = archive_be16dec(tmp.s+b); + archive_le16enc(tmp.s+b, val); + } + u16 = tmp.s; + } + } else { + if (!is_big_endian()) { + u16 = _p; + } else { + if (archive_string_ensure(&tmp, bytes+2) == NULL) + return (-1); + memcpy(tmp.s, _p, bytes); + for (b = 0; b < bytes; b += 2) { + uint16_t val = archive_le16dec(tmp.s+b); + archive_be16enc(tmp.s+b, val); + } + u16 = tmp.s; + } + } + + do { + defchar = 0; + ll = WideCharToMultiByte(sc->to_cp, 0, + (LPCWSTR)u16, bytes>>1, mbs, mbs_size, + NULL, &defchar); + if (ll == 0 && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + /* Need more buffer for MBS. */ + ll = WideCharToMultiByte(sc->to_cp, 0, + (LPCWSTR)u16, bytes, NULL, 0, NULL, NULL); + if (archive_string_ensure(as, ll +1) == NULL) + return (-1); + mbs = as->s + as->length; + mbs_size = as->buffer_length - as->length -1; + continue; + } + } while (0); + archive_string_free(&tmp); + as->length += ll; + as->s[as->length] = '\0'; + if (ll == 0 || defchar) + ret = -1; + return (ret); +} + +static int +win_strncat_from_utf16be(struct archive_string *as, const void *_p, size_t bytes, + struct archive_string_conv *sc) +{ + return (win_strncat_from_utf16(as, _p, bytes, sc, 1)); +} + +static int +win_strncat_from_utf16le(struct archive_string *as, const void *_p, size_t bytes, + struct archive_string_conv *sc) +{ + return (win_strncat_from_utf16(as, _p, bytes, sc, 0)); +} + +static int +is_big_endian(void) +{ + uint16_t d = 1; + + return (archive_be16dec(&d) == 1); +} + +/* + * Convert a current locale string to UTF-16BE/LE and copy the result. + * Return -1 if conversion failes. + */ +static int +win_strncat_to_utf16(struct archive_string *as16, const void *_p, size_t length, + struct archive_string_conv *sc, int bigendian) +{ + const char *s = (const char *)_p; + char *u16; + size_t count, avail; + + if (archive_string_ensure(as16, + as16->length + (length + 1) * 2) == NULL) + return (-1); + + u16 = as16->s + as16->length; + avail = as16->buffer_length - 2; + if (sc->from_cp == CP_C_LOCALE) { + /* + * "C" locale special process. + */ + count = 0; + while (count < length && *s) { + if (bigendian) + archive_be16enc(u16, *s); + else + archive_le16enc(u16, *s); + u16 += 2; + s++; + count++; + } + as16->length += count << 1; + as16->s[as16->length] = 0; + as16->s[as16->length+1] = 0; + return (0); + } + do { + count = MultiByteToWideChar(sc->from_cp, + MB_PRECOMPOSED, s, length, (LPWSTR)u16, (int)avail>>1); + if (count == 0 && + GetLastError() == ERROR_INSUFFICIENT_BUFFER) { + /* Need more buffer for UTF-16 string */ + count = MultiByteToWideChar(sc->from_cp, + MB_PRECOMPOSED, s, length, NULL, 0); + if (archive_string_ensure(as16, (count +1) * 2) + == NULL) + return (-1); + u16 = as16->s + as16->length; + avail = as16->buffer_length - 2; + continue; + } + } while (0); + as16->length += count * 2; + as16->s[as16->length] = 0; + as16->s[as16->length+1] = 0; + if (count == 0) + return (-1); + + if (is_big_endian()) { + if (!bigendian) { + while (count > 0) { + uint16_t v = archive_be16dec(u16); + archive_le16enc(u16, v); + u16 += 2; + count--; + } + } + } else { + if (bigendian) { + while (count > 0) { + uint16_t v = archive_le16dec(u16); + archive_be16enc(u16, v); + u16 += 2; + count--; + } + } + } + return (0); +} + +static int +win_strncat_to_utf16be(struct archive_string *as16, const void *_p, size_t length, + struct archive_string_conv *sc) +{ + return (win_strncat_to_utf16(as16, _p, length, sc, 1)); +} + +static int +win_strncat_to_utf16le(struct archive_string *as16, const void *_p, size_t length, + struct archive_string_conv *sc) +{ + return (win_strncat_to_utf16(as16, _p, length, sc, 0)); +} + +#endif /* _WIN32 && !__CYGWIN__ */ + +/* + * Do the best effort for conversions. + * We cannot handle UTF-16BE character-set without such iconv, + * but there is a chance if a string consists just ASCII code or + * a current locale is UTF-8. + */ + +/* + * Convert a UTF-16BE string to current locale and copy the result. + * Return -1 if conversion failes. + */ +static int +best_effort_strncat_from_utf16(struct archive_string *as, const void *_p, + size_t bytes, struct archive_string_conv *sc, int be) +{ + const char *utf16 = (const char *)_p; + char *mbs; + uint32_t uc; + int n, ret; + + (void)sc; /* UNUSED */ + /* + * Other case, we should do the best effort. + * If all character are ASCII(<0x7f), we can convert it. + * if not , we set a alternative character and return -1. + */ + ret = 0; + if (archive_string_ensure(as, as->length + bytes +1) == NULL) + return (-1); + mbs = as->s + as->length; + + while ((n = utf16_to_unicode(&uc, utf16, bytes, be)) != 0) { + if (n < 0) { + n *= -1; + ret = -1; + } + bytes -= n; + utf16 += n; + + if (uc > 127) { + /* We cannot handle it. */ + *mbs++ = '?'; + ret = -1; + } else + *mbs++ = (char)uc; + } + as->length = mbs - as->s; + as->s[as->length] = '\0'; + return (ret); +} + +static int +best_effort_strncat_from_utf16be(struct archive_string *as, const void *_p, + size_t bytes, struct archive_string_conv *sc) +{ + return (best_effort_strncat_from_utf16(as, _p, bytes, sc, 1)); +} + +static int +best_effort_strncat_from_utf16le(struct archive_string *as, const void *_p, + size_t bytes, struct archive_string_conv *sc) +{ + return (best_effort_strncat_from_utf16(as, _p, bytes, sc, 0)); +} + +/* + * Convert a current locale string to UTF-16BE/LE and copy the result. + * Return -1 if conversion failes. + */ +static int +best_effort_strncat_to_utf16(struct archive_string *as16, const void *_p, + size_t length, struct archive_string_conv *sc, int bigendian) +{ + const char *s = (const char *)_p; + char *utf16; + size_t remaining; + int ret; + + (void)sc; /* UNUSED */ + /* + * Other case, we should do the best effort. + * If all character are ASCII(<0x7f), we can convert it. + * if not , we set a alternative character and return -1. + */ + ret = 0; + remaining = length; + + if (archive_string_ensure(as16, + as16->length + (length + 1) * 2) == NULL) + return (-1); + + utf16 = as16->s + as16->length; + while (remaining--) { + unsigned c = *s++; + if (c > 127) { + /* We cannot handle it. */ + c = UNICODE_R_CHAR; + ret = -1; + } + if (bigendian) + archive_be16enc(utf16, c); + else + archive_le16enc(utf16, c); + utf16 += 2; + } + as16->length = utf16 - as16->s; + as16->s[as16->length] = 0; + as16->s[as16->length+1] = 0; + return (ret); +} + +static int +best_effort_strncat_to_utf16be(struct archive_string *as16, const void *_p, + size_t length, struct archive_string_conv *sc) +{ + return (best_effort_strncat_to_utf16(as16, _p, length, sc, 1)); +} + +static int +best_effort_strncat_to_utf16le(struct archive_string *as16, const void *_p, + size_t length, struct archive_string_conv *sc) +{ + return (best_effort_strncat_to_utf16(as16, _p, length, sc, 0)); +} + + +/* + * Multistring operations. + */ + +void +archive_mstring_clean(struct archive_mstring *aes) +{ + archive_wstring_free(&(aes->aes_wcs)); + archive_string_free(&(aes->aes_mbs)); + archive_string_free(&(aes->aes_utf8)); + archive_string_free(&(aes->aes_mbs_in_locale)); + aes->aes_set = 0; +} + +void +archive_mstring_copy(struct archive_mstring *dest, struct archive_mstring *src) +{ + dest->aes_set = src->aes_set; + archive_string_copy(&(dest->aes_mbs), &(src->aes_mbs)); + archive_string_copy(&(dest->aes_utf8), &(src->aes_utf8)); + archive_wstring_copy(&(dest->aes_wcs), &(src->aes_wcs)); +} + +int +archive_mstring_get_utf8(struct archive *a, struct archive_mstring *aes, + const char **p) +{ + struct archive_string_conv *sc; + int r; + + /* If we already have a UTF8 form, return that immediately. */ + if (aes->aes_set & AES_SET_UTF8) { + *p = aes->aes_utf8.s; + return (0); + } + + *p = NULL; + if (aes->aes_set & AES_SET_MBS) { + sc = archive_string_conversion_to_charset(a, "UTF-8", 1); + if (sc == NULL) + return (-1);/* Couldn't allocate memory for sc. */ + r = archive_strncpy_in_locale(&(aes->aes_mbs), aes->aes_mbs.s, + aes->aes_mbs.length, sc); + if (a == NULL) + free_sconv_object(sc); + if (r == 0) { + aes->aes_set |= AES_SET_UTF8; + *p = aes->aes_utf8.s; + return (0);/* success. */ + } else + return (-1);/* failure. */ + } + return (0);/* success. */ +} + +int +archive_mstring_get_mbs(struct archive *a, struct archive_mstring *aes, + const char **p) +{ + 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; + return (ret); + } + + *p = NULL; + /* If there's a WCS form, try converting with the native locale. */ + if (aes->aes_set & AES_SET_WCS) { + archive_string_empty(&(aes->aes_mbs)); + r = archive_string_append_from_wcs(&(aes->aes_mbs), + aes->aes_wcs.s, aes->aes_wcs.length); + *p = aes->aes_mbs.s; + if (r == 0) { + aes->aes_set |= AES_SET_MBS; + return (ret); + } else + ret = -1; + } + + /* + * Only a UTF-8 form cannot avail because its conversion already + * failed at archive_mstring_update_utf8(). + */ + return (ret); +} + +int +archive_mstring_get_wcs(struct archive *a, struct archive_mstring *aes, + const wchar_t **wp) +{ + int r, ret = 0; + + (void)a;/* UNUSED */ + /* Return WCS form if we already have it. */ + if (aes->aes_set & AES_SET_WCS) { + *wp = aes->aes_wcs.s; + return (ret); + } + + *wp = NULL; + /* Try converting MBS to WCS using native locale. */ + if (aes->aes_set & AES_SET_MBS) { + archive_wstring_empty(&(aes->aes_wcs)); + r = archive_wstring_append_from_mbs(&(aes->aes_wcs), + aes->aes_mbs.s, aes->aes_mbs.length); + if (r == 0) { + aes->aes_set |= AES_SET_WCS; + *wp = aes->aes_wcs.s; + } else + ret = -1;/* failure. */ + } + return (ret); +} + +int +archive_mstring_get_mbs_l(struct archive_mstring *aes, + const char **p, size_t *length, struct archive_string_conv *sc) +{ + int r, ret = 0; + +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * Internationalization programing on Windows must use Wide + * characters because Windows platform cannot make locale UTF-8. + */ + if (sc != NULL && (aes->aes_set & AES_SET_WCS) != 0) { + archive_string_empty(&(aes->aes_mbs_in_locale)); + r = archive_string_append_from_wcs_in_codepage( + &(aes->aes_mbs_in_locale), aes->aes_wcs.s, + aes->aes_wcs.length, sc); + if (r == 0) { + *p = aes->aes_mbs_in_locale.s; + if (length != NULL) + *length = aes->aes_mbs_in_locale.length; + return (0); + } else if (errno == ENOMEM) + return (-1); + else + ret = -1; + } +#endif + + /* If there is not an MBS form but is a WCS 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 we already have an MBS form, use it to be translated to + * specified character-set. */ + if (aes->aes_set & AES_SET_MBS) { + if (sc == NULL) { + /* Conversion is unneeded. */ + *p = aes->aes_mbs.s; + if (length != NULL) + *length = aes->aes_mbs.length; + return (0); + } + ret = archive_strncpy_in_locale(&(aes->aes_mbs_in_locale), + aes->aes_mbs.s, aes->aes_mbs.length, sc); + *p = aes->aes_mbs_in_locale.s; + if (length != NULL) + *length = aes->aes_mbs_in_locale.length; + } else { + *p = NULL; + if (length != NULL) + *length = 0; + } + return (ret); +} + +int +archive_mstring_copy_mbs(struct archive_mstring *aes, const char *mbs) +{ + if (mbs == NULL) { + aes->aes_set = 0; + return (0); + } + return (archive_mstring_copy_mbs_len(aes, mbs, strlen(mbs))); +} + +int +archive_mstring_copy_mbs_len(struct archive_mstring *aes, const char *mbs, + size_t len) +{ + if (mbs == NULL) { + aes->aes_set = 0; + return (0); + } + aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */ + archive_strncpy(&(aes->aes_mbs), mbs, len); + archive_string_empty(&(aes->aes_utf8)); + archive_wstring_empty(&(aes->aes_wcs)); + return (0); +} + +int +archive_mstring_copy_wcs(struct archive_mstring *aes, const wchar_t *wcs) +{ + return archive_mstring_copy_wcs_len(aes, wcs, wcs == NULL ? 0 : wcslen(wcs)); +} + +int +archive_mstring_copy_wcs_len(struct archive_mstring *aes, const wchar_t *wcs, + size_t len) +{ + if (wcs == NULL) { + aes->aes_set = 0; + } + aes->aes_set = AES_SET_WCS; /* Only WCS form set. */ + archive_string_empty(&(aes->aes_mbs)); + archive_string_empty(&(aes->aes_utf8)); + archive_wstrncpy(&(aes->aes_wcs), wcs, len); + return (0); +} + +int +archive_mstring_copy_mbs_len_l(struct archive_mstring *aes, + const char *mbs, size_t len, struct archive_string_conv *sc) +{ + int r; + + if (mbs == NULL) { + aes->aes_set = 0; + return (0); + } + archive_string_empty(&(aes->aes_mbs)); + archive_wstring_empty(&(aes->aes_wcs)); + archive_string_empty(&(aes->aes_utf8)); +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * Internationalization programing on Windows must use Wide + * characters because Windows platform cannot make locale UTF-8. + */ + if (sc == NULL) { + if (archive_string_append(&(aes->aes_mbs), + mbs, mbsnbytes(mbs, len)) == NULL) { + aes->aes_set = 0; + r = -1; + } else { + aes->aes_set = AES_SET_MBS; + r = 0; + } +#if defined(HAVE_ICONV) + } else if (sc != NULL && sc->cd_w != (iconv_t)-1) { + /* + * This case happens only when MultiByteToWideChar() cannot + * handle sc->from_cp, and we have to iconv in order to + * translate character-set to wchar_t,UTF-16. + */ + iconv_t cd = sc->cd; + unsigned from_cp; + int flag; + + /* + * Translate multi-bytes from some character-set to UTF-8. + */ + sc->cd = sc->cd_w; + r = archive_strncpy_in_locale(&(aes->aes_utf8), mbs, len, sc); + sc->cd = cd; + if (r != 0) { + aes->aes_set = 0; + return (r); + } + aes->aes_set = AES_SET_UTF8; + + /* + * Append the UTF-8 string into wstring. + */ + flag = sc->flag; + sc->flag &= ~(SCONV_NORMALIZATION_C + | SCONV_TO_UTF16| SCONV_FROM_UTF16); + from_cp = sc->from_cp; + sc->from_cp = CP_UTF8; + r = archive_wstring_append_from_mbs_in_codepage(&(aes->aes_wcs), + aes->aes_utf8.s, aes->aes_utf8.length, sc); + sc->flag = flag; + sc->from_cp = from_cp; + if (r == 0) + aes->aes_set |= AES_SET_WCS; +#endif + } else { + r = archive_wstring_append_from_mbs_in_codepage( + &(aes->aes_wcs), mbs, len, sc); + if (r == 0) + aes->aes_set = AES_SET_WCS; + else + aes->aes_set = 0; + } +#else + r = archive_strncpy_in_locale(&(aes->aes_mbs), mbs, len, sc); + if (r == 0) + aes->aes_set = AES_SET_MBS; /* Only MBS form is set now. */ + else + aes->aes_set = 0; +#endif + return (r); +} + +/* + * The 'update' form tries to proactively update all forms of + * this string (WCS and MBS) and returns an error if any of + * them fail. This is used by the 'pax' handler, for instance, + * to detect and report character-conversion failures early while + * still allowing clients to get potentially useful values from + * the more tolerant lazy conversions. (get_mbs and get_wcs will + * strive to give the user something useful, so you can get hopefully + * usable values even if some of the character conversions are failing.) + */ +int +archive_mstring_update_utf8(struct archive *a, struct archive_mstring *aes, + const char *utf8) +{ + struct archive_string_conv *sc; + int r; + + if (utf8 == NULL) { + aes->aes_set = 0; + return (0); /* Succeeded in clearing everything. */ + } + + /* Save the UTF8 string. */ + archive_strcpy(&(aes->aes_utf8), utf8); + + /* Empty the mbs and wcs strings. */ + archive_string_empty(&(aes->aes_mbs)); + archive_wstring_empty(&(aes->aes_wcs)); + + aes->aes_set = AES_SET_UTF8; /* Only UTF8 is set now. */ + + /* Try converting UTF-8 to MBS, return false on failure. */ + sc = archive_string_conversion_from_charset(a, "UTF-8", 1); + if (sc == NULL) + return (-1);/* Couldn't allocate memory for sc. */ + r = archive_strcpy_in_locale(&(aes->aes_mbs), utf8, sc); + if (a == NULL) + free_sconv_object(sc); + if (r != 0) + return (-1); + aes->aes_set = AES_SET_UTF8 | AES_SET_MBS; /* Both UTF8 and MBS set. */ + + /* Try converting MBS to WCS, return false on failure. */ + if (archive_wstring_append_from_mbs(&(aes->aes_wcs), aes->aes_mbs.s, + aes->aes_mbs.length)) + return (-1); + aes->aes_set = AES_SET_UTF8 | AES_SET_WCS | AES_SET_MBS; + + /* All conversions succeeded. */ + return (0); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_string.h b/Utilities/cmlibarchive/libarchive/archive_string.h index debfa5ef3..0e4c9b904 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string.h +++ b/Utilities/cmlibarchive/libarchive/archive_string.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,16 +22,18 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_string.h,v 1.13 2008/12/06 05:56:43 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_string.h 201092 2009-12-28 02:26:06Z kientzle $ * */ #ifndef __LIBARCHIVE_BUILD +#ifndef __LIBARCHIVE_TEST #error This header is only to be used internally to libarchive. #endif +#endif #ifndef ARCHIVE_STRING_H_INCLUDED -#define ARCHIVE_STRING_H_INCLUDED +#define ARCHIVE_STRING_H_INCLUDED #include #ifdef HAVE_STDLIB_H @@ -44,63 +46,100 @@ #include #endif +#include "archive.h" + /* - * Basic resizable/reusable string support a la Java's "StringBuffer." + * Basic resizable/reusable string support similar to Java's "StringBuffer." * * Unlike sbuf(9), the buffers here are fully reusable and track the * length throughout. - * - * Note that all visible symbols here begin with "__archive" as they - * are internal symbols not intended for anyone outside of this library - * to see or use. */ struct archive_string { - char *s; /* Pointer to the storage */ - size_t length; /* Length of 's' */ - size_t buffer_length; /* Length of malloc-ed storage */ + char *s; /* Pointer to the storage */ + size_t length; /* Length of 's' in characters */ + size_t buffer_length; /* Length of malloc-ed storage in bytes. */ +}; + +struct archive_wstring { + wchar_t *s; /* Pointer to the storage */ + size_t length; /* Length of 's' in characters */ + size_t buffer_length; /* Length of malloc-ed storage in bytes. */ }; +struct archive_string_conv; + /* Initialize an archive_string object on the stack or elsewhere. */ -#define archive_string_init(a) \ - do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0) +#define archive_string_init(a) \ + do { (a)->s = NULL; (a)->length = 0; (a)->buffer_length = 0; } while(0) /* Append a C char to an archive_string, resizing as necessary. */ struct archive_string * -__archive_strappend_char(struct archive_string *, char); -#define archive_strappend_char __archive_strappend_char +archive_strappend_char(struct archive_string *, char); + +/* Ditto for a wchar_t and an archive_wstring. */ +struct archive_wstring * +archive_wstrappend_wchar(struct archive_wstring *, wchar_t); + +/* Convert a Unicode string to current locale and append the result. */ +/* Returns -1 if conversion fails. */ +int +archive_string_append_from_wcs(struct archive_string *, const wchar_t *, size_t); + + +/* Create a string conversion object. + * Return NULL and set a error message if the conversion is not supported + * on the platform. */ +struct archive_string_conv * +archive_string_conversion_to_charset(struct archive *, const char *, int); +struct archive_string_conv * +archive_string_conversion_from_charset(struct archive *, const char *, int); +/* Create the default string conversion object for reading/writing an archive. + * Return NULL if the conversion is unneeded. + * Note: On non Windows platform this always returns NULL. + */ +struct archive_string_conv * +archive_string_default_conversion_for_read(struct archive *); +struct archive_string_conv * +archive_string_default_conversion_for_write(struct archive *); +/* Dispose of a string conversion object. */ +void +archive_string_conversion_free(struct archive *); +const char * +archive_string_conversion_charset_name(struct archive_string_conv *); +void +archive_string_conversion_set_opt(struct archive_string_conv *, int); +#define SCONV_SET_OPT_UTF8_LIBARCHIVE2X 1 -/* Convert a wide-char string to UTF-8 and append the result. */ -struct archive_string * -__archive_strappend_w_utf8(struct archive_string *, const wchar_t *); -#define archive_strappend_w_utf8 __archive_strappend_w_utf8 -/* Convert a wide-char string to current locale and append the result. */ -/* Returns NULL if conversion fails. */ -struct archive_string * -__archive_strappend_w_mbs(struct archive_string *, const wchar_t *); -#define archive_strappend_w_mbs __archive_strappend_w_mbs +/* Copy one archive_string to another in locale conversion. + * Return -1 if conversion failes. */ +int +archive_strncpy_in_locale(struct archive_string *, const void *, size_t, + struct archive_string_conv *); + +/* Copy one archive_string to another in locale conversion. + * Return -1 if conversion failes. */ +int +archive_strncat_in_locale(struct archive_string *, const void *, size_t, + struct archive_string_conv *); -/* Basic append operation. */ -struct archive_string * -__archive_string_append(struct archive_string *as, const char *p, size_t s); /* Copy one archive_string to another */ -void -__archive_string_copy(struct archive_string *dest, struct archive_string *src); -#define archive_string_copy(dest, src) \ - __archive_string_copy(dest, src) +#define archive_string_copy(dest, src) \ + ((dest)->length = 0, archive_string_concat((dest), (src))) +#define archive_wstring_copy(dest, src) \ + ((dest)->length = 0, archive_wstring_concat((dest), (src))) /* Concatenate one archive_string to another */ -void -__archive_string_concat(struct archive_string *dest, struct archive_string *src); -#define archive_string_concat(dest, src) \ - __archive_string_concat(dest, src) +void archive_string_concat(struct archive_string *dest, struct archive_string *src); +void archive_wstring_concat(struct archive_wstring *dest, struct archive_wstring *src); /* Ensure that the underlying buffer is at least as large as the request. */ struct archive_string * -__archive_string_ensure(struct archive_string *, size_t); -#define archive_string_ensure __archive_string_ensure +archive_string_ensure(struct archive_string *, size_t); +struct archive_wstring * +archive_wstring_ensure(struct archive_wstring *, size_t); /* Append C string, which may lack trailing \0. */ /* The source is declared void * here because this gets used with @@ -108,41 +147,91 @@ __archive_string_ensure(struct archive_string *, size_t); * Declaring it "char *" as with some of the other functions just * leads to a lot of extra casts. */ struct archive_string * -__archive_strncat(struct archive_string *, const void *, size_t); -#define archive_strncat __archive_strncat +archive_strncat(struct archive_string *, const void *, size_t); +struct archive_wstring * +archive_wstrncat(struct archive_wstring *, const wchar_t *, size_t); /* Append a C string to an archive_string, resizing as necessary. */ -#define archive_strcat(as,p) __archive_string_append((as),(p),strlen(p)) +struct archive_string * +archive_strcat(struct archive_string *, const void *); +struct archive_wstring * +archive_wstrcat(struct archive_wstring *, const wchar_t *); /* Copy a C string to an archive_string, resizing as necessary. */ -#define archive_strcpy(as,p) \ - ((as)->length = 0, __archive_string_append((as), (p), p == NULL ? 0 : strlen(p))) +#define archive_strcpy(as,p) \ + archive_strncpy((as), (p), ((p) == NULL ? 0 : strlen(p))) +#define archive_wstrcpy(as,p) \ + archive_wstrncpy((as), (p), ((p) == NULL ? 0 : wcslen(p))) +#define archive_strcpy_in_locale(as,p,lo) \ + archive_strncpy_in_locale((as), (p), ((p) == NULL ? 0 : strlen(p)), (lo)) /* Copy a C string to an archive_string with limit, resizing as necessary. */ -#define archive_strncpy(as,p,l) \ - ((as)->length=0, archive_strncat((as), (p), (l))) +#define archive_strncpy(as,p,l) \ + ((as)->length=0, archive_strncat((as), (p), (l))) +#define archive_wstrncpy(as,p,l) \ + ((as)->length = 0, archive_wstrncat((as), (p), (l))) /* Return length of string. */ -#define archive_strlen(a) ((a)->length) +#define archive_strlen(a) ((a)->length) /* Set string length to zero. */ -#define archive_string_empty(a) ((a)->length = 0) +#define archive_string_empty(a) ((a)->length = 0) +#define archive_wstring_empty(a) ((a)->length = 0) /* Release any allocated storage resources. */ -void __archive_string_free(struct archive_string *); -#define archive_string_free __archive_string_free +void archive_string_free(struct archive_string *); +void archive_wstring_free(struct archive_wstring *); /* Like 'vsprintf', but resizes the underlying string as necessary. */ -void __archive_string_vsprintf(struct archive_string *, const char *, - va_list); -#define archive_string_vsprintf __archive_string_vsprintf - -void __archive_string_sprintf(struct archive_string *, const char *, ...); -#define archive_string_sprintf __archive_string_sprintf +/* Note: This only implements a small subset of standard printf functionality. */ +void archive_string_vsprintf(struct archive_string *, const char *, + va_list) __LA_PRINTF(2, 0); +void archive_string_sprintf(struct archive_string *, const char *, ...) + __LA_PRINTF(2, 3); + +/* Translates from MBS to Unicode. */ +/* Returns non-zero if conversion failed in any way. */ +int archive_wstring_append_from_mbs(struct archive_wstring *dest, + const char *, size_t); + + +/* A "multistring" can hold Unicode, UTF8, or MBS versions of + * the string. If you set and read the same version, no translation + * is done. If you set and read different versions, the library + * will attempt to transparently convert. + */ +struct archive_mstring { + struct archive_string aes_mbs; + struct archive_string aes_utf8; + struct archive_wstring aes_wcs; + struct archive_string aes_mbs_in_locale; + /* Bitmap of which of the above are valid. Because we're lazy + * about malloc-ing and reusing the underlying storage, we + * can't rely on NULL pointers to indicate whether a string + * has been set. */ + int aes_set; +#define AES_SET_MBS 1 +#define AES_SET_UTF8 2 +#define AES_SET_WCS 4 +}; -/* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. - * Returns NULL if conversion failed in any way. */ -wchar_t *__archive_string_utf8_w(struct archive_string *as); +void archive_mstring_clean(struct archive_mstring *); +void archive_mstring_copy(struct archive_mstring *dest, struct archive_mstring *src); +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 **, + 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, + size_t); +int archive_mstring_copy_utf8(struct archive_mstring *, const char *utf8); +int archive_mstring_copy_wcs(struct archive_mstring *, const wchar_t *wcs); +int archive_mstring_copy_wcs_len(struct archive_mstring *, + const wchar_t *wcs, size_t); +int archive_mstring_copy_mbs_len_l(struct archive_mstring *, + const char *mbs, size_t, struct archive_string_conv *); +int archive_mstring_update_utf8(struct archive *, struct archive_mstring *aes, const char *utf8); #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_string_composition.h b/Utilities/cmlibarchive/libarchive/archive_string_composition.h new file mode 100644 index 000000000..cc4bf46c0 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_string_composition.h @@ -0,0 +1,1351 @@ +/*- + * Copyright (c) 2011 libarchive Project + * 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. + * + * $FreeBSD$ + * + */ + +/* + * ATTENTION! + * This file is generated by build/utils/gen_archive_string_composition_h.sh + * from http://unicode.org/Public/UNIDATA/UnicodeData.txt + * + * See also http://unicode.org/report/tr15/ + */ + +#ifndef __LIBARCHIVE_BUILD +#error This header is only to be used internally to libarchive. +#endif + +#ifndef ARCHIVE_STRING_COMPOSITION_H_INCLUDED +#define ARCHIVE_STRING_COMPOSITION_H_INCLUDED + +struct unicode_composition_table { + uint32_t cp1; + uint32_t cp2; + uint32_t nfc; +}; + +static const struct unicode_composition_table u_composition_table[] = { + { 0x0003C , 0x00338 , 0x0226E }, + { 0x0003D , 0x00338 , 0x02260 }, + { 0x0003E , 0x00338 , 0x0226F }, + { 0x00041 , 0x00300 , 0x000C0 }, + { 0x00041 , 0x00301 , 0x000C1 }, + { 0x00041 , 0x00302 , 0x000C2 }, + { 0x00041 , 0x00303 , 0x000C3 }, + { 0x00041 , 0x00304 , 0x00100 }, + { 0x00041 , 0x00306 , 0x00102 }, + { 0x00041 , 0x00307 , 0x00226 }, + { 0x00041 , 0x00308 , 0x000C4 }, + { 0x00041 , 0x00309 , 0x01EA2 }, + { 0x00041 , 0x0030A , 0x000C5 }, + { 0x00041 , 0x0030C , 0x001CD }, + { 0x00041 , 0x0030F , 0x00200 }, + { 0x00041 , 0x00311 , 0x00202 }, + { 0x00041 , 0x00323 , 0x01EA0 }, + { 0x00041 , 0x00325 , 0x01E00 }, + { 0x00041 , 0x00328 , 0x00104 }, + { 0x00042 , 0x00307 , 0x01E02 }, + { 0x00042 , 0x00323 , 0x01E04 }, + { 0x00042 , 0x00331 , 0x01E06 }, + { 0x00043 , 0x00301 , 0x00106 }, + { 0x00043 , 0x00302 , 0x00108 }, + { 0x00043 , 0x00307 , 0x0010A }, + { 0x00043 , 0x0030C , 0x0010C }, + { 0x00043 , 0x00327 , 0x000C7 }, + { 0x00044 , 0x00307 , 0x01E0A }, + { 0x00044 , 0x0030C , 0x0010E }, + { 0x00044 , 0x00323 , 0x01E0C }, + { 0x00044 , 0x00327 , 0x01E10 }, + { 0x00044 , 0x0032D , 0x01E12 }, + { 0x00044 , 0x00331 , 0x01E0E }, + { 0x00045 , 0x00300 , 0x000C8 }, + { 0x00045 , 0x00301 , 0x000C9 }, + { 0x00045 , 0x00302 , 0x000CA }, + { 0x00045 , 0x00303 , 0x01EBC }, + { 0x00045 , 0x00304 , 0x00112 }, + { 0x00045 , 0x00306 , 0x00114 }, + { 0x00045 , 0x00307 , 0x00116 }, + { 0x00045 , 0x00308 , 0x000CB }, + { 0x00045 , 0x00309 , 0x01EBA }, + { 0x00045 , 0x0030C , 0x0011A }, + { 0x00045 , 0x0030F , 0x00204 }, + { 0x00045 , 0x00311 , 0x00206 }, + { 0x00045 , 0x00323 , 0x01EB8 }, + { 0x00045 , 0x00327 , 0x00228 }, + { 0x00045 , 0x00328 , 0x00118 }, + { 0x00045 , 0x0032D , 0x01E18 }, + { 0x00045 , 0x00330 , 0x01E1A }, + { 0x00046 , 0x00307 , 0x01E1E }, + { 0x00047 , 0x00301 , 0x001F4 }, + { 0x00047 , 0x00302 , 0x0011C }, + { 0x00047 , 0x00304 , 0x01E20 }, + { 0x00047 , 0x00306 , 0x0011E }, + { 0x00047 , 0x00307 , 0x00120 }, + { 0x00047 , 0x0030C , 0x001E6 }, + { 0x00047 , 0x00327 , 0x00122 }, + { 0x00048 , 0x00302 , 0x00124 }, + { 0x00048 , 0x00307 , 0x01E22 }, + { 0x00048 , 0x00308 , 0x01E26 }, + { 0x00048 , 0x0030C , 0x0021E }, + { 0x00048 , 0x00323 , 0x01E24 }, + { 0x00048 , 0x00327 , 0x01E28 }, + { 0x00048 , 0x0032E , 0x01E2A }, + { 0x00049 , 0x00300 , 0x000CC }, + { 0x00049 , 0x00301 , 0x000CD }, + { 0x00049 , 0x00302 , 0x000CE }, + { 0x00049 , 0x00303 , 0x00128 }, + { 0x00049 , 0x00304 , 0x0012A }, + { 0x00049 , 0x00306 , 0x0012C }, + { 0x00049 , 0x00307 , 0x00130 }, + { 0x00049 , 0x00308 , 0x000CF }, + { 0x00049 , 0x00309 , 0x01EC8 }, + { 0x00049 , 0x0030C , 0x001CF }, + { 0x00049 , 0x0030F , 0x00208 }, + { 0x00049 , 0x00311 , 0x0020A }, + { 0x00049 , 0x00323 , 0x01ECA }, + { 0x00049 , 0x00328 , 0x0012E }, + { 0x00049 , 0x00330 , 0x01E2C }, + { 0x0004A , 0x00302 , 0x00134 }, + { 0x0004B , 0x00301 , 0x01E30 }, + { 0x0004B , 0x0030C , 0x001E8 }, + { 0x0004B , 0x00323 , 0x01E32 }, + { 0x0004B , 0x00327 , 0x00136 }, + { 0x0004B , 0x00331 , 0x01E34 }, + { 0x0004C , 0x00301 , 0x00139 }, + { 0x0004C , 0x0030C , 0x0013D }, + { 0x0004C , 0x00323 , 0x01E36 }, + { 0x0004C , 0x00327 , 0x0013B }, + { 0x0004C , 0x0032D , 0x01E3C }, + { 0x0004C , 0x00331 , 0x01E3A }, + { 0x0004D , 0x00301 , 0x01E3E }, + { 0x0004D , 0x00307 , 0x01E40 }, + { 0x0004D , 0x00323 , 0x01E42 }, + { 0x0004E , 0x00300 , 0x001F8 }, + { 0x0004E , 0x00301 , 0x00143 }, + { 0x0004E , 0x00303 , 0x000D1 }, + { 0x0004E , 0x00307 , 0x01E44 }, + { 0x0004E , 0x0030C , 0x00147 }, + { 0x0004E , 0x00323 , 0x01E46 }, + { 0x0004E , 0x00327 , 0x00145 }, + { 0x0004E , 0x0032D , 0x01E4A }, + { 0x0004E , 0x00331 , 0x01E48 }, + { 0x0004F , 0x00300 , 0x000D2 }, + { 0x0004F , 0x00301 , 0x000D3 }, + { 0x0004F , 0x00302 , 0x000D4 }, + { 0x0004F , 0x00303 , 0x000D5 }, + { 0x0004F , 0x00304 , 0x0014C }, + { 0x0004F , 0x00306 , 0x0014E }, + { 0x0004F , 0x00307 , 0x0022E }, + { 0x0004F , 0x00308 , 0x000D6 }, + { 0x0004F , 0x00309 , 0x01ECE }, + { 0x0004F , 0x0030B , 0x00150 }, + { 0x0004F , 0x0030C , 0x001D1 }, + { 0x0004F , 0x0030F , 0x0020C }, + { 0x0004F , 0x00311 , 0x0020E }, + { 0x0004F , 0x0031B , 0x001A0 }, + { 0x0004F , 0x00323 , 0x01ECC }, + { 0x0004F , 0x00328 , 0x001EA }, + { 0x00050 , 0x00301 , 0x01E54 }, + { 0x00050 , 0x00307 , 0x01E56 }, + { 0x00052 , 0x00301 , 0x00154 }, + { 0x00052 , 0x00307 , 0x01E58 }, + { 0x00052 , 0x0030C , 0x00158 }, + { 0x00052 , 0x0030F , 0x00210 }, + { 0x00052 , 0x00311 , 0x00212 }, + { 0x00052 , 0x00323 , 0x01E5A }, + { 0x00052 , 0x00327 , 0x00156 }, + { 0x00052 , 0x00331 , 0x01E5E }, + { 0x00053 , 0x00301 , 0x0015A }, + { 0x00053 , 0x00302 , 0x0015C }, + { 0x00053 , 0x00307 , 0x01E60 }, + { 0x00053 , 0x0030C , 0x00160 }, + { 0x00053 , 0x00323 , 0x01E62 }, + { 0x00053 , 0x00326 , 0x00218 }, + { 0x00053 , 0x00327 , 0x0015E }, + { 0x00054 , 0x00307 , 0x01E6A }, + { 0x00054 , 0x0030C , 0x00164 }, + { 0x00054 , 0x00323 , 0x01E6C }, + { 0x00054 , 0x00326 , 0x0021A }, + { 0x00054 , 0x00327 , 0x00162 }, + { 0x00054 , 0x0032D , 0x01E70 }, + { 0x00054 , 0x00331 , 0x01E6E }, + { 0x00055 , 0x00300 , 0x000D9 }, + { 0x00055 , 0x00301 , 0x000DA }, + { 0x00055 , 0x00302 , 0x000DB }, + { 0x00055 , 0x00303 , 0x00168 }, + { 0x00055 , 0x00304 , 0x0016A }, + { 0x00055 , 0x00306 , 0x0016C }, + { 0x00055 , 0x00308 , 0x000DC }, + { 0x00055 , 0x00309 , 0x01EE6 }, + { 0x00055 , 0x0030A , 0x0016E }, + { 0x00055 , 0x0030B , 0x00170 }, + { 0x00055 , 0x0030C , 0x001D3 }, + { 0x00055 , 0x0030F , 0x00214 }, + { 0x00055 , 0x00311 , 0x00216 }, + { 0x00055 , 0x0031B , 0x001AF }, + { 0x00055 , 0x00323 , 0x01EE4 }, + { 0x00055 , 0x00324 , 0x01E72 }, + { 0x00055 , 0x00328 , 0x00172 }, + { 0x00055 , 0x0032D , 0x01E76 }, + { 0x00055 , 0x00330 , 0x01E74 }, + { 0x00056 , 0x00303 , 0x01E7C }, + { 0x00056 , 0x00323 , 0x01E7E }, + { 0x00057 , 0x00300 , 0x01E80 }, + { 0x00057 , 0x00301 , 0x01E82 }, + { 0x00057 , 0x00302 , 0x00174 }, + { 0x00057 , 0x00307 , 0x01E86 }, + { 0x00057 , 0x00308 , 0x01E84 }, + { 0x00057 , 0x00323 , 0x01E88 }, + { 0x00058 , 0x00307 , 0x01E8A }, + { 0x00058 , 0x00308 , 0x01E8C }, + { 0x00059 , 0x00300 , 0x01EF2 }, + { 0x00059 , 0x00301 , 0x000DD }, + { 0x00059 , 0x00302 , 0x00176 }, + { 0x00059 , 0x00303 , 0x01EF8 }, + { 0x00059 , 0x00304 , 0x00232 }, + { 0x00059 , 0x00307 , 0x01E8E }, + { 0x00059 , 0x00308 , 0x00178 }, + { 0x00059 , 0x00309 , 0x01EF6 }, + { 0x00059 , 0x00323 , 0x01EF4 }, + { 0x0005A , 0x00301 , 0x00179 }, + { 0x0005A , 0x00302 , 0x01E90 }, + { 0x0005A , 0x00307 , 0x0017B }, + { 0x0005A , 0x0030C , 0x0017D }, + { 0x0005A , 0x00323 , 0x01E92 }, + { 0x0005A , 0x00331 , 0x01E94 }, + { 0x00061 , 0x00300 , 0x000E0 }, + { 0x00061 , 0x00301 , 0x000E1 }, + { 0x00061 , 0x00302 , 0x000E2 }, + { 0x00061 , 0x00303 , 0x000E3 }, + { 0x00061 , 0x00304 , 0x00101 }, + { 0x00061 , 0x00306 , 0x00103 }, + { 0x00061 , 0x00307 , 0x00227 }, + { 0x00061 , 0x00308 , 0x000E4 }, + { 0x00061 , 0x00309 , 0x01EA3 }, + { 0x00061 , 0x0030A , 0x000E5 }, + { 0x00061 , 0x0030C , 0x001CE }, + { 0x00061 , 0x0030F , 0x00201 }, + { 0x00061 , 0x00311 , 0x00203 }, + { 0x00061 , 0x00323 , 0x01EA1 }, + { 0x00061 , 0x00325 , 0x01E01 }, + { 0x00061 , 0x00328 , 0x00105 }, + { 0x00062 , 0x00307 , 0x01E03 }, + { 0x00062 , 0x00323 , 0x01E05 }, + { 0x00062 , 0x00331 , 0x01E07 }, + { 0x00063 , 0x00301 , 0x00107 }, + { 0x00063 , 0x00302 , 0x00109 }, + { 0x00063 , 0x00307 , 0x0010B }, + { 0x00063 , 0x0030C , 0x0010D }, + { 0x00063 , 0x00327 , 0x000E7 }, + { 0x00064 , 0x00307 , 0x01E0B }, + { 0x00064 , 0x0030C , 0x0010F }, + { 0x00064 , 0x00323 , 0x01E0D }, + { 0x00064 , 0x00327 , 0x01E11 }, + { 0x00064 , 0x0032D , 0x01E13 }, + { 0x00064 , 0x00331 , 0x01E0F }, + { 0x00065 , 0x00300 , 0x000E8 }, + { 0x00065 , 0x00301 , 0x000E9 }, + { 0x00065 , 0x00302 , 0x000EA }, + { 0x00065 , 0x00303 , 0x01EBD }, + { 0x00065 , 0x00304 , 0x00113 }, + { 0x00065 , 0x00306 , 0x00115 }, + { 0x00065 , 0x00307 , 0x00117 }, + { 0x00065 , 0x00308 , 0x000EB }, + { 0x00065 , 0x00309 , 0x01EBB }, + { 0x00065 , 0x0030C , 0x0011B }, + { 0x00065 , 0x0030F , 0x00205 }, + { 0x00065 , 0x00311 , 0x00207 }, + { 0x00065 , 0x00323 , 0x01EB9 }, + { 0x00065 , 0x00327 , 0x00229 }, + { 0x00065 , 0x00328 , 0x00119 }, + { 0x00065 , 0x0032D , 0x01E19 }, + { 0x00065 , 0x00330 , 0x01E1B }, + { 0x00066 , 0x00307 , 0x01E1F }, + { 0x00067 , 0x00301 , 0x001F5 }, + { 0x00067 , 0x00302 , 0x0011D }, + { 0x00067 , 0x00304 , 0x01E21 }, + { 0x00067 , 0x00306 , 0x0011F }, + { 0x00067 , 0x00307 , 0x00121 }, + { 0x00067 , 0x0030C , 0x001E7 }, + { 0x00067 , 0x00327 , 0x00123 }, + { 0x00068 , 0x00302 , 0x00125 }, + { 0x00068 , 0x00307 , 0x01E23 }, + { 0x00068 , 0x00308 , 0x01E27 }, + { 0x00068 , 0x0030C , 0x0021F }, + { 0x00068 , 0x00323 , 0x01E25 }, + { 0x00068 , 0x00327 , 0x01E29 }, + { 0x00068 , 0x0032E , 0x01E2B }, + { 0x00068 , 0x00331 , 0x01E96 }, + { 0x00069 , 0x00300 , 0x000EC }, + { 0x00069 , 0x00301 , 0x000ED }, + { 0x00069 , 0x00302 , 0x000EE }, + { 0x00069 , 0x00303 , 0x00129 }, + { 0x00069 , 0x00304 , 0x0012B }, + { 0x00069 , 0x00306 , 0x0012D }, + { 0x00069 , 0x00308 , 0x000EF }, + { 0x00069 , 0x00309 , 0x01EC9 }, + { 0x00069 , 0x0030C , 0x001D0 }, + { 0x00069 , 0x0030F , 0x00209 }, + { 0x00069 , 0x00311 , 0x0020B }, + { 0x00069 , 0x00323 , 0x01ECB }, + { 0x00069 , 0x00328 , 0x0012F }, + { 0x00069 , 0x00330 , 0x01E2D }, + { 0x0006A , 0x00302 , 0x00135 }, + { 0x0006A , 0x0030C , 0x001F0 }, + { 0x0006B , 0x00301 , 0x01E31 }, + { 0x0006B , 0x0030C , 0x001E9 }, + { 0x0006B , 0x00323 , 0x01E33 }, + { 0x0006B , 0x00327 , 0x00137 }, + { 0x0006B , 0x00331 , 0x01E35 }, + { 0x0006C , 0x00301 , 0x0013A }, + { 0x0006C , 0x0030C , 0x0013E }, + { 0x0006C , 0x00323 , 0x01E37 }, + { 0x0006C , 0x00327 , 0x0013C }, + { 0x0006C , 0x0032D , 0x01E3D }, + { 0x0006C , 0x00331 , 0x01E3B }, + { 0x0006D , 0x00301 , 0x01E3F }, + { 0x0006D , 0x00307 , 0x01E41 }, + { 0x0006D , 0x00323 , 0x01E43 }, + { 0x0006E , 0x00300 , 0x001F9 }, + { 0x0006E , 0x00301 , 0x00144 }, + { 0x0006E , 0x00303 , 0x000F1 }, + { 0x0006E , 0x00307 , 0x01E45 }, + { 0x0006E , 0x0030C , 0x00148 }, + { 0x0006E , 0x00323 , 0x01E47 }, + { 0x0006E , 0x00327 , 0x00146 }, + { 0x0006E , 0x0032D , 0x01E4B }, + { 0x0006E , 0x00331 , 0x01E49 }, + { 0x0006F , 0x00300 , 0x000F2 }, + { 0x0006F , 0x00301 , 0x000F3 }, + { 0x0006F , 0x00302 , 0x000F4 }, + { 0x0006F , 0x00303 , 0x000F5 }, + { 0x0006F , 0x00304 , 0x0014D }, + { 0x0006F , 0x00306 , 0x0014F }, + { 0x0006F , 0x00307 , 0x0022F }, + { 0x0006F , 0x00308 , 0x000F6 }, + { 0x0006F , 0x00309 , 0x01ECF }, + { 0x0006F , 0x0030B , 0x00151 }, + { 0x0006F , 0x0030C , 0x001D2 }, + { 0x0006F , 0x0030F , 0x0020D }, + { 0x0006F , 0x00311 , 0x0020F }, + { 0x0006F , 0x0031B , 0x001A1 }, + { 0x0006F , 0x00323 , 0x01ECD }, + { 0x0006F , 0x00328 , 0x001EB }, + { 0x00070 , 0x00301 , 0x01E55 }, + { 0x00070 , 0x00307 , 0x01E57 }, + { 0x00072 , 0x00301 , 0x00155 }, + { 0x00072 , 0x00307 , 0x01E59 }, + { 0x00072 , 0x0030C , 0x00159 }, + { 0x00072 , 0x0030F , 0x00211 }, + { 0x00072 , 0x00311 , 0x00213 }, + { 0x00072 , 0x00323 , 0x01E5B }, + { 0x00072 , 0x00327 , 0x00157 }, + { 0x00072 , 0x00331 , 0x01E5F }, + { 0x00073 , 0x00301 , 0x0015B }, + { 0x00073 , 0x00302 , 0x0015D }, + { 0x00073 , 0x00307 , 0x01E61 }, + { 0x00073 , 0x0030C , 0x00161 }, + { 0x00073 , 0x00323 , 0x01E63 }, + { 0x00073 , 0x00326 , 0x00219 }, + { 0x00073 , 0x00327 , 0x0015F }, + { 0x00074 , 0x00307 , 0x01E6B }, + { 0x00074 , 0x00308 , 0x01E97 }, + { 0x00074 , 0x0030C , 0x00165 }, + { 0x00074 , 0x00323 , 0x01E6D }, + { 0x00074 , 0x00326 , 0x0021B }, + { 0x00074 , 0x00327 , 0x00163 }, + { 0x00074 , 0x0032D , 0x01E71 }, + { 0x00074 , 0x00331 , 0x01E6F }, + { 0x00075 , 0x00300 , 0x000F9 }, + { 0x00075 , 0x00301 , 0x000FA }, + { 0x00075 , 0x00302 , 0x000FB }, + { 0x00075 , 0x00303 , 0x00169 }, + { 0x00075 , 0x00304 , 0x0016B }, + { 0x00075 , 0x00306 , 0x0016D }, + { 0x00075 , 0x00308 , 0x000FC }, + { 0x00075 , 0x00309 , 0x01EE7 }, + { 0x00075 , 0x0030A , 0x0016F }, + { 0x00075 , 0x0030B , 0x00171 }, + { 0x00075 , 0x0030C , 0x001D4 }, + { 0x00075 , 0x0030F , 0x00215 }, + { 0x00075 , 0x00311 , 0x00217 }, + { 0x00075 , 0x0031B , 0x001B0 }, + { 0x00075 , 0x00323 , 0x01EE5 }, + { 0x00075 , 0x00324 , 0x01E73 }, + { 0x00075 , 0x00328 , 0x00173 }, + { 0x00075 , 0x0032D , 0x01E77 }, + { 0x00075 , 0x00330 , 0x01E75 }, + { 0x00076 , 0x00303 , 0x01E7D }, + { 0x00076 , 0x00323 , 0x01E7F }, + { 0x00077 , 0x00300 , 0x01E81 }, + { 0x00077 , 0x00301 , 0x01E83 }, + { 0x00077 , 0x00302 , 0x00175 }, + { 0x00077 , 0x00307 , 0x01E87 }, + { 0x00077 , 0x00308 , 0x01E85 }, + { 0x00077 , 0x0030A , 0x01E98 }, + { 0x00077 , 0x00323 , 0x01E89 }, + { 0x00078 , 0x00307 , 0x01E8B }, + { 0x00078 , 0x00308 , 0x01E8D }, + { 0x00079 , 0x00300 , 0x01EF3 }, + { 0x00079 , 0x00301 , 0x000FD }, + { 0x00079 , 0x00302 , 0x00177 }, + { 0x00079 , 0x00303 , 0x01EF9 }, + { 0x00079 , 0x00304 , 0x00233 }, + { 0x00079 , 0x00307 , 0x01E8F }, + { 0x00079 , 0x00308 , 0x000FF }, + { 0x00079 , 0x00309 , 0x01EF7 }, + { 0x00079 , 0x0030A , 0x01E99 }, + { 0x00079 , 0x00323 , 0x01EF5 }, + { 0x0007A , 0x00301 , 0x0017A }, + { 0x0007A , 0x00302 , 0x01E91 }, + { 0x0007A , 0x00307 , 0x0017C }, + { 0x0007A , 0x0030C , 0x0017E }, + { 0x0007A , 0x00323 , 0x01E93 }, + { 0x0007A , 0x00331 , 0x01E95 }, + { 0x000A8 , 0x00300 , 0x01FED }, + { 0x000A8 , 0x00301 , 0x00385 }, + { 0x000A8 , 0x00342 , 0x01FC1 }, + { 0x000C2 , 0x00300 , 0x01EA6 }, + { 0x000C2 , 0x00301 , 0x01EA4 }, + { 0x000C2 , 0x00303 , 0x01EAA }, + { 0x000C2 , 0x00309 , 0x01EA8 }, + { 0x000C4 , 0x00304 , 0x001DE }, + { 0x000C5 , 0x00301 , 0x001FA }, + { 0x000C6 , 0x00301 , 0x001FC }, + { 0x000C6 , 0x00304 , 0x001E2 }, + { 0x000C7 , 0x00301 , 0x01E08 }, + { 0x000CA , 0x00300 , 0x01EC0 }, + { 0x000CA , 0x00301 , 0x01EBE }, + { 0x000CA , 0x00303 , 0x01EC4 }, + { 0x000CA , 0x00309 , 0x01EC2 }, + { 0x000CF , 0x00301 , 0x01E2E }, + { 0x000D4 , 0x00300 , 0x01ED2 }, + { 0x000D4 , 0x00301 , 0x01ED0 }, + { 0x000D4 , 0x00303 , 0x01ED6 }, + { 0x000D4 , 0x00309 , 0x01ED4 }, + { 0x000D5 , 0x00301 , 0x01E4C }, + { 0x000D5 , 0x00304 , 0x0022C }, + { 0x000D5 , 0x00308 , 0x01E4E }, + { 0x000D6 , 0x00304 , 0x0022A }, + { 0x000D8 , 0x00301 , 0x001FE }, + { 0x000DC , 0x00300 , 0x001DB }, + { 0x000DC , 0x00301 , 0x001D7 }, + { 0x000DC , 0x00304 , 0x001D5 }, + { 0x000DC , 0x0030C , 0x001D9 }, + { 0x000E2 , 0x00300 , 0x01EA7 }, + { 0x000E2 , 0x00301 , 0x01EA5 }, + { 0x000E2 , 0x00303 , 0x01EAB }, + { 0x000E2 , 0x00309 , 0x01EA9 }, + { 0x000E4 , 0x00304 , 0x001DF }, + { 0x000E5 , 0x00301 , 0x001FB }, + { 0x000E6 , 0x00301 , 0x001FD }, + { 0x000E6 , 0x00304 , 0x001E3 }, + { 0x000E7 , 0x00301 , 0x01E09 }, + { 0x000EA , 0x00300 , 0x01EC1 }, + { 0x000EA , 0x00301 , 0x01EBF }, + { 0x000EA , 0x00303 , 0x01EC5 }, + { 0x000EA , 0x00309 , 0x01EC3 }, + { 0x000EF , 0x00301 , 0x01E2F }, + { 0x000F4 , 0x00300 , 0x01ED3 }, + { 0x000F4 , 0x00301 , 0x01ED1 }, + { 0x000F4 , 0x00303 , 0x01ED7 }, + { 0x000F4 , 0x00309 , 0x01ED5 }, + { 0x000F5 , 0x00301 , 0x01E4D }, + { 0x000F5 , 0x00304 , 0x0022D }, + { 0x000F5 , 0x00308 , 0x01E4F }, + { 0x000F6 , 0x00304 , 0x0022B }, + { 0x000F8 , 0x00301 , 0x001FF }, + { 0x000FC , 0x00300 , 0x001DC }, + { 0x000FC , 0x00301 , 0x001D8 }, + { 0x000FC , 0x00304 , 0x001D6 }, + { 0x000FC , 0x0030C , 0x001DA }, + { 0x00102 , 0x00300 , 0x01EB0 }, + { 0x00102 , 0x00301 , 0x01EAE }, + { 0x00102 , 0x00303 , 0x01EB4 }, + { 0x00102 , 0x00309 , 0x01EB2 }, + { 0x00103 , 0x00300 , 0x01EB1 }, + { 0x00103 , 0x00301 , 0x01EAF }, + { 0x00103 , 0x00303 , 0x01EB5 }, + { 0x00103 , 0x00309 , 0x01EB3 }, + { 0x00112 , 0x00300 , 0x01E14 }, + { 0x00112 , 0x00301 , 0x01E16 }, + { 0x00113 , 0x00300 , 0x01E15 }, + { 0x00113 , 0x00301 , 0x01E17 }, + { 0x0014C , 0x00300 , 0x01E50 }, + { 0x0014C , 0x00301 , 0x01E52 }, + { 0x0014D , 0x00300 , 0x01E51 }, + { 0x0014D , 0x00301 , 0x01E53 }, + { 0x0015A , 0x00307 , 0x01E64 }, + { 0x0015B , 0x00307 , 0x01E65 }, + { 0x00160 , 0x00307 , 0x01E66 }, + { 0x00161 , 0x00307 , 0x01E67 }, + { 0x00168 , 0x00301 , 0x01E78 }, + { 0x00169 , 0x00301 , 0x01E79 }, + { 0x0016A , 0x00308 , 0x01E7A }, + { 0x0016B , 0x00308 , 0x01E7B }, + { 0x0017F , 0x00307 , 0x01E9B }, + { 0x001A0 , 0x00300 , 0x01EDC }, + { 0x001A0 , 0x00301 , 0x01EDA }, + { 0x001A0 , 0x00303 , 0x01EE0 }, + { 0x001A0 , 0x00309 , 0x01EDE }, + { 0x001A0 , 0x00323 , 0x01EE2 }, + { 0x001A1 , 0x00300 , 0x01EDD }, + { 0x001A1 , 0x00301 , 0x01EDB }, + { 0x001A1 , 0x00303 , 0x01EE1 }, + { 0x001A1 , 0x00309 , 0x01EDF }, + { 0x001A1 , 0x00323 , 0x01EE3 }, + { 0x001AF , 0x00300 , 0x01EEA }, + { 0x001AF , 0x00301 , 0x01EE8 }, + { 0x001AF , 0x00303 , 0x01EEE }, + { 0x001AF , 0x00309 , 0x01EEC }, + { 0x001AF , 0x00323 , 0x01EF0 }, + { 0x001B0 , 0x00300 , 0x01EEB }, + { 0x001B0 , 0x00301 , 0x01EE9 }, + { 0x001B0 , 0x00303 , 0x01EEF }, + { 0x001B0 , 0x00309 , 0x01EED }, + { 0x001B0 , 0x00323 , 0x01EF1 }, + { 0x001B7 , 0x0030C , 0x001EE }, + { 0x001EA , 0x00304 , 0x001EC }, + { 0x001EB , 0x00304 , 0x001ED }, + { 0x00226 , 0x00304 , 0x001E0 }, + { 0x00227 , 0x00304 , 0x001E1 }, + { 0x00228 , 0x00306 , 0x01E1C }, + { 0x00229 , 0x00306 , 0x01E1D }, + { 0x0022E , 0x00304 , 0x00230 }, + { 0x0022F , 0x00304 , 0x00231 }, + { 0x00292 , 0x0030C , 0x001EF }, + { 0x00391 , 0x00300 , 0x01FBA }, + { 0x00391 , 0x00301 , 0x00386 }, + { 0x00391 , 0x00304 , 0x01FB9 }, + { 0x00391 , 0x00306 , 0x01FB8 }, + { 0x00391 , 0x00313 , 0x01F08 }, + { 0x00391 , 0x00314 , 0x01F09 }, + { 0x00391 , 0x00345 , 0x01FBC }, + { 0x00395 , 0x00300 , 0x01FC8 }, + { 0x00395 , 0x00301 , 0x00388 }, + { 0x00395 , 0x00313 , 0x01F18 }, + { 0x00395 , 0x00314 , 0x01F19 }, + { 0x00397 , 0x00300 , 0x01FCA }, + { 0x00397 , 0x00301 , 0x00389 }, + { 0x00397 , 0x00313 , 0x01F28 }, + { 0x00397 , 0x00314 , 0x01F29 }, + { 0x00397 , 0x00345 , 0x01FCC }, + { 0x00399 , 0x00300 , 0x01FDA }, + { 0x00399 , 0x00301 , 0x0038A }, + { 0x00399 , 0x00304 , 0x01FD9 }, + { 0x00399 , 0x00306 , 0x01FD8 }, + { 0x00399 , 0x00308 , 0x003AA }, + { 0x00399 , 0x00313 , 0x01F38 }, + { 0x00399 , 0x00314 , 0x01F39 }, + { 0x0039F , 0x00300 , 0x01FF8 }, + { 0x0039F , 0x00301 , 0x0038C }, + { 0x0039F , 0x00313 , 0x01F48 }, + { 0x0039F , 0x00314 , 0x01F49 }, + { 0x003A1 , 0x00314 , 0x01FEC }, + { 0x003A5 , 0x00300 , 0x01FEA }, + { 0x003A5 , 0x00301 , 0x0038E }, + { 0x003A5 , 0x00304 , 0x01FE9 }, + { 0x003A5 , 0x00306 , 0x01FE8 }, + { 0x003A5 , 0x00308 , 0x003AB }, + { 0x003A5 , 0x00314 , 0x01F59 }, + { 0x003A9 , 0x00300 , 0x01FFA }, + { 0x003A9 , 0x00301 , 0x0038F }, + { 0x003A9 , 0x00313 , 0x01F68 }, + { 0x003A9 , 0x00314 , 0x01F69 }, + { 0x003A9 , 0x00345 , 0x01FFC }, + { 0x003AC , 0x00345 , 0x01FB4 }, + { 0x003AE , 0x00345 , 0x01FC4 }, + { 0x003B1 , 0x00300 , 0x01F70 }, + { 0x003B1 , 0x00301 , 0x003AC }, + { 0x003B1 , 0x00304 , 0x01FB1 }, + { 0x003B1 , 0x00306 , 0x01FB0 }, + { 0x003B1 , 0x00313 , 0x01F00 }, + { 0x003B1 , 0x00314 , 0x01F01 }, + { 0x003B1 , 0x00342 , 0x01FB6 }, + { 0x003B1 , 0x00345 , 0x01FB3 }, + { 0x003B5 , 0x00300 , 0x01F72 }, + { 0x003B5 , 0x00301 , 0x003AD }, + { 0x003B5 , 0x00313 , 0x01F10 }, + { 0x003B5 , 0x00314 , 0x01F11 }, + { 0x003B7 , 0x00300 , 0x01F74 }, + { 0x003B7 , 0x00301 , 0x003AE }, + { 0x003B7 , 0x00313 , 0x01F20 }, + { 0x003B7 , 0x00314 , 0x01F21 }, + { 0x003B7 , 0x00342 , 0x01FC6 }, + { 0x003B7 , 0x00345 , 0x01FC3 }, + { 0x003B9 , 0x00300 , 0x01F76 }, + { 0x003B9 , 0x00301 , 0x003AF }, + { 0x003B9 , 0x00304 , 0x01FD1 }, + { 0x003B9 , 0x00306 , 0x01FD0 }, + { 0x003B9 , 0x00308 , 0x003CA }, + { 0x003B9 , 0x00313 , 0x01F30 }, + { 0x003B9 , 0x00314 , 0x01F31 }, + { 0x003B9 , 0x00342 , 0x01FD6 }, + { 0x003BF , 0x00300 , 0x01F78 }, + { 0x003BF , 0x00301 , 0x003CC }, + { 0x003BF , 0x00313 , 0x01F40 }, + { 0x003BF , 0x00314 , 0x01F41 }, + { 0x003C1 , 0x00313 , 0x01FE4 }, + { 0x003C1 , 0x00314 , 0x01FE5 }, + { 0x003C5 , 0x00300 , 0x01F7A }, + { 0x003C5 , 0x00301 , 0x003CD }, + { 0x003C5 , 0x00304 , 0x01FE1 }, + { 0x003C5 , 0x00306 , 0x01FE0 }, + { 0x003C5 , 0x00308 , 0x003CB }, + { 0x003C5 , 0x00313 , 0x01F50 }, + { 0x003C5 , 0x00314 , 0x01F51 }, + { 0x003C5 , 0x00342 , 0x01FE6 }, + { 0x003C9 , 0x00300 , 0x01F7C }, + { 0x003C9 , 0x00301 , 0x003CE }, + { 0x003C9 , 0x00313 , 0x01F60 }, + { 0x003C9 , 0x00314 , 0x01F61 }, + { 0x003C9 , 0x00342 , 0x01FF6 }, + { 0x003C9 , 0x00345 , 0x01FF3 }, + { 0x003CA , 0x00300 , 0x01FD2 }, + { 0x003CA , 0x00301 , 0x00390 }, + { 0x003CA , 0x00342 , 0x01FD7 }, + { 0x003CB , 0x00300 , 0x01FE2 }, + { 0x003CB , 0x00301 , 0x003B0 }, + { 0x003CB , 0x00342 , 0x01FE7 }, + { 0x003CE , 0x00345 , 0x01FF4 }, + { 0x003D2 , 0x00301 , 0x003D3 }, + { 0x003D2 , 0x00308 , 0x003D4 }, + { 0x00406 , 0x00308 , 0x00407 }, + { 0x00410 , 0x00306 , 0x004D0 }, + { 0x00410 , 0x00308 , 0x004D2 }, + { 0x00413 , 0x00301 , 0x00403 }, + { 0x00415 , 0x00300 , 0x00400 }, + { 0x00415 , 0x00306 , 0x004D6 }, + { 0x00415 , 0x00308 , 0x00401 }, + { 0x00416 , 0x00306 , 0x004C1 }, + { 0x00416 , 0x00308 , 0x004DC }, + { 0x00417 , 0x00308 , 0x004DE }, + { 0x00418 , 0x00300 , 0x0040D }, + { 0x00418 , 0x00304 , 0x004E2 }, + { 0x00418 , 0x00306 , 0x00419 }, + { 0x00418 , 0x00308 , 0x004E4 }, + { 0x0041A , 0x00301 , 0x0040C }, + { 0x0041E , 0x00308 , 0x004E6 }, + { 0x00423 , 0x00304 , 0x004EE }, + { 0x00423 , 0x00306 , 0x0040E }, + { 0x00423 , 0x00308 , 0x004F0 }, + { 0x00423 , 0x0030B , 0x004F2 }, + { 0x00427 , 0x00308 , 0x004F4 }, + { 0x0042B , 0x00308 , 0x004F8 }, + { 0x0042D , 0x00308 , 0x004EC }, + { 0x00430 , 0x00306 , 0x004D1 }, + { 0x00430 , 0x00308 , 0x004D3 }, + { 0x00433 , 0x00301 , 0x00453 }, + { 0x00435 , 0x00300 , 0x00450 }, + { 0x00435 , 0x00306 , 0x004D7 }, + { 0x00435 , 0x00308 , 0x00451 }, + { 0x00436 , 0x00306 , 0x004C2 }, + { 0x00436 , 0x00308 , 0x004DD }, + { 0x00437 , 0x00308 , 0x004DF }, + { 0x00438 , 0x00300 , 0x0045D }, + { 0x00438 , 0x00304 , 0x004E3 }, + { 0x00438 , 0x00306 , 0x00439 }, + { 0x00438 , 0x00308 , 0x004E5 }, + { 0x0043A , 0x00301 , 0x0045C }, + { 0x0043E , 0x00308 , 0x004E7 }, + { 0x00443 , 0x00304 , 0x004EF }, + { 0x00443 , 0x00306 , 0x0045E }, + { 0x00443 , 0x00308 , 0x004F1 }, + { 0x00443 , 0x0030B , 0x004F3 }, + { 0x00447 , 0x00308 , 0x004F5 }, + { 0x0044B , 0x00308 , 0x004F9 }, + { 0x0044D , 0x00308 , 0x004ED }, + { 0x00456 , 0x00308 , 0x00457 }, + { 0x00474 , 0x0030F , 0x00476 }, + { 0x00475 , 0x0030F , 0x00477 }, + { 0x004D8 , 0x00308 , 0x004DA }, + { 0x004D9 , 0x00308 , 0x004DB }, + { 0x004E8 , 0x00308 , 0x004EA }, + { 0x004E9 , 0x00308 , 0x004EB }, + { 0x00627 , 0x00653 , 0x00622 }, + { 0x00627 , 0x00654 , 0x00623 }, + { 0x00627 , 0x00655 , 0x00625 }, + { 0x00648 , 0x00654 , 0x00624 }, + { 0x0064A , 0x00654 , 0x00626 }, + { 0x006C1 , 0x00654 , 0x006C2 }, + { 0x006D2 , 0x00654 , 0x006D3 }, + { 0x006D5 , 0x00654 , 0x006C0 }, + { 0x00928 , 0x0093C , 0x00929 }, + { 0x00930 , 0x0093C , 0x00931 }, + { 0x00933 , 0x0093C , 0x00934 }, + { 0x009C7 , 0x009BE , 0x009CB }, + { 0x009C7 , 0x009D7 , 0x009CC }, + { 0x00B47 , 0x00B3E , 0x00B4B }, + { 0x00B47 , 0x00B56 , 0x00B48 }, + { 0x00B47 , 0x00B57 , 0x00B4C }, + { 0x00B92 , 0x00BD7 , 0x00B94 }, + { 0x00BC6 , 0x00BBE , 0x00BCA }, + { 0x00BC6 , 0x00BD7 , 0x00BCC }, + { 0x00BC7 , 0x00BBE , 0x00BCB }, + { 0x00C46 , 0x00C56 , 0x00C48 }, + { 0x00CBF , 0x00CD5 , 0x00CC0 }, + { 0x00CC6 , 0x00CC2 , 0x00CCA }, + { 0x00CC6 , 0x00CD5 , 0x00CC7 }, + { 0x00CC6 , 0x00CD6 , 0x00CC8 }, + { 0x00CCA , 0x00CD5 , 0x00CCB }, + { 0x00D46 , 0x00D3E , 0x00D4A }, + { 0x00D46 , 0x00D57 , 0x00D4C }, + { 0x00D47 , 0x00D3E , 0x00D4B }, + { 0x00DD9 , 0x00DCA , 0x00DDA }, + { 0x00DD9 , 0x00DCF , 0x00DDC }, + { 0x00DD9 , 0x00DDF , 0x00DDE }, + { 0x00DDC , 0x00DCA , 0x00DDD }, + { 0x01025 , 0x0102E , 0x01026 }, + { 0x01B05 , 0x01B35 , 0x01B06 }, + { 0x01B07 , 0x01B35 , 0x01B08 }, + { 0x01B09 , 0x01B35 , 0x01B0A }, + { 0x01B0B , 0x01B35 , 0x01B0C }, + { 0x01B0D , 0x01B35 , 0x01B0E }, + { 0x01B11 , 0x01B35 , 0x01B12 }, + { 0x01B3A , 0x01B35 , 0x01B3B }, + { 0x01B3C , 0x01B35 , 0x01B3D }, + { 0x01B3E , 0x01B35 , 0x01B40 }, + { 0x01B3F , 0x01B35 , 0x01B41 }, + { 0x01B42 , 0x01B35 , 0x01B43 }, + { 0x01E36 , 0x00304 , 0x01E38 }, + { 0x01E37 , 0x00304 , 0x01E39 }, + { 0x01E5A , 0x00304 , 0x01E5C }, + { 0x01E5B , 0x00304 , 0x01E5D }, + { 0x01E62 , 0x00307 , 0x01E68 }, + { 0x01E63 , 0x00307 , 0x01E69 }, + { 0x01EA0 , 0x00302 , 0x01EAC }, + { 0x01EA0 , 0x00306 , 0x01EB6 }, + { 0x01EA1 , 0x00302 , 0x01EAD }, + { 0x01EA1 , 0x00306 , 0x01EB7 }, + { 0x01EB8 , 0x00302 , 0x01EC6 }, + { 0x01EB9 , 0x00302 , 0x01EC7 }, + { 0x01ECC , 0x00302 , 0x01ED8 }, + { 0x01ECD , 0x00302 , 0x01ED9 }, + { 0x01F00 , 0x00300 , 0x01F02 }, + { 0x01F00 , 0x00301 , 0x01F04 }, + { 0x01F00 , 0x00342 , 0x01F06 }, + { 0x01F00 , 0x00345 , 0x01F80 }, + { 0x01F01 , 0x00300 , 0x01F03 }, + { 0x01F01 , 0x00301 , 0x01F05 }, + { 0x01F01 , 0x00342 , 0x01F07 }, + { 0x01F01 , 0x00345 , 0x01F81 }, + { 0x01F02 , 0x00345 , 0x01F82 }, + { 0x01F03 , 0x00345 , 0x01F83 }, + { 0x01F04 , 0x00345 , 0x01F84 }, + { 0x01F05 , 0x00345 , 0x01F85 }, + { 0x01F06 , 0x00345 , 0x01F86 }, + { 0x01F07 , 0x00345 , 0x01F87 }, + { 0x01F08 , 0x00300 , 0x01F0A }, + { 0x01F08 , 0x00301 , 0x01F0C }, + { 0x01F08 , 0x00342 , 0x01F0E }, + { 0x01F08 , 0x00345 , 0x01F88 }, + { 0x01F09 , 0x00300 , 0x01F0B }, + { 0x01F09 , 0x00301 , 0x01F0D }, + { 0x01F09 , 0x00342 , 0x01F0F }, + { 0x01F09 , 0x00345 , 0x01F89 }, + { 0x01F0A , 0x00345 , 0x01F8A }, + { 0x01F0B , 0x00345 , 0x01F8B }, + { 0x01F0C , 0x00345 , 0x01F8C }, + { 0x01F0D , 0x00345 , 0x01F8D }, + { 0x01F0E , 0x00345 , 0x01F8E }, + { 0x01F0F , 0x00345 , 0x01F8F }, + { 0x01F10 , 0x00300 , 0x01F12 }, + { 0x01F10 , 0x00301 , 0x01F14 }, + { 0x01F11 , 0x00300 , 0x01F13 }, + { 0x01F11 , 0x00301 , 0x01F15 }, + { 0x01F18 , 0x00300 , 0x01F1A }, + { 0x01F18 , 0x00301 , 0x01F1C }, + { 0x01F19 , 0x00300 , 0x01F1B }, + { 0x01F19 , 0x00301 , 0x01F1D }, + { 0x01F20 , 0x00300 , 0x01F22 }, + { 0x01F20 , 0x00301 , 0x01F24 }, + { 0x01F20 , 0x00342 , 0x01F26 }, + { 0x01F20 , 0x00345 , 0x01F90 }, + { 0x01F21 , 0x00300 , 0x01F23 }, + { 0x01F21 , 0x00301 , 0x01F25 }, + { 0x01F21 , 0x00342 , 0x01F27 }, + { 0x01F21 , 0x00345 , 0x01F91 }, + { 0x01F22 , 0x00345 , 0x01F92 }, + { 0x01F23 , 0x00345 , 0x01F93 }, + { 0x01F24 , 0x00345 , 0x01F94 }, + { 0x01F25 , 0x00345 , 0x01F95 }, + { 0x01F26 , 0x00345 , 0x01F96 }, + { 0x01F27 , 0x00345 , 0x01F97 }, + { 0x01F28 , 0x00300 , 0x01F2A }, + { 0x01F28 , 0x00301 , 0x01F2C }, + { 0x01F28 , 0x00342 , 0x01F2E }, + { 0x01F28 , 0x00345 , 0x01F98 }, + { 0x01F29 , 0x00300 , 0x01F2B }, + { 0x01F29 , 0x00301 , 0x01F2D }, + { 0x01F29 , 0x00342 , 0x01F2F }, + { 0x01F29 , 0x00345 , 0x01F99 }, + { 0x01F2A , 0x00345 , 0x01F9A }, + { 0x01F2B , 0x00345 , 0x01F9B }, + { 0x01F2C , 0x00345 , 0x01F9C }, + { 0x01F2D , 0x00345 , 0x01F9D }, + { 0x01F2E , 0x00345 , 0x01F9E }, + { 0x01F2F , 0x00345 , 0x01F9F }, + { 0x01F30 , 0x00300 , 0x01F32 }, + { 0x01F30 , 0x00301 , 0x01F34 }, + { 0x01F30 , 0x00342 , 0x01F36 }, + { 0x01F31 , 0x00300 , 0x01F33 }, + { 0x01F31 , 0x00301 , 0x01F35 }, + { 0x01F31 , 0x00342 , 0x01F37 }, + { 0x01F38 , 0x00300 , 0x01F3A }, + { 0x01F38 , 0x00301 , 0x01F3C }, + { 0x01F38 , 0x00342 , 0x01F3E }, + { 0x01F39 , 0x00300 , 0x01F3B }, + { 0x01F39 , 0x00301 , 0x01F3D }, + { 0x01F39 , 0x00342 , 0x01F3F }, + { 0x01F40 , 0x00300 , 0x01F42 }, + { 0x01F40 , 0x00301 , 0x01F44 }, + { 0x01F41 , 0x00300 , 0x01F43 }, + { 0x01F41 , 0x00301 , 0x01F45 }, + { 0x01F48 , 0x00300 , 0x01F4A }, + { 0x01F48 , 0x00301 , 0x01F4C }, + { 0x01F49 , 0x00300 , 0x01F4B }, + { 0x01F49 , 0x00301 , 0x01F4D }, + { 0x01F50 , 0x00300 , 0x01F52 }, + { 0x01F50 , 0x00301 , 0x01F54 }, + { 0x01F50 , 0x00342 , 0x01F56 }, + { 0x01F51 , 0x00300 , 0x01F53 }, + { 0x01F51 , 0x00301 , 0x01F55 }, + { 0x01F51 , 0x00342 , 0x01F57 }, + { 0x01F59 , 0x00300 , 0x01F5B }, + { 0x01F59 , 0x00301 , 0x01F5D }, + { 0x01F59 , 0x00342 , 0x01F5F }, + { 0x01F60 , 0x00300 , 0x01F62 }, + { 0x01F60 , 0x00301 , 0x01F64 }, + { 0x01F60 , 0x00342 , 0x01F66 }, + { 0x01F60 , 0x00345 , 0x01FA0 }, + { 0x01F61 , 0x00300 , 0x01F63 }, + { 0x01F61 , 0x00301 , 0x01F65 }, + { 0x01F61 , 0x00342 , 0x01F67 }, + { 0x01F61 , 0x00345 , 0x01FA1 }, + { 0x01F62 , 0x00345 , 0x01FA2 }, + { 0x01F63 , 0x00345 , 0x01FA3 }, + { 0x01F64 , 0x00345 , 0x01FA4 }, + { 0x01F65 , 0x00345 , 0x01FA5 }, + { 0x01F66 , 0x00345 , 0x01FA6 }, + { 0x01F67 , 0x00345 , 0x01FA7 }, + { 0x01F68 , 0x00300 , 0x01F6A }, + { 0x01F68 , 0x00301 , 0x01F6C }, + { 0x01F68 , 0x00342 , 0x01F6E }, + { 0x01F68 , 0x00345 , 0x01FA8 }, + { 0x01F69 , 0x00300 , 0x01F6B }, + { 0x01F69 , 0x00301 , 0x01F6D }, + { 0x01F69 , 0x00342 , 0x01F6F }, + { 0x01F69 , 0x00345 , 0x01FA9 }, + { 0x01F6A , 0x00345 , 0x01FAA }, + { 0x01F6B , 0x00345 , 0x01FAB }, + { 0x01F6C , 0x00345 , 0x01FAC }, + { 0x01F6D , 0x00345 , 0x01FAD }, + { 0x01F6E , 0x00345 , 0x01FAE }, + { 0x01F6F , 0x00345 , 0x01FAF }, + { 0x01F70 , 0x00345 , 0x01FB2 }, + { 0x01F74 , 0x00345 , 0x01FC2 }, + { 0x01F7C , 0x00345 , 0x01FF2 }, + { 0x01FB6 , 0x00345 , 0x01FB7 }, + { 0x01FBF , 0x00300 , 0x01FCD }, + { 0x01FBF , 0x00301 , 0x01FCE }, + { 0x01FBF , 0x00342 , 0x01FCF }, + { 0x01FC6 , 0x00345 , 0x01FC7 }, + { 0x01FF6 , 0x00345 , 0x01FF7 }, + { 0x01FFE , 0x00300 , 0x01FDD }, + { 0x01FFE , 0x00301 , 0x01FDE }, + { 0x01FFE , 0x00342 , 0x01FDF }, + { 0x02190 , 0x00338 , 0x0219A }, + { 0x02192 , 0x00338 , 0x0219B }, + { 0x02194 , 0x00338 , 0x021AE }, + { 0x021D0 , 0x00338 , 0x021CD }, + { 0x021D2 , 0x00338 , 0x021CF }, + { 0x021D4 , 0x00338 , 0x021CE }, + { 0x02203 , 0x00338 , 0x02204 }, + { 0x02208 , 0x00338 , 0x02209 }, + { 0x0220B , 0x00338 , 0x0220C }, + { 0x02223 , 0x00338 , 0x02224 }, + { 0x02225 , 0x00338 , 0x02226 }, + { 0x0223C , 0x00338 , 0x02241 }, + { 0x02243 , 0x00338 , 0x02244 }, + { 0x02245 , 0x00338 , 0x02247 }, + { 0x02248 , 0x00338 , 0x02249 }, + { 0x0224D , 0x00338 , 0x0226D }, + { 0x02261 , 0x00338 , 0x02262 }, + { 0x02264 , 0x00338 , 0x02270 }, + { 0x02265 , 0x00338 , 0x02271 }, + { 0x02272 , 0x00338 , 0x02274 }, + { 0x02273 , 0x00338 , 0x02275 }, + { 0x02276 , 0x00338 , 0x02278 }, + { 0x02277 , 0x00338 , 0x02279 }, + { 0x0227A , 0x00338 , 0x02280 }, + { 0x0227B , 0x00338 , 0x02281 }, + { 0x0227C , 0x00338 , 0x022E0 }, + { 0x0227D , 0x00338 , 0x022E1 }, + { 0x02282 , 0x00338 , 0x02284 }, + { 0x02283 , 0x00338 , 0x02285 }, + { 0x02286 , 0x00338 , 0x02288 }, + { 0x02287 , 0x00338 , 0x02289 }, + { 0x02291 , 0x00338 , 0x022E2 }, + { 0x02292 , 0x00338 , 0x022E3 }, + { 0x022A2 , 0x00338 , 0x022AC }, + { 0x022A8 , 0x00338 , 0x022AD }, + { 0x022A9 , 0x00338 , 0x022AE }, + { 0x022AB , 0x00338 , 0x022AF }, + { 0x022B2 , 0x00338 , 0x022EA }, + { 0x022B3 , 0x00338 , 0x022EB }, + { 0x022B4 , 0x00338 , 0x022EC }, + { 0x022B5 , 0x00338 , 0x022ED }, + { 0x03046 , 0x03099 , 0x03094 }, + { 0x0304B , 0x03099 , 0x0304C }, + { 0x0304D , 0x03099 , 0x0304E }, + { 0x0304F , 0x03099 , 0x03050 }, + { 0x03051 , 0x03099 , 0x03052 }, + { 0x03053 , 0x03099 , 0x03054 }, + { 0x03055 , 0x03099 , 0x03056 }, + { 0x03057 , 0x03099 , 0x03058 }, + { 0x03059 , 0x03099 , 0x0305A }, + { 0x0305B , 0x03099 , 0x0305C }, + { 0x0305D , 0x03099 , 0x0305E }, + { 0x0305F , 0x03099 , 0x03060 }, + { 0x03061 , 0x03099 , 0x03062 }, + { 0x03064 , 0x03099 , 0x03065 }, + { 0x03066 , 0x03099 , 0x03067 }, + { 0x03068 , 0x03099 , 0x03069 }, + { 0x0306F , 0x03099 , 0x03070 }, + { 0x0306F , 0x0309A , 0x03071 }, + { 0x03072 , 0x03099 , 0x03073 }, + { 0x03072 , 0x0309A , 0x03074 }, + { 0x03075 , 0x03099 , 0x03076 }, + { 0x03075 , 0x0309A , 0x03077 }, + { 0x03078 , 0x03099 , 0x03079 }, + { 0x03078 , 0x0309A , 0x0307A }, + { 0x0307B , 0x03099 , 0x0307C }, + { 0x0307B , 0x0309A , 0x0307D }, + { 0x0309D , 0x03099 , 0x0309E }, + { 0x030A6 , 0x03099 , 0x030F4 }, + { 0x030AB , 0x03099 , 0x030AC }, + { 0x030AD , 0x03099 , 0x030AE }, + { 0x030AF , 0x03099 , 0x030B0 }, + { 0x030B1 , 0x03099 , 0x030B2 }, + { 0x030B3 , 0x03099 , 0x030B4 }, + { 0x030B5 , 0x03099 , 0x030B6 }, + { 0x030B7 , 0x03099 , 0x030B8 }, + { 0x030B9 , 0x03099 , 0x030BA }, + { 0x030BB , 0x03099 , 0x030BC }, + { 0x030BD , 0x03099 , 0x030BE }, + { 0x030BF , 0x03099 , 0x030C0 }, + { 0x030C1 , 0x03099 , 0x030C2 }, + { 0x030C4 , 0x03099 , 0x030C5 }, + { 0x030C6 , 0x03099 , 0x030C7 }, + { 0x030C8 , 0x03099 , 0x030C9 }, + { 0x030CF , 0x03099 , 0x030D0 }, + { 0x030CF , 0x0309A , 0x030D1 }, + { 0x030D2 , 0x03099 , 0x030D3 }, + { 0x030D2 , 0x0309A , 0x030D4 }, + { 0x030D5 , 0x03099 , 0x030D6 }, + { 0x030D5 , 0x0309A , 0x030D7 }, + { 0x030D8 , 0x03099 , 0x030D9 }, + { 0x030D8 , 0x0309A , 0x030DA }, + { 0x030DB , 0x03099 , 0x030DC }, + { 0x030DB , 0x0309A , 0x030DD }, + { 0x030EF , 0x03099 , 0x030F7 }, + { 0x030F0 , 0x03099 , 0x030F8 }, + { 0x030F1 , 0x03099 , 0x030F9 }, + { 0x030F2 , 0x03099 , 0x030FA }, + { 0x030FD , 0x03099 , 0x030FE }, + { 0x11099 , 0x110BA , 0x1109A }, + { 0x1109B , 0x110BA , 0x1109C }, + { 0x110A5 , 0x110BA , 0x110AB }, +}; + +#define CANONICAL_CLASS_MIN 0x0300 +#define CANONICAL_CLASS_MAX 0x1D244 + +#define IS_DECOMPOSABLE_BLOCK(uc) \ + (((uc)>>8) <= 0x1D2 && u_decomposable_blocks[(uc)>>8]) +static const char u_decomposable_blocks[0x1D2+1] = { + 0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,1,1,1,1,1,1,1,0,0, + 1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0, + 0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1, +}; + +/* Get Canonical Combining Class(CCC). */ +#define CCC(uc) \ + (((uc) > 0x1D244)?0:\ + ccc_val[ccc_val_index[ccc_index[(uc)>>8]][((uc)>>4)&0x0F]][(uc)&0x0F]) + +/* The table of the value of Canonical Cimbining Class */ +static const unsigned char ccc_val[][16] = { + /* idx=0: XXXX0 - XXXXF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=1: 00300 - 0030F */ + {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=2: 00310 - 0031F */ + {230, 230, 230, 230, 230, 232, 220, 220, 220, 220, 232, 216, 220, 220, 220, 220 }, + /* idx=3: 00320 - 0032F */ + {220, 202, 202, 220, 220, 220, 220, 202, 202, 220, 220, 220, 220, 220, 220, 220 }, + /* idx=4: 00330 - 0033F */ + {220, 220, 220, 220, 1, 1, 1, 1, 1, 220, 220, 220, 220, 230, 230, 230 }, + /* idx=5: 00340 - 0034F */ + {230, 230, 230, 230, 230, 240, 230, 220, 220, 220, 230, 230, 230, 220, 220, 0 }, + /* idx=6: 00350 - 0035F */ + {230, 230, 230, 220, 220, 220, 220, 230, 232, 220, 220, 230, 233, 234, 234, 233 }, + /* idx=7: 00360 - 0036F */ + {234, 234, 233, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=8: 00480 - 0048F */ + {0, 0, 0, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=9: 00590 - 0059F */ + {0, 220, 230, 230, 230, 230, 220, 230, 230, 230, 222, 220, 230, 230, 230, 230 }, + /* idx=10: 005A0 - 005AF */ + {230, 230, 220, 220, 220, 220, 220, 220, 230, 230, 220, 230, 230, 222, 228, 230 }, + /* idx=11: 005B0 - 005BF */ + {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 0, 23 }, + /* idx=12: 005C0 - 005CF */ + {0, 24, 25, 0, 230, 220, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=13: 00610 - 0061F */ + {230, 230, 230, 230, 230, 230, 230, 230, 30, 31, 32, 0, 0, 0, 0, 0 }, + /* idx=14: 00640 - 0064F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 28, 29, 30, 31 }, + /* idx=15: 00650 - 0065F */ + {32, 33, 34, 230, 230, 220, 220, 230, 230, 230, 230, 230, 220, 230, 230, 220 }, + /* idx=16: 00670 - 0067F */ + {35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=17: 006D0 - 006DF */ + {0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 230, 230, 230, 0, 0, 230 }, + /* idx=18: 006E0 - 006EF */ + {230, 230, 230, 220, 230, 0, 0, 230, 230, 0, 220, 230, 230, 220, 0, 0 }, + /* idx=19: 00710 - 0071F */ + {0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=20: 00730 - 0073F */ + {230, 220, 230, 230, 220, 230, 230, 220, 220, 220, 230, 220, 220, 230, 220, 230 }, + /* idx=21: 00740 - 0074F */ + {230, 230, 220, 230, 220, 230, 220, 230, 220, 230, 230, 0, 0, 0, 0, 0 }, + /* idx=22: 007E0 - 007EF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 230 }, + /* idx=23: 007F0 - 007FF */ + {230, 230, 220, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=24: 00810 - 0081F */ + {0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 0, 230, 230, 230, 230, 230 }, + /* idx=25: 00820 - 0082F */ + {230, 230, 230, 230, 0, 230, 230, 230, 0, 230, 230, 230, 230, 230, 0, 0 }, + /* idx=26: 00850 - 0085F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 0, 0, 0, 0 }, + /* idx=27: 00930 - 0093F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=28: 00940 - 0094F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=29: 00950 - 0095F */ + {0, 230, 220, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=30: 009B0 - 009BF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=31: 009C0 - 009CF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=32: 00A30 - 00A3F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=33: 00A40 - 00A4F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=34: 00AB0 - 00ABF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=35: 00AC0 - 00ACF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=36: 00B30 - 00B3F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=37: 00B40 - 00B4F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=38: 00BC0 - 00BCF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=39: 00C40 - 00C4F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=40: 00C50 - 00C5F */ + {0, 0, 0, 0, 0, 84, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=41: 00CB0 - 00CBF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0 }, + /* idx=42: 00CC0 - 00CCF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=43: 00D40 - 00D4F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=44: 00DC0 - 00DCF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0 }, + /* idx=45: 00E30 - 00E3F */ + {0, 0, 0, 0, 0, 0, 0, 0, 103, 103, 9, 0, 0, 0, 0, 0 }, + /* idx=46: 00E40 - 00E4F */ + {0, 0, 0, 0, 0, 0, 0, 0, 107, 107, 107, 107, 0, 0, 0, 0 }, + /* idx=47: 00EB0 - 00EBF */ + {0, 0, 0, 0, 0, 0, 0, 0, 118, 118, 0, 0, 0, 0, 0, 0 }, + /* idx=48: 00EC0 - 00ECF */ + {0, 0, 0, 0, 0, 0, 0, 0, 122, 122, 122, 122, 0, 0, 0, 0 }, + /* idx=49: 00F10 - 00F1F */ + {0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 0, 0, 0, 0, 0, 0 }, + /* idx=50: 00F30 - 00F3F */ + {0, 0, 0, 0, 0, 220, 0, 220, 0, 216, 0, 0, 0, 0, 0, 0 }, + /* idx=51: 00F70 - 00F7F */ + {0, 129, 130, 0, 132, 0, 0, 0, 0, 0, 130, 130, 130, 130, 0, 0 }, + /* idx=52: 00F80 - 00F8F */ + {130, 0, 230, 230, 9, 0, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=53: 00FC0 - 00FCF */ + {0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=54: 01030 - 0103F */ + {0, 0, 0, 0, 0, 0, 0, 7, 0, 9, 9, 0, 0, 0, 0, 0 }, + /* idx=55: 01080 - 0108F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0 }, + /* idx=56: 01350 - 0135F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230 }, + /* idx=57: 01710 - 0171F */ + {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=58: 01730 - 0173F */ + {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=59: 017D0 - 017DF */ + {0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 0, 0 }, + /* idx=60: 018A0 - 018AF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0 }, + /* idx=61: 01930 - 0193F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 222, 230, 220, 0, 0, 0, 0 }, + /* idx=62: 01A10 - 01A1F */ + {0, 0, 0, 0, 0, 0, 0, 230, 220, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=63: 01A60 - 01A6F */ + {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=64: 01A70 - 01A7F */ + {0, 0, 0, 0, 0, 230, 230, 230, 230, 230, 230, 230, 230, 0, 0, 220 }, + /* idx=65: 01B30 - 01B3F */ + {0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=66: 01B40 - 01B4F */ + {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=67: 01B60 - 01B6F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 220, 230, 230, 230 }, + /* idx=68: 01B70 - 01B7F */ + {230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=69: 01BA0 - 01BAF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0 }, + /* idx=70: 01BE0 - 01BEF */ + {0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=71: 01BF0 - 01BFF */ + {0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=72: 01C30 - 01C3F */ + {0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=73: 01CD0 - 01CDF */ + {230, 230, 230, 0, 1, 220, 220, 220, 220, 220, 230, 230, 220, 220, 220, 220 }, + /* idx=74: 01CE0 - 01CEF */ + {230, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 220, 0, 0 }, + /* idx=75: 01DC0 - 01DCF */ + {230, 230, 220, 230, 230, 230, 230, 230, 230, 230, 220, 230, 230, 234, 214, 220 }, + /* idx=76: 01DD0 - 01DDF */ + {202, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=77: 01DE0 - 01DEF */ + {230, 230, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=78: 01DF0 - 01DFF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 233, 220, 230, 220 }, + /* idx=79: 020D0 - 020DF */ + {230, 230, 1, 1, 230, 230, 230, 230, 1, 1, 1, 230, 230, 0, 0, 0 }, + /* idx=80: 020E0 - 020EF */ + {0, 230, 0, 0, 0, 1, 1, 230, 220, 230, 1, 1, 220, 220, 220, 220 }, + /* idx=81: 020F0 - 020FF */ + {230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=82: 02CE0 - 02CEF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230 }, + /* idx=83: 02CF0 - 02CFF */ + {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=84: 02D70 - 02D7F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9 }, + /* idx=85: 02DE0 - 02DEF */ + {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=86: 02DF0 - 02DFF */ + {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=87: 03020 - 0302F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 218, 228, 232, 222, 224, 224 }, + /* idx=88: 03090 - 0309F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0 }, + /* idx=89: 0A660 - 0A66F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230 }, + /* idx=90: 0A670 - 0A67F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 0, 0 }, + /* idx=91: 0A6F0 - 0A6FF */ + {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=92: 0A800 - 0A80F */ + {0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=93: 0A8C0 - 0A8CF */ + {0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=94: 0A8E0 - 0A8EF */ + {230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230 }, + /* idx=95: 0A8F0 - 0A8FF */ + {230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=96: 0A920 - 0A92F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 0, 0 }, + /* idx=97: 0A950 - 0A95F */ + {0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=98: 0A9B0 - 0A9BF */ + {0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=99: 0A9C0 - 0A9CF */ + {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=100: 0AAB0 - 0AABF */ + {230, 0, 230, 230, 220, 0, 0, 230, 230, 0, 0, 0, 0, 0, 230, 230 }, + /* idx=101: 0AAC0 - 0AACF */ + {0, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=102: 0ABE0 - 0ABEF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0 }, + /* idx=103: 0FB10 - 0FB1F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0 }, + /* idx=104: 0FE20 - 0FE2F */ + {230, 230, 230, 230, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=105: 101F0 - 101FF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0 }, + /* idx=106: 10A00 - 10A0F */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 230 }, + /* idx=107: 10A30 - 10A3F */ + {0, 0, 0, 0, 0, 0, 0, 0, 230, 1, 220, 0, 0, 0, 0, 9 }, + /* idx=108: 11040 - 1104F */ + {0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=109: 110B0 - 110BF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 7, 0, 0, 0, 0, 0 }, + /* idx=110: 1D160 - 1D16F */ + {0, 0, 0, 0, 0, 216, 216, 1, 1, 1, 0, 0, 0, 226, 216, 216 }, + /* idx=111: 1D170 - 1D17F */ + {216, 216, 216, 0, 0, 0, 0, 0, 0, 0, 0, 220, 220, 220, 220, 220 }, + /* idx=112: 1D180 - 1D18F */ + {220, 220, 220, 0, 0, 230, 230, 230, 230, 230, 220, 220, 0, 0, 0, 0 }, + /* idx=113: 1D1A0 - 1D1AF */ + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 230, 230, 230, 0, 0 }, + /* idx=114: 1D240 - 1D24F */ + {0, 0, 230, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +}; + +/* The index table to ccc_val[*][16] */ +static const unsigned char ccc_val_index[][16] = { + /* idx=0: XXX00 - XXXFF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=1: 00300 - 003FF */ + { 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=2: 00400 - 004FF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=3: 00500 - 005FF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,10,11,12, 0, 0, 0 }, + /* idx=4: 00600 - 006FF */ + { 0,13, 0, 0,14,15, 0,16, 0, 0, 0, 0, 0,17,18, 0 }, + /* idx=5: 00700 - 007FF */ + { 0,19, 0,20,21, 0, 0, 0, 0, 0, 0, 0, 0, 0,22,23 }, + /* idx=6: 00800 - 008FF */ + { 0,24,25, 0, 0,26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=7: 00900 - 009FF */ + { 0, 0, 0,27,28,29, 0, 0, 0, 0, 0,30,31, 0, 0, 0 }, + /* idx=8: 00A00 - 00AFF */ + { 0, 0, 0,32,33, 0, 0, 0, 0, 0, 0,34,35, 0, 0, 0 }, + /* idx=9: 00B00 - 00BFF */ + { 0, 0, 0,36,37, 0, 0, 0, 0, 0, 0, 0,38, 0, 0, 0 }, + /* idx=10: 00C00 - 00CFF */ + { 0, 0, 0, 0,39,40, 0, 0, 0, 0, 0,41,42, 0, 0, 0 }, + /* idx=11: 00D00 - 00DFF */ + { 0, 0, 0, 0,43, 0, 0, 0, 0, 0, 0, 0,44, 0, 0, 0 }, + /* idx=12: 00E00 - 00EFF */ + { 0, 0, 0,45,46, 0, 0, 0, 0, 0, 0,47,48, 0, 0, 0 }, + /* idx=13: 00F00 - 00FFF */ + { 0,49, 0,50, 0, 0, 0,51,52, 0, 0, 0,53, 0, 0, 0 }, + /* idx=14: 01000 - 010FF */ + { 0, 0, 0,54, 0, 0, 0, 0,55, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=15: 01300 - 013FF */ + { 0, 0, 0, 0, 0,56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=16: 01700 - 017FF */ + { 0,57, 0,58, 0, 0, 0, 0, 0, 0, 0, 0, 0,59, 0, 0 }, + /* idx=17: 01800 - 018FF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,60, 0, 0, 0, 0, 0 }, + /* idx=18: 01900 - 019FF */ + { 0, 0, 0,61, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=19: 01A00 - 01AFF */ + { 0,62, 0, 0, 0, 0,63,64, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=20: 01B00 - 01BFF */ + { 0, 0, 0,65,66, 0,67,68, 0, 0,69, 0, 0, 0,70,71 }, + /* idx=21: 01C00 - 01CFF */ + { 0, 0, 0,72, 0, 0, 0, 0, 0, 0, 0, 0, 0,73,74, 0 }, + /* idx=22: 01D00 - 01DFF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,75,76,77,78 }, + /* idx=23: 02000 - 020FF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,79,80,81 }, + /* idx=24: 02C00 - 02CFF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,82,83 }, + /* idx=25: 02D00 - 02DFF */ + { 0, 0, 0, 0, 0, 0, 0,84, 0, 0, 0, 0, 0, 0,85,86 }, + /* idx=26: 03000 - 030FF */ + { 0, 0,87, 0, 0, 0, 0, 0, 0,88, 0, 0, 0, 0, 0, 0 }, + /* idx=27: 0A600 - 0A6FF */ + { 0, 0, 0, 0, 0, 0,89,90, 0, 0, 0, 0, 0, 0, 0,91 }, + /* idx=28: 0A800 - 0A8FF */ + {92, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,93, 0,94,95 }, + /* idx=29: 0A900 - 0A9FF */ + { 0, 0,96, 0, 0,97, 0, 0, 0, 0, 0,98,99, 0, 0, 0 }, + /* idx=30: 0AA00 - 0AAFF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,100,101, 0, 0, 0 }, + /* idx=31: 0AB00 - 0ABFF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,102, 0 }, + /* idx=32: 0FB00 - 0FBFF */ + { 0,103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=33: 0FE00 - 0FEFF */ + { 0, 0,104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=34: 10100 - 101FF */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,105 }, + /* idx=35: 10A00 - 10AFF */ + {106, 0, 0,107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + /* idx=36: 11000 - 110FF */ + { 0, 0, 0, 0,108, 0, 0, 0, 0, 0, 0,109, 0, 0, 0, 0 }, + /* idx=37: 1D100 - 1D1FF */ + { 0, 0, 0, 0, 0, 0,110,111,112, 0,113, 0, 0, 0, 0, 0 }, + /* idx=38: 1D200 - 1D2FF */ + { 0, 0, 0, 0,114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +}; + +/* The index table to ccc_val_index[*][16] */ +static const unsigned char ccc_index[] = { + 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, 0, 0,15, 0, 0, 0,16, + 17,18,19,20,21,22, 0, 0,23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,24,25, 0, 0, + 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,27, 0, + 28,29,30,31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0, 0,33, 0, 0,34, 0, 0, 0, 0, 0, 0, + 0, 0,35, 0, 0, 0, 0, 0,36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0,37,38,}; + +#endif /* ARCHIVE_STRING_COMPOSITION_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c index cd5017b28..7d7d9713c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c +++ b/Utilities/cmlibarchive/libarchive/archive_string_sprintf.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_string_sprintf.c,v 1.10 2008/03/14 22:00:09 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_string_sprintf.c 189435 2009-03-06 05:14:55Z kientzle $"); /* * The use of printf()-family functions can be troublesome @@ -51,31 +51,34 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_string_sprintf.c,v 1.10 2008/03/1 static void append_uint(struct archive_string *as, uintmax_t d, unsigned base) { - static const char *digits = "0123456789abcdef"; - if (d >= base) - append_uint(as, d/base, base); - archive_strappend_char(as, digits[d % base]); + static const char *digits = "0123456789abcdef"; + if (d >= base) + append_uint(as, d/base, base); + archive_strappend_char(as, digits[d % base]); } static void append_int(struct archive_string *as, intmax_t d, unsigned base) { - if (d < 0) { - archive_strappend_char(as, '-'); - d = -d; - } - append_uint(as, d, base); + uintmax_t ud; + + if (d < 0) { + archive_strappend_char(as, '-'); + ud = (d == INTMAX_MIN) ? (uintmax_t)(INTMAX_MAX) + 1 : (uintmax_t)(-d); + } else + ud = d; + append_uint(as, ud, base); } void -__archive_string_sprintf(struct archive_string *as, const char *fmt, ...) +archive_string_sprintf(struct archive_string *as, const char *fmt, ...) { - va_list ap; + va_list ap; - va_start(ap, fmt); - archive_string_vsprintf(as, fmt, ap); - va_end(ap); + va_start(ap, fmt); + archive_string_vsprintf(as, fmt, ap); + va_end(ap); } /* @@ -83,82 +86,101 @@ __archive_string_sprintf(struct archive_string *as, const char *fmt, ...) * necessary. */ void -__archive_string_vsprintf(struct archive_string *as, const char *fmt, +archive_string_vsprintf(struct archive_string *as, const char *fmt, va_list ap) { - char long_flag; - intmax_t s; /* Signed integer temp. */ - uintmax_t u; /* Unsigned integer temp. */ - const char *p, *p2; - - if (__archive_string_ensure(as, 64) == NULL) - __archive_errx(1, "Out of memory"); - - if (fmt == NULL) { - as->s[0] = 0; - return; - } - - for (p = fmt; *p != '\0'; p++) { - const char *saved_p = p; - - if (*p != '%') { - archive_strappend_char(as, *p); - continue; - } - - p++; - - long_flag = '\0'; - switch(*p) { - case 'j': - long_flag = 'j'; - p++; - break; - case 'l': - long_flag = 'l'; - p++; - break; - } - - switch (*p) { - case '%': - __archive_strappend_char(as, '%'); - break; - case 'c': - s = va_arg(ap, int); - __archive_strappend_char(as, s); - break; - case 'd': - switch(long_flag) { - case 'j': s = va_arg(ap, intmax_t); break; - case 'l': s = va_arg(ap, long); break; - default: s = va_arg(ap, int); break; - } - append_int(as, s, 10); - break; - case 's': - p2 = va_arg(ap, char *); - archive_strcat(as, p2); - break; - case 'o': case 'u': case 'x': case 'X': - /* Common handling for unsigned integer formats. */ - switch(long_flag) { - case 'j': u = va_arg(ap, uintmax_t); break; - case 'l': u = va_arg(ap, unsigned long); break; - default: u = va_arg(ap, unsigned int); break; - } - /* Format it in the correct base. */ - switch (*p) { - case 'o': append_uint(as, u, 8); break; - case 'u': append_uint(as, u, 10); break; - default: append_uint(as, u, 16); break; - } - break; - default: - /* Rewind and print the initial '%' literally. */ - p = saved_p; - archive_strappend_char(as, *p); - } - } + char long_flag; + intmax_t s; /* Signed integer temp. */ + uintmax_t u; /* Unsigned integer temp. */ + const char *p, *p2; + const wchar_t *pw; + + if (archive_string_ensure(as, 64) == NULL) + __archive_errx(1, "Out of memory"); + + if (fmt == NULL) { + as->s[0] = 0; + return; + } + + for (p = fmt; *p != '\0'; p++) { + const char *saved_p = p; + + if (*p != '%') { + archive_strappend_char(as, *p); + continue; + } + + p++; + + long_flag = '\0'; + switch(*p) { + case 'j': + case 'l': + case 'z': + long_flag = *p; + p++; + break; + } + + switch (*p) { + case '%': + archive_strappend_char(as, '%'); + break; + case 'c': + s = va_arg(ap, int); + archive_strappend_char(as, s); + break; + case 'd': + switch(long_flag) { + case 'j': s = va_arg(ap, intmax_t); break; + case 'l': s = va_arg(ap, long); break; + case 'z': s = va_arg(ap, ssize_t); break; + default: s = va_arg(ap, int); break; + } + append_int(as, s, 10); + break; + case 's': + switch(long_flag) { + case 'l': + pw = va_arg(ap, wchar_t *); + if (pw == NULL) + pw = L"(null)"; + archive_string_append_from_wcs(as, pw, wcslen(pw)); + break; + default: + p2 = va_arg(ap, char *); + if (p2 == NULL) + p2 = "(null)"; + archive_strcat(as, p2); + break; + } + break; + case 'S': + pw = va_arg(ap, wchar_t *); + if (pw == NULL) + pw = L"(null)"; + archive_string_append_from_wcs(as, pw, wcslen(pw)); + break; + case 'o': case 'u': case 'x': case 'X': + /* Common handling for unsigned integer formats. */ + switch(long_flag) { + case 'j': u = va_arg(ap, uintmax_t); break; + case 'l': u = va_arg(ap, unsigned long); break; + case 'z': u = va_arg(ap, size_t); break; + default: u = va_arg(ap, unsigned int); break; + } + /* Format it in the correct base. */ + switch (*p) { + case 'o': append_uint(as, u, 8); break; + case 'u': append_uint(as, u, 10); break; + default: append_uint(as, u, 16); break; + } + break; + default: + /* Rewind and print the initial '%' literally. */ + p = saved_p; + archive_strappend_char(as, *p); + } + } } diff --git a/Utilities/cmlibarchive/libarchive/archive_util.3 b/Utilities/cmlibarchive/libarchive/archive_util.3 index 635e34b32..cd05d03f1 100644 --- a/Utilities/cmlibarchive/libarchive/archive_util.3 +++ b/Utilities/cmlibarchive/libarchive/archive_util.3 @@ -22,10 +22,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/archive_util.3,v 1.8 2008/03/10 14:44:40 jkoshy Exp $ +.\" $FreeBSD: head/lib/libarchive/archive_util.3 201098 2009-12-28 02:58:14Z kientzle $ .\" .Dd January 8, 2005 -.Dt archive_util 3 +.Dt ARCHIVE_UTIL 3 .Os .Sh NAME .Nm archive_clear_error , @@ -35,8 +35,12 @@ .Nm archive_errno , .Nm archive_error_string , .Nm archive_file_count , +.Nm archive_filter_code , +.Nm archive_filter_count , +.Nm archive_filter_name , .Nm archive_format , .Nm archive_format_name , +.Nm archive_position , .Nm archive_set_error .Nd libarchive utility functions .Sh SYNOPSIS @@ -56,9 +60,17 @@ .Ft int .Fn archive_file_count "struct archive *" .Ft int +.Fn archive_filter_code "struct archive *" "int" +.Ft int +.Fn archive_filter_count "struct archive *" "int" +.Ft const char * +.Fn archive_filter_name "struct archive *" "int" +.Ft int .Fn archive_format "struct archive *" .Ft const char * .Fn archive_format_name "struct archive *" +.Ft int64_t +.Fn archive_position "struct archive *" "int" .Ft void .Fo archive_set_error .Fa "struct archive *" @@ -77,17 +89,21 @@ library. Clears any error information left over from a previous call. Not generally used in client code. .It Fn archive_compression -Returns a numeric code indicating the current compression. -This value is set by -.Fn archive_read_open . +Synonym for +.Fn archive_filter_code(a, 0) . .It Fn archive_compression_name -Returns a text description of the current compression suitable for display. +Synonym for +.Fn archive_filter_name(a, 0) . .It Fn archive_copy_error Copies error information from one archive to another. .It Fn archive_errno Returns a numeric error code (see .Xr errno 2 ) indicating the reason for the most recent error return. +Note that this can not be reliably used to detect whether an +error has occurred. +It should be used only after another libarchive function +has returned an error status. .It Fn archive_error_string Returns a textual error message suitable for display. The error message here is usually more specific than that @@ -98,9 +114,45 @@ to .It Fn archive_file_count Returns a count of the number of files processed by this archive object. The count is incremented by calls to -.Xr archive_write_header +.Xr archive_write_header 3 or -.Xr archive_read_next_header . +.Xr archive_read_next_header 3 . +.It Fn archive_filter_code +Returns a numeric code identifying the indicated filter. +See +.Fn archive_filter_count +for details of the numbering. +.It Fn archive_filter_count +Returns the number of filters in the current pipeline. +For read archive handles, these filters are added automatically +by the automatic format detection. +For write archive handles, these filters are added by calls to the various +.Fn archive_write_add_filter_XXX +functions. +Filters in the resulting pipeline are numbered so that filter 0 +is the filter closest to the format handler. +As a convenience, functions that expect a filter number will +accept -1 as a synonym for the highest-numbered filter. +.Pp +For example, when reading a uuencoded gzipped tar archive, there +are three filters: +filter 0 is the gunzip filter, +filter 1 is the uudecode filter, +and filter 2 is the pseudo-filter that wraps the archive read functions. +In this case, requesting +.Fn archive_position(a, -1) +would be a synonym for +.Fn archive_position(a, 2) +which would return the number of bytes currently read from the archive, while +.Fn archive_position(a, 1) +would return the number of bytes after uudecoding, and +.Fn archive_position(a, 0) +would return the number of bytes after decompression. +.It Fn archive_filter_name +Returns a textual name identifying the indicated filter. +See +.Fn archive_filter_count +for details of the numbering. .It Fn archive_format Returns a numeric code indicating the format of the current archive entry. @@ -113,6 +165,16 @@ utilize GNU tar extensions and several entries that do not. These entries will have different format codes. .It Fn archive_format_name A textual description of the format of the current entry. +.It Fn archive_position +Returns the number of bytes read from or written to the indicated filter. +In particular, +.Fn archive_position(a, 0) +returns the number of bytes read or written by the format handler, while +.Fn archive_position(a, -1) +returns the number of bytes read or written to the archive. +See +.Fn archive_filter_count +for details of the numbering here. .It Fn archive_set_error Sets the numeric error code and error description that will be returned by diff --git a/Utilities/cmlibarchive/libarchive/archive_util.c b/Utilities/cmlibarchive/libarchive/archive_util.c index 142df01c8..e0852a3b5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_util.c +++ b/Utilities/cmlibarchive/libarchive/archive_util.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2009,2010 Michihiro NAKAJIMA * Copyright (c) 2003-2007 Tim Kientzle * All rights reserved. * @@ -25,110 +25,96 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_util.c,v 1.19 2008/10/21 12:10:30 des Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_util.c 201098 2009-12-28 02:58:14Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include #endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif #ifdef HAVE_STRING_H #include #endif +#if defined(HAVE_WINCRYPT_H) && !defined(__CYGWIN__) +#include +#endif #include "archive.h" #include "archive_private.h" #include "archive_string.h" -#if ARCHIVE_VERSION_NUMBER < 3000000 -/* These disappear in libarchive 3.0 */ -/* Deprecated. */ -int -archive_api_feature(void) -{ - return (ARCHIVE_API_FEATURE); -} - -/* Deprecated. */ -int -archive_api_version(void) -{ - return (ARCHIVE_API_VERSION); -} - -/* Deprecated synonym for archive_version_number() */ +/* Generic initialization of 'struct archive' objects. */ int -archive_version_stamp(void) -{ - return (archive_version_number()); -} - -/* Deprecated synonym for archive_version_string() */ -const char * -archive_version(void) +__archive_clean(struct archive *a) { - return (archive_version_string()); + archive_string_conversion_free(a); + return (ARCHIVE_OK); } -#endif int archive_version_number(void) { - return (ARCHIVE_VERSION_NUMBER); + return (ARCHIVE_VERSION_NUMBER); } const char * archive_version_string(void) { - return (ARCHIVE_VERSION_STRING); + return (ARCHIVE_VERSION_STRING); } int archive_errno(struct archive *a) { - return (a->archive_error_number); + return (a->archive_error_number); } const char * archive_error_string(struct archive *a) { - if (a->error != NULL && *a->error != '\0') - return (a->error); - else - return ("(Empty error message)"); + if (a->error != NULL && *a->error != '\0') + return (a->error); + else + return (NULL); } int archive_file_count(struct archive *a) { - return (a->file_count); + return (a->file_count); } int archive_format(struct archive *a) { - return (a->archive_format); + return (a->archive_format); } const char * archive_format_name(struct archive *a) { - return (a->archive_format_name); + return (a->archive_format_name); } int archive_compression(struct archive *a) { - return (a->compression_code); + return archive_filter_code(a, 0); } const char * archive_compression_name(struct archive *a) { - return (a->compression_name); + return archive_filter_name(a, 0); } @@ -138,7 +124,7 @@ archive_compression_name(struct archive *a) int64_t archive_position_compressed(struct archive *a) { - return (a->raw_position); + return archive_filter_bytes(a, -1); } /* @@ -147,243 +133,333 @@ archive_position_compressed(struct archive *a) int64_t archive_position_uncompressed(struct archive *a) { - return (a->file_position); + return archive_filter_bytes(a, 0); } void archive_clear_error(struct archive *a) { - archive_string_empty(&a->error_string); - a->error = NULL; + archive_string_empty(&a->error_string); + a->error = NULL; + a->archive_error_number = 0; } void archive_set_error(struct archive *a, int error_number, const char *fmt, ...) { - va_list ap; - - a->archive_error_number = error_number; - if (fmt == NULL) { - a->error = NULL; - return; - } - - va_start(ap, fmt); - archive_string_vsprintf(&(a->error_string), fmt, ap); - va_end(ap); - a->error = a->error_string.s; + va_list ap; + + a->archive_error_number = error_number; + if (fmt == NULL) { + a->error = NULL; + return; + } + + archive_string_empty(&(a->error_string)); + va_start(ap, fmt); + archive_string_vsprintf(&(a->error_string), fmt, ap); + va_end(ap); + a->error = a->error_string.s; } void archive_copy_error(struct archive *dest, struct archive *src) { - dest->archive_error_number = src->archive_error_number; + dest->archive_error_number = src->archive_error_number; - archive_string_copy(&dest->error_string, &src->error_string); - dest->error = dest->error_string.s; + archive_string_copy(&dest->error_string, &src->error_string); + dest->error = dest->error_string.s; } void __archive_errx(int retvalue, const char *msg) { - static const char *msg1 = "Fatal Internal Error in libarchive: "; - size_t s; - - s = write(2, msg1, strlen(msg1)); - s = write(2, msg, strlen(msg)); - s = write(2, "\n", 1); - (void)s; /* UNUSED */ - exit(retvalue); + static const char *msg1 = "Fatal Internal Error in libarchive: "; + size_t s; + + s = write(2, msg1, strlen(msg1)); + (void)s; /* UNUSED */ + s = write(2, msg, strlen(msg)); + (void)s; /* UNUSED */ + s = write(2, "\n", 1); + (void)s; /* UNUSED */ + exit(retvalue); } /* - * Parse option strings - * Detail of option format. - * - The option can accept: - * "opt-name", "!opt-name", "opt-name=value". - * - * - The option entries are separated by comma. - * e.g "compression=9,opt=XXX,opt-b=ZZZ" - * - * - The name of option string consist of '-' and alphabet - * but character '-' cannot be used for the first character. - * (Regular expression is [a-z][-a-z]+) - * - * - For a specfic format/filter, using the format name with ':'. - * e.g "zip:compression=9" - * (This "compression=9" option entry is for "zip" format only) - * - * If another entries follow it, those are not for - * the specfic format/filter. - * e.g handle "zip:compression=9,opt=XXX,opt-b=ZZZ" - * "zip" format/filter handler will get "compression=9" - * all format/filter handler will get "opt=XXX" - * all format/filter handler will get "opt-b=ZZZ" - * - * - Whitespace and tab are bypassed. - * + * Create a temporary file + */ +#if defined(_WIN32) && !defined(__CYGWIN__) + +/* + * Do not use Windows tmpfile() function. + * It will make a temporary file under the root directory + * and it'll cause permission error if a user who is + * non-Administrator creates temporary files. + * Also Windows version of mktemp family including _mktemp_s + * are not secure. */ int -__archive_parse_options(const char *p, const char *fn, int keysize, char *key, - int valsize, char *val) +__archive_mktemp(const char *tmpdir) +{ + static const wchar_t num[] = { + L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7', + L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F', + L'G', L'H', L'I', L'J', L'K', L'L', L'M', L'N', + L'O', L'P', L'Q', L'R', L'S', L'T', L'U', L'V', + L'W', L'X', L'Y', L'Z', L'a', L'b', L'c', L'd', + L'e', L'f', L'g', L'h', L'i', L'j', L'k', L'l', + L'm', L'n', L'o', L'p', L'q', L'r', L's', L't', + L'u', L'v', L'w', L'x', L'y', L'z' + }; + HCRYPTPROV hProv; + struct archive_wstring temp_name; + wchar_t *ws; + DWORD attr; + wchar_t *xp, *ep; + int fd; + + hProv = (HCRYPTPROV)NULL; + fd = -1; + ws = NULL; + archive_string_init(&temp_name); + + /* Get a temporary directory. */ + if (tmpdir == NULL) { + size_t l; + wchar_t *tmp; + + l = GetTempPathW(0, NULL); + if (l == 0) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + tmp = malloc(l*sizeof(wchar_t)); + if (tmp == NULL) { + errno = ENOMEM; + goto exit_tmpfile; + } + GetTempPathW(l, tmp); + archive_wstrcpy(&temp_name, tmp); + free(tmp); + } else { + archive_wstring_append_from_mbs(&temp_name, tmpdir, + strlen(tmpdir)); + if (temp_name.s[temp_name.length-1] != L'/') + archive_wstrappend_wchar(&temp_name, L'/'); + } + + /* Check if temp_name is a directory. */ + attr = GetFileAttributesW(temp_name.s); + if (attr == (DWORD)-1) { + if (GetLastError() != ERROR_FILE_NOT_FOUND) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + ws = __la_win_permissive_name_w(temp_name.s); + if (ws == NULL) { + errno = EINVAL; + goto exit_tmpfile; + } + attr = GetFileAttributesW(ws); + if (attr == (DWORD)-1) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + } + if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { + errno = ENOTDIR; + goto exit_tmpfile; + } + + /* + * Create a temporary file. + */ + archive_wstrcat(&temp_name, L"libarchive_"); + xp = temp_name.s + archive_strlen(&temp_name); + archive_wstrcat(&temp_name, L"XXXXXXXXXX"); + ep = temp_name.s + archive_strlen(&temp_name); + + if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + + for (;;) { + wchar_t *p; + HANDLE h; + + /* Generate a random file name through CryptGenRandom(). */ + p = xp; + if (!CryptGenRandom(hProv, (ep - p)*sizeof(wchar_t), (BYTE*)p)) { + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + for (; p < ep; p++) + *p = num[((DWORD)*p) % (sizeof(num)/sizeof(num[0]))]; + + free(ws); + ws = __la_win_permissive_name_w(temp_name.s); + if (ws == NULL) { + errno = EINVAL; + goto exit_tmpfile; + } + /* Specifies FILE_FLAG_DELETE_ON_CLOSE flag is to + * delete this temporary file immediately when this + * file closed. */ + h = CreateFileW(ws, + GENERIC_READ | GENERIC_WRITE | DELETE, + 0,/* Not share */ + NULL, + CREATE_NEW,/* Create a new file only */ + FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, + NULL); + if (h == INVALID_HANDLE_VALUE) { + /* The same file already exists. retry with + * a new filename. */ + if (GetLastError() == ERROR_FILE_EXISTS) + continue; + /* Otherwise, fail creation temporary file. */ + la_dosmaperr(GetLastError()); + goto exit_tmpfile; + } + fd = _open_osfhandle((intptr_t)h, _O_BINARY | _O_RDWR); + if (fd == -1) { + CloseHandle(h); + goto exit_tmpfile; + } else + break;/* success! */ + } +exit_tmpfile: + if (hProv != (HCRYPTPROV)NULL) + CryptReleaseContext(hProv, 0); + free(ws); + archive_wstring_free(&temp_name); + return (fd); +} + +#else + +static int +get_tempdir(struct archive_string *temppath) { - const char *p_org; - int apply; - int kidx, vidx; - int negative; - enum { - /* Requested for initialization. */ - INIT, - /* Finding format/filter-name and option-name. */ - F_BOTH, - /* Finding option-name only. - * (already detected format/filter-name) */ - F_NAME, - /* Getting option-value. */ - G_VALUE, - } state; - - p_org = p; - state = INIT; - kidx = vidx = negative = 0; - apply = 1; - while (*p) { - switch (state) { - case INIT: - kidx = vidx = 0; - negative = 0; - apply = 1; - state = F_BOTH; - break; - case F_BOTH: - case F_NAME: - if ((*p >= 'a' && *p <= 'z') || - (*p >= '0' && *p <= '9') || *p == '-') { - if (kidx == 0 && !(*p >= 'a' && *p <= 'z')) - /* Illegal sequence. */ - return (-1); - if (kidx >= keysize -1) - /* Too many characters. */ - return (-1); - key[kidx++] = *p++; - } else if (*p == '!') { - if (kidx != 0) - /* Illegal sequence. */ - return (-1); - negative = 1; - ++p; - } else if (*p == ',') { - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (!negative) - val[vidx++] = '1'; - /* We have got boolean option data. */ - ++p; - if (apply) - goto complete; - else - /* This option does not apply to the - * format which the fn variable - * indicate. */ - state = INIT; - } else if (*p == ':') { - /* obuf data is format name */ - if (state == F_NAME) - /* We already found it. */ - return (-1); - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (negative) - /* We cannot accept "!format-name:". */ - return (-1); - key[kidx] = '\0'; - if (strcmp(fn, key) != 0) - /* This option does not apply to the - * format which the fn variable - * indicate. */ - apply = 0; - kidx = 0; - ++p; - state = F_NAME; - } else if (*p == '=') { - if (kidx == 0) - /* Illegal sequence. */ - return (-1); - if (negative) - /* We cannot accept "!opt-name=value". */ - return (-1); - ++p; - state = G_VALUE; - } else if (*p == ' ') { - /* Pass the space character */ - ++p; - } else { - /* Illegal character. */ - return (-1); - } - break; - case G_VALUE: - if (*p == ',') { - if (vidx == 0) - /* Illegal sequence. */ - return (-1); - /* We have got option data. */ - ++p; - if (apply) - goto complete; - else - /* This option does not apply to the - * format which the fn variable - * indicate. */ - state = INIT; - } else if (*p == ' ') { - /* Pass the space character */ - ++p; - } else { - if (vidx >= valsize -1) - /* Too many characters. */ - return (-1); - val[vidx++] = *p++; - } - break; - } - } - - switch (state) { - case F_BOTH: - case F_NAME: - if (kidx != 0) { - if (!negative) - val[vidx++] = '1'; - /* We have got boolean option. */ - if (apply) - /* This option apply to the format which the - * fn variable indicate. */ - goto complete; - } - break; - case G_VALUE: - if (vidx == 0) - /* Illegal sequence. */ - return (-1); - /* We have got option value. */ - if (apply) - /* This option apply to the format which the fn - * variable indicate. */ - goto complete; - break; - case INIT:/* nothing */ - break; - } - - /* End of Option string. */ - return (0); - -complete: - key[kidx] = '\0'; - val[vidx] = '\0'; - /* Return a size which we've consumed for detecting option */ - return ((int)(p - p_org)); + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) +#ifdef _PATH_TMP + tmp = _PATH_TMP; +#else + tmp = "/tmp"; +#endif + archive_strcpy(temppath, tmp); + if (temppath->s[temppath->length-1] != '/') + archive_strappend_char(temppath, '/'); + return (ARCHIVE_OK); } + +#if defined(HAVE_MKSTEMP) + +/* + * We can use mkstemp(). + */ + +int +__archive_mktemp(const char *tmpdir) +{ + struct archive_string temp_name; + int fd = -1; + + archive_string_init(&temp_name); + if (tmpdir == NULL) { + if (get_tempdir(&temp_name) != ARCHIVE_OK) + goto exit_tmpfile; + } else { + archive_strcpy(&temp_name, tmpdir); + if (temp_name.s[temp_name.length-1] != '/') + archive_strappend_char(&temp_name, '/'); + } + archive_strcat(&temp_name, "libarchive_XXXXXX"); + fd = mkstemp(temp_name.s); + if (fd < 0) + goto exit_tmpfile; + unlink(temp_name.s); +exit_tmpfile: + archive_string_free(&temp_name); + return (fd); +} + +#else + +/* + * We use a private routine. + */ + +int +__archive_mktemp(const char *tmpdir) +{ + static const char num[] = { + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', + 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', + 'u', 'v', 'w', 'x', 'y', 'z' + }; + struct archive_string temp_name; + struct stat st; + int fd; + char *tp, *ep; + unsigned seed; + + fd = -1; + archive_string_init(&temp_name); + if (tmpdir == NULL) { + if (get_tempdir(&temp_name) != ARCHIVE_OK) + goto exit_tmpfile; + } else + archive_strcpy(&temp_name, tmpdir); + if (temp_name.s[temp_name.length-1] == '/') { + temp_name.s[temp_name.length-1] = '\0'; + temp_name.length --; + } + if (stat(temp_name.s, &st) < 0) + goto exit_tmpfile; + if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + goto exit_tmpfile; + } + archive_strcat(&temp_name, "/libarchive_"); + tp = temp_name.s + archive_strlen(&temp_name); + archive_strcat(&temp_name, "XXXXXXXXXX"); + ep = temp_name.s + archive_strlen(&temp_name); + + fd = open("/dev/random", O_RDONLY); + if (fd < 0) + seed = time(NULL); + else { + if (read(fd, &seed, sizeof(seed)) < 0) + seed = time(NULL); + close(fd); + } + do { + char *p; + + p = tp; + while (p < ep) + *p++ = num[((unsigned)rand_r(&seed)) % sizeof(num)]; + fd = open(temp_name.s, O_CREAT | O_EXCL | O_RDWR, 0600); + } while (fd < 0 && errno == EEXIST); + if (fd < 0) + goto exit_tmpfile; + unlink(temp_name.s); +exit_tmpfile: + archive_string_free(&temp_name); + return (fd); +} + +#endif /* HAVE_MKSTEMP */ +#endif /* !_WIN32 || __CYGWIN__ */ diff --git a/Utilities/cmlibarchive/libarchive/archive_virtual.c b/Utilities/cmlibarchive/libarchive/archive_virtual.c index c59213689..752dc17c2 100644 --- a/Utilities/cmlibarchive/libarchive/archive_virtual.c +++ b/Utilities/cmlibarchive/libarchive/archive_virtual.c @@ -24,71 +24,124 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_virtual.c,v 1.1 2007/03/03 07:37:36 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_virtual.c 201098 2009-12-28 02:58:14Z kientzle $"); #include "archive.h" #include "archive_entry.h" #include "archive_private.h" +int +archive_filter_code(struct archive *a, int n) +{ + return ((a->vtable->archive_filter_code)(a, n)); +} + +int +archive_filter_count(struct archive *a) +{ + return ((a->vtable->archive_filter_count)(a)); +} + +const char * +archive_filter_name(struct archive *a, int n) +{ + return ((a->vtable->archive_filter_name)(a, n)); +} + +int64_t +archive_filter_bytes(struct archive *a, int n) +{ + return ((a->vtable->archive_filter_bytes)(a, n)); +} + int archive_write_close(struct archive *a) { - return ((a->vtable->archive_close)(a)); + return ((a->vtable->archive_close)(a)); } int archive_read_close(struct archive *a) { - return ((a->vtable->archive_close)(a)); + return ((a->vtable->archive_close)(a)); } -#if ARCHIVE_API_VERSION > 1 int -archive_write_finish(struct archive *a) +archive_write_free(struct archive *a) { - return ((a->vtable->archive_finish)(a)); + return ((a->vtable->archive_free)(a)); } -#else -/* Temporarily allow library to compile with either 1.x or 2.0 API. */ -void + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* For backwards compatibility; will be removed with libarchive 4.0. */ +int archive_write_finish(struct archive *a) { - (void)(a->vtable->archive_finish)(a); + return ((a->vtable->archive_free)(a)); } #endif +int +archive_read_free(struct archive *a) +{ + return ((a->vtable->archive_free)(a)); +} + +#if ARCHIVE_VERSION_NUMBER < 4000000 +/* For backwards compatibility; will be removed with libarchive 4.0. */ int archive_read_finish(struct archive *a) { - return ((a->vtable->archive_finish)(a)); + return ((a->vtable->archive_free)(a)); } +#endif int archive_write_header(struct archive *a, struct archive_entry *entry) { - ++a->file_count; - return ((a->vtable->archive_write_header)(a, entry)); + ++a->file_count; + return ((a->vtable->archive_write_header)(a, entry)); } int archive_write_finish_entry(struct archive *a) { - return ((a->vtable->archive_write_finish_entry)(a)); + return ((a->vtable->archive_write_finish_entry)(a)); } -#if ARCHIVE_API_VERSION > 1 ssize_t -#else -/* Temporarily allow library to compile with either 1.x or 2.0 API. */ -int -#endif archive_write_data(struct archive *a, const void *buff, size_t s) { - return ((a->vtable->archive_write_data)(a, buff, s)); + return ((a->vtable->archive_write_data)(a, buff, s)); } ssize_t -archive_write_data_block(struct archive *a, const void *buff, size_t s, off_t o) +archive_write_data_block(struct archive *a, const void *buff, size_t s, int64_t o) +{ + if (a->vtable->archive_write_data_block == NULL) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "archive_write_data_block not supported"); + a->state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + return ((a->vtable->archive_write_data_block)(a, buff, s, o)); +} + +int +archive_read_next_header(struct archive *a, struct archive_entry **entry) +{ + return ((a->vtable->archive_read_next_header)(a, entry)); +} + +int +archive_read_next_header2(struct archive *a, struct archive_entry *entry) +{ + return ((a->vtable->archive_read_next_header2)(a, entry)); +} + +int +archive_read_data_block(struct archive *a, + const void **buff, size_t *s, int64_t *o) { - return ((a->vtable->archive_write_data_block)(a, buff, s, o)); + return ((a->vtable->archive_read_data_block)(a, buff, s, o)); } diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.c b/Utilities/cmlibarchive/libarchive/archive_windows.c index e194d7704..8f5d566a5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_windows.c +++ b/Utilities/cmlibarchive/libarchive/archive_windows.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2009-2011 Michihiro NAKAJIMA * Copyright (c) 2003-2007 Kees Zeelenberg * All rights reserved. * @@ -51,56 +51,54 @@ #include #include #include -#ifndef __BORLANDC__ +#ifdef HAVE_SYS_UTIME_H #include #endif #include +#include #include #include #include #include -#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER <= 1300) -# define EPOC_TIME (116444736000000000UI64) -#else -# define EPOC_TIME (116444736000000000ULL) -#endif +#include + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) -#if defined(_MSC_VER) && _MSC_VER < 1300 -/* VS 6 does not provide SetFilePointerEx, so define it here. */ -static BOOL SetFilePointerEx(HANDLE hFile, - LARGE_INTEGER liDistanceToMove, - PLARGE_INTEGER lpNewFilePointer, - DWORD dwMoveMethod) +#if defined(__LA_LSEEK_NEEDED) +static BOOL SetFilePointerEx_perso(HANDLE hFile, + LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, + DWORD dwMoveMethod) { - LARGE_INTEGER li; - li.QuadPart = liDistanceToMove.QuadPart; - li.LowPart = SetFilePointer(hFile, li.LowPart, &li.HighPart, dwMoveMethod); - if(lpNewFilePointer) { lpNewFilePointer->QuadPart = li.QuadPart; } - return li.LowPart != -1 || GetLastError() == NO_ERROR; + LARGE_INTEGER li; + li.QuadPart = liDistanceToMove.QuadPart; + li.LowPart = SetFilePointer( + hFile, li.LowPart, &li.HighPart, dwMoveMethod); + if(lpNewFilePointer) { + lpNewFilePointer->QuadPart = li.QuadPart; + } + return li.LowPart != -1 || GetLastError() == NO_ERROR; } #endif struct ustat { - int64_t st_atime; - uint32_t st_atime_nsec; - int64_t st_ctime; - uint32_t st_ctime_nsec; - int64_t st_mtime; - uint32_t st_mtime_nsec; - gid_t st_gid; - /* 64bits ino */ - int64_t st_ino; - mode_t st_mode; - uint32_t st_nlink; - uint64_t st_size; - uid_t st_uid; - dev_t st_dev; - dev_t st_rdev; + int64_t st_atime; + uint32_t st_atime_nsec; + int64_t st_ctime; + uint32_t st_ctime_nsec; + int64_t st_mtime; + uint32_t st_mtime_nsec; + gid_t st_gid; + /* 64bits ino */ + int64_t st_ino; + mode_t st_mode; + uint32_t st_nlink; + uint64_t st_size; + uid_t st_uid; + dev_t st_dev; + dev_t st_rdev; }; -/* Local replacement for undocumented Windows CRT function. */ -static void la_dosmaperr(unsigned long e); - /* Transform 64-bits ino into 32-bits by hashing. * You do not forget that really unique number size is 64-bits. */ @@ -108,10 +106,10 @@ static void la_dosmaperr(unsigned long e); static __inline ino_t getino(struct ustat *ub) { - ULARGE_INTEGER ino64; - ino64.QuadPart = ub->st_ino; - /* I don't know this hashing is correct way */ - return (ino64.LowPart ^ (ino64.LowPart >> INOSIZE)); + ULARGE_INTEGER ino64; + ino64.QuadPart = ub->st_ino; + /* I don't know this hashing is correct way */ + return (ino64.LowPart ^ (ino64.LowPart >> INOSIZE)); } /* @@ -120,657 +118,332 @@ getino(struct ustat *ub) * characters. * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx */ -static wchar_t * -permissive_name(const char *name) -{ - wchar_t *wn, *wnp; - wchar_t *ws, *wsp; - size_t l, len, slen; - int unc; - - len = strlen(name); - wn = malloc((len + 1) * sizeof(wchar_t)); - if (wn == NULL) - return (NULL); - l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); - if (l == 0) { - free(wn); - return (NULL); - } - wn[l] = L'\0'; - - /* Get a full path names */ - l = GetFullPathNameW(wn, 0, NULL, NULL); - if (l == 0) { - free(wn); - return (NULL); - } - wnp = malloc(l * sizeof(wchar_t)); - if (wnp == NULL) { - free(wn); - return (NULL); - } - len = GetFullPathNameW(wn, l, wnp, NULL); - free(wn); - wn = wnp; - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'?' && wnp[3] == L'\\') - /* We have already permissive names. */ - return (wn); - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'.' && wnp[3] == L'\\') { - /* Device names */ - if (((wnp[4] >= L'a' && wnp[4] <= L'z') || - (wnp[4] >= L'A' && wnp[4] <= L'Z')) && - wnp[5] == L':' && wnp[6] == L'\\') - wnp[2] = L'?';/* Not device names. */ - return (wn); - } - - unc = 0; - if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { - wchar_t *p = &wnp[2]; - - /* Skip server-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\') { - wchar_t *rp = ++p; - /* Skip share-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\' && p != rp) { - /* Now, match patterns such as - * "\\server-name\share-name\" */ - wnp += 2; - len -= 2; - unc = 1; - } - } - } - - slen = 4 + (unc * 4) + len + 1; - ws = wsp = malloc(slen * sizeof(wchar_t)); - if (ws == NULL) { - free(wn); - return (NULL); - } - /* prepend "\\?\" */ - wcsncpy(wsp, L"\\\\?\\", 4); - wsp += 4; - slen -= 4; - if (unc) { - /* append "UNC\" ---> "\\?\UNC\" */ - wcsncpy(wsp, L"UNC\\", 4); - wsp += 4; - slen -= 4; - } - wcsncpy(wsp, wnp, slen); - wsp[slen - 1] = L'\0'; /* Ensure null termination. */ - free(wn); - return (ws); +wchar_t * +__la_win_permissive_name(const char *name) +{ + wchar_t *wn; + wchar_t *ws; + size_t ll; + + ll = strlen(name); + wn = malloc((ll + 1) * sizeof(wchar_t)); + if (wn == NULL) + return (NULL); + ll = mbstowcs(wn, name, ll); + if (ll == (size_t)-1) { + free(wn); + return (NULL); + } + wn[ll] = L'\0'; + ws = __la_win_permissive_name_w(wn); + free(wn); + return (ws); +} + +wchar_t * +__la_win_permissive_name_w(const wchar_t *wname) +{ + wchar_t *wn, *wnp; + wchar_t *ws, *wsp; + DWORD l, len, slen; + int unc; + + /* Get a full-pathname. */ + l = GetFullPathNameW(wname, 0, NULL, NULL); + if (l == 0) + return (NULL); + /* NOTE: GetFullPathNameW has a bug that if the length of the file + * name is just one that return imcomplete buffer size. Thus, we + * have to add three to the size to allocate a sufficient buffer + * size for the full-pathname of the file name. */ + l += 3; + wnp = malloc(l * sizeof(wchar_t)); + if (wnp == NULL) + return (NULL); + len = GetFullPathNameW(wname, l, wnp, NULL); + wn = wnp; + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'?' && wnp[3] == L'\\') + /* We have already a permissive name. */ + return (wn); + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'.' && wnp[3] == L'\\') { + /* This is a device name */ + if (((wnp[4] >= L'a' && wnp[4] <= L'z') || + (wnp[4] >= L'A' && wnp[4] <= L'Z')) && + wnp[5] == L':' && wnp[6] == L'\\') + wnp[2] = L'?';/* Not device name. */ + return (wn); + } + + unc = 0; + if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { + wchar_t *p = &wnp[2]; + + /* Skip server-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\') { + wchar_t *rp = ++p; + /* Skip share-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\' && p != rp) { + /* Now, match patterns such as + * "\\server-name\share-name\" */ + wnp += 2; + len -= 2; + unc = 1; + } + } + } + + slen = 4 + (unc * 4) + len + 1; + ws = wsp = malloc(slen * sizeof(wchar_t)); + if (ws == NULL) { + free(wn); + return (NULL); + } + /* prepend "\\?\" */ + wcsncpy(wsp, L"\\\\?\\", 4); + wsp += 4; + slen -= 4; + if (unc) { + /* append "UNC\" ---> "\\?\UNC\" */ + wcsncpy(wsp, L"UNC\\", 4); + wsp += 4; + slen -= 4; + } + wcsncpy(wsp, wnp, slen); + wsp[slen - 1] = L'\0'; /* Ensure null termination. */ + free(wn); + return (ws); } +/* + * Create a file handle. + * This can exceed MAX_PATH limitation. + */ static HANDLE la_CreateFile(const char *path, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) { - wchar_t *wpath; - HANDLE handle; - - handle = CreateFileA(path, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); - if (handle != INVALID_HANDLE_VALUE) - return (handle); - if (GetLastError() != ERROR_PATH_NOT_FOUND) - return (handle); - wpath = permissive_name(path); - if (wpath == NULL) - return (handle); - handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode, - lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, - hTemplateFile); - free(wpath); - return (handle); -} - -static void * -la_GetFunctionKernel32(const char *name) -{ - static HINSTANCE lib; - static int set; - if (!set) { - set = 1; - lib = LoadLibrary("kernel32.dll"); - } - if (lib == NULL) { - fprintf(stderr, "Can't load kernel32.dll?!\n"); - exit(1); - } - return (void *)GetProcAddress(lib, name); -} - -static int -la_CreateHardLinkW(wchar_t *linkname, wchar_t *target) -{ - static BOOLEAN (WINAPI *f)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = la_GetFunctionKernel32("CreateHardLinkW"); - } - return f == NULL ? 0 : (*f)(linkname, target, NULL); -} - - -/* Make a link to src called dst. */ -static int -__link(const char *src, const char *dst, int sym) -{ - wchar_t *wsrc, *wdst; - int res, retval; - DWORD attr; - - if (src == NULL || dst == NULL) { - set_errno (EINVAL); - return -1; - } - - wsrc = permissive_name(src); - wdst = permissive_name(dst); - if (wsrc == NULL || wdst == NULL) { - free(wsrc); - free(wdst); - set_errno (EINVAL); - return -1; - } - - if ((attr = GetFileAttributesW(wsrc)) != -1) { - res = la_CreateHardLinkW(wdst, wsrc); - } else { - /* wsrc does not exist; try src prepend it with the dirname of wdst */ - wchar_t *wnewsrc, *slash; - int i, n, slen, wlen; - - if (strlen(src) >= 3 && isalpha((unsigned char)src[0]) && - src[1] == ':' && src[2] == '\\') { - /* Original src name is already full-path */ - retval = -1; - goto exit; - } - if (src[0] == '\\') { - /* Original src name is almost full-path - * (maybe src name is without drive) */ - retval = -1; - goto exit; - } - - wnewsrc = malloc ((wcslen(wsrc) + wcslen(wdst) + 1) * sizeof(wchar_t)); - if (wnewsrc == NULL) { - errno = ENOMEM; - retval = -1; - goto exit; - } - /* Copying a dirname of wdst */ - wcscpy(wnewsrc, wdst); - slash = wcsrchr(wnewsrc, L'\\'); - if (slash != NULL) - *++slash = L'\0'; - else - wcscat(wnewsrc, L"\\"); - /* Converting multi-byte src to wide-char src */ - wlen = wcslen(wsrc); - slen = strlen(src); - n = MultiByteToWideChar(CP_ACP, 0, src, slen, wsrc, slen); - if (n == 0) { - free (wnewsrc); - retval = -1; - goto exit; - } - for (i = 0; i < n; i++) - if (wsrc[i] == L'/') - wsrc[i] = L'\\'; - wcsncat(wnewsrc, wsrc, n); - /* Check again */ - attr = GetFileAttributesW(wnewsrc); - if (attr == -1 || (attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { - if (attr == -1) - la_dosmaperr(GetLastError()); - else - errno = EPERM; - free (wnewsrc); - retval = -1; - goto exit; - } - res = la_CreateHardLinkW(wdst, wnewsrc); - free (wnewsrc); - } - if (res == 0) { - la_dosmaperr(GetLastError()); - retval = -1; - } else - retval = 0; -exit: - free(wsrc); - free(wdst); - return (retval); -} - -/* Make a hard link to src called dst. */ -int -__la_link(const char *src, const char *dst) -{ - return __link (src, dst, 0); -} - -int -__la_ftruncate(int fd, off_t length) -{ - LARGE_INTEGER distance; - HANDLE handle; - - if (fd < 0) { - errno = EBADF; - return (-1); - } - handle = (HANDLE)_get_osfhandle(fd); - if (GetFileType(handle) != FILE_TYPE_DISK) { - errno = EBADF; - return (-1); - } - distance.QuadPart = length; - if (!SetFilePointerEx(handle, distance, NULL, FILE_BEGIN)) { - la_dosmaperr(GetLastError()); - return (-1); - } - if (!SetEndOfFile(handle)) { - la_dosmaperr(GetLastError()); - return (-1); - } - return (0); -} -#define WINTIME(sec, usec) ((Int32x32To64(sec, 10000000) + EPOC_TIME) + (usec * 10)) -static int -__hutimes(HANDLE handle, const struct __timeval *times) -{ - ULARGE_INTEGER wintm; - FILETIME fatime, fmtime; - - wintm.QuadPart = WINTIME(times[0].tv_sec, times[0].tv_usec); - fatime.dwLowDateTime = wintm.LowPart; - fatime.dwHighDateTime = wintm.HighPart; - wintm.QuadPart = WINTIME(times[1].tv_sec, times[1].tv_usec); - fmtime.dwLowDateTime = wintm.LowPart; - fmtime.dwHighDateTime = wintm.HighPart; - if (SetFileTime(handle, NULL, &fatime, &fmtime) == 0) { - errno = EINVAL; - return (-1); - } - return (0); -} - -int -__la_futimes(int fd, const struct __timeval *times) -{ - - return (__hutimes((HANDLE)_get_osfhandle(fd), times)); -} - -int -__la_utimes(const char *name, const struct __timeval *times) -{ - int ret; - HANDLE handle; - - handle = la_CreateFile(name, GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (handle == INVALID_HANDLE_VALUE) { - la_dosmaperr(GetLastError()); - return (-1); - } - ret = __hutimes(handle, times); - CloseHandle(handle); - return (ret); -} - -int -__la_chdir(const char *path) -{ - wchar_t *ws; - int r; - - r = SetCurrentDirectoryA(path); - if (r == 0) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) { - la_dosmaperr(GetLastError()); - return (-1); - } - } else - return (0); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = SetCurrentDirectoryW(ws); - free(ws); - if (r == 0) { - la_dosmaperr(GetLastError()); - return (-1); - } - return (0); -} - -int -__la_chmod(const char *path, mode_t mode) -{ - wchar_t *ws; - int r; - - r = _chmod(path, mode); - if (r >= 0 || errno != ENOENT) - return (r); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = _wchmod(ws, mode); - free(ws); - return (r); -} - -/* - * This fcntl is limited implemention. - */ -int -__la_fcntl(int fd, int cmd, int val) -{ - HANDLE handle; - - handle = (HANDLE)_get_osfhandle(fd); - if (GetFileType(handle) == FILE_TYPE_PIPE) { - if (cmd == F_SETFL && val == 0) { - DWORD mode = PIPE_WAIT; - if (SetNamedPipeHandleState( - handle, &mode, NULL, NULL) != 0) - return (0); - } - } - errno = EINVAL; - return (-1); -} - + wchar_t *wpath; + HANDLE handle; + + handle = CreateFileA(path, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + if (handle != INVALID_HANDLE_VALUE) + return (handle); + if (GetLastError() != ERROR_PATH_NOT_FOUND) + return (handle); + wpath = __la_win_permissive_name(path); + if (wpath == NULL) + return (handle); + handle = CreateFileW(wpath, dwDesiredAccess, dwShareMode, + lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, + hTemplateFile); + free(wpath); + return (handle); +} + +#if defined(__LA_LSEEK_NEEDED) __int64 __la_lseek(int fd, __int64 offset, int whence) { - LARGE_INTEGER distance; - LARGE_INTEGER newpointer; - HANDLE handle; - - if (fd < 0) { - errno = EBADF; - return (-1); - } - handle = (HANDLE)_get_osfhandle(fd); - if (GetFileType(handle) != FILE_TYPE_DISK) { - errno = EBADF; - return (-1); - } - distance.QuadPart = offset; - if (!SetFilePointerEx(handle, distance, &newpointer, whence)) { - DWORD lasterr; - - lasterr = GetLastError(); - if (lasterr == ERROR_BROKEN_PIPE) - return (0); - if (lasterr == ERROR_ACCESS_DENIED) - errno = EBADF; - else - la_dosmaperr(lasterr); - return (-1); - } - return (newpointer.QuadPart); -} - -int -__la_mkdir(const char *path, mode_t mode) -{ - wchar_t *ws; - int r; - - (void)mode;/* UNUSED */ - r = CreateDirectoryA(path, NULL); - if (r == 0) { - DWORD lasterr = GetLastError(); - if (lasterr != ERROR_FILENAME_EXCED_RANGE && - lasterr != ERROR_PATH_NOT_FOUND) { - la_dosmaperr(GetLastError()); - return (-1); - } - } else - return (0); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = CreateDirectoryW(ws, NULL); - free(ws); - if (r == 0) { - la_dosmaperr(GetLastError()); - return (-1); - } - return (0); -} - -/* Windows' mbstowcs is differrent error handling from other unix mbstowcs. - * That one is using MultiByteToWideChar function with MB_PRECOMPOSED and - * MB_ERR_INVALID_CHARS flags. - * This implements for only to pass libarchive_test. - */ -size_t -__la_mbstowcs(wchar_t *wcstr, const char *mbstr, size_t nwchars) -{ - - return (MultiByteToWideChar(CP_THREAD_ACP, MB_ERR_INVALID_CHARS, - mbstr, (int)strlen(mbstr), wcstr, - (int)nwchars)); + LARGE_INTEGER distance; + LARGE_INTEGER newpointer; + HANDLE handle; + + if (fd < 0) { + errno = EBADF; + return (-1); + } + handle = (HANDLE)_get_osfhandle(fd); + if (GetFileType(handle) != FILE_TYPE_DISK) { + errno = EBADF; + return (-1); + } + distance.QuadPart = offset; + if (!SetFilePointerEx_perso(handle, distance, &newpointer, whence)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_BROKEN_PIPE) + return (0); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return (newpointer.QuadPart); } +#endif +/* This can exceed MAX_PATH limitation. */ int __la_open(const char *path, int flags, ...) { - va_list ap; - wchar_t *ws; - int r, pmode; - DWORD attr; - - va_start(ap, flags); - pmode = va_arg(ap, int); - va_end(ap); - ws = NULL; - if ((flags & ~O_BINARY) == O_RDONLY) { - /* - * When we open a directory, _open function returns - * "Permission denied" error. - */ - attr = GetFileAttributesA(path); - if (attr == -1 && GetLastError() == ERROR_PATH_NOT_FOUND) { - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - attr = GetFileAttributesW(ws); - } - if (attr == -1) { - la_dosmaperr(GetLastError()); - free(ws); - return (-1); - } - if (attr & FILE_ATTRIBUTE_DIRECTORY) { - HANDLE handle; - - if (ws != NULL) - handle = CreateFileW(ws, 0, 0, NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | - FILE_ATTRIBUTE_READONLY, - NULL); - else - handle = CreateFileA(path, 0, 0, NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | - FILE_ATTRIBUTE_READONLY, - NULL); - free(ws); - if (handle == INVALID_HANDLE_VALUE) { - la_dosmaperr(GetLastError()); - return (-1); - } - r = _open_osfhandle((intptr_t)handle, _O_RDONLY); - return (r); - } - } - if (ws == NULL) { -#ifdef __BORLANDC__ - r = _open(path, flags); + va_list ap; + wchar_t *ws; + int r, pmode; + DWORD attr; + + va_start(ap, flags); + pmode = va_arg(ap, int); + va_end(ap); + ws = NULL; + if ((flags & ~O_BINARY) == O_RDONLY) { + /* + * When we open a directory, _open function returns + * "Permission denied" error. + */ + attr = GetFileAttributesA(path); + if (attr == (DWORD)-1 && GetLastError() == ERROR_PATH_NOT_FOUND) { + ws = __la_win_permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + attr = GetFileAttributesW(ws); + } + if (attr == (DWORD)-1) { + la_dosmaperr(GetLastError()); + free(ws); + return (-1); + } + if (attr & FILE_ATTRIBUTE_DIRECTORY) { + HANDLE handle; + + if (ws != NULL) + handle = CreateFileW(ws, 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | + FILE_ATTRIBUTE_READONLY, + NULL); + else + handle = CreateFileA(path, 0, 0, NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | + FILE_ATTRIBUTE_READONLY, + NULL); + free(ws); + if (handle == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + r = _open_osfhandle((intptr_t)handle, _O_RDONLY); + return (r); + } + } + if (ws == NULL) { +#if defined(__BORLANDC__) + /* Borland has no mode argument. + TODO: Fix mode of new file. */ + r = _open(path, flags); #else - r = _open(path, flags, pmode); + r = _open(path, flags, pmode); #endif - if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { - /* simular other POSIX system action to pass a test */ - attr = GetFileAttributesA(path); - if (attr == -1) - la_dosmaperr(GetLastError()); - else if (attr & FILE_ATTRIBUTE_DIRECTORY) - errno = EISDIR; - else - errno = EACCES; - return (-1); - } - if (r >= 0 || errno != ENOENT) - return (r); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - } - r = _wopen(ws, flags, pmode); - if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { - /* simular other POSIX system action to pass a test */ - attr = GetFileAttributesW(ws); - if (attr == -1) - la_dosmaperr(GetLastError()); - else if (attr & FILE_ATTRIBUTE_DIRECTORY) - errno = EISDIR; - else - errno = EACCES; - } - free(ws); - return (r); + if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { + /* Simulate other POSIX system action to pass our test suite. */ + attr = GetFileAttributesA(path); + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else if (attr & FILE_ATTRIBUTE_DIRECTORY) + errno = EISDIR; + else + errno = EACCES; + return (-1); + } + if (r >= 0 || errno != ENOENT) + return (r); + ws = __la_win_permissive_name(path); + if (ws == NULL) { + errno = EINVAL; + return (-1); + } + } + r = _wopen(ws, flags, pmode); + if (r < 0 && errno == EACCES && (flags & O_CREAT) != 0) { + /* Simulate other POSIX system action to pass our test suite. */ + attr = GetFileAttributesW(ws); + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else if (attr & FILE_ATTRIBUTE_DIRECTORY) + errno = EISDIR; + else + errno = EACCES; + } + free(ws); + return (r); } ssize_t __la_read(int fd, void *buf, size_t nbytes) { - HANDLE handle; - DWORD bytes_read, lasterr; - int r; + HANDLE handle; + DWORD bytes_read, lasterr; + int r; #ifdef _WIN64 - if (nbytes > UINT32_MAX) - nbytes = UINT32_MAX; + if (nbytes > UINT32_MAX) + nbytes = UINT32_MAX; #endif - if (fd < 0) { - errno = EBADF; - return (-1); - } - handle = (HANDLE)_get_osfhandle(fd); - if (GetFileType(handle) == FILE_TYPE_PIPE) { - DWORD sta; - if (GetNamedPipeHandleState( - handle, &sta, NULL, NULL, NULL, NULL, 0) != 0 && - (sta & PIPE_NOWAIT) == 0) { - DWORD avail = -1; - int cnt = 3; - - while (PeekNamedPipe( - handle, NULL, 0, NULL, &avail, NULL) != 0 && - avail == 0 && --cnt) - Sleep(100); - if (avail == 0) - return (0); - } - } - r = ReadFile(handle, buf, (uint32_t)nbytes, - &bytes_read, NULL); - if (r == 0) { - lasterr = GetLastError(); - if (lasterr == ERROR_NO_DATA) { - errno = EAGAIN; - return (-1); - } - if (lasterr == ERROR_BROKEN_PIPE) - return (0); - if (lasterr == ERROR_ACCESS_DENIED) - errno = EBADF; - else - la_dosmaperr(lasterr); - return (-1); - } - return ((ssize_t)bytes_read); -} - -/* Remove directory */ -int -__la_rmdir(const char *path) -{ - wchar_t *ws; - int r; - - r = _rmdir(path); - if (r >= 0 || errno != ENOENT) - return (r); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = _wrmdir(ws); - free(ws); - return (r); + if (fd < 0) { + errno = EBADF; + return (-1); + } + /* Do not pass 0 to third parameter of ReadFile(), read bytes. + * This will not return to application side. */ + if (nbytes == 0) + return (0); + handle = (HANDLE)_get_osfhandle(fd); + r = ReadFile(handle, buf, (uint32_t)nbytes, + &bytes_read, NULL); + if (r == 0) { + lasterr = GetLastError(); + if (lasterr == ERROR_NO_DATA) { + errno = EAGAIN; + return (-1); + } + if (lasterr == ERROR_BROKEN_PIPE) + return (0); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return ((ssize_t)bytes_read); } /* Convert Windows FILETIME to UTC */ __inline static void fileTimeToUTC(const FILETIME *filetime, time_t *time, long *ns) { - ULARGE_INTEGER utc; + ULARGE_INTEGER utc; - utc.HighPart = filetime->dwHighDateTime; - utc.LowPart = filetime->dwLowDateTime; - if (utc.QuadPart >= EPOC_TIME) { - utc.QuadPart -= EPOC_TIME; - *time = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ - *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ - } else { - *time = 0; - *ns = 0; - } + utc.HighPart = filetime->dwHighDateTime; + utc.LowPart = filetime->dwLowDateTime; + if (utc.QuadPart >= EPOC_TIME) { + utc.QuadPart -= EPOC_TIME; + *time = (time_t)(utc.QuadPart / 10000000); /* milli seconds base */ + *ns = (long)(utc.QuadPart % 10000000) * 100;/* nano seconds base */ + } else { + *time = 0; + *ns = 0; + } } /* Stat by handle - * Windows' stat() does not accept path which is added "\\?\" especially "?" + * Windows' stat() does not accept the path added "\\?\" especially "?" * character. - * It means we cannot access a long name path(which is longer than MAX_PATH). + * It means we cannot access the long name path longer than MAX_PATH. * So I've implemented simular Windows' stat() to access the long name path. * And I've added some feature. * 1. set st_ino by nFileIndexHigh and nFileIndexLow of @@ -781,252 +454,240 @@ fileTimeToUTC(const FILETIME *filetime, time_t *time, long *ns) static int __hstat(HANDLE handle, struct ustat *st) { - BY_HANDLE_FILE_INFORMATION info; - ULARGE_INTEGER ino64; - DWORD ftype; - mode_t mode; - time_t time; - long ns; - - switch (ftype = GetFileType(handle)) { - case FILE_TYPE_UNKNOWN: - errno = EBADF; - return (-1); - case FILE_TYPE_CHAR: - case FILE_TYPE_PIPE: - if (ftype == FILE_TYPE_CHAR) { - st->st_mode = S_IFCHR; - st->st_size = 0; - } else { - DWORD avail; - - st->st_mode = S_IFIFO; - if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL)) - st->st_size = avail; - else - st->st_size = 0; - } - st->st_atime = 0; - st->st_atime_nsec = 0; - st->st_mtime = 0; - st->st_mtime_nsec = 0; - st->st_ctime = 0; - st->st_ctime_nsec = 0; - st->st_ino = 0; - st->st_nlink = 1; - st->st_uid = 0; - st->st_gid = 0; - st->st_rdev = 0; - st->st_dev = 0; - return (0); - case FILE_TYPE_DISK: - break; - default: - /* This ftype is undocumented type. */ - la_dosmaperr(GetLastError()); - return (-1); - } - - ZeroMemory(&info, sizeof(info)); - if (!GetFileInformationByHandle (handle, &info)) { - la_dosmaperr(GetLastError()); - return (-1); - } - - mode = S_IRUSR | S_IRGRP | S_IROTH; - if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) - mode |= S_IWUSR | S_IWGRP | S_IWOTH; - if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; - else - mode |= S_IFREG; - st->st_mode = mode; - - fileTimeToUTC(&info.ftLastAccessTime, &time, &ns); - st->st_atime = time; - st->st_atime_nsec = ns; - fileTimeToUTC(&info.ftLastWriteTime, &time, &ns); - st->st_mtime = time; - st->st_mtime_nsec = ns; - fileTimeToUTC(&info.ftCreationTime, &time, &ns); - st->st_ctime = time; - st->st_ctime_nsec = ns; - st->st_size = - ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1)) - + (int64_t)(info.nFileSizeLow); + BY_HANDLE_FILE_INFORMATION info; + ULARGE_INTEGER ino64; + DWORD ftype; + mode_t mode; + time_t time; + long ns; + + switch (ftype = GetFileType(handle)) { + case FILE_TYPE_UNKNOWN: + errno = EBADF; + return (-1); + case FILE_TYPE_CHAR: + case FILE_TYPE_PIPE: + if (ftype == FILE_TYPE_CHAR) { + st->st_mode = S_IFCHR; + st->st_size = 0; + } else { + DWORD avail; + + st->st_mode = S_IFIFO; + if (PeekNamedPipe(handle, NULL, 0, NULL, &avail, NULL)) + st->st_size = avail; + else + st->st_size = 0; + } + st->st_atime = 0; + st->st_atime_nsec = 0; + st->st_mtime = 0; + st->st_mtime_nsec = 0; + st->st_ctime = 0; + st->st_ctime_nsec = 0; + st->st_ino = 0; + st->st_nlink = 1; + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + st->st_dev = 0; + return (0); + case FILE_TYPE_DISK: + break; + default: + /* This ftype is undocumented type. */ + la_dosmaperr(GetLastError()); + return (-1); + } + + ZeroMemory(&info, sizeof(info)); + if (!GetFileInformationByHandle (handle, &info)) { + la_dosmaperr(GetLastError()); + return (-1); + } + + mode = S_IRUSR | S_IRGRP | S_IROTH; + if ((info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) + mode |= S_IWUSR | S_IWGRP | S_IWOTH; + if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else + mode |= S_IFREG; + st->st_mode = mode; + + fileTimeToUTC(&info.ftLastAccessTime, &time, &ns); + st->st_atime = time; + st->st_atime_nsec = ns; + fileTimeToUTC(&info.ftLastWriteTime, &time, &ns); + st->st_mtime = time; + st->st_mtime_nsec = ns; + fileTimeToUTC(&info.ftCreationTime, &time, &ns); + st->st_ctime = time; + st->st_ctime_nsec = ns; + st->st_size = + ((int64_t)(info.nFileSizeHigh) * ((int64_t)MAXDWORD + 1)) + + (int64_t)(info.nFileSizeLow); #ifdef SIMULATE_WIN_STAT - st->st_ino = 0; - st->st_nlink = 1; - st->st_dev = 0; + st->st_ino = 0; + st->st_nlink = 1; + st->st_dev = 0; #else - /* Getting FileIndex as i-node. We have to remove a sequence which - * is high-16-bits of nFileIndexHigh. */ - ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL; - ino64.LowPart = info.nFileIndexLow; - st->st_ino = ino64.QuadPart; - st->st_nlink = info.nNumberOfLinks; - if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - ++st->st_nlink;/* Add parent directory. */ - st->st_dev = info.dwVolumeSerialNumber; + /* Getting FileIndex as i-node. We should remove a sequence which + * is high-16-bits of nFileIndexHigh. */ + ino64.HighPart = info.nFileIndexHigh & 0x0000FFFFUL; + ino64.LowPart = info.nFileIndexLow; + st->st_ino = ino64.QuadPart; + st->st_nlink = info.nNumberOfLinks; + if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + ++st->st_nlink;/* Add parent directory. */ + st->st_dev = info.dwVolumeSerialNumber; #endif - st->st_uid = 0; - st->st_gid = 0; - st->st_rdev = 0; - return (0); + st->st_uid = 0; + st->st_gid = 0; + st->st_rdev = 0; + return (0); } static void copy_stat(struct stat *st, struct ustat *us) { - st->st_atime = us->st_atime; - st->st_ctime = us->st_ctime; - st->st_mtime = us->st_mtime; - st->st_gid = us->st_gid; - st->st_ino = getino(us); - st->st_mode = us->st_mode; - st->st_nlink = us->st_nlink; - st->st_size = us->st_size; - st->st_uid = us->st_uid; - st->st_dev = us->st_dev; - st->st_rdev = us->st_rdev; + st->st_atime = us->st_atime; + st->st_ctime = us->st_ctime; + st->st_mtime = us->st_mtime; + st->st_gid = us->st_gid; + st->st_ino = getino(us); + st->st_mode = us->st_mode; + st->st_nlink = us->st_nlink; + st->st_size = us->st_size; + st->st_uid = us->st_uid; + st->st_dev = us->st_dev; + st->st_rdev = us->st_rdev; } +/* + * TODO: Remove a use of __la_fstat and __la_stat. + * We should use GetFileInformationByHandle in place + * where We still use the *stat functions. + */ int __la_fstat(int fd, struct stat *st) { - struct ustat u; - int ret; - - if (fd < 0) { - errno = EBADF; - return (-1); - } - ret = __hstat((HANDLE)_get_osfhandle(fd), &u); - if (ret >= 0) { - copy_stat(st, &u); - if (u.st_mode & (S_IFCHR | S_IFIFO)) { - st->st_dev = fd; - st->st_rdev = fd; - } - } - return (ret); -} - + struct ustat u; + int ret; + + if (fd < 0) { + errno = EBADF; + return (-1); + } + ret = __hstat((HANDLE)_get_osfhandle(fd), &u); + if (ret >= 0) { + copy_stat(st, &u); + if (u.st_mode & (S_IFCHR | S_IFIFO)) { + st->st_dev = fd; + st->st_rdev = fd; + } + } + return (ret); +} + +/* This can exceed MAX_PATH limitation. */ int __la_stat(const char *path, struct stat *st) { - HANDLE handle; - struct ustat u; - int ret; - - handle = la_CreateFile(path, 0, 0, NULL, OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_READONLY, - NULL); - if (handle == INVALID_HANDLE_VALUE) { - la_dosmaperr(GetLastError()); - return (-1); - } - ret = __hstat(handle, &u); - CloseHandle(handle); - if (ret >= 0) { - char *p; - - copy_stat(st, &u); - p = strrchr(path, '.'); - if (p != NULL && strlen(p) == 4) { - char exttype[4]; - - ++ p; - exttype[0] = toupper(*p++); - exttype[1] = toupper(*p++); - exttype[2] = toupper(*p++); - exttype[3] = '\0'; - if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") || - !strcmp(exttype, "BAT") || !strcmp(exttype, "COM")) - st->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH; - } - } - return (ret); -} - -int -__la_unlink(const char *path) -{ - wchar_t *ws; - int r; - - r = _unlink(path); - if (r >= 0 || errno != ENOENT) - return (r); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = _wunlink(ws); - free(ws); - return (r); + HANDLE handle; + struct ustat u; + int ret; + + handle = la_CreateFile(path, 0, 0, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL); + if (handle == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + ret = __hstat(handle, &u); + CloseHandle(handle); + if (ret >= 0) { + char *p; + + copy_stat(st, &u); + p = strrchr(path, '.'); + if (p != NULL && strlen(p) == 4) { + char exttype[4]; + + ++ p; + exttype[0] = toupper(*p++); + exttype[1] = toupper(*p++); + exttype[2] = toupper(*p++); + exttype[3] = '\0'; + if (!strcmp(exttype, "EXE") || !strcmp(exttype, "CMD") || + !strcmp(exttype, "BAT") || !strcmp(exttype, "COM")) + st->st_mode |= S_IXUSR | S_IXGRP | S_IXOTH; + } + } + return (ret); } /* - * This waitpid is limited implemention. + * This waitpid is limited implementation. */ pid_t __la_waitpid(pid_t wpid, int *status, int option) { - HANDLE child; - DWORD cs, ret; - - (void)option;/* UNUSED */ - child = OpenProcess(PROCESS_ALL_ACCESS, FALSE, wpid); - if (child == NULL) { - la_dosmaperr(GetLastError()); - return (-1); - } - ret = WaitForSingleObject(child, INFINITE); - if (ret == WAIT_FAILED) { - CloseHandle(child); - la_dosmaperr(GetLastError()); - return (-1); - } - if (GetExitCodeProcess(child, &cs) == 0) { - CloseHandle(child); - la_dosmaperr(GetLastError()); - return (-1); - } - if (cs == STILL_ACTIVE) - *status = 0x100; - else - *status = (int)(cs & 0xff); - CloseHandle(child); - return (wpid); + HANDLE child; + DWORD cs, ret; + + (void)option;/* UNUSED */ + *status = 0; + child = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, wpid); + if (child == NULL) { + la_dosmaperr(GetLastError()); + return (-1); + } + ret = WaitForSingleObject(child, INFINITE); + if (ret == WAIT_FAILED) { + CloseHandle(child); + la_dosmaperr(GetLastError()); + return (-1); + } + if (GetExitCodeProcess(child, &cs) == 0) { + CloseHandle(child); + la_dosmaperr(GetLastError()); + return (-1); + } + if (cs == STILL_ACTIVE) + *status = 0x100; + else + *status = (int)(cs & 0xff); + CloseHandle(child); + return (wpid); } ssize_t __la_write(int fd, const void *buf, size_t nbytes) { - DWORD bytes_written; + DWORD bytes_written; #ifdef _WIN64 - if (nbytes > UINT32_MAX) - nbytes = UINT32_MAX; + if (nbytes > UINT32_MAX) + nbytes = UINT32_MAX; #endif - if (fd < 0) { - errno = EBADF; - return (-1); - } - if (!WriteFile((HANDLE)_get_osfhandle(fd), buf, (uint32_t)nbytes, - &bytes_written, NULL)) { - DWORD lasterr; - - lasterr = GetLastError(); - if (lasterr == ERROR_ACCESS_DENIED) - errno = EBADF; - else - la_dosmaperr(lasterr); - return (-1); - } - return (bytes_written); + if (fd < 0) { + errno = EBADF; + return (-1); + } + if (!WriteFile((HANDLE)_get_osfhandle(fd), buf, (uint32_t)nbytes, + &bytes_written, NULL)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + return (-1); + } + return (bytes_written); } /* @@ -1036,12 +697,12 @@ __la_write(int fd, const void *buf, size_t nbytes) /*------------------------------------------------------------------------- * * win32error.c - * Map win32 error codes to errno values + * Map win32 error codes to errno values * * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ + * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1072,182 +733,81 @@ PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ static const struct { - DWORD winerr; - int doserr; + DWORD winerr; + int doserr; } doserrors[] = { - { ERROR_INVALID_FUNCTION, EINVAL }, - { ERROR_FILE_NOT_FOUND, ENOENT }, - { ERROR_PATH_NOT_FOUND, ENOENT }, - { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, - { ERROR_ACCESS_DENIED, EACCES }, - { ERROR_INVALID_HANDLE, EBADF }, - { ERROR_ARENA_TRASHED, ENOMEM }, - { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, - { ERROR_INVALID_BLOCK, ENOMEM }, - { ERROR_BAD_ENVIRONMENT, E2BIG }, - { ERROR_BAD_FORMAT, ENOEXEC }, - { ERROR_INVALID_ACCESS, EINVAL }, - { ERROR_INVALID_DATA, EINVAL }, - { ERROR_INVALID_DRIVE, ENOENT }, - { ERROR_CURRENT_DIRECTORY, EACCES }, - { ERROR_NOT_SAME_DEVICE, EXDEV }, - { ERROR_NO_MORE_FILES, ENOENT }, - { ERROR_LOCK_VIOLATION, EACCES }, - { ERROR_SHARING_VIOLATION, EACCES }, - { ERROR_BAD_NETPATH, ENOENT }, - { ERROR_NETWORK_ACCESS_DENIED, EACCES }, - { ERROR_BAD_NET_NAME, ENOENT }, - { ERROR_FILE_EXISTS, EEXIST }, - { ERROR_CANNOT_MAKE, EACCES }, - { ERROR_FAIL_I24, EACCES }, - { ERROR_INVALID_PARAMETER, EINVAL }, - { ERROR_NO_PROC_SLOTS, EAGAIN }, - { ERROR_DRIVE_LOCKED, EACCES }, - { ERROR_BROKEN_PIPE, EPIPE }, - { ERROR_DISK_FULL, ENOSPC }, - { ERROR_INVALID_TARGET_HANDLE, EBADF }, - { ERROR_INVALID_HANDLE, EINVAL }, - { ERROR_WAIT_NO_CHILDREN, ECHILD }, - { ERROR_CHILD_NOT_COMPLETE, ECHILD }, - { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, - { ERROR_NEGATIVE_SEEK, EINVAL }, - { ERROR_SEEK_ON_DEVICE, EACCES }, - { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, - { ERROR_NOT_LOCKED, EACCES }, - { ERROR_BAD_PATHNAME, ENOENT }, - { ERROR_MAX_THRDS_REACHED, EAGAIN }, - { ERROR_LOCK_FAILED, EACCES }, - { ERROR_ALREADY_EXISTS, EEXIST }, - { ERROR_FILENAME_EXCED_RANGE, ENOENT }, - { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, - { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } + { ERROR_INVALID_FUNCTION, EINVAL }, + { ERROR_FILE_NOT_FOUND, ENOENT }, + { ERROR_PATH_NOT_FOUND, ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, + { ERROR_ACCESS_DENIED, EACCES }, + { ERROR_INVALID_HANDLE, EBADF }, + { ERROR_ARENA_TRASHED, ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, + { ERROR_INVALID_BLOCK, ENOMEM }, + { ERROR_BAD_ENVIRONMENT, E2BIG }, + { ERROR_BAD_FORMAT, ENOEXEC }, + { ERROR_INVALID_ACCESS, EINVAL }, + { ERROR_INVALID_DATA, EINVAL }, + { ERROR_INVALID_DRIVE, ENOENT }, + { ERROR_CURRENT_DIRECTORY, EACCES }, + { ERROR_NOT_SAME_DEVICE, EXDEV }, + { ERROR_NO_MORE_FILES, ENOENT }, + { ERROR_LOCK_VIOLATION, EACCES }, + { ERROR_SHARING_VIOLATION, EACCES }, + { ERROR_BAD_NETPATH, ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, EACCES }, + { ERROR_BAD_NET_NAME, ENOENT }, + { ERROR_FILE_EXISTS, EEXIST }, + { ERROR_CANNOT_MAKE, EACCES }, + { ERROR_FAIL_I24, EACCES }, + { ERROR_INVALID_PARAMETER, EINVAL }, + { ERROR_NO_PROC_SLOTS, EAGAIN }, + { ERROR_DRIVE_LOCKED, EACCES }, + { ERROR_BROKEN_PIPE, EPIPE }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, EBADF }, + { ERROR_INVALID_HANDLE, EINVAL }, + { ERROR_WAIT_NO_CHILDREN, ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, + { ERROR_NEGATIVE_SEEK, EINVAL }, + { ERROR_SEEK_ON_DEVICE, EACCES }, + { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + { ERROR_NOT_LOCKED, EACCES }, + { ERROR_BAD_PATHNAME, ENOENT }, + { ERROR_MAX_THRDS_REACHED, EAGAIN }, + { ERROR_LOCK_FAILED, EACCES }, + { ERROR_ALREADY_EXISTS, EEXIST }, + { ERROR_FILENAME_EXCED_RANGE, ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } }; -static void -la_dosmaperr(unsigned long e) -{ - int i; - - if (e == 0) - { - errno = 0; - return; - } - - for (i = 0; i < sizeof(doserrors); i++) - { - if (doserrors[i].winerr == e) - { - errno = doserrors[i].doserr; - return; - } - } - - /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ - errno = EINVAL; - return; -} - -#if !defined(HAVE_OPENSSL_MD5_H) && !defined(HAVE_OPENSSL_SHA_H) -/* - * Message digest functions. - */ -static void -Digest_Init(Digest_CTX *ctx, ALG_ID algId) -{ - - ctx->valid = 0; - if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, 0)) { - if (GetLastError() != NTE_BAD_KEYSET) - return; - if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_NEWKEYSET)) - return; - } - - if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) { - CryptReleaseContext(ctx->cryptProv, 0); - return; - } - - ctx->valid = 1; -} - -static void -Digest_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len) -{ - - if (!ctx->valid) - return; - - CryptHashData(ctx->hash, - (unsigned char *)(uintptr_t)buf, - (DWORD)len, 0); -} - -static void -Digest_Final(unsigned char *buf, int bufsize, Digest_CTX *ctx) +void +__la_dosmaperr(unsigned long e) { - DWORD siglen = bufsize; - - if (!ctx->valid) - return; - - CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0); - CryptDestroyHash(ctx->hash); - CryptReleaseContext(ctx->cryptProv, 0); - ctx->valid = 0; -} + int i; -#define DIGEST_INIT(name, algid) \ -void name ## _Init(Digest_CTX *ctx)\ -{\ - Digest_Init(ctx, algid);\ -} + if (e == 0) + { + errno = 0; + return; + } -#define DIGEST_UPDATE(name) \ -void name ## _Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)\ -{\ - Digest_Update(ctx, buf, len);\ -} + for (i = 0; i < sizeof(doserrors); i++) + { + if (doserrors[i].winerr == e) + { + errno = doserrors[i].doserr; + return; + } + } -#define DIGEST_FINAL(name, size) \ -void name ## _Final(unsigned char buf[size], Digest_CTX *ctx)\ -{\ - Digest_Final(buf, size, ctx);\ + /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ + errno = EINVAL; + return; } -DIGEST_INIT(MD5, CALG_MD5) -DIGEST_UPDATE(MD5) -DIGEST_FINAL(MD5, MD5_DIGEST_LENGTH) - -DIGEST_INIT(SHA1, CALG_SHA1) -DIGEST_UPDATE(SHA1) -DIGEST_FINAL(SHA1, SHA1_DIGEST_LENGTH) - -/* - * SHA256 nor SHA384 nor SHA512 are not supported on Windows XP and Windows 2000. - */ -#ifdef CALG_SHA256 -DIGEST_INIT(SHA256, CALG_SHA256) -DIGEST_UPDATE(SHA256) -DIGEST_FINAL(SHA256, SHA256_DIGEST_LENGTH) -#endif - -#ifdef CALG_SHA384 -DIGEST_INIT(SHA384, CALG_SHA384) -DIGEST_UPDATE(SHA384) -DIGEST_FINAL(SHA384, SHA384_DIGEST_LENGTH) -#endif - -#ifdef CALG_SHA512 -DIGEST_INIT(SHA512, CALG_SHA512) -DIGEST_UPDATE(SHA512) -DIGEST_FINAL(SHA512, SHA384_DIGEST_LENGTH) -#endif - -#endif /* !HAVE_OPENSSL_MD5_H && !HAVE_OPENSSL_SHA_H */ - #endif /* _WIN32 && !__CYGWIN__ */ diff --git a/Utilities/cmlibarchive/libarchive/archive_windows.h b/Utilities/cmlibarchive/libarchive/archive_windows.h index f85f3f04c..c581af317 100644 --- a/Utilities/cmlibarchive/libarchive/archive_windows.h +++ b/Utilities/cmlibarchive/libarchive/archive_windows.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2009-2011 Michihiro NAKAJIMA * Copyright (c) 2003-2006 Tim Kientzle * All rights reserved. * @@ -46,377 +46,252 @@ */ #ifndef LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED -#define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED +#define LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED /* Start of configuration for native Win32 */ #include -#define set_errno(val) ((errno)=val) +#define set_errno(val) ((errno)=val) #include -#include /* brings in NULL */ +#include //brings in NULL +#if defined(HAVE_STDINT_H) +#include +#endif #include #include #include #include #include +#if defined(__MINGW32__) && defined(HAVE_UNISTD_H) +/* Prevent build error from a type mismatch of ftruncate(). + * This unistd.h defines it as ftruncate(int, off_t). */ +#include +#endif #define NOCRYPT #include - -#if !defined(STDIN_FILENO) -#define STDIN_FILENO 0 -#endif - -#if !defined(STDOUT_FILENO) -#define STDOUT_FILENO 1 -#endif - -#if !defined(STDERR_FILENO) -#define STDERR_FILENO 2 -#endif - +//#define EFTYPE 7 #if defined(_MSC_VER) /* TODO: Fix the code, don't suppress the warnings. */ -#pragma warning(disable:4761) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */ -/* this one shows up on vs 6 */ -# if _MSC_VER < 1300 -# pragma warning(disable:4244) /* 'integral size mismatch in argument; conversion supplied */ -# endif -#pragma warning(default: 4365) /* 'action':conversion from 'type_1' to 'type_2', signed/unsigned mismatch */ -#pragma warning(disable: 4244) /* conversion from '__int64' to 'off_t', possible loss of data */ +#pragma warning(push,1) +#pragma warning(disable:4761) /* integral size mismatch in argument; conversion supplied */ +#endif +#if defined(__BORLANDC__) +#pragma warn -8068 /* Constant out of range in comparison. */ +#pragma warn -8072 /* Suspicious pointer arithmetic. */ #endif #ifndef NULL #ifdef __cplusplus -#define NULL 0 +#define NULL 0 #else -#define NULL ((void *)0) +#define NULL ((void *)0) #endif #endif /* Alias the Windows _function to the POSIX equivalent. */ -#define access _access -#define chdir __la_chdir -#define chmod __la_chmod -#define close _close -#define fcntl __la_fcntl +#define close _close +#define fcntl(fd, cmd, flg) /* No operation. */ #ifndef fileno -#define fileno _fileno +#define fileno _fileno #endif -#define fstat __la_fstat -#define ftruncate __la_ftruncate -#define futimes __la_futimes -#define getcwd _getcwd -#define link __la_link -#define lseek __la_lseek -#define lstat __la_stat -#define mbstowcs __la_mbstowcs -#define mkdir(d,m) __la_mkdir(d, m) -#define mktemp _mktemp -#define open __la_open -#define read __la_read -#define rmdir __la_rmdir -#define stat(path,stref) __la_stat(path,stref) -#ifndef __BORLANDC__ -#define strdup _strdup +#define fstat __la_fstat +#if !defined(__BORLANDC__) +#define lseek _lseeki64 +#else +#define lseek __la_lseek +#define __LA_LSEEK_NEEDED #endif -#define tzset _tzset -#ifndef __BORLANDC__ -#define umask _umask +#define lstat __la_stat +#define open __la_open +#define read __la_read +#if !defined(__BORLANDC__) +#define setmode _setmode #endif -#define unlink __la_unlink -#define utimes __la_utimes -#define waitpid __la_waitpid -#define write __la_write +#define stat(path,stref) __la_stat(path,stref) +#if !defined(__BORLANDC__) +#define strdup _strdup +#endif +#define tzset _tzset +#if !defined(__BORLANDC__) +#define umask _umask +#endif +#define waitpid __la_waitpid +#define write __la_write #ifndef O_RDONLY - #define O_RDONLY _O_RDONLY - #define O_WRONLY _O_WRONLY - #define O_TRUNC _O_TRUNC - #define O_CREAT _O_CREAT - #define O_EXCL _O_EXCL +#define O_RDONLY _O_RDONLY +#define O_WRONLY _O_WRONLY +#define O_TRUNC _O_TRUNC +#define O_CREAT _O_CREAT +#define O_EXCL _O_EXCL +#define O_BINARY _O_BINARY #endif #ifndef _S_IFIFO - #define _S_IFIFO 0010000 /* pipe */ + #define _S_IFIFO 0010000 /* pipe */ #endif #ifndef _S_IFCHR - #define _S_IFCHR 0020000 /* character special */ + #define _S_IFCHR 0020000 /* character special */ #endif #ifndef _S_IFDIR - #define _S_IFDIR 0040000 /* directory */ + #define _S_IFDIR 0040000 /* directory */ #endif #ifndef _S_IFBLK - #define _S_IFBLK 0060000 /* block special */ + #define _S_IFBLK 0060000 /* block special */ #endif #ifndef _S_IFLNK - #define _S_IFLNK 0120000 /* symbolic link */ + #define _S_IFLNK 0120000 /* symbolic link */ #endif #ifndef _S_IFSOCK - #define _S_IFSOCK 0140000 /* socket */ + #define _S_IFSOCK 0140000 /* socket */ #endif -#ifndef _S_IFREG - #define _S_IFREG 0100000 /* regular */ +#ifndef _S_IFREG + #define _S_IFREG 0100000 /* regular */ #endif -#ifndef _S_IFMT - #define _S_IFMT 0170000 /* file type mask */ +#ifndef _S_IFMT + #define _S_IFMT 0170000 /* file type mask */ #endif + #ifndef S_IFIFO - #define S_IFIFO _S_IFIFO +#define S_IFIFO _S_IFIFO #endif - +//#define S_IFCHR _S_IFCHR +//#define S_IFDIR _S_IFDIR #ifndef S_IFBLK - #define S_IFBLK _S_IFBLK +#define S_IFBLK _S_IFBLK #endif #ifndef S_IFLNK - #define S_IFLNK _S_IFLNK +#define S_IFLNK _S_IFLNK #endif #ifndef S_IFSOCK - #define S_IFSOCK _S_IFSOCK -#endif -#ifndef S_ISBLK - #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */ - #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */ - #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */ - #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */ - #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */ +#define S_IFSOCK _S_IFSOCK #endif -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */ -#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */ - -#define _S_ISUID 0004000 /* set user id on execution */ -#define _S_ISGID 0002000 /* set group id on execution */ -#define _S_ISVTX 0001000 /* save swapped text even after use */ +//#define S_IFREG _S_IFREG +//#define S_IFMT _S_IFMT -#define S_ISUID _S_ISUID -#define S_ISGID _S_ISGID -#define S_ISVTX _S_ISVTX - -#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) -#define _S_IXUSR _S_IEXEC /* read permission, user */ -#define _S_IWUSR _S_IWRITE /* write permission, user */ -#define _S_IRUSR _S_IREAD /* execute/search permission, user */ -#define _S_IRWXG (_S_IRWXU >> 3) -#define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */ -#define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */ -#define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */ -#define _S_IRWXO (_S_IRWXG >> 3) -#define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */ -#define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */ -#define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */ +#ifndef S_ISBLK +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) /* block special */ +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) /* fifo or socket */ +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) /* char special */ +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) /* directory */ +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) /* regular file */ +#endif +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) /* Symbolic link */ +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) /* Socket */ + +#define _S_ISUID 0004000 /* set user id on execution */ +#define _S_ISGID 0002000 /* set group id on execution */ +#define _S_ISVTX 0001000 /* save swapped text even after use */ + +#define S_ISUID _S_ISUID +#define S_ISGID _S_ISGID +#define S_ISVTX _S_ISVTX + +#define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) +#define _S_IXUSR _S_IEXEC /* read permission, user */ +#define _S_IWUSR _S_IWRITE /* write permission, user */ +#define _S_IRUSR _S_IREAD /* execute/search permission, user */ +#define _S_IRWXG (_S_IRWXU >> 3) +#define _S_IXGRP (_S_IXUSR >> 3) /* read permission, group */ +#define _S_IWGRP (_S_IWUSR >> 3) /* write permission, group */ +#define _S_IRGRP (_S_IRUSR >> 3) /* execute/search permission, group */ +#define _S_IRWXO (_S_IRWXG >> 3) +#define _S_IXOTH (_S_IXGRP >> 3) /* read permission, other */ +#define _S_IWOTH (_S_IWGRP >> 3) /* write permission, other */ +#define _S_IROTH (_S_IRGRP >> 3) /* execute/search permission, other */ #ifndef S_IRWXU - #define S_IRWXU _S_IRWXU - #define S_IXUSR _S_IXUSR - #define S_IWUSR _S_IWUSR - #define S_IRUSR _S_IRUSR -#endif -#define S_IRWXG _S_IRWXG -#define S_IXGRP _S_IXGRP -#define S_IWGRP _S_IWGRP -#define S_IRGRP _S_IRGRP -#define S_IRWXO _S_IRWXO -#define S_IXOTH _S_IXOTH -#define S_IWOTH _S_IWOTH -#define S_IROTH _S_IROTH - -#define F_DUPFD 0 /* Duplicate file descriptor. */ -#define F_GETFD 1 /* Get file descriptor flags. */ -#define F_SETFD 2 /* Set file descriptor flags. */ -#define F_GETFL 3 /* Get file status flags. */ -#define F_SETFL 4 /* Set file status flags. */ -#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ -#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ -#define F_GETLK 7 /* Get record locking info. */ -#define F_SETLK 8 /* Set record locking info (non-blocking). */ -#define F_SETLKW 9 /* Set record locking info (blocking). */ +#define S_IRWXU _S_IRWXU +#define S_IXUSR _S_IXUSR +#define S_IWUSR _S_IWUSR +#define S_IRUSR _S_IRUSR +#endif +#define S_IRWXG _S_IRWXG +#define S_IXGRP _S_IXGRP +#define S_IWGRP _S_IWGRP +#define S_IRGRP _S_IRGRP +#define S_IRWXO _S_IRWXO +#define S_IXOTH _S_IXOTH +#define S_IWOTH _S_IWOTH +#define S_IROTH _S_IROTH + +#define F_DUPFD 0 /* Duplicate file descriptor. */ +#define F_GETFD 1 /* Get file descriptor flags. */ +#define F_SETFD 2 /* Set file descriptor flags. */ +#define F_GETFL 3 /* Get file status flags. */ +#define F_SETFL 4 /* Set file status flags. */ +#define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ +#define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ +#define F_GETLK 7 /* Get record locking info. */ +#define F_SETLK 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW 9 /* Set record locking info (blocking). */ /* XXX missing */ -#define F_GETLK64 7 /* Get record locking info. */ -#define F_SETLK64 8 /* Set record locking info (non-blocking). */ -#define F_SETLKW64 9 /* Set record locking info (blocking). */ +#define F_GETLK64 7 /* Get record locking info. */ +#define F_SETLK64 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 9 /* Set record locking info (blocking). */ /* File descriptor flags used with F_GETFD and F_SETFD. */ -#define FD_CLOEXEC 1 /* Close on exec. */ +#define FD_CLOEXEC 1 /* Close on exec. */ -/*NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else... */ -#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */ -/*#define O_NDELAY O_NONBLOCK */ +//NOT SURE IF O_NONBLOCK is OK here but at least the 0x0004 flag is not used by anything else... +#define O_NONBLOCK 0x0004 /* Non-blocking I/O. */ +//#define O_NDELAY O_NONBLOCK /* Symbolic constants for the access() function */ #if !defined(F_OK) - #define R_OK 4 /* Test for read permission */ - #define W_OK 2 /* Test for write permission */ - #define X_OK 1 /* Test for execute permission */ - #define F_OK 0 /* Test for existence of file */ -#endif - - -#ifdef _LARGEFILE_SOURCE -# define __USE_LARGEFILE 1 /* declare fseeko and ftello */ + #define R_OK 4 /* Test for read permission */ + #define W_OK 2 /* Test for write permission */ + #define X_OK 1 /* Test for execute permission */ + #define F_OK 0 /* Test for existence of file */ #endif -#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 -# define __USE_FILE_OFFSET64 1 /* replace 32-bit functions by 64-bit ones */ -#endif - -#if __USE_LARGEFILE && __USE_FILE_OFFSET64 -/* replace stat and seek by their large-file equivalents */ -#undef stat -#define stat _stati64 - -#undef lseek -#define lseek _lseeki64 -#define lseek64 _lseeki64 -#define tell _telli64 -#define tell64 _telli64 - -#ifdef __MINGW32__ -# define fseek fseeko64 -# define fseeko fseeko64 -# define ftell ftello64 -# define ftello ftello64 -# define ftell64 ftello64 -#endif /* __MINGW32__ */ -#endif /* LARGE_FILES */ - -#ifdef USE_WINSOCK_TIMEVAL -/* Winsock timeval has long size tv_sec. */ -#define __timeval timeval -#else -struct _timeval64i32 { - time_t tv_sec; - long tv_usec; -}; -#define __timeval _timeval64i32 -#endif - -#if defined(_MSC_VER) || defined(__BORLANDC__) - typedef int pid_t; -#endif /* _MSC_VER __BORLANDC__ */ - -/* Message digest define */ -#if !defined(HAVE_OPENSSL_MD5_H) && !defined(HAVE_OPENSSL_SHA_H) -# if defined(_MSC_VER) && _MSC_VER < 1300 -# define _WIN32_WINNT 0x0400 -# endif -#include -typedef struct { - int valid; - HCRYPTPROV cryptProv; - HCRYPTHASH hash; -} Digest_CTX; -#endif - -#if !defined(HAVE_OPENSSL_MD5_H) && defined(CALG_MD5) -#define MD5_DIGEST_LENGTH 16 -#define HAVE_MD5 1 -#define MD5_CTX Digest_CTX -#endif -#ifndef HAVE_OPENSSL_SHA_H -#ifdef CALG_SHA1 -#define SHA1_DIGEST_LENGTH 20 -#define HAVE_SHA1 1 -#define SHA1_CTX Digest_CTX -#endif -#ifdef CALG_SHA256 -#define SHA256_DIGEST_LENGTH 32 -#define HAVE_SHA256 1 -#define SHA256_CTX Digest_CTX -#endif -#ifdef CALG_SHA384 -#define SHA384_DIGEST_LENGTH 48 -#define HAVE_SHA384 1 -#define SHA384_CTX Digest_CTX -#endif -#ifdef CALG_SHA512 -#define SHA512_DIGEST_LENGTH 64 -#define HAVE_SHA512 1 -#define SHA512_CTX Digest_CTX -#endif -#endif /* HAVE_OPENSSL_SHA_H */ - -/* End of Win32 definitions. */ - -/* Tell libarchive code that we have simulations for these. */ -#ifndef HAVE_FTRUNCATE -#define HAVE_FTRUNCATE 1 -#endif -#ifndef HAVE_FUTIMES -#define HAVE_FUTIMES 1 -#endif -#ifndef HAVE_UTIMES -#define HAVE_UTIMES 1 -#endif -#ifndef HAVE_LINK -#define HAVE_LINK 1 -#endif /* Replacement POSIX function */ -extern int __la_chdir(const char *path); -extern int __la_chmod(const char *path, mode_t mode); -extern int __la_fcntl(int fd, int cmd, int val); -extern int __la_fstat(int fd, struct stat *st); -extern int __la_ftruncate(int fd, off_t length); -extern int __la_futimes(int fd, const struct __timeval *times); -extern int __la_link(const char *src, const char *dst); -extern __int64 __la_lseek(int fd, __int64 offset, int whence); -extern size_t __la_mbstowcs(wchar_t *wcstr, const char *mbstr, size_t nwchars); -extern int __la_mkdir(const char *path, mode_t mode); -extern int __la_open(const char *path, int flags, ...); -extern ssize_t __la_read(int fd, void *buf, size_t nbytes); -extern int __la_rmdir(const char *path); -extern int __la_stat(const char *path, struct stat *st); -extern int __la_unlink(const char *path); -extern int __la_utimes(const char *name, const struct __timeval *times); -extern pid_t __la_waitpid(pid_t wpid, int *status, int option); -extern ssize_t __la_write(int fd, const void *buf, size_t nbytes); - -#define _stat64i32(path, st) __la_stat(path, st) -#define _stat64(path, st) __la_stat(path, st) +extern int __la_fstat(int fd, struct stat *st); +extern int __la_lstat(const char *path, struct stat *st); +#if defined(__LA_LSEEK_NEEDED) +extern __int64 __la_lseek(int fd, __int64 offset, int whence); +#endif +extern int __la_open(const char *path, int flags, ...); +extern ssize_t __la_read(int fd, void *buf, size_t nbytes); +extern int __la_stat(const char *path, struct stat *st); +extern pid_t __la_waitpid(pid_t wpid, int *status, int option); +extern ssize_t __la_write(int fd, const void *buf, size_t nbytes); + +#define _stat64i32(path, st) __la_stat(path, st) +#define _stat64(path, st) __la_stat(path, st) /* for status returned by la_waitpid */ -#define WIFSIGNALED(sts) 0 -#define WTERMSIG(sts) 0 -#define WIFEXITED(sts) ((sts & 0x100) == 0) -#define WEXITSTATUS(sts) (sts & 0x0FF) - -/* Message digest function */ -#if !defined(HAVE_OPENSSL_MD5_H) && !defined(HAVE_OPENSSL_SHA_H) -#ifdef MD5_DIGEST_LENGTH -extern void MD5_Init(Digest_CTX *ctx); -extern void MD5_Update(Digest_CTX *ctx, const unsigned char *buf, - size_t len); -extern void MD5_Final(unsigned char buf[MD5_DIGEST_LENGTH], - Digest_CTX *ctx); -#endif -#ifdef SHA1_DIGEST_LENGTH -extern void SHA1_Init(Digest_CTX *ctx); -extern void SHA1_Update(Digest_CTX *ctx, const unsigned char *buf, - size_t len); -extern void SHA1_Final(unsigned char buf[SHA1_DIGEST_LENGTH], - Digest_CTX *ctx); -#endif -#ifdef SHA256_DIGEST_LENGTH -extern void SHA256_Init(Digest_CTX *ctx); -extern void SHA256_Update(Digest_CTX *ctx, const unsigned char *buf, - size_t len); -extern void SHA256_Final(unsigned char buf[SHA256_DIGEST_LENGTH], - Digest_CTX *ctx); -#endif -#ifdef SHA384_DIGEST_LENGTH -extern void SHA384_Init(Digest_CTX *ctx); -extern void SHA384_Update(Digest_CTX *ctx, const unsigned char *buf, - size_t len); -extern void SHA384_Final(unsigned char buf[SHA384_DIGEST_LENGTH], - Digest_CTX *ctx); -#endif -#ifdef SHA512_DIGEST_LENGTH -extern void SHA512_Init(Digest_CTX *ctx); -extern void SHA512_Update(Digest_CTX *ctx, const unsigned char *buf, - size_t len); -extern void SHA512_Final(unsigned char buf[SHA512_DIGEST_LENGTH], - Digest_CTX *ctx); -#endif +#define WIFEXITED(sts) ((sts & 0x100) == 0) +#define WEXITSTATUS(sts) (sts & 0x0FF) + +extern wchar_t *__la_win_permissive_name(const char *name); +extern wchar_t *__la_win_permissive_name_w(const wchar_t *wname); +extern void __la_dosmaperr(unsigned long e); +#define la_dosmaperr(e) __la_dosmaperr(e) + +#if defined(HAVE_WCRTOMB) && defined(__BORLANDC__) +typedef int mbstate_t; +size_t wcrtomb(char *, wchar_t, mbstate_t *); +#endif + +#if defined(_MSC_VER) && _MSC_VER < 1300 +WINBASEAPI BOOL WINAPI GetVolumePathNameW( + LPCWSTR lpszFileName, + LPWSTR lpszVolumePathName, + DWORD cchBufferLength + ); +# if _WIN32_WINNT < 0x0500 /* windows.h not providing 0x500 API */ +typedef struct _FILE_ALLOCATED_RANGE_BUFFER { + LARGE_INTEGER FileOffset; + LARGE_INTEGER Length; +} FILE_ALLOCATED_RANGE_BUFFER, *PFILE_ALLOCATED_RANGE_BUFFER; +# define FSCTL_SET_SPARSE \ + CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_WRITE_DATA) +# define FSCTL_QUERY_ALLOCATED_RANGES \ + CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 51, METHOD_NEITHER, FILE_READ_DATA) +# endif #endif #endif /* LIBARCHIVE_ARCHIVE_WINDOWS_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write.3 b/Utilities/cmlibarchive/libarchive/archive_write.3 index cb8c46ba5..f87386a8b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write.3 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle +.\" Copyright (c) 2003-2011 Tim Kientzle .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,110 +22,16 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/archive_write.3,v 1.25 2008/11/01 19:11:21 kientzle Exp $ +.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $ .\" -.Dd May 11, 2008 -.Dt archive_write 3 +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE 3 .Os .Sh NAME -.Nm archive_write_new , -.Nm archive_write_set_format_cpio , -.Nm archive_write_set_format_pax , -.Nm archive_write_set_format_pax_restricted , -.Nm archive_write_set_format_shar , -.Nm archive_write_set_format_shar_binary , -.Nm archive_write_set_format_ustar , -.Nm archive_write_get_bytes_per_block , -.Nm archive_write_set_bytes_per_block , -.Nm archive_write_set_bytes_in_last_block , -.Nm archive_write_set_compression_bzip2 , -.Nm archive_write_set_compression_compress , -.Nm archive_write_set_compression_gzip , -.Nm archive_write_set_compression_none , -.Nm archive_write_set_compression_program , -.Nm archive_write_set_compressor_options , -.Nm archive_write_set_format_options , -.Nm archive_write_set_options , -.Nm archive_write_open , -.Nm archive_write_open_fd , -.Nm archive_write_open_FILE , -.Nm archive_write_open_filename , -.Nm archive_write_open_memory , -.Nm archive_write_header , -.Nm archive_write_data , -.Nm archive_write_finish_entry , -.Nm archive_write_close , -.Nm archive_write_finish +.Nm archive_write .Nd functions for creating archives .Sh SYNOPSIS .In archive.h -.Ft struct archive * -.Fn archive_write_new "void" -.Ft int -.Fn archive_write_get_bytes_per_block "struct archive *" -.Ft int -.Fn archive_write_set_bytes_per_block "struct archive *" "int bytes_per_block" -.Ft int -.Fn archive_write_set_bytes_in_last_block "struct archive *" "int" -.Ft int -.Fn archive_write_set_compression_bzip2 "struct archive *" -.Ft int -.Fn archive_write_set_compression_compress "struct archive *" -.Ft int -.Fn archive_write_set_compression_gzip "struct archive *" -.Ft int -.Fn archive_write_set_compression_none "struct archive *" -.Ft int -.Fn archive_write_set_compression_program "struct archive *" "const char * cmd" -.Ft int -.Fn archive_write_set_format_cpio "struct archive *" -.Ft int -.Fn archive_write_set_format_pax "struct archive *" -.Ft int -.Fn archive_write_set_format_pax_restricted "struct archive *" -.Ft int -.Fn archive_write_set_format_shar "struct archive *" -.Ft int -.Fn archive_write_set_format_shar_binary "struct archive *" -.Ft int -.Fn archive_write_set_format_ustar "struct archive *" -.Ft int -.Fn archive_write_set_format_options "struct archive *" "const char *" -.Ft int -.Fn archive_write_set_compressor_options "struct archive *" "const char *" -.Ft int -.Fn archive_write_set_options "struct archive *" "const char *" -.Ft int -.Fo archive_write_open -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "archive_open_callback *" -.Fa "archive_write_callback *" -.Fa "archive_close_callback *" -.Fc -.Ft int -.Fn archive_write_open_fd "struct archive *" "int fd" -.Ft int -.Fn archive_write_open_FILE "struct archive *" "FILE *file" -.Ft int -.Fn archive_write_open_filename "struct archive *" "const char *filename" -.Ft int -.Fo archive_write_open_memory -.Fa "struct archive *" -.Fa "void *buffer" -.Fa "size_t bufferSize" -.Fa "size_t *outUsed" -.Fc -.Ft int -.Fn archive_write_header "struct archive *" "struct archive_entry *" -.Ft ssize_t -.Fn archive_write_data "struct archive *" "const void *" "size_t" -.Ft int -.Fn archive_write_finish_entry "struct archive *" -.Ft int -.Fn archive_write_close "struct archive *" -.Ft int -.Fn archive_write_finish "struct archive *" .Sh DESCRIPTION These functions provide a complete API for creating streaming archive files. @@ -133,316 +39,83 @@ The general process is to first create the .Tn struct archive object, set any desired options, initialize the archive, append entries, then close the archive and release all resources. -The following summary describes the functions in approximately -the order they are ordinarily used: -.Bl -tag -width indent -.It Fn archive_write_new -Allocates and initializes a +.\" +.Ss Create archive object +See +.Xr archive_write_new 3 . +.Pp +To write an archive, you must first obtain an initialized .Tn struct archive -object suitable for writing a tar archive. -.It Fn archive_write_set_bytes_per_block -Sets the block size used for writing the archive data. -Every call to the write callback function, except possibly the last one, will -use this value for the length. -The third parameter is a boolean that specifies whether or not the final block -written will be padded to the full block size. -If it is zero, the last block will not be padded. -If it is non-zero, padding will be added both before and after compression. -The default is to use a block size of 10240 bytes and to pad the last block. -Note that a block size of zero will suppress internal blocking -and cause writes to be sent directly to the write callback as they occur. -.It Fn archive_write_get_bytes_per_block -Retrieve the block size to be used for writing. -A value of -1 here indicates that the library should use default values. -A value of zero indicates that internal blocking is suppressed. -.It Fn archive_write_set_bytes_in_last_block -Sets the block size used for writing the last block. -If this value is zero, the last block will be padded to the same size -as the other blocks. -Otherwise, the final block will be padded to a multiple of this size. -In particular, setting it to 1 will cause the final block to not be padded. -For compressed output, any padding generated by this option -is applied only after the compression. -The uncompressed data is always unpadded. -The default is to pad the last block to the full block size (note that -.Fn archive_write_open_filename -will set this based on the file type). -Unlike the other -.Dq set -functions, this function can be called after the archive is opened. -.It Fn archive_write_get_bytes_in_last_block -Retrieve the currently-set value for last block size. -A value of -1 here indicates that the library should use default values. -.It Xo -.Fn archive_write_set_format_cpio , -.Fn archive_write_set_format_pax , -.Fn archive_write_set_format_pax_restricted , -.Fn archive_write_set_format_shar , -.Fn archive_write_set_format_shar_binary , -.Fn archive_write_set_format_ustar -.Xc -Sets the format that will be used for the archive. -The library can write -POSIX octet-oriented cpio format archives, -POSIX-standard -.Dq pax interchange -format archives, -traditional -.Dq shar -archives, -enhanced -.Dq binary -shar archives that store a variety of file attributes and handle binary files, +object from +.Fn archive_write_new . +.\" +.Ss Enable filters and formats, configure block size and padding +See +.Xr archive_write_filter 3 , +.Xr archive_write_format 3 and -POSIX-standard -.Dq ustar -archives. -The pax interchange format is a backwards-compatible tar format that -adds key/value attributes to each entry and supports arbitrary -filenames, linknames, uids, sizes, etc. -.Dq Restricted pax interchange format -is the library default; this is the same as pax format, but suppresses -the pax extended header for most normal files. -In most cases, this will result in ordinary ustar archives. -.It Xo -.Fn archive_write_set_compression_bzip2 , -.Fn archive_write_set_compression_compress , -.Fn archive_write_set_compression_gzip , -.Fn archive_write_set_compression_none -.Xc -The resulting archive will be compressed as specified. -Note that the compressed output is always properly blocked. -.It Fn archive_write_set_compression_program -The archive will be fed into the specified compression program. -The output of that program is blocked and written to the client -write callbacks. -.It Xo -.Fn archive_write_set_compressor_options , -.Fn archive_write_set_format_options , -.Fn archive_write_set_options -.Xc -Specifies options that will be passed to the currently-enabled -compressor and/or format writer. -The argument is a comma-separated list of individual options. -Individual options have one of the following forms: -.Bl -tag -compact -width indent -.It Ar option=value -The option/value pair will be provided to every module. -Modules that do not accept an option with this name will ignore it. -.It Ar option -The option will be provided to every module with a value of -.Dq 1 . -.It Ar !option -The option will be provided to every module with a NULL value. -.It Ar module:option=value , Ar module:option , Ar module:!option -As above, but the corresponding option and value will be provided -only to modules whose name matches -.Ar module . -.El -The return value will be -.Cm ARCHIVE_OK -if any module accepts the option, or -.Cm ARCHIVE_WARN -if no module accepted the option, or -.Cm ARCHIVE_FATAL -if there was a fatal error while attempting to process the option. +.Xr archive_write_blocksize 3 . .Pp -The currently supported options are: -.Bl -tag -compact -width indent -.It Compressor gzip -.Bl -tag -compact -width indent -.It Cm compression-level -The value is interpreted as a decimal integer specifying the -gzip compression level. -.El -.It Compressor xz -.Bl -tag -compact -width indent -.It Cm compression-level -The value is interpreted as a decimal integer specifying the -compression level. -.El -.It Format mtree -.Bl -tag -compact -width indent -.It Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname -Enable a particular keyword in the mtree output. -Prefix with an exclamation mark to disable the corresponding keyword. -The default is equivalent to -.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . -.It Cm all -Enables all of the above keywords. -.It Cm use-set -Enables generation of -.Cm /set -lines that specify default values for the following files and/or directories. -.It Cm indent -XXX needs explanation XXX -.El -.El -.It Fn archive_write_open -Freeze the settings, open the archive, and prepare for writing entries. -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. -.It Fn archive_write_open_fd -A convenience form of -.Fn archive_write_open -that accepts a file descriptor. -The -.Fn archive_write_open_fd -function is safe for use with tape drives or other -block-oriented devices. -.It Fn archive_write_open_FILE -A convenience form of +You can then modify this object for the desired operations with the +various +.Fn archive_write_set_XXX +functions. +In particular, you will need to invoke appropriate +.Fn archive_write_add_XXX +and +.Fn archive_write_set_XXX +functions to enable the corresponding compression and format +support. +.\" +.Ss Set options +See +.Xr archive_read_set_options 3 . +.\" +.Ss Open archive +See +.Xr archive_write_open 3 . +.Pp +Once you have prepared the +.Tn struct archive +object, you call .Fn archive_write_open -that accepts a +to actually open the archive and prepare it for writing. +There are several variants of this function; +the most basic expects you to provide pointers to several +functions that can provide blocks of bytes from the archive. +There are convenience forms that allow you to +specify a filename, file descriptor, .Ft "FILE *" -pointer. -Note that -.Fn archive_write_open_FILE -is not safe for writing to tape drives or other devices -that require correct blocking. -.It Fn archive_write_open_file -A deprecated synonym for -.Fn archive_write_open_filename . -.It Fn archive_write_open_filename -A convenience form of -.Fn archive_write_open -that accepts a filename. -A NULL argument indicates that the output should be written to standard output; -an argument of -.Dq - -will open a file with that name. -If you have not invoked -.Fn archive_write_set_bytes_in_last_block , -then -.Fn archive_write_open_filename -will adjust the last-block padding depending on the file: -it will enable padding when writing to standard output or -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 . -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 -that accepts a pointer to a block of memory that will receive -the archive. -The final -.Ft "size_t *" -argument points to a variable that will be updated -after each write to reflect how much of the buffer -is currently in use. -You should be careful to ensure that this variable -remains allocated until after the archive is -closed. -.It Fn archive_write_header -Build and write a header using the data in the provided -.Tn struct archive_entry -structure. +object, or a block of memory from which to write the archive data. +.\" +.Ss Produce archive See -.Xr archive_entry 3 -for information on creating and populating -.Tn struct archive_entry -objects. -.It Fn archive_write_data -Write data corresponding to the header just written. -Returns number of bytes written or -1 on error. -.It Fn archive_write_finish_entry -Close out the entry just written. -In particular, this writes out the final padding required by some formats. -Ordinarily, clients never need to call this, as it -is called automatically by -.Fn archive_write_next_header +.Xr archive_write_header 3 and -.Fn archive_write_close -as needed. -.It Fn archive_write_close -Complete the archive and invoke the close callback. -.It Fn archive_write_finish -Invokes -.Fn archive_write_close -if it was not invoked manually, then releases all resources. -Note that this function was declared to return -.Ft void -in libarchive 1.x, which made it impossible to detect errors when -.Fn archive_write_close -was invoked implicitly from this function. -This is corrected beginning with libarchive 2.0. -.El -More information about the -.Va struct archive -object and the overall design of the library can be found in the -.Xr libarchive 3 -overview. -.Sh IMPLEMENTATION -Compression support is built-in to libarchive, which uses zlib and bzlib -to handle gzip and bzip2 compression, respectively. -.Sh CLIENT CALLBACKS -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 : -.Bl -item -offset indent -.It -.Ft typedef int -.Fn archive_open_callback "struct archive *" "void *client_data" -.El -.Pp -The open callback is invoked by -.Fn archive_write_open . -It should return -.Cm ARCHIVE_OK -if the underlying file or data source is successfully -opened. -If the open fails, it should call -.Fn archive_set_error -to register an error code and message and return -.Cm ARCHIVE_FATAL . -.Bl -item -offset indent -.It -.Ft typedef ssize_t -.Fo archive_write_callback -.Fa "struct archive *" -.Fa "void *client_data" -.Fa "const void *buffer" -.Fa "size_t length" -.Fc -.El +.Xr archive_write_data 3 . .Pp -The write callback is invoked whenever the library -needs to write raw bytes to the archive. -For correct blocking, each call to the write callback function -should translate into a single -.Xr write 2 -system call. -This is especially critical when writing archives to tape drives. -On success, the write callback should return the -number of bytes actually written. -On error, the callback should invoke -.Fn archive_set_error -to register an error code and message and return -1. -.Bl -item -offset indent -.It -.Ft typedef int -.Fn archive_close_callback "struct archive *" "void *client_data" -.El +Individual archive entries are written in a three-step +process: +You first initialize a +.Tn struct archive_entry +structure with information about the new entry. +At a minimum, you should set the pathname of the +entry and provide a +.Va struct stat +with a valid +.Va st_mode +field, which specifies the type of object and +.Va st_size +field, which specifies the size of the data portion of the object. +.\" +.Ss Release resources +See +.Xr archive_write_free 3 . .Pp -The close callback is invoked by archive_close when -the archive processing is complete. -The callback should return -.Cm ARCHIVE_OK -on success. -On failure, the callback should invoke -.Fn archive_set_error -to register an error code and message and -return -.Cm ARCHIVE_FATAL. +After all entries have been written, use the +.Fn archive_write_free +function to release all resources. +.\" .Sh EXAMPLE The following sketch illustrates basic usage of the library. In this example, @@ -453,6 +126,9 @@ and .Xr close 2 system calls. .Bd -literal -offset indent +#ifdef __linux__ +#define _FILE_OFFSET_BITS 64 +#endif #include #include #include @@ -461,8 +137,8 @@ system calls. #include struct mydata { - const char *name; - int fd; + const char *name; + int fd; }; int @@ -508,7 +184,7 @@ write_archive(const char *outname, const char **filename) a = archive_write_new(); mydata->name = outname; - archive_write_set_compression_gzip(a); + archive_write_add_filter_gzip(a); archive_write_set_format_ustar(a); archive_write_open(a, mydata, myopen, mywrite, myclose); while (*filename) { @@ -517,76 +193,35 @@ write_archive(const char *outname, const char **filename) archive_entry_copy_stat(entry, &st); archive_entry_set_pathname(entry, *filename); archive_write_header(a, entry); - fd = open(*filename, O_RDONLY); - len = read(fd, buff, sizeof(buff)); - while ( len > 0 ) { - archive_write_data(a, buff, len); - len = read(fd, buff, sizeof(buff)); + if ((fd = open(*filename, O_RDONLY)) != -1) { + len = read(fd, buff, sizeof(buff)); + while ( len > 0 ) { + archive_write_data(a, buff, len); + len = read(fd, buff, sizeof(buff)); + } + close(fd); } archive_entry_free(entry); filename++; } - archive_write_finish(a); + archive_write_free(a); } int main(int argc, const char **argv) { - const char *outname; - argv++; - outname = argv++; - write_archive(outname, argv); - return 0; + const char *outname; + argv++; + outname = argv++; + write_archive(outname, argv); + return 0; } .Ed -.Sh RETURN VALUES -Most functions return -.Cm ARCHIVE_OK -(zero) on success, or one of several non-zero -error codes for errors. -Specific error codes include: -.Cm ARCHIVE_RETRY -for operations that might succeed if retried, -.Cm ARCHIVE_WARN -for unusual conditions that do not prevent further operations, and -.Cm ARCHIVE_FATAL -for serious errors that make remaining operations impossible. -The -.Fn archive_errno -and -.Fn archive_error_string -functions can be used to retrieve an appropriate error code and a -textual error message. -.Pp -.Fn archive_write_new -returns a pointer to a newly-allocated -.Tn struct archive -object. -.Pp -.Fn archive_write_data -returns a count of the number of bytes actually written. -On error, -1 is returned and the -.Fn archive_errno -and -.Fn archive_error_string -functions will return appropriate values. -Note that if the client-provided write callback function -returns a non-zero value, that error will be propagated back to the caller -through whatever API function resulted in that call, which -may include -.Fn archive_write_header , -.Fn archive_write_data , -.Fn archive_write_close , -or -.Fn archive_write_finish . -The client callback can call -.Fn archive_set_error -to provide values that can then be retrieved by -.Fn archive_errno -and -.Fn archive_error_string . .Sh SEE ALSO .Xr tar 1 , .Xr libarchive 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , .Xr tar 5 .Sh HISTORY The diff --git a/Utilities/cmlibarchive/libarchive/archive_write.c b/Utilities/cmlibarchive/libarchive/archive_write.c index f9cc3f9d4..b4b3867f0 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write.c +++ b/Utilities/cmlibarchive/libarchive/archive_write.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,12 +24,12 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write.c,v 1.27 2008/03/14 23:09:02 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write.c 201099 2009-12-28 03:03:00Z kientzle $"); /* * This file contains the "essential" portions of the write API, that * is, stuff that will essentially always be used by any client that - * actually needs to write a archive. Optional pieces have been, as + * actually needs to write an archive. Optional pieces have been, as * far as possible, separated out into separate files to reduce * needlessly bloating statically-linked clients. */ @@ -37,6 +37,9 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write.c,v 1.27 2008/03/14 23:09:0 #ifdef HAVE_SYS_WAIT_H #include #endif +#ifdef HAVE_ERRNO_H +#include +#endif #ifdef HAVE_LIMITS_H #include #endif @@ -59,26 +62,42 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write.c,v 1.27 2008/03/14 23:09:0 static struct archive_vtable *archive_write_vtable(void); -static int _archive_write_close(struct archive *); -static int _archive_write_finish(struct archive *); -static int _archive_write_header(struct archive *, struct archive_entry *); -static int _archive_write_finish_entry(struct archive *); -static ssize_t _archive_write_data(struct archive *, const void *, size_t); +static int _archive_filter_code(struct archive *, int); +static const char *_archive_filter_name(struct archive *, int); +static int64_t _archive_filter_bytes(struct archive *, int); +static int _archive_write_filter_count(struct archive *); +static int _archive_write_close(struct archive *); +static int _archive_write_free(struct archive *); +static int _archive_write_header(struct archive *, struct archive_entry *); +static int _archive_write_finish_entry(struct archive *); +static ssize_t _archive_write_data(struct archive *, const void *, size_t); + +struct archive_none { + size_t buffer_size; + size_t avail; + char *buffer; + char *next; +}; static struct archive_vtable * archive_write_vtable(void) { - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_close = _archive_write_close; - av.archive_finish = _archive_write_finish; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - } - return (&av); + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_close = _archive_write_close; + av.archive_filter_bytes = _archive_filter_bytes; + av.archive_filter_code = _archive_filter_code; + av.archive_filter_name = _archive_filter_name; + av.archive_filter_count = _archive_write_filter_count; + av.archive_free = _archive_write_free; + av.archive_write_header = _archive_write_header; + av.archive_write_finish_entry = _archive_write_finish_entry; + av.archive_write_data = _archive_write_data; + inited = 1; + } + return (&av); } /* @@ -87,219 +106,340 @@ archive_write_vtable(void) struct archive * archive_write_new(void) { - struct archive_write *a; - unsigned char *nulls; - - a = (struct archive_write *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_WRITE_MAGIC; - a->archive.state = ARCHIVE_STATE_NEW; - a->archive.vtable = archive_write_vtable(); - /* - * The value 10240 here matches the traditional tar default, - * but is otherwise arbitrary. - * TODO: Set the default block size from the format selected. - */ - a->bytes_per_block = 10240; - a->bytes_in_last_block = -1; /* Default */ - - /* Initialize a block of nulls for padding purposes. */ - a->null_length = 1024; - nulls = (unsigned char *)malloc(a->null_length); - if (nulls == NULL) { - free(a); - return (NULL); - } - memset(nulls, 0, a->null_length); - a->nulls = nulls; - /* - * Set default compression, but don't set a default format. - * Were we to set a default format here, we would force every - * client to link in support for that format, even if they didn't - * ever use it. - */ - archive_write_set_compression_none(&a->archive); - return (&a->archive); + struct archive_write *a; + unsigned char *nulls; + + a = (struct archive_write *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_WRITE_MAGIC; + a->archive.state = ARCHIVE_STATE_NEW; + a->archive.vtable = archive_write_vtable(); + /* + * The value 10240 here matches the traditional tar default, + * but is otherwise arbitrary. + * TODO: Set the default block size from the format selected. + */ + a->bytes_per_block = 10240; + a->bytes_in_last_block = -1; /* Default */ + + /* Initialize a block of nulls for padding purposes. */ + a->null_length = 1024; + nulls = (unsigned char *)malloc(a->null_length); + if (nulls == NULL) { + free(a); + return (NULL); + } + memset(nulls, 0, a->null_length); + a->nulls = nulls; + return (&a->archive); } /* - * Set write options for the format. Returns 0 if successful. + * Set the block size. Returns 0 if successful. */ int -archive_write_set_format_options(struct archive *_a, const char *s) +archive_write_set_bytes_per_block(struct archive *_a, int bytes_per_block) { - struct archive_write *a = (struct archive_write *)_a; - char key[64], val[64]; - int len, r, ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_format_options"); - archive_clear_error(&a->archive); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - if (a->format_options == NULL) - /* This format does not support option. */ - return (ARCHIVE_OK); - - while ((len = __archive_parse_options(s, a->format_name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = a->format_options(a, key, NULL); - else - r = a->format_options(a, key, val); - if (r == ARCHIVE_FATAL) - return (r); - if (r < ARCHIVE_OK) { /* This key was not handled. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", key); - ret = ARCHIVE_WARN; - } - s += len; - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Malformed options string."); - return (ARCHIVE_WARN); - } - return (ret); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_bytes_per_block"); + a->bytes_per_block = bytes_per_block; + return (ARCHIVE_OK); } /* - * Set write options for the compressor. Returns 0 if successful. + * Get the current block size. -1 if it has never been set. */ int -archive_write_set_compressor_options(struct archive *_a, const char *s) +archive_write_get_bytes_per_block(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - char key[64], val[64]; - int len, r; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compressor_options"); - archive_clear_error(&a->archive); - - if (s == NULL || *s == '\0') - return (ARCHIVE_OK); - if (a->compressor.options == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", s); - /* This compressor does not support option. */ - return (ARCHIVE_WARN); - } - - while ((len = __archive_parse_options(s, a->archive.compression_name, - sizeof(key), key, sizeof(val), val)) > 0) { - if (val[0] == '\0') - r = a->compressor.options(a, key, NULL); - else - r = a->compressor.options(a, key, val); - if (r == ARCHIVE_FATAL) - return (r); - if (r < ARCHIVE_OK) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Unsupported option ``%s''", key); - ret = ARCHIVE_WARN; - } - s += len; - } - if (len < 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Illegal format options."); - return (ARCHIVE_WARN); - } - return (ret); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_get_bytes_per_block"); + return (a->bytes_per_block); } /* - * Set write options for the format and the compressor. Returns 0 if successful. + * Set the size for the last block. + * Returns 0 if successful. */ int -archive_write_set_options(struct archive *_a, const char *s) +archive_write_set_bytes_in_last_block(struct archive *_a, int bytes) { - int r1, r2; - - r1 = archive_write_set_format_options(_a, s); - if (r1 < ARCHIVE_WARN) - return (r1); - r2 = archive_write_set_compressor_options(_a, s); - if (r2 < ARCHIVE_WARN) - return (r2); - if (r1 == ARCHIVE_WARN && r2 == ARCHIVE_WARN) - return (ARCHIVE_WARN); - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_set_bytes_in_last_block"); + a->bytes_in_last_block = bytes; + return (ARCHIVE_OK); } /* - * Set the block size. Returns 0 if successful. + * Return the value set above. -1 indicates it has not been set. */ int -archive_write_set_bytes_per_block(struct archive *_a, int bytes_per_block) +archive_write_get_bytes_in_last_block(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_bytes_per_block"); - a->bytes_per_block = bytes_per_block; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_get_bytes_in_last_block"); + return (a->bytes_in_last_block); } /* - * Get the current block size. -1 if it has never been set. + * dev/ino of a file to be rejected. Used to prevent adding + * an archive to itself recursively. */ int -archive_write_get_bytes_per_block(struct archive *_a) +archive_write_set_skip_file(struct archive *_a, int64_t d, int64_t i) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_get_bytes_per_block"); - return (a->bytes_per_block); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_set_skip_file"); + a->skip_file_set = 1; + a->skip_file_dev = d; + a->skip_file_ino = i; + return (ARCHIVE_OK); } /* - * Set the size for the last block. - * Returns 0 if successful. + * Allocate and return the next filter structure. */ -int -archive_write_set_bytes_in_last_block(struct archive *_a, int bytes) +struct archive_write_filter * +__archive_write_allocate_filter(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_set_bytes_in_last_block"); - a->bytes_in_last_block = bytes; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f; + + f = calloc(1, sizeof(*f)); + f->archive = _a; + if (a->filter_first == NULL) + a->filter_first = f; + else + a->filter_last->next_filter = f; + a->filter_last = f; + return f; } /* - * Return the value set above. -1 indicates it has not been set. + * Write data to a particular filter. */ int -archive_write_get_bytes_in_last_block(struct archive *_a) +__archive_write_filter(struct archive_write_filter *f, + const void *buff, size_t length) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_get_bytes_in_last_block"); - return (a->bytes_in_last_block); + int r; + if (length == 0) + return(ARCHIVE_OK); + r = (f->write)(f, buff, length); + f->bytes_written += length; + return (r); } +/* + * Open a filter. + */ +int +__archive_write_open_filter(struct archive_write_filter *f) +{ + if (f->open == NULL) + return (ARCHIVE_OK); + return (f->open)(f); +} /* - * dev/ino of a file to be rejected. Used to prevent adding - * an archive to itself recursively. + * Close a filter. */ int -archive_write_set_skip_file(struct archive *_a, dev_t d, ino_t i) +__archive_write_close_filter(struct archive_write_filter *f) +{ + if (f->close != NULL) + return (f->close)(f); + if (f->next_filter != NULL) + return (__archive_write_close_filter(f->next_filter)); + return (ARCHIVE_OK); +} + +int +__archive_write_output(struct archive_write *a, const void *buff, size_t length) +{ + return (__archive_write_filter(a->filter_first, buff, length)); +} + +int +__archive_write_nulls(struct archive_write *a, size_t length) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; - return (ARCHIVE_OK); + if (length == 0) + return (ARCHIVE_OK); + + while (length > 0) { + size_t to_write = length < a->null_length ? length : a->null_length; + int r = __archive_write_output(a, a->nulls, to_write); + if (r < ARCHIVE_OK) + return (r); + length -= to_write; + } + return (ARCHIVE_OK); } +static int +archive_write_client_open(struct archive_write_filter *f) +{ + struct archive_write *a = (struct archive_write *)f->archive; + struct archive_none *state; + void *buffer; + size_t buffer_size; + + f->bytes_per_block = archive_write_get_bytes_per_block(f->archive); + f->bytes_in_last_block = + archive_write_get_bytes_in_last_block(f->archive); + buffer_size = f->bytes_per_block; + + state = (struct archive_none *)calloc(1, sizeof(*state)); + buffer = (char *)malloc(buffer_size); + if (state == NULL || buffer == NULL) { + free(state); + free(buffer); + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for output buffering"); + return (ARCHIVE_FATAL); + } + + state->buffer_size = buffer_size; + state->buffer = buffer; + state->next = state->buffer; + state->avail = state->buffer_size; + f->data = state; + + if (a->client_opener == NULL) + return (ARCHIVE_OK); + return (a->client_opener(f->archive, a->client_data)); +} + +static int +archive_write_client_write(struct archive_write_filter *f, + const void *_buff, size_t length) +{ + struct archive_write *a = (struct archive_write *)f->archive; + struct archive_none *state = (struct archive_none *)f->data; + const char *buff = (const char *)_buff; + ssize_t remaining, to_copy; + ssize_t bytes_written; + + remaining = length; + + /* + * If there is no buffer for blocking, just pass the data + * straight through to the client write callback. In + * particular, this supports "no write delay" operation for + * special applications. Just set the block size to zero. + */ + if (state->buffer_size == 0) { + while (remaining > 0) { + bytes_written = (a->client_writer)(&a->archive, + a->client_data, buff, remaining); + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + remaining -= bytes_written; + buff += bytes_written; + } + return (ARCHIVE_OK); + } + + /* If the copy buffer isn't empty, try to fill it. */ + if (state->avail < state->buffer_size) { + /* If buffer is not empty... */ + /* ... copy data into buffer ... */ + to_copy = ((size_t)remaining > state->avail) ? + state->avail : (size_t)remaining; + memcpy(state->next, buff, to_copy); + state->next += to_copy; + state->avail -= to_copy; + buff += to_copy; + remaining -= to_copy; + /* ... if it's full, write it out. */ + if (state->avail == 0) { + char *p = state->buffer; + size_t to_write = state->buffer_size; + while (to_write > 0) { + bytes_written = (a->client_writer)(&a->archive, + a->client_data, p, to_write); + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + if ((size_t)bytes_written > to_write) { + archive_set_error(&(a->archive), + -1, "write overrun"); + return (ARCHIVE_FATAL); + } + p += bytes_written; + to_write -= bytes_written; + } + state->next = state->buffer; + state->avail = state->buffer_size; + } + } + + while ((size_t)remaining > state->buffer_size) { + /* Write out full blocks directly to client. */ + bytes_written = (a->client_writer)(&a->archive, + a->client_data, buff, state->buffer_size); + if (bytes_written <= 0) + return (ARCHIVE_FATAL); + buff += bytes_written; + remaining -= bytes_written; + } + + if (remaining > 0) { + /* Copy last bit into copy buffer. */ + memcpy(state->next, buff, remaining); + state->next += remaining; + state->avail -= remaining; + } + return (ARCHIVE_OK); +} + +static int +archive_write_client_close(struct archive_write_filter *f) +{ + struct archive_write *a = (struct archive_write *)f->archive; + struct archive_none *state = (struct archive_none *)f->data; + ssize_t block_length; + ssize_t target_block_length; + ssize_t bytes_written; + int ret = ARCHIVE_OK; + + /* If there's pending data, pad and write the last block */ + if (state->next != state->buffer) { + block_length = state->buffer_size - state->avail; + + /* Tricky calculation to determine size of last block */ + if (a->bytes_in_last_block <= 0) + /* Default or Zero: pad to full block */ + target_block_length = a->bytes_per_block; + else + /* Round to next multiple of bytes_in_last_block. */ + target_block_length = a->bytes_in_last_block * + ( (block_length + a->bytes_in_last_block - 1) / + a->bytes_in_last_block); + if (target_block_length > a->bytes_per_block) + target_block_length = a->bytes_per_block; + if (block_length < target_block_length) { + memset(state->next, 0, + target_block_length - block_length); + block_length = target_block_length; + } + bytes_written = (a->client_writer)(&a->archive, + a->client_data, state->buffer, block_length); + ret = bytes_written <= 0 ? ARCHIVE_FATAL : ARCHIVE_OK; + } + if (a->client_closer) + (*a->client_closer)(&a->archive, a->client_data); + free(state->buffer); + free(state); + a->client_data = NULL; + return (ret); +} /* * Open the archive using the current settings. @@ -309,97 +449,146 @@ archive_write_open(struct archive *_a, void *client_data, archive_open_callback *opener, archive_write_callback *writer, archive_close_callback *closer) { - struct archive_write *a = (struct archive_write *)_a; - int ret; - - ret = ARCHIVE_OK; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_open"); - archive_clear_error(&a->archive); - a->archive.state = ARCHIVE_STATE_HEADER; - a->client_data = client_data; - a->client_writer = writer; - a->client_opener = opener; - a->client_closer = closer; - ret = (a->compressor.init)(a); - if (a->format_init && ret == ARCHIVE_OK) - ret = (a->format_init)(a); - return (ret); + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *client_filter; + int ret, r1; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_open"); + archive_clear_error(&a->archive); + + a->client_writer = writer; + a->client_opener = opener; + a->client_closer = closer; + 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; + + ret = __archive_write_open_filter(a->filter_first); + if (ret < ARCHIVE_WARN) { + r1 = __archive_write_close_filter(a->filter_first); + return (r1 < ret ? r1 : ret); + } + + a->archive.state = ARCHIVE_STATE_HEADER; + if (a->format_init) + ret = (a->format_init)(a); + return (ret); } - /* * Close out the archive. - * - * Be careful: user might just call write_new and then write_finish. - * Don't assume we actually wrote anything or performed any non-trivial - * initialization. */ static int _archive_write_close(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int r = ARCHIVE_OK, r1 = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_close"); - - /* Finish the last entry. */ - if (a->archive.state & ARCHIVE_STATE_DATA) - r = ((a->format_finish_entry)(a)); - - /* Finish off the archive. */ - if (a->format_finish != NULL) { - r1 = (a->format_finish)(a); - if (r1 < r) - r = r1; - } - - /* Release format resources. */ - if (a->format_destroy != NULL) { - r1 = (a->format_destroy)(a); - if (r1 < r) - r = r1; - } - - /* Finish the compression and close the stream. */ - if (a->compressor.finish != NULL) { - r1 = (a->compressor.finish)(a); - if (r1 < r) - r = r1; - } - - /* Close out the client stream. */ - if (a->client_closer != NULL) { - r1 = (a->client_closer)(&a->archive, a->client_data); - if (r1 < r) - r = r1; - } - - a->archive.state = ARCHIVE_STATE_CLOSED; - return (r); + struct archive_write *a = (struct archive_write *)_a; + int r = ARCHIVE_OK, r1 = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, + "archive_write_close"); + if (a->archive.state == ARCHIVE_STATE_NEW + || a->archive.state == ARCHIVE_STATE_CLOSED) + return (ARCHIVE_OK); /* Okay to close() when not open. */ + + archive_clear_error(&a->archive); + + /* Finish the last entry. */ + if (a->archive.state == ARCHIVE_STATE_DATA) + r = ((a->format_finish_entry)(a)); + + /* Finish off the archive. */ + /* TODO: have format closers invoke compression close. */ + if (a->format_close != NULL) { + r1 = (a->format_close)(a); + if (r1 < r) + r = r1; + } + + /* Finish the compression and close the stream. */ + r1 = __archive_write_close_filter(a->filter_first); + if (r1 < r) + r = r1; + + if (a->archive.state != ARCHIVE_STATE_FATAL) + a->archive.state = ARCHIVE_STATE_CLOSED; + return (r); +} + +static int +_archive_write_filter_count(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *p = a->filter_first; + int count = 0; + while(p) { + count++; + p = p->next_filter; + } + return count; +} + +void +__archive_write_filters_free(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + int r = ARCHIVE_OK, r1; + + while (a->filter_first != NULL) { + struct archive_write_filter *next + = a->filter_first->next_filter; + if (a->filter_first->free != NULL) { + r1 = (*a->filter_first->free)(a->filter_first); + if (r > r1) + r = r1; + } + free(a->filter_first); + a->filter_first = next; + } + a->filter_last = NULL; } /* * Destroy the archive structure. + * + * Be careful: user might just call write_new and then write_free. + * Don't assume we actually wrote anything or performed any non-trivial + * initialization. */ static int -_archive_write_finish(struct archive *_a) +_archive_write_free(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int r = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_finish"); - if (a->archive.state != ARCHIVE_STATE_CLOSED) - r = archive_write_close(&a->archive); - - /* Release various dynamic buffers. */ - free((void *)(uintptr_t)(const void *)a->nulls); - archive_string_free(&a->archive.error_string); - a->archive.magic = 0; - free(a); - return (r); + struct archive_write *a = (struct archive_write *)_a; + int r = ARCHIVE_OK, r1; + + if (_a == NULL) + return (ARCHIVE_OK); + /* It is okay to call free() in state FATAL. */ + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_free"); + if (a->archive.state != ARCHIVE_STATE_FATAL) + r = archive_write_close(&a->archive); + + /* Release format resources. */ + if (a->format_free != NULL) { + r1 = (a->format_free)(a); + if (r1 < r) + r = r1; + } + + __archive_write_filters_free(_a); + + /* Release various dynamic buffers. */ + free((void *)(uintptr_t)(const void *)a->nulls); + archive_string_free(&a->archive.error_string); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a); + return (r); } /* @@ -408,49 +597,65 @@ _archive_write_finish(struct archive *_a) static int _archive_write_header(struct archive *_a, struct archive_entry *entry) { - struct archive_write *a = (struct archive_write *)_a; - int ret, r2; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_DATA | ARCHIVE_STATE_HEADER, "archive_write_header"); - archive_clear_error(&a->archive); - - /* In particular, "retry" and "fatal" get returned immediately. */ - ret = archive_write_finish_entry(&a->archive); - if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN) - return (ret); - - if (a->skip_file_dev != 0 && - archive_entry_dev(entry) == a->skip_file_dev && - a->skip_file_ino != 0 && - archive_entry_ino64(entry) == a->skip_file_ino) { - archive_set_error(&a->archive, 0, - "Can't add archive to itself"); - return (ARCHIVE_FAILED); - } - - /* Format and write header. */ - r2 = ((a->format_write_header)(a, entry)); - if (r2 < ret) - ret = r2; - - a->archive.state = ARCHIVE_STATE_DATA; - return (ret); + struct archive_write *a = (struct archive_write *)_a; + int ret, r2; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_DATA | ARCHIVE_STATE_HEADER, "archive_write_header"); + archive_clear_error(&a->archive); + + if (a->format_write_header == NULL) { + archive_set_error(&(a->archive), -1, + "Format must be set before you can write to an archive."); + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + + /* In particular, "retry" and "fatal" get returned immediately. */ + ret = archive_write_finish_entry(&a->archive); + if (ret == ARCHIVE_FATAL) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + if (ret < ARCHIVE_OK && ret != ARCHIVE_WARN) + return (ret); + + if (a->skip_file_set && + archive_entry_dev_is_set(entry) && + archive_entry_ino_is_set(entry) && + archive_entry_dev(entry) == a->skip_file_dev && + archive_entry_ino64(entry) == a->skip_file_ino) { + archive_set_error(&a->archive, 0, + "Can't add archive to itself"); + return (ARCHIVE_FAILED); + } + + /* Format and write header. */ + r2 = ((a->format_write_header)(a, entry)); + if (r2 == ARCHIVE_FATAL) { + a->archive.state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); + } + if (r2 < ret) + ret = r2; + + a->archive.state = ARCHIVE_STATE_DATA; + return (ret); } static int _archive_write_finish_entry(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_finish_entry"); - if (a->archive.state & ARCHIVE_STATE_DATA) - ret = (a->format_finish_entry)(a); - a->archive.state = ARCHIVE_STATE_HEADER; - return (ret); + struct archive_write *a = (struct archive_write *)_a; + int ret = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_finish_entry"); + if (a->archive.state & ARCHIVE_STATE_DATA) + ret = (a->format_finish_entry)(a); + a->archive.state = ARCHIVE_STATE_HEADER; + return (ret); } /* @@ -459,9 +664,46 @@ _archive_write_finish_entry(struct archive *_a) static ssize_t _archive_write_data(struct archive *_a, const void *buff, size_t s) { - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_data"); - archive_clear_error(&a->archive); - return ((a->format_write_data)(a, buff, s)); + struct archive_write *a = (struct archive_write *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data"); + archive_clear_error(&a->archive); + return ((a->format_write_data)(a, buff, s)); +} + +static struct archive_write_filter * +filter_lookup(struct archive *_a, int n) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = a->filter_first; + if (n == -1) + return a->filter_last; + if (n < 0) + return NULL; + while (n > 0 && f != NULL) { + f = f->next_filter; + --n; + } + return f; +} + +static int +_archive_filter_code(struct archive *_a, int n) +{ + struct archive_write_filter *f = filter_lookup(_a, n); + return f == NULL ? -1 : f->code; +} + +static const char * +_archive_filter_name(struct archive *_a, int n) +{ + struct archive_write_filter *f = filter_lookup(_a, n); + return f != NULL ? f->name : NULL; +} + +static int64_t +_archive_filter_bytes(struct archive *_a, int n) +{ + struct archive_write_filter *f = filter_lookup(_a, n); + return f == NULL ? -1 : f->bytes_written; } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c new file mode 100644 index 000000000..096a6a4c7 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_bzip2.c @@ -0,0 +1,335 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * 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: head/lib/libarchive/archive_write_set_compression_bzip2.c 201091 2009-12-28 02:22:41Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_write_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_bzip2(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_bzip2(a)); +} +#endif + +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) +int +archive_write_add_filter_bzip2(struct archive *a) +{ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "bzip2 compression not supported on this platform"); + return (ARCHIVE_FATAL); +} +#else +/* Don't compile this if we don't have bzlib. */ + +struct private_data { + int compression_level; + bz_stream stream; + int64_t total_in; + char *compressed; + size_t compressed_buffer_size; +}; + +/* + * Yuck. bzlib.h is not const-correct, so I need this one bit + * of ugly hackery to convert a const * pointer to a non-const pointer. + */ +#define SET_NEXT_IN(st,src) \ + (st)->stream.next_in = (char *)(uintptr_t)(const void *)(src) + +static int archive_compressor_bzip2_close(struct archive_write_filter *); +static int archive_compressor_bzip2_free(struct archive_write_filter *); +static int archive_compressor_bzip2_open(struct archive_write_filter *); +static int archive_compressor_bzip2_options(struct archive_write_filter *, + const char *, const char *); +static int archive_compressor_bzip2_write(struct archive_write_filter *, + const void *, size_t); +static int drive_compressor(struct archive_write_filter *, + struct private_data *, int finishing); + +/* + * Add a bzip2 compression filter to this write handle. + */ +int +archive_write_add_filter_bzip2(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + struct private_data *data; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_bzip2"); + + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + data->compression_level = 9; /* default */ + + f->data = data; + f->options = &archive_compressor_bzip2_options; + f->close = &archive_compressor_bzip2_close; + f->free = &archive_compressor_bzip2_free; + f->open = &archive_compressor_bzip2_open; + f->code = ARCHIVE_COMPRESSION_BZIP2; + f->name = "bzip2"; + return (ARCHIVE_OK); +} + +/* + * Setup callback. + */ +static int +archive_compressor_bzip2_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != 0) + return (ret); + + /* TODO: Find a better way to size this. (Maybe look at the */ + /* block size expected by the following filter?) */ + if (data->compressed == NULL) { + data->compressed_buffer_size = 65536; + data->compressed + = (char *)malloc(data->compressed_buffer_size); + if (data->compressed == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + return (ARCHIVE_FATAL); + } + } + + memset(&data->stream, 0, sizeof(data->stream)); + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + f->write = archive_compressor_bzip2_write; + + /* Initialize compression library */ + ret = BZ2_bzCompressInit(&(data->stream), + data->compression_level, 0, 30); + if (ret == BZ_OK) { + f->data = data; + return (ARCHIVE_OK); + } + + /* Library setup failed: clean up. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + + /* Override the error message if we know what really went wrong. */ + switch (ret) { + case BZ_PARAM_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "invalid setup parameter"); + break; + case BZ_MEM_ERROR: + archive_set_error(f->archive, ENOMEM, + "Internal error initializing compression library: " + "out of memory"); + break; + case BZ_CONFIG_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "mis-compiled library"); + break; + } + + return (ARCHIVE_FATAL); + +} + +/* + * Set write options. + */ +static int +archive_compressor_bzip2_options(struct archive_write_filter *f, + const char *key, const char *value) +{ + struct private_data *data = (struct private_data *)f->data; + + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') + return (ARCHIVE_WARN); + data->compression_level = value[0] - '0'; + /* Make '0' be a synonym for '1'. */ + /* This way, bzip2 compressor supports the same 0..9 + * range of levels as gzip. */ + if (data->compression_level < 1) + data->compression_level = 1; + return (ARCHIVE_OK); + } + + return (ARCHIVE_WARN); +} + +/* + * Write data to the compressed stream. + * + * Returns ARCHIVE_OK if all data written, error otherwise. + */ +static int +archive_compressor_bzip2_write(struct archive_write_filter *f, + const void *buff, size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + + /* Update statistics */ + data->total_in += length; + + /* Compress input data to output buffer */ + SET_NEXT_IN(data, buff); + data->stream.avail_in = length; + if (drive_compressor(f, data, 0)) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + + +/* + * Finish the compression. + */ +static int +archive_compressor_bzip2_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret, r1; + + /* Finish compression cycle. */ + ret = drive_compressor(f, data, 1); + if (ret == ARCHIVE_OK) { + /* Write the last block */ + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size - data->stream.avail_out); + } + + switch (BZ2_bzCompressEnd(&(data->stream))) { + case BZ_OK: + break; + default: + archive_set_error(f->archive, ARCHIVE_ERRNO_PROGRAMMER, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + } + + r1 = __archive_write_close_filter(f->next_filter); + return (r1 < ret ? r1 : ret); +} + +static int +archive_compressor_bzip2_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + free(data->compressed); + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Utility function to push input data through compressor, writing + * full output blocks as necessary. + * + * Note that this handles both the regular write case (finishing == + * false) and the end-of-archive case (finishing == true). + */ +static int +drive_compressor(struct archive_write_filter *f, + struct private_data *data, int finishing) +{ + int ret; + + for (;;) { + if (data->stream.avail_out == 0) { + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size); + if (ret != ARCHIVE_OK) { + /* TODO: Handle this write failure */ + return (ARCHIVE_FATAL); + } + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + } + + /* If there's nothing to do, we're done. */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + + ret = BZ2_bzCompress(&(data->stream), + finishing ? BZ_FINISH : BZ_RUN); + + switch (ret) { + case BZ_RUN_OK: + /* In non-finishing case, did compressor + * consume everything? */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + break; + case BZ_FINISH_OK: /* Finishing: There's more work to do */ + break; + case BZ_STREAM_END: /* Finishing: all done */ + /* Only occurs in finishing case */ + return (ARCHIVE_OK); + default: + /* Any other return value indicates an error */ + archive_set_error(f->archive, + ARCHIVE_ERRNO_PROGRAMMER, + "Bzip2 compression failed;" + " BZ2_bzCompress() returned %d", + ret); + return (ARCHIVE_FATAL); + } + } +} + +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c new file mode 100644 index 000000000..465ff0e77 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_compress.c @@ -0,0 +1,445 @@ +/*- + * Copyright (c) 2008 Joerg Sonnenberger + * 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. + */ + +/*- + * Copyright (c) 1985, 1986, 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Diomidis Spinellis and James A. Woods, derived from original + * work by Spencer Thomas and Joseph Orost. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "archive_platform.h" + +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_compress.c 201111 2009-12-28 03:33:05Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_write_private.h" + +#define HSIZE 69001 /* 95% occupancy */ +#define HSHIFT 8 /* 8 - trunc(log2(HSIZE / 65536)) */ +#define CHECK_GAP 10000 /* Ratio check interval. */ + +#define MAXCODE(bits) ((1 << (bits)) - 1) + +/* + * the next two codes should not be changed lightly, as they must not + * lie within the contiguous general code space. + */ +#define FIRST 257 /* First free entry. */ +#define CLEAR 256 /* Table clear output code. */ + +struct private_data { + int64_t in_count, out_count, checkpoint; + + int code_len; /* Number of bits/code. */ + int cur_maxcode; /* Maximum code, given n_bits. */ + int max_maxcode; /* Should NEVER generate this code. */ + int hashtab [HSIZE]; + unsigned short codetab [HSIZE]; + int first_free; /* First unused entry. */ + int compress_ratio; + + int cur_code, cur_fcode; + + int bit_offset; + unsigned char bit_buf; + + unsigned char *compressed; + size_t compressed_buffer_size; + size_t compressed_offset; +}; + +static int archive_compressor_compress_open(struct archive_write_filter *); +static int archive_compressor_compress_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_compress_close(struct archive_write_filter *); +static int archive_compressor_compress_free(struct archive_write_filter *); + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_compress(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_compress(a)); +} +#endif + +/* + * Add a compress filter to this write handle. + */ +int +archive_write_add_filter_compress(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_compress"); + f->open = &archive_compressor_compress_open; + f->code = ARCHIVE_COMPRESSION_COMPRESS; + f->name = "compress"; + return (ARCHIVE_OK); +} + +/* + * Setup callback. + */ +static int +archive_compressor_compress_open(struct archive_write_filter *f) +{ + int ret; + struct private_data *state; + + f->code = ARCHIVE_COMPRESSION_COMPRESS; + f->name = "compress"; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + state = (struct private_data *)calloc(1, sizeof(*state)); + if (state == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression"); + return (ARCHIVE_FATAL); + } + + state->compressed_buffer_size = 65536; + state->compressed = malloc(state->compressed_buffer_size); + + if (state->compressed == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + free(state); + return (ARCHIVE_FATAL); + } + + f->write = archive_compressor_compress_write; + f->close = archive_compressor_compress_close; + f->free = archive_compressor_compress_free; + + state->max_maxcode = 0x10000; /* Should NEVER generate this code. */ + state->in_count = 0; /* Length of input. */ + state->bit_buf = 0; + state->bit_offset = 0; + state->out_count = 3; /* Includes 3-byte header mojo. */ + state->compress_ratio = 0; + state->checkpoint = CHECK_GAP; + state->code_len = 9; + state->cur_maxcode = MAXCODE(state->code_len); + state->first_free = FIRST; + + memset(state->hashtab, 0xff, sizeof(state->hashtab)); + + /* Prime output buffer with a gzip header. */ + state->compressed[0] = 0x1f; /* Compress */ + state->compressed[1] = 0x9d; + state->compressed[2] = 0x90; /* Block mode, 16bit max */ + state->compressed_offset = 3; + + f->data = state; + return (0); +} + +/*- + * Output the given code. + * Inputs: + * code: A n_bits-bit integer. If == -1, then EOF. This assumes + * that n_bits <= (long)wordsize - 1. + * Outputs: + * Outputs code to the file. + * Assumptions: + * Chars are 8 bits long. + * Algorithm: + * Maintain a BITS character long buffer (so that 8 codes will + * fit in it exactly). Use the VAX insv instruction to insert each + * code in turn. When the buffer fills up empty it and start over. + */ + +static const unsigned char rmask[9] = + {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; + +static int +output_byte(struct archive_write_filter *f, unsigned char c) +{ + struct private_data *state = f->data; + + state->compressed[state->compressed_offset++] = c; + ++state->out_count; + + if (state->compressed_buffer_size == state->compressed_offset) { + int ret = __archive_write_filter(f->next_filter, + state->compressed, state->compressed_buffer_size); + if (ret != ARCHIVE_OK) + return ARCHIVE_FATAL; + state->compressed_offset = 0; + } + + return ARCHIVE_OK; +} + +static int +output_code(struct archive_write_filter *f, int ocode) +{ + struct private_data *state = f->data; + int bits, ret, clear_flg, bit_offset; + + clear_flg = ocode == CLEAR; + + /* + * Since ocode is always >= 8 bits, only need to mask the first + * hunk on the left. + */ + bit_offset = state->bit_offset % 8; + state->bit_buf |= (ocode << bit_offset) & 0xff; + output_byte(f, state->bit_buf); + + bits = state->code_len - (8 - bit_offset); + ocode >>= 8 - bit_offset; + /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ + if (bits >= 8) { + output_byte(f, ocode & 0xff); + ocode >>= 8; + bits -= 8; + } + /* Last bits. */ + state->bit_offset += state->code_len; + state->bit_buf = ocode & rmask[bits]; + if (state->bit_offset == state->code_len * 8) + state->bit_offset = 0; + + /* + * If the next entry is going to be too big for the ocode size, + * then increase it, if possible. + */ + if (clear_flg || state->first_free > state->cur_maxcode) { + /* + * Write the whole buffer, because the input side won't + * discover the size increase until after it has read it. + */ + if (state->bit_offset > 0) { + while (state->bit_offset < state->code_len * 8) { + ret = output_byte(f, state->bit_buf); + if (ret != ARCHIVE_OK) + return ret; + state->bit_offset += 8; + state->bit_buf = 0; + } + } + state->bit_buf = 0; + state->bit_offset = 0; + + if (clear_flg) { + state->code_len = 9; + state->cur_maxcode = MAXCODE(state->code_len); + } else { + state->code_len++; + if (state->code_len == 16) + state->cur_maxcode = state->max_maxcode; + else + state->cur_maxcode = MAXCODE(state->code_len); + } + } + + return (ARCHIVE_OK); +} + +static int +output_flush(struct archive_write_filter *f) +{ + struct private_data *state = f->data; + int ret; + + /* At EOF, write the rest of the buffer. */ + if (state->bit_offset % 8) { + state->code_len = (state->bit_offset % 8 + 7) / 8; + ret = output_byte(f, state->bit_buf); + if (ret != ARCHIVE_OK) + return ret; + } + + return (ARCHIVE_OK); +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_compress_write(struct archive_write_filter *f, + const void *buff, size_t length) +{ + struct private_data *state = (struct private_data *)f->data; + int i; + int ratio; + int c, disp, ret; + const unsigned char *bp; + + if (length == 0) + return ARCHIVE_OK; + + bp = buff; + + if (state->in_count == 0) { + state->cur_code = *bp++; + ++state->in_count; + --length; + } + + while (length--) { + c = *bp++; + state->in_count++; + state->cur_fcode = (c << 16) + state->cur_code; + i = ((c << HSHIFT) ^ state->cur_code); /* Xor hashing. */ + + if (state->hashtab[i] == state->cur_fcode) { + state->cur_code = state->codetab[i]; + continue; + } + if (state->hashtab[i] < 0) /* Empty slot. */ + goto nomatch; + /* Secondary hash (after G. Knott). */ + if (i == 0) + disp = 1; + else + disp = HSIZE - i; + probe: + if ((i -= disp) < 0) + i += HSIZE; + + if (state->hashtab[i] == state->cur_fcode) { + state->cur_code = state->codetab[i]; + continue; + } + if (state->hashtab[i] >= 0) + goto probe; + nomatch: + ret = output_code(f, state->cur_code); + if (ret != ARCHIVE_OK) + return ret; + state->cur_code = c; + if (state->first_free < state->max_maxcode) { + state->codetab[i] = state->first_free++; /* code -> hashtable */ + state->hashtab[i] = state->cur_fcode; + continue; + } + if (state->in_count < state->checkpoint) + continue; + + state->checkpoint = state->in_count + CHECK_GAP; + + if (state->in_count <= 0x007fffff) + ratio = state->in_count * 256 / state->out_count; + else if ((ratio = state->out_count / 256) == 0) + ratio = 0x7fffffff; + else + ratio = state->in_count / ratio; + + if (ratio > state->compress_ratio) + state->compress_ratio = ratio; + else { + state->compress_ratio = 0; + memset(state->hashtab, 0xff, sizeof(state->hashtab)); + state->first_free = FIRST; + ret = output_code(f, CLEAR); + if (ret != ARCHIVE_OK) + return ret; + } + } + + return (ARCHIVE_OK); +} + + +/* + * Finish the compression... + */ +static int +archive_compressor_compress_close(struct archive_write_filter *f) +{ + struct private_data *state = (struct private_data *)f->data; + int ret, ret2; + + ret = output_code(f, state->cur_code); + if (ret != ARCHIVE_OK) + goto cleanup; + ret = output_flush(f); + if (ret != ARCHIVE_OK) + goto cleanup; + + /* Write the last block */ + ret = __archive_write_filter(f->next_filter, + state->compressed, state->compressed_offset); +cleanup: + ret2 = __archive_write_close_filter(f->next_filter); + if (ret > ret2) + ret = ret2; + free(state->compressed); + free(state); + return (ret); +} + +static int +archive_compressor_compress_free(struct archive_write_filter *f) +{ + (void)f; /* UNUSED */ + return (ARCHIVE_OK); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c new file mode 100644 index 000000000..d08ee265b --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_gzip.c @@ -0,0 +1,356 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * 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: head/lib/libarchive/archive_write_set_compression_gzip.c 201081 2009-12-28 02:04:42Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_write_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_gzip(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_gzip(a)); +} +#endif + +#ifndef HAVE_ZLIB_H +int +archive_write_add_filter_gzip(struct archive *a) +{ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "gzip compression not supported on this platform"); + return (ARCHIVE_FATAL); +} +#else +/* Don't compile this if we don't have zlib. */ + +struct private_data { + int compression_level; + z_stream stream; + int64_t total_in; + unsigned char *compressed; + size_t compressed_buffer_size; + unsigned long crc; +}; + +/* + * Yuck. zlib.h is not const-correct, so I need this one bit + * of ugly hackery to convert a const * pointer to a non-const pointer. + */ +#define SET_NEXT_IN(st,src) \ + (st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src) + +static int archive_compressor_gzip_options(struct archive_write_filter *, + const char *, const char *); +static int archive_compressor_gzip_open(struct archive_write_filter *); +static int archive_compressor_gzip_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_gzip_close(struct archive_write_filter *); +static int archive_compressor_gzip_free(struct archive_write_filter *); +static int drive_compressor(struct archive_write_filter *, + struct private_data *, int finishing); + + +/* + * Add a gzip compression filter to this write handle. + */ +int +archive_write_add_filter_gzip(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + struct private_data *data; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_gzip"); + + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + f->data = data; + data->compression_level = Z_DEFAULT_COMPRESSION; + f->open = &archive_compressor_gzip_open; + f->options = &archive_compressor_gzip_options; + f->close = &archive_compressor_gzip_close; + f->free = &archive_compressor_gzip_free; + f->code = ARCHIVE_COMPRESSION_GZIP; + f->name = "gzip"; + return (ARCHIVE_OK); +} + +/* + * Setup callback. + */ +static int +archive_compressor_gzip_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + time_t t; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + if (data->compressed == NULL) { + data->compressed_buffer_size = 65536; + data->compressed + = (unsigned char *)malloc(data->compressed_buffer_size); + if (data->compressed == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + return (ARCHIVE_FATAL); + } + } + + data->crc = crc32(0L, NULL, 0); + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + + /* Prime output buffer with a gzip header. */ + t = time(NULL); + data->compressed[0] = 0x1f; /* GZip signature bytes */ + data->compressed[1] = 0x8b; + data->compressed[2] = 0x08; /* "Deflate" compression */ + data->compressed[3] = 0; /* No options */ + data->compressed[4] = (t)&0xff; /* Timestamp */ + data->compressed[5] = (t>>8)&0xff; + data->compressed[6] = (t>>16)&0xff; + data->compressed[7] = (t>>24)&0xff; + data->compressed[8] = 0; /* No deflate options */ + data->compressed[9] = 3; /* OS=Unix */ + data->stream.next_out += 10; + data->stream.avail_out -= 10; + + f->write = archive_compressor_gzip_write; + + /* Initialize compression library. */ + ret = deflateInit2(&(data->stream), + data->compression_level, + Z_DEFLATED, + -15 /* < 0 to suppress zlib header */, + 8, + Z_DEFAULT_STRATEGY); + + if (ret == Z_OK) { + f->data = data; + return (ARCHIVE_OK); + } + + /* Library setup failed: clean up. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, "Internal error " + "initializing compression library"); + + /* Override the error message if we know what really went wrong. */ + switch (ret) { + case Z_STREAM_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid setup parameter"); + break; + case Z_MEM_ERROR: + archive_set_error(f->archive, ENOMEM, "Internal error initializing " + "compression library"); + break; + case Z_VERSION_ERROR: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid library version"); + break; + } + + return (ARCHIVE_FATAL); +} + +/* + * Set write options. + */ +static int +archive_compressor_gzip_options(struct archive_write_filter *f, const char *key, + const char *value) +{ + struct private_data *data = (struct private_data *)f->data; + + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') + return (ARCHIVE_WARN); + data->compression_level = value[0] - '0'; + return (ARCHIVE_OK); + } + return (ARCHIVE_WARN); +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_gzip_write(struct archive_write_filter *f, const void *buff, + size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + /* Update statistics */ + data->crc = crc32(data->crc, (const Bytef *)buff, length); + data->total_in += length; + + /* Compress input data to output buffer */ + SET_NEXT_IN(data, buff); + data->stream.avail_in = length; + if ((ret = drive_compressor(f, data, 0)) != ARCHIVE_OK) + return (ret); + + return (ARCHIVE_OK); +} + +/* + * Finish the compression... + */ +static int +archive_compressor_gzip_close(struct archive_write_filter *f) +{ + unsigned char trailer[8]; + struct private_data *data = (struct private_data *)f->data; + int ret, r1; + + /* Finish compression cycle */ + ret = drive_compressor(f, data, 1); + if (ret == ARCHIVE_OK) { + /* Write the last compressed data. */ + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size - data->stream.avail_out); + } + if (ret == ARCHIVE_OK) { + /* Build and write out 8-byte trailer. */ + trailer[0] = (data->crc)&0xff; + trailer[1] = (data->crc >> 8)&0xff; + trailer[2] = (data->crc >> 16)&0xff; + trailer[3] = (data->crc >> 24)&0xff; + trailer[4] = (data->total_in)&0xff; + trailer[5] = (data->total_in >> 8)&0xff; + trailer[6] = (data->total_in >> 16)&0xff; + trailer[7] = (data->total_in >> 24)&0xff; + ret = __archive_write_filter(f->next_filter, trailer, 8); + } + + switch (deflateEnd(&(data->stream))) { + case Z_OK: + break; + default: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + } + r1 = __archive_write_close_filter(f->next_filter); + return (r1 < ret ? r1 : ret); +} + +static int +archive_compressor_gzip_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + free(data->compressed); + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Utility function to push input data through compressor, + * writing full output blocks as necessary. + * + * Note that this handles both the regular write case (finishing == + * false) and the end-of-archive case (finishing == true). + */ +static int +drive_compressor(struct archive_write_filter *f, + struct private_data *data, int finishing) +{ + int ret; + + for (;;) { + if (data->stream.avail_out == 0) { + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + } + + /* If there's nothing to do, we're done. */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + + ret = deflate(&(data->stream), + finishing ? Z_FINISH : Z_NO_FLUSH ); + + switch (ret) { + case Z_OK: + /* In non-finishing case, check if compressor + * consumed everything */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + /* In finishing case, this return always means + * there's more work */ + break; + case Z_STREAM_END: + /* This return can only occur in finishing case. */ + return (ARCHIVE_OK); + default: + /* Any other return value indicates an error. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "GZip compression failed:" + " deflate() call returned status %d", + ret); + return (ARCHIVE_FATAL); + } + } +} + +#endif /* HAVE_ZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_file_nonexistent.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c similarity index 75% rename from Utilities/cmlibarchive/libarchive/test/test_read_file_nonexistent.c rename to Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c index f47fca405..3c06c642e 100644 --- a/Utilities/cmlibarchive/libarchive/test/test_read_file_nonexistent.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_none.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2009 Tim Kientzle + * Copyright (c) 2003-2010 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,16 +22,22 @@ * (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 "test.h" -__FBSDID("$FreeBSD$"); -DEFINE_TEST(test_read_file_nonexistent) +#include "archive_platform.h" +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_compression_none.c 201080 2009-12-28 02:03:54Z kientzle $"); + +#include "archive.h" + +int +archive_write_set_compression_none(struct archive *a) { - struct archive* a = archive_read_new(); - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_FATAL, - archive_read_open_filename(a, "notexistent.tar", 512)); - archive_read_finish(a); + (void)a; /* UNUSED */ + return (ARCHIVE_OK); } - +int +archive_write_add_filter_none(struct archive *a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c new file mode 100644 index 000000000..3dcc9df7b --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_program.c @@ -0,0 +1,327 @@ +/*- + * Copyright (c) 2007 Joerg Sonnenberger + * 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: head/lib/libarchive/archive_write_set_compression_program.c 201104 2009-12-28 03:14:30Z kientzle $"); + +#ifdef HAVE_SYS_WAIT_H +# include +#endif +#ifdef HAVE_ERRNO_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include +#endif +#ifdef HAVE_STDLIB_H +# include +#endif +#ifdef HAVE_STRING_H +# include +#endif + +#include "archive.h" +#include "archive_private.h" +#include "archive_write_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_program(struct archive *a, const char *cmd) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_program(a, cmd)); +} +#endif + +/* This capability is only available on POSIX systems. */ +#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ + !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) + +/* + * On non-Posix systems, allow the program to build, but choke if + * this function is actually invoked. + */ +int +archive_write_add_filter_program(struct archive *_a, const char *cmd) +{ + archive_set_error(_a, -1, + "External compression programs not supported on this platform"); + return (ARCHIVE_FATAL); +} + +#else + +#include "filter_fork.h" + +struct private_data { + char *cmd; + char *description; + pid_t child; + int child_stdin, child_stdout; + + char *child_buf; + size_t child_buf_len, child_buf_avail; +}; + +static int archive_compressor_program_open(struct archive_write_filter *); +static int archive_compressor_program_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_program_close(struct archive_write_filter *); +static int archive_compressor_program_free(struct archive_write_filter *); + +/* + * Add a filter to this write handle that passes all data through an + * external program. + */ +int +archive_write_add_filter_program(struct archive *_a, const char *cmd) +{ + struct archive_write_filter *f = __archive_write_allocate_filter(_a); + struct archive_write *a = (struct archive_write *)_a; + struct private_data *data; + static const char *prefix = "Program: "; + archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_program"); + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + data->cmd = strdup(cmd); + data->description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); + strcpy(data->description, prefix); + strcat(data->description, cmd); + + f->name = data->description; + f->data = data; + f->open = &archive_compressor_program_open; + f->code = ARCHIVE_COMPRESSION_PROGRAM; + return (ARCHIVE_OK); +} + +/* + * Setup callback. + */ +static int +archive_compressor_program_open(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + if (data->child_buf == NULL) { + data->child_buf_len = 65536; + data->child_buf_avail = 0; + data->child_buf = malloc(data->child_buf_len); + + if (data->child_buf == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate compression buffer"); + return (ARCHIVE_FATAL); + } + } + + if ((data->child = __archive_create_child(data->cmd, + &data->child_stdin, &data->child_stdout)) == -1) { + archive_set_error(f->archive, EINVAL, + "Can't initialise filter"); + return (ARCHIVE_FATAL); + } + + f->write = archive_compressor_program_write; + f->close = archive_compressor_program_close; + f->free = archive_compressor_program_free; + return (0); +} + +static ssize_t +child_write(struct archive_write_filter *f, const char *buf, size_t buf_len) +{ + struct private_data *data = f->data; + ssize_t ret; + + if (data->child_stdin == -1) + return (-1); + + if (buf_len == 0) + return (-1); + +restart_write: + do { + ret = write(data->child_stdin, buf, buf_len); + } while (ret == -1 && errno == EINTR); + + if (ret > 0) + return (ret); + if (ret == 0) { + close(data->child_stdin); + data->child_stdin = -1; + fcntl(data->child_stdout, F_SETFL, 0); + return (0); + } + if (ret == -1 && errno != EAGAIN) + return (-1); + + if (data->child_stdout == -1) { + fcntl(data->child_stdin, F_SETFL, 0); + __archive_check_child(data->child_stdin, data->child_stdout); + goto restart_write; + } + + do { + ret = read(data->child_stdout, + data->child_buf + data->child_buf_avail, + data->child_buf_len - data->child_buf_avail); + } while (ret == -1 && errno == EINTR); + + if (ret == 0 || (ret == -1 && errno == EPIPE)) { + close(data->child_stdout); + data->child_stdout = -1; + fcntl(data->child_stdin, F_SETFL, 0); + goto restart_write; + } + if (ret == -1 && errno == EAGAIN) { + __archive_check_child(data->child_stdin, data->child_stdout); + goto restart_write; + } + if (ret == -1) + return (-1); + + data->child_buf_avail += ret; + + ret = __archive_write_filter(f->next_filter, + data->child_buf, data->child_buf_avail); + if (ret <= 0) + return (-1); + + if ((size_t)ret < data->child_buf_avail) { + memmove(data->child_buf, data->child_buf + ret, + data->child_buf_avail - ret); + } + data->child_buf_avail -= ret; + goto restart_write; +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_program_write(struct archive_write_filter *f, + const void *buff, size_t length) +{ + ssize_t ret; + const char *buf; + + buf = buff; + while (length > 0) { + ret = child_write(f, buf, length); + if (ret == -1 || ret == 0) { + archive_set_error(f->archive, EIO, + "Can't write to filter"); + return (ARCHIVE_FATAL); + } + length -= ret; + buf += ret; + } + return (ARCHIVE_OK); +} + + +/* + * Finish the compression... + */ +static int +archive_compressor_program_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret, r1, status; + ssize_t bytes_read; + + ret = 0; + close(data->child_stdin); + data->child_stdin = -1; + fcntl(data->child_stdout, F_SETFL, 0); + + for (;;) { + do { + bytes_read = read(data->child_stdout, + data->child_buf + data->child_buf_avail, + data->child_buf_len - data->child_buf_avail); + } while (bytes_read == -1 && errno == EINTR); + + if (bytes_read == 0 || (bytes_read == -1 && errno == EPIPE)) + break; + + if (bytes_read == -1) { + archive_set_error(f->archive, errno, + "Read from filter failed unexpectedly."); + ret = ARCHIVE_FATAL; + goto cleanup; + } + data->child_buf_avail += bytes_read; + + ret = __archive_write_filter(f->next_filter, + data->child_buf, data->child_buf_avail); + if (ret != ARCHIVE_OK) { + ret = ARCHIVE_FATAL; + goto cleanup; + } + data->child_buf_avail = 0; + } + +cleanup: + /* Shut down the child. */ + if (data->child_stdin != -1) + close(data->child_stdin); + if (data->child_stdout != -1) + close(data->child_stdout); + while (waitpid(data->child, &status, 0) == -1 && errno == EINTR) + continue; + + if (status != 0) { + archive_set_error(f->archive, EIO, + "Filter exited with failure."); + ret = ARCHIVE_FATAL; + } + r1 = __archive_write_close_filter(f->next_filter); + return (r1 < ret ? r1 : ret); +} + +static int +archive_compressor_program_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + free(data->cmd); + free(data->description); + free(data->child_buf); + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c new file mode 100644 index 000000000..b06775224 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_add_filter_xz.c @@ -0,0 +1,502 @@ +/*- + * Copyright (c) 2009,2010 Michihiro NAKAJIMA + * Copyright (c) 2003-2010 Tim Kientzle + * 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: head/lib/libarchive/archive_write_set_compression_xz.c 201108 2009-12-28 03:28:21Z kientzle $"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include +#ifdef HAVE_LZMA_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_private.h" +#include "archive_write_private.h" + +#if ARCHIVE_VERSION_NUMBER < 4000000 +int +archive_write_set_compression_lzip(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_lzip(a)); +} + +int +archive_write_set_compression_lzma(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_lzma(a)); +} + +int +archive_write_set_compression_xz(struct archive *a) +{ + __archive_write_filters_free(a); + return (archive_write_add_filter_xz(a)); +} + +#endif + +#ifndef HAVE_LZMA_H +int +archive_write_add_filter_xz(struct archive *a) +{ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "xz compression not supported on this platform"); + return (ARCHIVE_FATAL); +} + +int +archive_write_add_filter_lzma(struct archive *a) +{ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma compression not supported on this platform"); + return (ARCHIVE_FATAL); +} + +int +archive_write_add_filter_lzip(struct archive *a) +{ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma compression not supported on this platform"); + return (ARCHIVE_FATAL); +} +#else +/* Don't compile this if we don't have liblzma. */ + +struct private_data { + int compression_level; + lzma_stream stream; + lzma_filter lzmafilters[2]; + lzma_options_lzma lzma_opt; + int64_t total_in; + unsigned char *compressed; + size_t compressed_buffer_size; + int64_t total_out; + /* the CRC32 value of uncompressed data for lzip */ + uint32_t crc32; +}; + +static int archive_compressor_xz_options(struct archive_write_filter *, + const char *, const char *); +static int archive_compressor_xz_open(struct archive_write_filter *); +static int archive_compressor_xz_write(struct archive_write_filter *, + const void *, size_t); +static int archive_compressor_xz_close(struct archive_write_filter *); +static int archive_compressor_xz_free(struct archive_write_filter *); +static int drive_compressor(struct archive_write_filter *, + struct private_data *, int finishing); + +struct option_value { + uint32_t dict_size; + uint32_t nice_len; + lzma_match_finder mf; +}; +static const struct option_value option_values[] = { + { 1 << 16, 32, LZMA_MF_HC3}, + { 1 << 20, 32, LZMA_MF_HC3}, + { 3 << 19, 32, LZMA_MF_HC4}, + { 1 << 21, 32, LZMA_MF_BT4}, + { 3 << 20, 32, LZMA_MF_BT4}, + { 1 << 22, 32, LZMA_MF_BT4}, + { 1 << 23, 64, LZMA_MF_BT4}, + { 1 << 24, 64, LZMA_MF_BT4}, + { 3 << 23, 64, LZMA_MF_BT4}, + { 1 << 25, 64, LZMA_MF_BT4} +}; + +static int +common_setup(struct archive_write_filter *f) +{ + struct private_data *data; + struct archive_write *a = (struct archive_write *)f->archive; + data = calloc(1, sizeof(*data)); + if (data == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + f->data = data; + data->compression_level = LZMA_PRESET_DEFAULT; + f->open = &archive_compressor_xz_open; + f->close = archive_compressor_xz_close; + f->free = archive_compressor_xz_free; + f->options = &archive_compressor_xz_options; + return (ARCHIVE_OK); +} + +/* + * Add an xz compression filter to this write handle. + */ +int +archive_write_add_filter_xz(struct archive *_a) +{ + struct archive_write_filter *f; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_xz"); + f = __archive_write_allocate_filter(_a); + r = common_setup(f); + if (r == ARCHIVE_OK) { + f->code = ARCHIVE_COMPRESSION_XZ; + f->name = "xz"; + } + return (r); +} + +/* LZMA is handled identically, we just need a different compression + * code set. (The liblzma setup looks at the code to determine + * the one place that XZ and LZMA require different handling.) */ +int +archive_write_add_filter_lzma(struct archive *_a) +{ + struct archive_write_filter *f; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_lzma"); + f = __archive_write_allocate_filter(_a); + r = common_setup(f); + if (r == ARCHIVE_OK) { + f->code = ARCHIVE_COMPRESSION_LZMA; + f->name = "lzma"; + } + return (r); +} + +int +archive_write_add_filter_lzip(struct archive *_a) +{ + struct archive_write_filter *f; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_add_filter_lzip"); + f = __archive_write_allocate_filter(_a); + r = common_setup(f); + if (r == ARCHIVE_OK) { + f->code = ARCHIVE_COMPRESSION_LZIP; + f->name = "lzip"; + } + return (r); +} + +static int +archive_compressor_xz_init_stream(struct archive_write_filter *f, + struct private_data *data) +{ + static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT; + int ret; + + data->stream = lzma_stream_init_data; + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + if (f->code == ARCHIVE_COMPRESSION_XZ) + ret = lzma_stream_encoder(&(data->stream), + data->lzmafilters, LZMA_CHECK_CRC64); + else if (f->code == ARCHIVE_COMPRESSION_LZMA) + ret = lzma_alone_encoder(&(data->stream), &data->lzma_opt); + else { /* ARCHIVE_COMPRESSION_LZIP */ + int dict_size = data->lzma_opt.dict_size; + int ds, log2dic, wedges; + + /* Calculate a coded dictionary size */ + if (dict_size < (1 << 12) || dict_size > (1 << 27)) { + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Unacceptable dictionary dize for lzip: %d", + dict_size); + return (ARCHIVE_FATAL); + } + for (log2dic = 27; log2dic >= 12; log2dic--) { + if (dict_size & (1 << log2dic)) + break; + } + if (dict_size > (1 << log2dic)) { + log2dic++; + wedges = + ((1 << log2dic) - dict_size) / (1 << (log2dic - 4)); + } else + wedges = 0; + ds = ((wedges << 5) & 0xe0) | (log2dic & 0x1f); + + data->crc32 = 0; + /* Make a header */ + data->compressed[0] = 0x4C; + data->compressed[1] = 0x5A; + data->compressed[2] = 0x49; + data->compressed[3] = 0x50; + data->compressed[4] = 1;/* Version */ + data->compressed[5] = (unsigned char)ds; + data->stream.next_out += 6; + data->stream.avail_out -= 6; + + ret = lzma_raw_encoder(&(data->stream), data->lzmafilters); + } + if (ret == LZMA_OK) + return (ARCHIVE_OK); + + switch (ret) { + case LZMA_MEM_ERROR: + archive_set_error(f->archive, ENOMEM, + "Internal error initializing compression library: " + "Cannot allocate memory"); + break; + default: + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "It's a bug in liblzma"); + break; + } + return (ARCHIVE_FATAL); +} + +/* + * Setup callback. + */ +static int +archive_compressor_xz_open(struct archive_write_filter *f) +{ + struct private_data *data = f->data; + int ret; + + ret = __archive_write_open_filter(f->next_filter); + if (ret != ARCHIVE_OK) + return (ret); + + if (data->compressed == NULL) { + data->compressed_buffer_size = 65536; + data->compressed + = (unsigned char *)malloc(data->compressed_buffer_size); + if (data->compressed == NULL) { + archive_set_error(f->archive, ENOMEM, + "Can't allocate data for compression buffer"); + return (ARCHIVE_FATAL); + } + } + + f->write = archive_compressor_xz_write; + + /* Initialize compression library. */ + if (f->code == ARCHIVE_COMPRESSION_LZIP) { + const struct option_value *val = + &option_values[data->compression_level]; + + data->lzma_opt.dict_size = val->dict_size; + data->lzma_opt.preset_dict = NULL; + data->lzma_opt.preset_dict_size = 0; + data->lzma_opt.lc = LZMA_LC_DEFAULT; + data->lzma_opt.lp = LZMA_LP_DEFAULT; + data->lzma_opt.pb = LZMA_PB_DEFAULT; + data->lzma_opt.mode = + data->compression_level<= 2? LZMA_MODE_FAST:LZMA_MODE_NORMAL; + data->lzma_opt.nice_len = val->nice_len; + data->lzma_opt.mf = val->mf; + data->lzma_opt.depth = 0; + data->lzmafilters[0].id = LZMA_FILTER_LZMA1; + data->lzmafilters[0].options = &data->lzma_opt; + data->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ + } else { + if (lzma_lzma_preset(&data->lzma_opt, data->compression_level)) { + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + } + data->lzmafilters[0].id = LZMA_FILTER_LZMA2; + data->lzmafilters[0].options = &data->lzma_opt; + data->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ + } + ret = archive_compressor_xz_init_stream(f, data); + if (ret == LZMA_OK) { + f->data = data; + return (0); + } + return (ARCHIVE_FATAL); +} + +/* + * Set write options. + */ +static int +archive_compressor_xz_options(struct archive_write_filter *f, + const char *key, const char *value) +{ + struct private_data *data = (struct private_data *)f->data; + + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') + return (ARCHIVE_WARN); + data->compression_level = value[0] - '0'; + if (data->compression_level > 6) + data->compression_level = 6; + return (ARCHIVE_OK); + } + + return (ARCHIVE_WARN); +} + +/* + * Write data to the compressed stream. + */ +static int +archive_compressor_xz_write(struct archive_write_filter *f, + const void *buff, size_t length) +{ + struct private_data *data = (struct private_data *)f->data; + int ret; + + /* Update statistics */ + data->total_in += length; + if (f->code == ARCHIVE_COMPRESSION_LZIP) + data->crc32 = lzma_crc32(buff, length, data->crc32); + + /* Compress input data to output buffer */ + data->stream.next_in = buff; + data->stream.avail_in = length; + if ((ret = drive_compressor(f, data, 0)) != ARCHIVE_OK) + return (ret); + + return (ARCHIVE_OK); +} + + +/* + * Finish the compression... + */ +static int +archive_compressor_xz_close(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + int ret, r1; + + ret = drive_compressor(f, data, 1); + if (ret == ARCHIVE_OK) { + data->total_out += + data->compressed_buffer_size - data->stream.avail_out; + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size - data->stream.avail_out); + if (f->code == ARCHIVE_COMPRESSION_LZIP && ret == ARCHIVE_OK) { + archive_le32enc(data->compressed, data->crc32); + archive_le64enc(data->compressed+4, data->total_in); + archive_le64enc(data->compressed+12, data->total_out + 20); + ret = __archive_write_filter(f->next_filter, + data->compressed, 20); + } + } + lzma_end(&(data->stream)); + r1 = __archive_write_close_filter(f->next_filter); + return (r1 < ret ? r1 : ret); +} + +static int +archive_compressor_xz_free(struct archive_write_filter *f) +{ + struct private_data *data = (struct private_data *)f->data; + free(data->compressed); + free(data); + f->data = NULL; + return (ARCHIVE_OK); +} + +/* + * Utility function to push input data through compressor, + * writing full output blocks as necessary. + * + * Note that this handles both the regular write case (finishing == + * false) and the end-of-archive case (finishing == true). + */ +static int +drive_compressor(struct archive_write_filter *f, + struct private_data *data, int finishing) +{ + int ret; + + for (;;) { + if (data->stream.avail_out == 0) { + data->total_out += data->compressed_buffer_size; + ret = __archive_write_filter(f->next_filter, + data->compressed, + data->compressed_buffer_size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + data->stream.next_out = data->compressed; + data->stream.avail_out = data->compressed_buffer_size; + } + + /* If there's nothing to do, we're done. */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + + ret = lzma_code(&(data->stream), + finishing ? LZMA_FINISH : LZMA_RUN ); + + switch (ret) { + case LZMA_OK: + /* In non-finishing case, check if compressor + * consumed everything */ + if (!finishing && data->stream.avail_in == 0) + return (ARCHIVE_OK); + /* In finishing case, this return always means + * there's more work */ + break; + case LZMA_STREAM_END: + /* This return can only occur in finishing case. */ + if (finishing) + return (ARCHIVE_OK); + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "lzma compression data error"); + return (ARCHIVE_FATAL); + case LZMA_MEMLIMIT_ERROR: + archive_set_error(f->archive, ENOMEM, + "lzma compression error: " + "%ju MiB would have been needed", + (uintmax_t)((lzma_memusage(&(data->stream)) + + 1024 * 1024 -1) + / (1024 * 1024))); + return (ARCHIVE_FATAL); + default: + /* Any other return value indicates an error. */ + archive_set_error(f->archive, ARCHIVE_ERRNO_MISC, + "lzma compression failed:" + " lzma_code() call returned status %d", + ret); + return (ARCHIVE_FATAL); + } + } +} + +#endif /* HAVE_LZMA_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3 b/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3 new file mode 100644 index 000000000..96c75382a --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_blocksize.3 @@ -0,0 +1,112 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_BLOCKSIZE 3 +.Os +.Sh NAME +.Nm archive_write_get_bytes_per_block , +.Nm archive_write_set_bytes_per_block , +.Nm archive_write_get_bytes_in_last_block , +.Nm archive_write_set_bytes_in_last_block +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_get_bytes_per_block "struct archive *" +.Ft int +.Fn archive_write_set_bytes_per_block "struct archive *" "int bytes_per_block" +.Ft int +.Fn archive_write_get_bytes_in_last_block "struct archive *" +.Ft int +.Fn archive_write_set_bytes_in_last_block "struct archive *" "int" +.Sh DESCRIPTION +.Bl -tag -width indent +.It Fn archive_write_set_bytes_per_block +Sets the block size used for writing the archive data. +Every call to the write callback function, except possibly the last one, will +use this value for the length. +The default is to use a block size of 10240 bytes. +Note that a block size of zero will suppress internal blocking +and cause writes to be sent directly to the write callback as they occur. +.It Fn archive_write_get_bytes_per_block +Retrieve the block size to be used for writing. +A value of -1 here indicates that the library should use default values. +A value of zero indicates that internal blocking is suppressed. +.It Fn archive_write_set_bytes_in_last_block +Sets the block size used for writing the last block. +If this value is zero, the last block will be padded to the same size +as the other blocks. +Otherwise, the final block will be padded to a multiple of this size. +In particular, setting it to 1 will cause the final block to not be padded. +For compressed output, any padding generated by this option +is applied only after the compression. +The uncompressed data is always unpadded. +The default is to pad the last block to the full block size (note that +.Fn archive_write_open_filename +will set this based on the file type). +Unlike the other +.Dq set +functions, this function can be called after the archive is opened. +.It Fn archive_write_get_bytes_in_last_block +Retrieve the currently-set value for last block size. +A value of -1 here indicates that the library should use default values. +.El +.\" .Sh EXAMPLE +.Sh RETURN VALUES +.Fn archive_write_set_bytes_per_block +and +.Fn archive_write_set_bytes_in_last_block +return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.Pp +.Fn archive_write_get_bytes_per_block +and +.Fn archive_write_get_bytes_in_last_block +return currently configured block size +.Po +.Li -1 +indicates the default block size +.Pc , +or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_data.3 b/Utilities/cmlibarchive/libarchive/archive_write_data.3 new file mode 100644 index 000000000..fc399bc30 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_data.3 @@ -0,0 +1,60 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE 3 +.Os +.Sh NAME +.Nm archive_write_data +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft ssize_t +.Fn archive_write_data "struct archive *" "const void *" "size_t" +.Sh DESCRIPTION +Write data corresponding to the header just written. +.\" .Sh EXAMPLE +.\" +.Sh RETURN VALUES +This function returns the number of bytes actually written, or +.Li -1 +on error. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_finish_entry 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 b/Utilities/cmlibarchive/libarchive/archive_write_disk.3 index 5ed4a5038..ffadb04fe 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk.3 +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk.3 @@ -25,7 +25,7 @@ .\" $FreeBSD: src/lib/libarchive/archive_write_disk.3,v 1.4 2008/09/04 05:22:00 kientzle Exp $ .\" .Dd August 5, 2008 -.Dt archive_write_disk 3 +.Dt ARCHIVE_WRITE_DISK 3 .Os .Sh NAME .Nm archive_write_disk_new , @@ -36,9 +36,11 @@ .Nm archive_write_disk_set_user_lookup , .Nm archive_write_header , .Nm archive_write_data , +.Nm archive_write_data_block , .Nm archive_write_finish_entry , .Nm archive_write_close , .Nm archive_write_finish +.Nm archive_write_free .Nd functions for creating objects on disk .Sh SYNOPSIS .In archive.h @@ -68,12 +70,16 @@ .Fn archive_write_header "struct archive *" "struct archive_entry *" .Ft ssize_t .Fn archive_write_data "struct archive *" "const void *" "size_t" +.Ft ssize_t +.Fn archive_write_data_block "struct archive *" "const void *" "size_t size" "int64_t offset" .Ft int .Fn archive_write_finish_entry "struct archive *" .Ft int .Fn archive_write_close "struct archive *" .Ft int .Fn archive_write_finish "struct archive *" +.Ft int +.Fn archive_write_free "struct archive *" .Sh DESCRIPTION These functions provide a complete API for creating objects on disk from @@ -221,6 +227,20 @@ objects. .It Fn archive_write_data Write data corresponding to the header just written. Returns number of bytes written or -1 on error. +.It Fn archive_write_data_block +Write data corresponding to the header just written. +This is like +.Fn archive_write_data +except that it performs a seek on the file being +written to the specified offset before writing the data. +This is useful when restoring sparse files from archive +formats that support sparse files. +Returns number of bytes written or -1 on error. +(Note: This is currently not supported for +.Tn archive_write +handles, only for +.Tn archive_write_disk +handles.) .It Fn archive_write_finish_entry Close out the entry just written. Ordinarily, clients never need to call this, as it @@ -229,6 +249,9 @@ is called automatically by and .Fn archive_write_close as needed. +However, some file attributes are written to disk only +after the file is closed, so this can be necessary +if you need to work with the file on disk right away. .It Fn archive_write_close Set any attributes that could not be set during the initial restore. For example, directory timestamps are not restored initially because @@ -240,6 +263,9 @@ The library maintains a list of all such deferred attributes and sets them when this function is invoked. .It Fn archive_write_finish +This is a deprecated synonym for +.Fn archive_write_free . +.It Fn archive_write_free Invokes .Fn archive_write_close if it was not invoked manually, then releases all resources. @@ -263,12 +289,6 @@ for operations that might succeed if retried, for unusual conditions that do not prevent further operations, and .Cm ARCHIVE_FATAL for serious errors that make remaining operations impossible. -The -.Fn archive_errno -and -.Fn archive_error_string -functions can be used to retrieve an appropriate error code and a -textual error message. .Pp .Fn archive_write_disk_new returns a pointer to a newly-allocated @@ -276,12 +296,18 @@ returns a pointer to a newly-allocated object. .Pp .Fn archive_write_data -returns a count of the number of bytes actually written. -On error, -1 is returned and the +returns a count of the number of bytes actually written, +or +.Li -1 +on error. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the .Fn archive_errno and .Fn archive_error_string -functions will return appropriate values. +functions. +.\" .Sh SEE ALSO .Xr archive_read 3 , .Xr archive_write 3 , @@ -339,7 +365,7 @@ In particular, the directory .Pa aa is created as well as the final object .Pa bb . -In theory, this can be exploited to create an entire directory heirarchy +In theory, this can be exploited to create an entire directory hierarchy with a single request. Of course, this does not work if the .Cm ARCHIVE_EXTRACT_NODOTDOT @@ -371,5 +397,5 @@ compact implementation when appropriate. .Pp There should be a corresponding .Nm archive_read_disk -interface that walks a directory heirarchy and returns archive -entry objects. \ No newline at end of file +interface that walks a directory hierarchy and returns archive +entry objects. diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk.c b/Utilities/cmlibarchive/libarchive/archive_write_disk.c deleted file mode 100644 index 8221a9f2e..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk.c +++ /dev/null @@ -1,2600 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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: src/lib/libarchive/archive_write_disk.c,v 1.42 2008/12/06 05:55:46 kientzle Exp $"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_ACL_H -#include -#endif -#ifdef HAVE_SYS_EXTATTR_H -#include -#endif -#ifdef HAVE_SYS_XATTR_H -#include -#endif -#ifdef HAVE_ATTR_XATTR_H -#include -#endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TIME_H -#include -#endif -#ifdef HAVE_SYS_UTIME_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ -#endif -/* - * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. - * As the include guards don't agree, the order of include is important. - */ -#ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ -#endif -#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -#include /* Linux file flags, broken on Cygwin */ -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_UTIME_H -#include -#endif - -#include "archive.h" -#include "archive_string.h" -#include "archive_entry.h" -#include "archive_private.h" - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -struct fixup_entry { - struct fixup_entry *next; - mode_t mode; - int64_t atime; - int64_t birthtime; - int64_t mtime; - unsigned long atime_nanos; - unsigned long birthtime_nanos; - unsigned long mtime_nanos; - unsigned long fflags_set; - int fixup; /* bitmask of what needs fixing */ - char *name; -}; - -/* - * We use a bitmask to track which operations remain to be done for - * this file. In particular, this helps us avoid unnecessary - * operations when it's possible to take care of one step as a - * side-effect of another. For example, mkdir() can specify the mode - * for the newly-created object but symlink() cannot. This means we - * can skip chmod() if mkdir() succeeded, but we must explicitly - * chmod() if we're trying to create a directory that already exists - * (mkdir() failed) or if we're restoring a symlink. Similarly, we - * need to verify UID/GID before trying to restore SUID/SGID bits; - * that verification can occur explicitly through a stat() call or - * implicitly because of a successful chown() call. - */ -#define TODO_MODE_FORCE 0x40000000 -#define TODO_MODE_BASE 0x20000000 -#define TODO_SUID 0x10000000 -#define TODO_SUID_CHECK 0x08000000 -#define TODO_SGID 0x04000000 -#define TODO_SGID_CHECK 0x02000000 -#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID) -#define TODO_TIMES ARCHIVE_EXTRACT_TIME -#define TODO_OWNER ARCHIVE_EXTRACT_OWNER -#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS -#define TODO_ACLS ARCHIVE_EXTRACT_ACL -#define TODO_XATTR ARCHIVE_EXTRACT_XATTR - -struct archive_write_disk { - struct archive archive; - - mode_t user_umask; - struct fixup_entry *fixup_list; - struct fixup_entry *current_fixup; - uid_t user_uid; - dev_t skip_file_dev; - ino_t skip_file_ino; - time_t start_time; - - gid_t (*lookup_gid)(void *private, const char *gname, gid_t gid); - void (*cleanup_gid)(void *private); - void *lookup_gid_data; - uid_t (*lookup_uid)(void *private, const char *gname, gid_t gid); - void (*cleanup_uid)(void *private); - void *lookup_uid_data; - - /* - * Full path of last file to satisfy symlink checks. - */ - struct archive_string path_safe; - - /* - * Cached stat data from disk for the current entry. - * If this is valid, pst points to st. Otherwise, - * pst is null. - */ - struct stat st; - struct stat *pst; - - /* Information about the object being restored right now. */ - struct archive_entry *entry; /* Entry being extracted. */ - char *name; /* Name of entry, possibly edited. */ - struct archive_string _name_data; /* backing store for 'name' */ - /* Tasks remaining for this object. */ - int todo; - /* Tasks deferred until end-of-archive. */ - int deferred; - /* Options requested by the client. */ - int flags; - /* Handle for the file we're restoring. */ - int fd; - /* Current offset for writing data to the file. */ - off_t offset; - /* Last offset actually written to disk. */ - off_t fd_offset; - /* Maximum size of file, -1 if unknown. */ - off_t filesize; - /* Dir we were in before this restore; only for deep paths. */ - int restore_pwd; - /* Mode we should use for this entry; affected by _PERM and umask. */ - mode_t mode; - /* UID/GID to use in restoring this entry. */ - uid_t uid; - gid_t gid; -}; - -/* - * Default mode for dirs created automatically (will be modified by umask). - * Note that POSIX specifies 0777 for implicity-created dirs, "modified - * by the process' file creation mask." - */ -#define DEFAULT_DIR_MODE 0777 -/* - * Dir modes are restored in two steps: During the extraction, the permissions - * in the archive are modified to match the following limits. During - * the post-extract fixup pass, the permissions from the archive are - * applied. - */ -#define MINIMUM_DIR_MODE 0700 -#define MAXIMUM_DIR_MODE 0775 - -static int check_symlinks(struct archive_write_disk *); -static int create_filesystem_object(struct archive_write_disk *); -static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname); -#ifdef HAVE_FCHDIR -static void edit_deep_directories(struct archive_write_disk *ad); -#endif -static int cleanup_pathname(struct archive_write_disk *); -static int create_dir(struct archive_write_disk *, char *); -static int create_parent_dir(struct archive_write_disk *, char *); -static int older(struct stat *, struct archive_entry *); -static int restore_entry(struct archive_write_disk *); -#ifdef HAVE_POSIX_ACL -static int set_acl(struct archive_write_disk *, int fd, struct archive_entry *, - acl_type_t, int archive_entry_acl_type, const char *tn); -#endif -static int set_acls(struct archive_write_disk *); -static int set_xattrs(struct archive_write_disk *); -static int set_fflags(struct archive_write_disk *); -static int set_fflags_platform(struct archive_write_disk *, int fd, - const char *name, mode_t mode, - unsigned long fflags_set, unsigned long fflags_clear); -static int set_ownership(struct archive_write_disk *); -static int set_mode(struct archive_write_disk *, int mode); -static int set_time(int, int, const char *, time_t, long, time_t, long); -static int set_times(struct archive_write_disk *); -static struct fixup_entry *sort_dir_list(struct fixup_entry *p); -static gid_t trivial_lookup_gid(void *, const char *, gid_t); -static uid_t trivial_lookup_uid(void *, const char *, uid_t); -static ssize_t write_data_block(struct archive_write_disk *, - const char *, size_t); - -static struct archive_vtable *archive_write_disk_vtable(void); - -static int _archive_write_close(struct archive *); -static int _archive_write_finish(struct archive *); -static int _archive_write_header(struct archive *, struct archive_entry *); -static int _archive_write_finish_entry(struct archive *); -static ssize_t _archive_write_data(struct archive *, const void *, size_t); -static ssize_t _archive_write_data_block(struct archive *, const void *, size_t, off_t); - -static int -_archive_write_disk_lazy_stat(struct archive_write_disk *a) -{ - if (a->pst != NULL) { - /* Already have stat() data available. */ - return (ARCHIVE_OK); - } -#ifdef HAVE_FSTAT - if (a->fd >= 0 && fstat(a->fd, &a->st) == 0) { - a->pst = &a->st; - return (ARCHIVE_OK); - } -#endif - /* - * XXX At this point, symlinks should not be hit, otherwise - * XXX a race occured. Do we want to check explicitly for that? - */ - if (lstat(a->name, &a->st) == 0) { - a->pst = &a->st; - return (ARCHIVE_OK); - } - archive_set_error(&a->archive, errno, "Couldn't stat file"); - return (ARCHIVE_WARN); -} - -static struct archive_vtable * -archive_write_disk_vtable(void) -{ - static struct archive_vtable av; - static int inited = 0; - - if (!inited) { - av.archive_close = _archive_write_close; - av.archive_finish = _archive_write_finish; - av.archive_write_header = _archive_write_header; - av.archive_write_finish_entry = _archive_write_finish_entry; - av.archive_write_data = _archive_write_data; - av.archive_write_data_block = _archive_write_data_block; - } - return (&av); -} - - -int -archive_write_disk_set_options(struct archive *_a, int flags) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - - a->flags = flags; - return (ARCHIVE_OK); -} - - -/* - * Extract this entry to disk. - * - * TODO: Validate hardlinks. According to the standards, we're - * supposed to check each extracted hardlink and squawk if it refers - * to a file that we didn't restore. I'm not entirely convinced this - * is a good idea, but more importantly: Is there any way to validate - * hardlinks without keeping a complete list of filenames from the - * entire archive?? Ugh. - * - */ -static int -_archive_write_header(struct archive *_a, struct archive_entry *entry) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - struct fixup_entry *fe; - int ret, r; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_disk_header"); - archive_clear_error(&a->archive); - if (a->archive.state & ARCHIVE_STATE_DATA) { - r = _archive_write_finish_entry(&a->archive); - if (r == ARCHIVE_FATAL) - return (r); - } - - /* Set up for this particular entry. */ - a->pst = NULL; - a->current_fixup = NULL; - a->deferred = 0; - if (a->entry) { - archive_entry_free(a->entry); - a->entry = NULL; - } - a->entry = archive_entry_clone(entry); - a->fd = -1; - a->fd_offset = 0; - a->offset = 0; - a->uid = a->user_uid; - a->mode = archive_entry_mode(a->entry); - if (archive_entry_size_is_set(a->entry)) - a->filesize = archive_entry_size(a->entry); - else - a->filesize = -1; - archive_strcpy(&(a->_name_data), archive_entry_pathname(a->entry)); - a->name = a->_name_data.s; - archive_clear_error(&a->archive); - - /* - * Clean up the requested path. This is necessary for correct - * dir restores; the dir restore logic otherwise gets messed - * up by nonsense like "dir/.". - */ - ret = cleanup_pathname(a); - if (ret != ARCHIVE_OK) - return (ret); - - /* - * Set the umask to zero 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 - * reason. This will be reset before we return. Note that we - * don't need to do this in _finish_entry, as the chmod(), etc, - * system calls don't obey umask. - */ - a->user_umask = umask(0); - /* From here on, early exit requires "goto done" to clean up. */ - - /* Figure out what we need to do for this entry. */ - a->todo = TODO_MODE_BASE; - if (a->flags & ARCHIVE_EXTRACT_PERM) { - a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */ - /* - * SGID requires an extra "check" step because we - * cannot easily predict the GID that the system will - * assign. (Different systems assign GIDs to files - * based on a variety of criteria, including process - * credentials and the gid of the enclosing - * directory.) We can only restore the SGID bit if - * the file has the right GID, and we only know the - * GID if we either set it (see set_ownership) or if - * we've actually called stat() on the file after it - * was restored. Since there are several places at - * which we might verify the GID, we need a TODO bit - * to keep track. - */ - if (a->mode & S_ISGID) - a->todo |= TODO_SGID | TODO_SGID_CHECK; - /* - * Verifying the SUID is simpler, but can still be - * done in multiple ways, hence the separate "check" bit. - */ - if (a->mode & S_ISUID) - a->todo |= TODO_SUID | TODO_SUID_CHECK; - } else { - /* - * User didn't request full permissions, so don't - * restore SUID, SGID bits and obey umask. - */ - a->mode &= ~S_ISUID; - a->mode &= ~S_ISGID; - a->mode &= ~S_ISVTX; - a->mode &= ~a->user_umask; - } -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) - a->todo |= TODO_OWNER; -#endif - if (a->flags & ARCHIVE_EXTRACT_TIME) - a->todo |= TODO_TIMES; - if (a->flags & ARCHIVE_EXTRACT_ACL) - a->todo |= TODO_ACLS; - if (a->flags & ARCHIVE_EXTRACT_XATTR) - a->todo |= TODO_XATTR; - if (a->flags & ARCHIVE_EXTRACT_FFLAGS) - a->todo |= TODO_FFLAGS; - if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { - ret = check_symlinks(a); - if (ret != ARCHIVE_OK) - goto done; - } -#ifdef HAVE_FCHDIR - /* If path exceeds PATH_MAX, shorten the path. */ - edit_deep_directories(a); -#endif - - ret = restore_entry(a); - - /* - * On the GNU tar mailing list, some people working with new - * Linux filesystems observed that system xattrs used as - * layout hints need to be restored before the file contents - * are written, so this can't be done at file close. - */ - if (a->todo & TODO_XATTR) { - int r2 = set_xattrs(a); - if (r2 < ret) ret = r2; - } - -#ifdef HAVE_FCHDIR - /* If we changed directory above, restore it here. */ - if (a->restore_pwd >= 0) { - r = fchdir(a->restore_pwd); - if (r != 0) { - archive_set_error(&a->archive, errno, "chdir() failure"); - ret = ARCHIVE_FATAL; - } - close(a->restore_pwd); - a->restore_pwd = -1; - } -#endif - - /* - * Fixup uses the unedited pathname from archive_entry_pathname(), - * because it is relative to the base dir and the edited path - * might be relative to some intermediate dir as a result of the - * deep restore logic. - */ - if (a->deferred & TODO_MODE) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_MODE_BASE; - fe->mode = a->mode; - } - - if ((a->deferred & TODO_TIMES) - && (archive_entry_mtime_is_set(entry) - || archive_entry_atime_is_set(entry))) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_TIMES; - if (archive_entry_atime_is_set(entry)) { - fe->atime = archive_entry_atime(entry); - fe->atime_nanos = archive_entry_atime_nsec(entry); - } else { - /* If atime is unset, use start time. */ - fe->atime = a->start_time; - fe->atime_nanos = 0; - } - if (archive_entry_mtime_is_set(entry)) { - fe->mtime = archive_entry_mtime(entry); - fe->mtime_nanos = archive_entry_mtime_nsec(entry); - } else { - /* If mtime is unset, use start time. */ - fe->mtime = a->start_time; - fe->mtime_nanos = 0; - } - if (archive_entry_birthtime_is_set(entry)) { - fe->birthtime = archive_entry_birthtime(entry); - fe->birthtime_nanos = archive_entry_birthtime_nsec(entry); - } else { - /* If birthtime is unset, use mtime. */ - fe->birthtime = fe->mtime; - fe->birthtime_nanos = fe->mtime_nanos; - } - } - - if (a->deferred & TODO_FFLAGS) { - fe = current_fixup(a, archive_entry_pathname(entry)); - fe->fixup |= TODO_FFLAGS; - /* TODO: Complete this.. defer fflags from below. */ - } - - /* We've created the object and are ready to pour data into it. */ - if (ret >= ARCHIVE_WARN) - a->archive.state = ARCHIVE_STATE_DATA; - /* - * If it's not open, tell our client not to try writing. - * In particular, dirs, links, etc, don't get written to. - */ - if (a->fd < 0) { - archive_entry_set_size(entry, 0); - a->filesize = 0; - } -done: - /* Restore the user's umask before returning. */ - umask(a->user_umask); - - return (ret); -} - -int -archive_write_disk_set_skip_file(struct archive *_a, dev_t d, ino_t i) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file"); - a->skip_file_dev = d; - a->skip_file_ino = i; - return (ARCHIVE_OK); -} - -static ssize_t -write_data_block(struct archive_write_disk *a, const char *buff, size_t size) -{ - uint64_t start_size = size; - ssize_t bytes_written = 0; - ssize_t block_size = 0, bytes_to_write; - - if (size == 0) - return (ARCHIVE_OK); - - if (a->filesize == 0 || a->fd < 0) { - archive_set_error(&a->archive, 0, - "Attempt to write to an empty file"); - return (ARCHIVE_WARN); - } - - if (a->flags & ARCHIVE_EXTRACT_SPARSE) { -#if HAVE_STRUCT_STAT_ST_BLKSIZE - int r; - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - block_size = a->pst->st_blksize; -#else - /* XXX TODO XXX Is there a more appropriate choice here ? */ - /* This needn't match the filesystem allocation size. */ - block_size = 16*1024; -#endif - } - - /* If this write would run beyond the file size, truncate it. */ - if (a->filesize >= 0 && (off_t)(a->offset + size) > a->filesize) - start_size = size = (size_t)(a->filesize - a->offset); - - /* Write the data. */ - while (size > 0) { - if (block_size == 0) { - bytes_to_write = size; - } else { - /* We're sparsifying the file. */ - const char *p, *end; - off_t block_end; - - /* Skip leading zero bytes. */ - for (p = buff, end = buff + size; p < end; ++p) { - if (*p != '\0') - break; - } - a->offset += p - buff; - size -= p - buff; - buff = p; - if (size == 0) - break; - - /* Calculate next block boundary after offset. */ - block_end - = (a->offset / block_size + 1) * block_size; - - /* If the adjusted write would cross block boundary, - * truncate it to the block boundary. */ - bytes_to_write = size; - if (a->offset + bytes_to_write > block_end) - bytes_to_write = block_end - a->offset; - } - /* Seek if necessary to the specified offset. */ - if (a->offset != a->fd_offset) { - if (lseek(a->fd, a->offset, SEEK_SET) < 0) { - archive_set_error(&a->archive, errno, - "Seek failed"); - return (ARCHIVE_FATAL); - } - a->fd_offset = a->offset; - a->archive.file_position = a->offset; - a->archive.raw_position = a->offset; - } - bytes_written = write(a->fd, buff, bytes_to_write); - if (bytes_written < 0) { - archive_set_error(&a->archive, errno, "Write failed"); - return (ARCHIVE_WARN); - } - buff += bytes_written; - size -= bytes_written; - a->offset += bytes_written; - a->archive.file_position += bytes_written; - a->archive.raw_position += bytes_written; - a->fd_offset = a->offset; - } - return (start_size - size); -} - -static ssize_t -_archive_write_data_block(struct archive *_a, - const void *buff, size_t size, off_t offset) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - ssize_t r; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_disk_block"); - - a->offset = offset; - r = write_data_block(a, buff, size); - if (r < ARCHIVE_OK) - return (r); - if ((size_t)r < size) { - archive_set_error(&a->archive, 0, - "Write request too large"); - return (ARCHIVE_WARN); - } - return (ARCHIVE_OK); -} - -static ssize_t -_archive_write_data(struct archive *_a, const void *buff, size_t size) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_DATA, "archive_write_data"); - - return (write_data_block(a, buff, size)); -} - -static int -_archive_write_finish_entry(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - int ret = ARCHIVE_OK; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_finish_entry"); - if (a->archive.state & ARCHIVE_STATE_HEADER) - return (ARCHIVE_OK); - archive_clear_error(&a->archive); - - /* Pad or truncate file to the right size. */ - if (a->fd < 0) { - /* There's no file. */ - } else if (a->filesize < 0) { - /* File size is unknown, so we can't set the size. */ - } else if (a->fd_offset == a->filesize) { - /* Last write ended at exactly the filesize; we're done. */ - /* Hopefully, this is the common case. */ - } else { -#if HAVE_FTRUNCATE - if (ftruncate(a->fd, a->filesize) == -1 && - a->filesize == 0) { - archive_set_error(&a->archive, errno, - "File size could not be restored"); - return (ARCHIVE_FAILED); - } -#endif - /* - * Not all platforms implement the XSI option to - * extend files via ftruncate. Stat() the file again - * to see what happened. - */ - a->pst = NULL; - if ((ret = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (ret); - /* We can use lseek()/write() to extend the file if - * ftruncate didn't work or isn't available. */ - if (a->st.st_size < a->filesize) { - const char nul = '\0'; - if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) { - archive_set_error(&a->archive, errno, - "Seek failed"); - return (ARCHIVE_FATAL); - } - if (write(a->fd, &nul, 1) < 0) { - archive_set_error(&a->archive, errno, - "Write to restore size failed"); - return (ARCHIVE_FATAL); - } - a->pst = NULL; - } - } - - /* Restore metadata. */ - - /* - * Look up the "real" UID only if we're going to need it. - * TODO: the TODO_SGID condition can be dropped here, can't it? - */ - if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) { - a->uid = a->lookup_uid(a->lookup_uid_data, - archive_entry_uname(a->entry), - archive_entry_uid(a->entry)); - } - /* Look up the "real" GID only if we're going to need it. */ - /* TODO: the TODO_SUID condition can be dropped here, can't it? */ - if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) { - a->gid = a->lookup_gid(a->lookup_gid_data, - archive_entry_gname(a->entry), - archive_entry_gid(a->entry)); - } - /* - * If restoring ownership, do it before trying to restore suid/sgid - * bits. If we set the owner, we know what it is and can skip - * a stat() call to examine the ownership of the file on disk. - */ - if (a->todo & TODO_OWNER) - ret = set_ownership(a); - if (a->todo & TODO_MODE) { - int r2 = set_mode(a, a->mode); - if (r2 < ret) ret = r2; - } - if (a->todo & TODO_ACLS) { - int r2 = set_acls(a); - if (r2 < ret) ret = r2; - } - /* - * Some flags prevent file modification; they must be restored after - * file contents are written. - */ - if (a->todo & TODO_FFLAGS) { - int r2 = set_fflags(a); - if (r2 < ret) ret = r2; - } - /* - * Time has to be restored after all other metadata; - * otherwise atime will get changed. - */ - if (a->todo & TODO_TIMES) { - int r2 = set_times(a); - if (r2 < ret) ret = r2; - } - - /* If there's an fd, we can close it now. */ - if (a->fd >= 0) { - close(a->fd); - a->fd = -1; - } - /* If there's an entry, we can release it now. */ - if (a->entry) { - archive_entry_free(a->entry); - a->entry = NULL; - } - a->archive.state = ARCHIVE_STATE_HEADER; - return (ret); -} - -int -archive_write_disk_set_group_lookup(struct archive *_a, - void *private_data, - gid_t (*lookup_gid)(void *private, const char *gname, gid_t gid), - void (*cleanup_gid)(void *private)) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup"); - - a->lookup_gid = lookup_gid; - a->cleanup_gid = cleanup_gid; - a->lookup_gid_data = private_data; - return (ARCHIVE_OK); -} - -int -archive_write_disk_set_user_lookup(struct archive *_a, - void *private_data, - uid_t (*lookup_uid)(void *private, const char *uname, uid_t uid), - void (*cleanup_uid)(void *private)) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup"); - - a->lookup_uid = lookup_uid; - a->cleanup_uid = cleanup_uid; - a->lookup_uid_data = private_data; - return (ARCHIVE_OK); -} - - -/* - * Create a new archive_write_disk object and initialize it with global state. - */ -struct archive * -archive_write_disk_new(void) -{ - struct archive_write_disk *a; - - a = (struct archive_write_disk *)malloc(sizeof(*a)); - if (a == NULL) - return (NULL); - memset(a, 0, sizeof(*a)); - a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; - /* We're ready to write a header immediately. */ - a->archive.state = ARCHIVE_STATE_HEADER; - a->archive.vtable = archive_write_disk_vtable(); - a->lookup_uid = trivial_lookup_uid; - a->lookup_gid = trivial_lookup_gid; - a->start_time = time(NULL); -#ifdef HAVE_GETEUID - a->user_uid = geteuid(); -#endif /* HAVE_GETEUID */ - if (archive_string_ensure(&a->path_safe, 512) == NULL) { - free(a); - return (NULL); - } - return (&a->archive); -} - - -/* - * If pathname is longer than PATH_MAX, chdir to a suitable - * intermediate dir and edit the path down to a shorter suffix. Note - * that this routine never returns an error; if the chdir() attempt - * fails for any reason, we just go ahead with the long pathname. The - * object creation is likely to fail, but any error will get handled - * at that time. - */ -#ifdef HAVE_FCHDIR -static void -edit_deep_directories(struct archive_write_disk *a) -{ - int ret; - char *tail = a->name; - - a->restore_pwd = -1; - - /* If path is short, avoid the open() below. */ - if (strlen(tail) <= PATH_MAX) - return; - - /* Try to record our starting dir. */ - a->restore_pwd = open(".", O_RDONLY | O_BINARY); - if (a->restore_pwd < 0) - return; - - /* As long as the path is too long... */ - while (strlen(tail) > PATH_MAX) { - /* Locate a dir prefix shorter than PATH_MAX. */ - tail += PATH_MAX - 8; - while (tail > a->name && *tail != '/') - tail--; - /* Exit if we find a too-long path component. */ - if (tail <= a->name) - return; - /* Create the intermediate dir and chdir to it. */ - *tail = '\0'; /* Terminate dir portion */ - ret = create_dir(a, a->name); - if (ret == ARCHIVE_OK && chdir(a->name) != 0) - ret = ARCHIVE_FAILED; - *tail = '/'; /* Restore the / we removed. */ - if (ret != ARCHIVE_OK) - return; - tail++; - /* The chdir() succeeded; we've now shortened the path. */ - a->name = tail; - } - return; -} -#endif - -/* - * The main restore function. - */ -static int -restore_entry(struct archive_write_disk *a) -{ - int ret = ARCHIVE_OK, en; - - if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { - /* - * TODO: Fix this. Apparently, there are platforms - * that still allow root to hose the entire filesystem - * by unlinking a dir. The S_ISDIR() test above - * prevents us from using unlink() here if the new - * object is a dir, but that doesn't mean the old - * object isn't a dir. - */ - if (unlink(a->name) == 0) { - /* We removed it, reset cached stat. */ - a->pst = NULL; - } else if (errno == ENOENT) { - /* File didn't exist, that's just as good. */ - } else if (rmdir(a->name) == 0) { - /* It was a dir, but now it's gone. */ - a->pst = NULL; - } else { - /* We tried, but couldn't get rid of it. */ - archive_set_error(&a->archive, errno, - "Could not unlink"); - return(ARCHIVE_FAILED); - } - } - - /* Try creating it first; if this fails, we'll try to recover. */ - en = create_filesystem_object(a); - - if ((en == ENOTDIR || en == ENOENT) - && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) { - /* If the parent dir doesn't exist, try creating it. */ - create_parent_dir(a, a->name); - /* Now try to create the object again. */ - en = create_filesystem_object(a); - } - - if ((en == EISDIR || en == EEXIST) - && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { - /* If we're not overwriting, we're done. */ - archive_set_error(&a->archive, en, "Already exists"); - return (ARCHIVE_FAILED); - } - - /* - * Some platforms return EISDIR if you call - * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some - * return EEXIST. POSIX is ambiguous, requiring EISDIR - * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT) - * on an existing item. - */ - if (en == EISDIR) { - /* A dir is in the way of a non-dir, rmdir it. */ - if (rmdir(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't remove already-existing dir"); - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* Try again. */ - en = create_filesystem_object(a); - } else if (en == EEXIST) { - /* - * We know something is in the way, but we don't know what; - * we need to find out before we go any further. - */ - int r = 0; - /* - * The SECURE_SYMLINK logic has already removed a - * symlink to a dir if the client wants that. So - * follow the symlink if we're creating a dir. - */ - if (S_ISDIR(a->mode)) - r = stat(a->name, &a->st); - /* - * If it's not a dir (or it's a broken symlink), - * then don't follow it. - */ - if (r != 0 || !S_ISDIR(a->mode)) - r = lstat(a->name, &a->st); - if (r != 0) { - archive_set_error(&a->archive, errno, - "Can't stat existing object"); - return (ARCHIVE_FAILED); - } - - /* - * NO_OVERWRITE_NEWER doesn't apply to directories. - */ - if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER) - && !S_ISDIR(a->st.st_mode)) { - if (!older(&(a->st), a->entry)) { - archive_set_error(&a->archive, 0, - "File on disk is not older; skipping."); - return (ARCHIVE_FAILED); - } - } - - /* If it's our archive, we're done. */ - if (a->skip_file_dev > 0 && - a->skip_file_ino > 0 && - a->st.st_dev == a->skip_file_dev && - a->st.st_ino == a->skip_file_ino) { - archive_set_error(&a->archive, 0, "Refusing to overwrite archive"); - return (ARCHIVE_FAILED); - } - - if (!S_ISDIR(a->st.st_mode)) { - /* A non-dir is in the way, unlink it. */ - if (unlink(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't unlink already-existing object"); - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* Try again. */ - en = create_filesystem_object(a); - } else if (!S_ISDIR(a->mode)) { - /* A dir is in the way of a non-dir, rmdir it. */ - if (rmdir(a->name) != 0) { - archive_set_error(&a->archive, errno, - "Can't remove already-existing dir"); - return (ARCHIVE_FAILED); - } - /* Try again. */ - en = create_filesystem_object(a); - } else { - /* - * There's a dir in the way of a dir. Don't - * waste time with rmdir()/mkdir(), just fix - * up the permissions on the existing dir. - * Note that we don't change perms on existing - * dirs unless _EXTRACT_PERM is specified. - */ - if ((a->mode != a->st.st_mode) - && (a->todo & TODO_MODE_FORCE)) - a->deferred |= (a->todo & TODO_MODE); - /* Ownership doesn't need deferred fixup. */ - en = 0; /* Forget the EEXIST. */ - } - } - - if (en) { - /* Everything failed; give up here. */ - archive_set_error(&a->archive, en, "Can't create '%s'", - a->name); - return (ARCHIVE_FAILED); - } - - a->pst = NULL; /* Cached stat data no longer valid. */ - return (ret); -} - -/* - * Returns 0 if creation succeeds, or else returns errno value from - * the failed system call. Note: This function should only ever perform - * a single system call. - */ -static int -create_filesystem_object(struct archive_write_disk *a) -{ - /* Create the entry. */ - const char *linkname; - mode_t final_mode, mode; - int r; - - /* We identify hard/symlinks according to the link names. */ - /* Since link(2) and symlink(2) don't handle modes, we're done here. */ - linkname = archive_entry_hardlink(a->entry); - if (linkname != NULL) { -#if !HAVE_LINK - return (EPERM); -#else - r = link(linkname, a->name) ? errno : 0; - /* - * New cpio and pax formats allow hardlink entries - * to carry data, so we may have to open the file - * for hardlink entries. - * - * If the hardlink was successfully created and - * the archive doesn't have carry data for it, - * consider it to be non-authoritive for meta data. - * This is consistent with GNU tar and BSD pax. - * If the hardlink does carry data, let the last - * archive entry decide ownership. - */ - if (r == 0 && a->filesize <= 0) { - a->todo = 0; - a->deferred = 0; - } if (r == 0 && a->filesize > 0) { - a->fd = open(a->name, O_WRONLY | O_TRUNC | O_BINARY); - if (a->fd < 0) - r = errno; - } - return (r); -#endif - } - linkname = archive_entry_symlink(a->entry); - if (linkname != NULL) { -#if HAVE_SYMLINK - return symlink(linkname, a->name) ? errno : 0; -#else - return (EPERM); -#endif - } - - /* - * The remaining system calls all set permissions, so let's - * try to take advantage of that to avoid an extra chmod() - * call. (Recall that umask is set to zero right now!) - */ - - /* Mode we want for the final restored object (w/o file type bits). */ - final_mode = a->mode & 07777; - /* - * The mode that will actually be restored in this step. Note - * that SUID, SGID, etc, require additional work to ensure - * security, so we never restore them at this point. - */ - mode = final_mode & 0777; - - switch (a->mode & AE_IFMT) { - default: - /* POSIX requires that we fall through here. */ - /* FALLTHROUGH */ - case AE_IFREG: - a->fd = open(a->name, - O_WRONLY | O_CREAT | O_EXCL | O_BINARY, mode); - r = (a->fd < 0); - break; - case AE_IFCHR: -#ifdef HAVE_MKNOD - /* Note: we use AE_IFCHR for the case label, and - * S_IFCHR for the mknod() call. This is correct. */ - r = mknod(a->name, mode | S_IFCHR, - archive_entry_rdev(a->entry)); -#else - /* TODO: Find a better way to warn about our inability - * to restore a char device node. */ - return (EINVAL); -#endif /* HAVE_MKNOD */ - break; - case AE_IFBLK: -#ifdef HAVE_MKNOD - r = mknod(a->name, mode | S_IFBLK, - archive_entry_rdev(a->entry)); -#else - /* TODO: Find a better way to warn about our inability - * to restore a block device node. */ - return (EINVAL); -#endif /* HAVE_MKNOD */ - break; - case AE_IFDIR: - mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE; - r = mkdir(a->name, mode); - if (r == 0) { - /* Defer setting dir times. */ - a->deferred |= (a->todo & TODO_TIMES); - a->todo &= ~TODO_TIMES; - /* Never use an immediate chmod(). */ - /* We can't avoid the chmod() entirely if EXTRACT_PERM - * because of SysV SGID inheritance. */ - if ((mode != final_mode) - || (a->flags & ARCHIVE_EXTRACT_PERM)) - a->deferred |= (a->todo & TODO_MODE); - a->todo &= ~TODO_MODE; - } - break; - case AE_IFIFO: -#ifdef HAVE_MKFIFO - r = mkfifo(a->name, mode); -#else - /* TODO: Find a better way to warn about our inability - * to restore a fifo. */ - return (EINVAL); -#endif /* HAVE_MKFIFO */ - break; - } - - /* All the system calls above set errno on failure. */ - if (r) - return (errno); - - /* If we managed to set the final mode, we've avoided a chmod(). */ - if (mode == final_mode) - a->todo &= ~TODO_MODE; - return (0); -} - -/* - * Cleanup function for archive_extract. Mostly, this involves processing - * the fixup list, which is used to address a number of problems: - * * Dir permissions might prevent us from restoring a file in that - * dir, so we restore the dir with minimum 0700 permissions first, - * then correct the mode at the end. - * * Similarly, the act of restoring a file touches the directory - * and changes the timestamp on the dir, so we have to touch-up dir - * timestamps at the end as well. - * * Some file flags can interfere with the restore by, for example, - * preventing the creation of hardlinks to those files. - * - * Note that tar/cpio do not require that archives be in a particular - * order; there is no way to know when the last file has been restored - * within a directory, so there's no way to optimize the memory usage - * here by fixing up the directory any earlier than the - * end-of-archive. - * - * XXX TODO: Directory ACLs should be restored here, for the same - * reason we set directory perms here. XXX - */ -static int -_archive_write_close(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - struct fixup_entry *next, *p; - int ret; - - __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, - ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, - "archive_write_disk_close"); - ret = _archive_write_finish_entry(&a->archive); - - /* Sort dir list so directories are fixed up in depth-first order. */ - p = sort_dir_list(a->fixup_list); - - while (p != NULL) { - a->pst = NULL; /* Mark stat cache as out-of-date. */ - if (p->fixup & TODO_TIMES) { -#ifdef HAVE_UTIMES - /* {f,l,}utimes() are preferred, when available. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - struct __timeval times[2]; -#else - struct timeval times[2]; -#endif - times[0].tv_sec = p->atime; - times[0].tv_usec = p->atime_nanos / 1000; -#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME - /* if it's valid and not mtime, push the birthtime first */ - if (((times[1].tv_sec = p->birthtime) < p->mtime) && - (p->birthtime > 0)) - { - times[1].tv_usec = p->birthtime_nanos / 1000; - utimes(p->name, times); - } -#endif - times[1].tv_sec = p->mtime; - times[1].tv_usec = p->mtime_nanos / 1000; -#ifdef HAVE_LUTIMES - lutimes(p->name, times); -#else - utimes(p->name, times); -#endif -#else - /* utime() is more portable, but less precise. */ - struct utimbuf times; - times.modtime = p->mtime; - times.actime = p->atime; - - utime(p->name, ×); -#endif - } - if (p->fixup & TODO_MODE_BASE) - chmod(p->name, p->mode); - - if (p->fixup & TODO_FFLAGS) - set_fflags_platform(a, -1, p->name, - p->mode, p->fflags_set, 0); - - next = p->next; - free(p->name); - free(p); - p = next; - } - a->fixup_list = NULL; - return (ret); -} - -static int -_archive_write_finish(struct archive *_a) -{ - struct archive_write_disk *a = (struct archive_write_disk *)_a; - int ret; - ret = _archive_write_close(&a->archive); - if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL) - (a->cleanup_gid)(a->lookup_gid_data); - if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL) - (a->cleanup_uid)(a->lookup_uid_data); - if (a->entry) - archive_entry_free(a->entry); - archive_string_free(&a->_name_data); - archive_string_free(&a->archive.error_string); - archive_string_free(&a->path_safe); - free(a); - return (ret); -} - -/* - * Simple O(n log n) merge sort to order the fixup list. In - * particular, we want to restore dir timestamps depth-first. - */ -static struct fixup_entry * -sort_dir_list(struct fixup_entry *p) -{ - struct fixup_entry *a, *b, *t; - - if (p == NULL) - return (NULL); - /* A one-item list is already sorted. */ - if (p->next == NULL) - return (p); - - /* Step 1: split the list. */ - t = p; - a = p->next->next; - while (a != NULL) { - /* Step a twice, t once. */ - a = a->next; - if (a != NULL) - a = a->next; - t = t->next; - } - /* Now, t is at the mid-point, so break the list here. */ - b = t->next; - t->next = NULL; - a = p; - - /* Step 2: Recursively sort the two sub-lists. */ - a = sort_dir_list(a); - b = sort_dir_list(b); - - /* Step 3: Merge the returned lists. */ - /* Pick the first element for the merged list. */ - if (strcmp(a->name, b->name) > 0) { - t = p = a; - a = a->next; - } else { - t = p = b; - b = b->next; - } - - /* Always put the later element on the list first. */ - while (a != NULL && b != NULL) { - if (strcmp(a->name, b->name) > 0) { - t->next = a; - a = a->next; - } else { - t->next = b; - b = b->next; - } - t = t->next; - } - - /* Only one list is non-empty, so just splice it on. */ - if (a != NULL) - t->next = a; - if (b != NULL) - t->next = b; - - return (p); -} - -/* - * Returns a new, initialized fixup entry. - * - * TODO: Reduce the memory requirements for this list by using a tree - * structure rather than a simple list of names. - */ -static struct fixup_entry * -new_fixup(struct archive_write_disk *a, const char *pathname) -{ - struct fixup_entry *fe; - - fe = (struct fixup_entry *)malloc(sizeof(struct fixup_entry)); - if (fe == NULL) - return (NULL); - fe->next = a->fixup_list; - a->fixup_list = fe; - fe->fixup = 0; - fe->name = strdup(pathname); - return (fe); -} - -/* - * Returns a fixup structure for the current entry. - */ -static struct fixup_entry * -current_fixup(struct archive_write_disk *a, const char *pathname) -{ - if (a->current_fixup == NULL) - a->current_fixup = new_fixup(a, pathname); - return (a->current_fixup); -} - -/* TODO: Make this work. */ -/* - * TODO: The deep-directory support bypasses this; disable deep directory - * support if we're doing symlink checks. - */ -/* - * TODO: Someday, integrate this with the deep dir support; they both - * scan the path and both can be optimized by comparing against other - * recent paths. - */ -/* TODO: Extend this to support symlinks on Windows Vista and later. */ -static int -check_symlinks(struct archive_write_disk *a) -{ -#if !defined(HAVE_LSTAT) - /* Platform doesn't have lstat, so we can't look for symlinks. */ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -#else - char *pn, *p; - char c; - int r; - struct stat st; - - /* - * Guard against symlink tricks. Reject any archive entry whose - * destination would be altered by a symlink. - */ - /* Whatever we checked last time doesn't need to be re-checked. */ - pn = a->name; - p = a->path_safe.s; - while ((*pn != '\0') && (*p == *pn)) - ++p, ++pn; - c = pn[0]; - /* Keep going until we've checked the entire name. */ - while (pn[0] != '\0' && (pn[0] != '/' || pn[1] != '\0')) { - /* Skip the next path element. */ - while (*pn != '\0' && *pn != '/') - ++pn; - c = pn[0]; - pn[0] = '\0'; - /* Check that we haven't hit a symlink. */ - r = lstat(a->name, &st); - if (r != 0) { - /* We've hit a dir that doesn't exist; stop now. */ - if (errno == ENOENT) - break; - } else if (S_ISLNK(st.st_mode)) { - if (c == '\0') { - /* - * Last element is symlink; remove it - * so we can overwrite it with the - * item being extracted. - */ - if (unlink(a->name)) { - archive_set_error(&a->archive, errno, - "Could not remove symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - a->pst = NULL; - /* - * Even if we did remove it, a warning - * is in order. The warning is silly, - * though, if we're just replacing one - * symlink with another symlink. - */ - if (!S_ISLNK(a->mode)) { - archive_set_error(&a->archive, 0, - "Removing symlink %s", - a->name); - } - /* Symlink gone. No more problem! */ - pn[0] = c; - return (0); - } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) { - /* User asked us to remove problems. */ - if (unlink(a->name) != 0) { - archive_set_error(&a->archive, 0, - "Cannot remove intervening symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - a->pst = NULL; - } else { - archive_set_error(&a->archive, 0, - "Cannot extract through symlink %s", - a->name); - pn[0] = c; - return (ARCHIVE_FAILED); - } - } - } - pn[0] = c; - /* We've checked and/or cleaned the whole path, so remember it. */ - archive_strcpy(&a->path_safe, a->name); - return (ARCHIVE_OK); -#endif -} - -#if defined(_WIN32) || defined(__CYGWIN__) -/* - * 1. Convert a path separator from '\' to '/' . - * We shouldn't check multi-byte character directly because some - * character-set have been using the '\' character for a part of - * its multibyte character code. - * 2. Replace unusable characters in Windows with underscore('_'). - * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx - */ -static void -cleanup_pathname_win(struct archive_write_disk *a) -{ - wchar_t wc; - char *p; - size_t alen, l; - - alen = 0; - l = 0; - for (p = a->name; *p != '\0'; p++) { - ++alen; - if (*p == '\\') - l = 1; - /* Rewrite the path name if its character is a unusable. */ - if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || - *p == '<' || *p == '>' || *p == '|') - *p = '_'; - } - if (alen == 0 || l == 0) - return; - /* - * Convert path separator. - */ - p = a->name; - while (*p != '\0' && alen) { - l = mbtowc(&wc, p, alen); - if (l == -1) { - while (*p != '\0') { - if (*p == '\\') - *p = '/'; - ++p; - } - break; - } - if (l == 1 && wc == L'\\') - *p = '/'; - p += l; - alen -= l; - } -} -#endif - -/* - * Canonicalize the pathname. In particular, this strips duplicate - * '/' characters, '.' elements, and trailing '/'. It also raises an - * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is - * set) any '..' in the path. - */ -static int -cleanup_pathname(struct archive_write_disk *a) -{ - char *dest, *src; - char separator = '\0'; - - dest = src = a->name; - if (*src == '\0') { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid empty pathname"); - return (ARCHIVE_FAILED); - } - -#if defined(_WIN32) || defined(__CYGWIN__) - cleanup_pathname_win(a); -#endif - /* Skip leading '/'. */ - if (*src == '/') - separator = *src++; - - /* Scan the pathname one element at a time. */ - for (;;) { - /* src points to first char after '/' */ - if (src[0] == '\0') { - break; - } else if (src[0] == '/') { - /* Found '//', ignore second one. */ - src++; - continue; - } else if (src[0] == '.') { - if (src[1] == '\0') { - /* Ignore trailing '.' */ - break; - } else if (src[1] == '/') { - /* Skip './'. */ - src += 2; - continue; - } else if (src[1] == '.') { - if (src[2] == '/' || src[2] == '\0') { - /* Conditionally warn about '..' */ - if (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_MISC, - "Path contains '..'"); - return (ARCHIVE_FAILED); - } - } - /* - * Note: Under no circumstances do we - * remove '..' elements. In - * particular, restoring - * '/foo/../bar/' should create the - * 'foo' dir as a side-effect. - */ - } - } - - /* Copy current element, including leading '/'. */ - if (separator) - *dest++ = '/'; - while (*src != '\0' && *src != '/') { - *dest++ = *src++; - } - - if (*src == '\0') - break; - - /* Skip '/' separator. */ - separator = *src++; - } - /* - * We've just copied zero or more path elements, not including the - * final '/'. - */ - if (dest == a->name) { - /* - * Nothing got copied. The path must have been something - * like '.' or '/' or './' or '/././././/./'. - */ - if (separator) - *dest++ = '/'; - else - *dest++ = '.'; - } - /* Terminate the result. */ - *dest = '\0'; - return (ARCHIVE_OK); -} - -/* - * Create the parent directory of the specified path, assuming path - * is already in mutable storage. - */ -static int -create_parent_dir(struct archive_write_disk *a, char *path) -{ - char *slash; - int r; - - /* Remove tail element to obtain parent name. */ - slash = strrchr(path, '/'); - if (slash == NULL) - return (ARCHIVE_OK); - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - return (r); -} - -/* - * Create the specified dir, recursing to create parents as necessary. - * - * Returns ARCHIVE_OK if the path exists when we're done here. - * Otherwise, returns ARCHIVE_FAILED. - * Assumes path is in mutable storage; path is unchanged on exit. - */ -static int -create_dir(struct archive_write_disk *a, char *path) -{ - struct stat st; - struct fixup_entry *le; - char *slash, *base; - mode_t mode_final, mode; - int r; - - r = ARCHIVE_OK; - - /* Check for special names and just skip them. */ - slash = strrchr(path, '/'); - if (slash == NULL) - base = path; - else - base = slash + 1; - - if (base[0] == '\0' || - (base[0] == '.' && base[1] == '\0') || - (base[0] == '.' && base[1] == '.' && base[2] == '\0')) { - /* Don't bother trying to create null path, '.', or '..'. */ - if (slash != NULL) { - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - return (r); - } - return (ARCHIVE_OK); - } - - /* - * Yes, this should be stat() and not lstat(). Using lstat() - * here loses the ability to extract through symlinks. Also note - * that this should not use the a->st cache. - */ - if (stat(path, &st) == 0) { - if (S_ISDIR(st.st_mode)) - return (ARCHIVE_OK); - if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { - archive_set_error(&a->archive, EEXIST, - "Can't create directory '%s'", path); - return (ARCHIVE_FAILED); - } - if (unlink(path) != 0) { - archive_set_error(&a->archive, errno, - "Can't create directory '%s': " - "Conflicting file cannot be removed"); - return (ARCHIVE_FAILED); - } - } else if (errno != ENOENT && errno != ENOTDIR) { - /* Stat failed? */ - archive_set_error(&a->archive, errno, "Can't test directory '%s'", path); - return (ARCHIVE_FAILED); - } else if (slash != NULL) { - *slash = '\0'; - r = create_dir(a, path); - *slash = '/'; - if (r != ARCHIVE_OK) - return (r); - } - - /* - * Mode we want for the final restored directory. Per POSIX, - * implicitly-created dirs must be created obeying the umask. - * There's no mention whether this is different for privileged - * restores (which the rest of this code handles by pretending - * umask=0). I've chosen here to always obey the user's umask for - * implicit dirs, even if _EXTRACT_PERM was specified. - */ - mode_final = DEFAULT_DIR_MODE & ~a->user_umask; - /* Mode we want on disk during the restore process. */ - mode = mode_final; - mode |= MINIMUM_DIR_MODE; - mode &= MAXIMUM_DIR_MODE; - if (mkdir(path, mode) == 0) { - if (mode != mode_final) { - le = new_fixup(a, path); - le->fixup |=TODO_MODE_BASE; - le->mode = mode_final; - } - return (ARCHIVE_OK); - } - - /* - * Without the following check, a/b/../b/c/d fails at the - * second visit to 'b', so 'd' can't be created. Note that we - * don't add it to the fixup list here, as it's already been - * added. - */ - if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) - return (ARCHIVE_OK); - - archive_set_error(&a->archive, errno, "Failed to create dir '%s'", - path); - return (ARCHIVE_FAILED); -} - -/* - * Note: Although we can skip setting the user id if the desired user - * id matches the current user, we cannot skip setting the group, as - * many systems set the gid based on the containing directory. So - * we have to perform a chown syscall if we want to set the SGID - * bit. (The alternative is to stat() and then possibly chown(); it's - * more efficient to skip the stat() and just always chown().) Note - * that a successful chown() here clears the TODO_SGID_CHECK bit, which - * allows set_mode to skip the stat() check for the GID. - */ -static int -set_ownership(struct archive_write_disk *a) -{ -#ifndef __CYGWIN__ -/* unfortunately, on win32 there is no 'root' user with uid 0, - so we just have to try the chown and see if it works */ - - /* If we know we can't change it, don't bother trying. */ - if (a->user_uid != 0 && a->user_uid != a->uid) { - archive_set_error(&a->archive, errno, - "Can't set UID=%d", a->uid); - return (ARCHIVE_WARN); - } -#endif - -#ifdef HAVE_FCHOWN - /* If we have an fd, we can avoid a race. */ - if (a->fd >= 0 && fchown(a->fd, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#endif - - /* We prefer lchown() but will use chown() if that's all we have. */ - /* Of course, if we have neither, this will always fail. */ -#ifdef HAVE_LCHOWN - if (lchown(a->name, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#elif HAVE_CHOWN - if (!S_ISLNK(a->mode) && chown(a->name, a->uid, a->gid) == 0) { - /* We've set owner and know uid/gid are correct. */ - a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); - return (ARCHIVE_OK); - } -#endif - - archive_set_error(&a->archive, errno, - "Can't set user=%d/group=%d for %s", a->uid, a->gid, - a->name); - return (ARCHIVE_WARN); -} - -#ifdef HAVE_UTIMES -/* - * The utimes()-family functions provide high resolution and - * a way to set time on an fd or a symlink. We prefer them - * when they're available. - */ -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - struct __timeval times[2]; -#else - struct timeval times[2]; -#endif - - times[0].tv_sec = atime; - times[0].tv_usec = atime_nsec / 1000; - times[1].tv_sec = mtime; - times[1].tv_usec = mtime_nsec / 1000; - -#ifdef HAVE_FUTIMES - if (fd >= 0) - return (futimes(fd, times)); -#else - (void)fd; /* UNUSED */ -#endif -#ifdef HAVE_LUTIMES - (void)mode; /* UNUSED */ - return (lutimes(name, times)); -#else - if (S_ISLNK(mode)) - return (0); - return (utimes(name, times)); -#endif -} -#elif defined(HAVE_UTIME) -/* - * utime() is an older, more standard interface that we'll use - * if utimes() isn't available. - */ -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ - struct utimbuf times; - (void)fd; /* UNUSED */ - (void)name; /* UNUSED */ - (void)atime_nsec; /* UNUSED */ - (void)mtime_nsec; /* UNUSED */ - times.actime = atime; - times.modtime = mtime; - if (S_ISLNK(mode)) - return (ARCHIVE_OK); - return (utime(name, ×)); -} -#else -static int -set_time(int fd, int mode, const char *name, - time_t atime, long atime_nsec, - time_t mtime, long mtime_nsec) -{ - return (ARCHIVE_WARN); -} -#endif - -static int -set_times(struct archive_write_disk *a) -{ - time_t atime = a->start_time, mtime = a->start_time; - long atime_nsec = 0, mtime_nsec = 0; - - /* If no time was provided, we're done. */ - if (!archive_entry_atime_is_set(a->entry) -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - && !archive_entry_birthtime_is_set(a->entry) -#endif - && !archive_entry_mtime_is_set(a->entry)) - return (ARCHIVE_OK); - - /* If no atime was specified, use start time instead. */ - /* In theory, it would be marginally more correct to use - * time(NULL) here, but that would cost us an extra syscall - * for little gain. */ - if (archive_entry_atime_is_set(a->entry)) { - atime = archive_entry_atime(a->entry); - atime_nsec = archive_entry_atime_nsec(a->entry); - } - - /* - * If you have struct stat.st_birthtime, we assume BSD birthtime - * semantics, in which {f,l,}utimes() updates birthtime to earliest - * mtime. So we set the time twice, first using the birthtime, - * then using the mtime. - */ -#if HAVE_STRUCT_STAT_ST_BIRTHTIME - /* If birthtime is set, flush that through to disk first. */ - if (archive_entry_birthtime_is_set(a->entry)) - if (set_time(a->fd, a->mode, a->name, atime, atime_nsec, - archive_entry_birthtime(a->entry), - archive_entry_birthtime_nsec(a->entry))) { - archive_set_error(&a->archive, errno, - "Can't update time for %s", - a->name); - return (ARCHIVE_WARN); - } -#endif - - if (archive_entry_mtime_is_set(a->entry)) { - mtime = archive_entry_mtime(a->entry); - mtime_nsec = archive_entry_mtime_nsec(a->entry); - } - if (set_time(a->fd, a->mode, a->name, - atime, atime_nsec, mtime, mtime_nsec)) { - archive_set_error(&a->archive, errno, - "Can't update time for %s", - a->name); - return (ARCHIVE_WARN); - } - - /* - * Note: POSIX does not provide a portable way to restore ctime. - * (Apart from resetting the system clock, which is distasteful.) - * So, any restoration of ctime will necessarily be OS-specific. - */ - - return (ARCHIVE_OK); -} - -static int -set_mode(struct archive_write_disk *a, int mode) -{ - int r = ARCHIVE_OK; - mode &= 07777; /* Strip off file type bits. */ - - if (a->todo & TODO_SGID_CHECK) { - /* - * If we don't know the GID is right, we must stat() - * to verify it. We can't just check the GID of this - * process, since systems sometimes set GID from - * the enclosing dir or based on ACLs. - */ - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - if (a->pst->st_gid != a->gid) { - mode &= ~ S_ISGID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - /* - * This is only an error if you - * requested owner restore. If you - * didn't, we'll try to restore - * sgid/suid, but won't consider it a - * problem if we can't. - */ - archive_set_error(&a->archive, -1, - "Can't restore SGID bit"); - r = ARCHIVE_WARN; - } -#endif - } - /* While we're here, double-check the UID. */ - if (a->pst->st_uid != a->uid - && (a->todo & TODO_SUID)) { - mode &= ~ S_ISUID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - archive_set_error(&a->archive, -1, - "Can't restore SUID bit"); - r = ARCHIVE_WARN; - } -#endif - } - a->todo &= ~TODO_SGID_CHECK; - a->todo &= ~TODO_SUID_CHECK; - } else if (a->todo & TODO_SUID_CHECK) { - /* - * If we don't know the UID is right, we can just check - * the user, since all systems set the file UID from - * the process UID. - */ - if (a->user_uid != a->uid) { - mode &= ~ S_ISUID; -#if !defined(_WIN32) || defined(__CYGWIN__) - if (a->flags & ARCHIVE_EXTRACT_OWNER) { - archive_set_error(&a->archive, -1, - "Can't make file SUID"); - r = ARCHIVE_WARN; - } -#endif - } - a->todo &= ~TODO_SUID_CHECK; - } - - if (S_ISLNK(a->mode)) { -#ifdef HAVE_LCHMOD - /* - * If this is a symlink, use lchmod(). If the - * platform doesn't support lchmod(), just skip it. A - * platform that doesn't provide a way to set - * permissions on symlinks probably ignores - * permissions on symlinks, so a failure here has no - * impact. - */ - if (lchmod(a->name, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } -#endif - } else if (!S_ISDIR(a->mode)) { - /* - * If it's not a symlink and not a dir, then use - * fchmod() or chmod(), depending on whether we have - * an fd. Dirs get their perms set during the - * post-extract fixup, which is handled elsewhere. - */ -#ifdef HAVE_FCHMOD - if (a->fd >= 0) { - if (fchmod(a->fd, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } - } else -#endif - /* If this platform lacks fchmod(), then - * we'll just use chmod(). */ - if (chmod(a->name, mode) != 0) { - archive_set_error(&a->archive, errno, - "Can't set permissions to 0%o", (int)mode); - r = ARCHIVE_WARN; - } - } - return (r); -} - -static int -set_fflags(struct archive_write_disk *a) -{ - struct fixup_entry *le; - unsigned long set, clear; - int r; - int critical_flags; - mode_t mode = archive_entry_mode(a->entry); - - /* - * Make 'critical_flags' hold all file flags that can't be - * immediately restored. For example, on BSD systems, - * SF_IMMUTABLE prevents hardlinks from being created, so - * should not be set until after any hardlinks are created. To - * preserve some semblance of portability, this uses #ifdef - * extensively. Ugly, but it works. - * - * Yes, Virginia, this does create a security race. It's mitigated - * somewhat by the practice of creating dirs 0700 until the extract - * is done, but it would be nice if we could do more than that. - * People restoring critical file systems should be wary of - * other programs that might try to muck with files as they're - * being restored. - */ - /* Hopefully, the compiler will optimize this mess into a constant. */ - critical_flags = 0; -#ifdef SF_IMMUTABLE - critical_flags |= SF_IMMUTABLE; -#endif -#ifdef UF_IMMUTABLE - critical_flags |= UF_IMMUTABLE; -#endif -#ifdef SF_APPEND - critical_flags |= SF_APPEND; -#endif -#ifdef UF_APPEND - critical_flags |= UF_APPEND; -#endif -#ifdef EXT2_APPEND_FL - critical_flags |= EXT2_APPEND_FL; -#endif -#ifdef EXT2_IMMUTABLE_FL - critical_flags |= EXT2_IMMUTABLE_FL; -#endif - - if (a->todo & TODO_FFLAGS) { - archive_entry_fflags(a->entry, &set, &clear); - - /* - * The first test encourages the compiler to eliminate - * all of this if it's not necessary. - */ - if ((critical_flags != 0) && (set & critical_flags)) { - le = current_fixup(a, a->name); - le->fixup |= TODO_FFLAGS; - le->fflags_set = set; - /* Store the mode if it's not already there. */ - if ((le->fixup & TODO_MODE) == 0) - le->mode = mode; - } else { - r = set_fflags_platform(a, a->fd, - a->name, mode, set, clear); - if (r != ARCHIVE_OK) - return (r); - } - } - return (ARCHIVE_OK); -} - - -#if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS) -/* - * BSD reads flags using stat() and sets them with one of {f,l,}chflags() - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - int r; - - (void)mode; /* UNUSED */ - if (set == 0 && clear == 0) - return (ARCHIVE_OK); - - /* - * XXX Is the stat here really necessary? Or can I just use - * the 'set' flags directly? In particular, I'm not sure - * about the correct approach if we're overwriting an existing - * file that already has flags on it. XXX - */ - if ((r = _archive_write_disk_lazy_stat(a)) != ARCHIVE_OK) - return (r); - - a->st.st_flags &= ~clear; - a->st.st_flags |= set; -#ifdef HAVE_FCHFLAGS - /* If platform has fchflags() and we were given an fd, use it. */ - if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#endif - /* - * If we can't use the fd to set the flags, we'll use the - * pathname to set flags. We prefer lchflags() but will use - * chflags() if we must. - */ -#ifdef HAVE_LCHFLAGS - if (lchflags(name, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#elif defined(HAVE_CHFLAGS) - if (S_ISLNK(a->st.st_mode)) { - archive_set_error(&a->archive, errno, - "Can't set file flags on symlink."); - return (ARCHIVE_WARN); - } - if (chflags(name, a->st.st_flags) == 0) - return (ARCHIVE_OK); -#endif - archive_set_error(&a->archive, errno, - "Failed to set file flags"); - return (ARCHIVE_WARN); -} - -#elif defined(EXT2_IOC_GETFLAGS) && defined(EXT2_IOC_SETFLAGS) -/* - * Linux uses ioctl() to read and write file flags. - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - int ret; - int myfd = fd; - unsigned long newflags, oldflags; - unsigned long sf_mask = 0; - - if (set == 0 && clear == 0) - return (ARCHIVE_OK); - /* Only regular files and dirs can have flags. */ - if (!S_ISREG(mode) && !S_ISDIR(mode)) - return (ARCHIVE_OK); - - /* If we weren't given an fd, open it ourselves. */ - if (myfd < 0) - myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY); - if (myfd < 0) - return (ARCHIVE_OK); - - /* - * Linux has no define for the flags that are only settable by - * the root user. This code may seem a little complex, but - * there seem to be some Linux systems that lack these - * defines. (?) The code below degrades reasonably gracefully - * if sf_mask is incomplete. - */ -#ifdef EXT2_IMMUTABLE_FL - sf_mask |= EXT2_IMMUTABLE_FL; -#endif -#ifdef EXT2_APPEND_FL - sf_mask |= EXT2_APPEND_FL; -#endif - /* - * XXX As above, this would be way simpler if we didn't have - * to read the current flags from disk. XXX - */ - ret = ARCHIVE_OK; - /* Try setting the flags as given. */ - if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) { - newflags = (oldflags & ~clear) | set; - if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) - goto cleanup; - if (errno != EPERM) - goto fail; - } - /* If we couldn't set all the flags, try again with a subset. */ - if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) { - newflags &= ~sf_mask; - oldflags &= sf_mask; - newflags |= oldflags; - if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) - goto cleanup; - } - /* We couldn't set the flags, so report the failure. */ -fail: - archive_set_error(&a->archive, errno, - "Failed to set file flags"); - ret = ARCHIVE_WARN; -cleanup: - if (fd < 0) - close(myfd); - return (ret); -} - -#else - -/* - * Of course, some systems have neither BSD chflags() nor Linux' flags - * support through ioctl(). - */ -static int -set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, - mode_t mode, unsigned long set, unsigned long clear) -{ - (void)a; /* UNUSED */ - (void)fd; /* UNUSED */ - (void)name; /* UNUSED */ - (void)mode; /* UNUSED */ - (void)set; /* UNUSED */ - (void)clear; /* UNUSED */ - return (ARCHIVE_OK); -} - -#endif /* __linux */ - -#ifndef HAVE_POSIX_ACL -/* Default empty function body to satisfy mainline code. */ -static int -set_acls(struct archive_write_disk *a) -{ - (void)a; /* UNUSED */ - return (ARCHIVE_OK); -} - -#else - -/* - * XXX TODO: What about ACL types other than ACCESS and DEFAULT? - */ -static int -set_acls(struct archive_write_disk *a) -{ - int ret; - - ret = set_acl(a, a->fd, a->entry, ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); - if (ret != ARCHIVE_OK) - return (ret); - ret = set_acl(a, a->fd, a->entry, ACL_TYPE_DEFAULT, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); - return (ret); -} - - -static int -set_acl(struct archive_write_disk *a, int fd, struct archive_entry *entry, - acl_type_t acl_type, int ae_requested_type, const char *tname) -{ - acl_t acl; - acl_entry_t acl_entry; - acl_permset_t acl_permset; - int ret; - int ae_type, ae_permset, ae_tag, ae_id; - uid_t ae_uid; - gid_t ae_gid; - const char *ae_name; - int entries; - const char *name; - - ret = ARCHIVE_OK; - entries = archive_entry_acl_reset(entry, ae_requested_type); - if (entries == 0) - return (ARCHIVE_OK); - acl = acl_init(entries); - while (archive_entry_acl_next(entry, ae_requested_type, &ae_type, - &ae_permset, &ae_tag, &ae_id, &ae_name) == ARCHIVE_OK) { - acl_create_entry(&acl, &acl_entry); - - switch (ae_tag) { - case ARCHIVE_ENTRY_ACL_USER: - acl_set_tag_type(acl_entry, ACL_USER); - ae_uid = a->lookup_uid(a->lookup_uid_data, - ae_name, ae_id); - acl_set_qualifier(acl_entry, &ae_uid); - break; - case ARCHIVE_ENTRY_ACL_GROUP: - acl_set_tag_type(acl_entry, ACL_GROUP); - ae_gid = a->lookup_gid(a->lookup_gid_data, - ae_name, ae_id); - acl_set_qualifier(acl_entry, &ae_gid); - break; - case ARCHIVE_ENTRY_ACL_USER_OBJ: - acl_set_tag_type(acl_entry, ACL_USER_OBJ); - break; - case ARCHIVE_ENTRY_ACL_GROUP_OBJ: - acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); - break; - case ARCHIVE_ENTRY_ACL_MASK: - acl_set_tag_type(acl_entry, ACL_MASK); - break; - case ARCHIVE_ENTRY_ACL_OTHER: - acl_set_tag_type(acl_entry, ACL_OTHER); - break; - default: - /* XXX */ - break; - } - - acl_get_permset(acl_entry, &acl_permset); - acl_clear_perms(acl_permset); - if (ae_permset & ARCHIVE_ENTRY_ACL_EXECUTE) - acl_add_perm(acl_permset, ACL_EXECUTE); - if (ae_permset & ARCHIVE_ENTRY_ACL_WRITE) - acl_add_perm(acl_permset, ACL_WRITE); - if (ae_permset & ARCHIVE_ENTRY_ACL_READ) - acl_add_perm(acl_permset, ACL_READ); - } - - name = archive_entry_pathname(entry); - - /* Try restoring the ACL through 'fd' if we can. */ -#if HAVE_ACL_SET_FD - if (fd >= 0 && acl_type == ACL_TYPE_ACCESS && acl_set_fd(fd, acl) == 0) - ret = ARCHIVE_OK; - else -#else -#if HAVE_ACL_SET_FD_NP - if (fd >= 0 && acl_set_fd_np(fd, acl, acl_type) == 0) - ret = ARCHIVE_OK; - else -#endif -#endif - if (acl_set_file(name, acl_type, acl) != 0) { - archive_set_error(&a->archive, errno, "Failed to set %s acl", tname); - ret = ARCHIVE_WARN; - } - acl_free(acl); - return (ret); -} -#endif - -#if HAVE_LSETXATTR -/* - * Restore extended attributes - Linux implementation - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - struct archive_entry *entry = a->entry; - static int warning_done = 0; - int ret = ARCHIVE_OK; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - size_t size; - archive_entry_xattr_next(entry, &name, &value, &size); - if (name != NULL && - strncmp(name, "xfsroot.", 8) != 0 && - strncmp(name, "system.", 7) != 0) { - int e; -#if HAVE_FSETXATTR - if (a->fd >= 0) - e = fsetxattr(a->fd, name, value, size, 0); - else -#endif - { - e = lsetxattr(archive_entry_pathname(entry), - name, value, size, 0); - } - if (e == -1) { - if (errno == ENOTSUP) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - ret = ARCHIVE_WARN; - } - } else { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Invalid extended attribute encountered"); - ret = ARCHIVE_WARN; - } - } - return (ret); -} -#elif HAVE_EXTATTR_SET_FILE -/* - * Restore extended attributes - FreeBSD implementation - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - struct archive_entry *entry = a->entry; - static int warning_done = 0; - int ret = ARCHIVE_OK; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - size_t size; - archive_entry_xattr_next(entry, &name, &value, &size); - if (name != NULL) { - int e; - int namespace; - - if (strncmp(name, "user.", 5) == 0) { - /* "user." attributes go to user namespace */ - name += 5; - namespace = EXTATTR_NAMESPACE_USER; - } else { - /* Warn about other extended attributes. */ - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "Can't restore extended attribute ``%s''", - name); - ret = ARCHIVE_WARN; - continue; - } - errno = 0; -#if HAVE_EXTATTR_SET_FD - if (a->fd >= 0) - e = extattr_set_fd(a->fd, namespace, name, value, size); - else -#endif - /* TODO: should we use extattr_set_link() instead? */ - { - e = extattr_set_file(archive_entry_pathname(entry), - namespace, name, value, size); - } - if (e != (int)size) { - if (errno == ENOTSUP) { - if (!warning_done) { - warning_done = 1; - archive_set_error(&a->archive, errno, - "Cannot restore extended " - "attributes on this file " - "system"); - } - } else { - archive_set_error(&a->archive, errno, - "Failed to set extended attribute"); - } - - ret = ARCHIVE_WARN; - } - } - } - return (ret); -} -#else -/* - * Restore extended attributes - stub implementation for unsupported systems - */ -static int -set_xattrs(struct archive_write_disk *a) -{ - static int warning_done = 0; - - /* If there aren't any extended attributes, then it's okay not - * to extract them, otherwise, issue a single warning. */ - if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) { - warning_done = 1; - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Cannot restore extended attributes on this system"); - return (ARCHIVE_WARN); - } - /* Warning was already emitted; suppress further warnings. */ - return (ARCHIVE_OK); -} -#endif - - -/* - * Trivial implementations of gid/uid lookup functions. - * These are normally overridden by the client, but these stub - * versions ensure that we always have something that works. - */ -static gid_t -trivial_lookup_gid(void *private_data, const char *gname, gid_t gid) -{ - (void)private_data; /* UNUSED */ - (void)gname; /* UNUSED */ - return (gid); -} - -static uid_t -trivial_lookup_uid(void *private_data, const char *uname, uid_t uid) -{ - (void)private_data; /* UNUSED */ - (void)uname; /* UNUSED */ - return (uid); -} - -/* - * Test if file on disk is older than entry. - */ -static int -older(struct stat *st, struct archive_entry *entry) -{ - /* First, test the seconds and return if we have a definite answer. */ - /* Definitely older. */ - if (st->st_mtime < archive_entry_mtime(entry)) - return (1); - /* Definitely younger. */ - if (st->st_mtime > archive_entry_mtime(entry)) - return (0); - /* If this platform supports fractional seconds, try those. */ -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC - /* Definitely older. */ - if (st->st_mtimespec.tv_nsec < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC - /* Definitely older. */ - if (st->st_mtim.tv_nsec < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIME_N - /* older. */ - if (st->st_mtime_n < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_UMTIME - /* older. */ - if (st->st_umtime * 1000 < archive_entry_mtime_nsec(entry)) - return (1); -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC - /* older. */ - if (st->st_mtime_usec * 1000 < archive_entry_mtime_nsec(entry)) - return (1); -#else - /* This system doesn't have high-res timestamps. */ -#endif - /* Same age or newer, so not older. */ - return (0); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c new file mode 100644 index 000000000..99afab2f6 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_posix.c @@ -0,0 +1,2844 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * 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 + * in this position and unchanged. + * 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$"); + +#if !defined(_WIN32) || defined(__CYGWIN__) + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_ACL_H +#include +#endif +#ifdef HAVE_SYS_EXTATTR_H +#include +#endif +#ifdef HAVE_SYS_XATTR_H +#include +#endif +#ifdef HAVE_SYS_EA_H +#include +#endif +#ifdef HAVE_ATTR_XATTR_H +#include +#endif +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#ifdef HAVE_COPYFILE_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif +#ifdef HAVE_LANGINFO_H +#include +#endif +#ifdef HAVE_LINUX_FS_H +#include /* for Linux file flags */ +#endif +/* + * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. + * As the include guards don't agree, the order of include is important. + */ +#ifdef HAVE_LINUX_EXT2_FS_H +#include /* for Linux file flags */ +#endif +#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) +#include /* Linux file flags, broken on Cygwin */ +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#ifdef HAVE_PWD_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_UTIME_H +#include +#endif +#ifdef F_GETTIMES /* Tru64 specific */ +#include +#endif + +#if __APPLE__ +#include +#if TARGET_OS_MAC && !TARGET_OS_EMBEDDED && HAVE_QUARANTINE_H +#include +#define HAVE_QUARANTINE 1 +#endif +#endif + +/* TODO: Support Mac OS 'quarantine' feature. This is really just a + * standard tag to mark files that have been downloaded as "tainted". + * On Mac OS, we should mark the extracted files as tainted if the + * archive being read was tainted. Windows has a similar feature; we + * should investigate ways to support this generically. */ + +#include "archive.h" +#include "archive_acl_private.h" +#include "archive_string.h" +#include "archive_entry.h" +#include "archive_private.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +struct fixup_entry { + struct fixup_entry *next; + struct archive_acl acl; + mode_t mode; + int64_t atime; + int64_t birthtime; + int64_t mtime; + int64_t ctime; + unsigned long atime_nanos; + unsigned long birthtime_nanos; + unsigned long mtime_nanos; + unsigned long ctime_nanos; + unsigned long fflags_set; + size_t mac_metadata_size; + void *mac_metadata; + int fixup; /* bitmask of what needs fixing */ + char *name; +}; + +/* + * We use a bitmask to track which operations remain to be done for + * this file. In particular, this helps us avoid unnecessary + * operations when it's possible to take care of one step as a + * side-effect of another. For example, mkdir() can specify the mode + * for the newly-created object but symlink() cannot. This means we + * can skip chmod() if mkdir() succeeded, but we must explicitly + * chmod() if we're trying to create a directory that already exists + * (mkdir() failed) or if we're restoring a symlink. Similarly, we + * need to verify UID/GID before trying to restore SUID/SGID bits; + * that verification can occur explicitly through a stat() call or + * implicitly because of a successful chown() call. + */ +#define TODO_MODE_FORCE 0x40000000 +#define TODO_MODE_BASE 0x20000000 +#define TODO_SUID 0x10000000 +#define TODO_SUID_CHECK 0x08000000 +#define TODO_SGID 0x04000000 +#define TODO_SGID_CHECK 0x02000000 +#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID) +#define TODO_TIMES ARCHIVE_EXTRACT_TIME +#define TODO_OWNER ARCHIVE_EXTRACT_OWNER +#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS +#define TODO_ACLS ARCHIVE_EXTRACT_ACL +#define TODO_XATTR ARCHIVE_EXTRACT_XATTR +#define TODO_MAC_METADATA ARCHIVE_EXTRACT_MAC_METADATA + +struct archive_write_disk { + struct archive archive; + + mode_t user_umask; + struct fixup_entry *fixup_list; + struct fixup_entry *current_fixup; + int64_t user_uid; + int skip_file_set; + dev_t skip_file_dev; + ino_t skip_file_ino; + time_t start_time; + + int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid); + void (*cleanup_gid)(void *private); + void *lookup_gid_data; + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid); + void (*cleanup_uid)(void *private); + void *lookup_uid_data; + + /* + * Full path of last file to satisfy symlink checks. + */ + struct archive_string path_safe; + + /* + * Cached stat data from disk for the current entry. + * If this is valid, pst points to st. Otherwise, + * pst is null. + */ + struct stat st; + struct stat *pst; + + /* Information about the object being restored right now. */ + struct archive_entry *entry; /* Entry being extracted. */ + char *name; /* Name of entry, possibly edited. */ + struct archive_string _name_data; /* backing store for 'name' */ + /* Tasks remaining for this object. */ + int todo; + /* Tasks deferred until end-of-archive. */ + int deferred; + /* Options requested by the client. */ + int flags; + /* Handle for the file we're restoring. */ + int fd; + /* Current offset for writing data to the file. */ + int64_t offset; + /* Last offset actually written to disk. */ + int64_t fd_offset; + /* Total bytes actually written to files. */ + int64_t total_bytes_written; + /* Maximum size of file, -1 if unknown. */ + int64_t filesize; + /* Dir we were in before this restore; only for deep paths. */ + int restore_pwd; + /* Mode we should use for this entry; affected by _PERM and umask. */ + mode_t mode; + /* UID/GID to use in restoring this entry. */ + int64_t uid; + int64_t gid; +}; + +/* + * Default mode for dirs created automatically (will be modified by umask). + * Note that POSIX specifies 0777 for implicitly-created dirs, "modified + * by the process' file creation mask." + */ +#define DEFAULT_DIR_MODE 0777 +/* + * Dir modes are restored in two steps: During the extraction, the permissions + * in the archive are modified to match the following limits. During + * the post-extract fixup pass, the permissions from the archive are + * applied. + */ +#define MINIMUM_DIR_MODE 0700 +#define MAXIMUM_DIR_MODE 0775 + +static int check_symlinks(struct archive_write_disk *); +static int create_filesystem_object(struct archive_write_disk *); +static struct fixup_entry *current_fixup(struct archive_write_disk *, const char *pathname); +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) +static void edit_deep_directories(struct archive_write_disk *ad); +#endif +static int cleanup_pathname(struct archive_write_disk *); +static int create_dir(struct archive_write_disk *, char *); +static int create_parent_dir(struct archive_write_disk *, char *); +static int older(struct stat *, struct archive_entry *); +static int restore_entry(struct archive_write_disk *); +#ifdef HAVE_POSIX_ACL +static int set_acl(struct archive_write_disk *, int fd, const char *, struct archive_acl *, + acl_type_t, int archive_entry_acl_type, const char *tn); +#endif +static int set_acls(struct archive_write_disk *, int fd, const char *, struct archive_acl *); +static int set_mac_metadata(struct archive_write_disk *, const char *, + const void *, size_t); +static int set_xattrs(struct archive_write_disk *); +static int set_fflags(struct archive_write_disk *); +static int set_fflags_platform(struct archive_write_disk *, int fd, + const char *name, mode_t mode, + unsigned long fflags_set, unsigned long fflags_clear); +static int set_ownership(struct archive_write_disk *); +static int set_mode(struct archive_write_disk *, int mode); +static int set_time(int, int, const char *, time_t, long, time_t, long); +static int set_times(struct archive_write_disk *, int, int, const char *, + time_t, long, time_t, long, time_t, long, time_t, long); +static int set_times_from_entry(struct archive_write_disk *); +static struct fixup_entry *sort_dir_list(struct fixup_entry *p); +static ssize_t write_data_block(struct archive_write_disk *, + const char *, size_t); + +static struct archive_vtable *archive_write_disk_vtable(void); + +static int _archive_write_disk_close(struct archive *); +static int _archive_write_disk_free(struct archive *); +static int _archive_write_disk_header(struct archive *, struct archive_entry *); +static int64_t _archive_write_disk_filter_bytes(struct archive *, int); +static int _archive_write_disk_finish_entry(struct archive *); +static ssize_t _archive_write_disk_data(struct archive *, const void *, size_t); +static ssize_t _archive_write_disk_data_block(struct archive *, const void *, size_t, int64_t); + +static int +lazy_stat(struct archive_write_disk *a) +{ + if (a->pst != NULL) { + /* Already have stat() data available. */ + return (ARCHIVE_OK); + } +#ifdef HAVE_FSTAT + if (a->fd >= 0 && fstat(a->fd, &a->st) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } +#endif + /* + * XXX At this point, symlinks should not be hit, otherwise + * XXX a race occurred. Do we want to check explicitly for that? + */ + if (lstat(a->name, &a->st) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } + archive_set_error(&a->archive, errno, "Couldn't stat file"); + return (ARCHIVE_WARN); +} + +static struct archive_vtable * +archive_write_disk_vtable(void) +{ + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_close = _archive_write_disk_close; + av.archive_filter_bytes = _archive_write_disk_filter_bytes; + av.archive_free = _archive_write_disk_free; + av.archive_write_header = _archive_write_disk_header; + av.archive_write_finish_entry + = _archive_write_disk_finish_entry; + av.archive_write_data = _archive_write_disk_data; + av.archive_write_data_block = _archive_write_disk_data_block; + inited = 1; + } + return (&av); +} + +static int64_t +_archive_write_disk_filter_bytes(struct archive *_a, int n) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + (void)n; /* UNUSED */ + if (n == -1 || n == 0) + return (a->total_bytes_written); + return (-1); +} + + +int +archive_write_disk_set_options(struct archive *_a, int flags) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + a->flags = flags; + return (ARCHIVE_OK); +} + + +/* + * Extract this entry to disk. + * + * TODO: Validate hardlinks. According to the standards, we're + * supposed to check each extracted hardlink and squawk if it refers + * to a file that we didn't restore. I'm not entirely convinced this + * is a good idea, but more importantly: Is there any way to validate + * hardlinks without keeping a complete list of filenames from the + * entire archive?? Ugh. + * + */ +static int +_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; + int ret, r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_header"); + archive_clear_error(&a->archive); + if (a->archive.state & ARCHIVE_STATE_DATA) { + r = _archive_write_disk_finish_entry(&a->archive); + if (r == ARCHIVE_FATAL) + return (r); + } + + /* Set up for this particular entry. */ + a->pst = NULL; + a->current_fixup = NULL; + a->deferred = 0; + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->entry = archive_entry_clone(entry); + a->fd = -1; + a->fd_offset = 0; + a->offset = 0; + a->restore_pwd = -1; + a->uid = a->user_uid; + a->mode = archive_entry_mode(a->entry); + if (archive_entry_size_is_set(a->entry)) + a->filesize = archive_entry_size(a->entry); + else + a->filesize = -1; + archive_strcpy(&(a->_name_data), archive_entry_pathname(a->entry)); + a->name = a->_name_data.s; + archive_clear_error(&a->archive); + + /* + * Clean up the requested path. This is necessary for correct + * dir restores; the dir restore logic otherwise gets messed + * up by nonsense like "dir/.". + */ + ret = cleanup_pathname(a); + if (ret != ARCHIVE_OK) + return (ret); + + /* + * 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 + * reason. + */ + umask(a->user_umask = umask(0)); + + /* Figure out what we need to do for this entry. */ + a->todo = TODO_MODE_BASE; + if (a->flags & ARCHIVE_EXTRACT_PERM) { + a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */ + /* + * SGID requires an extra "check" step because we + * cannot easily predict the GID that the system will + * assign. (Different systems assign GIDs to files + * based on a variety of criteria, including process + * credentials and the gid of the enclosing + * directory.) We can only restore the SGID bit if + * the file has the right GID, and we only know the + * GID if we either set it (see set_ownership) or if + * we've actually called stat() on the file after it + * was restored. Since there are several places at + * which we might verify the GID, we need a TODO bit + * to keep track. + */ + if (a->mode & S_ISGID) + a->todo |= TODO_SGID | TODO_SGID_CHECK; + /* + * Verifying the SUID is simpler, but can still be + * done in multiple ways, hence the separate "check" bit. + */ + if (a->mode & S_ISUID) + a->todo |= TODO_SUID | TODO_SUID_CHECK; + } else { + /* + * User didn't request full permissions, so don't + * restore SUID, SGID bits and obey umask. + */ + a->mode &= ~S_ISUID; + a->mode &= ~S_ISGID; + a->mode &= ~S_ISVTX; + a->mode &= ~a->user_umask; + } + if (a->flags & ARCHIVE_EXTRACT_OWNER) + a->todo |= TODO_OWNER; + if (a->flags & ARCHIVE_EXTRACT_TIME) + a->todo |= TODO_TIMES; + if (a->flags & ARCHIVE_EXTRACT_ACL) { + if (archive_entry_filetype(a->entry) == AE_IFDIR) + a->deferred |= TODO_ACLS; + else + a->todo |= TODO_ACLS; + } + if (a->flags & ARCHIVE_EXTRACT_MAC_METADATA) { + if (archive_entry_filetype(a->entry) == AE_IFDIR) + a->deferred |= TODO_MAC_METADATA; + else + a->todo |= TODO_MAC_METADATA; + } + if (a->flags & ARCHIVE_EXTRACT_XATTR) + a->todo |= TODO_XATTR; + if (a->flags & ARCHIVE_EXTRACT_FFLAGS) + a->todo |= TODO_FFLAGS; + if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { + ret = check_symlinks(a); + if (ret != ARCHIVE_OK) + return (ret); + } +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) + /* If path exceeds PATH_MAX, shorten the path. */ + edit_deep_directories(a); +#endif + + ret = restore_entry(a); + + /* + * TODO: There are rumours that some extended attributes must + * be restored before file data is written. If this is true, + * then we either need to write all extended attributes both + * before and after restoring the data, or find some rule for + * determining which must go first and which last. Due to the + * many ways people are using xattrs, this may prove to be an + * intractable problem. + */ + +#ifdef HAVE_FCHDIR + /* If we changed directory above, restore it here. */ + if (a->restore_pwd >= 0) { + r = fchdir(a->restore_pwd); + if (r != 0) { + archive_set_error(&a->archive, errno, "chdir() failure"); + ret = ARCHIVE_FATAL; + } + close(a->restore_pwd); + a->restore_pwd = -1; + } +#endif + + /* + * Fixup uses the unedited pathname from archive_entry_pathname(), + * because it is relative to the base dir and the edited path + * might be relative to some intermediate dir as a result of the + * deep restore logic. + */ + if (a->deferred & TODO_MODE) { + fe = current_fixup(a, archive_entry_pathname(entry)); + fe->fixup |= TODO_MODE_BASE; + fe->mode = a->mode; + } + + if ((a->deferred & TODO_TIMES) + && (archive_entry_mtime_is_set(entry) + || archive_entry_atime_is_set(entry))) { + fe = current_fixup(a, archive_entry_pathname(entry)); + fe->mode = a->mode; + fe->fixup |= TODO_TIMES; + if (archive_entry_atime_is_set(entry)) { + fe->atime = archive_entry_atime(entry); + fe->atime_nanos = archive_entry_atime_nsec(entry); + } else { + /* If atime is unset, use start time. */ + fe->atime = a->start_time; + fe->atime_nanos = 0; + } + if (archive_entry_mtime_is_set(entry)) { + fe->mtime = archive_entry_mtime(entry); + fe->mtime_nanos = archive_entry_mtime_nsec(entry); + } else { + /* If mtime is unset, use start time. */ + fe->mtime = a->start_time; + fe->mtime_nanos = 0; + } + if (archive_entry_birthtime_is_set(entry)) { + fe->birthtime = archive_entry_birthtime(entry); + fe->birthtime_nanos = archive_entry_birthtime_nsec(entry); + } else { + /* If birthtime is unset, use mtime. */ + fe->birthtime = fe->mtime; + fe->birthtime_nanos = fe->mtime_nanos; + } + } + + if (a->deferred & TODO_ACLS) { + fe = current_fixup(a, archive_entry_pathname(entry)); + archive_acl_copy(&fe->acl, archive_entry_acl(entry)); + } + + if (a->deferred & TODO_MAC_METADATA) { + const void *metadata; + size_t metadata_size; + metadata = archive_entry_mac_metadata(a->entry, &metadata_size); + if (metadata != NULL && metadata_size > 0) { + fe = current_fixup(a, archive_entry_pathname(entry)); + fe->mac_metadata = malloc(metadata_size); + if (fe->mac_metadata != NULL) { + memcpy(fe->mac_metadata, metadata, metadata_size); + fe->mac_metadata_size = metadata_size; + fe->fixup |= TODO_MAC_METADATA; + } + } + } + + if (a->deferred & TODO_FFLAGS) { + fe = current_fixup(a, archive_entry_pathname(entry)); + fe->fixup |= TODO_FFLAGS; + /* TODO: Complete this.. defer fflags from below. */ + } + + /* We've created the object and are ready to pour data into it. */ + if (ret >= ARCHIVE_WARN) + a->archive.state = ARCHIVE_STATE_DATA; + /* + * If it's not open, tell our client not to try writing. + * In particular, dirs, links, etc, don't get written to. + */ + if (a->fd < 0) { + archive_entry_set_size(entry, 0); + a->filesize = 0; + } + + return (ret); +} + +int +archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file"); + a->skip_file_set = 1; + a->skip_file_dev = d; + a->skip_file_ino = i; + return (ARCHIVE_OK); +} + +static ssize_t +write_data_block(struct archive_write_disk *a, const char *buff, size_t size) +{ + uint64_t start_size = size; + ssize_t bytes_written = 0; + ssize_t block_size = 0, bytes_to_write; + + if (size == 0) + return (ARCHIVE_OK); + + if (a->filesize == 0 || a->fd < 0) { + archive_set_error(&a->archive, 0, + "Attempt to write to an empty file"); + return (ARCHIVE_WARN); + } + + if (a->flags & ARCHIVE_EXTRACT_SPARSE) { +#if HAVE_STRUCT_STAT_ST_BLKSIZE + int r; + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + block_size = a->pst->st_blksize; +#else + /* XXX TODO XXX Is there a more appropriate choice here ? */ + /* This needn't match the filesystem allocation size. */ + block_size = 16*1024; +#endif + } + + /* If this write would run beyond the file size, truncate it. */ + if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize) + start_size = size = (size_t)(a->filesize - a->offset); + + /* Write the data. */ + while (size > 0) { + if (block_size == 0) { + bytes_to_write = size; + } else { + /* We're sparsifying the file. */ + const char *p, *end; + int64_t block_end; + + /* Skip leading zero bytes. */ + for (p = buff, end = buff + size; p < end; ++p) { + if (*p != '\0') + break; + } + a->offset += p - buff; + size -= p - buff; + buff = p; + if (size == 0) + break; + + /* Calculate next block boundary after offset. */ + block_end + = (a->offset / block_size + 1) * block_size; + + /* If the adjusted write would cross block boundary, + * truncate it to the block boundary. */ + bytes_to_write = size; + if (a->offset + bytes_to_write > block_end) + bytes_to_write = block_end - a->offset; + } + /* Seek if necessary to the specified offset. */ + if (a->offset != a->fd_offset) { + if (lseek(a->fd, a->offset, SEEK_SET) < 0) { + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + a->fd_offset = a->offset; + } + bytes_written = write(a->fd, buff, bytes_to_write); + if (bytes_written < 0) { + archive_set_error(&a->archive, errno, "Write failed"); + return (ARCHIVE_WARN); + } + buff += bytes_written; + size -= bytes_written; + a->total_bytes_written += bytes_written; + a->offset += bytes_written; + a->fd_offset = a->offset; + } + return (start_size - size); +} + +static ssize_t +_archive_write_disk_data_block(struct archive *_a, + const void *buff, size_t size, int64_t offset) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + ssize_t r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data_block"); + + a->offset = offset; + r = write_data_block(a, buff, size); + if (r < ARCHIVE_OK) + return (r); + if ((size_t)r < size) { + archive_set_error(&a->archive, 0, + "Write request too large"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static ssize_t +_archive_write_disk_data(struct archive *_a, const void *buff, size_t size) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data"); + + return (write_data_block(a, buff, size)); +} + +static int +_archive_write_disk_finish_entry(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + int ret = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_finish_entry"); + if (a->archive.state & ARCHIVE_STATE_HEADER) + return (ARCHIVE_OK); + archive_clear_error(&a->archive); + + /* Pad or truncate file to the right size. */ + if (a->fd < 0) { + /* There's no file. */ + } else if (a->filesize < 0) { + /* File size is unknown, so we can't set the size. */ + } else if (a->fd_offset == a->filesize) { + /* Last write ended at exactly the filesize; we're done. */ + /* Hopefully, this is the common case. */ + } else { +#if HAVE_FTRUNCATE + if (ftruncate(a->fd, a->filesize) == -1 && + a->filesize == 0) { + archive_set_error(&a->archive, errno, + "File size could not be restored"); + return (ARCHIVE_FAILED); + } +#endif + /* + * Not all platforms implement the XSI option to + * extend files via ftruncate. Stat() the file again + * to see what happened. + */ + a->pst = NULL; + if ((ret = lazy_stat(a)) != ARCHIVE_OK) + return (ret); + /* We can use lseek()/write() to extend the file if + * ftruncate didn't work or isn't available. */ + if (a->st.st_size < a->filesize) { + const char nul = '\0'; + if (lseek(a->fd, a->filesize - 1, SEEK_SET) < 0) { + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + if (write(a->fd, &nul, 1) < 0) { + archive_set_error(&a->archive, errno, + "Write to restore size failed"); + return (ARCHIVE_FATAL); + } + a->pst = NULL; + } + } + + /* Restore metadata. */ + + /* + * Look up the "real" UID only if we're going to need it. + * TODO: the TODO_SGID condition can be dropped here, can't it? + */ + if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) { + a->uid = archive_write_disk_uid(&a->archive, + archive_entry_uname(a->entry), + archive_entry_uid(a->entry)); + } + /* Look up the "real" GID only if we're going to need it. */ + /* TODO: the TODO_SUID condition can be dropped here, can't it? */ + if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) { + a->gid = archive_write_disk_gid(&a->archive, + archive_entry_gname(a->entry), + archive_entry_gid(a->entry)); + } + + /* + * Restore ownership before set_mode tries to restore suid/sgid + * bits. If we set the owner, we know what it is and can skip + * a stat() call to examine the ownership of the file on disk. + */ + if (a->todo & TODO_OWNER) + ret = set_ownership(a); + + /* + * set_mode must precede ACLs on systems such as Solaris and + * FreeBSD where setting the mode implicitly clears extended ACLs + */ + if (a->todo & TODO_MODE) { + int r2 = set_mode(a, a->mode); + if (r2 < ret) ret = r2; + } + + /* + * Security-related extended attributes (such as + * security.capability on Linux) have to be restored last, + * since they're implicitly removed by other file changes. + */ + if (a->todo & TODO_XATTR) { + int r2 = set_xattrs(a); + if (r2 < ret) ret = r2; + } + + /* + * Some flags prevent file modification; they must be restored after + * file contents are written. + */ + if (a->todo & TODO_FFLAGS) { + int r2 = set_fflags(a); + if (r2 < ret) ret = r2; + } + + /* + * Time must follow most other metadata; + * otherwise atime will get changed. + */ + if (a->todo & TODO_TIMES) { + int r2 = set_times_from_entry(a); + if (r2 < ret) ret = r2; + } + + /* + * Mac extended metadata includes ACLs. + */ + if (a->todo & TODO_MAC_METADATA) { + const void *metadata; + size_t metadata_size; + metadata = archive_entry_mac_metadata(a->entry, &metadata_size); + if (metadata != NULL && metadata_size > 0) { + int r2 = set_mac_metadata(a, archive_entry_pathname(a->entry), metadata, metadata_size); + if (r2 < ret) ret = r2; + } + } + + /* + * ACLs must be restored after timestamps because there are + * ACLs that prevent attribute changes (including time). + */ + if (a->todo & TODO_ACLS) { + int r2 = set_acls(a, a->fd, + archive_entry_pathname(a->entry), + archive_entry_acl(a->entry)); + if (r2 < ret) ret = r2; + } + + /* If there's an fd, we can close it now. */ + if (a->fd >= 0) { + close(a->fd); + a->fd = -1; + } + /* If there's an entry, we can release it now. */ + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->archive.state = ARCHIVE_STATE_HEADER; + return (ret); +} + +int +archive_write_disk_set_group_lookup(struct archive *_a, + void *private_data, + int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid), + void (*cleanup_gid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup"); + + if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL) + (a->cleanup_gid)(a->lookup_gid_data); + + a->lookup_gid = lookup_gid; + a->cleanup_gid = cleanup_gid; + a->lookup_gid_data = private_data; + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_user_lookup(struct archive *_a, + void *private_data, + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid), + void (*cleanup_uid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup"); + + if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL) + (a->cleanup_uid)(a->lookup_uid_data); + + a->lookup_uid = lookup_uid; + a->cleanup_uid = cleanup_uid; + a->lookup_uid_data = private_data; + return (ARCHIVE_OK); +} + +int64_t +archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_gid"); + if (a->lookup_gid) + return (a->lookup_gid)(a->lookup_gid_data, name, id); + return (id); +} + +int64_t +archive_write_disk_uid(struct archive *_a, const char *name, int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_uid"); + if (a->lookup_uid) + return (a->lookup_uid)(a->lookup_uid_data, name, id); + return (id); +} + +/* + * Create a new archive_write_disk object and initialize it with global state. + */ +struct archive * +archive_write_disk_new(void) +{ + struct archive_write_disk *a; + + a = (struct archive_write_disk *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; + /* We're ready to write a header immediately. */ + a->archive.state = ARCHIVE_STATE_HEADER; + a->archive.vtable = archive_write_disk_vtable(); + a->start_time = time(NULL); + /* Query and restore the umask. */ + umask(a->user_umask = umask(0)); +#ifdef HAVE_GETEUID + a->user_uid = geteuid(); +#endif /* HAVE_GETEUID */ + if (archive_string_ensure(&a->path_safe, 512) == NULL) { + free(a); + return (NULL); + } + return (&a->archive); +} + + +/* + * If pathname is longer than PATH_MAX, chdir to a suitable + * intermediate dir and edit the path down to a shorter suffix. Note + * that this routine never returns an error; if the chdir() attempt + * fails for any reason, we just go ahead with the long pathname. The + * object creation is likely to fail, but any error will get handled + * at that time. + */ +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) +static void +edit_deep_directories(struct archive_write_disk *a) +{ + int ret; + char *tail = a->name; + + /* If path is short, avoid the open() below. */ + if (strlen(tail) <= PATH_MAX) + return; + + /* Try to record our starting dir. */ + a->restore_pwd = open(".", O_RDONLY | O_BINARY); + if (a->restore_pwd < 0) + return; + + /* As long as the path is too long... */ + while (strlen(tail) > PATH_MAX) { + /* Locate a dir prefix shorter than PATH_MAX. */ + tail += PATH_MAX - 8; + while (tail > a->name && *tail != '/') + tail--; + /* Exit if we find a too-long path component. */ + if (tail <= a->name) + return; + /* Create the intermediate dir and chdir to it. */ + *tail = '\0'; /* Terminate dir portion */ + ret = create_dir(a, a->name); + if (ret == ARCHIVE_OK && chdir(a->name) != 0) + ret = ARCHIVE_FAILED; + *tail = '/'; /* Restore the / we removed. */ + if (ret != ARCHIVE_OK) + return; + tail++; + /* The chdir() succeeded; we've now shortened the path. */ + a->name = tail; + } + return; +} +#endif + +/* + * The main restore function. + */ +static int +restore_entry(struct archive_write_disk *a) +{ + int ret = ARCHIVE_OK, en; + + if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { + /* + * TODO: Fix this. Apparently, there are platforms + * that still allow root to hose the entire filesystem + * by unlinking a dir. The S_ISDIR() test above + * prevents us from using unlink() here if the new + * object is a dir, but that doesn't mean the old + * object isn't a dir. + */ + if (unlink(a->name) == 0) { + /* We removed it, reset cached stat. */ + a->pst = NULL; + } else if (errno == ENOENT) { + /* File didn't exist, that's just as good. */ + } else if (rmdir(a->name) == 0) { + /* It was a dir, but now it's gone. */ + a->pst = NULL; + } else { + /* We tried, but couldn't get rid of it. */ + archive_set_error(&a->archive, errno, + "Could not unlink"); + return(ARCHIVE_FAILED); + } + } + + /* Try creating it first; if this fails, we'll try to recover. */ + en = create_filesystem_object(a); + + if ((en == ENOTDIR || en == ENOENT) + && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) { + /* If the parent dir doesn't exist, try creating it. */ + create_parent_dir(a, a->name); + /* Now try to create the object again. */ + en = create_filesystem_object(a); + } + + if ((en == EISDIR || en == EEXIST) + && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + /* If we're not overwriting, we're done. */ + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + + /* + * Some platforms return EISDIR if you call + * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some + * return EEXIST. POSIX is ambiguous, requiring EISDIR + * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT) + * on an existing item. + */ + if (en == EISDIR) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't remove already-existing dir"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (en == EEXIST) { + /* + * We know something is in the way, but we don't know what; + * we need to find out before we go any further. + */ + int r = 0; + /* + * The SECURE_SYMLINKS logic has already removed a + * symlink to a dir if the client wants that. So + * follow the symlink if we're creating a dir. + */ + if (S_ISDIR(a->mode)) + r = stat(a->name, &a->st); + /* + * If it's not a dir (or it's a broken symlink), + * then don't follow it. + */ + if (r != 0 || !S_ISDIR(a->mode)) + r = lstat(a->name, &a->st); + if (r != 0) { + archive_set_error(&a->archive, errno, + "Can't stat existing object"); + return (ARCHIVE_FAILED); + } + + /* + * NO_OVERWRITE_NEWER doesn't apply to directories. + */ + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER) + && !S_ISDIR(a->st.st_mode)) { + if (!older(&(a->st), a->entry)) { + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + } + + /* If it's our archive, we're done. */ + if (a->skip_file_set && + a->st.st_dev == a->skip_file_dev && + a->st.st_ino == a->skip_file_ino) { + archive_set_error(&a->archive, 0, "Refusing to overwrite archive"); + return (ARCHIVE_FAILED); + } + + if (!S_ISDIR(a->st.st_mode)) { + /* A non-dir is in the way, unlink it. */ + if (unlink(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't unlink already-existing object"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (!S_ISDIR(a->mode)) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't remove already-existing dir"); + return (ARCHIVE_FAILED); + } + /* Try again. */ + en = create_filesystem_object(a); + } else { + /* + * There's a dir in the way of a dir. Don't + * waste time with rmdir()/mkdir(), just fix + * up the permissions on the existing dir. + * Note that we don't change perms on existing + * dirs unless _EXTRACT_PERM is specified. + */ + if ((a->mode != a->st.st_mode) + && (a->todo & TODO_MODE_FORCE)) + a->deferred |= (a->todo & TODO_MODE); + /* Ownership doesn't need deferred fixup. */ + en = 0; /* Forget the EEXIST. */ + } + } + + if (en) { + /* Everything failed; give up here. */ + archive_set_error(&a->archive, en, "Can't create '%s'", + a->name); + return (ARCHIVE_FAILED); + } + + a->pst = NULL; /* Cached stat data no longer valid. */ + return (ret); +} + +/* + * Returns 0 if creation succeeds, or else returns errno value from + * the failed system call. Note: This function should only ever perform + * a single system call. + */ +static int +create_filesystem_object(struct archive_write_disk *a) +{ + /* Create the entry. */ + const char *linkname; + mode_t final_mode, mode; + int r; + + /* We identify hard/symlinks according to the link names. */ + /* Since link(2) and symlink(2) don't handle modes, we're done here. */ + linkname = archive_entry_hardlink(a->entry); + if (linkname != NULL) { +#if !HAVE_LINK + return (EPERM); +#else + r = link(linkname, a->name) ? errno : 0; + /* + * New cpio and pax formats allow hardlink entries + * to carry data, so we may have to open the file + * for hardlink entries. + * + * If the hardlink was successfully created and + * the archive doesn't have carry data for it, + * consider it to be non-authoritive for meta data. + * This is consistent with GNU tar and BSD pax. + * If the hardlink does carry data, let the last + * archive entry decide ownership. + */ + if (r == 0 && a->filesize <= 0) { + a->todo = 0; + a->deferred = 0; + } else if (r == 0 && a->filesize > 0) { + a->fd = open(a->name, O_WRONLY | O_TRUNC | O_BINARY); + if (a->fd < 0) + r = errno; + } + return (r); +#endif + } + linkname = archive_entry_symlink(a->entry); + if (linkname != NULL) { +#if HAVE_SYMLINK + return symlink(linkname, a->name) ? errno : 0; +#else + return (EPERM); +#endif + } + + /* + * The remaining system calls all set permissions, so let's + * try to take advantage of that to avoid an extra chmod() + * call. (Recall that umask is set to zero right now!) + */ + + /* Mode we want for the final restored object (w/o file type bits). */ + final_mode = a->mode & 07777; + /* + * The mode that will actually be restored in this step. Note + * that SUID, SGID, etc, require additional work to ensure + * security, so we never restore them at this point. + */ + mode = final_mode & 0777 & a->user_umask; + + switch (a->mode & AE_IFMT) { + default: + /* POSIX requires that we fall through here. */ + /* FALLTHROUGH */ + case AE_IFREG: + a->fd = open(a->name, + O_WRONLY | O_CREAT | O_EXCL | O_BINARY, mode); + r = (a->fd < 0); + break; + case AE_IFCHR: +#ifdef HAVE_MKNOD + /* Note: we use AE_IFCHR for the case label, and + * S_IFCHR for the mknod() call. This is correct. */ + r = mknod(a->name, mode | S_IFCHR, + archive_entry_rdev(a->entry)); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a char device node. */ + return (EINVAL); +#endif /* HAVE_MKNOD */ + case AE_IFBLK: +#ifdef HAVE_MKNOD + r = mknod(a->name, mode | S_IFBLK, + archive_entry_rdev(a->entry)); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a block device node. */ + return (EINVAL); +#endif /* HAVE_MKNOD */ + case AE_IFDIR: + mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE; + r = mkdir(a->name, mode); + if (r == 0) { + /* Defer setting dir times. */ + a->deferred |= (a->todo & TODO_TIMES); + a->todo &= ~TODO_TIMES; + /* Never use an immediate chmod(). */ + /* We can't avoid the chmod() entirely if EXTRACT_PERM + * because of SysV SGID inheritance. */ + if ((mode != final_mode) + || (a->flags & ARCHIVE_EXTRACT_PERM)) + a->deferred |= (a->todo & TODO_MODE); + a->todo &= ~TODO_MODE; + } + break; + case AE_IFIFO: +#ifdef HAVE_MKFIFO + r = mkfifo(a->name, mode); + break; +#else + /* TODO: Find a better way to warn about our inability + * to restore a fifo. */ + return (EINVAL); +#endif /* HAVE_MKFIFO */ + } + + /* All the system calls above set errno on failure. */ + if (r) + return (errno); + + /* If we managed to set the final mode, we've avoided a chmod(). */ + if (mode == final_mode) + a->todo &= ~TODO_MODE; + return (0); +} + +/* + * Cleanup function for archive_extract. Mostly, this involves processing + * the fixup list, which is used to address a number of problems: + * * Dir permissions might prevent us from restoring a file in that + * dir, so we restore the dir with minimum 0700 permissions first, + * then correct the mode at the end. + * * Similarly, the act of restoring a file touches the directory + * and changes the timestamp on the dir, so we have to touch-up dir + * timestamps at the end as well. + * * Some file flags can interfere with the restore by, for example, + * preventing the creation of hardlinks to those files. + * * Mac OS extended metadata includes ACLs, so must be deferred on dirs. + * + * Note that tar/cpio do not require that archives be in a particular + * order; there is no way to know when the last file has been restored + * within a directory, so there's no way to optimize the memory usage + * here by fixing up the directory any earlier than the + * end-of-archive. + * + * XXX TODO: Directory ACLs should be restored here, for the same + * reason we set directory perms here. XXX + */ +static int +_archive_write_disk_close(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + struct fixup_entry *next, *p; + int ret; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_close"); + ret = _archive_write_disk_finish_entry(&a->archive); + + /* Sort dir list so directories are fixed up in depth-first order. */ + p = sort_dir_list(a->fixup_list); + + while (p != NULL) { + a->pst = NULL; /* Mark stat cache as out-of-date. */ + if (p->fixup & TODO_TIMES) { + set_times(a, -1, p->mode, p->name, + p->atime, p->atime_nanos, + p->birthtime, p->birthtime_nanos, + p->mtime, p->mtime_nanos, + p->ctime, p->ctime_nanos); + } + if (p->fixup & TODO_MODE_BASE) + chmod(p->name, p->mode); + if (p->fixup & TODO_ACLS) + set_acls(a, -1, p->name, &p->acl); + if (p->fixup & TODO_FFLAGS) + set_fflags_platform(a, -1, p->name, + p->mode, p->fflags_set, 0); + if (p->fixup & TODO_MAC_METADATA) + set_mac_metadata(a, p->name, p->mac_metadata, + p->mac_metadata_size); + next = p->next; + archive_acl_clear(&p->acl); + free(p->mac_metadata); + free(p->name); + free(p); + p = next; + } + a->fixup_list = NULL; + return (ret); +} + +static int +_archive_write_disk_free(struct archive *_a) +{ + struct archive_write_disk *a; + int ret; + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_disk_free"); + a = (struct archive_write_disk *)_a; + ret = _archive_write_disk_close(&a->archive); + archive_write_disk_set_group_lookup(&a->archive, NULL, NULL, NULL); + archive_write_disk_set_user_lookup(&a->archive, NULL, NULL, NULL); + if (a->entry) + archive_entry_free(a->entry); + archive_string_free(&a->_name_data); + archive_string_free(&a->archive.error_string); + archive_string_free(&a->path_safe); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a); + return (ret); +} + +/* + * Simple O(n log n) merge sort to order the fixup list. In + * particular, we want to restore dir timestamps depth-first. + */ +static struct fixup_entry * +sort_dir_list(struct fixup_entry *p) +{ + struct fixup_entry *a, *b, *t; + + if (p == NULL) + return (NULL); + /* A one-item list is already sorted. */ + if (p->next == NULL) + return (p); + + /* Step 1: split the list. */ + t = p; + a = p->next->next; + while (a != NULL) { + /* Step a twice, t once. */ + a = a->next; + if (a != NULL) + a = a->next; + t = t->next; + } + /* Now, t is at the mid-point, so break the list here. */ + b = t->next; + t->next = NULL; + a = p; + + /* Step 2: Recursively sort the two sub-lists. */ + a = sort_dir_list(a); + b = sort_dir_list(b); + + /* Step 3: Merge the returned lists. */ + /* Pick the first element for the merged list. */ + if (strcmp(a->name, b->name) > 0) { + t = p = a; + a = a->next; + } else { + t = p = b; + b = b->next; + } + + /* Always put the later element on the list first. */ + while (a != NULL && b != NULL) { + if (strcmp(a->name, b->name) > 0) { + t->next = a; + a = a->next; + } else { + t->next = b; + b = b->next; + } + t = t->next; + } + + /* Only one list is non-empty, so just splice it on. */ + if (a != NULL) + t->next = a; + if (b != NULL) + t->next = b; + + return (p); +} + +/* + * Returns a new, initialized fixup entry. + * + * TODO: Reduce the memory requirements for this list by using a tree + * structure rather than a simple list of names. + */ +static struct fixup_entry * +new_fixup(struct archive_write_disk *a, const char *pathname) +{ + struct fixup_entry *fe; + + fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry)); + if (fe == NULL) + return (NULL); + fe->next = a->fixup_list; + a->fixup_list = fe; + fe->fixup = 0; + fe->name = strdup(pathname); + return (fe); +} + +/* + * Returns a fixup structure for the current entry. + */ +static struct fixup_entry * +current_fixup(struct archive_write_disk *a, const char *pathname) +{ + if (a->current_fixup == NULL) + a->current_fixup = new_fixup(a, pathname); + return (a->current_fixup); +} + +/* TODO: Make this work. */ +/* + * TODO: The deep-directory support bypasses this; disable deep directory + * support if we're doing symlink checks. + */ +/* + * TODO: Someday, integrate this with the deep dir support; they both + * scan the path and both can be optimized by comparing against other + * recent paths. + */ +/* TODO: Extend this to support symlinks on Windows Vista and later. */ +static int +check_symlinks(struct archive_write_disk *a) +{ +#if !defined(HAVE_LSTAT) + /* Platform doesn't have lstat, so we can't look for symlinks. */ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +#else + char *pn; + char c; + int r; + struct stat st; + + /* + * Guard against symlink tricks. Reject any archive entry whose + * destination would be altered by a symlink. + */ + /* Whatever we checked last time doesn't need to be re-checked. */ + pn = a->name; + if (archive_strlen(&(a->path_safe)) > 0) { + char *p = a->path_safe.s; + while ((*pn != '\0') && (*p == *pn)) + ++p, ++pn; + } + c = pn[0]; + /* Keep going until we've checked the entire name. */ + while (pn[0] != '\0' && (pn[0] != '/' || pn[1] != '\0')) { + /* Skip the next path element. */ + while (*pn != '\0' && *pn != '/') + ++pn; + c = pn[0]; + pn[0] = '\0'; + /* Check that we haven't hit a symlink. */ + r = lstat(a->name, &st); + if (r != 0) { + /* We've hit a dir that doesn't exist; stop now. */ + if (errno == ENOENT) + break; + } else if (S_ISLNK(st.st_mode)) { + if (c == '\0') { + /* + * Last element is symlink; remove it + * so we can overwrite it with the + * item being extracted. + */ + if (unlink(a->name)) { + archive_set_error(&a->archive, errno, + "Could not remove symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* + * Even if we did remove it, a warning + * is in order. The warning is silly, + * though, if we're just replacing one + * symlink with another symlink. + */ + if (!S_ISLNK(a->mode)) { + archive_set_error(&a->archive, 0, + "Removing symlink %s", + a->name); + } + /* Symlink gone. No more problem! */ + pn[0] = c; + return (0); + } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) { + /* User asked us to remove problems. */ + if (unlink(a->name) != 0) { + archive_set_error(&a->archive, 0, + "Cannot remove intervening symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + a->pst = NULL; + } else { + archive_set_error(&a->archive, 0, + "Cannot extract through symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + } + } + pn[0] = c; + /* We've checked and/or cleaned the whole path, so remember it. */ + archive_strcpy(&a->path_safe, a->name); + return (ARCHIVE_OK); +#endif +} + +#if defined(__CYGWIN__) +/* + * 1. Convert a path separator from '\' to '/' . + * We shouldn't check multibyte character directly because some + * character-set have been using the '\' character for a part of + * its multibyte character code. + * 2. Replace unusable characters in Windows with underscore('_'). + * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx + */ +static void +cleanup_pathname_win(struct archive_write_disk *a) +{ + wchar_t wc; + char *p; + size_t alen, l; + int mb, complete, utf8; + + alen = 0; + mb = 0; + complete = 1; + utf8 = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)? 1: 0; + for (p = a->name; *p != '\0'; p++) { + ++alen; + if (*p == '\\') { + /* If previous byte is smaller than 128, + * this is not second byte of multibyte characters, + * so we can replace '\' with '/'. */ + if (utf8 || !mb) + *p = '/'; + else + complete = 0;/* uncompleted. */ + } else if (*(unsigned char *)p > 127) + mb = 1; + else + mb = 0; + /* Rewrite the path name if its next character is unusable. */ + if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || + *p == '<' || *p == '>' || *p == '|') + *p = '_'; + } + if (complete) + return; + + /* + * Convert path separator in wide-character. + */ + p = a->name; + while (*p != '\0' && alen) { + l = mbtowc(&wc, p, alen); + if (l == -1) { + while (*p != '\0') { + if (*p == '\\') + *p = '/'; + ++p; + } + break; + } + if (l == 1 && wc == L'\\') + *p = '/'; + p += l; + alen -= l; + } +} +#endif + +/* + * Canonicalize the pathname. In particular, this strips duplicate + * '/' characters, '.' elements, and trailing '/'. It also raises an + * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is + * set) any '..' in the path. + */ +static int +cleanup_pathname(struct archive_write_disk *a) +{ + char *dest, *src; + char separator = '\0'; + + dest = src = a->name; + if (*src == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid empty pathname"); + return (ARCHIVE_FAILED); + } + +#if defined(__CYGWIN__) + cleanup_pathname_win(a); +#endif + /* Skip leading '/'. */ + if (*src == '/') + separator = *src++; + + /* Scan the pathname one element at a time. */ + for (;;) { + /* src points to first char after '/' */ + if (src[0] == '\0') { + break; + } else if (src[0] == '/') { + /* Found '//', ignore second one. */ + src++; + continue; + } else if (src[0] == '.') { + if (src[1] == '\0') { + /* Ignore trailing '.' */ + break; + } else if (src[1] == '/') { + /* Skip './'. */ + src += 2; + continue; + } else if (src[1] == '.') { + if (src[2] == '/' || src[2] == '\0') { + /* Conditionally warn about '..' */ + if (a->flags & ARCHIVE_EXTRACT_SECURE_NODOTDOT) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Path contains '..'"); + return (ARCHIVE_FAILED); + } + } + /* + * Note: Under no circumstances do we + * remove '..' elements. In + * particular, restoring + * '/foo/../bar/' should create the + * 'foo' dir as a side-effect. + */ + } + } + + /* Copy current element, including leading '/'. */ + if (separator) + *dest++ = '/'; + while (*src != '\0' && *src != '/') { + *dest++ = *src++; + } + + if (*src == '\0') + break; + + /* Skip '/' separator. */ + separator = *src++; + } + /* + * We've just copied zero or more path elements, not including the + * final '/'. + */ + if (dest == a->name) { + /* + * Nothing got copied. The path must have been something + * like '.' or '/' or './' or '/././././/./'. + */ + if (separator) + *dest++ = '/'; + else + *dest++ = '.'; + } + /* Terminate the result. */ + *dest = '\0'; + return (ARCHIVE_OK); +} + +/* + * Create the parent directory of the specified path, assuming path + * is already in mutable storage. + */ +static int +create_parent_dir(struct archive_write_disk *a, char *path) +{ + char *slash; + int r; + + /* Remove tail element to obtain parent name. */ + slash = strrchr(path, '/'); + if (slash == NULL) + return (ARCHIVE_OK); + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + return (r); +} + +/* + * Create the specified dir, recursing to create parents as necessary. + * + * Returns ARCHIVE_OK if the path exists when we're done here. + * Otherwise, returns ARCHIVE_FAILED. + * Assumes path is in mutable storage; path is unchanged on exit. + */ +static int +create_dir(struct archive_write_disk *a, char *path) +{ + struct stat st; + struct fixup_entry *le; + char *slash, *base; + mode_t mode_final, mode; + int r; + + /* Check for special names and just skip them. */ + slash = strrchr(path, '/'); + if (slash == NULL) + base = path; + else + base = slash + 1; + + if (base[0] == '\0' || + (base[0] == '.' && base[1] == '\0') || + (base[0] == '.' && base[1] == '.' && base[2] == '\0')) { + /* Don't bother trying to create null path, '.', or '..'. */ + if (slash != NULL) { + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + return (r); + } + return (ARCHIVE_OK); + } + + /* + * Yes, this should be stat() and not lstat(). Using lstat() + * here loses the ability to extract through symlinks. Also note + * that this should not use the a->st cache. + */ + if (stat(path, &st) == 0) { + if (S_ISDIR(st.st_mode)) + return (ARCHIVE_OK); + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + archive_set_error(&a->archive, EEXIST, + "Can't create directory '%s'", path); + return (ARCHIVE_FAILED); + } + if (unlink(path) != 0) { + archive_set_error(&a->archive, errno, + "Can't create directory '%s': " + "Conflicting file cannot be removed", + path); + return (ARCHIVE_FAILED); + } + } else if (errno != ENOENT && errno != ENOTDIR) { + /* Stat failed? */ + archive_set_error(&a->archive, errno, "Can't test directory '%s'", path); + return (ARCHIVE_FAILED); + } else if (slash != NULL) { + *slash = '\0'; + r = create_dir(a, path); + *slash = '/'; + if (r != ARCHIVE_OK) + return (r); + } + + /* + * Mode we want for the final restored directory. Per POSIX, + * implicitly-created dirs must be created obeying the umask. + * There's no mention whether this is different for privileged + * restores (which the rest of this code handles by pretending + * umask=0). I've chosen here to always obey the user's umask for + * implicit dirs, even if _EXTRACT_PERM was specified. + */ + mode_final = DEFAULT_DIR_MODE & ~a->user_umask; + /* Mode we want on disk during the restore process. */ + mode = mode_final; + mode |= MINIMUM_DIR_MODE; + mode &= MAXIMUM_DIR_MODE; + if (mkdir(path, mode) == 0) { + if (mode != mode_final) { + le = new_fixup(a, path); + le->fixup |=TODO_MODE_BASE; + le->mode = mode_final; + } + return (ARCHIVE_OK); + } + + /* + * Without the following check, a/b/../b/c/d fails at the + * second visit to 'b', so 'd' can't be created. Note that we + * don't add it to the fixup list here, as it's already been + * added. + */ + if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) + return (ARCHIVE_OK); + + archive_set_error(&a->archive, errno, "Failed to create dir '%s'", + path); + return (ARCHIVE_FAILED); +} + +/* + * Note: Although we can skip setting the user id if the desired user + * id matches the current user, we cannot skip setting the group, as + * many systems set the gid based on the containing directory. So + * we have to perform a chown syscall if we want to set the SGID + * bit. (The alternative is to stat() and then possibly chown(); it's + * more efficient to skip the stat() and just always chown().) Note + * that a successful chown() here clears the TODO_SGID_CHECK bit, which + * allows set_mode to skip the stat() check for the GID. + */ +static int +set_ownership(struct archive_write_disk *a) +{ +#ifndef __CYGWIN__ +/* unfortunately, on win32 there is no 'root' user with uid 0, + so we just have to try the chown and see if it works */ + + /* If we know we can't change it, don't bother trying. */ + if (a->user_uid != 0 && a->user_uid != a->uid) { + archive_set_error(&a->archive, errno, + "Can't set UID=%jd", (intmax_t)a->uid); + return (ARCHIVE_WARN); + } +#endif + +#ifdef HAVE_FCHOWN + /* If we have an fd, we can avoid a race. */ + if (a->fd >= 0 && fchown(a->fd, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#endif + + /* We prefer lchown() but will use chown() if that's all we have. */ + /* Of course, if we have neither, this will always fail. */ +#ifdef HAVE_LCHOWN + if (lchown(a->name, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#elif HAVE_CHOWN + if (!S_ISLNK(a->mode) && chown(a->name, a->uid, a->gid) == 0) { + /* We've set owner and know uid/gid are correct. */ + a->todo &= ~(TODO_OWNER | TODO_SGID_CHECK | TODO_SUID_CHECK); + return (ARCHIVE_OK); + } +#endif + + archive_set_error(&a->archive, errno, + "Can't set user=%jd/group=%jd for %s", + (intmax_t)a->uid, (intmax_t)a->gid, a->name); + return (ARCHIVE_WARN); +} + +/* + * Note: Returns 0 on success, non-zero on failure. + */ +static int +set_time(int fd, int mode, const char *name, + time_t atime, long atime_nsec, + time_t mtime, long mtime_nsec) +{ + /* Select the best implementation for this platform. */ +#if defined(HAVE_UTIMENSAT) && defined(HAVE_FUTIMENS) + /* + * utimensat() and futimens() are defined in + * POSIX.1-2008. They support ns resolution and setting times + * on fds and symlinks. + */ + struct timespec ts[2]; + ts[0].tv_sec = atime; + ts[0].tv_nsec = atime_nsec; + ts[1].tv_sec = mtime; + ts[1].tv_nsec = mtime_nsec; + if (fd >= 0) + return futimens(fd, ts); + return utimensat(AT_FDCWD, name, ts, AT_SYMLINK_NOFOLLOW); + +#elif HAVE_UTIMES + /* + * The utimes()-family functions support µs-resolution and + * setting times fds and symlinks. utimes() is documented as + * LEGACY by POSIX, futimes() and lutimes() are not described + * in POSIX. + */ + struct timeval times[2]; + + times[0].tv_sec = atime; + times[0].tv_usec = atime_nsec / 1000; + times[1].tv_sec = mtime; + times[1].tv_usec = mtime_nsec / 1000; + +#ifdef HAVE_FUTIMES + if (fd >= 0) + return (futimes(fd, times)); +#else + (void)fd; /* UNUSED */ +#endif +#ifdef HAVE_LUTIMES + (void)mode; /* UNUSED */ + return (lutimes(name, times)); +#else + if (S_ISLNK(mode)) + return (0); + return (utimes(name, times)); +#endif + +#elif defined(HAVE_UTIME) + /* + * utime() is POSIX-standard but only supports 1s resolution and + * does not support fds or symlinks. + */ + struct utimbuf times; + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)atime_nsec; /* UNUSED */ + (void)mtime_nsec; /* UNUSED */ + times.actime = atime; + times.modtime = mtime; + if (S_ISLNK(mode)) + return (ARCHIVE_OK); + return (utime(name, ×)); + +#else + /* + * We don't know how to set the time on this platform. + */ + return (ARCHIVE_WARN); +#endif +} + +#ifdef F_SETTIMES /* Tru64 */ +static int +set_time_tru64(int fd, int mode, const char *name, + time_t atime, long atime_nsec, + time_t mtime, long mtime_nsec, + time_t ctime, long ctime_nsec) +{ + struct attr_timbuf tstamp; + struct timeval times[3]; + times[0].tv_sec = atime; + times[0].tv_usec = atime_nsec / 1000; + times[1].tv_sec = mtime; + times[1].tv_usec = mtime_nsec / 1000; + times[2].tv_sec = ctime; + times[2].tv_usec = ctime_nsec / 1000; + tstamp.atime = times[0]; + tstamp.mtime = times[1]; + tstamp.ctime = times[2]; + return (fcntl(fd,F_SETTIMES,&tstamp)); +} +#endif /* Tru64 */ + +static int +set_times(struct archive_write_disk *a, + int fd, int mode, const char *name, + time_t atime, long atime_nanos, + time_t birthtime, long birthtime_nanos, + time_t mtime, long mtime_nanos, + time_t ctime, long ctime_nanos) +{ + /* Note: set_time doesn't use libarchive return conventions! + * It uses syscall conventions. So 0 here instead of ARCHIVE_OK. */ + int r1 = 0, r2 = 0; + +#ifdef F_SETTIMES + /* + * on Tru64 try own fcntl first which can restore even the + * ctime, fall back to default code path below if it fails + * or if we are not running as root + */ + if (a->user_uid == 0 && + set_time_tru64(fd, mode, name, + atime, atime_nanos, mtime, + mtime_nanos, ctime, ctime_nanos) == 0) { + return (ARCHIVE_OK); + } +#endif /* Tru64 */ + +#ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME + /* + * If you have struct stat.st_birthtime, we assume BSD + * birthtime semantics, in which {f,l,}utimes() updates + * birthtime to earliest mtime. So we set the time twice, + * first using the birthtime, then using the mtime. If + * birthtime == mtime, this isn't necessary, so we skip it. + * If birthtime > mtime, then this won't work, so we skip it. + */ + if (birthtime < mtime + || (birthtime == mtime && birthtime_nanos < mtime_nanos)) + r1 = set_time(fd, mode, name, + atime, atime_nanos, + birthtime, birthtime_nanos); +#endif + r2 = set_time(fd, mode, name, + atime, atime_nanos, + mtime, mtime_nanos); + if (r1 != 0 || r2 != 0) { + archive_set_error(&a->archive, errno, + "Can't restore time"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +set_times_from_entry(struct archive_write_disk *a) +{ + time_t atime, birthtime, mtime, ctime; + long atime_nsec, birthtime_nsec, mtime_nsec, ctime_nsec; + + /* Suitable defaults. */ + atime = birthtime = mtime = ctime = a->start_time; + atime_nsec = birthtime_nsec = mtime_nsec = ctime_nsec = 0; + + /* If no time was provided, we're done. */ + if (!archive_entry_atime_is_set(a->entry) +#if HAVE_STRUCT_STAT_ST_BIRTHTIME + && !archive_entry_birthtime_is_set(a->entry) +#endif + && !archive_entry_mtime_is_set(a->entry)) + return (ARCHIVE_OK); + + if (archive_entry_atime_is_set(a->entry)) { + atime = archive_entry_atime(a->entry); + atime_nsec = archive_entry_atime_nsec(a->entry); + } + if (archive_entry_birthtime_is_set(a->entry)) { + birthtime = archive_entry_birthtime(a->entry); + birthtime_nsec = archive_entry_birthtime_nsec(a->entry); + } + if (archive_entry_mtime_is_set(a->entry)) { + mtime = archive_entry_mtime(a->entry); + mtime_nsec = archive_entry_mtime_nsec(a->entry); + } + if (archive_entry_ctime_is_set(a->entry)) { + ctime = archive_entry_ctime(a->entry); + ctime_nsec = archive_entry_ctime_nsec(a->entry); + } + + return set_times(a, a->fd, a->mode, a->name, + atime, atime_nsec, + birthtime, birthtime_nsec, + mtime, mtime_nsec, + ctime, ctime_nsec); +} + +static int +set_mode(struct archive_write_disk *a, int mode) +{ + int r = ARCHIVE_OK; + mode &= 07777; /* Strip off file type bits. */ + + if (a->todo & TODO_SGID_CHECK) { + /* + * If we don't know the GID is right, we must stat() + * to verify it. We can't just check the GID of this + * process, since systems sometimes set GID from + * the enclosing dir or based on ACLs. + */ + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + if (a->pst->st_gid != a->gid) { + mode &= ~ S_ISGID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + /* + * This is only an error if you + * requested owner restore. If you + * didn't, we'll try to restore + * sgid/suid, but won't consider it a + * problem if we can't. + */ + archive_set_error(&a->archive, -1, + "Can't restore SGID bit"); + r = ARCHIVE_WARN; + } + } + /* While we're here, double-check the UID. */ + if (a->pst->st_uid != a->uid + && (a->todo & TODO_SUID)) { + mode &= ~ S_ISUID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + archive_set_error(&a->archive, -1, + "Can't restore SUID bit"); + r = ARCHIVE_WARN; + } + } + a->todo &= ~TODO_SGID_CHECK; + a->todo &= ~TODO_SUID_CHECK; + } else if (a->todo & TODO_SUID_CHECK) { + /* + * If we don't know the UID is right, we can just check + * the user, since all systems set the file UID from + * the process UID. + */ + if (a->user_uid != a->uid) { + mode &= ~ S_ISUID; + if (a->flags & ARCHIVE_EXTRACT_OWNER) { + archive_set_error(&a->archive, -1, + "Can't make file SUID"); + r = ARCHIVE_WARN; + } + } + a->todo &= ~TODO_SUID_CHECK; + } + + if (S_ISLNK(a->mode)) { +#ifdef HAVE_LCHMOD + /* + * If this is a symlink, use lchmod(). If the + * platform doesn't support lchmod(), just skip it. A + * platform that doesn't provide a way to set + * permissions on symlinks probably ignores + * permissions on symlinks, so a failure here has no + * impact. + */ + if (lchmod(a->name, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } +#endif + } else if (!S_ISDIR(a->mode)) { + /* + * If it's not a symlink and not a dir, then use + * fchmod() or chmod(), depending on whether we have + * an fd. Dirs get their perms set during the + * post-extract fixup, which is handled elsewhere. + */ +#ifdef HAVE_FCHMOD + if (a->fd >= 0) { + if (fchmod(a->fd, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } else +#endif + /* If this platform lacks fchmod(), then + * we'll just use chmod(). */ + if (chmod(a->name, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } + return (r); +} + +static int +set_fflags(struct archive_write_disk *a) +{ + struct fixup_entry *le; + unsigned long set, clear; + int r; + int critical_flags; + mode_t mode = archive_entry_mode(a->entry); + + /* + * Make 'critical_flags' hold all file flags that can't be + * immediately restored. For example, on BSD systems, + * SF_IMMUTABLE prevents hardlinks from being created, so + * should not be set until after any hardlinks are created. To + * preserve some semblance of portability, this uses #ifdef + * extensively. Ugly, but it works. + * + * Yes, Virginia, this does create a security race. It's mitigated + * somewhat by the practice of creating dirs 0700 until the extract + * is done, but it would be nice if we could do more than that. + * People restoring critical file systems should be wary of + * other programs that might try to muck with files as they're + * being restored. + */ + /* Hopefully, the compiler will optimize this mess into a constant. */ + critical_flags = 0; +#ifdef SF_IMMUTABLE + critical_flags |= SF_IMMUTABLE; +#endif +#ifdef UF_IMMUTABLE + critical_flags |= UF_IMMUTABLE; +#endif +#ifdef SF_APPEND + critical_flags |= SF_APPEND; +#endif +#ifdef UF_APPEND + critical_flags |= UF_APPEND; +#endif +#ifdef EXT2_APPEND_FL + critical_flags |= EXT2_APPEND_FL; +#endif +#ifdef EXT2_IMMUTABLE_FL + critical_flags |= EXT2_IMMUTABLE_FL; +#endif + + if (a->todo & TODO_FFLAGS) { + archive_entry_fflags(a->entry, &set, &clear); + + /* + * The first test encourages the compiler to eliminate + * all of this if it's not necessary. + */ + if ((critical_flags != 0) && (set & critical_flags)) { + le = current_fixup(a, a->name); + le->fixup |= TODO_FFLAGS; + le->fflags_set = set; + /* Store the mode if it's not already there. */ + if ((le->fixup & TODO_MODE) == 0) + le->mode = mode; + } else { + r = set_fflags_platform(a, a->fd, + a->name, mode, set, clear); + if (r != ARCHIVE_OK) + return (r); + } + } + return (ARCHIVE_OK); +} + + +#if ( defined(HAVE_LCHFLAGS) || defined(HAVE_CHFLAGS) || defined(HAVE_FCHFLAGS) ) && defined(HAVE_STRUCT_STAT_ST_FLAGS) +/* + * BSD reads flags using stat() and sets them with one of {f,l,}chflags() + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + int r; + + (void)mode; /* UNUSED */ + if (set == 0 && clear == 0) + return (ARCHIVE_OK); + + /* + * XXX Is the stat here really necessary? Or can I just use + * the 'set' flags directly? In particular, I'm not sure + * about the correct approach if we're overwriting an existing + * file that already has flags on it. XXX + */ + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + + a->st.st_flags &= ~clear; + a->st.st_flags |= set; +#ifdef HAVE_FCHFLAGS + /* If platform has fchflags() and we were given an fd, use it. */ + if (fd >= 0 && fchflags(fd, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#endif + /* + * If we can't use the fd to set the flags, we'll use the + * pathname to set flags. We prefer lchflags() but will use + * chflags() if we must. + */ +#ifdef HAVE_LCHFLAGS + if (lchflags(name, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#elif defined(HAVE_CHFLAGS) + if (S_ISLNK(a->st.st_mode)) { + archive_set_error(&a->archive, errno, + "Can't set file flags on symlink."); + return (ARCHIVE_WARN); + } + if (chflags(name, a->st.st_flags) == 0) + return (ARCHIVE_OK); +#endif + archive_set_error(&a->archive, errno, + "Failed to set file flags"); + return (ARCHIVE_WARN); +} + +#elif defined(EXT2_IOC_GETFLAGS) && defined(EXT2_IOC_SETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS) +/* + * Linux uses ioctl() to read and write file flags. + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + int ret; + int myfd = fd; + unsigned long newflags, oldflags; + unsigned long sf_mask = 0; + + if (set == 0 && clear == 0) + return (ARCHIVE_OK); + /* Only regular files and dirs can have flags. */ + if (!S_ISREG(mode) && !S_ISDIR(mode)) + return (ARCHIVE_OK); + + /* If we weren't given an fd, open it ourselves. */ + if (myfd < 0) + myfd = open(name, O_RDONLY | O_NONBLOCK | O_BINARY); + if (myfd < 0) + return (ARCHIVE_OK); + + /* + * Linux has no define for the flags that are only settable by + * the root user. This code may seem a little complex, but + * there seem to be some Linux systems that lack these + * defines. (?) The code below degrades reasonably gracefully + * if sf_mask is incomplete. + */ +#ifdef EXT2_IMMUTABLE_FL + sf_mask |= EXT2_IMMUTABLE_FL; +#endif +#ifdef EXT2_APPEND_FL + sf_mask |= EXT2_APPEND_FL; +#endif + /* + * XXX As above, this would be way simpler if we didn't have + * to read the current flags from disk. XXX + */ + ret = ARCHIVE_OK; + + /* Read the current file flags. */ + if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) < 0) + goto fail; + + /* Try setting the flags as given. */ + newflags = (oldflags & ~clear) | set; + if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) + goto cleanup; + if (errno != EPERM) + goto fail; + + /* If we couldn't set all the flags, try again with a subset. */ + newflags &= ~sf_mask; + oldflags &= sf_mask; + newflags |= oldflags; + if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0) + goto cleanup; + + /* We couldn't set the flags, so report the failure. */ +fail: + archive_set_error(&a->archive, errno, + "Failed to set file flags"); + ret = ARCHIVE_WARN; +cleanup: + if (fd < 0) + close(myfd); + return (ret); +} + +#else + +/* + * Of course, some systems have neither BSD chflags() nor Linux' flags + * support through ioctl(). + */ +static int +set_fflags_platform(struct archive_write_disk *a, int fd, const char *name, + mode_t mode, unsigned long set, unsigned long clear) +{ + (void)a; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)mode; /* UNUSED */ + (void)set; /* UNUSED */ + (void)clear; /* UNUSED */ + return (ARCHIVE_OK); +} + +#endif /* __linux */ + +#ifndef HAVE_COPYFILE_H +/* Default is to simply drop Mac extended metadata. */ +static int +set_mac_metadata(struct archive_write_disk *a, const char *pathname, + const void *metadata, size_t metadata_size) +{ + (void)a; /* UNUSED */ + (void)pathname; /* UNUSED */ + (void)metadata; /* UNUSED */ + (void)metadata_size; /* UNUSED */ + return (ARCHIVE_OK); +} +#else + +/* + * On Mac OS, we use copyfile() to unpack the metadata and + * apply it to the target file. + */ +static int +set_mac_metadata(struct archive_write_disk *a, const char *pathname, + const void *metadata, size_t metadata_size) +{ + struct archive_string tmp; + ssize_t written; + int fd; + int ret = ARCHIVE_OK; + + /* This would be simpler if copyfile() could just accept the + * metadata as a block of memory; then we could sidestep this + * silly dance of writing the data to disk just so that + * copyfile() can read it back in again. */ + archive_string_init(&tmp); + archive_strcpy(&tmp, pathname); + archive_strcat(&tmp, ".XXXXXX"); + fd = mkstemp(tmp.s); + + if (fd < 0) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + return (ARCHIVE_WARN); + } + written = write(fd, metadata, metadata_size); + close(fd); + if (written != metadata_size + || copyfile(tmp.s, pathname, 0, + COPYFILE_UNPACK | COPYFILE_NOFOLLOW + | COPYFILE_ACL | COPYFILE_XATTR)) { + archive_set_error(&a->archive, errno, + "Failed to restore metadata"); + ret = ARCHIVE_WARN; + } + unlink(tmp.s); + return (ret); +} +#endif + +#ifndef HAVE_POSIX_ACL +/* Default empty function body to satisfy mainline code. */ +static int +set_acls(struct archive_write_disk *a, int fd, const char *name, + struct archive_acl *acl) +{ + (void)a; /* UNUSED */ + (void)fd; /* UNUSED */ + (void)name; /* UNUSED */ + (void)acl; /* UNUSED */ + return (ARCHIVE_OK); +} + +#else + +/* + * XXX TODO: What about ACL types other than ACCESS and DEFAULT? + */ +static int +set_acls(struct archive_write_disk *a, int fd, const char *name, + struct archive_acl *abstract_acl) +{ + int ret; + + ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_ACCESS, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access"); + if (ret != ARCHIVE_OK) + return (ret); + ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_DEFAULT, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default"); + return (ret); +} + + +static int +set_acl(struct archive_write_disk *a, int fd, const char *name, + struct archive_acl *abstract_acl, + acl_type_t acl_type, int ae_requested_type, const char *tname) +{ + acl_t acl; + acl_entry_t acl_entry; + acl_permset_t acl_permset; + int ret; + int ae_type, ae_permset, ae_tag, ae_id; + uid_t ae_uid; + gid_t ae_gid; + const char *ae_name; + int entries; + + ret = ARCHIVE_OK; + entries = archive_acl_reset(abstract_acl, ae_requested_type); + if (entries == 0) + return (ARCHIVE_OK); + acl = acl_init(entries); + while (archive_acl_next(&a->archive, abstract_acl, + ae_requested_type, &ae_type, &ae_permset, &ae_tag, &ae_id, + &ae_name) == ARCHIVE_OK) { + acl_create_entry(&acl, &acl_entry); + + switch (ae_tag) { + case ARCHIVE_ENTRY_ACL_USER: + acl_set_tag_type(acl_entry, ACL_USER); + ae_uid = archive_write_disk_uid(&a->archive, + ae_name, ae_id); + acl_set_qualifier(acl_entry, &ae_uid); + break; + case ARCHIVE_ENTRY_ACL_GROUP: + acl_set_tag_type(acl_entry, ACL_GROUP); + ae_gid = archive_write_disk_gid(&a->archive, + ae_name, ae_id); + acl_set_qualifier(acl_entry, &ae_gid); + break; + case ARCHIVE_ENTRY_ACL_USER_OBJ: + acl_set_tag_type(acl_entry, ACL_USER_OBJ); + break; + case ARCHIVE_ENTRY_ACL_GROUP_OBJ: + acl_set_tag_type(acl_entry, ACL_GROUP_OBJ); + break; + case ARCHIVE_ENTRY_ACL_MASK: + acl_set_tag_type(acl_entry, ACL_MASK); + break; + case ARCHIVE_ENTRY_ACL_OTHER: + acl_set_tag_type(acl_entry, ACL_OTHER); + break; + default: + /* XXX */ + break; + } + + acl_get_permset(acl_entry, &acl_permset); + acl_clear_perms(acl_permset); + if (ae_permset & ARCHIVE_ENTRY_ACL_EXECUTE) + acl_add_perm(acl_permset, ACL_EXECUTE); + if (ae_permset & ARCHIVE_ENTRY_ACL_WRITE) + acl_add_perm(acl_permset, ACL_WRITE); + if (ae_permset & ARCHIVE_ENTRY_ACL_READ) + acl_add_perm(acl_permset, ACL_READ); + } + + /* Try restoring the ACL through 'fd' if we can. */ +#if HAVE_ACL_SET_FD + if (fd >= 0 && acl_type == ACL_TYPE_ACCESS && acl_set_fd(fd, acl) == 0) + ret = ARCHIVE_OK; + else +#else +#if HAVE_ACL_SET_FD_NP + if (fd >= 0 && acl_set_fd_np(fd, acl, acl_type) == 0) + ret = ARCHIVE_OK; + else +#endif +#endif + if (acl_set_file(name, acl_type, acl) != 0) { + archive_set_error(&a->archive, errno, "Failed to set %s acl", tname); + ret = ARCHIVE_WARN; + } + acl_free(acl); + return (ret); +} +#endif + +#if HAVE_LSETXATTR || HAVE_LSETEA +/* + * Restore extended attributes - Linux and AIX implementations: + * AIX' ea interface is syntaxwise identical to the Linux xattr interface. + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + struct archive_entry *entry = a->entry; + static int warning_done = 0; + int ret = ARCHIVE_OK; + int i = archive_entry_xattr_reset(entry); + + while (i--) { + const char *name; + const void *value; + size_t size; + archive_entry_xattr_next(entry, &name, &value, &size); + if (name != NULL && + strncmp(name, "xfsroot.", 8) != 0 && + strncmp(name, "system.", 7) != 0) { + int e; +#if HAVE_FSETXATTR + if (a->fd >= 0) + e = fsetxattr(a->fd, name, value, size, 0); + else +#elif HAVE_FSETEA + if (a->fd >= 0) + e = fsetea(a->fd, name, value, size, 0); + else +#endif + { +#if HAVE_LSETXATTR + e = lsetxattr(archive_entry_pathname(entry), + name, value, size, 0); +#elif HAVE_LSETEA + e = lsetea(archive_entry_pathname(entry), + name, value, size, 0); +#endif + } + if (e == -1) { + if (errno == ENOTSUP || errno == ENOSYS) { + if (!warning_done) { + warning_done = 1; + archive_set_error(&a->archive, errno, + "Cannot restore extended " + "attributes on this file " + "system"); + } + } else + archive_set_error(&a->archive, errno, + "Failed to set extended attribute"); + ret = ARCHIVE_WARN; + } + } else { + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Invalid extended attribute encountered"); + ret = ARCHIVE_WARN; + } + } + return (ret); +} +#elif HAVE_EXTATTR_SET_FILE && HAVE_DECL_EXTATTR_NAMESPACE_USER +/* + * Restore extended attributes - FreeBSD implementation + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + struct archive_entry *entry = a->entry; + static int warning_done = 0; + int ret = ARCHIVE_OK; + int i = archive_entry_xattr_reset(entry); + + while (i--) { + const char *name; + const void *value; + size_t size; + archive_entry_xattr_next(entry, &name, &value, &size); + if (name != NULL) { + int e; + int namespace; + + if (strncmp(name, "user.", 5) == 0) { + /* "user." attributes go to user namespace */ + name += 5; + namespace = EXTATTR_NAMESPACE_USER; + } else { + /* Warn about other extended attributes. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't restore extended attribute ``%s''", + name); + ret = ARCHIVE_WARN; + continue; + } + errno = 0; +#if HAVE_EXTATTR_SET_FD + if (a->fd >= 0) + e = extattr_set_fd(a->fd, namespace, name, value, size); + else +#endif + /* TODO: should we use extattr_set_link() instead? */ + { + e = extattr_set_file(archive_entry_pathname(entry), + namespace, name, value, size); + } + if (e != (int)size) { + if (errno == ENOTSUP || errno == ENOSYS) { + if (!warning_done) { + warning_done = 1; + archive_set_error(&a->archive, errno, + "Cannot restore extended " + "attributes on this file " + "system"); + } + } else { + archive_set_error(&a->archive, errno, + "Failed to set extended attribute"); + } + + ret = ARCHIVE_WARN; + } + } + } + return (ret); +} +#else +/* + * Restore extended attributes - stub implementation for unsupported systems + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + static int warning_done = 0; + + /* If there aren't any extended attributes, then it's okay not + * to extract them, otherwise, issue a single warning. */ + if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) { + warning_done = 1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Cannot restore extended attributes on this system"); + return (ARCHIVE_WARN); + } + /* Warning was already emitted; suppress further warnings. */ + return (ARCHIVE_OK); +} +#endif + +/* + * Test if file on disk is older than entry. + */ +static int +older(struct stat *st, struct archive_entry *entry) +{ + /* First, test the seconds and return if we have a definite answer. */ + /* Definitely older. */ + if (st->st_mtime < archive_entry_mtime(entry)) + return (1); + /* Definitely younger. */ + if (st->st_mtime > archive_entry_mtime(entry)) + return (0); + /* If this platform supports fractional seconds, try those. */ +#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC + /* Definitely older. */ + if (st->st_mtimespec.tv_nsec < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC + /* Definitely older. */ + if (st->st_mtim.tv_nsec < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIME_N + /* older. */ + if (st->st_mtime_n < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_UMTIME + /* older. */ + if (st->st_umtime * 1000 < archive_entry_mtime_nsec(entry)) + return (1); +#elif HAVE_STRUCT_STAT_ST_MTIME_USEC + /* older. */ + if (st->st_mtime_usec * 1000 < archive_entry_mtime_nsec(entry)) + return (1); +#else + /* This system doesn't have high-res timestamps. */ +#endif + /* Same age or newer, so not older. */ + return (0); +} + +#endif /* !_WIN32 || __CYGWIN__ */ + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h index 3722c19b4..707c0cf03 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_private.h @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_write_disk_private.h,v 1.1 2007/03/03 07:37:36 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_write_disk_private.h 201086 2009-12-28 02:17:53Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c index 2849b9f57..5ee89a79a 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_set_standard_lookup.c @@ -23,12 +23,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 /* getpwnam_r and getgrnam_r signatures */ -#endif - #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_disk_set_standard_lookup.c,v 1.4 2007/05/29 01:00:19 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_disk_set_standard_lookup.c 201083 2009-12-28 02:09:57Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -55,16 +51,16 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_disk_set_standard_lookup.c, #include "archive_write_disk_private.h" struct bucket { - char *name; - int hash; - id_t id; + char *name; + int hash; + id_t id; }; static const size_t cache_size = 127; -static unsigned int hash(const char *); -static gid_t lookup_gid(void *, const char *uname, gid_t); -static uid_t lookup_uid(void *, const char *uname, uid_t); -static void cleanup(void *); +static unsigned int hash(const char *); +static int64_t lookup_gid(void *, const char *uname, int64_t); +static int64_t lookup_uid(void *, const char *uname, int64_t); +static void cleanup(void *); /* * Installs functions that use getpwnam()/getgrnam()---along with @@ -88,160 +84,179 @@ static void cleanup(void *); int archive_write_disk_set_standard_lookup(struct archive *a) { - struct bucket *ucache = malloc(cache_size * sizeof(struct bucket)); - struct bucket *gcache = malloc(cache_size * sizeof(struct bucket)); - memset(ucache, 0, cache_size * sizeof(struct bucket)); - memset(gcache, 0, cache_size * sizeof(struct bucket)); - archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup); - archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup); - return (ARCHIVE_OK); + struct bucket *ucache = malloc(cache_size * sizeof(struct bucket)); + struct bucket *gcache = malloc(cache_size * sizeof(struct bucket)); + memset(ucache, 0, cache_size * sizeof(struct bucket)); + memset(gcache, 0, cache_size * sizeof(struct bucket)); + archive_write_disk_set_group_lookup(a, gcache, lookup_gid, cleanup); + archive_write_disk_set_user_lookup(a, ucache, lookup_uid, cleanup); + return (ARCHIVE_OK); } -static gid_t -lookup_gid(void *private_data, const char *gname, gid_t gid) +static int64_t +lookup_gid(void *private_data, const char *gname, int64_t gid) { - int h; - struct bucket *b; - struct bucket *gcache = (struct bucket *)private_data; - - /* If no gname, just use the gid provided. */ - if (gname == NULL || *gname == '\0') - return (gid); - - /* Try to find gname in the cache. */ - h = hash(gname); - b = &gcache[h % cache_size ]; - if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0) - return ((gid_t)b->id); - - /* Free the cache slot for a new entry. */ - if (b->name != NULL) - free(b->name); - b->name = strdup(gname); - /* Note: If strdup fails, that's okay; we just won't cache. */ - b->hash = h; + int h; + struct bucket *b; + struct bucket *gcache = (struct bucket *)private_data; + + /* If no gname, just use the gid provided. */ + if (gname == NULL || *gname == '\0') + return (gid); + + /* Try to find gname in the cache. */ + h = hash(gname); + b = &gcache[h % cache_size ]; + if (b->name != NULL && b->hash == h && strcmp(gname, b->name) == 0) + return ((gid_t)b->id); + + /* Free the cache slot for a new entry. */ + if (b->name != NULL) + free(b->name); + b->name = strdup(gname); + /* Note: If strdup fails, that's okay; we just won't cache. */ + b->hash = h; #if HAVE_GRP_H - { - char _buffer[128]; - size_t bufsize = 128; - char *buffer = _buffer; - struct group grent, *result; - int r; - - for (;;) { - result = &grent; /* Old getgrnam_r ignores last argument. */ - r = getgrnam_r(gname, &grent, buffer, bufsize, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - bufsize *= 2; - if (buffer != _buffer) - free(buffer); - buffer = malloc(bufsize); - if (buffer == NULL) - break; - } - if (result != NULL) - gid = result->gr_gid; - if (buffer != _buffer) - free(buffer); - } +# if HAVE_GETGRNAM_R + { + char _buffer[128]; + size_t bufsize = 128; + char *buffer = _buffer; + struct group grent, *result; + int r; + + for (;;) { + result = &grent; /* Old getgrnam_r ignores last arg. */ + r = getgrnam_r(gname, &grent, buffer, bufsize, &result); + if (r == 0) + break; + if (r != ERANGE) + break; + bufsize *= 2; + if (buffer != _buffer) + free(buffer); + buffer = malloc(bufsize); + if (buffer == NULL) + break; + } + if (result != NULL) + gid = result->gr_gid; + if (buffer != _buffer) + free(buffer); + } +# else /* HAVE_GETGRNAM_R */ + { + struct group *result; + + result = getgrnam(gname); + if (result != NULL) + gid = result->gr_gid; + } +# endif /* HAVE_GETGRNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: do a gname->gid lookup for Windows. */ + /* TODO: do a gname->gid lookup for Windows. */ #else - #error No way to perform gid lookups on this platform + #error No way to perform gid lookups on this platform #endif - b->id = gid; + b->id = gid; - return (gid); + return (gid); } -static uid_t -lookup_uid(void *private_data, const char *uname, uid_t uid) +static int64_t +lookup_uid(void *private_data, const char *uname, int64_t uid) { - int h; - struct bucket *b; - struct bucket *ucache = (struct bucket *)private_data; - - /* If no uname, just use the uid provided. */ - if (uname == NULL || *uname == '\0') - return (uid); - - /* Try to find uname in the cache. */ - h = hash(uname); - b = &ucache[h % cache_size ]; - if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0) - return ((uid_t)b->id); - - /* Free the cache slot for a new entry. */ - if (b->name != NULL) - free(b->name); - b->name = strdup(uname); - /* Note: If strdup fails, that's okay; we just won't cache. */ - b->hash = h; + int h; + struct bucket *b; + struct bucket *ucache = (struct bucket *)private_data; + + /* If no uname, just use the uid provided. */ + if (uname == NULL || *uname == '\0') + return (uid); + + /* Try to find uname in the cache. */ + h = hash(uname); + b = &ucache[h % cache_size ]; + if (b->name != NULL && b->hash == h && strcmp(uname, b->name) == 0) + return ((uid_t)b->id); + + /* Free the cache slot for a new entry. */ + if (b->name != NULL) + free(b->name); + b->name = strdup(uname); + /* Note: If strdup fails, that's okay; we just won't cache. */ + b->hash = h; #if HAVE_PWD_H - { - char _buffer[128]; - size_t bufsize = 128; - char *buffer = _buffer; - struct passwd pwent, *result; - int r; - - for (;;) { - result = &pwent; /* Old getpwnam_r ignores last argument. */ - r = getpwnam_r(uname, &pwent, buffer, bufsize, &result); - if (r == 0) - break; - if (r != ERANGE) - break; - bufsize *= 2; - if (buffer != _buffer) - free(buffer); - buffer = malloc(bufsize); - if (buffer == NULL) - break; - } - if (result != NULL) - uid = result->pw_uid; - if (buffer != _buffer) - free(buffer); - } +# if HAVE_GETPWNAM_R + { + char _buffer[128]; + size_t bufsize = 128; + char *buffer = _buffer; + struct passwd pwent, *result; + int r; + + for (;;) { + result = &pwent; /* Old getpwnam_r ignores last arg. */ + r = getpwnam_r(uname, &pwent, buffer, bufsize, &result); + if (r == 0) + break; + if (r != ERANGE) + break; + bufsize *= 2; + if (buffer != _buffer) + free(buffer); + buffer = malloc(bufsize); + if (buffer == NULL) + break; + } + if (result != NULL) + uid = result->pw_uid; + if (buffer != _buffer) + free(buffer); + } +# else /* HAVE_GETPWNAM_R */ + { + struct passwd *result; + + result = getpwnam(uname); + if (result != NULL) + uid = result->pw_uid; + } +#endif /* HAVE_GETPWNAM_R */ #elif defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: do a uname->uid lookup for Windows. */ + /* TODO: do a uname->uid lookup for Windows. */ #else - #error No way to look up uids on this platform + #error No way to look up uids on this platform #endif - b->id = uid; + b->id = uid; - return (uid); + return (uid); } static void cleanup(void *private) { - size_t i; - struct bucket *cache = (struct bucket *)private; + size_t i; + struct bucket *cache = (struct bucket *)private; - for (i = 0; i < cache_size; i++) - free(cache[i].name); - free(cache); + for (i = 0; i < cache_size; i++) + free(cache[i].name); + free(cache); } static unsigned int hash(const char *p) { - /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm, - as used by ELF for hashing function names. */ - unsigned g, h = 0; - while (*p != '\0') { - h = ( h << 4 ) + *p++; - g = h & 0xF0000000; - if (g) { - h ^= g >> 24; - h &= 0x0FFFFFFF; - } - } - return h; + /* A 32-bit version of Peter Weinberger's (PJW) hash algorithm, + as used by ELF for hashing function names. */ + unsigned g, h = 0; + while (*p != '\0') { + h = (h << 4) + *p++; + if ((g = h & 0xF0000000) != 0) { + h ^= g >> 24; + h &= 0x0FFFFFFF; + } + } + return h; } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c new file mode 100644 index 000000000..2dc2d92e8 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_disk_windows.c @@ -0,0 +1,2551 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * Copyright (c) 2011 Michihiro NAKAJIMA + * 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 + * in this position and unchanged. + * 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$"); + +#if defined(_WIN32) && !defined(__CYGWIN__) + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_SYS_UTIME_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#include + +/* TODO: Support Mac OS 'quarantine' feature. This is really just a + * standard tag to mark files that have been downloaded as "tainted". + * On Mac OS, we should mark the extracted files as tainted if the + * archive being read was tainted. Windows has a similar feature; we + * should investigate ways to support this generically. */ + +#include "archive.h" +#include "archive_acl_private.h" +#include "archive_string.h" +#include "archive_entry.h" +#include "archive_private.h" + +#ifndef O_BINARY +#define O_BINARY 0 +#endif +#ifndef IO_REPARSE_TAG_SYMLINK +/* Old SDKs do not provide IO_REPARSE_TAG_SYMLINK */ +#define IO_REPARSE_TAG_SYMLINK 0xA000000CL +#endif + +static BOOL SetFilePointerEx_perso(HANDLE hFile, + LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, + DWORD dwMoveMethod) +{ + LARGE_INTEGER li; + li.QuadPart = liDistanceToMove.QuadPart; + li.LowPart = SetFilePointer( + hFile, li.LowPart, &li.HighPart, dwMoveMethod); + if(lpNewFilePointer) { + lpNewFilePointer->QuadPart = li.QuadPart; + } + return li.LowPart != -1 || GetLastError() == NO_ERROR; +} + +struct fixup_entry { + struct fixup_entry *next; + struct archive_acl acl; + mode_t mode; + int64_t atime; + int64_t birthtime; + int64_t mtime; + int64_t ctime; + unsigned long atime_nanos; + unsigned long birthtime_nanos; + unsigned long mtime_nanos; + unsigned long ctime_nanos; + unsigned long fflags_set; + int fixup; /* bitmask of what needs fixing */ + wchar_t *name; +}; + +/* + * We use a bitmask to track which operations remain to be done for + * this file. In particular, this helps us avoid unnecessary + * operations when it's possible to take care of one step as a + * side-effect of another. For example, mkdir() can specify the mode + * for the newly-created object but symlink() cannot. This means we + * can skip chmod() if mkdir() succeeded, but we must explicitly + * chmod() if we're trying to create a directory that already exists + * (mkdir() failed) or if we're restoring a symlink. Similarly, we + * need to verify UID/GID before trying to restore SUID/SGID bits; + * that verification can occur explicitly through a stat() call or + * implicitly because of a successful chown() call. + */ +#define TODO_MODE_FORCE 0x40000000 +#define TODO_MODE_BASE 0x20000000 +#define TODO_SUID 0x10000000 +#define TODO_SUID_CHECK 0x08000000 +#define TODO_SGID 0x04000000 +#define TODO_SGID_CHECK 0x02000000 +#define TODO_MODE (TODO_MODE_BASE|TODO_SUID|TODO_SGID) +#define TODO_TIMES ARCHIVE_EXTRACT_TIME +#define TODO_OWNER ARCHIVE_EXTRACT_OWNER +#define TODO_FFLAGS ARCHIVE_EXTRACT_FFLAGS +#define TODO_ACLS ARCHIVE_EXTRACT_ACL +#define TODO_XATTR ARCHIVE_EXTRACT_XATTR +#define TODO_MAC_METADATA ARCHIVE_EXTRACT_MAC_METADATA + +struct archive_write_disk { + struct archive archive; + + mode_t user_umask; + struct fixup_entry *fixup_list; + struct fixup_entry *current_fixup; + int64_t user_uid; + int skip_file_set; + dev_t skip_file_dev; + ino_t skip_file_ino; + time_t start_time; + + int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid); + void (*cleanup_gid)(void *private); + void *lookup_gid_data; + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid); + void (*cleanup_uid)(void *private); + void *lookup_uid_data; + + /* + * Full path of last file to satisfy symlink checks. + */ + struct archive_wstring path_safe; + + /* + * Cached stat data from disk for the current entry. + * If this is valid, pst points to st. Otherwise, + * pst is null. + */ + BY_HANDLE_FILE_INFORMATION st; + BY_HANDLE_FILE_INFORMATION *pst; + + /* Information about the object being restored right now. */ + struct archive_entry *entry; /* Entry being extracted. */ + wchar_t *name; /* Name of entry, possibly edited. */ + struct archive_wstring _name_data; /* backing store for 'name' */ + /* Tasks remaining for this object. */ + int todo; + /* Tasks deferred until end-of-archive. */ + int deferred; + /* Options requested by the client. */ + int flags; + /* Handle for the file we're restoring. */ + HANDLE fh; + /* Current offset for writing data to the file. */ + int64_t offset; + /* Last offset actually written to disk. */ + int64_t fd_offset; + /* Total bytes actually written to files. */ + int64_t total_bytes_written; + /* Maximum size of file, -1 if unknown. */ + int64_t filesize; + /* Dir we were in before this restore; only for deep paths. */ + int restore_pwd; + /* Mode we should use for this entry; affected by _PERM and umask. */ + mode_t mode; + /* UID/GID to use in restoring this entry. */ + int64_t uid; + int64_t gid; +}; + +/* + * Default mode for dirs created automatically (will be modified by umask). + * Note that POSIX specifies 0777 for implicity-created dirs, "modified + * by the process' file creation mask." + */ +#define DEFAULT_DIR_MODE 0777 +/* + * Dir modes are restored in two steps: During the extraction, the permissions + * in the archive are modified to match the following limits. During + * the post-extract fixup pass, the permissions from the archive are + * applied. + */ +#define MINIMUM_DIR_MODE 0700 +#define MAXIMUM_DIR_MODE 0775 + +static int check_symlinks(struct archive_write_disk *); +static int create_filesystem_object(struct archive_write_disk *); +static struct fixup_entry *current_fixup(struct archive_write_disk *, const wchar_t *pathname); +#if defined(HAVE_FCHDIR) && defined(PATH_MAX) +static void edit_deep_directories(struct archive_write_disk *ad); +#endif +static int cleanup_pathname(struct archive_write_disk *); +static int create_dir(struct archive_write_disk *, wchar_t *); +static int create_parent_dir(struct archive_write_disk *, wchar_t *); +static int older(BY_HANDLE_FILE_INFORMATION *, struct archive_entry *); +static int restore_entry(struct archive_write_disk *); +#ifdef HAVE_POSIX_ACL +static int set_acl(struct archive_write_disk *, int fd, const char *, struct archive_acl *, + acl_type_t, int archive_entry_acl_type, const char *tn); +#endif +static int set_acls(struct archive_write_disk *, HANDLE h, const wchar_t *, struct archive_acl *); +static int set_xattrs(struct archive_write_disk *); +static int set_fflags(struct archive_write_disk *); +static int set_ownership(struct archive_write_disk *); +static int set_mode(struct archive_write_disk *, int mode); +static int set_times(struct archive_write_disk *, HANDLE, int, const wchar_t *, + time_t, long, time_t, long, time_t, long, time_t, long); +static int set_times_from_entry(struct archive_write_disk *); +static struct fixup_entry *sort_dir_list(struct fixup_entry *p); +static ssize_t write_data_block(struct archive_write_disk *, + const char *, size_t); + +static struct archive_vtable *archive_write_disk_vtable(void); + +static int _archive_write_disk_close(struct archive *); +static int _archive_write_disk_free(struct archive *); +static int _archive_write_disk_header(struct archive *, struct archive_entry *); +static int64_t _archive_write_disk_filter_bytes(struct archive *, int); +static int _archive_write_disk_finish_entry(struct archive *); +static ssize_t _archive_write_disk_data(struct archive *, const void *, size_t); +static ssize_t _archive_write_disk_data_block(struct archive *, const void *, size_t, int64_t); + +#define bhfi_dev(bhfi) ((bhfi)->dwVolumeSerialNumber) +/* Treat FileIndex as i-node. We should remove a sequence number + * which is high-16-bits of nFileIndexHigh. */ +#define bhfi_ino(bhfi) \ + ((((int64_t)((bhfi)->nFileIndexHigh & 0x0000FFFFUL)) << 32) \ + + (bhfi)->nFileIndexLow) +#define bhfi_size(bhfi) \ + ((((int64_t)(bhfi)->nFileSizeHigh) << 32) + (bhfi)->nFileSizeLow) + +static int +file_information(struct archive_write_disk *a, wchar_t *path, + BY_HANDLE_FILE_INFORMATION *st, mode_t *mode, int sim_lstat) +{ + HANDLE h; + int r; + DWORD flag = FILE_FLAG_BACKUP_SEMANTICS; + WIN32_FIND_DATAW findData; + + if (sim_lstat || mode != NULL) { + h = FindFirstFileW(path, &findData); + if (h == INVALID_HANDLE_VALUE && + GetLastError() == ERROR_INVALID_NAME) { + wchar_t *full; + full = __la_win_permissive_name_w(path); + h = FindFirstFileW(full, &findData); + free(full); + } + if (h == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + FindClose(h); + } + + /* Is symlink file ? */ + if (sim_lstat && + ((findData.dwFileAttributes + & FILE_ATTRIBUTE_REPARSE_POINT) && + (findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK))) + flag |= FILE_FLAG_OPEN_REPARSE_POINT; + + h = CreateFileW(a->name, 0, 0, NULL, + OPEN_EXISTING, flag, NULL); + if (h == INVALID_HANDLE_VALUE && + GetLastError() == ERROR_INVALID_NAME) { + wchar_t *full; + full = __la_win_permissive_name_w(path); + h = CreateFileW(full, 0, 0, NULL, + OPEN_EXISTING, flag, NULL); + free(full); + } + if (h == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + return (-1); + } + r = GetFileInformationByHandle(h, st); + CloseHandle(h); + if (r == 0) { + la_dosmaperr(GetLastError()); + return (-1); + } + + if (mode == NULL) + return (0); + + *mode = S_IRUSR | S_IRGRP | S_IROTH; + if ((st->dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0) + *mode |= S_IWUSR | S_IWGRP | S_IWOTH; + if ((st->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) && + findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) + *mode |= S_IFLNK; + else if (st->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + *mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + else { + const wchar_t *p; + + *mode |= S_IFREG; + p = wcsrchr(path, L'.'); + if (p != NULL && wcslen(p) == 4) { + switch (p[1]) { + case L'B': case L'b': + if ((p[2] == L'A' || p[2] == L'a' ) && + (p[3] == L'T' || p[3] == L't' )) + *mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + case L'C': case L'c': + if (((p[2] == L'M' || p[2] == L'm' ) && + (p[3] == L'D' || p[3] == L'd' )) || + ((p[2] == L'M' || p[2] == L'm' ) && + (p[3] == L'D' || p[3] == L'd' ))) + *mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + case L'E': case L'e': + if ((p[2] == L'X' || p[2] == L'x' ) && + (p[3] == L'E' || p[3] == L'e' )) + *mode |= S_IXUSR | S_IXGRP | S_IXOTH; + break; + default: + break; + } + } + } + return (0); +} + +/* + * Note: The path, for example, "aa/a/../b../c" will be converted to "aa/c" + * by GetFullPathNameW() W32 API, which __la_win_permissive_name_w uses. + * It means we cannot handle multiple dirs in one archive_entry. + * So we have to make the full-pathname in another way, which does not + * break "../" path string. + */ +int +permissive_name_w(struct archive_write_disk *a) +{ + wchar_t *wn, *wnp; + wchar_t *ws, *wsp; + DWORD l; + + wnp = a->name; + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'?' && wnp[3] == L'\\') + /* We have already a permissive name. */ + return (0); + + if (wnp[0] == L'\\' && wnp[1] == L'\\' && + wnp[2] == L'.' && wnp[3] == L'\\') { + /* This is a device name */ + if (((wnp[4] >= L'a' && wnp[4] <= L'z') || + (wnp[4] >= L'A' && wnp[4] <= L'Z')) && + wnp[5] == L':' && wnp[6] == L'\\') { + wnp[2] = L'?';/* Not device name. */ + return (0); + } + } + + /* + * A full-pathname starting with a drive name like "C:\abc". + */ + if (((wnp[0] >= L'a' && wnp[0] <= L'z') || + (wnp[0] >= L'A' && wnp[0] <= L'Z')) && + wnp[1] == L':' && wnp[2] == L'\\') { + wn = _wcsdup(wnp); + if (wn == NULL) + return (-1); + archive_wstring_ensure(&(a->_name_data), 4 + wcslen(wn) + 1); + a->name = a->_name_data.s; + /* Prepend "\\?\" */ + archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4); + archive_wstrcat(&(a->_name_data), wn); + free(wn); + return (0); + } + + /* + * A full-pathname pointig a network drive + * like "\\\\file". + */ + if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { + const wchar_t *p = &wnp[2]; + + /* Skip server-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\') { + const wchar_t *rp = ++p; + /* Skip share-name letters. */ + while (*p != L'\\' && *p != L'\0') + ++p; + if (*p == L'\\' && p != rp) { + /* Now, match patterns such as + * "\\server-name\share-name\" */ + wn = _wcsdup(wnp); + if (wn == NULL) + return (-1); + archive_wstring_ensure(&(a->_name_data), 8 + wcslen(wn) + 1); + a->name = a->_name_data.s; + /* Prepend "\\?\UNC\" */ + archive_wstrncpy(&(a->_name_data), L"\\\\?\\UNC\\", 8); + archive_wstrcat(&(a->_name_data), wn+2); + free(wn); + return (0); + } + } + return (0); + } + + /* + * Get current working directory. + */ + l = GetCurrentDirectoryW(0, NULL); + if (l == 0) + return (-1); + ws = malloc(l * sizeof(wchar_t)); + l = GetCurrentDirectoryW(l, ws); + if (l == 0) { + free(ws); + return (-1); + } + wsp = ws; + + /* + * A full-pathname starting without a drive name like "\abc". + */ + if (wnp[0] == L'\\') { + wn = _wcsdup(wnp); + if (wn == NULL) + return (-1); + archive_wstring_ensure(&(a->_name_data), 4 + 2 + wcslen(wn) + 1); + a->name = a->_name_data.s; + /* Prepend "\\?\" and drive name. */ + archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4); + archive_wstrncat(&(a->_name_data), wsp, 2); + archive_wstrcat(&(a->_name_data), wn); + free(wsp); + free(wn); + return (0); + } + + wn = _wcsdup(wnp); + if (wn == NULL) + return (-1); + archive_wstring_ensure(&(a->_name_data), 4 + l + 1 + wcslen(wn) + 1); + a->name = a->_name_data.s; + /* Prepend "\\?\" and drive name. */ + archive_wstrncpy(&(a->_name_data), L"\\\\?\\", 4); + archive_wstrncat(&(a->_name_data), wsp, l); + archive_wstrncat(&(a->_name_data), L"\\", 1); + archive_wstrcat(&(a->_name_data), wn); + a->name = a->_name_data.s; + free(wsp); + free(wn); + return (0); +} + +int +la_chmod(const wchar_t *path, mode_t mode) +{ + DWORD attr; + BOOL r; + wchar_t *fullname; + int ret = 0; + + fullname = NULL; + attr = GetFileAttributesW(path); + if (attr == (DWORD)-1 && + GetLastError() == ERROR_INVALID_NAME) { + fullname = __la_win_permissive_name_w(path); + attr = GetFileAttributesW(fullname); + } + if (attr == (DWORD)-1) { + la_dosmaperr(GetLastError()); + ret = -1; + goto exit_chmode; + } + if (mode & _S_IWRITE) + attr &= ~FILE_ATTRIBUTE_READONLY; + else + attr |= FILE_ATTRIBUTE_READONLY; + if (fullname != NULL) + r = SetFileAttributesW(fullname, attr); + else + r = SetFileAttributesW(path, attr); + if (r == 0) { + la_dosmaperr(GetLastError()); + ret = -1; + } +exit_chmode: + free(fullname); + return (ret); +} + +static void * +la_GetFunctionKernel32(const char *name) +{ + static HINSTANCE lib; + static int set; + if (!set) { + set = 1; + lib = LoadLibrary("kernel32.dll"); + } + if (lib == NULL) { + fprintf(stderr, "Can't load kernel32.dll?!\n"); + exit(1); + } + return (void *)GetProcAddress(lib, name); +} + +static int +la_CreateHardLinkW(wchar_t *linkname, wchar_t *target) +{ + static BOOLEAN (WINAPI *f)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); + static int set; + BOOL ret; + + if (!set) { + set = 1; + f = la_GetFunctionKernel32("CreateHardLinkW"); + } + if (!f) + return (0); + ret = (*f)(linkname, target, NULL); + if (!ret) { + /* Under windows 2000, it is necessary to remove + * the "\\?\" prefix. */ +#define IS_UNC(name) ((name[0] == L'U' || name[0] == L'u') && \ + (name[1] == L'N' || name[1] == L'n') && \ + (name[2] == L'C' || name[2] == L'c') && \ + name[3] == L'\\') + if (!wcsncmp(linkname,L"\\\\?\\", 4)) { + linkname += 4; + if (IS_UNC(linkname)) + linkname += 4; + } + if (!wcsncmp(target,L"\\\\?\\", 4)) { + target += 4; + if (IS_UNC(target)) + target += 4; + } +#undef IS_UNC + ret = (*f)(linkname, target, NULL); + } + return (ret); +} + +static int +la_ftruncate(HANDLE handle, int64_t length) +{ + LARGE_INTEGER distance; + + if (GetFileType(handle) != FILE_TYPE_DISK) { + errno = EBADF; + return (-1); + } + distance.QuadPart = length; + if (!SetFilePointerEx_perso(handle, distance, NULL, FILE_BEGIN)) { + la_dosmaperr(GetLastError()); + return (-1); + } + if (!SetEndOfFile(handle)) { + la_dosmaperr(GetLastError()); + return (-1); + } + return (0); +} + +static int +lazy_stat(struct archive_write_disk *a) +{ + if (a->pst != NULL) { + /* Already have stat() data available. */ + return (ARCHIVE_OK); + } + if (a->fh != INVALID_HANDLE_VALUE && + GetFileInformationByHandle(a->fh, &a->st) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } + + /* + * XXX At this point, symlinks should not be hit, otherwise + * XXX a race occured. Do we want to check explicitly for that? + */ + if (file_information(a, a->name, &a->st, NULL, 1) == 0) { + a->pst = &a->st; + return (ARCHIVE_OK); + } + archive_set_error(&a->archive, errno, "Couldn't stat file"); + return (ARCHIVE_WARN); +} + +static struct archive_vtable * +archive_write_disk_vtable(void) +{ + static struct archive_vtable av; + static int inited = 0; + + if (!inited) { + av.archive_close = _archive_write_disk_close; + av.archive_filter_bytes = _archive_write_disk_filter_bytes; + av.archive_free = _archive_write_disk_free; + av.archive_write_header = _archive_write_disk_header; + av.archive_write_finish_entry + = _archive_write_disk_finish_entry; + av.archive_write_data = _archive_write_disk_data; + av.archive_write_data_block = _archive_write_disk_data_block; + inited = 1; + } + return (&av); +} + +static int64_t +_archive_write_disk_filter_bytes(struct archive *_a, int n) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + (void)n; /* UNUSED */ + if (n == -1 || n == 0) + return (a->total_bytes_written); + return (-1); +} + + +int +archive_write_disk_set_options(struct archive *_a, int flags) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + a->flags = flags; + return (ARCHIVE_OK); +} + + +/* + * Extract this entry to disk. + * + * TODO: Validate hardlinks. According to the standards, we're + * supposed to check each extracted hardlink and squawk if it refers + * to a file that we didn't restore. I'm not entirely convinced this + * is a good idea, but more importantly: Is there any way to validate + * hardlinks without keeping a complete list of filenames from the + * entire archive?? Ugh. + * + */ +static int +_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; + int ret, r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_header"); + archive_clear_error(&a->archive); + if (a->archive.state & ARCHIVE_STATE_DATA) { + r = _archive_write_disk_finish_entry(&a->archive); + if (r == ARCHIVE_FATAL) + return (r); + } + + /* Set up for this particular entry. */ + a->pst = NULL; + a->current_fixup = NULL; + a->deferred = 0; + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->entry = archive_entry_clone(entry); + a->fh = INVALID_HANDLE_VALUE; + a->fd_offset = 0; + a->offset = 0; + a->restore_pwd = -1; + a->uid = a->user_uid; + a->mode = archive_entry_mode(a->entry); + if (archive_entry_size_is_set(a->entry)) + a->filesize = archive_entry_size(a->entry); + else + a->filesize = -1; + archive_wstrcpy(&(a->_name_data), archive_entry_pathname_w(a->entry)); + a->name = a->_name_data.s; + archive_clear_error(&a->archive); + + /* + * Clean up the requested path. This is necessary for correct + * dir restores; the dir restore logic otherwise gets messed + * up by nonsense like "dir/.". + */ + ret = cleanup_pathname(a); + if (ret != ARCHIVE_OK) + return (ret); + + /* + * Generate a full-pathname and use it from here. + */ + if (permissive_name_w(a) < 0) { + errno = EINVAL; + return (ARCHIVE_FAILED); + } + + /* + * 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 + * reason. + */ + umask(a->user_umask = umask(0)); + + /* Figure out what we need to do for this entry. */ + a->todo = TODO_MODE_BASE; + if (a->flags & ARCHIVE_EXTRACT_PERM) { + a->todo |= TODO_MODE_FORCE; /* Be pushy about permissions. */ + /* + * SGID requires an extra "check" step because we + * cannot easily predict the GID that the system will + * assign. (Different systems assign GIDs to files + * based on a variety of criteria, including process + * credentials and the gid of the enclosing + * directory.) We can only restore the SGID bit if + * the file has the right GID, and we only know the + * GID if we either set it (see set_ownership) or if + * we've actually called stat() on the file after it + * was restored. Since there are several places at + * which we might verify the GID, we need a TODO bit + * to keep track. + */ + if (a->mode & S_ISGID) + a->todo |= TODO_SGID | TODO_SGID_CHECK; + /* + * Verifying the SUID is simpler, but can still be + * done in multiple ways, hence the separate "check" bit. + */ + if (a->mode & S_ISUID) + a->todo |= TODO_SUID | TODO_SUID_CHECK; + } else { + /* + * User didn't request full permissions, so don't + * restore SUID, SGID bits and obey umask. + */ + a->mode &= ~S_ISUID; + a->mode &= ~S_ISGID; + a->mode &= ~S_ISVTX; + a->mode &= ~a->user_umask; + } +#if 0 + if (a->flags & ARCHIVE_EXTRACT_OWNER) + a->todo |= TODO_OWNER; +#endif + if (a->flags & ARCHIVE_EXTRACT_TIME) + a->todo |= TODO_TIMES; + if (a->flags & ARCHIVE_EXTRACT_ACL) { + if (archive_entry_filetype(a->entry) == AE_IFDIR) + a->deferred |= TODO_ACLS; + else + a->todo |= TODO_ACLS; + } + if (a->flags & ARCHIVE_EXTRACT_XATTR) + a->todo |= TODO_XATTR; + if (a->flags & ARCHIVE_EXTRACT_FFLAGS) + a->todo |= TODO_FFLAGS; + if (a->flags & ARCHIVE_EXTRACT_SECURE_SYMLINKS) { + ret = check_symlinks(a); + if (ret != ARCHIVE_OK) + return (ret); + } + + ret = restore_entry(a); + + /* + * TODO: There are rumours that some extended attributes must + * be restored before file data is written. If this is true, + * then we either need to write all extended attributes both + * before and after restoring the data, or find some rule for + * determining which must go first and which last. Due to the + * many ways people are using xattrs, this may prove to be an + * intractable problem. + */ + + /* + * Fixup uses the unedited pathname from archive_entry_pathname(), + * because it is relative to the base dir and the edited path + * might be relative to some intermediate dir as a result of the + * deep restore logic. + */ + if (a->deferred & TODO_MODE) { + fe = current_fixup(a, archive_entry_pathname_w(entry)); + fe->fixup |= TODO_MODE_BASE; + fe->mode = a->mode; + } + + if ((a->deferred & TODO_TIMES) + && (archive_entry_mtime_is_set(entry) + || archive_entry_atime_is_set(entry))) { + fe = current_fixup(a, archive_entry_pathname_w(entry)); + fe->mode = a->mode; + fe->fixup |= TODO_TIMES; + if (archive_entry_atime_is_set(entry)) { + fe->atime = archive_entry_atime(entry); + fe->atime_nanos = archive_entry_atime_nsec(entry); + } else { + /* If atime is unset, use start time. */ + fe->atime = a->start_time; + fe->atime_nanos = 0; + } + if (archive_entry_mtime_is_set(entry)) { + fe->mtime = archive_entry_mtime(entry); + fe->mtime_nanos = archive_entry_mtime_nsec(entry); + } else { + /* If mtime is unset, use start time. */ + fe->mtime = a->start_time; + fe->mtime_nanos = 0; + } + if (archive_entry_birthtime_is_set(entry)) { + fe->birthtime = archive_entry_birthtime(entry); + fe->birthtime_nanos = archive_entry_birthtime_nsec(entry); + } else { + /* If birthtime is unset, use mtime. */ + fe->birthtime = fe->mtime; + fe->birthtime_nanos = fe->mtime_nanos; + } + } + + if (a->deferred & TODO_ACLS) { + fe = current_fixup(a, archive_entry_pathname_w(entry)); + archive_acl_copy(&fe->acl, archive_entry_acl(entry)); + } + + if (a->deferred & TODO_FFLAGS) { + fe = current_fixup(a, archive_entry_pathname_w(entry)); + fe->fixup |= TODO_FFLAGS; + /* TODO: Complete this.. defer fflags from below. */ + } + + /* + * On Windows, A creating sparse file requires a special mark. + */ + if (a->fh != INVALID_HANDLE_VALUE && + archive_entry_sparse_count(entry) > 0) { + int64_t base = 0, offset, length; + int i, cnt = archive_entry_sparse_reset(entry); + int sparse = 0; + + for (i = 0; i < cnt; i++) { + archive_entry_sparse_next(entry, &offset, &length); + if (offset - base >= 4096) { + sparse = 1;/* we have a hole. */ + break; + } + base = offset + length; + } + if (sparse) { + DWORD dmy; + /* Mark this file as sparse. */ + DeviceIoControl(a->fh, FSCTL_SET_SPARSE, + NULL, 0, NULL, 0, &dmy, NULL); + } + } + + /* We've created the object and are ready to pour data into it. */ + if (ret >= ARCHIVE_WARN) + a->archive.state = ARCHIVE_STATE_DATA; + /* + * If it's not open, tell our client not to try writing. + * In particular, dirs, links, etc, don't get written to. + */ + if (a->fh == INVALID_HANDLE_VALUE) { + archive_entry_set_size(entry, 0); + a->filesize = 0; + } + + return (ret); +} + +int +archive_write_disk_set_skip_file(struct archive *_a, int64_t d, int64_t i) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_skip_file"); + a->skip_file_set = 1; + a->skip_file_dev = d; + a->skip_file_ino = i; + return (ARCHIVE_OK); +} + +static ssize_t +write_data_block(struct archive_write_disk *a, const char *buff, size_t size) +{ + uint64_t start_size = size; + DWORD bytes_written = 0; + ssize_t block_size = 0, bytes_to_write; + + if (size == 0) + return (ARCHIVE_OK); + + if (a->filesize == 0 || a->fh == INVALID_HANDLE_VALUE) { + archive_set_error(&a->archive, 0, + "Attempt to write to an empty file"); + return (ARCHIVE_WARN); + } + + if (a->flags & ARCHIVE_EXTRACT_SPARSE) { + /* XXX TODO XXX Is there a more appropriate choice here ? */ + /* This needn't match the filesystem allocation size. */ + block_size = 16*1024; + } + + /* If this write would run beyond the file size, truncate it. */ + if (a->filesize >= 0 && (int64_t)(a->offset + size) > a->filesize) + start_size = size = (size_t)(a->filesize - a->offset); + + /* Write the data. */ + while (size > 0) { + if (block_size == 0) { + bytes_to_write = size; + } else { + /* We're sparsifying the file. */ + const char *p, *end; + int64_t block_end; + + /* Skip leading zero bytes. */ + for (p = buff, end = buff + size; p < end; ++p) { + if (*p != '\0') + break; + } + a->offset += p - buff; + size -= p - buff; + buff = p; + if (size == 0) + break; + + /* Calculate next block boundary after offset. */ + block_end + = (a->offset / block_size + 1) * block_size; + + /* If the adjusted write would cross block boundary, + * truncate it to the block boundary. */ + bytes_to_write = size; + if (a->offset + bytes_to_write > block_end) + bytes_to_write = block_end - a->offset; + } + /* Seek if necessary to the specified offset. */ + if (a->offset != a->fd_offset) { + LARGE_INTEGER distance; + distance.QuadPart = a->offset; + if (SetFilePointerEx_perso(a->fh, distance, NULL, FILE_BEGIN) == 0) { + DWORD lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + a->fd_offset = a->offset; + } + if (!WriteFile(a->fh, buff, (uint32_t)bytes_to_write, + &bytes_written, NULL)) { + DWORD lasterr; + + lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, "Write failed"); + return (ARCHIVE_WARN); + } + buff += bytes_written; + size -= bytes_written; + a->total_bytes_written += bytes_written; + a->offset += bytes_written; + a->fd_offset = a->offset; + } + return (start_size - size); +} + +static ssize_t +_archive_write_disk_data_block(struct archive *_a, + const void *buff, size_t size, int64_t offset) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + ssize_t r; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data_block"); + + a->offset = offset; + r = write_data_block(a, buff, size); + if (r < ARCHIVE_OK) + return (r); + if ((size_t)r < size) { + archive_set_error(&a->archive, 0, + "Write request too large"); + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static ssize_t +_archive_write_disk_data(struct archive *_a, const void *buff, size_t size) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_DATA, "archive_write_data"); + + return (write_data_block(a, buff, size)); +} + +static int +_archive_write_disk_finish_entry(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + int ret = ARCHIVE_OK; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_finish_entry"); + if (a->archive.state & ARCHIVE_STATE_HEADER) + return (ARCHIVE_OK); + archive_clear_error(&a->archive); + + /* Pad or truncate file to the right size. */ + if (a->fh == INVALID_HANDLE_VALUE) { + /* There's no file. */ + } else if (a->filesize < 0) { + /* File size is unknown, so we can't set the size. */ + } else if (a->fd_offset == a->filesize) { + /* Last write ended at exactly the filesize; we're done. */ + /* Hopefully, this is the common case. */ + } else { + if (la_ftruncate(a->fh, a->filesize) == -1 && + a->filesize == 0) { + archive_set_error(&a->archive, errno, + "File size could not be restored"); + return (ARCHIVE_FAILED); + } + /* + * Not all platforms implement the XSI option to + * extend files via ftruncate. Stat() the file again + * to see what happened. + */ + a->pst = NULL; + if ((ret = lazy_stat(a)) != ARCHIVE_OK) + return (ret); + /* We can use lseek()/write() to extend the file if + * ftruncate didn't work or isn't available. */ + if (bhfi_size(&(a->st)) < a->filesize) { + const char nul = '\0'; + LARGE_INTEGER distance; + distance.QuadPart = a->filesize - 1; + if (!SetFilePointerEx_perso(a->fh, distance, NULL, FILE_BEGIN)) { + DWORD lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, + "Seek failed"); + return (ARCHIVE_FATAL); + } + if (!WriteFile(a->fh, &nul, 1, NULL, NULL)) { + DWORD lasterr = GetLastError(); + if (lasterr == ERROR_ACCESS_DENIED) + errno = EBADF; + else + la_dosmaperr(lasterr); + archive_set_error(&a->archive, errno, + "Write to restore size failed"); + return (ARCHIVE_FATAL); + } + a->pst = NULL; + } + } + + /* Restore metadata. */ + + /* + * Look up the "real" UID only if we're going to need it. + * TODO: the TODO_SGID condition can be dropped here, can't it? + */ + if (a->todo & (TODO_OWNER | TODO_SUID | TODO_SGID)) { + a->uid = archive_write_disk_uid(&a->archive, + archive_entry_uname(a->entry), + archive_entry_uid(a->entry)); + } + /* Look up the "real" GID only if we're going to need it. */ + /* TODO: the TODO_SUID condition can be dropped here, can't it? */ + if (a->todo & (TODO_OWNER | TODO_SGID | TODO_SUID)) { + a->gid = archive_write_disk_gid(&a->archive, + archive_entry_gname(a->entry), + archive_entry_gid(a->entry)); + } + + /* + * Restore ownership before set_mode tries to restore suid/sgid + * bits. If we set the owner, we know what it is and can skip + * a stat() call to examine the ownership of the file on disk. + */ + if (a->todo & TODO_OWNER) + ret = set_ownership(a); + + /* + * set_mode must precede ACLs on systems such as Solaris and + * FreeBSD where setting the mode implicitly clears extended ACLs + */ + if (a->todo & TODO_MODE) { + int r2 = set_mode(a, a->mode); + if (r2 < ret) ret = r2; + } + + /* + * Security-related extended attributes (such as + * security.capability on Linux) have to be restored last, + * since they're implicitly removed by other file changes. + */ + if (a->todo & TODO_XATTR) { + int r2 = set_xattrs(a); + if (r2 < ret) ret = r2; + } + + /* + * Some flags prevent file modification; they must be restored after + * file contents are written. + */ + if (a->todo & TODO_FFLAGS) { + int r2 = set_fflags(a); + if (r2 < ret) ret = r2; + } + + /* + * Time must follow most other metadata; + * otherwise atime will get changed. + */ + if (a->todo & TODO_TIMES) { + int r2 = set_times_from_entry(a); + if (r2 < ret) ret = r2; + } + + /* + * ACLs must be restored after timestamps because there are + * ACLs that prevent attribute changes (including time). + */ + if (a->todo & TODO_ACLS) { + int r2 = set_acls(a, a->fh, + archive_entry_pathname_w(a->entry), + archive_entry_acl(a->entry)); + if (r2 < ret) ret = r2; + } + + /* If there's an fd, we can close it now. */ + if (a->fh != INVALID_HANDLE_VALUE) { + CloseHandle(a->fh); + a->fh = INVALID_HANDLE_VALUE; + } + /* If there's an entry, we can release it now. */ + if (a->entry) { + archive_entry_free(a->entry); + a->entry = NULL; + } + a->archive.state = ARCHIVE_STATE_HEADER; + return (ret); +} + +int +archive_write_disk_set_group_lookup(struct archive *_a, + void *private_data, + int64_t (*lookup_gid)(void *private, const char *gname, int64_t gid), + void (*cleanup_gid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_group_lookup"); + + if (a->cleanup_gid != NULL && a->lookup_gid_data != NULL) + (a->cleanup_gid)(a->lookup_gid_data); + + a->lookup_gid = lookup_gid; + a->cleanup_gid = cleanup_gid; + a->lookup_gid_data = private_data; + return (ARCHIVE_OK); +} + +int +archive_write_disk_set_user_lookup(struct archive *_a, + void *private_data, + int64_t (*lookup_uid)(void *private, const char *uname, int64_t uid), + void (*cleanup_uid)(void *private)) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_set_user_lookup"); + + if (a->cleanup_uid != NULL && a->lookup_uid_data != NULL) + (a->cleanup_uid)(a->lookup_uid_data); + + a->lookup_uid = lookup_uid; + a->cleanup_uid = cleanup_uid; + a->lookup_uid_data = private_data; + return (ARCHIVE_OK); +} + +int64_t +archive_write_disk_gid(struct archive *_a, const char *name, int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_gid"); + if (a->lookup_gid) + return (a->lookup_gid)(a->lookup_gid_data, name, id); + return (id); +} + +int64_t +archive_write_disk_uid(struct archive *_a, const char *name, int64_t id) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY, "archive_write_disk_uid"); + if (a->lookup_uid) + return (a->lookup_uid)(a->lookup_uid_data, name, id); + return (id); +} + +/* + * Create a new archive_write_disk object and initialize it with global state. + */ +struct archive * +archive_write_disk_new(void) +{ + struct archive_write_disk *a; + + a = (struct archive_write_disk *)malloc(sizeof(*a)); + if (a == NULL) + return (NULL); + memset(a, 0, sizeof(*a)); + a->archive.magic = ARCHIVE_WRITE_DISK_MAGIC; + /* We're ready to write a header immediately. */ + a->archive.state = ARCHIVE_STATE_HEADER; + a->archive.vtable = archive_write_disk_vtable(); + a->start_time = time(NULL); + /* Query and restore the umask. */ + umask(a->user_umask = umask(0)); + if (archive_wstring_ensure(&a->path_safe, 512) == NULL) { + free(a); + return (NULL); + } + return (&a->archive); +} + +static int +disk_unlink(wchar_t *path) +{ + wchar_t *fullname; + int r; + + r = _wunlink(path); + if (r != 0 && GetLastError() == ERROR_INVALID_NAME) { + fullname = __la_win_permissive_name_w(path); + r = _wunlink(fullname); + free(fullname); + } + return (r); +} + +static int +disk_rmdir(wchar_t *path) +{ + wchar_t *fullname; + int r; + + r = _wrmdir(path); + if (r != 0 && GetLastError() == ERROR_INVALID_NAME) { + fullname = __la_win_permissive_name_w(path); + r = _wrmdir(fullname); + free(fullname); + } + return (r); +} + +/* + * The main restore function. + */ +static int +restore_entry(struct archive_write_disk *a) +{ + int ret = ARCHIVE_OK, en; + + if (a->flags & ARCHIVE_EXTRACT_UNLINK && !S_ISDIR(a->mode)) { + /* + * TODO: Fix this. Apparently, there are platforms + * that still allow root to hose the entire filesystem + * by unlinking a dir. The S_ISDIR() test above + * prevents us from using unlink() here if the new + * object is a dir, but that doesn't mean the old + * object isn't a dir. + */ + if (disk_unlink(a->name) == 0) { + /* We removed it, reset cached stat. */ + a->pst = NULL; + } else if (errno == ENOENT) { + /* File didn't exist, that's just as good. */ + } else if (disk_rmdir(a->name) == 0) { + /* It was a dir, but now it's gone. */ + a->pst = NULL; + } else { + /* We tried, but couldn't get rid of it. */ + archive_set_error(&a->archive, errno, + "Could not unlink"); + return(ARCHIVE_FAILED); + } + } + + /* Try creating it first; if this fails, we'll try to recover. */ + en = create_filesystem_object(a); + + if ((en == ENOTDIR || en == ENOENT) + && !(a->flags & ARCHIVE_EXTRACT_NO_AUTODIR)) { + wchar_t *full; + /* If the parent dir doesn't exist, try creating it. */ + create_parent_dir(a, a->name); + /* Now try to create the object again. */ + full = __la_win_permissive_name_w(a->name); + if (full == NULL) { + en = EINVAL; + } else { + /* Remove multiple directories such as "a/../b../c" */ + archive_wstrcpy(&(a->_name_data), full); + a->name = a->_name_data.s; + free(full); + en = create_filesystem_object(a); + } + } + + if ((en == EISDIR || en == EEXIST) + && (a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + /* If we're not overwriting, we're done. */ + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + + /* + * Some platforms return EISDIR if you call + * open(O_WRONLY | O_EXCL | O_CREAT) on a directory, some + * return EEXIST. POSIX is ambiguous, requiring EISDIR + * for open(O_WRONLY) on a dir and EEXIST for open(O_EXCL | O_CREAT) + * on an existing item. + */ + if (en == EISDIR) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (disk_rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't remove already-existing dir"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (en == EEXIST) { + mode_t st_mode; + /* + * We know something is in the way, but we don't know what; + * we need to find out before we go any further. + */ + int r = 0; + /* + * The SECURE_SYMLINK logic has already removed a + * symlink to a dir if the client wants that. So + * follow the symlink if we're creating a dir. + */ + if (S_ISDIR(a->mode)) + r = file_information(a, a->name, &a->st, &st_mode, 0); + /* + * If it's not a dir (or it's a broken symlink), + * then don't follow it. + */ + if (r != 0 || !S_ISDIR(a->mode)) + r = file_information(a, a->name, &a->st, &st_mode, 1); + if (r != 0) { + archive_set_error(&a->archive, errno, + "Can't stat existing object"); + return (ARCHIVE_FAILED); + } + + /* + * NO_OVERWRITE_NEWER doesn't apply to directories. + */ + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER) + && !S_ISDIR(st_mode)) { + if (!older(&(a->st), a->entry)) { + archive_entry_unset_size(a->entry); + return (ARCHIVE_OK); + } + } + + /* If it's our archive, we're done. */ + if (a->skip_file_set && + bhfi_dev(&a->st) == a->skip_file_dev && + bhfi_ino(&a->st) == a->skip_file_ino) { + archive_set_error(&a->archive, 0, "Refusing to overwrite archive"); + return (ARCHIVE_FAILED); + } + + if (!S_ISDIR(st_mode)) { + /* A non-dir is in the way, unlink it. */ + if (disk_unlink(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't unlink already-existing object"); + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* Try again. */ + en = create_filesystem_object(a); + } else if (!S_ISDIR(a->mode)) { + /* A dir is in the way of a non-dir, rmdir it. */ + if (disk_rmdir(a->name) != 0) { + archive_set_error(&a->archive, errno, + "Can't remove already-existing dir"); + return (ARCHIVE_FAILED); + } + /* Try again. */ + en = create_filesystem_object(a); + } else { + /* + * There's a dir in the way of a dir. Don't + * waste time with rmdir()/mkdir(), just fix + * up the permissions on the existing dir. + * Note that we don't change perms on existing + * dirs unless _EXTRACT_PERM is specified. + */ + if ((a->mode != st_mode) + && (a->todo & TODO_MODE_FORCE)) + a->deferred |= (a->todo & TODO_MODE); + /* Ownership doesn't need deferred fixup. */ + en = 0; /* Forget the EEXIST. */ + } + } + + if (en) { + /* Everything failed; give up here. */ + archive_set_error(&a->archive, en, "Can't create '%s'", + a->name); + return (ARCHIVE_FAILED); + } + + a->pst = NULL; /* Cached stat data no longer valid. */ + return (ret); +} + +/* + * Returns 0 if creation succeeds, or else returns errno value from + * the failed system call. Note: This function should only ever perform + * a single system call. + */ +static int +create_filesystem_object(struct archive_write_disk *a) +{ + /* Create the entry. */ + const wchar_t *linkname; + wchar_t *fullname; + mode_t final_mode, mode; + int r; + + /* We identify hard/symlinks according to the link names. */ + /* Since link(2) and symlink(2) don't handle modes, we're done here. */ + linkname = archive_entry_hardlink_w(a->entry); + if (linkname != NULL) { + wchar_t *linkfull, *namefull; + + linkfull = __la_win_permissive_name_w(linkname); + namefull = __la_win_permissive_name_w(a->name); + if (linkfull == NULL || namefull == NULL) { + errno = EINVAL; + r = -1; + } else { + r = la_CreateHardLinkW(namefull, linkfull); + if (r == 0) { + la_dosmaperr(GetLastError()); + r = errno; + } else + r = 0; + } + /* + * New cpio and pax formats allow hardlink entries + * to carry data, so we may have to open the file + * for hardlink entries. + * + * If the hardlink was successfully created and + * the archive doesn't have carry data for it, + * consider it to be non-authoritive for meta data. + * This is consistent with GNU tar and BSD pax. + * If the hardlink does carry data, let the last + * archive entry decide ownership. + */ + if (r == 0 && a->filesize <= 0) { + a->todo = 0; + a->deferred = 0; + } else if (r == 0 && a->filesize > 0) { + a->fh = CreateFileW(namefull, GENERIC_WRITE, 0, NULL, + TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (a->fh == INVALID_HANDLE_VALUE) { + la_dosmaperr(GetLastError()); + r = errno; + } + } + free(linkfull); + free(namefull); + return (r); + } + linkname = archive_entry_symlink_w(a->entry); + if (linkname != NULL) { +#if HAVE_SYMLINK + return symlink(linkname, a->name) ? errno : 0; +#else + return (EPERM); +#endif + } + + /* + * The remaining system calls all set permissions, so let's + * try to take advantage of that to avoid an extra chmod() + * call. (Recall that umask is set to zero right now!) + */ + + /* Mode we want for the final restored object (w/o file type bits). */ + final_mode = a->mode & 07777; + /* + * The mode that will actually be restored in this step. Note + * that SUID, SGID, etc, require additional work to ensure + * security, so we never restore them at this point. + */ + mode = final_mode & 0777 & a->user_umask; + + switch (a->mode & AE_IFMT) { + default: + /* POSIX requires that we fall through here. */ + /* FALLTHROUGH */ + case AE_IFREG: + fullname = a->name; + /* O_WRONLY | O_CREAT | O_EXCL */ + a->fh = CreateFileW(fullname, GENERIC_WRITE, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + if (a->fh == INVALID_HANDLE_VALUE && + GetLastError() == ERROR_INVALID_NAME && + fullname == a->name) { + fullname = __la_win_permissive_name_w(a->name); + a->fh = CreateFileW(fullname, GENERIC_WRITE, 0, NULL, + CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + } + if (a->fh == INVALID_HANDLE_VALUE) { + if (GetLastError() == ERROR_ACCESS_DENIED) { + DWORD attr; + /* Simulate an errno of POSIX system. */ + attr = GetFileAttributesW(fullname); + if (attr == (DWORD)-1) + la_dosmaperr(GetLastError()); + else if (attr & FILE_ATTRIBUTE_DIRECTORY) + errno = EISDIR; + else + errno = EACCES; + } else + la_dosmaperr(GetLastError()); + r = 1; + } else + r = 0; + if (fullname != a->name) + free(fullname); + break; + case AE_IFCHR: + case AE_IFBLK: + /* TODO: Find a better way to warn about our inability + * to restore a block device node. */ + return (EINVAL); + case AE_IFDIR: + mode = (mode | MINIMUM_DIR_MODE) & MAXIMUM_DIR_MODE; + fullname = a->name; + r = CreateDirectoryW(fullname, NULL); + if (r == 0 && GetLastError() == ERROR_INVALID_NAME && + fullname == a->name) { + fullname = __la_win_permissive_name_w(a->name); + r = CreateDirectoryW(fullname, NULL); + } + if (r != 0) { + r = 0; + /* Defer setting dir times. */ + a->deferred |= (a->todo & TODO_TIMES); + a->todo &= ~TODO_TIMES; + /* Never use an immediate chmod(). */ + /* We can't avoid the chmod() entirely if EXTRACT_PERM + * because of SysV SGID inheritance. */ + if ((mode != final_mode) + || (a->flags & ARCHIVE_EXTRACT_PERM)) + a->deferred |= (a->todo & TODO_MODE); + a->todo &= ~TODO_MODE; + } else { + la_dosmaperr(GetLastError()); + r = -1; + } + if (fullname != a->name) + free(fullname); + break; + case AE_IFIFO: + /* TODO: Find a better way to warn about our inability + * to restore a fifo. */ + return (EINVAL); + } + + /* All the system calls above set errno on failure. */ + if (r) + return (errno); + + /* If we managed to set the final mode, we've avoided a chmod(). */ + if (mode == final_mode) + a->todo &= ~TODO_MODE; + return (0); +} + +/* + * Cleanup function for archive_extract. Mostly, this involves processing + * the fixup list, which is used to address a number of problems: + * * Dir permissions might prevent us from restoring a file in that + * dir, so we restore the dir with minimum 0700 permissions first, + * then correct the mode at the end. + * * Similarly, the act of restoring a file touches the directory + * and changes the timestamp on the dir, so we have to touch-up dir + * timestamps at the end as well. + * * Some file flags can interfere with the restore by, for example, + * preventing the creation of hardlinks to those files. + * * Mac OS extended metadata includes ACLs, so must be deferred on dirs. + * + * Note that tar/cpio do not require that archives be in a particular + * order; there is no way to know when the last file has been restored + * within a directory, so there's no way to optimize the memory usage + * here by fixing up the directory any earlier than the + * end-of-archive. + * + * XXX TODO: Directory ACLs should be restored here, for the same + * reason we set directory perms here. XXX + */ +static int +_archive_write_disk_close(struct archive *_a) +{ + struct archive_write_disk *a = (struct archive_write_disk *)_a; + struct fixup_entry *next, *p; + int ret; + + archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_HEADER | ARCHIVE_STATE_DATA, + "archive_write_disk_close"); + ret = _archive_write_disk_finish_entry(&a->archive); + + /* Sort dir list so directories are fixed up in depth-first order. */ + p = sort_dir_list(a->fixup_list); + + while (p != NULL) { + a->pst = NULL; /* Mark stat cache as out-of-date. */ + if (p->fixup & TODO_TIMES) { + set_times(a, INVALID_HANDLE_VALUE, p->mode, p->name, + p->atime, p->atime_nanos, + p->birthtime, p->birthtime_nanos, + p->mtime, p->mtime_nanos, + p->ctime, p->ctime_nanos); + } + if (p->fixup & TODO_MODE_BASE) + la_chmod(p->name, p->mode); + if (p->fixup & TODO_ACLS) + set_acls(a, INVALID_HANDLE_VALUE, p->name, &p->acl); + next = p->next; + archive_acl_clear(&p->acl); + free(p->name); + free(p); + p = next; + } + a->fixup_list = NULL; + return (ret); +} + +static int +_archive_write_disk_free(struct archive *_a) +{ + struct archive_write_disk *a; + int ret; + if (_a == NULL) + return (ARCHIVE_OK); + archive_check_magic(_a, ARCHIVE_WRITE_DISK_MAGIC, + ARCHIVE_STATE_ANY | ARCHIVE_STATE_FATAL, "archive_write_disk_free"); + a = (struct archive_write_disk *)_a; + ret = _archive_write_disk_close(&a->archive); + archive_write_disk_set_group_lookup(&a->archive, NULL, NULL, NULL); + archive_write_disk_set_user_lookup(&a->archive, NULL, NULL, NULL); + if (a->entry) + archive_entry_free(a->entry); + archive_wstring_free(&a->_name_data); + archive_string_free(&a->archive.error_string); + archive_wstring_free(&a->path_safe); + a->archive.magic = 0; + __archive_clean(&a->archive); + free(a); + return (ret); +} + +/* + * Simple O(n log n) merge sort to order the fixup list. In + * particular, we want to restore dir timestamps depth-first. + */ +static struct fixup_entry * +sort_dir_list(struct fixup_entry *p) +{ + struct fixup_entry *a, *b, *t; + + if (p == NULL) + return (NULL); + /* A one-item list is already sorted. */ + if (p->next == NULL) + return (p); + + /* Step 1: split the list. */ + t = p; + a = p->next->next; + while (a != NULL) { + /* Step a twice, t once. */ + a = a->next; + if (a != NULL) + a = a->next; + t = t->next; + } + /* Now, t is at the mid-point, so break the list here. */ + b = t->next; + t->next = NULL; + a = p; + + /* Step 2: Recursively sort the two sub-lists. */ + a = sort_dir_list(a); + b = sort_dir_list(b); + + /* Step 3: Merge the returned lists. */ + /* Pick the first element for the merged list. */ + if (wcscmp(a->name, b->name) > 0) { + t = p = a; + a = a->next; + } else { + t = p = b; + b = b->next; + } + + /* Always put the later element on the list first. */ + while (a != NULL && b != NULL) { + if (wcscmp(a->name, b->name) > 0) { + t->next = a; + a = a->next; + } else { + t->next = b; + b = b->next; + } + t = t->next; + } + + /* Only one list is non-empty, so just splice it on. */ + if (a != NULL) + t->next = a; + if (b != NULL) + t->next = b; + + return (p); +} + +/* + * Returns a new, initialized fixup entry. + * + * TODO: Reduce the memory requirements for this list by using a tree + * structure rather than a simple list of names. + */ +static struct fixup_entry * +new_fixup(struct archive_write_disk *a, const wchar_t *pathname) +{ + struct fixup_entry *fe; + + fe = (struct fixup_entry *)calloc(1, sizeof(struct fixup_entry)); + if (fe == NULL) + return (NULL); + fe->next = a->fixup_list; + a->fixup_list = fe; + fe->fixup = 0; + fe->name = _wcsdup(pathname); + return (fe); +} + +/* + * Returns a fixup structure for the current entry. + */ +static struct fixup_entry * +current_fixup(struct archive_write_disk *a, const wchar_t *pathname) +{ + if (a->current_fixup == NULL) + a->current_fixup = new_fixup(a, pathname); + return (a->current_fixup); +} + +/* TODO: Make this work. */ +/* + * TODO: The deep-directory support bypasses this; disable deep directory + * support if we're doing symlink checks. + */ +/* + * TODO: Someday, integrate this with the deep dir support; they both + * scan the path and both can be optimized by comparing against other + * recent paths. + */ +/* TODO: Extend this to support symlinks on Windows Vista and later. */ +static int +check_symlinks(struct archive_write_disk *a) +{ + wchar_t *pn, *p; + wchar_t c; + int r; + BY_HANDLE_FILE_INFORMATION st; + mode_t st_mode; + + /* + * Guard against symlink tricks. Reject any archive entry whose + * destination would be altered by a symlink. + */ + /* Whatever we checked last time doesn't need to be re-checked. */ + pn = a->name; + p = a->path_safe.s; + while ((*pn != '\0') && (*p == *pn)) + ++p, ++pn; + c = pn[0]; + /* Keep going until we've checked the entire name. */ + while (pn[0] != '\0' && (pn[0] != '\\' || pn[1] != '\0')) { + /* Skip the next path element. */ + while (*pn != '\0' && *pn != '\\') + ++pn; + c = pn[0]; + pn[0] = '\0'; + /* Check that we haven't hit a symlink. */ + r = file_information(a, a->name, &st, &st_mode, 1); + if (r != 0) { + /* We've hit a dir that doesn't exist; stop now. */ + if (errno == ENOENT) + break; + } else if (S_ISLNK(st_mode)) { + if (c == '\0') { + /* + * Last element is symlink; remove it + * so we can overwrite it with the + * item being extracted. + */ + if (disk_unlink(a->name)) { + archive_set_error(&a->archive, errno, + "Could not remove symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + a->pst = NULL; + /* + * Even if we did remove it, a warning + * is in order. The warning is silly, + * though, if we're just replacing one + * symlink with another symlink. + */ + if (!S_ISLNK(a->mode)) { + archive_set_error(&a->archive, 0, + "Removing symlink %s", + a->name); + } + /* Symlink gone. No more problem! */ + pn[0] = c; + return (0); + } else if (a->flags & ARCHIVE_EXTRACT_UNLINK) { + /* User asked us to remove problems. */ + if (disk_unlink(a->name) != 0) { + archive_set_error(&a->archive, 0, + "Cannot remove intervening symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + a->pst = NULL; + } else { + archive_set_error(&a->archive, 0, + "Cannot extract through symlink %s", + a->name); + pn[0] = c; + return (ARCHIVE_FAILED); + } + } + } + pn[0] = c; + /* We've checked and/or cleaned the whole path, so remember it. */ + archive_wstrcpy(&a->path_safe, a->name); + return (ARCHIVE_OK); +} + +static int +guidword(wchar_t *p, int n) +{ + int i; + + for (i = 0; i < n; i++) { + if ((*p >= L'0' && *p <= L'9') || + (*p >= L'a' && *p <= L'f') || + (*p >= L'A' && *p <= L'F')) + p++; + else + return (-1); + } + return (0); +} + +/* + * Canonicalize the pathname. In particular, this strips duplicate + * '\' characters, '.' elements, and trailing '\'. It also raises an + * error for an empty path, a trailing '..' or (if _SECURE_NODOTDOT is + * set) any '..' in the path. + */ +static int +cleanup_pathname(struct archive_write_disk *a) +{ + wchar_t *dest, *src, *p, *top; + wchar_t separator = L'\0'; + + p = a->name; + if (*p == L'\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid empty pathname"); + return (ARCHIVE_FAILED); + } + + /* Replace '/' by '\' */ + for (; *p != L'\0'; p++) { + if (*p == L'/') + *p = L'\\'; + } + p = a->name; + + /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or + * "\\?\Volume{GUID}\" + * (absolute path prefixes used by Windows API) */ + if (p[0] == L'\\' && p[1] == L'\\' && + (p[2] == L'.' || p[2] == L'?') && p[3] == L'\\') + { + /* A path begin with "\\?\UNC\" */ + if (p[2] == L'?' && + (p[4] == L'U' || p[4] == L'u') && + (p[5] == L'N' || p[5] == L'n') && + (p[6] == L'C' || p[6] == L'c') && + p[7] == L'\\') + p += 8; + /* A path begin with "\\?\Volume{GUID}\" */ + else if (p[2] == L'?' && + (p[4] == L'V' || p[4] == L'v') && + (p[5] == L'O' || p[5] == L'o') && + (p[6] == L'L' || p[6] == L'l') && + (p[7] == L'U' || p[7] == L'u') && + (p[8] == L'M' || p[8] == L'm') && + (p[9] == L'E' || p[9] == L'e') && + p[10] == L'{') { + if (guidword(p+11, 8) == 0 && p[19] == L'-' && + guidword(p+20, 4) == 0 && p[24] == L'-' && + guidword(p+25, 4) == 0 && p[29] == L'-' && + guidword(p+30, 4) == 0 && p[34] == L'-' && + guidword(p+35, 12) == 0 && p[47] == L'}' && + p[48] == L'\\') + p += 49; + else + p += 4; + /* A path begin with "\\.\PhysicalDriveX" */ + } else if (p[2] == L'.' && + (p[4] == L'P' || p[4] == L'p') && + (p[5] == L'H' || p[5] == L'h') && + (p[6] == L'Y' || p[6] == L'y') && + (p[7] == L'S' || p[7] == L's') && + (p[8] == L'I' || p[8] == L'i') && + (p[9] == L'C' || p[9] == L'c') && + (p[9] == L'A' || p[9] == L'a') && + (p[9] == L'L' || p[9] == L'l') && + (p[9] == L'D' || p[9] == L'd') && + (p[9] == L'R' || p[9] == L'r') && + (p[9] == L'I' || p[9] == L'i') && + (p[9] == L'V' || p[9] == L'v') && + (p[9] == L'E' || p[9] == L'e') && + (p[10] >= L'0' && p[10] <= L'9') && + p[11] == L'\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a physical drive name"); + return (ARCHIVE_FAILED); + } else + p += 4; + } + + /* Skip leading drive letter from archives created + * on Windows. */ + if (((p[0] >= L'a' && p[0] <= L'z') || + (p[0] >= L'A' && p[0] <= L'Z')) && + p[1] == L':') { + if (p[2] == L'\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a drive name"); + return (ARCHIVE_FAILED); + } + if (p[2] == L'\\') + p += 2; + } + + top = dest = src = p; + /* Rewrite the path name if its character is a unusable. */ + for (; *p != L'\0'; p++) { + if (*p == L':' || *p == L'*' || *p == L'?' || *p == L'"' || + *p == L'<' || *p == L'>' || *p == L'|') + *p = L'_'; + } + /* Skip leading '\'. */ + if (*src == L'\\') + separator = *src++; + + /* Scan the pathname one element at a time. */ + for (;;) { + /* src points to first char after '\' */ + if (src[0] == L'\0') { + break; + } else if (src[0] == L'\\') { + /* Found '\\'('//'), ignore second one. */ + src++; + continue; + } else if (src[0] == L'.') { + if (src[1] == L'\0') { + /* Ignore trailing '.' */ + break; + } else if (src[1] == L'\\') { + /* Skip '.\'. */ + src += 2; + continue; + } else if (src[1] == L'.') { + if (src[2] == L'\\' || src[2] == L'\0') { + /* Conditionally warn about '..' */ + if (a->flags & + ARCHIVE_EXTRACT_SECURE_NODOTDOT) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Path contains '..'"); + return (ARCHIVE_FAILED); + } + } + /* + * Note: Under no circumstances do we + * remove '..' elements. In + * particular, restoring + * '\foo\..\bar\' should create the + * 'foo' dir as a side-effect. + */ + } + } + + /* Copy current element, including leading '\'. */ + if (separator) + *dest++ = L'\\'; + while (*src != L'\0' && *src != L'\\') { + *dest++ = *src++; + } + + if (*src == L'\0') + break; + + /* Skip '\' separator. */ + separator = *src++; + } + /* + * We've just copied zero or more path elements, not including the + * final '\'. + */ + if (dest == top) { + /* + * Nothing got copied. The path must have been something + * like '.' or '\' or './' or '/././././/./'. + */ + if (separator) + *dest++ = L'\\'; + else + *dest++ = L'.'; + } + /* Terminate the result. */ + *dest = L'\0'; + return (ARCHIVE_OK); +} + +/* + * Create the parent directory of the specified path, assuming path + * is already in mutable storage. + */ +static int +create_parent_dir(struct archive_write_disk *a, wchar_t *path) +{ + wchar_t *slash; + int r; + + /* Remove tail element to obtain parent name. */ + slash = wcsrchr(path, L'\\'); + if (slash == NULL) + return (ARCHIVE_OK); + *slash = L'\0'; + r = create_dir(a, path); + *slash = L'\\'; + return (r); +} + +/* + * Create the specified dir, recursing to create parents as necessary. + * + * Returns ARCHIVE_OK if the path exists when we're done here. + * Otherwise, returns ARCHIVE_FAILED. + * Assumes path is in mutable storage; path is unchanged on exit. + */ +static int +create_dir(struct archive_write_disk *a, wchar_t *path) +{ + BY_HANDLE_FILE_INFORMATION st; + struct fixup_entry *le; + wchar_t *slash, *base, *full; + mode_t mode_final, mode, st_mode; + int r; + + /* Check for special names and just skip them. */ + slash = wcsrchr(path, L'\\'); + if (slash == NULL) + base = path; + else + base = slash + 1; + + if (base[0] == L'\0' || + (base[0] == L'.' && base[1] == L'\0') || + (base[0] == L'.' && base[1] == L'.' && base[2] == L'\0')) { + /* Don't bother trying to create null path, '.', or '..'. */ + if (slash != NULL) { + *slash = L'\0'; + r = create_dir(a, path); + *slash = L'\\'; + return (r); + } + return (ARCHIVE_OK); + } + + /* + * Yes, this should be stat() and not lstat(). Using lstat() + * here loses the ability to extract through symlinks. Also note + * that this should not use the a->st cache. + */ + if (file_information(a, path, &st, &st_mode, 0) == 0) { + if (S_ISDIR(st_mode)) + return (ARCHIVE_OK); + if ((a->flags & ARCHIVE_EXTRACT_NO_OVERWRITE)) { + archive_set_error(&a->archive, EEXIST, + "Can't create directory '%s'", path); + return (ARCHIVE_FAILED); + } + if (disk_unlink(path) != 0) { + archive_set_error(&a->archive, errno, + "Can't create directory '%s': " + "Conflicting file cannot be removed", + path); + return (ARCHIVE_FAILED); + } + } else if (errno != ENOENT && errno != ENOTDIR) { + /* Stat failed? */ + archive_set_error(&a->archive, errno, "Can't test directory '%s'", path); + return (ARCHIVE_FAILED); + } else if (slash != NULL) { + *slash = '\0'; + r = create_dir(a, path); + *slash = '\\'; + if (r != ARCHIVE_OK) + return (r); + } + + /* + * Mode we want for the final restored directory. Per POSIX, + * implicitly-created dirs must be created obeying the umask. + * There's no mention whether this is different for privileged + * restores (which the rest of this code handles by pretending + * umask=0). I've chosen here to always obey the user's umask for + * implicit dirs, even if _EXTRACT_PERM was specified. + */ + mode_final = DEFAULT_DIR_MODE & ~a->user_umask; + /* Mode we want on disk during the restore process. */ + mode = mode_final; + mode |= MINIMUM_DIR_MODE; + mode &= MAXIMUM_DIR_MODE; + /* + * Apply __la_win_permissive_name_w to path in order to + * remove '../' path string. + */ + full = __la_win_permissive_name_w(path); + if (full == NULL) + errno = EINVAL; + else if (CreateDirectoryW(full, NULL) != 0) { + if (mode != mode_final) { + le = new_fixup(a, path); + le->fixup |=TODO_MODE_BASE; + le->mode = mode_final; + } + free(full); + return (ARCHIVE_OK); + } else { + la_dosmaperr(GetLastError()); + } + free(full); + + /* + * Without the following check, a/b/../b/c/d fails at the + * second visit to 'b', so 'd' can't be created. Note that we + * don't add it to the fixup list here, as it's already been + * added. + */ + if (file_information(a, path, &st, &st_mode, 0) == 0 && S_ISDIR(st_mode)) + return (ARCHIVE_OK); + + archive_set_error(&a->archive, errno, "Failed to create dir '%s'", + path); + return (ARCHIVE_FAILED); +} + +/* + * Note: Although we can skip setting the user id if the desired user + * id matches the current user, we cannot skip setting the group, as + * many systems set the gid based on the containing directory. So + * we have to perform a chown syscall if we want to set the SGID + * bit. (The alternative is to stat() and then possibly chown(); it's + * more efficient to skip the stat() and just always chown().) Note + * that a successful chown() here clears the TODO_SGID_CHECK bit, which + * allows set_mode to skip the stat() check for the GID. + */ +static int +set_ownership(struct archive_write_disk *a) +{ +/* unfortunately, on win32 there is no 'root' user with uid 0, + so we just have to try the chown and see if it works */ + + /* If we know we can't change it, don't bother trying. */ + if (a->user_uid != 0 && a->user_uid != a->uid) { + archive_set_error(&a->archive, errno, + "Can't set UID=%jd", (intmax_t)a->uid); + return (ARCHIVE_WARN); + } + + archive_set_error(&a->archive, errno, + "Can't set user=%jd/group=%jd for %s", + (intmax_t)a->uid, (intmax_t)a->gid, a->name); + return (ARCHIVE_WARN); +} + +static int +set_times(struct archive_write_disk *a, + HANDLE h, int mode, const wchar_t *name, + time_t atime, long atime_nanos, + time_t birthtime, long birthtime_nanos, + time_t mtime, long mtime_nanos, + time_t ctime, long ctime_nanos) +{ +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +#define WINTIME(sec, nsec) ((Int32x32To64(sec, 10000000) + EPOC_TIME)\ + + (((nsec)/1000)*10)) + + HANDLE hw = 0; + ULARGE_INTEGER wintm; + FILETIME *pfbtime; + FILETIME fatime, fbtime, fmtime; + + (void)ctime; /* UNUSED */ + (void)ctime_nanos; /* UNUSED */ + + if (h != INVALID_HANDLE_VALUE) { + hw = NULL; + } else { + wchar_t *ws; + + if (S_ISLNK(mode)) + return (ARCHIVE_OK); + ws = __la_win_permissive_name_w(name); + if (ws == NULL) + goto settimes_failed; + hw = CreateFileW(ws, FILE_WRITE_ATTRIBUTES, + 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + free(ws); + if (hw == INVALID_HANDLE_VALUE) + goto settimes_failed; + h = hw; + } + + wintm.QuadPart = WINTIME(atime, atime_nanos); + fatime.dwLowDateTime = wintm.LowPart; + fatime.dwHighDateTime = wintm.HighPart; + wintm.QuadPart = WINTIME(mtime, mtime_nanos); + fmtime.dwLowDateTime = wintm.LowPart; + fmtime.dwHighDateTime = wintm.HighPart; + /* + * SetFileTime() supports birthtime. + */ + if (birthtime > 0 || birthtime_nanos > 0) { + wintm.QuadPart = WINTIME(birthtime, birthtime_nanos); + fbtime.dwLowDateTime = wintm.LowPart; + fbtime.dwHighDateTime = wintm.HighPart; + pfbtime = &fbtime; + } else + pfbtime = NULL; + if (SetFileTime(h, pfbtime, &fatime, &fmtime) == 0) + goto settimes_failed; + CloseHandle(hw); + return (ARCHIVE_OK); + +settimes_failed: + CloseHandle(hw); + archive_set_error(&a->archive, EINVAL, "Can't restore time"); + return (ARCHIVE_WARN); +} + +static int +set_times_from_entry(struct archive_write_disk *a) +{ + time_t atime, birthtime, mtime, ctime; + long atime_nsec, birthtime_nsec, mtime_nsec, ctime_nsec; + + /* Suitable defaults. */ + atime = birthtime = mtime = ctime = a->start_time; + atime_nsec = birthtime_nsec = mtime_nsec = ctime_nsec = 0; + + /* If no time was provided, we're done. */ + if (!archive_entry_atime_is_set(a->entry) + && !archive_entry_birthtime_is_set(a->entry) + && !archive_entry_mtime_is_set(a->entry)) + return (ARCHIVE_OK); + + if (archive_entry_atime_is_set(a->entry)) { + atime = archive_entry_atime(a->entry); + atime_nsec = archive_entry_atime_nsec(a->entry); + } + if (archive_entry_birthtime_is_set(a->entry)) { + birthtime = archive_entry_birthtime(a->entry); + birthtime_nsec = archive_entry_birthtime_nsec(a->entry); + } + if (archive_entry_mtime_is_set(a->entry)) { + mtime = archive_entry_mtime(a->entry); + mtime_nsec = archive_entry_mtime_nsec(a->entry); + } + if (archive_entry_ctime_is_set(a->entry)) { + ctime = archive_entry_ctime(a->entry); + ctime_nsec = archive_entry_ctime_nsec(a->entry); + } + + return set_times(a, a->fh, a->mode, a->name, + atime, atime_nsec, + birthtime, birthtime_nsec, + mtime, mtime_nsec, + ctime, ctime_nsec); +} + +static int +set_mode(struct archive_write_disk *a, int mode) +{ + int r = ARCHIVE_OK; + mode &= 07777; /* Strip off file type bits. */ + + if (a->todo & TODO_SGID_CHECK) { + /* + * If we don't know the GID is right, we must stat() + * to verify it. We can't just check the GID of this + * process, since systems sometimes set GID from + * the enclosing dir or based on ACLs. + */ + if ((r = lazy_stat(a)) != ARCHIVE_OK) + return (r); + if (0 != a->gid) { + mode &= ~ S_ISGID; + } + /* While we're here, double-check the UID. */ + if (0 != a->uid + && (a->todo & TODO_SUID)) { + mode &= ~ S_ISUID; + } + a->todo &= ~TODO_SGID_CHECK; + a->todo &= ~TODO_SUID_CHECK; + } else if (a->todo & TODO_SUID_CHECK) { + /* + * If we don't know the UID is right, we can just check + * the user, since all systems set the file UID from + * the process UID. + */ + if (a->user_uid != a->uid) { + mode &= ~ S_ISUID; + } + a->todo &= ~TODO_SUID_CHECK; + } + + if (S_ISLNK(a->mode)) { +#ifdef HAVE_LCHMOD + /* + * If this is a symlink, use lchmod(). If the + * platform doesn't support lchmod(), just skip it. A + * platform that doesn't provide a way to set + * permissions on symlinks probably ignores + * permissions on symlinks, so a failure here has no + * impact. + */ + if (lchmod(a->name, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } +#endif + } else if (!S_ISDIR(a->mode)) { + /* + * If it's not a symlink and not a dir, then use + * fchmod() or chmod(), depending on whether we have + * an fd. Dirs get their perms set during the + * post-extract fixup, which is handled elsewhere. + */ +#ifdef HAVE_FCHMOD + if (a->fd >= 0) { + if (fchmod(a->fd, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } else +#endif + /* If this platform lacks fchmod(), then + * we'll just use chmod(). */ + if (la_chmod(a->name, mode) != 0) { + archive_set_error(&a->archive, errno, + "Can't set permissions to 0%o", (int)mode); + r = ARCHIVE_WARN; + } + } + return (r); +} + +static int +set_fflags(struct archive_write_disk *a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +} + +/* Default empty function body to satisfy mainline code. */ +static int +set_acls(struct archive_write_disk *a, HANDLE h, const wchar_t *name, + struct archive_acl *acl) +{ + (void)a; /* UNUSED */ + (void)h; /* UNUSED */ + (void)name; /* UNUSED */ + (void)acl; /* UNUSED */ + return (ARCHIVE_OK); +} + +/* + * Restore extended attributes - stub implementation for unsupported systems + */ +static int +set_xattrs(struct archive_write_disk *a) +{ + static int warning_done = 0; + + /* If there aren't any extended attributes, then it's okay not + * to extract them, otherwise, issue a single warning. */ + if (archive_entry_xattr_count(a->entry) != 0 && !warning_done) { + warning_done = 1; + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Cannot restore extended attributes on this system"); + return (ARCHIVE_WARN); + } + /* Warning was already emitted; suppress further warnings. */ + return (ARCHIVE_OK); +} + +static void +fileTimeToUtc(const FILETIME *filetime, time_t *time, long *ns) +{ + ULARGE_INTEGER utc; + + utc.HighPart = filetime->dwHighDateTime; + utc.LowPart = filetime->dwLowDateTime; + if (utc.QuadPart >= EPOC_TIME) { + utc.QuadPart -= EPOC_TIME; + /* milli seconds base */ + *time = (time_t)(utc.QuadPart / 10000000); + /* nano seconds base */ + *ns = (long)(utc.QuadPart % 10000000) * 100; + } else { + *time = 0; + *ns = 0; + } +} +/* + * Test if file on disk is older than entry. + */ +static int +older(BY_HANDLE_FILE_INFORMATION *st, struct archive_entry *entry) +{ + time_t sec; + long nsec; + + fileTimeToUtc(&st->ftLastWriteTime, &sec, &nsec); + /* First, test the seconds and return if we have a definite answer. */ + /* Definitely older. */ + if (sec < archive_entry_mtime(entry)) + return (1); + /* Definitely younger. */ + if (sec > archive_entry_mtime(entry)) + return (0); + if (nsec < archive_entry_mtime_nsec(entry)) + return (1); + /* Same age or newer, so not older. */ + return (0); +} + +#endif /* _WIN32 && !__CYGWIN__ */ + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_filter.3 b/Utilities/cmlibarchive/libarchive/archive_write_filter.3 new file mode 100644 index 000000000..00438d405 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_filter.3 @@ -0,0 +1,98 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_FILTER 3 +.Os +.Sh NAME +.Nm archive_write_add_filter_bzip2 , +.Nm archive_write_add_filter_compress , +.Nm archive_write_add_filter_gzip , +.Nm archive_write_add_filter_lzip , +.Nm archive_write_add_filter_lzma , +.Nm archive_write_add_filter_none , +.Nm archive_write_add_filter_program , +.Nm archive_write_add_filter_xz +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_add_filter_bzip2 "struct archive *" +.Ft int +.Fn archive_write_add_filter_compress "struct archive *" +.Ft int +.Fn archive_write_add_filter_gzip "struct archive *" +.Ft int +.Fn archive_write_add_filter_lzip "struct archive *" +.Ft int +.Fn archive_write_add_filter_lzma "struct archive *" +.Ft int +.Fn archive_write_add_filter_none "struct archive *" +.Ft int +.Fn archive_write_add_filter_program "struct archive *" "const char * cmd" +.Ft int +.Fn archive_write_add_filter_xz "struct archive *" +.Sh DESCRIPTION +.Bl -tag -width indent +.It Xo +.Fn archive_write_add_filter_bzip2 , +.Fn archive_write_add_filter_compress , +.Fn archive_write_add_filter_gzip , +.Fn archive_write_add_filter_lzip , +.Fn archive_write_add_filter_lzma , +.Fn archive_write_add_filter_xz , +.Xc +The resulting archive will be compressed as specified. +Note that the compressed output is always properly blocked. +.It Fn archive_write_add_filter_none +This is never necessary. +It is provided only for backwards compatibility. +.It Fn archive_write_add_filter_program +The archive will be fed into the specified compression program. +The output of that program is blocked and written to the client +write callbacks. +.El +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write 3 , +.Xr archive_write_format 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 new file mode 100644 index 000000000..3add60129 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_finish_entry.3 @@ -0,0 +1,74 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_FINISH_ENTRY 3 +.Os +.Sh NAME +.Nm archive_write_finish_entry +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_finish_entry "struct archive *" +.Sh DESCRIPTION +Close out the entry just written. +In particular, this writes out the final padding required by some formats. +Ordinarily, clients never need to call this, as it +is called automatically by +.Fn archive_write_next_header +and +.Fn archive_write_close +as needed. +.\" .Sh EXAMPLE +.Sh RETURN VALUES +This function returns +.Cm ARCHIVE_OK +on success, or one of several non-zero +error codes for errors. +Specific error codes include: +.Cm ARCHIVE_RETRY +for operations that might succeed if retried, +.Cm ARCHIVE_WARN +for unusual conditions that do not prevent further operations, and +.Cm ARCHIVE_FATAL +for serious errors that make remaining operations impossible. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_data 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_format.3 b/Utilities/cmlibarchive/libarchive/archive_write_format.3 new file mode 100644 index 000000000..e12e7d865 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_format.3 @@ -0,0 +1,98 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_FORMAT 3 +.Os +.Sh NAME +.Nm archive_write_set_format_cpio , +.Nm archive_write_set_format_pax , +.Nm archive_write_set_format_pax_restricted , +.Nm archive_write_set_format_shar , +.Nm archive_write_set_format_shar_dump , +.Nm archive_write_set_format_ustar +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_set_format_cpio "struct archive *" +.Ft int +.Fn archive_write_set_format_pax "struct archive *" +.Ft int +.Fn archive_write_set_format_pax_restricted "struct archive *" +.Ft int +.Fn archive_write_set_format_shar "struct archive *" +.Ft int +.Fn archive_write_set_format_shar_dump "struct archive *" +.Ft int +.Fn archive_write_set_format_ustar "struct archive *" +.Sh DESCRIPTION +These functions set the format that will be used for the archive. +.Pp +The library can write +POSIX octet-oriented cpio format archives, +POSIX-standard +.Dq pax interchange +format archives, +traditional +.Dq shar +archives, +enhanced +.Dq dump +shar archives that store a variety of file attributes and handle binary files, +and +POSIX-standard +.Dq ustar +archives. +The pax interchange format is a backwards-compatible tar format that +adds key/value attributes to each entry and supports arbitrary +filenames, linknames, uids, sizes, etc. +.Dq Restricted pax interchange format +is the library default; this is the same as pax format, but suppresses +the pax extended header for most normal files. +In most cases, this will result in ordinary ustar archives. +.\" +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_free.3 b/Utilities/cmlibarchive/libarchive/archive_write_free.3 new file mode 100644 index 000000000..27efe18b0 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_free.3 @@ -0,0 +1,81 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_FREE 3 +.Os +.Sh NAME +.Nm archive_write_close , +.Nm archive_write_finish , +.Nm archive_write_free +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_close "struct archive *" +.Ft int +.Fn archive_write_finish "struct archive *" +.Ft int +.Fn archive_write_free "struct archive *" +.Sh DESCRIPTION +.Bl -tag -width indent +.It Fn archive_write_close +Complete the archive and invoke the close callback. +.It Fn archive_write_finish +This is a deprecated synonym for +.Fn archive_write_free . +.It Fn archive_write_free +Invokes +.Fn archive_write_close +if necessary, then releases all resources. +If you need detailed information about +.Fn archive_write_close +failures, you should be careful to call it separately, as +you cannot obtain error information after +.Fn archive_write_free +returns. +.El +.\" .Sh EXAMPLE +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_header.3 b/Utilities/cmlibarchive/libarchive/archive_write_header.3 new file mode 100644 index 000000000..423b38e46 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_header.3 @@ -0,0 +1,71 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_HEADER 3 +.Os +.Sh NAME +.Nm archive_write_header +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fn archive_write_header "struct archive *" "struct archive_entry *" +.Sh DESCRIPTION +Build and write a header using the data in the provided +.Tn struct archive_entry +structure. +See +.Xr archive_entry 3 +for information on creating and populating +.Tn struct archive_entry +objects. +.\" .Sh EXAMPLE +.Sh RETURN VALUES +This function returns +.Cm ARCHIVE_OK +on success, or one of the following on error: +.Cm ARCHIVE_RETRY +for operations that might succeed if retried, +.Cm ARCHIVE_WARN +for unusual conditions that do not prevent further operations, and +.Cm ARCHIVE_FATAL +for serious errors that make remaining operations impossible. +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_new.3 b/Utilities/cmlibarchive/libarchive/archive_write_new.3 new file mode 100644 index 000000000..d626ccb73 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_new.3 @@ -0,0 +1,56 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE_NEW 3 +.Os +.Sh NAME +.Nm archive_write_new +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft struct archive * +.Fn archive_write_new "void" +.Sh DESCRIPTION +Allocates and initializes a +.Tn struct archive +object suitable for writing a tar archive. +.Dv NULL +is returned on error. +.Pp +A complete description of the +.Tn struct archive +object can be found in the overview manual page for +.Xr libarchive 3 . +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open.3 b/Utilities/cmlibarchive/libarchive/archive_write_open.3 new file mode 100644 index 000000000..0d12cb3b3 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_open.3 @@ -0,0 +1,233 @@ +.\" Copyright (c) 2003-2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $ +.\" +.Dd March 23, 2011 +.Dt ARCHIVE_WRITE 3 +.Os +.Sh NAME +.Nm archive_write_open , +.Nm archive_write_open_fd , +.Nm archive_write_open_FILE , +.Nm archive_write_open_filename , +.Nm archive_write_open_memory +.Nd functions for creating archives +.Sh SYNOPSIS +.In archive.h +.Ft int +.Fo archive_write_open +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "archive_open_callback *" +.Fa "archive_write_callback *" +.Fa "archive_close_callback *" +.Fc +.Ft int +.Fn archive_write_open_fd "struct archive *" "int fd" +.Ft int +.Fn archive_write_open_FILE "struct archive *" "FILE *file" +.Ft int +.Fn archive_write_open_filename "struct archive *" "const char *filename" +.Ft int +.Fo archive_write_open_memory +.Fa "struct archive *" +.Fa "void *buffer" +.Fa "size_t bufferSize" +.Fa "size_t *outUsed" +.Fc +.Sh DESCRIPTION +.Bl -tag -width indent +.It Fn archive_write_open +Freeze the settings, open the archive, and prepare for writing entries. +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. +.It Fn archive_write_open_fd +A convenience form of +.Fn archive_write_open +that accepts a file descriptor. +The +.Fn archive_write_open_fd +function is safe for use with tape drives or other +block-oriented devices. +.It Fn archive_write_open_FILE +A convenience form of +.Fn archive_write_open +that accepts a +.Ft "FILE *" +pointer. +Note that +.Fn archive_write_open_FILE +is not safe for writing to tape drives or other devices +that require correct blocking. +.It Fn archive_write_open_file +A deprecated synonym for +.Fn archive_write_open_filename . +.It Fn archive_write_open_filename +A convenience form of +.Fn archive_write_open +that accepts a filename. +A NULL argument indicates that the output should be written to standard output; +an argument of +.Dq - +will open a file with that name. +If you have not invoked +.Fn archive_write_set_bytes_in_last_block , +then +.Fn archive_write_open_filename +will adjust the last-block padding depending on the file: +it will enable padding when writing to standard output or +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 . +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 +that accepts a pointer to a block of memory that will receive +the archive. +The final +.Ft "size_t *" +argument points to a variable that will be updated +after each write to reflect how much of the buffer +is currently in use. +You should be careful to ensure that this variable +remains allocated until after the archive is +closed. +.El +More information about the +.Va struct archive +object and the overall design of the library can be found in the +.Xr libarchive 3 +overview. +.\" +.Sh CLIENT CALLBACKS +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 : +.Bl -item -offset indent +.It +.Ft typedef int +.Fn archive_open_callback "struct archive *" "void *client_data" +.El +.Pp +The open callback is invoked by +.Fn archive_write_open . +It should return +.Cm ARCHIVE_OK +if the underlying file or data source is successfully +opened. +If the open fails, it should call +.Fn archive_set_error +to register an error code and message and return +.Cm ARCHIVE_FATAL . +.Bl -item -offset indent +.It +.Ft typedef ssize_t +.Fo archive_write_callback +.Fa "struct archive *" +.Fa "void *client_data" +.Fa "const void *buffer" +.Fa "size_t length" +.Fc +.El +.Pp +The write callback is invoked whenever the library +needs to write raw bytes to the archive. +For correct blocking, each call to the write callback function +should translate into a single +.Xr write 2 +system call. +This is especially critical when writing archives to tape drives. +On success, the write callback should return the +number of bytes actually written. +On error, the callback should invoke +.Fn archive_set_error +to register an error code and message and return -1. +.Bl -item -offset indent +.It +.Ft typedef int +.Fn archive_close_callback "struct archive *" "void *client_data" +.El +.Pp +The close callback is invoked by archive_close when +the archive processing is complete. +The callback should return +.Cm ARCHIVE_OK +on success. +On failure, the callback should invoke +.Fn archive_set_error +to register an error code and message and +return +.Cm ARCHIVE_FATAL. +.Pp +Note that if the client-provided write callback function +returns a non-zero value, that error will be propagated back to the caller +through whatever API function resulted in that call, which +may include +.Fn archive_write_header , +.Fn archive_write_data , +.Fn archive_write_close , +.Fn archive_write_finish , +or +.Fn archive_write_free . +The client callback can call +.Fn archive_set_error +to provide values that can then be retrieved by +.Fn archive_errno +and +.Fn archive_error_string . +.\" .Sh EXAMPLE +.Sh RETURN VALUES +These functions return +.Cm ARCHIVE_OK +on success, or +.Cm ARCHIVE_FATAL . +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_write 3 , +.Xr archive_write_filter 3 , +.Xr archive_write_format 3 , +.Xr archive_write_new 3 , +.Xr archive_write_set_options 3 , +.Xr cpio 5 , +.Xr mtree 5 , +.Xr tar 5 diff --git a/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c index 1e05bc592..d5c426cf9 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_fd.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_fd.c,v 1.9 2007/01/09 08:05:56 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_open_fd.c 201093 2009-12-28 02:28:44Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -51,93 +51,94 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_fd.c,v 1.9 2007/01/09 #include "archive.h" struct write_fd_data { - off_t offset; - int fd; + int fd; }; -static int file_close(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 file_close(struct archive *, void *); +static int file_open(struct archive *, void *); +static ssize_t file_write(struct archive *, void *, const void *buff, size_t); int archive_write_open_fd(struct archive *a, int fd) { - struct write_fd_data *mine; - - mine = (struct write_fd_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - mine->fd = fd; -#if defined(__CYGWIN__) || defined(__BORLANDC__) - setmode(mine->fd, O_BINARY); -#elif defined(_WIN32) - _setmode(mine->fd, _O_BINARY); + struct write_fd_data *mine; + + mine = (struct write_fd_data *)malloc(sizeof(*mine)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + mine->fd = 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_open(a, mine, + file_open, file_write, file_close)); } static int file_open(struct archive *a, void *client_data) { - struct write_fd_data *mine; - struct stat st; - - mine = (struct write_fd_data *)client_data; - - if (fstat(mine->fd, &st) != 0) { - archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd); - return (ARCHIVE_FATAL); - } - - /* - * If this is a regular file, don't add it to itself. - */ - if (S_ISREG(st.st_mode)) - archive_write_set_skip_file(a, st.st_dev, st.st_ino); - - /* - * If client hasn't explicitly set the last block handling, - * then set it here. - */ - if (archive_write_get_bytes_in_last_block(a) < 0) { - /* If the output is a block or character device, fifo, - * or stdout, pad the last block, otherwise leave it - * unpadded. */ - if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || - S_ISFIFO(st.st_mode) || (mine->fd == 1)) - /* Last block will be fully padded. */ - archive_write_set_bytes_in_last_block(a, 0); - else - archive_write_set_bytes_in_last_block(a, 1); - } - - return (ARCHIVE_OK); + struct write_fd_data *mine; + struct stat st; + + mine = (struct write_fd_data *)client_data; + + if (fstat(mine->fd, &st) != 0) { + archive_set_error(a, errno, "Couldn't stat fd %d", mine->fd); + return (ARCHIVE_FATAL); + } + + /* + * If this is a regular file, don't add it to itself. + */ + if (S_ISREG(st.st_mode)) + archive_write_set_skip_file(a, st.st_dev, st.st_ino); + + /* + * If client hasn't explicitly set the last block handling, + * then set it here. + */ + if (archive_write_get_bytes_in_last_block(a) < 0) { + /* If the output is a block or character device, fifo, + * or stdout, pad the last block, otherwise leave it + * unpadded. */ + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || + S_ISFIFO(st.st_mode) || (mine->fd == 1)) + /* Last block will be fully padded. */ + archive_write_set_bytes_in_last_block(a, 0); + else + archive_write_set_bytes_in_last_block(a, 1); + } + + return (ARCHIVE_OK); } static ssize_t file_write(struct archive *a, void *client_data, const void *buff, size_t length) { - struct write_fd_data *mine; - ssize_t bytesWritten; - - mine = (struct write_fd_data *)client_data; - bytesWritten = write(mine->fd, buff, length); - if (bytesWritten <= 0) { - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); + struct write_fd_data *mine; + ssize_t bytesWritten; + + mine = (struct write_fd_data *)client_data; + for (;;) { + bytesWritten = write(mine->fd, buff, length); + if (bytesWritten <= 0) { + if (errno == EINTR) + continue; + archive_set_error(a, errno, "Write error"); + return (-1); + } + return (bytesWritten); + } } static int file_close(struct archive *a, void *client_data) { - struct write_fd_data *mine = (struct write_fd_data *)client_data; + struct write_fd_data *mine = (struct write_fd_data *)client_data; - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + 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 dcd515f65..f6b141239 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_file.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_file.c @@ -48,58 +48,62 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_file.c,v 1.19 2007/01/ #include "archive.h" struct write_FILE_data { - FILE *f; + FILE *f; }; -static int file_close(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 file_close(struct archive *, void *); +static int file_open(struct archive *, void *); +static ssize_t file_write(struct archive *, void *, const void *buff, size_t); int archive_write_open_FILE(struct archive *a, FILE *f) { - struct write_FILE_data *mine; + struct write_FILE_data *mine; - mine = (struct write_FILE_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - mine->f = f; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); + mine = (struct write_FILE_data *)malloc(sizeof(*mine)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + mine->f = f; + return (archive_write_open(a, mine, + file_open, file_write, file_close)); } static int file_open(struct archive *a, void *client_data) { - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ + (void)a; /* UNUSED */ + (void)client_data; /* UNUSED */ - return (ARCHIVE_OK); + return (ARCHIVE_OK); } static ssize_t file_write(struct archive *a, void *client_data, const void *buff, size_t length) { - struct write_FILE_data *mine; - size_t bytesWritten; + struct write_FILE_data *mine; + size_t bytesWritten; - mine = client_data; - bytesWritten = fwrite(buff, 1, length, mine->f); - if (bytesWritten < length) { - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); + mine = client_data; + for (;;) { + bytesWritten = fwrite(buff, 1, length, mine->f); + if (bytesWritten <= 0) { + if (errno == EINTR) + continue; + archive_set_error(a, errno, "Write error"); + return (-1); + } + return (bytesWritten); + } } static int file_close(struct archive *a, void *client_data) { - struct write_FILE_data *mine = client_data; + struct write_FILE_data *mine = client_data; - (void)a; /* UNUSED */ - free(mine); - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + 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 3c577fae5..868986631 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_filename.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_filename.c,v 1.20 2008/02/19 05:46:58 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_open_filename.c 191165 2009-04-17 00:39:35Z kientzle $"); #ifdef HAVE_SYS_STAT_H #include @@ -46,117 +46,203 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_filename.c,v 1.20 2008 #endif #include "archive.h" +#include "archive_string.h" #ifndef O_BINARY #define O_BINARY 0 #endif struct write_file_data { - int fd; - char filename[1]; + int fd; + char mbs_filename; + union { + char m[1]; + wchar_t w[1]; + } filename; /* Must be last! */ }; -static int file_close(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 file_close(struct archive *, void *); +static int file_open(struct archive *, void *); +static ssize_t file_write(struct archive *, void *, const void *buff, size_t); int archive_write_open_file(struct archive *a, const char *filename) { - return (archive_write_open_filename(a, filename)); + return (archive_write_open_filename(a, filename)); } int archive_write_open_filename(struct archive *a, const char *filename) { - struct write_file_data *mine; - - if (filename == NULL || filename[0] == '\0') - return (archive_write_open_fd(a, 1)); - - mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - strcpy(mine->filename, filename); - mine->fd = -1; - return (archive_write_open(a, mine, - file_open, file_write, file_close)); + struct write_file_data *mine; + + if (filename == NULL || filename[0] == '\0') + return (archive_write_open_fd(a, 1)); + + mine = (struct write_file_data *)malloc(sizeof(*mine) + strlen(filename)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + strcpy(mine->filename.m, filename); + mine->mbs_filename = 1; + mine->fd = -1; + return (archive_write_open(a, mine, + file_open, file_write, file_close)); } +int +archive_write_open_filename_w(struct archive *a, const wchar_t *filename) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + struct write_file_data *mine; + + if (filename == NULL || filename[0] == L'\0') + return (archive_write_open_fd(a, 1)); + + mine = malloc(sizeof(*mine) + wcslen(filename) * sizeof(wchar_t)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + wcscpy(mine->filename.w, filename); + mine->mbs_filename = 0; + mine->fd = -1; + return (archive_write_open(a, mine, + file_open, file_write, file_close)); +#else + /* + * POSIX system does not support a wchar_t interface for + * open() system call, so we have to translate a wchar_t + * filename to multi-byte one and use it. + */ + struct archive_string fn; + int r; + + if (filename == NULL || filename[0] == L'\0') + return (archive_write_open_fd(a, 1)); + + archive_string_init(&fn); + if (archive_string_append_from_wcs(&fn, filename, + wcslen(filename)) != 0) { + archive_set_error(a, EINVAL, + "Failed to convert a wide-character filename to" + " a multi-byte filename"); + archive_string_free(&fn); + return (ARCHIVE_FATAL); + } + r = archive_write_open_filename(a, fn.s); + archive_string_free(&fn); + return (r); +#endif +} + + static int file_open(struct archive *a, void *client_data) { - int flags; - struct write_file_data *mine; - struct stat st; - - mine = (struct write_file_data *)client_data; - flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; - - /* - * Open the file. - */ - mine->fd = open(mine->filename, flags, 0666); - if (mine->fd < 0) { - archive_set_error(a, errno, "Failed to open '%s'", - mine->filename); - return (ARCHIVE_FATAL); - } - - if (fstat(mine->fd, &st) != 0) { - archive_set_error(a, errno, "Couldn't stat '%s'", - mine->filename); - return (ARCHIVE_FATAL); - } - - /* - * Set up default last block handling. - */ - if (archive_write_get_bytes_in_last_block(a) < 0) { - if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || - S_ISFIFO(st.st_mode)) - /* Pad last block when writing to device or FIFO. */ - archive_write_set_bytes_in_last_block(a, 0); - else - /* Don't pad last block otherwise. */ - archive_write_set_bytes_in_last_block(a, 1); - } - - /* - * If the output file is a regular file, don't add it to - * itself. If it's a device file, it's okay to add the device - * entry to the output archive. - */ - if (S_ISREG(st.st_mode)) - archive_write_set_skip_file(a, st.st_dev, st.st_ino); - - return (ARCHIVE_OK); + int flags; + struct write_file_data *mine; + struct stat st; + + mine = (struct write_file_data *)client_data; + flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY; + + /* + * Open the file. + */ + if (mine->mbs_filename) { + mine->fd = open(mine->filename.m, flags, 0666); + if (mine->fd < 0) { + archive_set_error(a, errno, "Failed to open '%s'", + mine->filename.m); + return (ARCHIVE_FATAL); + } + + if (fstat(mine->fd, &st) != 0) { + archive_set_error(a, errno, "Couldn't stat '%s'", + mine->filename.m); + return (ARCHIVE_FATAL); + } + } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + mine->fd = _wopen(mine->filename.w, flags, 0666); + if (mine->fd < 0 && errno == ENOENT) { + wchar_t *fullpath; + fullpath = __la_win_permissive_name_w(mine->filename.w); + if (fullpath != NULL) { + mine->fd = _wopen(fullpath, flags, 0666); + free(fullpath); + } + } + if (mine->fd < 0) { + archive_set_error(a, errno, "Failed to open '%S'", + mine->filename.w); + return (ARCHIVE_FATAL); + } + + if (fstat(mine->fd, &st) != 0) { + archive_set_error(a, errno, "Couldn't stat '%S'", + mine->filename.w); + return (ARCHIVE_FATAL); + } +#else + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Unexpedted operation in archive_write_open_filename"); + return (ARCHIVE_FATAL); +#endif + } + + /* + * Set up default last block handling. + */ + if (archive_write_get_bytes_in_last_block(a) < 0) { + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || + S_ISFIFO(st.st_mode)) + /* Pad last block when writing to device or FIFO. */ + archive_write_set_bytes_in_last_block(a, 0); + else + /* Don't pad last block otherwise. */ + archive_write_set_bytes_in_last_block(a, 1); + } + + /* + * If the output file is a regular file, don't add it to + * itself. If it's a device file, it's okay to add the device + * entry to the output archive. + */ + if (S_ISREG(st.st_mode)) + archive_write_set_skip_file(a, st.st_dev, st.st_ino); + + return (ARCHIVE_OK); } static ssize_t file_write(struct archive *a, void *client_data, const void *buff, size_t length) { - struct write_file_data *mine; - ssize_t bytesWritten; - - mine = (struct write_file_data *)client_data; - bytesWritten = write(mine->fd, buff, length); - if (bytesWritten <= 0) { - archive_set_error(a, errno, "Write error"); - return (-1); - } - return (bytesWritten); + struct write_file_data *mine; + ssize_t bytesWritten; + + mine = (struct write_file_data *)client_data; + for (;;) { + bytesWritten = write(mine->fd, buff, length); + if (bytesWritten <= 0) { + if (errno == EINTR) + continue; + archive_set_error(a, errno, "Write error"); + return (-1); + } + return (bytesWritten); + } } static int file_close(struct archive *a, void *client_data) { - struct write_file_data *mine = (struct write_file_data *)client_data; + struct write_file_data *mine = (struct write_file_data *)client_data; - (void)a; /* UNUSED */ - close(mine->fd); - free(mine); - return (ARCHIVE_OK); + (void)a; /* UNUSED */ + close(mine->fd); + 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 f04bd9aab..4f8d679e5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_open_memory.c @@ -32,28 +32,16 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_open_memory.c,v 1.3 2007/01 #include "archive.h" -/* - * This is a little tricky. I used to allow the - * compression handling layer to fork the compressor, - * which means this write function gets invoked in - * a separate process. That would, of course, make it impossible - * to actually use the data stored into memory here. - * Fortunately, none of the compressors fork today and - * I'm reluctant to use that route in the future but, if - * forking compressors ever do reappear, this will have - * to get a lot more complicated. - */ - struct write_memory_data { - size_t used; - size_t size; - size_t * client_size; - unsigned char * buff; + size_t used; + size_t size; + size_t * client_size; + unsigned char * buff; }; -static int memory_write_close(struct archive *, void *); -static int memory_write_open(struct archive *, void *); -static ssize_t memory_write(struct archive *, void *, const void *buff, size_t); +static int memory_write_close(struct archive *, void *); +static int memory_write_open(struct archive *, void *); +static ssize_t memory_write(struct archive *, void *, const void *buff, size_t); /* * Client provides a pointer to a block of memory to receive @@ -63,33 +51,33 @@ static ssize_t memory_write(struct archive *, void *, const void *buff, size_t) int archive_write_open_memory(struct archive *a, void *buff, size_t buffSize, size_t *used) { - struct write_memory_data *mine; + struct write_memory_data *mine; - mine = (struct write_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buff = buff; - mine->size = buffSize; - mine->client_size = used; - return (archive_write_open(a, mine, - memory_write_open, memory_write, memory_write_close)); + mine = (struct write_memory_data *)malloc(sizeof(*mine)); + if (mine == NULL) { + archive_set_error(a, ENOMEM, "No memory"); + return (ARCHIVE_FATAL); + } + memset(mine, 0, sizeof(*mine)); + mine->buff = buff; + mine->size = buffSize; + mine->client_size = used; + return (archive_write_open(a, mine, + memory_write_open, memory_write, memory_write_close)); } static int memory_write_open(struct archive *a, void *client_data) { - struct write_memory_data *mine; - mine = client_data; - mine->used = 0; - if (mine->client_size != NULL) - *mine->client_size = mine->used; - /* Disable padding if it hasn't been set explicitly. */ - if (-1 == archive_write_get_bytes_in_last_block(a)) - archive_write_set_bytes_in_last_block(a, 1); - return (ARCHIVE_OK); + struct write_memory_data *mine; + mine = client_data; + mine->used = 0; + if (mine->client_size != NULL) + *mine->client_size = mine->used; + /* Disable padding if it hasn't been set explicitly. */ + if (-1 == archive_write_get_bytes_in_last_block(a)) + archive_write_set_bytes_in_last_block(a, 1); + return (ARCHIVE_OK); } /* @@ -101,26 +89,26 @@ memory_write_open(struct archive *a, void *client_data) static ssize_t memory_write(struct archive *a, void *client_data, const void *buff, size_t length) { - struct write_memory_data *mine; - mine = client_data; + struct write_memory_data *mine; + mine = client_data; - if (mine->used + length > mine->size) { - archive_set_error(a, ENOMEM, "Buffer exhausted"); - return (ARCHIVE_FATAL); - } - memcpy(mine->buff + mine->used, buff, length); - mine->used += length; - if (mine->client_size != NULL) - *mine->client_size = mine->used; - return (length); + if (mine->used + length > mine->size) { + archive_set_error(a, ENOMEM, "Buffer exhausted"); + return (ARCHIVE_FATAL); + } + memcpy(mine->buff + mine->used, buff, length); + mine->used += length; + if (mine->client_size != NULL) + *mine->client_size = mine->used; + return (length); } static int memory_write_close(struct archive *a, void *client_data) { - struct write_memory_data *mine; - (void)a; /* UNUSED */ - mine = client_data; - free(mine); - return (ARCHIVE_OK); + struct write_memory_data *mine; + (void)a; /* UNUSED */ + mine = client_data; + free(mine); + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_private.h b/Utilities/cmlibarchive/libarchive/archive_write_private.h index 3cc93a721..91284cf1b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_private.h +++ b/Utilities/cmlibarchive/libarchive/archive_write_private.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/archive_write_private.h,v 1.3 2008/03/15 11:04:45 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD @@ -30,79 +30,92 @@ #endif #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED -#define ARCHIVE_WRITE_PRIVATE_H_INCLUDED +#define ARCHIVE_WRITE_PRIVATE_H_INCLUDED #include "archive.h" #include "archive_string.h" #include "archive_private.h" +struct archive_write; + +struct archive_write_filter { + int64_t bytes_written; + struct archive *archive; /* Associated archive. */ + struct archive_write_filter *next_filter; /* Who I write to. */ + int (*options)(struct archive_write_filter *, + const char *key, const char *value); + int (*open)(struct archive_write_filter *); + int (*write)(struct archive_write_filter *, const void *, size_t); + int (*close)(struct archive_write_filter *); + int (*free)(struct archive_write_filter *); + void *data; + const char *name; + int code; + int bytes_per_block; + int bytes_in_last_block; +}; + +#if ARCHIVE_VERSION < 4000000 +void __archive_write_filters_free(struct archive *); +#endif + +struct archive_write_filter *__archive_write_allocate_filter(struct archive *); + +int __archive_write_output(struct archive_write *, const void *, size_t); +int __archive_write_nulls(struct archive_write *, size_t); +int __archive_write_filter(struct archive_write_filter *, const void *, size_t); +int __archive_write_open_filter(struct archive_write_filter *); +int __archive_write_close_filter(struct archive_write_filter *); + struct archive_write { - struct archive archive; - - /* Dev/ino of the archive being written. */ - dev_t skip_file_dev; - int64_t skip_file_ino; - - /* Utility: Pointer to a block of nulls. */ - const unsigned char *nulls; - size_t null_length; - - /* Callbacks to open/read/write/close archive stream. */ - archive_open_callback *client_opener; - archive_write_callback *client_writer; - archive_close_callback *client_closer; - void *client_data; - - /* - * Blocking information. Note that bytes_in_last_block is - * misleadingly named; I should find a better name. These - * control the final output from all compressors, including - * compression_none. - */ - int bytes_per_block; - int bytes_in_last_block; - - /* - * These control whether data within a gzip/bzip2 compressed - * stream gets padded or not. If pad_uncompressed is set, - * the data will be padded to a full block before being - * compressed. The pad_uncompressed_byte determines the value - * that will be used for padding. Note that these have no - * effect on compression "none." - */ - int pad_uncompressed; - int pad_uncompressed_byte; /* TODO: Support this. */ - - /* - * On write, the client just invokes an archive_write_set function - * which sets up the data here directly. - */ - struct { - void *data; - void *config; - int (*init)(struct archive_write *); - int (*options)(struct archive_write *, - const char *key, const char *value); - int (*finish)(struct archive_write *); - int (*write)(struct archive_write *, const void *, size_t); - } compressor; - - /* - * Pointers to format-specific functions for writing. They're - * initialized by archive_write_set_format_XXX() calls. - */ - void *format_data; - const char *format_name; - int (*format_init)(struct archive_write *); - int (*format_options)(struct archive_write *, - const char *key, const char *value); - int (*format_finish)(struct archive_write *); - int (*format_destroy)(struct archive_write *); - int (*format_finish_entry)(struct archive_write *); - int (*format_write_header)(struct archive_write *, - struct archive_entry *); - ssize_t (*format_write_data)(struct archive_write *, - const void *buff, size_t); + struct archive archive; + + /* Dev/ino of the archive being written. */ + int skip_file_set; + dev_t skip_file_dev; + int64_t skip_file_ino; + + /* Utility: Pointer to a block of nulls. */ + const unsigned char *nulls; + size_t null_length; + + /* Callbacks to open/read/write/close archive stream. */ + archive_open_callback *client_opener; + archive_write_callback *client_writer; + archive_close_callback *client_closer; + void *client_data; + + /* + * Blocking information. Note that bytes_in_last_block is + * misleadingly named; I should find a better name. These + * control the final output from all compressors, including + * compression_none. + */ + int bytes_per_block; + int bytes_in_last_block; + + /* + * First and last write filters in the pipeline. + */ + struct archive_write_filter *filter_first; + struct archive_write_filter *filter_last; + + /* + * Pointers to format-specific functions for writing. They're + * initialized by archive_write_set_format_XXX() calls. + */ + void *format_data; + const char *format_name; + int (*format_init)(struct archive_write *); + int (*format_options)(struct archive_write *, + const char *key, const char *value); + int (*format_finish_entry)(struct archive_write *); + int (*format_write_header)(struct archive_write *, + struct archive_entry *); + ssize_t (*format_write_data)(struct archive_write *, + const void *buff, size_t); + int (*format_close)(struct archive_write *); + int (*format_free)(struct archive_write *); }; /* @@ -117,6 +130,7 @@ struct archive_write { */ int __archive_write_format_header_ustar(struct archive_write *, char buff[512], - struct archive_entry *, int tartype, int strict); + struct archive_entry *, int tartype, int strict, + struct archive_string_conv *); #endif diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_bzip2.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_bzip2.c deleted file mode 100644 index ec5ff428d..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_bzip2.c +++ /dev/null @@ -1,410 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_write_set_compression_bzip2.c,v 1.13 2007/12/30 04:58:21 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_BZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_BZLIB_H -int -archive_write_set_compression_bzip2(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "bzip2 compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have bzlib. */ - -struct private_data { - bz_stream stream; - int64_t total_in; - char *compressed; - size_t compressed_buffer_size; -}; - -struct private_config { - int compression_level; -}; - -/* - * Yuck. bzlib.h is not const-correct, so I need this one bit - * of ugly hackery to convert a const * pointer to a non-const pointer. - */ -#define SET_NEXT_IN(st,src) \ - (st)->stream.next_in = (char *)(uintptr_t)(const void *)(src) - -static int archive_compressor_bzip2_finish(struct archive_write *); -static int archive_compressor_bzip2_init(struct archive_write *); -static int archive_compressor_bzip2_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_bzip2_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - -/* - * Allocate, initialize and return an archive object. - */ -int -archive_write_set_compression_bzip2(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct private_config *config; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_bzip2"); - config = malloc(sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = archive_compressor_bzip2_finish; - config->compression_level = 9; /* default */ - a->compressor.init = &archive_compressor_bzip2_init; - a->compressor.options = &archive_compressor_bzip2_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_BZIP2; - a->archive.compression_name = "bzip2"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_bzip2_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != 0) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (char *)malloc(state->compressed_buffer_size); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - a->compressor.write = archive_compressor_bzip2_write; - - /* Initialize compression library */ - ret = BZ2_bzCompressInit(&(state->stream), - config->compression_level, 0, 30); - if (ret == BZ_OK) { - a->compressor.data = state; - return (ARCHIVE_OK); - } - - /* Library setup failed: clean up. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library"); - free(state->compressed); - free(state); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case BZ_PARAM_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "invalid setup parameter"); - break; - case BZ_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Internal error initializing compression library: " - "out of memory"); - break; - case BZ_CONFIG_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "mis-compiled library"); - break; - } - - return (ARCHIVE_FATAL); - -} - -/* - * Set write options. - */ -static int -archive_compressor_bzip2_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - /* Make '0' be a synonym for '1'. */ - /* This way, bzip2 compressor supports the same 0..9 - * range of levels as gzip. */ - if (config->compression_level < 1) - config->compression_level = 1; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - * - * Returns ARCHIVE_OK if all data written, error otherwise. - */ -static int -archive_compressor_bzip2_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->total_in += length; - - /* Compress input data to output buffer */ - SET_NEXT_IN(state, buff); - state->stream.avail_in = length; - if (drive_compressor(a, state, 0)) - return (ARCHIVE_FATAL); - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression. - */ -static int -archive_compressor_bzip2_finish(struct archive_write *a) -{ - ssize_t block_length; - int ret; - struct private_data *state; - ssize_t target_block_length; - ssize_t bytes_written; - unsigned tocopy; - - ret = ARCHIVE_OK; - state = (struct private_data *)a->compressor.data; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered?\n" - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - SET_NEXT_IN(state, a->nulls); - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle. */ - ret = drive_compressor(a, state, 1); - if (ret) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - target_block_length = block_length; - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - - /* TODO: Handle short write of final block. */ - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else { - a->archive.raw_position += ret; - ret = ARCHIVE_OK; - } - - /* Cleanup: shut down compressor, release memory, etc. */ -cleanup: - switch (BZ2_bzCompressEnd(&(state->stream))) { - case BZ_OK: - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Failed to clean up compressor"); - ret = ARCHIVE_FATAL; - } - - free(state->compressed); - free(state); - } - /* Free configuration data even if we were never fully initialized. */ - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, writing - * full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remainder to - * front and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - - a->archive.raw_position += bytes_written; - state->stream.next_out = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = BZ2_bzCompress(&(state->stream), - finishing ? BZ_FINISH : BZ_RUN); - - switch (ret) { - case BZ_RUN_OK: - /* In non-finishing case, did compressor - * consume everything? */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - break; - case BZ_FINISH_OK: /* Finishing: There's more work to do */ - break; - case BZ_STREAM_END: /* Finishing: all done */ - /* Only occurs in finishing case */ - return (ARCHIVE_OK); - default: - /* Any other return value indicates an error */ - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "Bzip2 compression failed;" - " BZ2_bzCompress() returned %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_BZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_compress.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_compress.c deleted file mode 100644 index 3cc73644f..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_compress.c +++ /dev/null @@ -1,494 +0,0 @@ -/*- - * Copyright (c) 2008 Joerg Sonnenberger - * 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. - */ - -/*- - * Copyright (c) 1985, 1986, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Diomidis Spinellis and James A. Woods, derived from original - * work by Spencer Thomas and Joseph Orost. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "archive_platform.h" - -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_compression_compress.c,v 1.1 2008/03/14 20:35:37 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#define HSIZE 69001 /* 95% occupancy */ -#define HSHIFT 8 /* 8 - trunc(log2(HSIZE / 65536)) */ -#define CHECK_GAP 10000 /* Ratio check interval. */ - -#define MAXCODE(bits) ((1 << (bits)) - 1) - -/* - * the next two codes should not be changed lightly, as they must not - * lie within the contiguous general code space. - */ -#define FIRST 257 /* First free entry. */ -#define CLEAR 256 /* Table clear output code. */ - -struct private_data { - off_t in_count, out_count, checkpoint; - - int code_len; /* Number of bits/code. */ - int cur_maxcode; /* Maximum code, given n_bits. */ - int max_maxcode; /* Should NEVER generate this code. */ - int hashtab [HSIZE]; - unsigned short codetab [HSIZE]; - int first_free; /* First unused entry. */ - int compress_ratio; - - int cur_code, cur_fcode; - - int bit_offset; - unsigned char bit_buf; - - unsigned char *compressed; - size_t compressed_buffer_size; - size_t compressed_offset; -}; - -static int archive_compressor_compress_finish(struct archive_write *); -static int archive_compressor_compress_init(struct archive_write *); -static int archive_compressor_compress_write(struct archive_write *, - const void *, size_t); - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_compress(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_compress"); - a->compressor.init = &archive_compressor_compress_init; - a->archive.compression_code = ARCHIVE_COMPRESSION_COMPRESS; - a->archive.compression_name = "compress"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_compress_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - - a->archive.compression_code = ARCHIVE_COMPRESSION_COMPRESS; - a->archive.compression_name = "compress"; - - if (a->bytes_per_block < 4) { - archive_set_error(&a->archive, EINVAL, - "Can't write Compress header as single block"); - return (ARCHIVE_FATAL); - } - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = malloc(state->compressed_buffer_size); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - a->compressor.write = archive_compressor_compress_write; - a->compressor.finish = archive_compressor_compress_finish; - - state->max_maxcode = 0x10000; /* Should NEVER generate this code. */ - state->in_count = 0; /* Length of input. */ - state->bit_buf = 0; - state->bit_offset = 0; - state->out_count = 3; /* Includes 3-byte header mojo. */ - state->compress_ratio = 0; - state->checkpoint = CHECK_GAP; - state->code_len = 9; - state->cur_maxcode = MAXCODE(state->code_len); - state->first_free = FIRST; - - memset(state->hashtab, 0xff, sizeof(state->hashtab)); - - /* Prime output buffer with a gzip header. */ - state->compressed[0] = 0x1f; /* Compress */ - state->compressed[1] = 0x9d; - state->compressed[2] = 0x90; /* Block mode, 16bit max */ - state->compressed_offset = 3; - - a->compressor.data = state; - return (0); -} - -/*- - * Output the given code. - * Inputs: - * code: A n_bits-bit integer. If == -1, then EOF. This assumes - * that n_bits =< (long)wordsize - 1. - * Outputs: - * Outputs code to the file. - * Assumptions: - * Chars are 8 bits long. - * Algorithm: - * Maintain a BITS character long buffer (so that 8 codes will - * fit in it exactly). Use the VAX insv instruction to insert each - * code in turn. When the buffer fills up empty it and start over. - */ - -static unsigned char rmask[9] = - {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff}; - -static int -output_byte(struct archive_write *a, unsigned char c) -{ - struct private_data *state = a->compressor.data; - ssize_t bytes_written; - - state->compressed[state->compressed_offset++] = c; - ++state->out_count; - - if (state->compressed_buffer_size == state->compressed_offset) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, - state->compressed, state->compressed_buffer_size); - if (bytes_written <= 0) - return ARCHIVE_FATAL; - a->archive.raw_position += bytes_written; - state->compressed_offset = 0; - } - - return ARCHIVE_OK; -} - -static int -output_code(struct archive_write *a, int ocode) -{ - struct private_data *state = a->compressor.data; - int bits, ret, clear_flg, bit_offset; - - clear_flg = ocode == CLEAR; - bits = state->code_len; - - /* - * Since ocode is always >= 8 bits, only need to mask the first - * hunk on the left. - */ - bit_offset = state->bit_offset % 8; - state->bit_buf |= (ocode << bit_offset) & 0xff; - output_byte(a, state->bit_buf); - - bits = state->code_len - (8 - bit_offset); - ocode >>= 8 - bit_offset; - /* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */ - if (bits >= 8) { - output_byte(a, ocode & 0xff); - ocode >>= 8; - bits -= 8; - } - /* Last bits. */ - state->bit_offset += state->code_len; - state->bit_buf = ocode & rmask[bits]; - if (state->bit_offset == state->code_len * 8) - state->bit_offset = 0; - - /* - * If the next entry is going to be too big for the ocode size, - * then increase it, if possible. - */ - if (clear_flg || state->first_free > state->cur_maxcode) { - /* - * Write the whole buffer, because the input side won't - * discover the size increase until after it has read it. - */ - if (state->bit_offset > 0) { - while (state->bit_offset < state->code_len * 8) { - ret = output_byte(a, state->bit_buf); - if (ret != ARCHIVE_OK) - return ret; - state->bit_offset += 8; - state->bit_buf = 0; - } - } - state->bit_buf = 0; - state->bit_offset = 0; - - if (clear_flg) { - state->code_len = 9; - state->cur_maxcode = MAXCODE(state->code_len); - } else { - state->code_len++; - if (state->code_len == 16) - state->cur_maxcode = state->max_maxcode; - else - state->cur_maxcode = MAXCODE(state->code_len); - } - } - - return (ARCHIVE_OK); -} - -static int -output_flush(struct archive_write *a) -{ - struct private_data *state = a->compressor.data; - int ret; - - /* At EOF, write the rest of the buffer. */ - if (state->bit_offset % 8) { - state->code_len = (state->bit_offset % 8 + 7) / 8; - ret = output_byte(a, state->bit_buf); - if (ret != ARCHIVE_OK) - return ret; - } - - return (ARCHIVE_OK); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_compress_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int i; - int ratio; - int c, disp, ret; - const unsigned char *bp; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - if (length == 0) - return ARCHIVE_OK; - - bp = buff; - - if (state->in_count == 0) { - state->cur_code = *bp++; - ++state->in_count; - --length; - } - - while (length--) { - c = *bp++; - state->in_count++; - state->cur_fcode = (c << 16) + state->cur_code; - i = ((c << HSHIFT) ^ state->cur_code); /* Xor hashing. */ - - if (state->hashtab[i] == state->cur_fcode) { - state->cur_code = state->codetab[i]; - continue; - } - if (state->hashtab[i] < 0) /* Empty slot. */ - goto nomatch; - /* Secondary hash (after G. Knott). */ - if (i == 0) - disp = 1; - else - disp = HSIZE - i; - probe: - if ((i -= disp) < 0) - i += HSIZE; - - if (state->hashtab[i] == state->cur_fcode) { - state->cur_code = state->codetab[i]; - continue; - } - if (state->hashtab[i] >= 0) - goto probe; - nomatch: - ret = output_code(a, state->cur_code); - if (ret != ARCHIVE_OK) - return ret; - state->cur_code = c; - if (state->first_free < state->max_maxcode) { - state->codetab[i] = state->first_free++; /* code -> hashtable */ - state->hashtab[i] = state->cur_fcode; - continue; - } - if (state->in_count < state->checkpoint) - continue; - - state->checkpoint = state->in_count + CHECK_GAP; - - if (state->in_count <= 0x007fffff) - ratio = state->in_count * 256 / state->out_count; - else if ((ratio = state->out_count / 256) == 0) - ratio = 0x7fffffff; - else - ratio = state->in_count / ratio; - - if (ratio > state->compress_ratio) - state->compress_ratio = ratio; - else { - state->compress_ratio = 0; - memset(state->hashtab, 0xff, sizeof(state->hashtab)); - state->first_free = FIRST; - ret = output_code(a, CLEAR); - if (ret != ARCHIVE_OK) - return ret; - } - } - - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_compress_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - unsigned tocopy; - - state = (struct private_data *)a->compressor.data; - ret = 0; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - while (state->in_count % a->bytes_per_block != 0) { - tocopy = a->bytes_per_block - - (state->in_count % a->bytes_per_block); - if (tocopy > a->null_length) - tocopy = a->null_length; - ret = archive_compressor_compress_write(a, a->nulls, - tocopy); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - ret = output_code(a, state->cur_code); - if (ret != ARCHIVE_OK) - goto cleanup; - ret = output_flush(a); - if (ret != ARCHIVE_OK) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->compressed_offset; - - /* Tricky calculation to determine size of last block. */ - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->compressed + state->compressed_offset, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else - a->archive.raw_position += bytes_written; - -cleanup: - free(state->compressed); - free(state); - return (ret); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_gzip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_gzip.c deleted file mode 100644 index 17a637824..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_gzip.c +++ /dev/null @@ -1,478 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_write_set_compression_gzip.c,v 1.16 2008/02/21 03:21:50 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_ZLIB_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_ZLIB_H -int -archive_write_set_compression_gzip(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "gzip compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have zlib. */ - -struct private_data { - z_stream stream; - int64_t total_in; - unsigned char *compressed; - size_t compressed_buffer_size; - unsigned long crc; -}; - -struct private_config { - int compression_level; -}; - - -/* - * Yuck. zlib.h is not const-correct, so I need this one bit - * of ugly hackery to convert a const * pointer to a non-const pointer. - */ -#define SET_NEXT_IN(st,src) \ - (st)->stream.next_in = (Bytef *)(uintptr_t)(const void *)(src) - -static int archive_compressor_gzip_finish(struct archive_write *); -static int archive_compressor_gzip_init(struct archive_write *); -static int archive_compressor_gzip_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_gzip_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_gzip(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - struct private_config *config; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_gzip"); - config = malloc(sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = &archive_compressor_gzip_finish; - config->compression_level = Z_DEFAULT_COMPRESSION; - a->compressor.init = &archive_compressor_gzip_init; - a->compressor.options = &archive_compressor_gzip_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_GZIP; - a->archive.compression_name = "gzip"; - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_gzip_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - time_t t; - - config = (struct private_config *)a->compressor.config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - /* - * The next check is a temporary workaround until the gzip - * code can be overhauled some. The code should not require - * that compressed_buffer_size == bytes_per_block. Removing - * this assumption will allow us to compress larger chunks at - * a time, which should improve overall performance - * marginally. As a minor side-effect, such a cleanup would - * allow us to support truly arbitrary block sizes. - */ - if (a->bytes_per_block < 10) { - archive_set_error(&a->archive, EINVAL, - "GZip compressor requires a minimum 10 byte block size"); - return (ARCHIVE_FATAL); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - /* - * See comment above. We should set compressed_buffer_size to - * max(bytes_per_block, 65536), but the code can't handle that yet. - */ - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (unsigned char *)malloc(state->compressed_buffer_size); - state->crc = crc32(0L, NULL, 0); - - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - - /* Prime output buffer with a gzip header. */ - t = time(NULL); - state->compressed[0] = 0x1f; /* GZip signature bytes */ - state->compressed[1] = 0x8b; - state->compressed[2] = 0x08; /* "Deflate" compression */ - state->compressed[3] = 0; /* No options */ - state->compressed[4] = (t)&0xff; /* Timestamp */ - state->compressed[5] = (t>>8)&0xff; - state->compressed[6] = (t>>16)&0xff; - state->compressed[7] = (t>>24)&0xff; - state->compressed[8] = 0; /* No deflate options */ - state->compressed[9] = 3; /* OS=Unix */ - state->stream.next_out += 10; - state->stream.avail_out -= 10; - - a->compressor.write = archive_compressor_gzip_write; - - /* Initialize compression library. */ - ret = deflateInit2(&(state->stream), - config->compression_level, - Z_DEFLATED, - -15 /* < 0 to suppress zlib header */, - 8, - Z_DEFAULT_STRATEGY); - - if (ret == Z_OK) { - a->compressor.data = state; - return (0); - } - - /* Library setup failed: clean up. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal error " - "initializing compression library"); - free(state->compressed); - free(state); - - /* Override the error message if we know what really went wrong. */ - switch (ret) { - case Z_STREAM_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: invalid setup parameter"); - break; - case Z_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, "Internal error initializing " - "compression library"); - break; - case Z_VERSION_ERROR: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing " - "compression library: invalid library version"); - break; - } - - return (ARCHIVE_FATAL); -} - -/* - * Set write options. - */ -static int -archive_compressor_gzip_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_gzip_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->crc = crc32(state->crc, (const Bytef *)buff, length); - state->total_in += length; - - /* Compress input data to output buffer */ - SET_NEXT_IN(state, buff); - state->stream.avail_in = length; - if ((ret = drive_compressor(a, state, 0)) != ARCHIVE_OK) - return (ret); - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - -/* - * Finish the compression... - */ -static int -archive_compressor_gzip_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - unsigned tocopy; - unsigned char trailer[8]; - - state = (struct private_data *)a->compressor.data; - ret = 0; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - SET_NEXT_IN(state, a->nulls); - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->crc = crc32(state->crc, a->nulls, - state->stream.avail_in); - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle */ - if (((ret = drive_compressor(a, state, 1))) != ARCHIVE_OK) - goto cleanup; - - /* Build trailer: 4-byte CRC and 4-byte length. */ - trailer[0] = (state->crc)&0xff; - trailer[1] = (state->crc >> 8)&0xff; - trailer[2] = (state->crc >> 16)&0xff; - trailer[3] = (state->crc >> 24)&0xff; - trailer[4] = (state->total_in)&0xff; - trailer[5] = (state->total_in >> 8)&0xff; - trailer[6] = (state->total_in >> 16)&0xff; - trailer[7] = (state->total_in >> 24)&0xff; - - /* Add trailer to current block. */ - tocopy = 8; - if (tocopy > state->stream.avail_out) - tocopy = state->stream.avail_out; - memcpy(state->stream.next_out, trailer, tocopy); - state->stream.next_out += tocopy; - state->stream.avail_out -= tocopy; - - /* If it overflowed, flush and start a new block. */ - if (tocopy < 8) { - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, state->compressed_buffer_size); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - memcpy(state->stream.next_out, trailer + tocopy, 8-tocopy); - state->stream.next_out += 8-tocopy; - state->stream.avail_out -= 8-tocopy; - } - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - target_block_length = block_length; - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - - /* Cleanup: shut down compressor, release memory, etc. */ - cleanup: - switch (deflateEnd(&(state->stream))) { - case Z_OK: - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Failed to clean up compressor"); - ret = ARCHIVE_FATAL; - } - free(state->compressed); - free(state); - } - /* Clean up config area even if we never initialized. */ - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, - * writing full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remaining to - * front of block and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - a->archive.raw_position += bytes_written; - state->stream.next_out - = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = deflate(&(state->stream), - finishing ? Z_FINISH : Z_NO_FLUSH ); - - switch (ret) { - case Z_OK: - /* In non-finishing case, check if compressor - * consumed everything */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - /* In finishing case, this return always means - * there's more work */ - break; - case Z_STREAM_END: - /* This return can only occur in finishing case. */ - return (ARCHIVE_OK); - default: - /* Any other return value indicates an error. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "GZip compression failed:" - " deflate() call returned status %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_ZLIB_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_none.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_none.c deleted file mode 100644 index f27d629a1..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_none.c +++ /dev/null @@ -1,259 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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: src/lib/libarchive/archive_write_set_compression_none.c,v 1.16 2007/12/30 04:58:22 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -static int archive_compressor_none_finish(struct archive_write *a); -static int archive_compressor_none_init(struct archive_write *); -static int archive_compressor_none_write(struct archive_write *, - const void *, size_t); - -struct archive_none { - char *buffer; - ssize_t buffer_size; - char *next; /* Current insert location */ - ssize_t avail; /* Free space left in buffer */ -}; - -int -archive_write_set_compression_none(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_none"); - a->compressor.init = &archive_compressor_none_init; - return (0); -} - -/* - * Setup callback. - */ -static int -archive_compressor_none_init(struct archive_write *a) -{ - int ret; - struct archive_none *state; - - a->archive.compression_code = ARCHIVE_COMPRESSION_NONE; - a->archive.compression_name = "none"; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != 0) - return (ret); - } - - state = (struct archive_none *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for output buffering"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - state->buffer_size = a->bytes_per_block; - if (state->buffer_size != 0) { - state->buffer = (char *)malloc(state->buffer_size); - if (state->buffer == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate output buffer"); - free(state); - return (ARCHIVE_FATAL); - } - } - - state->next = state->buffer; - state->avail = state->buffer_size; - - a->compressor.data = state; - a->compressor.write = archive_compressor_none_write; - a->compressor.finish = archive_compressor_none_finish; - return (ARCHIVE_OK); -} - -/* - * Write data to the stream. - */ -static int -archive_compressor_none_write(struct archive_write *a, const void *vbuff, - size_t length) -{ - const char *buff; - ssize_t remaining, to_copy; - ssize_t bytes_written; - struct archive_none *state; - - state = (struct archive_none *)a->compressor.data; - buff = (const char *)vbuff; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - remaining = length; - - /* - * If there is no buffer for blocking, just pass the data - * straight through to the client write callback. In - * particular, this supports "no write delay" operation for - * special applications. Just set the block size to zero. - */ - if (state->buffer_size == 0) { - while (remaining > 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, remaining); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - a->archive.raw_position += bytes_written; - remaining -= bytes_written; - buff += bytes_written; - } - a->archive.file_position += length; - return (ARCHIVE_OK); - } - - /* If the copy buffer isn't empty, try to fill it. */ - if (state->avail < state->buffer_size) { - /* If buffer is not empty... */ - /* ... copy data into buffer ... */ - to_copy = (remaining > state->avail) ? - state->avail : remaining; - memcpy(state->next, buff, to_copy); - state->next += to_copy; - state->avail -= to_copy; - buff += to_copy; - remaining -= to_copy; - /* ... if it's full, write it out. */ - if (state->avail == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->buffer, state->buffer_size); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - /* XXX TODO: if bytes_written < state->buffer_size */ - a->archive.raw_position += bytes_written; - state->next = state->buffer; - state->avail = state->buffer_size; - } - } - - while (remaining > state->buffer_size) { - /* Write out full blocks directly to client. */ - bytes_written = (a->client_writer)(&a->archive, - a->client_data, buff, state->buffer_size); - if (bytes_written <= 0) - return (ARCHIVE_FATAL); - a->archive.raw_position += bytes_written; - buff += bytes_written; - remaining -= bytes_written; - } - - if (remaining > 0) { - /* Copy last bit into copy buffer. */ - memcpy(state->next, buff, remaining); - state->next += remaining; - state->avail -= remaining; - } - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression. - */ -static int -archive_compressor_none_finish(struct archive_write *a) -{ - ssize_t block_length; - ssize_t target_block_length; - ssize_t bytes_written; - int ret; - int ret2; - struct archive_none *state; - - state = (struct archive_none *)a->compressor.data; - ret = ret2 = ARCHIVE_OK; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* If there's pending data, pad and write the last block */ - if (state->next != state->buffer) { - block_length = state->buffer_size - state->avail; - - /* Tricky calculation to determine size of last block */ - target_block_length = block_length; - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->next, 0, - target_block_length - block_length); - block_length = target_block_length; - } - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->buffer, block_length); - if (bytes_written <= 0) - ret = ARCHIVE_FATAL; - else { - a->archive.raw_position += bytes_written; - ret = ARCHIVE_OK; - } - } - if (state->buffer) - free(state->buffer); - free(state); - a->compressor.data = NULL; - - return (ret); -} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_program.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_program.c deleted file mode 100644 index e9f995273..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_program.c +++ /dev/null @@ -1,349 +0,0 @@ -/*- - * Copyright (c) 2007 Joerg Sonnenberger - * 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: src/lib/libarchive/archive_write_set_compression_program.c,v 1.3 2008/06/15 10:45:57 kientzle Exp $"); - -/* This capability is only available on POSIX systems. */ -#if (!defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ - !(defined(HAVE_FORK) || defined(HAVE_VFORK))) && (!defined(_WIN32) || defined(__CYGWIN__)) -#include "archive.h" - -/* - * On non-Posix systems, allow the program to build, but choke if - * this function is actually invoked. - */ -int -archive_write_set_compression_program(struct archive *_a, const char *cmd) -{ - archive_set_error(_a, -1, - "External compression programs not supported on this platform"); - return (ARCHIVE_FATAL); -} - -#else - -#ifdef HAVE_SYS_WAIT_H -# include -#endif -#ifdef HAVE_ERRNO_H -# include -#endif -#ifdef HAVE_FCNTL_H -# include -#endif -#ifdef HAVE_STDLIB_H -# include -#endif -#ifdef HAVE_STRING_H -# include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#include "filter_fork.h" - -struct private_data { - char *description; - pid_t child; - int child_stdin, child_stdout; - - char *child_buf; - size_t child_buf_len, child_buf_avail; -}; - -static int archive_compressor_program_finish(struct archive_write *); -static int archive_compressor_program_init(struct archive_write *); -static int archive_compressor_program_write(struct archive_write *, - const void *, size_t); - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_program(struct archive *_a, const char *cmd) -{ - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_program"); - a->compressor.init = &archive_compressor_program_init; - a->compressor.config = strdup(cmd); - return (ARCHIVE_OK); -} - -/* - * Setup callback. - */ -static int -archive_compressor_program_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - static const char *prefix = "Program: "; - char *cmd = a->compressor.config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - - a->archive.compression_code = ARCHIVE_COMPRESSION_PROGRAM; - state->description = (char *)malloc(strlen(prefix) + strlen(cmd) + 1); - strcpy(state->description, prefix); - strcat(state->description, cmd); - a->archive.compression_name = state->description; - - state->child_buf_len = a->bytes_per_block; - state->child_buf_avail = 0; - state->child_buf = malloc(state->child_buf_len); - - if (state->child_buf == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - - if ((state->child = __archive_create_child(cmd, - &state->child_stdin, &state->child_stdout)) == -1) { - archive_set_error(&a->archive, EINVAL, - "Can't initialise filter"); - free(state->child_buf); - free(state); - return (ARCHIVE_FATAL); - } - - a->compressor.write = archive_compressor_program_write; - a->compressor.finish = archive_compressor_program_finish; - - a->compressor.data = state; - return (0); -} - -static ssize_t -child_write(struct archive_write *a, const char *buf, size_t buf_len) -{ - struct private_data *state = a->compressor.data; - ssize_t ret; - - if (state->child_stdin == -1) - return (-1); - - if (buf_len == 0) - return (-1); - -restart_write: - do { - ret = write(state->child_stdin, buf, buf_len); - } while (ret == -1 && errno == EINTR); - - if (ret > 0) - return (ret); - if (ret == 0) { - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - return (0); - } - if (ret == -1 && errno != EAGAIN) - return (-1); - - if (state->child_stdout == -1) { - fcntl(state->child_stdin, F_SETFL, 0); - __archive_check_child(state->child_stdin, state->child_stdout); - goto restart_write; - } - - do { - ret = read(state->child_stdout, - state->child_buf + state->child_buf_avail, - state->child_buf_len - state->child_buf_avail); - } while (ret == -1 && errno == EINTR); - - if (ret == 0 || (ret == -1 && errno == EPIPE)) { - close(state->child_stdout); - state->child_stdout = -1; - fcntl(state->child_stdin, F_SETFL, 0); - goto restart_write; - } - if (ret == -1 && errno == EAGAIN) { - __archive_check_child(state->child_stdin, state->child_stdout); - goto restart_write; - } - if (ret == -1) - return (-1); - - state->child_buf_avail += ret; - - ret = (a->client_writer)(&a->archive, a->client_data, - state->child_buf, state->child_buf_avail); - if (ret <= 0) - return (-1); - - if ((size_t)ret < state->child_buf_avail) { - memmove(state->child_buf, state->child_buf + ret, - state->child_buf_avail - ret); - } - state->child_buf_avail -= ret; - a->archive.raw_position += ret; - goto restart_write; -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_program_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - ssize_t ret; - const char *buf; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - buf = buff; - while (length > 0) { - ret = child_write(a, buf, length); - if (ret == -1 || ret == 0) { - archive_set_error(&a->archive, EIO, - "Can't write to filter"); - return (ARCHIVE_FATAL); - } - length -= ret; - buf += ret; - } - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_program_finish(struct archive_write *a) -{ - int ret, status; - ssize_t bytes_read, bytes_written; - struct private_data *state; - - state = (struct private_data *)a->compressor.data; - ret = 0; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* XXX pad compressed data. */ - - close(state->child_stdin); - state->child_stdin = -1; - fcntl(state->child_stdout, F_SETFL, 0); - - for (;;) { - do { - bytes_read = read(state->child_stdout, - state->child_buf + state->child_buf_avail, - state->child_buf_len - state->child_buf_avail); - } while (bytes_read == -1 && errno == EINTR); - - if (bytes_read == 0 || (bytes_read == -1 && errno == EPIPE)) - break; - - if (bytes_read == -1) { - archive_set_error(&a->archive, errno, - "Read from filter failed unexpectedly."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - state->child_buf_avail += bytes_read; - - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->child_buf, state->child_buf_avail); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - if ((size_t)bytes_written < state->child_buf_avail) { - memmove(state->child_buf, - state->child_buf + bytes_written, - state->child_buf_avail - bytes_written); - } - state->child_buf_avail -= bytes_written; - a->archive.raw_position += bytes_written; - } - - /* XXX pad final compressed block. */ - -cleanup: - /* Shut down the child. */ - if (state->child_stdin != -1) - close(state->child_stdin); - if (state->child_stdout != -1) - close(state->child_stdout); - while (waitpid(state->child, &status, 0) == -1 && errno == EINTR) - continue; - - if (status != 0) { - archive_set_error(&a->archive, EIO, - "Filter exited with failure."); - ret = ARCHIVE_FATAL; - } - - /* Release our configuration data. */ - free(a->compressor.config); - a->compressor.config = NULL; - - /* Release our private state data. */ - free(state->child_buf); - free(state->description); - free(state); - return (ret); -} - -#endif /* !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_xz.c b/Utilities/cmlibarchive/libarchive/archive_write_set_compression_xz.c deleted file mode 100644 index 3883b4062..000000000 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_compression_xz.c +++ /dev/null @@ -1,439 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * 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$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#include -#ifdef HAVE_LZMA_H -#include -#endif - -#include "archive.h" -#include "archive_private.h" -#include "archive_write_private.h" - -#ifndef HAVE_LZMA_H -int -archive_write_set_compression_xz(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "xz compression not supported on this platform"); - return (ARCHIVE_FATAL); -} - -int -archive_write_set_compression_lzma(struct archive *a) -{ - archive_set_error(a, ARCHIVE_ERRNO_MISC, - "lzma compression not supported on this platform"); - return (ARCHIVE_FATAL); -} -#else -/* Don't compile this if we don't have liblzma. */ - -struct private_data { - lzma_stream stream; - lzma_filter lzmafilters[2]; - lzma_options_lzma lzma_opt; - int64_t total_in; - unsigned char *compressed; - size_t compressed_buffer_size; -}; - -struct private_config { - int compression_level; -}; - -static int archive_compressor_xz_init(struct archive_write *); -static int archive_compressor_xz_options(struct archive_write *, - const char *, const char *); -static int archive_compressor_xz_finish(struct archive_write *); -static int archive_compressor_xz_write(struct archive_write *, - const void *, size_t); -static int drive_compressor(struct archive_write *, struct private_data *, - int finishing); - - -/* - * Allocate, initialize and return a archive object. - */ -int -archive_write_set_compression_xz(struct archive *_a) -{ - struct private_config *config; - struct archive_write *a = (struct archive_write *)_a; - __archive_check_magic(&a->archive, ARCHIVE_WRITE_MAGIC, - ARCHIVE_STATE_NEW, "archive_write_set_compression_xz"); - config = calloc(1, sizeof(*config)); - if (config == NULL) { - archive_set_error(&a->archive, ENOMEM, "Out of memory"); - return (ARCHIVE_FATAL); - } - a->compressor.config = config; - a->compressor.finish = archive_compressor_xz_finish; - config->compression_level = LZMA_PRESET_DEFAULT; - a->compressor.init = &archive_compressor_xz_init; - a->compressor.options = &archive_compressor_xz_options; - a->archive.compression_code = ARCHIVE_COMPRESSION_XZ; - a->archive.compression_name = "xz"; - return (ARCHIVE_OK); -} - -/* LZMA is handled identically, we just need a different compression - * code set. (The liblzma setup looks at the code to determine - * the one place that XZ and LZMA require different handling.) */ -int -archive_write_set_compression_lzma(struct archive *_a) -{ - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_compression_xz(_a); - if (r != ARCHIVE_OK) - return (r); - a->archive.compression_code = ARCHIVE_COMPRESSION_LZMA; - a->archive.compression_name = "lzma"; - return (ARCHIVE_OK); -} - -static int -archive_compressor_xz_init_stream(struct archive_write *a, - struct private_data *state) -{ - int ret; - - state->stream = (lzma_stream)LZMA_STREAM_INIT; - state->stream.next_out = state->compressed; - state->stream.avail_out = state->compressed_buffer_size; - if (a->archive.compression_code == ARCHIVE_COMPRESSION_XZ) - ret = lzma_stream_encoder(&(state->stream), - state->lzmafilters, LZMA_CHECK_CRC64); - else - ret = lzma_alone_encoder(&(state->stream), &state->lzma_opt); - if (ret == LZMA_OK) - return (ARCHIVE_OK); - - switch (ret) { - case LZMA_MEM_ERROR: - archive_set_error(&a->archive, ENOMEM, - "Internal error initializing compression library: " - "Cannot allocate memory"); - break; - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library: " - "It's a bug in liblzma"); - break; - } - return (ARCHIVE_FATAL); -} - -/* - * Setup callback. - */ -static int -archive_compressor_xz_init(struct archive_write *a) -{ - int ret; - struct private_data *state; - struct private_config *config; - - if (a->client_opener != NULL) { - ret = (a->client_opener)(&a->archive, a->client_data); - if (ret != ARCHIVE_OK) - return (ret); - } - - state = (struct private_data *)malloc(sizeof(*state)); - if (state == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression"); - return (ARCHIVE_FATAL); - } - memset(state, 0, sizeof(*state)); - config = a->compressor.config; - - /* - * See comment above. We should set compressed_buffer_size to - * max(bytes_per_block, 65536), but the code can't handle that yet. - */ - state->compressed_buffer_size = a->bytes_per_block; - state->compressed = (unsigned char *)malloc(state->compressed_buffer_size); - if (state->compressed == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate data for compression buffer"); - free(state); - return (ARCHIVE_FATAL); - } - a->compressor.write = archive_compressor_xz_write; - - /* Initialize compression library. */ - if (lzma_lzma_preset(&state->lzma_opt, config->compression_level)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Internal error initializing compression library"); - free(state->compressed); - free(state); - } - state->lzmafilters[0].id = LZMA_FILTER_LZMA2; - state->lzmafilters[0].options = &state->lzma_opt; - state->lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ - ret = archive_compressor_xz_init_stream(a, state); - if (ret == LZMA_OK) { - a->compressor.data = state; - return (0); - } - /* Library setup failed: clean up. */ - free(state->compressed); - free(state); - - return (ARCHIVE_FATAL); -} - -/* - * Set write options. - */ -static int -archive_compressor_xz_options(struct archive_write *a, const char *key, - const char *value) -{ - struct private_config *config; - - config = (struct private_config *)a->compressor.config; - if (strcmp(key, "compression-level") == 0) { - if (value == NULL || !(value[0] >= '0' && value[0] <= '9') || - value[1] != '\0') - return (ARCHIVE_WARN); - config->compression_level = value[0] - '0'; - if (config->compression_level > 6) - config->compression_level = 6; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); -} - -/* - * Write data to the compressed stream. - */ -static int -archive_compressor_xz_write(struct archive_write *a, const void *buff, - size_t length) -{ - struct private_data *state; - int ret; - - state = (struct private_data *)a->compressor.data; - if (a->client_writer == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - return (ARCHIVE_FATAL); - } - - /* Update statistics */ - state->total_in += length; - - /* Compress input data to output buffer */ - state->stream.next_in = buff; - state->stream.avail_in = length; - if ((ret = drive_compressor(a, state, 0)) != ARCHIVE_OK) - return (ret); - - a->archive.file_position += length; - return (ARCHIVE_OK); -} - - -/* - * Finish the compression... - */ -static int -archive_compressor_xz_finish(struct archive_write *a) -{ - ssize_t block_length, target_block_length, bytes_written; - int ret; - struct private_data *state; - unsigned tocopy; - - ret = ARCHIVE_OK; - state = (struct private_data *)a->compressor.data; - if (state != NULL) { - if (a->client_writer == NULL) { - archive_set_error(&a->archive, - ARCHIVE_ERRNO_PROGRAMMER, - "No write callback is registered? " - "This is probably an internal programming error."); - ret = ARCHIVE_FATAL; - goto cleanup; - } - - /* By default, always pad the uncompressed data. */ - if (a->pad_uncompressed) { - tocopy = a->bytes_per_block - - (state->total_in % a->bytes_per_block); - while (tocopy > 0 && tocopy < (unsigned)a->bytes_per_block) { - state->stream.next_in = a->nulls; - state->stream.avail_in = tocopy < a->null_length ? - tocopy : a->null_length; - state->total_in += state->stream.avail_in; - tocopy -= state->stream.avail_in; - ret = drive_compressor(a, state, 0); - if (ret != ARCHIVE_OK) - goto cleanup; - } - } - - /* Finish compression cycle */ - if (((ret = drive_compressor(a, state, 1))) != ARCHIVE_OK) - goto cleanup; - - /* Optionally, pad the final compressed block. */ - block_length = state->stream.next_out - state->compressed; - - /* Tricky calculation to determine size of last block. */ - target_block_length = block_length; - if (a->bytes_in_last_block <= 0) - /* Default or Zero: pad to full block */ - target_block_length = a->bytes_per_block; - else - /* Round length to next multiple of bytes_in_last_block. */ - target_block_length = a->bytes_in_last_block * - ( (block_length + a->bytes_in_last_block - 1) / - a->bytes_in_last_block); - if (target_block_length > a->bytes_per_block) - target_block_length = a->bytes_per_block; - if (block_length < target_block_length) { - memset(state->stream.next_out, 0, - target_block_length - block_length); - block_length = target_block_length; - } - - /* Write the last block */ - bytes_written = (a->client_writer)(&a->archive, a->client_data, - state->compressed, block_length); - if (bytes_written <= 0) { - ret = ARCHIVE_FATAL; - goto cleanup; - } - a->archive.raw_position += bytes_written; - - /* Cleanup: shut down compressor, release memory, etc. */ - cleanup: - lzma_end(&(state->stream)); - free(state->compressed); - free(state); - } - free(a->compressor.config); - a->compressor.config = NULL; - return (ret); -} - -/* - * Utility function to push input data through compressor, - * writing full output blocks as necessary. - * - * Note that this handles both the regular write case (finishing == - * false) and the end-of-archive case (finishing == true). - */ -static int -drive_compressor(struct archive_write *a, struct private_data *state, int finishing) -{ - ssize_t bytes_written; - int ret; - - for (;;) { - if (state->stream.avail_out == 0) { - bytes_written = (a->client_writer)(&a->archive, - a->client_data, state->compressed, - state->compressed_buffer_size); - if (bytes_written <= 0) { - /* TODO: Handle this write failure */ - return (ARCHIVE_FATAL); - } else if ((size_t)bytes_written < state->compressed_buffer_size) { - /* Short write: Move remaining to - * front of block and keep filling */ - memmove(state->compressed, - state->compressed + bytes_written, - state->compressed_buffer_size - bytes_written); - } - a->archive.raw_position += bytes_written; - state->stream.next_out - = state->compressed + - state->compressed_buffer_size - bytes_written; - state->stream.avail_out = bytes_written; - } - - /* If there's nothing to do, we're done. */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - - ret = lzma_code(&(state->stream), - finishing ? LZMA_FINISH : LZMA_RUN ); - - switch (ret) { - case LZMA_OK: - /* In non-finishing case, check if compressor - * consumed everything */ - if (!finishing && state->stream.avail_in == 0) - return (ARCHIVE_OK); - /* In finishing case, this return always means - * there's more work */ - break; - case LZMA_STREAM_END: - /* This return can only occur in finishing case. */ - if (finishing) - return (ARCHIVE_OK); - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "lzma compression data error"); - return (ARCHIVE_FATAL); - case LZMA_MEMLIMIT_ERROR: - archive_set_error(&a->archive, ENOMEM, - "lzma compression error: " - "%ju MiB would have been needed", - (lzma_memusage(&(state->stream)) + 1024 * 1024 -1) - / (1024 * 1024)); - return (ARCHIVE_FATAL); - default: - /* Any other return value indicates an error. */ - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "lzma compression failed:" - " lzma_code() call returned status %d", - ret); - return (ARCHIVE_FATAL); - } - } -} - -#endif /* HAVE_LZMA_H */ diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c index c2088f667..641d56f6c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format.c,v 1.6 2008/08/31 07:21:46 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -41,32 +41,36 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format.c,v 1.6 2008/08/ static struct { int code; int (*setter)(struct archive *); } codes[] = { - { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio }, - { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc }, - { ARCHIVE_FORMAT_CPIO_POSIX, archive_write_set_format_cpio }, - { ARCHIVE_FORMAT_MTREE, archive_write_set_format_mtree }, - { ARCHIVE_FORMAT_SHAR, archive_write_set_format_shar }, - { ARCHIVE_FORMAT_SHAR_BASE, archive_write_set_format_shar }, - { ARCHIVE_FORMAT_SHAR_DUMP, archive_write_set_format_shar_dump }, - { ARCHIVE_FORMAT_TAR, archive_write_set_format_pax_restricted }, - { ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax }, - { ARCHIVE_FORMAT_TAR_PAX_RESTRICTED, - archive_write_set_format_pax_restricted }, - { ARCHIVE_FORMAT_TAR_USTAR, archive_write_set_format_ustar }, - { ARCHIVE_FORMAT_ZIP, archive_write_set_format_zip }, - { 0, NULL } + { ARCHIVE_FORMAT_7ZIP, archive_write_set_format_7zip }, + { ARCHIVE_FORMAT_CPIO, archive_write_set_format_cpio }, + { ARCHIVE_FORMAT_CPIO_POSIX, archive_write_set_format_cpio }, + { ARCHIVE_FORMAT_CPIO_SVR4_NOCRC, archive_write_set_format_cpio_newc }, + { ARCHIVE_FORMAT_ISO9660, archive_write_set_format_iso9660 }, + { ARCHIVE_FORMAT_MTREE, archive_write_set_format_mtree }, + { ARCHIVE_FORMAT_SHAR, archive_write_set_format_shar }, + { ARCHIVE_FORMAT_SHAR_BASE, archive_write_set_format_shar }, + { ARCHIVE_FORMAT_SHAR_DUMP, archive_write_set_format_shar_dump }, + { ARCHIVE_FORMAT_TAR, archive_write_set_format_pax_restricted }, + { ARCHIVE_FORMAT_TAR_GNUTAR, archive_write_set_format_gnutar }, + { ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE, archive_write_set_format_pax }, + { ARCHIVE_FORMAT_TAR_PAX_RESTRICTED, + archive_write_set_format_pax_restricted }, + { ARCHIVE_FORMAT_TAR_USTAR, archive_write_set_format_ustar }, + { ARCHIVE_FORMAT_XAR, archive_write_set_format_xar }, + { ARCHIVE_FORMAT_ZIP, archive_write_set_format_zip }, + { 0, NULL } }; int archive_write_set_format(struct archive *a, int code) { - int i; + int i; - for (i = 0; codes[i].code != 0; i++) { - if (code == codes[i].code) - return ((codes[i].setter)(a)); - } + for (i = 0; codes[i].code != 0; i++) { + if (code == codes[i].code) + return ((codes[i].setter)(a)); + } - archive_set_error(a, EINVAL, "No such format"); - return (ARCHIVE_FATAL); + archive_set_error(a, EINVAL, "No such format"); + return (ARCHIVE_FATAL); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c new file mode 100644 index 000000000..5bb248c55 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_7zip.c @@ -0,0 +1,2303 @@ +/*- + * Copyright (c) 2011 Michihiro NAKAJIMA + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_BZLIB_H +#include +#endif +#if HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#ifndef HAVE_ZLIB_H +#include "archive_crc32.h" +#endif +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_ppmd7_private.h" +#include "archive_private.h" +#include "archive_rb.h" +#include "archive_string.h" +#include "archive_write_private.h" + +/* + * Codec ID + */ +#define _7Z_COPY 0 +#define _7Z_LZMA1 0x030101 +#define _7Z_LZMA2 0x21 +#define _7Z_DEFLATE 0x040108 +#define _7Z_BZIP2 0x040202 +#define _7Z_PPMD 0x030401 + +/* + * 7-Zip header property IDs. + */ +#define kEnd 0x00 +#define kHeader 0x01 +#define kArchiveProperties 0x02 +#define kAdditionalStreamsInfo 0x03 +#define kMainStreamsInfo 0x04 +#define kFilesInfo 0x05 +#define kPackInfo 0x06 +#define kUnPackInfo 0x07 +#define kSubStreamsInfo 0x08 +#define kSize 0x09 +#define kCRC 0x0A +#define kFolder 0x0B +#define kCodersUnPackSize 0x0C +#define kNumUnPackStream 0x0D +#define kEmptyStream 0x0E +#define kEmptyFile 0x0F +#define kAnti 0x10 +#define kName 0x11 +#define kCTime 0x12 +#define kATime 0x13 +#define kMTime 0x14 +#define kAttributes 0x15 +#define kEncodedHeader 0x17 + +enum la_zaction { + ARCHIVE_Z_FINISH, + ARCHIVE_Z_RUN +}; + +/* + * A stream object of universal compressor. + */ +struct la_zstream { + const uint8_t *next_in; + size_t avail_in; + uint64_t total_in; + + uint8_t *next_out; + size_t avail_out; + uint64_t total_out; + + uint32_t prop_size; + uint8_t *props; + + int valid; + void *real_stream; + int (*code) (struct archive *a, + struct la_zstream *lastrm, + enum la_zaction action); + int (*end)(struct archive *a, + struct la_zstream *lastrm); +}; + +#define PPMD7_DEFAULT_ORDER 6 +#define PPMD7_DEFAULT_MEM_SIZE (1 << 24) + +struct ppmd_stream { + int stat; + CPpmd7 ppmd7_context; + CPpmd7z_RangeEnc range_enc; + IByteOut byteout; + uint8_t *buff; + uint8_t *buff_ptr; + uint8_t *buff_end; + size_t buff_bytes; +}; + +struct coder { + unsigned codec; + size_t prop_size; + uint8_t *props; +}; + +struct file { + struct archive_rb_node rbnode; + + struct file *next; + unsigned name_len; + uint8_t *utf16name;/* UTF16-LE name. */ + uint64_t size; + unsigned flg; +#define MTIME_IS_SET (1<<0) +#define ATIME_IS_SET (1<<1) +#define CTIME_IS_SET (1<<2) +#define CRC32_IS_SET (1<<3) +#define HAS_STREAM (1<<4) + + struct { + time_t time; + long time_ns; + } times[3]; +#define MTIME 0 +#define ATIME 1 +#define CTIME 2 + + mode_t mode; + uint32_t crc32; + + int dir:1; +}; + +struct _7zip { + int temp_fd; + uint64_t temp_offset; + + struct file *cur_file; + size_t total_number_entry; + size_t total_number_nonempty_entry; + size_t total_number_empty_entry; + size_t total_number_dir_entry; + size_t total_bytes_entry_name; + size_t total_number_time_defined[3]; + uint64_t total_bytes_compressed; + uint64_t total_bytes_uncompressed; + uint64_t entry_bytes_remaining; + uint32_t entry_crc32; + uint32_t precode_crc32; + uint32_t encoded_crc32; + int crc32flg; +#define PRECODE_CRC32 1 +#define ENCODED_CRC32 2 + + unsigned opt_compression; + int opt_compression_level; + + struct la_zstream stream; + struct coder coder; + + struct archive_string_conv *sconv; + + /* + * Compressed data buffer. + */ + unsigned char wbuff[1024 * 64]; + size_t wbuff_remaining; + + /* + * The list of the file entries which has its contents is used to + * manage struct file objects. + * We use 'next' a menber of struct file to chain. + */ + struct { + struct file *first; + struct file **last; + } file_list, empty_list; + struct archive_rb_tree rbtree;/* for empty files */ +}; + +static int _7z_options(struct archive_write *, + const char *, const char *); +static int _7z_write_header(struct archive_write *, + struct archive_entry *); +static ssize_t _7z_write_data(struct archive_write *, + const void *, size_t); +static int _7z_finish_entry(struct archive_write *); +static int _7z_close(struct archive_write *); +static int _7z_free(struct archive_write *); +static int file_cmp_node(const struct archive_rb_node *, + const struct archive_rb_node *); +static int file_cmp_key(const struct archive_rb_node *, const void *); +static int file_new(struct archive_write *a, struct archive_entry *, + struct file **); +static void file_free(struct file *); +static void file_register(struct _7zip *, struct file *); +static void file_register_empty(struct _7zip *, struct file *); +static void file_init_register(struct _7zip *); +static void file_init_register_empty(struct _7zip *); +static void file_free_register(struct _7zip *); +static ssize_t compress_out(struct archive_write *, const void *, size_t , + enum la_zaction); +static int compression_init_encoder_copy(struct archive *, + struct la_zstream *); +static int compression_code_copy(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_copy(struct archive *, struct la_zstream *); +static int compression_init_encoder_deflate(struct archive *, + struct la_zstream *, int, int); +#ifdef HAVE_ZLIB_H +static int compression_code_deflate(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_deflate(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_bzip2(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int compression_code_bzip2(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_bzip2(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_lzma1(struct archive *, + struct la_zstream *, int); +static int compression_init_encoder_lzma2(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_LZMA_H) +static int compression_code_lzma(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_lzma(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_ppmd(struct archive *, + struct la_zstream *, unsigned, uint32_t); +static int compression_code_ppmd(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_ppmd(struct archive *, struct la_zstream *); +static int _7z_compression_init_encoder(struct archive_write *, unsigned, + int); +static int compression_code(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end(struct archive *, + struct la_zstream *); +static int enc_uint64(struct archive_write *, uint64_t); +static int make_header(struct archive_write *, uint64_t, uint64_t, + uint64_t, int, struct coder *); +static int make_streamsInfo(struct archive_write *, uint64_t, uint64_t, + uint64_t, int, struct coder *, int, uint32_t); + +int +archive_write_set_format_7zip(struct archive *_a) +{ + static const struct archive_rb_tree_ops rb_ops = { + file_cmp_node, file_cmp_key + }; + struct archive_write *a = (struct archive_write *)_a; + struct _7zip *zip; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_7zip"); + + /* If another format was already registered, unregister it. */ + if (a->format_free != NULL) + (a->format_free)(a); + + zip = calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate 7-Zip data"); + return (ARCHIVE_FATAL); + } + zip->temp_fd = -1; + __archive_rb_tree_init(&(zip->rbtree), &rb_ops); + file_init_register(zip); + file_init_register_empty(zip); + + /* Set default compression type and its level. */ +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA1; +#elif defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + zip->opt_compression = _7Z_BZIP2; +#elif defined(HAVE_ZLIB_H) + zip->opt_compression = _7Z_DEFLATE; +#else + zip->opt_compression = _7Z_COPY; +#endif + zip->opt_compression_level = 6; + + a->format_data = zip; + + a->format_name = "7zip"; + a->format_options = _7z_options; + a->format_write_header = _7z_write_header; + a->format_write_data = _7z_write_data; + a->format_finish_entry = _7z_finish_entry; + a->format_close = _7z_close; + a->format_free = _7z_free; + a->archive.archive_format = ARCHIVE_FORMAT_7ZIP; + a->archive.archive_format_name = "7zip"; + + return (ARCHIVE_OK); +} + +static int +_7z_options(struct archive_write *a, const char *key, const char *value) +{ + struct _7zip *zip; + + zip = (struct _7zip *)a->format_data; + + if (strcmp(key, "compression") == 0) { + const char *name = NULL; + + if (value == NULL || strcmp(value, "copy") == 0 || + strcmp(value, "COPY") == 0 || + strcmp(value, "store") == 0 || + strcmp(value, "STORE") == 0) + zip->opt_compression = _7Z_COPY; + else if (strcmp(value, "deflate") == 0 || + strcmp(value, "DEFLATE") == 0) +#if HAVE_ZLIB_H + zip->opt_compression = _7Z_DEFLATE; +#else + name = "deflate"; +#endif + else if (strcmp(value, "bzip2") == 0 || + strcmp(value, "BZIP2") == 0) +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + zip->opt_compression = _7Z_BZIP2; +#else + name = "bzip2"; +#endif + else if (strcmp(value, "lzma1") == 0 || + strcmp(value, "LZMA1") == 0) +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA1; +#else + name = "lzma1"; +#endif + else if (strcmp(value, "lzma2") == 0 || + strcmp(value, "LZMA2") == 0) +#if HAVE_LZMA_H + zip->opt_compression = _7Z_LZMA2; +#else + name = "lzma2"; +#endif + else if (strcmp(value, "ppmd") == 0 || + strcmp(value, "PPMD") == 0 || + strcmp(value, "PPMd") == 0) + zip->opt_compression = _7Z_PPMD; + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unkonwn compression name: `%s'", + value); + return (ARCHIVE_FAILED); + } + if (name != NULL) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "`%s' compression not supported " + "on this platform", + name); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); + } + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || + !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Illeagal value `%s'", + value); + return (ARCHIVE_FAILED); + } + zip->opt_compression_level = value[0] - '0'; + return (ARCHIVE_OK); + } + + return (ARCHIVE_FAILED); +} + +static int +_7z_write_header(struct archive_write *a, struct archive_entry *entry) +{ + struct _7zip *zip; + struct file *file; + int r; + + zip = (struct _7zip *)a->format_data; + zip->cur_file = NULL; + zip->entry_bytes_remaining = 0; + + if (zip->sconv == NULL) { + zip->sconv = archive_string_conversion_to_charset( + &a->archive, "UTF-16LE", 1); + if (zip->sconv == NULL) + return (ARCHIVE_FATAL); + } + + r = file_new(a, entry, &file); + if (r < ARCHIVE_WARN) { + file_free(file); + return (r); + } + + if (file->flg & MTIME_IS_SET) + zip->total_number_time_defined[MTIME]++; + if (file->flg & CTIME_IS_SET) + zip->total_number_time_defined[CTIME]++; + if (file->flg & ATIME_IS_SET) + zip->total_number_time_defined[ATIME]++; + + if (file->size == 0 && file->dir) { + if (!__archive_rb_tree_insert_node(&(zip->rbtree), + (struct archive_rb_node *)file)) + file_free(file); + } + zip->total_number_entry++; + zip->total_bytes_entry_name += file->name_len + 2; + if (file->size == 0) { + /* Count up the number of empty files. */ + zip->total_number_empty_entry++; + if (file->dir) + zip->total_number_dir_entry++; + else + file_register_empty(zip, file); + return (r); + } + + /* + * Init compression. + */ + if ((zip->total_number_entry - zip->total_number_empty_entry) == 1) { + r = _7z_compression_init_encoder(a, zip->opt_compression, + zip->opt_compression_level); + if (r < 0) { + file_free(file); + return (ARCHIVE_FATAL); + } + } + + /* Register a non-empty file. */ + file_register(zip, file); + + /* + * Set the current file to cur_file to read its contents. + */ + zip->cur_file = file; + + + /* Save a offset of current file in temporary file. */ + zip->entry_bytes_remaining = file->size; + zip->entry_crc32 = 0; + + /* + * Store a symbolic link name as file contents. + */ + if (archive_entry_filetype(entry) == AE_IFLNK) { + ssize_t bytes; + const void *p = (const void *)archive_entry_symlink(entry); + bytes = compress_out(a, p, file->size, ARCHIVE_Z_RUN); + if (bytes < 0) + return ((int)bytes); + zip->entry_crc32 = crc32(zip->entry_crc32, p, bytes); + zip->entry_bytes_remaining -= bytes; + } + + return (r); +} + +/* + * Write data to a temporary file. + */ +static int +write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + struct _7zip *zip; + unsigned char *p; + ssize_t ws; + + zip = (struct _7zip *)a->format_data; + + /* + * Open a temporary file. + */ + if (zip->temp_fd == -1) { + zip->temp_offset = 0; + zip->temp_fd = __archive_mktemp(NULL); + if (zip->temp_fd < 0) { + archive_set_error(&a->archive, errno, + "Couldn't create temporary file"); + return (ARCHIVE_FATAL); + } + } + + p = (unsigned char *)buff; + while (s) { + ws = write(zip->temp_fd, p, s); + if (ws < 0) { + archive_set_error(&(a->archive), errno, + "fwrite function failed"); + return (ARCHIVE_FATAL); + } + s -= ws; + p += ws; + zip->temp_offset += ws; + } + return (ARCHIVE_OK); +} + +static ssize_t +compress_out(struct archive_write *a, const void *buff, size_t s, + enum la_zaction run) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + int r; + + if (run == ARCHIVE_Z_FINISH && zip->stream.total_in == 0 && s == 0) + return (0); + + if ((zip->crc32flg & PRECODE_CRC32) && s) + zip->precode_crc32 = crc32(zip->precode_crc32, buff, s); + zip->stream.next_in = (const unsigned char *)buff; + zip->stream.avail_in = s; + do { + /* Compress file data. */ + r = compression_code(&(a->archive), &(zip->stream), run); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) + return (ARCHIVE_FATAL); + if (zip->stream.avail_out == 0) { + if (write_to_temp(a, zip->wbuff, sizeof(zip->wbuff)) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->stream.next_out = zip->wbuff; + zip->stream.avail_out = sizeof(zip->wbuff); + if (zip->crc32flg & ENCODED_CRC32) + zip->encoded_crc32 = crc32(zip->encoded_crc32, + zip->wbuff, sizeof(zip->wbuff)); + } + } while (zip->stream.avail_in); + if (run == ARCHIVE_Z_FINISH) { + uint64_t bytes = sizeof(zip->wbuff) - zip->stream.avail_out; + if (write_to_temp(a, zip->wbuff, bytes) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if ((zip->crc32flg & ENCODED_CRC32) && bytes) + zip->encoded_crc32 = crc32(zip->encoded_crc32, + zip->wbuff, bytes); + } + + return (s); +} + +static ssize_t +_7z_write_data(struct archive_write *a, const void *buff, size_t s) +{ + struct _7zip *zip; + ssize_t bytes; + + zip = (struct _7zip *)a->format_data; + + if (s > zip->entry_bytes_remaining) + s = zip->entry_bytes_remaining; + if (s == 0 || zip->cur_file == NULL) + return (0); + bytes = compress_out(a, buff, s, ARCHIVE_Z_RUN); + if (bytes < 0) + return (bytes); + zip->entry_crc32 = crc32(zip->entry_crc32, buff, bytes); + zip->entry_bytes_remaining -= bytes; + return (bytes); +} + +static int +_7z_finish_entry(struct archive_write *a) +{ + struct _7zip *zip; + size_t s; + ssize_t r; + + zip = (struct _7zip *)a->format_data; + if (zip->cur_file == NULL) + return (ARCHIVE_OK); + + while (zip->entry_bytes_remaining > 0) { + s = zip->entry_bytes_remaining; + if (s > a->null_length) + s = a->null_length; + r = _7z_write_data(a, a->nulls, s); + if (r < 0) + return (r); + } + zip->total_bytes_compressed += zip->stream.total_in; + zip->total_bytes_uncompressed += zip->stream.total_out; + zip->cur_file->crc32 = zip->entry_crc32; + zip->cur_file = NULL; + + return (ARCHIVE_OK); +} + +static int +flush_wbuff(struct archive_write *a) +{ + struct _7zip *zip; + int r; + size_t s; + + zip = (struct _7zip *)a->format_data; + s = sizeof(zip->wbuff) - zip->wbuff_remaining; + r = __archive_write_output(a, zip->wbuff, s); + if (r != ARCHIVE_OK) + return (r); + zip->wbuff_remaining = sizeof(zip->wbuff); + return (r); +} + +static int +copy_out(struct archive_write *a, uint64_t offset, uint64_t length) +{ + struct _7zip *zip; + int r; + + zip = (struct _7zip *)a->format_data; + if (zip->temp_offset > 0 && + lseek(zip->temp_fd, offset, SEEK_SET) < 0) { + archive_set_error(&(a->archive), errno, "lseek failed"); + return (ARCHIVE_FATAL); + } + while (length) { + size_t rsize; + ssize_t rs; + unsigned char *wb; + + if (length > zip->wbuff_remaining) + rsize = zip->wbuff_remaining; + else + rsize = (size_t)length; + wb = zip->wbuff + (sizeof(zip->wbuff) - zip->wbuff_remaining); + rs = read(zip->temp_fd, wb, rsize); + if (rs < 0) { + archive_set_error(&(a->archive), errno, + "Can't read temporary file(%jd)", + (intmax_t)rs); + return (ARCHIVE_FATAL); + } + if (rs == 0) { + archive_set_error(&(a->archive), 0, + "Truncated 7-Zip archive"); + return (ARCHIVE_FATAL); + } + zip->wbuff_remaining -= rs; + length -= rs; + if (zip->wbuff_remaining == 0) { + r = flush_wbuff(a); + if (r != ARCHIVE_OK) + return (r); + } + } + return (ARCHIVE_OK); +} + +static int +_7z_close(struct archive_write *a) +{ + struct _7zip *zip; + unsigned char *wb; + uint64_t header_offset, header_size, header_unpacksize; + uint64_t length; + uint32_t header_crc32; + int r; + + zip = (struct _7zip *)a->format_data; + + if (zip->total_number_entry > 0) { + struct archive_rb_node *n; + uint64_t data_offset, data_size, data_unpacksize; + unsigned header_compression; + + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + data_offset = 0; + data_size = zip->stream.total_out; + data_unpacksize = zip->stream.total_in; + zip->coder.codec = zip->opt_compression; + zip->coder.prop_size = zip->stream.prop_size; + zip->coder.props = zip->stream.props; + zip->stream.prop_size = 0; + zip->stream.props = NULL; + zip->total_number_nonempty_entry = + zip->total_number_entry - zip->total_number_empty_entry; + + /* Connect an empty file list. */ + *zip->file_list.last = zip->empty_list.first; + zip->file_list.last = zip->empty_list.last; + /* Connect a directory file list. */ + ARCHIVE_RB_TREE_FOREACH(n, &(zip->rbtree)) { + file_register(zip, (struct file *)n); + } + + /* + * NOTE: 7z command supports just LZMA1, LZMA2 and COPY for + * the compression type for encoding the header. + */ +#if HAVE_LZMA_H + header_compression = _7Z_LZMA1; + /* If the stored file is only one, do not encode the header. + * This is the same way 7z command does. */ + if (zip->total_number_entry == 1) + header_compression = _7Z_COPY; +#else + header_compression = _7Z_COPY; +#endif + r = _7z_compression_init_encoder(a, header_compression, 6); + if (r < 0) + return (r); + zip->crc32flg = PRECODE_CRC32; + zip->precode_crc32 = 0; + r = make_header(a, data_offset, data_size, data_unpacksize, + 1, &(zip->coder)); + if (r < 0) + return (r); + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + header_offset = data_offset + data_size; + header_size = zip->stream.total_out; + header_crc32 = zip->precode_crc32; + header_unpacksize = zip->stream.total_in; + + if (header_compression != _7Z_COPY) { + /* + * Encode the header in order to reduce the size + * of the archive. + */ + free(zip->coder.props); + zip->coder.codec = header_compression; + zip->coder.prop_size = zip->stream.prop_size; + zip->coder.props = zip->stream.props; + zip->stream.prop_size = 0; + zip->stream.props = NULL; + + r = _7z_compression_init_encoder(a, _7Z_COPY, 0); + if (r < 0) + return (r); + zip->crc32flg = ENCODED_CRC32; + zip->encoded_crc32 = 0; + + /* + * Make EncodedHeader. + */ + r = enc_uint64(a, kEncodedHeader); + if (r < 0) + return (r); + r = make_streamsInfo(a, header_offset, header_size, + header_unpacksize, 1, &(zip->coder), 0, + header_crc32); + if (r < 0) + return (r); + r = (int)compress_out(a, NULL, 0, ARCHIVE_Z_FINISH); + if (r < 0) + return (r); + header_offset = header_offset + header_size; + header_size = zip->stream.total_out; + header_crc32 = zip->encoded_crc32; + } + zip->crc32flg = 0; + } else { + header_offset = header_size = 0; + header_crc32 = 0; + } + + length = zip->temp_offset; + + /* + * Make the zip header on wbuff(write buffer). + */ + wb = zip->wbuff; + zip->wbuff_remaining = sizeof(zip->wbuff); + memcpy(&wb[0], "7z\xBC\xAF\x27\x1C", 6); + wb[6] = 0;/* Major version. */ + wb[7] = 3;/* Minor version. */ + archive_le64enc(&wb[12], header_offset);/* Next Header Offset */ + archive_le64enc(&wb[20], header_size);/* Next Header Size */ + archive_le32enc(&wb[28], header_crc32);/* Next Header CRC */ + archive_le32enc(&wb[8], crc32(0, &wb[12], 20));/* Start Header CRC */ + zip->wbuff_remaining -= 32; + + /* + * Read all file contents and an encoded header from the temporary + * file and write out it. + */ + r = copy_out(a, 0, length); + if (r != ARCHIVE_OK) + return (r); + r = flush_wbuff(a); + return (r); +} + +/* + * Encode 64 bits value into 7-Zip's encoded UINT64 value. + */ +static int +enc_uint64(struct archive_write *a, uint64_t val) +{ + unsigned mask = 0x80; + uint8_t numdata[9]; + int i; + + numdata[0] = 0; + for (i = 1; i < sizeof(numdata); i++) { + if (val < mask) { + numdata[0] |= (uint8_t)val; + break; + } + numdata[i] = (uint8_t)val; + val >>= 8; + numdata[0] |= mask; + mask >>= 1; + } + return (compress_out(a, numdata, i, ARCHIVE_Z_RUN)); +} + +static int +make_substreamsInfo(struct archive_write *a, struct coder *coders) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + + /* + * Make SubStreamsInfo. + */ + r = enc_uint64(a, kSubStreamsInfo); + if (r < 0) + return (r); + + if (zip->total_number_nonempty_entry > 1 && coders->codec != _7Z_COPY) { + /* + * Make NumUnPackStream. + */ + r = enc_uint64(a, kNumUnPackStream); + if (r < 0) + return (r); + + /* Write numUnpackStreams */ + r = enc_uint64(a, zip->total_number_nonempty_entry); + if (r < 0) + return (r); + + /* + * Make kSize. + */ + r = enc_uint64(a, kSize); + if (r < 0) + return (r); + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->next == NULL || + file->next->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + } + + /* + * Make CRC. + */ + r = enc_uint64(a, kCRC); + if (r < 0) + return (r); + + + /* All are defined */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + uint8_t crc[4]; + if (file->size == 0) + break; + archive_le32enc(crc, file->crc32); + r = compress_out(a, crc, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + return (ARCHIVE_OK); +} + +static int +make_streamsInfo(struct archive_write *a, uint64_t offset, uint64_t pack_size, + uint64_t unpack_size, int num_coder, struct coder *coders, int substrm, + uint32_t header_crc) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + uint8_t codec_buff[8]; + int numFolders, fi; + int codec_size; + int i, r; + + if (coders->codec == _7Z_COPY) + numFolders = zip->total_number_nonempty_entry; + else + numFolders = 1; + + /* + * Make PackInfo. + */ + r = enc_uint64(a, kPackInfo); + if (r < 0) + return (r); + + /* Write PackPos. */ + r = enc_uint64(a, offset); + if (r < 0) + return (r); + + /* Write NumPackStreams. */ + r = enc_uint64(a, numFolders); + if (r < 0) + return (r); + + /* Make Size. */ + r = enc_uint64(a, kSize); + if (r < 0) + return (r); + + if (numFolders > 1) { + struct file *file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + } else { + /* Write size. */ + r = enc_uint64(a, pack_size); + if (r < 0) + return (r); + } + + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + /* + * Make UnPackInfo. + */ + r = enc_uint64(a, kUnPackInfo); + if (r < 0) + return (r); + + /* + * Make Folder. + */ + r = enc_uint64(a, kFolder); + if (r < 0) + return (r); + + /* Write NumFolders. */ + r = enc_uint64(a, numFolders); + if (r < 0) + return (r); + + /* Write External. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + for (fi = 0; fi < numFolders; fi++) { + /* Write NumCoders. */ + r = enc_uint64(a, num_coder); + if (r < 0) + return (r); + + for (i = 0; i < num_coder; i++) { + unsigned codec_id = coders[i].codec; + + /* Write Codec flag. */ + archive_be64enc(codec_buff, codec_id); + for (codec_size = 8; codec_size > 0; codec_size--) { + if (codec_buff[8 - codec_size]) + break; + } + if (codec_size == 0) + codec_size = 1; + if (coders[i].prop_size) + r = enc_uint64(a, codec_size | 0x20); + else + r = enc_uint64(a, codec_size); + if (r < 0) + return (r); + + /* Write Codec ID. */ + codec_size &= 0x0f; + r = compress_out(a, &codec_buff[8-codec_size], + codec_size, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + + if (coders[i].prop_size) { + /* Write Codec property size. */ + r = enc_uint64(a, coders[i].prop_size); + if (r < 0) + return (r); + + /* Write Codec properties. */ + r = compress_out(a, coders[i].props, + coders[i].prop_size, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + } + + /* + * Make CodersUnPackSize. + */ + r = enc_uint64(a, kCodersUnPackSize); + if (r < 0) + return (r); + + if (numFolders > 1) { + struct file *file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + break; + r = enc_uint64(a, file->size); + if (r < 0) + return (r); + } + + } else { + /* Write UnPackSize. */ + r = enc_uint64(a, unpack_size); + if (r < 0) + return (r); + } + + if (!substrm) { + uint8_t crc[4]; + /* + * Make CRC. + */ + r = enc_uint64(a, kCRC); + if (r < 0) + return (r); + + /* All are defined */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + archive_le32enc(crc, header_crc); + r = compress_out(a, crc, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + if (substrm) { + /* + * Make SubStreamsInfo. + */ + r = make_substreamsInfo(a, coders); + if (r < 0) + return (r); + } + + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + return (ARCHIVE_OK); +} + + +#define EPOC_TIME ARCHIVE_LITERAL_ULL(116444736000000000) +static uint64_t +utcToFiletime(time_t time, long ns) +{ + uint64_t fileTime; + + fileTime = time; + fileTime *= 10000000; + fileTime += ns / 100; + fileTime += EPOC_TIME; + return (fileTime); +} + +static int +make_time(struct archive_write *a, uint8_t type, unsigned flg, int ti) +{ + uint8_t filetime[8]; + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + uint8_t mask, byte; + + /* + * Make Time Bools. + */ + if (zip->total_number_time_defined[ti] == zip->total_number_entry) { + /* Write Time Type. */ + r = enc_uint64(a, type); + if (r < 0) + return (r); + /* Write EmptyStream Size. */ + r = enc_uint64(a, 2 + zip->total_number_entry * 8); + if (r < 0) + return (r); + /* All are defined. */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + } else { + if (zip->total_number_time_defined[ti] == 0) + return (ARCHIVE_OK); + + /* Write Time Type. */ + r = enc_uint64(a, type); + if (r < 0) + return (r); + /* Write EmptyStream Size. */ + r = enc_uint64(a, 2 + ((zip->total_number_entry + 7) >> 3) + + zip->total_number_time_defined[ti] * 8); + if (r < 0) + return (r); + + /* All are not defined. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + byte = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->flg & flg) + byte |= mask; + mask >>= 1; + if (mask == 0) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + byte = 0; + } + } + if (mask != 0x80) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + /* External. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + + /* + * Make Times. + */ + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if ((file->flg & flg) == 0) + continue; + archive_le64enc(filetime, utcToFiletime(file->times[ti].time, + file->times[ti].time_ns)); + r = compress_out(a, filetime, 8, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + return (ARCHIVE_OK); +} + +static int +make_header(struct archive_write *a, uint64_t offset, uint64_t pack_size, + uint64_t unpack_size, int codernum, struct coder *coders) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + struct file *file; + int r; + uint8_t mask, byte; + + /* + * Make FilesInfo. + */ + r = enc_uint64(a, kHeader); + if (r < 0) + return (r); + + /* + * If there are empty files only, do not write MainStreamInfo. + */ + if (zip->total_number_nonempty_entry) { + /* + * Make MainStreamInfo. + */ + r = enc_uint64(a, kMainStreamsInfo); + if (r < 0) + return (r); + r = make_streamsInfo(a, offset, pack_size, unpack_size, + codernum, coders, 1, 0); + if (r < 0) + return (r); + } + + /* + * Make FilesInfo. + */ + r = enc_uint64(a, kFilesInfo); + if (r < 0) + return (r); + + /* Write numFiles. */ + r = enc_uint64(a, zip->total_number_entry); + if (r < 0) + return (r); + + if (zip->total_number_empty_entry > 0) { + /* Make EmptyStream. */ + r = enc_uint64(a, kEmptyStream); + if (r < 0) + return (r); + + /* Write EmptyStream Size. */ + r = enc_uint64(a, (zip->total_number_entry+7)>>3); + if (r < 0) + return (r); + + byte = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size == 0) + byte |= mask; + mask >>= 1; + if (mask == 0) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + byte = 0; + } + } + if (mask != 0x80) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + if (zip->total_number_empty_entry > zip->total_number_dir_entry) { + /* Make EmptyFile. */ + r = enc_uint64(a, kEmptyFile); + if (r < 0) + return (r); + + /* Write EmptyFile Size. */ + r = enc_uint64(a, (zip->total_number_empty_entry + 7) >> 3); + if (r < 0) + return (r); + + byte = 0; + mask = 0x80; + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + if (file->size) + continue; + if (!file->dir) + byte |= mask; + mask >>= 1; + if (mask == 0) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + mask = 0x80; + byte = 0; + } + } + if (mask != 0x80) { + r = compress_out(a, &byte, 1, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + } + + /* Make Name. */ + r = enc_uint64(a, kName); + if (r < 0) + return (r); + + /* Write Nume size. */ + r = enc_uint64(a, zip->total_bytes_entry_name+1); + if (r < 0) + return (r); + + /* Write dmy byte. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + r = compress_out(a, file->utf16name, file->name_len+2, + ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Make MTime. */ + r = make_time(a, kMTime, MTIME_IS_SET, MTIME); + if (r < 0) + return (r); + + /* Make CTime. */ + r = make_time(a, kCTime, CTIME_IS_SET, CTIME); + if (r < 0) + return (r); + + /* Make ATime. */ + r = make_time(a, kATime, ATIME_IS_SET, ATIME); + if (r < 0) + return (r); + + /* Make Attributes. */ + r = enc_uint64(a, kAttributes); + if (r < 0) + return (r); + + /* Write Attributes size. */ + r = enc_uint64(a, 2 + zip->total_number_entry * 4); + if (r < 0) + return (r); + + /* Write "All Are Defined". */ + r = enc_uint64(a, 1); + if (r < 0) + return (r); + + /* Write dmy byte. */ + r = enc_uint64(a, 0); + if (r < 0) + return (r); + + file = zip->file_list.first; + for (;file != NULL; file = file->next) { + /* + * High 16bits is unix mode. + * Low 16bits is Windows attributes. + */ + uint32_t encattr, attr; + if (file->dir) + attr = 0x8010; + else + attr = 0x8020; + if ((file->mode & 0222) == 0) + attr |= 1;/* Read Only. */ + attr |= ((uint32_t)file->mode) << 16; + archive_le32enc(&encattr, attr); + r = compress_out(a, &encattr, 4, ARCHIVE_Z_RUN); + if (r < 0) + return (r); + } + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + /* Write End. */ + r = enc_uint64(a, kEnd); + if (r < 0) + return (r); + + return (ARCHIVE_OK); +} + + +static int +_7z_free(struct archive_write *a) +{ + struct _7zip *zip = (struct _7zip *)a->format_data; + + file_free_register(zip); + compression_end(&(a->archive), &(zip->stream)); + free(zip->coder.props); + free(zip); + + return (ARCHIVE_OK); +} + +static int +file_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + struct file *f1 = (struct file *)n1; + struct file *f2 = (struct file *)n2; + + if (f1->name_len == f2->name_len) + return (memcmp(f1->utf16name, f2->utf16name, f1->name_len)); + return (f1->name_len > f2->name_len)?1:-1; +} + +static int +file_cmp_key(const struct archive_rb_node *n, const void *key) +{ + struct file *f = (struct file *)n; + + return (f->name_len - *(const char *)key); +} + +static int +file_new(struct archive_write *a, struct archive_entry *entry, + struct file **newfile) +{ + struct _7zip *zip; + struct file *file; + const char *u16; + size_t u16len; + int ret = ARCHIVE_OK; + + zip = (struct _7zip *)a->format_data; + *newfile = NULL; + + file = calloc(1, sizeof(*file)); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + + if (0 > archive_entry_pathname_l(entry, &u16, &u16len, zip->sconv)) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for UTF-16LE"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "A filename cannot be converted to UTF-16LE;" + "You should disable making Joliet extension"); + ret = ARCHIVE_WARN; + } + file->utf16name = malloc(u16len + 2); + if (file->utf16name == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Name"); + return (ARCHIVE_FATAL); + } + memcpy(file->utf16name, u16, u16len); + file->utf16name[u16len+0] = 0; + file->utf16name[u16len+1] = 0; + file->name_len = u16len; + file->mode = archive_entry_mode(entry); + if (archive_entry_filetype(entry) == AE_IFREG) + file->size = archive_entry_size(entry); + else + archive_entry_set_size(entry, 0); + if (archive_entry_filetype(entry) == AE_IFDIR) + file->dir = 1; + else if (archive_entry_filetype(entry) == AE_IFLNK) + file->size = strlen(archive_entry_symlink(entry)); + if (archive_entry_mtime_is_set(entry)) { + file->flg |= MTIME_IS_SET; + file->times[MTIME].time = archive_entry_mtime(entry); + file->times[MTIME].time_ns = archive_entry_mtime_nsec(entry); + } + if (archive_entry_atime_is_set(entry)) { + file->flg |= ATIME_IS_SET; + file->times[ATIME].time = archive_entry_atime(entry); + file->times[ATIME].time_ns = archive_entry_atime_nsec(entry); + } + if (archive_entry_ctime_is_set(entry)) { + file->flg |= CTIME_IS_SET; + file->times[CTIME].time = archive_entry_ctime(entry); + file->times[CTIME].time_ns = archive_entry_ctime_nsec(entry); + } + + *newfile = file; + return (ret); +} + +static void +file_free(struct file *file) +{ + free(file->utf16name); + free(file); +} + +static void +file_register(struct _7zip *zip, struct file *file) +{ + file->next = NULL; + *zip->file_list.last = file; + zip->file_list.last = &(file->next); +} + +static void +file_init_register(struct _7zip *zip) +{ + zip->file_list.first = NULL; + zip->file_list.last = &(zip->file_list.first); +} + +static void +file_free_register(struct _7zip *zip) +{ + struct file *file, *file_next; + + file = zip->file_list.first; + while (file != NULL) { + file_next = file->next; + file_free(file); + file = file_next; + } +} + +static void +file_register_empty(struct _7zip *zip, struct file *file) +{ + file->next = NULL; + *zip->empty_list.last = file; + zip->empty_list.last = &(file->next); +} + +static void +file_init_register_empty(struct _7zip *zip) +{ + zip->empty_list.first = NULL; + zip->empty_list.last = &(zip->empty_list.first); +} + +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) || !defined(HAVE_LZMA_H) +static int +compression_unsupported_encoder(struct archive *a, + struct la_zstream *lastrm, const char *name) +{ + + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "%s compression not supported on this platform", name); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_FAILED); +} +#endif + +/* + * _7_COPY compressor. + */ +static int +compression_init_encoder_copy(struct archive *a, struct la_zstream *lastrm) +{ + + if (lastrm->valid) + compression_end(a, lastrm); + lastrm->valid = 1; + lastrm->code = compression_code_copy; + lastrm->end = compression_end_copy; + return (ARCHIVE_OK); +} + +static int +compression_code_copy(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + size_t bytes; + + (void)a; /* UNUSED */ + if (lastrm->avail_out > lastrm->avail_in) + bytes = lastrm->avail_in; + else + bytes = lastrm->avail_out; + if (bytes) { + memcpy(lastrm->next_out, lastrm->next_in, bytes); + lastrm->next_in += bytes; + lastrm->avail_in -= bytes; + lastrm->total_in += bytes; + lastrm->next_out += bytes; + lastrm->avail_out -= bytes; + lastrm->total_out += bytes; + } + if (action == ARCHIVE_Z_FINISH && lastrm->avail_in == 0) + return (ARCHIVE_EOF); + return (ARCHIVE_OK); +} + +static int +compression_end_copy(struct archive *a, struct la_zstream *lastrm) +{ + (void)a; /* UNUSED */ + lastrm->valid = 0; + return (ARCHIVE_OK); +} + +/* + * _7_DEFLATE compressor. + */ +#ifdef HAVE_ZLIB_H +static int +compression_init_encoder_deflate(struct archive *a, + struct la_zstream *lastrm, int level, int withheader) +{ + z_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for gzip stream"); + return (ARCHIVE_FATAL); + } + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + if (deflateInit2(strm, level, Z_DEFLATED, + (withheader)?15:-15, + 8, Z_DEFAULT_STRATEGY) != Z_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_deflate; + lastrm->end = compression_end_deflate; + return (ARCHIVE_OK); +} + +static int +compression_code_deflate(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + r = deflate(strm, + (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case Z_OK: + return (ARCHIVE_OK); + case Z_STREAM_END: + return (ARCHIVE_EOF); + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "GZip compression failed:" + " deflate() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_deflate(struct archive *a, struct la_zstream *lastrm) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + r = deflateEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != Z_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} +#else +static int +compression_init_encoder_deflate(struct archive *a, + struct la_zstream *lastrm, int level, int withheader) +{ + + (void) level; /* UNUSED */ + (void) withheader; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "deflate")); +} +#endif + +/* + * _7_BZIP2 compressor. + */ +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + bz_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for bzip2 stream"); + return (ARCHIVE_FATAL); + } + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_bzip2; + lastrm->end = compression_end_bzip2; + return (ARCHIVE_OK); +} + +static int +compression_code_bzip2(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + r = BZ2_bzCompress(strm, + (action == ARCHIVE_Z_FINISH)? BZ_FINISH: BZ_RUN); + lastrm->next_in = (const unsigned char *)strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = + (((uint64_t)(uint32_t)strm->total_in_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_in_lo32; + lastrm->next_out = (unsigned char *)strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = + (((uint64_t)(uint32_t)strm->total_out_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_out_lo32; + switch (r) { + case BZ_RUN_OK: /* Non-finishing */ + case BZ_FINISH_OK: /* Finishing: There's more work to do */ + return (ARCHIVE_OK); + case BZ_STREAM_END: /* Finishing: all done */ + /* Only occurs in finishing case */ + return (ARCHIVE_EOF); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Bzip2 compression failed:" + " BZ2_bzCompress() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_bzip2(struct archive *a, struct la_zstream *lastrm) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + r = BZ2_bzCompressEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != BZ_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +#else +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "bzip2")); +} +#endif + +/* + * _7_LZMA1, _7_LZMA2 compressor. + */ +#if defined(HAVE_LZMA_H) +static int +compression_init_encoder_lzma(struct archive *a, + struct la_zstream *lastrm, int level, uint64_t filter_id) +{ + static const lzma_stream lzma_init_data = LZMA_STREAM_INIT; + lzma_stream *strm; + lzma_filter *lzmafilters; + lzma_options_lzma lzma_opt; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm) + sizeof(*lzmafilters) * 2); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for lzma stream"); + return (ARCHIVE_FATAL); + } + lzmafilters = (lzma_filter *)(strm+1); + if (level > 6) + level = 6; + if (lzma_lzma_preset(&lzma_opt, level)) { + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lzmafilters[0].id = filter_id; + lzmafilters[0].options = &lzma_opt; + lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ + + r = lzma_properties_size(&(lastrm->prop_size), lzmafilters); + if (r != LZMA_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma_properties_size failed"); + return (ARCHIVE_FATAL); + } + if (lastrm->prop_size) { + lastrm->props = malloc(lastrm->prop_size); + if (lastrm->props == NULL) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Cannot allocate memory"); + return (ARCHIVE_FATAL); + } + r = lzma_properties_encode(lzmafilters, lastrm->props); + if (r != LZMA_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma_properties_encode failed"); + return (ARCHIVE_FATAL); + } + } + + *strm = lzma_init_data; + r = lzma_raw_encoder(strm, lzmafilters); + switch (r) { + case LZMA_OK: + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_lzma; + lastrm->end = compression_end_lzma; + r = ARCHIVE_OK; + break; + case LZMA_MEM_ERROR: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library: " + "Cannot allocate memory"); + r = ARCHIVE_FATAL; + break; + default: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "It's a bug in liblzma"); + r = ARCHIVE_FATAL; + break; + } + return (r); +} + +static int +compression_init_encoder_lzma1(struct archive *a, + struct la_zstream *lastrm, int level) +{ + return compression_init_encoder_lzma(a, lastrm, level, + LZMA_FILTER_LZMA1); +} + +static int +compression_init_encoder_lzma2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + return compression_init_encoder_lzma(a, lastrm, level, + LZMA_FILTER_LZMA2); +} + +static int +compression_code_lzma(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + lzma_stream *strm; + int r; + + strm = (lzma_stream *)lastrm->real_stream; + strm->next_in = lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + r = lzma_code(strm, + (action == ARCHIVE_Z_FINISH)? LZMA_FINISH: LZMA_RUN); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case LZMA_OK: + /* Non-finishing case */ + return (ARCHIVE_OK); + case LZMA_STREAM_END: + /* This return can only occur in finishing case. */ + return (ARCHIVE_EOF); + case LZMA_MEMLIMIT_ERROR: + archive_set_error(a, ENOMEM, + "lzma compression error:" + " %ju MiB would have been needed", + (uintmax_t)((lzma_memusage(strm) + 1024 * 1024 -1) + / (1024 * 1024))); + return (ARCHIVE_FATAL); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma compression failed:" + " lzma_code() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_lzma(struct archive *a, struct la_zstream *lastrm) +{ + lzma_stream *strm; + + (void)a; /* UNUSED */ + strm = (lzma_stream *)lastrm->real_stream; + lzma_end(strm); + free(strm); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_OK); +} +#else +static int +compression_init_encoder_lzma1(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "lzma")); +} +static int +compression_init_encoder_lzma2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "lzma")); +} +#endif + +/* + * _7_PPMD compressor. + */ +static void * +ppmd_alloc(void *p, size_t size) +{ + (void)p; + return malloc(size); +} +static void +ppmd_free(void *p, void *address) +{ + (void)p; + free(address); +} +static ISzAlloc g_szalloc = { ppmd_alloc, ppmd_free }; +static void +ppmd_write(void *p, Byte b) +{ + struct archive_write *a = ((IByteOut *)p)->a; + struct _7zip *zip = (struct _7zip *)(a->format_data); + struct la_zstream *lastrm = &(zip->stream); + struct ppmd_stream *strm; + + if (lastrm->avail_out) { + *lastrm->next_out++ = b; + lastrm->avail_out--; + lastrm->total_out++; + return; + } + strm = (struct ppmd_stream *)lastrm->real_stream; + if (strm->buff_ptr < strm->buff_end) { + *strm->buff_ptr++ = b; + strm->buff_bytes++; + } +} + +static int +compression_init_encoder_ppmd(struct archive *a, + struct la_zstream *lastrm, unsigned maxOrder, uint32_t msize) +{ + struct ppmd_stream *strm; + uint8_t *props; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + strm->buff = malloc(32); + if (strm->buff == NULL) { + free(strm); + archive_set_error(a, ENOMEM, + "Can't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + strm->buff_ptr = strm->buff; + strm->buff_end = strm->buff + 32; + + props = malloc(1+4); + if (props == NULL) { + free(strm->buff); + free(strm); + archive_set_error(a, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + props[0] = maxOrder; + archive_le32enc(props+1, msize); + __archive_ppmd7_functions.Ppmd7_Construct(&strm->ppmd7_context); + r = __archive_ppmd7_functions.Ppmd7_Alloc( + &strm->ppmd7_context, msize, &g_szalloc); + if (r == 0) { + free(strm->buff); + free(strm); + free(props); + archive_set_error(a, ENOMEM, + "Coludn't allocate memory for PPMd"); + return (ARCHIVE_FATAL); + } + __archive_ppmd7_functions.Ppmd7_Init(&(strm->ppmd7_context), maxOrder); + strm->byteout.a = (struct archive_write *)a; + strm->byteout.Write = ppmd_write; + strm->range_enc.Stream = &(strm->byteout); + __archive_ppmd7_functions.Ppmd7z_RangeEnc_Init(&(strm->range_enc)); + strm->stat = 0; + + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_ppmd; + lastrm->end = compression_end_ppmd; + lastrm->prop_size = 5; + lastrm->props = props; + return (ARCHIVE_OK); +} + +static int +compression_code_ppmd(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + struct ppmd_stream *strm; + + strm = (struct ppmd_stream *)lastrm->real_stream; + + /* Copy encoded data if there are remaining bytes from previous call. */ + if (strm->buff_bytes) { + uint8_t *p = strm->buff_ptr - strm->buff_bytes; + while (lastrm->avail_out && strm->buff_bytes) { + *lastrm->next_out++ = *p++; + lastrm->avail_out--; + lastrm->total_out++; + strm->buff_bytes--; + } + if (strm->buff_bytes) + return (ARCHIVE_OK); + if (strm->stat == 1) + return (ARCHIVE_EOF); + strm->buff_ptr = strm->buff; + } + while (lastrm->avail_in && lastrm->avail_out) { + __archive_ppmd7_functions.Ppmd7_EncodeSymbol( + &(strm->ppmd7_context), &(strm->range_enc), + *lastrm->next_in++); + lastrm->avail_in--; + lastrm->total_in++; + } + if (lastrm->avail_in == 0 && action == ARCHIVE_Z_FINISH) { + __archive_ppmd7_functions.Ppmd7z_RangeEnc_FlushData( + &(strm->range_enc)); + strm->stat = 1; + /* Return EOF if there are no remaining bytes. */ + if (strm->buff_bytes == 0) + return (ARCHIVE_EOF); + } + return (ARCHIVE_OK); +} + +static int +compression_end_ppmd(struct archive *a, struct la_zstream *lastrm) +{ + struct ppmd_stream *strm; + + strm = (struct ppmd_stream *)lastrm->real_stream; + __archive_ppmd7_functions.Ppmd7_Free(&strm->ppmd7_context, &g_szalloc); + free(strm->buff); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + return (ARCHIVE_OK); +} + +/* + * Universal compressor initializer. + */ +static int +_7z_compression_init_encoder(struct archive_write *a, unsigned compression, + int compression_level) +{ + struct _7zip *zip; + int r; + + zip = (struct _7zip *)a->format_data; + switch (compression) { + case _7Z_DEFLATE: + r = compression_init_encoder_deflate( + &(a->archive), &(zip->stream), + compression_level, 0); + break; + case _7Z_BZIP2: + r = compression_init_encoder_bzip2( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_LZMA1: + r = compression_init_encoder_lzma1( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_LZMA2: + r = compression_init_encoder_lzma2( + &(a->archive), &(zip->stream), + compression_level); + break; + case _7Z_PPMD: + r = compression_init_encoder_ppmd( + &(a->archive), &(zip->stream), + PPMD7_DEFAULT_ORDER, PPMD7_DEFAULT_MEM_SIZE); + break; + case _7Z_COPY: + default: + r = compression_init_encoder_copy( + &(a->archive), &(zip->stream)); + break; + } + if (r == ARCHIVE_OK) { + zip->stream.total_in = 0; + zip->stream.next_out = zip->wbuff; + zip->stream.avail_out = sizeof(zip->wbuff); + zip->stream.total_out = 0; + } + + return (r); +} + +static int +compression_code(struct archive *a, struct la_zstream *lastrm, + enum la_zaction action) +{ + if (lastrm->valid) + return (lastrm->code(a, lastrm, action)); + return (ARCHIVE_OK); +} + +static int +compression_end(struct archive *a, struct la_zstream *lastrm) +{ + if (lastrm->valid) { + lastrm->prop_size = 0; + free(lastrm->props); + lastrm->props = NULL; + return (lastrm->end(a, lastrm)); + } + return (ARCHIVE_OK); +} + + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c index 82ef9294b..956b93228 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ar.c @@ -26,7 +26,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_ar.c,v 1.8 2008/08/10 02:06:28 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ar.c 201108 2009-12-28 03:28:21Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -44,11 +44,12 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_ar.c,v 1.8 2008/ #include "archive_write_private.h" struct ar_w { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; - int is_strtab; - int has_strtab; - char *strtab; + uint64_t entry_bytes_remaining; + uint64_t entry_padding; + int is_strtab; + int has_strtab; + char wrote_global_header; + char *strtab; }; /* @@ -69,40 +70,48 @@ struct ar_w { #define AR_fmag_offset 58 #define AR_fmag_size 2 -static int archive_write_set_format_ar(struct archive_write *); -static int archive_write_ar_header(struct archive_write *, - struct archive_entry *); -static ssize_t archive_write_ar_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_ar_destroy(struct archive_write *); -static int archive_write_ar_finish(struct archive_write *); -static int archive_write_ar_finish_entry(struct archive_write *); -static const char *ar_basename(const char *path); -static int format_octal(int64_t v, char *p, int s); -static int format_decimal(int64_t v, char *p, int s); +static int archive_write_set_format_ar(struct archive_write *); +static int archive_write_ar_header(struct archive_write *, + struct archive_entry *); +static ssize_t archive_write_ar_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_ar_free(struct archive_write *); +static int archive_write_ar_close(struct archive_write *); +static int archive_write_ar_finish_entry(struct archive_write *); +static const char *ar_basename(const char *path); +static int format_octal(int64_t v, char *p, int s); +static int format_decimal(int64_t v, char *p, int s); int archive_write_set_format_ar_bsd(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); - if (r == ARCHIVE_OK) { - a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; - a->archive.archive_format_name = "ar (BSD)"; - } - return (r); + struct archive_write *a = (struct archive_write *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_ar_bsd"); + r = archive_write_set_format_ar(a); + if (r == ARCHIVE_OK) { + a->archive.archive_format = ARCHIVE_FORMAT_AR_BSD; + a->archive.archive_format_name = "ar (BSD)"; + } + return (r); } int archive_write_set_format_ar_svr4(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int r = archive_write_set_format_ar(a); - if (r == ARCHIVE_OK) { - a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; - a->archive.archive_format_name = "ar (GNU/SVR4)"; - } - return (r); + struct archive_write *a = (struct archive_write *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_ar_svr4"); + r = archive_write_set_format_ar(a); + if (r == ARCHIVE_OK) { + a->archive.archive_format = ARCHIVE_FORMAT_AR_GNU; + a->archive.archive_format_name = "ar (GNU/SVR4)"; + } + return (r); } /* @@ -111,342 +120,346 @@ archive_write_set_format_ar_svr4(struct archive *_a) static int archive_write_set_format_ar(struct archive_write *a) { - struct ar_w *ar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - ar = (struct ar_w *)malloc(sizeof(*ar)); - if (ar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data"); - return (ARCHIVE_FATAL); - } - memset(ar, 0, sizeof(*ar)); - a->format_data = ar; - - a->format_name = "ar"; - a->format_write_header = archive_write_ar_header; - a->format_write_data = archive_write_ar_data; - a->format_finish = archive_write_ar_finish; - a->format_destroy = archive_write_ar_destroy; - a->format_finish_entry = archive_write_ar_finish_entry; - return (ARCHIVE_OK); + struct ar_w *ar; + + /* If someone else was already registered, unregister them. */ + if (a->format_free != NULL) + (a->format_free)(a); + + ar = (struct ar_w *)malloc(sizeof(*ar)); + if (ar == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate ar data"); + return (ARCHIVE_FATAL); + } + memset(ar, 0, sizeof(*ar)); + a->format_data = ar; + + a->format_name = "ar"; + a->format_write_header = archive_write_ar_header; + a->format_write_data = archive_write_ar_data; + a->format_close = archive_write_ar_close; + a->format_free = archive_write_ar_free; + a->format_finish_entry = archive_write_ar_finish_entry; + return (ARCHIVE_OK); } static int archive_write_ar_header(struct archive_write *a, struct archive_entry *entry) { - int ret, append_fn; - char buff[60]; - char *ss, *se; - struct ar_w *ar; - const char *pathname; - const char *filename; - int64_t size; - - ret = 0; - append_fn = 0; - ar = (struct ar_w *)a->format_data; - ar->is_strtab = 0; - filename = NULL; - size = archive_entry_size(entry); - - - /* - * Reject files with empty name. - */ - pathname = archive_entry_pathname(entry); - if (*pathname == '\0') { - archive_set_error(&a->archive, EINVAL, - "Invalid filename"); - return (ARCHIVE_WARN); - } - - /* - * If we are now at the beginning of the archive, - * we need first write the ar global header. - */ - if (a->archive.file_position == 0) - (a->compressor.write)(a, "!\n", 8); - - memset(buff, ' ', 60); - strncpy(&buff[AR_fmag_offset], "`\n", 2); - - if (strcmp(pathname, "/") == 0 ) { - /* Entry is archive symbol table in GNU format */ - buff[AR_name_offset] = '/'; - goto stat; - } - if (strcmp(pathname, "__.SYMDEF") == 0) { - /* Entry is archive symbol table in BSD format */ - strncpy(buff + AR_name_offset, "__.SYMDEF", 9); - goto stat; - } - if (strcmp(pathname, "//") == 0) { - /* - * Entry is archive filename table, inform that we should - * collect strtab in next _data call. - */ - ar->is_strtab = 1; - buff[AR_name_offset] = buff[AR_name_offset + 1] = '/'; - /* - * For archive string table, only ar_size filed should - * be set. - */ - goto size; - } - - /* - * Otherwise, entry is a normal archive member. - * Strip leading paths from filenames, if any. - */ - if ((filename = ar_basename(pathname)) == NULL) { - /* Reject filenames with trailing "/" */ - archive_set_error(&a->archive, EINVAL, - "Invalid filename"); - return (ARCHIVE_WARN); - } - - if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) { - /* - * SVR4/GNU variant use a "/" to mark then end of the filename, - * make it possible to have embedded spaces in the filename. - * So, the longest filename here (without extension) is - * actually 15 bytes. - */ - if (strlen(filename) <= 15) { - strncpy(&buff[AR_name_offset], - filename, strlen(filename)); - buff[AR_name_offset + strlen(filename)] = '/'; - } else { - /* - * For filename longer than 15 bytes, GNU variant - * makes use of a string table and instead stores the - * offset of the real filename to in the ar_name field. - * The string table should have been written before. - */ - if (ar->has_strtab <= 0) { - archive_set_error(&a->archive, EINVAL, - "Can't find string table"); - return (ARCHIVE_WARN); - } - - se = (char *)malloc(strlen(filename) + 3); - if (se == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate filename buffer"); - return (ARCHIVE_FATAL); - } - - strncpy(se, filename, strlen(filename)); - strcpy(se + strlen(filename), "/\n"); - - ss = strstr(ar->strtab, se); - free(se); - - if (ss == NULL) { - archive_set_error(&a->archive, EINVAL, - "Invalid string table"); - return (ARCHIVE_WARN); - } - - /* - * GNU variant puts "/" followed by digits into - * ar_name field. These digits indicates the real - * filename string's offset to the string table. - */ - buff[AR_name_offset] = '/'; - if (format_decimal(ss - ar->strtab, - buff + AR_name_offset + 1, - AR_name_size - 1)) { - archive_set_error(&a->archive, ERANGE, - "string table offset too large"); - return (ARCHIVE_WARN); - } - } - } else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) { - /* - * BSD variant: for any file name which is more than - * 16 chars or contains one or more embedded space(s), the - * string "#1/" followed by the ASCII length of the name is - * put into the ar_name field. The file size (stored in the - * ar_size field) is incremented by the length of the name. - * The name is then written immediately following the - * archive header. - */ - if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) { - strncpy(&buff[AR_name_offset], filename, strlen(filename)); - buff[AR_name_offset + strlen(filename)] = ' '; - } - else { - strncpy(buff + AR_name_offset, "#1/", 3); - if (format_decimal(strlen(filename), - buff + AR_name_offset + 3, - AR_name_size - 3)) { - archive_set_error(&a->archive, ERANGE, - "File name too long"); - return (ARCHIVE_WARN); - } - append_fn = 1; - size += strlen(filename); - } - } + int ret, append_fn; + char buff[60]; + char *ss, *se; + struct ar_w *ar; + const char *pathname; + const char *filename; + int64_t size; + + append_fn = 0; + ar = (struct ar_w *)a->format_data; + ar->is_strtab = 0; + filename = NULL; + size = archive_entry_size(entry); + + + /* + * Reject files with empty name. + */ + pathname = archive_entry_pathname(entry); + if (*pathname == '\0') { + archive_set_error(&a->archive, EINVAL, + "Invalid filename"); + return (ARCHIVE_WARN); + } + + /* + * If we are now at the beginning of the archive, + * we need first write the ar global header. + */ + if (!ar->wrote_global_header) { + __archive_write_output(a, "!\n", 8); + ar->wrote_global_header = 1; + } + + memset(buff, ' ', 60); + strncpy(&buff[AR_fmag_offset], "`\n", 2); + + if (strcmp(pathname, "/") == 0 ) { + /* Entry is archive symbol table in GNU format */ + buff[AR_name_offset] = '/'; + goto stat; + } + if (strcmp(pathname, "__.SYMDEF") == 0) { + /* Entry is archive symbol table in BSD format */ + strncpy(buff + AR_name_offset, "__.SYMDEF", 9); + goto stat; + } + if (strcmp(pathname, "//") == 0) { + /* + * Entry is archive filename table, inform that we should + * collect strtab in next _data call. + */ + ar->is_strtab = 1; + buff[AR_name_offset] = buff[AR_name_offset + 1] = '/'; + /* + * For archive string table, only ar_size field should + * be set. + */ + goto size; + } + + /* + * Otherwise, entry is a normal archive member. + * Strip leading paths from filenames, if any. + */ + if ((filename = ar_basename(pathname)) == NULL) { + /* Reject filenames with trailing "/" */ + archive_set_error(&a->archive, EINVAL, + "Invalid filename"); + return (ARCHIVE_WARN); + } + + if (a->archive.archive_format == ARCHIVE_FORMAT_AR_GNU) { + /* + * SVR4/GNU variant use a "/" to mark then end of the filename, + * make it possible to have embedded spaces in the filename. + * So, the longest filename here (without extension) is + * actually 15 bytes. + */ + if (strlen(filename) <= 15) { + strncpy(&buff[AR_name_offset], + filename, strlen(filename)); + buff[AR_name_offset + strlen(filename)] = '/'; + } else { + /* + * For filename longer than 15 bytes, GNU variant + * makes use of a string table and instead stores the + * offset of the real filename to in the ar_name field. + * The string table should have been written before. + */ + if (ar->has_strtab <= 0) { + archive_set_error(&a->archive, EINVAL, + "Can't find string table"); + return (ARCHIVE_WARN); + } + + se = (char *)malloc(strlen(filename) + 3); + if (se == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate filename buffer"); + return (ARCHIVE_FATAL); + } + + strncpy(se, filename, strlen(filename)); + strcpy(se + strlen(filename), "/\n"); + + ss = strstr(ar->strtab, se); + free(se); + + if (ss == NULL) { + archive_set_error(&a->archive, EINVAL, + "Invalid string table"); + return (ARCHIVE_WARN); + } + + /* + * GNU variant puts "/" followed by digits into + * ar_name field. These digits indicates the real + * filename string's offset to the string table. + */ + buff[AR_name_offset] = '/'; + if (format_decimal(ss - ar->strtab, + buff + AR_name_offset + 1, + AR_name_size - 1)) { + archive_set_error(&a->archive, ERANGE, + "string table offset too large"); + return (ARCHIVE_WARN); + } + } + } else if (a->archive.archive_format == ARCHIVE_FORMAT_AR_BSD) { + /* + * BSD variant: for any file name which is more than + * 16 chars or contains one or more embedded space(s), the + * string "#1/" followed by the ASCII length of the name is + * put into the ar_name field. The file size (stored in the + * ar_size field) is incremented by the length of the name. + * The name is then written immediately following the + * archive header. + */ + if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) { + strncpy(&buff[AR_name_offset], filename, strlen(filename)); + buff[AR_name_offset + strlen(filename)] = ' '; + } + else { + strncpy(buff + AR_name_offset, "#1/", 3); + if (format_decimal(strlen(filename), + buff + AR_name_offset + 3, + AR_name_size - 3)) { + archive_set_error(&a->archive, ERANGE, + "File name too long"); + return (ARCHIVE_WARN); + } + append_fn = 1; + size += strlen(filename); + } + } stat: - if (format_decimal(archive_entry_mtime(entry), buff + AR_date_offset, AR_date_size)) { - archive_set_error(&a->archive, ERANGE, - "File modification time too large"); - return (ARCHIVE_WARN); - } - if (format_decimal(archive_entry_uid(entry), buff + AR_uid_offset, AR_uid_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric user ID too large"); - return (ARCHIVE_WARN); - } - if (format_decimal(archive_entry_gid(entry), buff + AR_gid_offset, AR_gid_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric group ID too large"); - return (ARCHIVE_WARN); - } - if (format_octal(archive_entry_mode(entry), buff + AR_mode_offset, AR_mode_size)) { - archive_set_error(&a->archive, ERANGE, - "Numeric mode too large"); - return (ARCHIVE_WARN); - } - /* - * Sanity Check: A non-pseudo archive member should always be - * a regular file. - */ - if (filename != NULL && archive_entry_filetype(entry) != AE_IFREG) { - archive_set_error(&a->archive, EINVAL, - "Regular file required for non-pseudo member"); - return (ARCHIVE_WARN); - } + if (format_decimal(archive_entry_mtime(entry), buff + AR_date_offset, AR_date_size)) { + archive_set_error(&a->archive, ERANGE, + "File modification time too large"); + return (ARCHIVE_WARN); + } + if (format_decimal(archive_entry_uid(entry), buff + AR_uid_offset, AR_uid_size)) { + archive_set_error(&a->archive, ERANGE, + "Numeric user ID too large"); + return (ARCHIVE_WARN); + } + if (format_decimal(archive_entry_gid(entry), buff + AR_gid_offset, AR_gid_size)) { + archive_set_error(&a->archive, ERANGE, + "Numeric group ID too large"); + return (ARCHIVE_WARN); + } + if (format_octal(archive_entry_mode(entry), buff + AR_mode_offset, AR_mode_size)) { + archive_set_error(&a->archive, ERANGE, + "Numeric mode too large"); + return (ARCHIVE_WARN); + } + /* + * Sanity Check: A non-pseudo archive member should always be + * a regular file. + */ + if (filename != NULL && archive_entry_filetype(entry) != AE_IFREG) { + archive_set_error(&a->archive, EINVAL, + "Regular file required for non-pseudo member"); + return (ARCHIVE_WARN); + } size: - if (format_decimal(size, buff + AR_size_offset, AR_size_size)) { - archive_set_error(&a->archive, ERANGE, - "File size out of range"); - return (ARCHIVE_WARN); - } - - ret = (a->compressor.write)(a, buff, 60); - if (ret != ARCHIVE_OK) - return (ret); - - ar->entry_bytes_remaining = size; - ar->entry_padding = ar->entry_bytes_remaining % 2; - - if (append_fn > 0) { - ret = (a->compressor.write)(a, filename, strlen(filename)); - if (ret != ARCHIVE_OK) - return (ret); - ar->entry_bytes_remaining -= strlen(filename); - } - - return (ARCHIVE_OK); + if (format_decimal(size, buff + AR_size_offset, AR_size_size)) { + archive_set_error(&a->archive, ERANGE, + "File size out of range"); + return (ARCHIVE_WARN); + } + + ret = __archive_write_output(a, buff, 60); + if (ret != ARCHIVE_OK) + return (ret); + + ar->entry_bytes_remaining = size; + ar->entry_padding = ar->entry_bytes_remaining % 2; + + if (append_fn > 0) { + ret = __archive_write_output(a, filename, strlen(filename)); + if (ret != ARCHIVE_OK) + return (ret); + ar->entry_bytes_remaining -= strlen(filename); + } + + return (ARCHIVE_OK); } static ssize_t archive_write_ar_data(struct archive_write *a, const void *buff, size_t s) { - struct ar_w *ar; - int ret; - - ar = (struct ar_w *)a->format_data; - if (s > ar->entry_bytes_remaining) - s = ar->entry_bytes_remaining; - - if (ar->is_strtab > 0) { - if (ar->has_strtab > 0) { - archive_set_error(&a->archive, EINVAL, - "More than one string tables exist"); - return (ARCHIVE_WARN); - } - - ar->strtab = (char *)malloc(s); - if (ar->strtab == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate strtab buffer"); - return (ARCHIVE_FATAL); - } - strncpy(ar->strtab, buff, s); - ar->has_strtab = 1; - } - - ret = (a->compressor.write)(a, buff, s); - if (ret != ARCHIVE_OK) - return (ret); - - ar->entry_bytes_remaining -= s; - return (s); + struct ar_w *ar; + int ret; + + ar = (struct ar_w *)a->format_data; + if (s > ar->entry_bytes_remaining) + s = ar->entry_bytes_remaining; + + if (ar->is_strtab > 0) { + if (ar->has_strtab > 0) { + archive_set_error(&a->archive, EINVAL, + "More than one string tables exist"); + return (ARCHIVE_WARN); + } + + ar->strtab = (char *)malloc(s); + if (ar->strtab == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate strtab buffer"); + return (ARCHIVE_FATAL); + } + strncpy(ar->strtab, buff, s); + ar->has_strtab = 1; + } + + ret = __archive_write_output(a, buff, s); + if (ret != ARCHIVE_OK) + return (ret); + + ar->entry_bytes_remaining -= s; + return (s); } static int -archive_write_ar_destroy(struct archive_write *a) +archive_write_ar_free(struct archive_write *a) { - struct ar_w *ar; + struct ar_w *ar; - ar = (struct ar_w *)a->format_data; + ar = (struct ar_w *)a->format_data; - if (ar == NULL) - return (ARCHIVE_OK); + if (ar == NULL) + return (ARCHIVE_OK); - if (ar->has_strtab > 0) { - free(ar->strtab); - ar->strtab = NULL; - } + if (ar->has_strtab > 0) { + free(ar->strtab); + ar->strtab = NULL; + } - free(ar); - a->format_data = NULL; - return (ARCHIVE_OK); + free(ar); + a->format_data = NULL; + return (ARCHIVE_OK); } static int -archive_write_ar_finish(struct archive_write *a) +archive_write_ar_close(struct archive_write *a) { - int ret; - - /* - * If we haven't written anything yet, we need to write - * the ar global header now to make it a valid ar archive. - */ - if (a->archive.file_position == 0) { - ret = (a->compressor.write)(a, "!\n", 8); - return (ret); - } - - return (ARCHIVE_OK); + struct ar_w *ar; + int ret; + + /* + * If we haven't written anything yet, we need to write + * the ar global header now to make it a valid ar archive. + */ + ar = (struct ar_w *)a->format_data; + if (!ar->wrote_global_header) { + ar->wrote_global_header = 1; + ret = __archive_write_output(a, "!\n", 8); + return (ret); + } + + return (ARCHIVE_OK); } static int archive_write_ar_finish_entry(struct archive_write *a) { - struct ar_w *ar; - int ret; - - ar = (struct ar_w *)a->format_data; - - if (ar->entry_bytes_remaining != 0) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Entry remaining bytes larger than 0"); - return (ARCHIVE_WARN); - } - - if (ar->entry_padding == 0) { - return (ARCHIVE_OK); - } - - if (ar->entry_padding != 1) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Padding wrong size: %d should be 1 or 0", - ar->entry_padding); - return (ARCHIVE_WARN); - } - - ret = (a->compressor.write)(a, "\n", 1); - return (ret); + struct ar_w *ar; + int ret; + + ar = (struct ar_w *)a->format_data; + + if (ar->entry_bytes_remaining != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Entry remaining bytes larger than 0"); + return (ARCHIVE_WARN); + } + + if (ar->entry_padding == 0) { + return (ARCHIVE_OK); + } + + if (ar->entry_padding != 1) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Padding wrong size: %ju should be 1 or 0", + (uintmax_t)ar->entry_padding); + return (ARCHIVE_WARN); + } + + ret = __archive_write_output(a, "\n", 1); + return (ret); } /* @@ -457,37 +470,37 @@ archive_write_ar_finish_entry(struct archive_write *a) static int format_octal(int64_t v, char *p, int s) { - int len; - char *h; - - len = s; - h = p; - - /* Octal values can't be negative, so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; /* Start at the end and work backwards. */ - do { - *--p = (char)('0' + (v & 7)); - v >>= 3; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '7'; - - return (-1); + int len; + char *h; + + len = s; + h = p; + + /* Octal values can't be negative, so use 0. */ + if (v < 0) { + while (len-- > 0) + *p++ = '0'; + return (-1); + } + + p += s; /* Start at the end and work backwards. */ + do { + *--p = (char)('0' + (v & 7)); + v >>= 3; + } while (--s > 0 && v > 0); + + if (v == 0) { + memmove(h, p, len - s); + p = h + len - s; + while (s-- > 0) + *p++ = ' '; + return (0); + } + /* If it overflowed, fill field with max value. */ + while (len-- > 0) + *p++ = '7'; + + return (-1); } /* @@ -496,56 +509,56 @@ format_octal(int64_t v, char *p, int s) static int format_decimal(int64_t v, char *p, int s) { - int len; - char *h; - - len = s; - h = p; - - /* Negative values in ar header are meaningless , so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } - - p += s; - do { - *--p = (char)('0' + (v % 10)); - v /= 10; - } while (--s > 0 && v > 0); - - if (v == 0) { - memmove(h, p, len - s); - p = h + len - s; - while (s-- > 0) - *p++ = ' '; - return (0); - } - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '9'; - - return (-1); + int len; + char *h; + + len = s; + h = p; + + /* Negative values in ar header are meaningless, so use 0. */ + if (v < 0) { + while (len-- > 0) + *p++ = '0'; + return (-1); + } + + p += s; + do { + *--p = (char)('0' + (v % 10)); + v /= 10; + } while (--s > 0 && v > 0); + + if (v == 0) { + memmove(h, p, len - s); + p = h + len - s; + while (s-- > 0) + *p++ = ' '; + return (0); + } + /* If it overflowed, fill field with max value. */ + while (len-- > 0) + *p++ = '9'; + + return (-1); } static const char * ar_basename(const char *path) { - const char *endp, *startp; - - endp = path + strlen(path) - 1; - /* - * For filename with trailing slash(es), we return - * NULL indicating an error. - */ - if (*endp == '/') - return (NULL); - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - return (startp); + const char *endp, *startp; + + endp = path + strlen(path) - 1; + /* + * For filename with trailing slash(es), we return + * NULL indicating an error. + */ + if (*endp == '/') + return (NULL); + + /* Find the start of the base */ + startp = endp; + while (startp > path && *(startp - 1) != '/') + startp--; + + return (startp); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c index db1c950e1..9671f60f8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_by_name.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_by_name.c,v 1.9 2008/09/01 02:50:53 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_by_name.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -44,33 +44,43 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_by_name.c,v 1.9 static struct { const char *name; int (*setter)(struct archive *); } names[] = { - { "ar", archive_write_set_format_ar_bsd }, - { "arbsd", archive_write_set_format_ar_bsd }, - { "argnu", archive_write_set_format_ar_svr4 }, - { "arsvr4", archive_write_set_format_ar_svr4 }, - { "cpio", archive_write_set_format_cpio }, - { "mtree", archive_write_set_format_mtree }, - { "newc", archive_write_set_format_cpio_newc }, - { "odc", archive_write_set_format_cpio }, - { "pax", archive_write_set_format_pax }, - { "posix", archive_write_set_format_pax }, - { "shar", archive_write_set_format_shar }, - { "shardump", archive_write_set_format_shar_dump }, - { "ustar", archive_write_set_format_ustar }, - { "zip", archive_write_set_format_zip }, - { NULL, NULL } + { "7zip", archive_write_set_format_7zip }, + { "ar", archive_write_set_format_ar_bsd }, + { "arbsd", archive_write_set_format_ar_bsd }, + { "argnu", archive_write_set_format_ar_svr4 }, + { "arsvr4", archive_write_set_format_ar_svr4 }, + { "bsdtar", archive_write_set_format_pax_restricted }, + { "cd9660", archive_write_set_format_iso9660 }, + { "cpio", archive_write_set_format_cpio }, + { "gnutar", archive_write_set_format_gnutar }, + { "iso", archive_write_set_format_iso9660 }, + { "iso9660", archive_write_set_format_iso9660 }, + { "mtree", archive_write_set_format_mtree }, + { "newc", archive_write_set_format_cpio_newc }, + { "odc", archive_write_set_format_cpio }, + { "pax", archive_write_set_format_pax }, + { "paxr", archive_write_set_format_pax_restricted }, + { "posix", archive_write_set_format_pax }, + { "rpax", archive_write_set_format_pax_restricted }, + { "shar", archive_write_set_format_shar }, + { "shardump", archive_write_set_format_shar_dump }, + { "ustar", archive_write_set_format_ustar }, + { "xar", archive_write_set_format_xar }, + { "zip", archive_write_set_format_zip }, + { NULL, NULL } }; int archive_write_set_format_by_name(struct archive *a, const char *name) { - int i; + int i; - for (i = 0; names[i].name != NULL; i++) { - if (strcmp(name, names[i].name) == 0) - return ((names[i].setter)(a)); - } + for (i = 0; names[i].name != NULL; i++) { + if (strcmp(name, names[i].name) == 0) + return ((names[i].setter)(a)); + } - archive_set_error(a, EINVAL, "No such format '%s'", name); - return (ARCHIVE_FATAL); + archive_set_error(a, EINVAL, "No such format '%s'", name); + a->state = ARCHIVE_STATE_FATAL; + return (ARCHIVE_FATAL); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c index 1c5bb1396..92b9bfb0b 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio.c @@ -24,7 +24,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_cpio.c,v 1.14 2008/03/15 11:04:45 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio.c 201170 2009-12-29 06:34:23Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -39,158 +39,361 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_cpio.c,v 1.14 20 #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_write_private.h" -static ssize_t archive_write_cpio_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_cpio_finish(struct archive_write *); -static int archive_write_cpio_destroy(struct archive_write *); -static int archive_write_cpio_finish_entry(struct archive_write *); -static int archive_write_cpio_header(struct archive_write *, - struct archive_entry *); -static int format_octal(int64_t, void *, int); -static int64_t format_octal_recursive(int64_t, char *, int); +static ssize_t archive_write_cpio_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_cpio_close(struct archive_write *); +static int archive_write_cpio_free(struct archive_write *); +static int archive_write_cpio_finish_entry(struct archive_write *); +static int archive_write_cpio_header(struct archive_write *, + struct archive_entry *); +static int archive_write_cpio_options(struct archive_write *, + const char *, const char *); +static int format_octal(int64_t, void *, int); +static int64_t format_octal_recursive(int64_t, char *, int); +static int write_header(struct archive_write *, struct archive_entry *); struct cpio { - uint64_t entry_bytes_remaining; -}; + uint64_t entry_bytes_remaining; + + int64_t ino_next; -struct cpio_header { - char c_magic[6]; - char c_dev[6]; - char c_ino[6]; - char c_mode[6]; - char c_uid[6]; - char c_gid[6]; - char c_nlink[6]; - char c_rdev[6]; - char c_mtime[11]; - char c_namesize[6]; - char c_filesize[11]; + struct { int64_t old; int new;} *ino_list; + size_t ino_list_size; + size_t ino_list_next; + + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; }; +#define c_magic_offset 0 +#define c_magic_size 6 +#define c_dev_offset 6 +#define c_dev_size 6 +#define c_ino_offset 12 +#define c_ino_size 6 +#define c_mode_offset 18 +#define c_mode_size 6 +#define c_uid_offset 24 +#define c_uid_size 6 +#define c_gid_offset 30 +#define c_gid_size 6 +#define c_nlink_offset 36 +#define c_nlink_size 6 +#define c_rdev_offset 42 +#define c_rdev_size 6 +#define c_mtime_offset 48 +#define c_mtime_size 11 +#define c_namesize_offset 59 +#define c_namesize_size 6 +#define c_filesize_offset 65 +#define c_filesize_size 11 + /* * Set output format to 'cpio' format. */ int archive_write_set_format_cpio(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct cpio *cpio; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - a->format_data = cpio; - - a->pad_uncompressed = 1; - a->format_name = "cpio"; - a->format_write_header = archive_write_cpio_header; - a->format_write_data = archive_write_cpio_data; - a->format_finish_entry = archive_write_cpio_finish_entry; - a->format_finish = archive_write_cpio_finish; - a->format_destroy = archive_write_cpio_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; - a->archive.archive_format_name = "POSIX cpio"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct cpio *cpio; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_cpio"); + + /* If someone else was already registered, unregister them. */ + if (a->format_free != NULL) + (a->format_free)(a); + + cpio = (struct cpio *)calloc(1, sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + a->format_data = cpio; + a->format_name = "cpio"; + a->format_options = archive_write_cpio_options; + a->format_write_header = archive_write_cpio_header; + a->format_write_data = archive_write_cpio_data; + a->format_finish_entry = archive_write_cpio_finish_entry; + a->format_close = archive_write_cpio_close; + a->format_free = archive_write_cpio_free; + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_POSIX; + a->archive.archive_format_name = "POSIX cpio"; + return (ARCHIVE_OK); +} + +static int +archive_write_cpio_options(struct archive_write *a, const char *key, + const char *val) +{ + struct cpio *cpio = (struct cpio *)a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: hdrcharset option needs a character-set name", + a->format_name); + else { + cpio->opt_sconv = archive_string_conversion_to_charset( + &a->archive, val, 0); + if (cpio->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: unknown keyword ``%s''", a->format_name, key); + + return (ret); +} + +/* + * Ino values are as long as 64 bits on some systems; cpio format + * only allows 18 bits and relies on the ino values to identify hardlinked + * files. So, we can't merely "hash" the ino numbers since collisions + * would corrupt the archive. Instead, we generate synthetic ino values + * to store in the archive and maintain a map of original ino values to + * synthetic ones so we can preserve hardlink information. + * + * TODO: Make this more efficient. It's not as bad as it looks (most + * files don't have any hardlinks and we don't do any work here for those), + * but it wouldn't be hard to do better. + * + * TODO: Work with dev/ino pairs here instead of just ino values. + */ +static int +synthesize_ino_value(struct cpio *cpio, struct archive_entry *entry) +{ + int64_t ino = archive_entry_ino64(entry); + int ino_new; + size_t i; + + /* + * If no index number was given, don't assign one. In + * particular, this handles the end-of-archive marker + * correctly by giving it a zero index value. (This is also + * why we start our synthetic index numbers with one below.) + */ + if (ino == 0) + return (0); + + /* Don't store a mapping if we don't need to. */ + if (archive_entry_nlink(entry) < 2) { + return ++cpio->ino_next; + } + + /* Look up old ino; if we have it, this is a hardlink + * and we reuse the same value. */ + for (i = 0; i < cpio->ino_list_next; ++i) { + if (cpio->ino_list[i].old == ino) + return (cpio->ino_list[i].new); + } + + /* Assign a new index number. */ + ino_new = ++cpio->ino_next; + + /* Ensure space for the new mapping. */ + if (cpio->ino_list_size <= cpio->ino_list_next) { + size_t newsize = cpio->ino_list_size < 512 + ? 512 : cpio->ino_list_size * 2; + void *newlist = realloc(cpio->ino_list, + sizeof(cpio->ino_list[0]) * newsize); + if (newlist == NULL) + return (-1); + + cpio->ino_list_size = newsize; + cpio->ino_list = newlist; + } + + /* Record and return the new value. */ + cpio->ino_list[cpio->ino_list_next].old = ino; + cpio->ino_list[cpio->ino_list_next].new = ino_new; + ++cpio->ino_list_next; + return (ino_new); +} + + +static struct archive_string_conv * +get_sconv(struct archive_write *a) +{ + struct cpio *cpio; + struct archive_string_conv *sconv; + + cpio = (struct cpio *)a->format_data; + sconv = cpio->opt_sconv; + if (sconv == NULL) { + if (!cpio->init_default_conversion) { + cpio->sconv_default = + archive_string_default_conversion_for_write( + &(a->archive)); + cpio->init_default_conversion = 1; + } + sconv = cpio->sconv_default; + } + return (sconv); } static int archive_write_cpio_header(struct archive_write *a, struct archive_entry *entry) { - struct cpio *cpio; - const char *p, *path; - int pathlength, ret; - int64_t ino; - struct cpio_header h; - - cpio = (struct cpio *)a->format_data; - ret = 0; - - path = archive_entry_pathname(entry); - pathlength = strlen(path) + 1; /* Include trailing null. */ - - memset(&h, 0, sizeof(h)); - format_octal(070707, &h.c_magic, sizeof(h.c_magic)); - format_octal(archive_entry_dev(entry), &h.c_dev, sizeof(h.c_dev)); - /* - * TODO: Generate artificial inode numbers rather than just - * re-using the ones off the disk. That way, the 18-bit c_ino - * field only limits the number of files in the archive. - */ - ino = archive_entry_ino64(entry); - if (ino < 0 || ino > 0777777) { - archive_set_error(&a->archive, ERANGE, - "large inode number truncated"); - ret = ARCHIVE_WARN; - } - - format_octal(archive_entry_ino64(entry) & 0777777, &h.c_ino, sizeof(h.c_ino)); - format_octal(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); - format_octal(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); - format_octal(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); - format_octal(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) - format_octal(archive_entry_dev(entry), &h.c_rdev, sizeof(h.c_rdev)); - else - format_octal(0, &h.c_rdev, sizeof(h.c_rdev)); - format_octal(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); - format_octal(pathlength, &h.c_namesize, sizeof(h.c_namesize)); - - /* Non-regular files don't store bodies. */ - if (archive_entry_filetype(entry) != AE_IFREG) - archive_entry_set_size(entry, 0); - - /* Symlinks get the link written as the body of the entry. */ - p = archive_entry_symlink(entry); - if (p != NULL && *p != '\0') - format_octal(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); - else - format_octal(archive_entry_size(entry), - &h.c_filesize, sizeof(h.c_filesize)); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - ret = (a->compressor.write)(a, path, pathlength); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - cpio->entry_bytes_remaining = archive_entry_size(entry); - - /* Write the symlink now. */ - if (p != NULL && *p != '\0') - ret = (a->compressor.write)(a, p, strlen(p)); - - return (ret); + const char *path; + size_t len; + + if (archive_entry_filetype(entry) == 0) { + archive_set_error(&a->archive, -1, "Filetype required"); + return (ARCHIVE_FAILED); + } + + if (archive_entry_pathname_l(entry, &path, &len, get_sconv(a)) != 0 + && errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + if (len == 0 || path == NULL || path[0] == '\0') { + archive_set_error(&a->archive, -1, "Pathname required"); + return (ARCHIVE_FAILED); + } + + if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) < 0) { + archive_set_error(&a->archive, -1, "Size required"); + return (ARCHIVE_FAILED); + } + return write_header(a, entry); +} + +static int +write_header(struct archive_write *a, struct archive_entry *entry) +{ + struct cpio *cpio; + const char *p, *path; + int pathlength, ret, ret_final; + int64_t ino; + char h[76]; + struct archive_string_conv *sconv; + size_t len; + + cpio = (struct cpio *)a->format_data; + ret_final = ARCHIVE_OK; + sconv = get_sconv(a); + + ret = archive_entry_pathname_l(entry, &path, &len, sconv); + if (ret != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", + archive_entry_pathname(entry), + archive_string_conversion_charset_name(sconv)); + ret_final = ARCHIVE_WARN; + } + /* Include trailing null. */ + pathlength = (int)len + 1; + + memset(h, 0, sizeof(h)); + format_octal(070707, h + c_magic_offset, c_magic_size); + format_octal(archive_entry_dev(entry), h + c_dev_offset, c_dev_size); + + ino = synthesize_ino_value(cpio, entry); + if (ino < 0) { + archive_set_error(&a->archive, ENOMEM, + "No memory for ino translation table"); + return (ARCHIVE_FATAL); + } else if (ino > 0777777) { + archive_set_error(&a->archive, ERANGE, + "Too many files for this cpio format"); + return (ARCHIVE_FATAL); + } + format_octal(ino & 0777777, h + c_ino_offset, c_ino_size); + + /* TODO: Set ret_final to ARCHIVE_WARN if any of these overflow. */ + format_octal(archive_entry_mode(entry), h + c_mode_offset, c_mode_size); + format_octal(archive_entry_uid(entry), h + c_uid_offset, c_uid_size); + format_octal(archive_entry_gid(entry), h + c_gid_offset, c_gid_size); + 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); + else + format_octal(0, h + c_rdev_offset, c_rdev_size); + format_octal(archive_entry_mtime(entry), h + c_mtime_offset, c_mtime_size); + format_octal(pathlength, h + c_namesize_offset, c_namesize_size); + + /* Non-regular files don't store bodies. */ + if (archive_entry_filetype(entry) != AE_IFREG) + archive_entry_set_size(entry, 0); + + /* Symlinks get the link written as the body of the entry. */ + ret = archive_entry_symlink_l(entry, &p, &len, sconv); + if (ret != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + archive_entry_symlink(entry), + archive_string_conversion_charset_name(sconv)); + ret_final = ARCHIVE_WARN; + } + if (len > 0 && p != NULL && *p != '\0') + ret = format_octal(strlen(p), h + c_filesize_offset, + c_filesize_size); + else + ret = format_octal(archive_entry_size(entry), + h + c_filesize_offset, c_filesize_size); + if (ret) { + archive_set_error(&a->archive, ERANGE, + "File is too large for cpio format."); + return (ARCHIVE_FAILED); + } + + ret = __archive_write_output(a, h, sizeof(h)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + ret = __archive_write_output(a, path, pathlength); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + cpio->entry_bytes_remaining = archive_entry_size(entry); + + /* Write the symlink now. */ + if (p != NULL && *p != '\0') { + ret = __archive_write_output(a, p, strlen(p)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + return (ret_final); } static ssize_t archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s) { - struct cpio *cpio; - int ret; - - cpio = (struct cpio *)a->format_data; - if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - cpio->entry_bytes_remaining -= s; - if (ret >= 0) - return (s); - else - return (ret); + struct cpio *cpio; + int ret; + + cpio = (struct cpio *)a->format_data; + if (s > cpio->entry_bytes_remaining) + s = cpio->entry_bytes_remaining; + + ret = __archive_write_output(a, buff, s); + cpio->entry_bytes_remaining -= s; + if (ret >= 0) + return (s); + else + return (ret); } /* @@ -199,73 +402,63 @@ archive_write_cpio_data(struct archive_write *a, const void *buff, size_t s) static int format_octal(int64_t v, void *p, int digits) { - int64_t max; - int ret; - - max = (((int64_t)1) << (digits * 3)) - 1; - if (v >= 0 && v <= max) { - format_octal_recursive(v, (char *)p, digits); - ret = 0; - } else { - format_octal_recursive(max, (char *)p, digits); - ret = -1; - } - return (ret); + int64_t max; + int ret; + + max = (((int64_t)1) << (digits * 3)) - 1; + if (v >= 0 && v <= max) { + format_octal_recursive(v, (char *)p, digits); + ret = 0; + } else { + format_octal_recursive(max, (char *)p, digits); + ret = -1; + } + return (ret); } static int64_t format_octal_recursive(int64_t v, char *p, int s) { - if (s == 0) - return (v); - v = format_octal_recursive(v, p+1, s-1); - *p = '0' + (v & 7); - return (v >>= 3); + if (s == 0) + return (v); + v = format_octal_recursive(v, p+1, s-1); + *p = '0' + (v & 7); + return (v >> 3); } static int -archive_write_cpio_finish(struct archive_write *a) +archive_write_cpio_close(struct archive_write *a) { - struct cpio *cpio; - int er; - struct archive_entry *trailer; - - cpio = (struct cpio *)a->format_data; - trailer = archive_entry_new(); - /* nlink = 1 here for GNU cpio compat. */ - archive_entry_set_nlink(trailer, 1); - archive_entry_set_pathname(trailer, "TRAILER!!!"); - er = archive_write_cpio_header(a, trailer); - archive_entry_free(trailer); - return (er); + int er; + struct archive_entry *trailer; + + trailer = archive_entry_new2(NULL); + /* nlink = 1 here for GNU cpio compat. */ + archive_entry_set_nlink(trailer, 1); + archive_entry_set_size(trailer, 0); + archive_entry_set_pathname(trailer, "TRAILER!!!"); + er = write_header(a, trailer); + archive_entry_free(trailer); + return (er); } static int -archive_write_cpio_destroy(struct archive_write *a) +archive_write_cpio_free(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio; - cpio = (struct cpio *)a->format_data; - free(cpio); - a->format_data = NULL; - return (ARCHIVE_OK); + cpio = (struct cpio *)a->format_data; + free(cpio->ino_list); + free(cpio); + a->format_data = NULL; + return (ARCHIVE_OK); } static int archive_write_cpio_finish_entry(struct archive_write *a) { - struct cpio *cpio; - int to_write, ret; - - cpio = (struct cpio *)a->format_data; - ret = ARCHIVE_OK; - while (cpio->entry_bytes_remaining > 0) { - to_write = cpio->entry_bytes_remaining < a->null_length ? - cpio->entry_bytes_remaining : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - cpio->entry_bytes_remaining -= to_write; - } - return (ret); + struct cpio *cpio; + + cpio = (struct cpio *)a->format_data; + return (__archive_write_nulls(a, cpio->entry_bytes_remaining)); } 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 c8a188241..d06c391a8 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_cpio_newc.c @@ -25,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_cpio_newc.c,v 1.4 2008/03/15 11:04:45 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_cpio_newc.c 201160 2009-12-29 05:41:57Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -40,43 +40,64 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_cpio_newc.c,v 1. #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_write_private.h" -static ssize_t archive_write_newc_data(struct archive_write *, - const void *buff, size_t s); -static int archive_write_newc_finish(struct archive_write *); -static int archive_write_newc_destroy(struct archive_write *); -static int archive_write_newc_finish_entry(struct archive_write *); -static int archive_write_newc_header(struct archive_write *, - struct archive_entry *); -static int format_hex(int64_t, void *, int); -static int64_t format_hex_recursive(int64_t, char *, int); +static ssize_t archive_write_newc_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_newc_close(struct archive_write *); +static int archive_write_newc_free(struct archive_write *); +static int archive_write_newc_finish_entry(struct archive_write *); +static int archive_write_newc_header(struct archive_write *, + struct archive_entry *); +static int archive_write_newc_options(struct archive_write *, + const char *, const char *); +static int format_hex(int64_t, void *, int); +static int64_t format_hex_recursive(int64_t, char *, int); +static int write_header(struct archive_write *, struct archive_entry *); struct cpio { - uint64_t entry_bytes_remaining; - int padding; -}; + uint64_t entry_bytes_remaining; + int padding; -struct cpio_header_newc { - char c_magic[6]; - char c_ino[8]; - char c_mode[8]; - char c_uid[8]; - char c_gid[8]; - char c_nlink[8]; - char c_mtime[8]; - char c_filesize[8]; - char c_devmajor[8]; - char c_devminor[8]; - char c_rdevmajor[8]; - char c_rdevminor[8]; - char c_namesize[8]; - char c_checksum[8]; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; }; +#define c_magic_offset 0 +#define c_magic_size 6 +#define c_ino_offset 6 +#define c_ino_size 8 +#define c_mode_offset 14 +#define c_mode_size 8 +#define c_uid_offset 22 +#define c_uid_size 8 +#define c_gid_offset 30 +#define c_gid_size 8 +#define c_nlink_offset 38 +#define c_nlink_size 8 +#define c_mtime_offset 46 +#define c_mtime_size 8 +#define c_filesize_offset 54 +#define c_filesize_size 8 +#define c_devmajor_offset 62 +#define c_devmajor_size 8 +#define c_devminor_offset 70 +#define c_devminor_size 8 +#define c_rdevmajor_offset 78 +#define c_rdevmajor_size 8 +#define c_rdevminor_offset 86 +#define c_rdevminor_size 8 +#define c_namesize_offset 94 +#define c_namesize_size 8 +#define c_checksum_offset 102 +#define c_checksum_size 8 +#define c_header_size 110 + /* Logic trick: difference between 'n' and next multiple of 4 */ -#define PAD4(n) (3 & (1 + ~(n))) +#define PAD4(n) (3 & (1 + ~(n))) /* * Set output format to 'cpio' format. @@ -84,131 +105,252 @@ struct cpio_header_newc { int archive_write_set_format_cpio_newc(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct cpio *cpio; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - cpio = (struct cpio *)malloc(sizeof(*cpio)); - if (cpio == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); - return (ARCHIVE_FATAL); - } - memset(cpio, 0, sizeof(*cpio)); - a->format_data = cpio; - - a->pad_uncompressed = 1; - a->format_name = "cpio"; - a->format_write_header = archive_write_newc_header; - a->format_write_data = archive_write_newc_data; - a->format_finish_entry = archive_write_newc_finish_entry; - a->format_finish = archive_write_newc_finish; - a->format_destroy = archive_write_newc_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; - a->archive.archive_format_name = "SVR4 cpio nocrc"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct cpio *cpio; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_cpio_newc"); + + /* If someone else was already registered, unregister them. */ + if (a->format_free != NULL) + (a->format_free)(a); + + cpio = (struct cpio *)malloc(sizeof(*cpio)); + if (cpio == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate cpio data"); + return (ARCHIVE_FATAL); + } + memset(cpio, 0, sizeof(*cpio)); + a->format_data = cpio; + a->format_name = "cpio"; + a->format_options = archive_write_newc_options; + a->format_write_header = archive_write_newc_header; + a->format_write_data = archive_write_newc_data; + a->format_finish_entry = archive_write_newc_finish_entry; + a->format_close = archive_write_newc_close; + a->format_free = archive_write_newc_free; + a->archive.archive_format = ARCHIVE_FORMAT_CPIO_SVR4_NOCRC; + a->archive.archive_format_name = "SVR4 cpio nocrc"; + return (ARCHIVE_OK); +} + +static int +archive_write_newc_options(struct archive_write *a, const char *key, + const char *val) +{ + struct cpio *cpio = (struct cpio *)a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: hdrcharset option needs a character-set name", + a->format_name); + else { + cpio->opt_sconv = archive_string_conversion_to_charset( + &a->archive, val, 0); + if (cpio->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: unknown keyword ``%s''", a->format_name, key); + + return (ret); +} + +static struct archive_string_conv * +get_sconv(struct archive_write *a) +{ + struct cpio *cpio; + struct archive_string_conv *sconv; + + cpio = (struct cpio *)a->format_data; + sconv = cpio->opt_sconv; + if (sconv == NULL) { + if (!cpio->init_default_conversion) { + cpio->sconv_default = + archive_string_default_conversion_for_write( + &(a->archive)); + cpio->init_default_conversion = 1; + } + sconv = cpio->sconv_default; + } + return (sconv); } static int archive_write_newc_header(struct archive_write *a, struct archive_entry *entry) { - struct cpio *cpio; - const char *p, *path; - int pathlength, ret; - struct cpio_header_newc h; - int pad; - - cpio = (struct cpio *)a->format_data; - ret = 0; - - path = archive_entry_pathname(entry); - pathlength = strlen(path) + 1; /* Include trailing null. */ - - memset(&h, 0, sizeof(h)); - format_hex(0x070701, &h.c_magic, sizeof(h.c_magic)); - format_hex(archive_entry_devmajor(entry), &h.c_devmajor, sizeof(h.c_devmajor)); - format_hex(archive_entry_devminor(entry), &h.c_devminor, sizeof(h.c_devminor)); - if (archive_entry_ino64(entry) > 0xffffffff) { - archive_set_error(&a->archive, ERANGE, "large inode number truncated"); - ret = ARCHIVE_WARN; - } - - format_hex(archive_entry_ino64(entry) & 0xffffffff, &h.c_ino, sizeof(h.c_ino)); - format_hex(archive_entry_mode(entry), &h.c_mode, sizeof(h.c_mode)); - format_hex(archive_entry_uid(entry), &h.c_uid, sizeof(h.c_uid)); - format_hex(archive_entry_gid(entry), &h.c_gid, sizeof(h.c_gid)); - format_hex(archive_entry_nlink(entry), &h.c_nlink, sizeof(h.c_nlink)); - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) { - format_hex(archive_entry_rdevmajor(entry), &h.c_rdevmajor, sizeof(h.c_rdevmajor)); - format_hex(archive_entry_rdevminor(entry), &h.c_rdevminor, sizeof(h.c_rdevminor)); - } else { - format_hex(0, &h.c_rdevmajor, sizeof(h.c_rdevmajor)); - format_hex(0, &h.c_rdevminor, sizeof(h.c_rdevminor)); - } - format_hex(archive_entry_mtime(entry), &h.c_mtime, sizeof(h.c_mtime)); - format_hex(pathlength, &h.c_namesize, sizeof(h.c_namesize)); - format_hex(0, &h.c_checksum, sizeof(h.c_checksum)); - - /* Non-regular files don't store bodies. */ - if (archive_entry_filetype(entry) != AE_IFREG) - archive_entry_set_size(entry, 0); - - /* Symlinks get the link written as the body of the entry. */ - p = archive_entry_symlink(entry); - if (p != NULL && *p != '\0') - format_hex(strlen(p), &h.c_filesize, sizeof(h.c_filesize)); - else - format_hex(archive_entry_size(entry), - &h.c_filesize, sizeof(h.c_filesize)); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* Pad pathname to even length. */ - ret = (a->compressor.write)(a, path, pathlength); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - pad = PAD4(pathlength + sizeof(struct cpio_header_newc)); - if (pad) - ret = (a->compressor.write)(a, "\0\0\0", pad); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - cpio->entry_bytes_remaining = archive_entry_size(entry); - cpio->padding = PAD4(cpio->entry_bytes_remaining); - - /* Write the symlink now. */ - if (p != NULL && *p != '\0') { - ret = (a->compressor.write)(a, p, strlen(p)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - pad = PAD4(strlen(p)); - ret = (a->compressor.write)(a, "\0\0\0", pad); - } - - return (ret); + const char *path; + size_t len; + + if (archive_entry_filetype(entry) == 0) { + archive_set_error(&a->archive, -1, "Filetype required"); + return (ARCHIVE_FAILED); + } + + if (archive_entry_pathname_l(entry, &path, &len, get_sconv(a)) != 0 + && errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + if (len == 0 || path == NULL || path[0] == '\0') { + archive_set_error(&a->archive, -1, "Pathname required"); + return (ARCHIVE_FAILED); + } + + if (archive_entry_hardlink(entry) == NULL + && (!archive_entry_size_is_set(entry) || archive_entry_size(entry) < 0)) { + archive_set_error(&a->archive, -1, "Size required"); + return (ARCHIVE_FAILED); + } + return write_header(a, entry); +} + +static int +write_header(struct archive_write *a, struct archive_entry *entry) +{ + int64_t ino; + struct cpio *cpio; + const char *p, *path; + int pathlength, ret, ret_final; + char h[c_header_size]; + struct archive_string_conv *sconv; + size_t len; + int pad; + + cpio = (struct cpio *)a->format_data; + ret_final = ARCHIVE_OK; + sconv = get_sconv(a); + + ret = archive_entry_pathname_l(entry, &path, &len, sconv); + if (ret != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", + archive_entry_pathname(entry), + archive_string_conversion_charset_name(sconv)); + ret_final = ARCHIVE_WARN; + } + pathlength = (int)len + 1; /* Include trailing null. */ + + memset(h, 0, c_header_size); + format_hex(0x070701, h + c_magic_offset, c_magic_size); + format_hex(archive_entry_devmajor(entry), h + c_devmajor_offset, + c_devmajor_size); + format_hex(archive_entry_devminor(entry), h + c_devminor_offset, + c_devminor_size); + + ino = archive_entry_ino64(entry); + if (ino > 0xffffffff) { + archive_set_error(&a->archive, ERANGE, + "large inode number truncated"); + ret_final = ARCHIVE_WARN; + } + + /* TODO: Set ret_final to ARCHIVE_WARN if any of these overflow. */ + format_hex(ino & 0xffffffff, h + c_ino_offset, c_ino_size); + format_hex(archive_entry_mode(entry), h + c_mode_offset, c_mode_size); + format_hex(archive_entry_uid(entry), h + c_uid_offset, c_uid_size); + format_hex(archive_entry_gid(entry), h + c_gid_offset, c_gid_size); + format_hex(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_hex(archive_entry_rdevmajor(entry), h + c_rdevmajor_offset, c_rdevmajor_size); + format_hex(archive_entry_rdevminor(entry), h + c_rdevminor_offset, c_rdevminor_size); + } else { + format_hex(0, h + c_rdevmajor_offset, c_rdevmajor_size); + format_hex(0, h + c_rdevminor_offset, c_rdevminor_size); + } + format_hex(archive_entry_mtime(entry), h + c_mtime_offset, c_mtime_size); + format_hex(pathlength, h + c_namesize_offset, c_namesize_size); + format_hex(0, h + c_checksum_offset, c_checksum_size); + + /* Non-regular files don't store bodies. */ + if (archive_entry_filetype(entry) != AE_IFREG) + archive_entry_set_size(entry, 0); + + /* Symlinks get the link written as the body of the entry. */ + ret = archive_entry_symlink_l(entry, &p, &len, sconv); + if (ret != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Likname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + archive_entry_symlink(entry), + archive_string_conversion_charset_name(sconv)); + ret_final = ARCHIVE_WARN; + } + if (len > 0 && p != NULL && *p != '\0') + ret = format_hex(strlen(p), h + c_filesize_offset, + c_filesize_size); + else + ret = format_hex(archive_entry_size(entry), + h + c_filesize_offset, c_filesize_size); + if (ret) { + archive_set_error(&a->archive, ERANGE, + "File is too large for this format."); + return (ARCHIVE_FAILED); + } + + ret = __archive_write_output(a, h, c_header_size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Pad pathname to even length. */ + ret = __archive_write_output(a, path, pathlength); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + pad = PAD4(pathlength + c_header_size); + if (pad) { + ret = __archive_write_output(a, "\0\0\0", pad); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + cpio->entry_bytes_remaining = archive_entry_size(entry); + cpio->padding = PAD4(cpio->entry_bytes_remaining); + + /* Write the symlink now. */ + if (p != NULL && *p != '\0') { + ret = __archive_write_output(a, p, strlen(p)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + pad = PAD4(strlen(p)); + ret = __archive_write_output(a, "\0\0\0", pad); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + return (ret_final); } static ssize_t archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) { - struct cpio *cpio; - int ret; - - cpio = (struct cpio *)a->format_data; - if (s > cpio->entry_bytes_remaining) - s = cpio->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - cpio->entry_bytes_remaining -= s; - if (ret >= 0) - return (s); - else - return (ret); + struct cpio *cpio; + int ret; + + cpio = (struct cpio *)a->format_data; + if (s > cpio->entry_bytes_remaining) + s = cpio->entry_bytes_remaining; + + ret = __archive_write_output(a, buff, s); + cpio->entry_bytes_remaining -= s; + if (ret >= 0) + return (s); + else + return (ret); } /* @@ -217,73 +359,62 @@ archive_write_newc_data(struct archive_write *a, const void *buff, size_t s) static int format_hex(int64_t v, void *p, int digits) { - int64_t max; - int ret; - - max = (((int64_t)1) << (digits * 4)) - 1; - if (v >= 0 && v <= max) { - format_hex_recursive(v, (char *)p, digits); - ret = 0; - } else { - format_hex_recursive(max, (char *)p, digits); - ret = -1; - } - return (ret); + int64_t max; + int ret; + + max = (((int64_t)1) << (digits * 4)) - 1; + if (v >= 0 && v <= max) { + format_hex_recursive(v, (char *)p, digits); + ret = 0; + } else { + format_hex_recursive(max, (char *)p, digits); + ret = -1; + } + return (ret); } static int64_t format_hex_recursive(int64_t v, char *p, int s) { - if (s == 0) - return (v); - v = format_hex_recursive(v, p+1, s-1); - *p = "0123456789abcdef"[v & 0xf]; - return (v >>= 4); + if (s == 0) + return (v); + v = format_hex_recursive(v, p+1, s-1); + *p = "0123456789abcdef"[v & 0xf]; + return (v >> 4); } static int -archive_write_newc_finish(struct archive_write *a) +archive_write_newc_close(struct archive_write *a) { - struct cpio *cpio; - int er; - struct archive_entry *trailer; - - cpio = (struct cpio *)a->format_data; - trailer = archive_entry_new(); - archive_entry_set_nlink(trailer, 1); - archive_entry_set_pathname(trailer, "TRAILER!!!"); - er = archive_write_newc_header(a, trailer); - archive_entry_free(trailer); - return (er); + int er; + struct archive_entry *trailer; + + trailer = archive_entry_new(); + archive_entry_set_nlink(trailer, 1); + archive_entry_set_size(trailer, 0); + archive_entry_set_pathname(trailer, "TRAILER!!!"); + /* Bypass the required data checks. */ + er = write_header(a, trailer); + archive_entry_free(trailer); + return (er); } static int -archive_write_newc_destroy(struct archive_write *a) +archive_write_newc_free(struct archive_write *a) { - struct cpio *cpio; + struct cpio *cpio; - cpio = (struct cpio *)a->format_data; - free(cpio); - a->format_data = NULL; - return (ARCHIVE_OK); + cpio = (struct cpio *)a->format_data; + free(cpio); + a->format_data = NULL; + return (ARCHIVE_OK); } static int archive_write_newc_finish_entry(struct archive_write *a) { - struct cpio *cpio; - int to_write, ret; - - cpio = (struct cpio *)a->format_data; - ret = ARCHIVE_OK; - while (cpio->entry_bytes_remaining > 0) { - to_write = cpio->entry_bytes_remaining < a->null_length ? - cpio->entry_bytes_remaining : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - cpio->entry_bytes_remaining -= to_write; - } - ret = (a->compressor.write)(a, a->nulls, cpio->padding); - return (ret); + struct cpio *cpio; + + cpio = (struct cpio *)a->format_data; + return (__archive_write_nulls(a, cpio->entry_bytes_remaining + cpio->padding)); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c new file mode 100644 index 000000000..e091ed23f --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_gnutar.c @@ -0,0 +1,684 @@ +/*- + * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). + * Author: Jonas Gastal + * Copyright (c) 2011 Michihiro NAKAJIMA + * + * 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: head/lib/libarchive/archive_write_set_format_gnu_tar.c 191579 2009-04-27 18:35:03Z gastal $"); + + +#ifdef HAVE_ERRNO_H +#include +#endif +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif + +#include "archive.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_write_private.h" + +struct gnutar { + uint64_t entry_bytes_remaining; + uint64_t entry_padding; + const char * linkname; + size_t linkname_length; + const char * pathname; + size_t pathname_length; + const char * uname; + size_t uname_length; + const char * gname; + size_t gname_length; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; +}; + +/* + * Define structure of GNU tar header. + */ +#define GNUTAR_name_offset 0 +#define GNUTAR_name_size 100 +#define GNUTAR_mode_offset 100 +#define GNUTAR_mode_size 7 +#define GNUTAR_mode_max_size 8 +#define GNUTAR_uid_offset 108 +#define GNUTAR_uid_size 7 +#define GNUTAR_uid_max_size 8 +#define GNUTAR_gid_offset 116 +#define GNUTAR_gid_size 7 +#define GNUTAR_gid_max_size 8 +#define GNUTAR_size_offset 124 +#define GNUTAR_size_size 11 +#define GNUTAR_size_max_size 12 +#define GNUTAR_mtime_offset 136 +#define GNUTAR_mtime_size 11 +#define GNUTAR_mtime_max_size 11 +#define GNUTAR_checksum_offset 148 +#define GNUTAR_checksum_size 8 +#define GNUTAR_typeflag_offset 156 +#define GNUTAR_typeflag_size 1 +#define GNUTAR_linkname_offset 157 +#define GNUTAR_linkname_size 100 +#define GNUTAR_magic_offset 257 +#define GNUTAR_magic_size 6 +#define GNUTAR_version_offset 263 +#define GNUTAR_version_size 2 +#define GNUTAR_uname_offset 265 +#define GNUTAR_uname_size 32 +#define GNUTAR_gname_offset 297 +#define GNUTAR_gname_size 32 +#define GNUTAR_rdevmajor_offset 329 +#define GNUTAR_rdevmajor_size 6 +#define GNUTAR_rdevmajor_max_size 8 +#define GNUTAR_rdevminor_offset 337 +#define GNUTAR_rdevminor_size 6 +#define GNUTAR_rdevminor_max_size 8 + +/* + * A filled-in copy of the header for initialization. + */ +static const char template_header[] = { + /* name: 100 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0, + /* Mode, null termination: 8 bytes */ + '0','0','0','0','0','0', '0','\0', + /* uid, null termination: 8 bytes */ + '0','0','0','0','0','0', '0','\0', + /* gid, null termination: 8 bytes */ + '0','0','0','0','0','0', '0','\0', + /* size, space termation: 12 bytes */ + '0','0','0','0','0','0','0','0','0','0','0', '\0', + /* mtime, space termation: 12 bytes */ + '0','0','0','0','0','0','0','0','0','0','0', '\0', + /* Initial checksum value: 8 spaces */ + ' ',' ',' ',' ',' ',' ',' ',' ', + /* Typeflag: 1 byte */ + '0', /* '0' = regular file */ + /* Linkname: 100 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0, + /* Magic: 8 bytes */ + 'u','s','t','a','r',' ', ' ','\0', + /* Uname: 32 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + /* Gname: 32 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + /* rdevmajor + null padding: 8 bytes */ + '\0','\0','\0','\0','\0','\0', '\0','\0', + /* rdevminor + null padding: 8 bytes */ + '\0','\0','\0','\0','\0','\0', '\0','\0', + /* Padding: 167 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0 +}; + +static int archive_write_gnutar_options(struct archive_write *, + const char *, const char *); +static int archive_format_gnutar_header(struct archive_write *, char h[512], + struct archive_entry *, int tartype); +static int archive_write_gnutar_header(struct archive_write *, + struct archive_entry *entry); +static ssize_t archive_write_gnutar_data(struct archive_write *a, const void *buff, + size_t s); +static int archive_write_gnutar_free(struct archive_write *); +static int archive_write_gnutar_close(struct archive_write *); +static int archive_write_gnutar_finish_entry(struct archive_write *); +static int format_256(int64_t, char *, int); +static int format_number(int64_t, char *, int size, int maxsize); +static int format_octal(int64_t, char *, int); + +/* + * Set output format to 'GNU tar' format. + */ +int +archive_write_set_format_gnutar(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct gnutar *gnutar; + + gnutar = (struct gnutar *)calloc(1, sizeof(*gnutar)); + if (gnutar == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate gnutar data"); + return (ARCHIVE_FATAL); + } + a->format_data = gnutar; + a->format_name = "gnutar"; + a->format_options = archive_write_gnutar_options; + a->format_write_header = archive_write_gnutar_header; + a->format_write_data = archive_write_gnutar_data; + a->format_close = archive_write_gnutar_close; + a->format_free = archive_write_gnutar_free; + a->format_finish_entry = archive_write_gnutar_finish_entry; + a->archive.archive_format = ARCHIVE_FORMAT_TAR_GNUTAR; + a->archive.archive_format_name = "GNU tar"; + return (ARCHIVE_OK); +} + +static int +archive_write_gnutar_options(struct archive_write *a, const char *key, + const char *val) +{ + struct gnutar *gnutar = (struct gnutar *)a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: hdrcharset option needs a character-set name", + a->format_name); + else { + gnutar->opt_sconv = archive_string_conversion_to_charset( + &a->archive, val, 0); + if (gnutar->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: unknown keyword ``%s''", a->format_name, key); + + return (ret); +} + +static int +archive_write_gnutar_close(struct archive_write *a) +{ + return (__archive_write_nulls(a, 512*2)); +} + +static int +archive_write_gnutar_free(struct archive_write *a) +{ + struct gnutar *gnutar; + + gnutar = (struct gnutar *)a->format_data; + free(gnutar); + a->format_data = NULL; + return (ARCHIVE_OK); +} + +static int +archive_write_gnutar_finish_entry(struct archive_write *a) +{ + struct gnutar *gnutar; + int ret; + + gnutar = (struct gnutar *)a->format_data; + ret = __archive_write_nulls(a, + gnutar->entry_bytes_remaining + gnutar->entry_padding); + gnutar->entry_bytes_remaining = gnutar->entry_padding = 0; + return (ret); +} + +static ssize_t +archive_write_gnutar_data(struct archive_write *a, const void *buff, size_t s) +{ + struct gnutar *gnutar; + int ret; + + gnutar = (struct gnutar *)a->format_data; + if (s > gnutar->entry_bytes_remaining) + s = gnutar->entry_bytes_remaining; + ret = __archive_write_output(a, buff, s); + gnutar->entry_bytes_remaining -= s; + if (ret != ARCHIVE_OK) + return (ret); + return (s); +} + +static int +archive_write_gnutar_header(struct archive_write *a, + struct archive_entry *entry) +{ + char buff[512]; + int r, ret, ret2 = ARCHIVE_OK; + int tartype; + struct gnutar *gnutar; + struct archive_string_conv *sconv; + + gnutar = (struct gnutar *)a->format_data; + + /* Setup default string conversion. */ + if (gnutar->opt_sconv == NULL) { + if (!gnutar->init_default_conversion) { + gnutar->sconv_default = + archive_string_default_conversion_for_write( + &(a->archive)); + gnutar->init_default_conversion = 1; + } + sconv = gnutar->sconv_default; + } else + sconv = gnutar->opt_sconv; + + /* Only regular files (not hardlinks) have data. */ + if (archive_entry_hardlink(entry) != NULL || + archive_entry_symlink(entry) != NULL || + !(archive_entry_filetype(entry) == AE_IFREG)) + archive_entry_set_size(entry, 0); + + if (AE_IFDIR == archive_entry_filetype(entry)) { + const char *p; + char *t; + /* + * Ensure a trailing '/'. Modify the entry so + * the client sees the change. + */ + p = archive_entry_pathname(entry); + if (p[strlen(p) - 1] != '/') { + t = (char *)malloc(strlen(p) + 2); + if (t == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate gnutar data"); + return(ARCHIVE_FATAL); + } + strcpy(t, p); + strcat(t, "/"); + archive_entry_copy_pathname(entry, t); + free(t); + } + } + + r = archive_entry_pathname_l(entry, &(gnutar->pathname), + &(gnutar->pathname_length), sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathame"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", + archive_entry_pathname(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + r = archive_entry_uname_l(entry, &(gnutar->uname), + &(gnutar->uname_length), sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate uname '%s' to %s", + archive_entry_uname(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + r = archive_entry_gname_l(entry, &(gnutar->gname), + &(gnutar->gname_length), sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate gname '%s' to %s", + archive_entry_gname(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + + /* If linkname is longer than 100 chars we need to add a 'K' header. */ + r = archive_entry_hardlink_l(entry, &(gnutar->linkname), + &(gnutar->linkname_length), sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + archive_entry_hardlink(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + if (gnutar->linkname_length == 0) { + r = archive_entry_symlink_l(entry, &(gnutar->linkname), + &(gnutar->linkname_length), sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + archive_entry_hardlink(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + } + if (gnutar->linkname_length > GNUTAR_linkname_size) { + size_t todo = gnutar->linkname_length; + struct archive_entry *temp = archive_entry_new2(&a->archive); + + /* Uname/gname here don't really matter since noone reads them; + * these are the values that GNU tar happens to use on FreeBSD. */ + archive_entry_set_uname(temp, "root"); + archive_entry_set_gname(temp, "wheel"); + + archive_entry_set_pathname(temp, "././@LongLink"); + archive_entry_set_size(temp, gnutar->linkname_length + 1); + ret = archive_format_gnutar_header(a, buff, temp, 'K'); + if (ret < ARCHIVE_WARN) + return (ret); + ret = __archive_write_output(a, buff, 512); + if(ret < ARCHIVE_WARN) + return (ret); + archive_entry_free(temp); + /* Write as many 512 bytes blocks as needed to write full name. */ + ret = __archive_write_output(a, gnutar->linkname, todo); + if(ret < ARCHIVE_WARN) + return (ret); + ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)todo)); + if (ret < ARCHIVE_WARN) + return (ret); + } + + /* If pathname is longer than 100 chars we need to add an 'L' header. */ + if (gnutar->pathname_length > GNUTAR_name_size) { + const char *pathname = gnutar->pathname; + size_t todo = gnutar->pathname_length; + struct archive_entry *temp = archive_entry_new2(&a->archive); + + /* Uname/gname here don't really matter since noone reads them; + * these are the values that GNU tar happens to use on FreeBSD. */ + archive_entry_set_uname(temp, "root"); + archive_entry_set_gname(temp, "wheel"); + + archive_entry_set_pathname(temp, "././@LongLink"); + archive_entry_set_size(temp, gnutar->pathname_length + 1); + ret = archive_format_gnutar_header(a, buff, temp, 'L'); + if (ret < ARCHIVE_WARN) + return (ret); + ret = __archive_write_output(a, buff, 512); + if(ret < ARCHIVE_WARN) + return (ret); + archive_entry_free(temp); + /* Write as many 512 bytes blocks as needed to write full name. */ + ret = __archive_write_output(a, pathname, todo); + if(ret < ARCHIVE_WARN) + return (ret); + ret = __archive_write_nulls(a, 0x1ff & (-(ssize_t)todo)); + if (ret < ARCHIVE_WARN) + return (ret); + } + + if (archive_entry_hardlink(entry) != NULL) { + tartype = '1'; + } else + switch (archive_entry_filetype(entry)) { + case AE_IFREG: tartype = '0' ; break; + case AE_IFLNK: tartype = '2' ; break; + case AE_IFCHR: tartype = '3' ; break; + case AE_IFBLK: tartype = '4' ; break; + case AE_IFDIR: tartype = '5' ; break; + case AE_IFIFO: tartype = '6' ; break; + case AE_IFSOCK: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive socket"); + return (ARCHIVE_FAILED); + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive this (mode=0%lo)", + (unsigned long)archive_entry_mode(entry)); + return (ARCHIVE_FAILED); + } + + ret = archive_format_gnutar_header(a, buff, entry, tartype); + if (ret < ARCHIVE_WARN) + return (ret); + if (ret2 < ret) + ret = ret2; + ret2 = __archive_write_output(a, buff, 512); + if (ret2 < ARCHIVE_WARN) + return (ret2); + if (ret2 < ret) + ret = ret2; + + gnutar->entry_bytes_remaining = archive_entry_size(entry); + gnutar->entry_padding = 0x1ff & (-(int64_t)gnutar->entry_bytes_remaining); + return (ret); +} + +static int +archive_format_gnutar_header(struct archive_write *a, char h[512], + struct archive_entry *entry, int tartype) +{ + unsigned int checksum; + int i, ret; + size_t copy_length; + const char *p; + struct gnutar *gnutar; + + gnutar = (struct gnutar *)a->format_data; + + ret = 0; + + /* + * The "template header" already includes the signature, + * various end-of-field markers, and other required elements. + */ + memcpy(h, &template_header, 512); + + /* + * Because the block is already null-filled, and strings + * are allowed to exactly fill their destination (without null), + * I use memcpy(dest, src, strlen()) here a lot to copy strings. + */ + + if (tartype == 'K' || tartype == 'L') { + p = archive_entry_pathname(entry); + copy_length = strlen(p); + } else { + p = gnutar->pathname; + copy_length = gnutar->pathname_length; + } + if (copy_length > GNUTAR_name_size) + copy_length = GNUTAR_name_size; + memcpy(h + GNUTAR_name_offset, p, copy_length); + + if ((copy_length = gnutar->linkname_length) > 0) { + if (copy_length > GNUTAR_linkname_size) + copy_length = GNUTAR_linkname_size; + memcpy(h + GNUTAR_linkname_offset, gnutar->linkname, + copy_length); + } + + /* TODO: How does GNU tar handle unames longer than GNUTAR_uname_size? */ + if (tartype == 'K' || tartype == 'L') { + p = archive_entry_uname(entry); + copy_length = strlen(p); + } else { + p = gnutar->uname; + copy_length = gnutar->uname_length; + } + if (copy_length > 0) { + if (copy_length > GNUTAR_uname_size) + copy_length = GNUTAR_uname_size; + memcpy(h + GNUTAR_uname_offset, p, copy_length); + } + + /* TODO: How does GNU tar handle gnames longer than GNUTAR_gname_size? */ + if (tartype == 'K' || tartype == 'L') { + p = archive_entry_gname(entry); + copy_length = strlen(p); + } else { + p = gnutar->gname; + copy_length = gnutar->gname_length; + } + if (copy_length > 0) { + if (strlen(p) > GNUTAR_gname_size) + copy_length = GNUTAR_gname_size; + memcpy(h + GNUTAR_gname_offset, p, copy_length); + } + + /* By truncating the mode here, we ensure it always fits. */ + format_octal(archive_entry_mode(entry) & 07777, + h + GNUTAR_mode_offset, GNUTAR_mode_size); + + /* TODO: How does GNU tar handle large UIDs? */ + if (format_octal(archive_entry_uid(entry), + h + GNUTAR_uid_offset, GNUTAR_uid_size)) { + archive_set_error(&a->archive, ERANGE, + "Numeric user ID %jd too large", + (intmax_t)archive_entry_uid(entry)); + ret = ARCHIVE_FAILED; + } + + /* TODO: How does GNU tar handle large GIDs? */ + if (format_octal(archive_entry_gid(entry), + h + GNUTAR_gid_offset, GNUTAR_gid_size)) { + archive_set_error(&a->archive, ERANGE, + "Numeric group ID %jd too large", + (intmax_t)archive_entry_gid(entry)); + ret = ARCHIVE_FAILED; + } + + /* GNU tar supports base-256 here, so should never overflow. */ + if (format_number(archive_entry_size(entry), h + GNUTAR_size_offset, + GNUTAR_size_size, GNUTAR_size_max_size)) { + archive_set_error(&a->archive, ERANGE, + "File size out of range"); + ret = ARCHIVE_FAILED; + } + + /* Shouldn't overflow before 2106, since mtime field is 33 bits. */ + format_octal(archive_entry_mtime(entry), + h + GNUTAR_mtime_offset, GNUTAR_mtime_size); + + if (archive_entry_filetype(entry) == AE_IFBLK + || archive_entry_filetype(entry) == AE_IFCHR) { + if (format_octal(archive_entry_rdevmajor(entry), + h + GNUTAR_rdevmajor_offset, + GNUTAR_rdevmajor_size)) { + archive_set_error(&a->archive, ERANGE, + "Major device number too large"); + ret = ARCHIVE_FAILED; + } + + if (format_octal(archive_entry_rdevminor(entry), + h + GNUTAR_rdevminor_offset, + GNUTAR_rdevminor_size)) { + archive_set_error(&a->archive, ERANGE, + "Minor device number too large"); + ret = ARCHIVE_FAILED; + } + } + + h[GNUTAR_typeflag_offset] = tartype; + + checksum = 0; + for (i = 0; i < 512; i++) + checksum += 255 & (unsigned int)h[i]; + h[GNUTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */ + /* h[GNUTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */ + format_octal(checksum, h + GNUTAR_checksum_offset, 6); + return (ret); +} + +/* + * Format a number into a field, falling back to base-256 if necessary. + */ +static int +format_number(int64_t v, char *p, int s, int maxsize) +{ + int64_t limit = ((int64_t)1 << (s*3)); + + if (v < limit) + return (format_octal(v, p, s)); + return (format_256(v, p, maxsize)); +} + +/* + * Format a number into the specified field using base-256. + */ +static int +format_256(int64_t v, char *p, int s) +{ + p += s; + while (s-- > 0) { + *--p = (char)(v & 0xff); + v >>= 8; + } + *p |= 0x80; /* Set the base-256 marker bit. */ + return (0); +} + +/* + * Format a number into the specified field using octal. + */ +static int +format_octal(int64_t v, char *p, int s) +{ + int len = s; + + /* Octal values can't be negative, so use 0. */ + if (v < 0) + v = 0; + + p += s; /* Start at the end and work backwards. */ + while (s-- > 0) { + *--p = (char)('0' + (v & 7)); + v >>= 3; + } + + if (v == 0) + return (0); + + /* If it overflowed, fill field with max value. */ + while (len-- > 0) + *p++ = '7'; + + return (-1); +} diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c new file mode 100644 index 000000000..87136a67d --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_iso9660.c @@ -0,0 +1,8114 @@ +/*- + * Copyright (c) 2009-2011 Michihiro NAKAJIMA + * 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" + +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_UTSNAME_H +#include +#endif +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#include +#include +#ifdef HAVE_STDLIB_H +#include +#endif +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_rb.h" +#include "archive_write_private.h" + +#if defined(_WIN32) && !defined(__CYGWIN__) +#define getuid() 0 +#define getgid() 0 +#endif + +/*#define DEBUG 1*/ +#ifdef DEBUG +/* To compare to the ISO image file made by mkisofs. */ +#define COMPAT_MKISOFS 1 +#endif + +#define LOGICAL_BLOCK_BITS 11 +#define LOGICAL_BLOCK_SIZE 2048 +#define PATH_TABLE_BLOCK_SIZE 4096 + +#define SYSTEM_AREA_BLOCK 16 +#define PRIMARY_VOLUME_DESCRIPTOR_BLOCK 1 +#define SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK 1 +#define BOOT_RECORD_DESCRIPTOR_BLOCK 1 +#define VOLUME_DESCRIPTOR_SET_TERMINATOR_BLOCK 1 +#define NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK 1 +#define RRIP_ER_BLOCK 1 +#define PADDING_BLOCK 150 + +#define FD_1_2M_SIZE (1024 * 1200) +#define FD_1_44M_SIZE (1024 * 1440) +#define FD_2_88M_SIZE (1024 * 2880) +#define MULTI_EXTENT_SIZE (ARCHIVE_LITERAL_LL(1) << 32) /* 4Gi bytes. */ +#define MAX_DEPTH 8 +#define RR_CE_SIZE 28 /* SUSP "CE" extension size */ + +#define FILE_FLAG_EXISTENCE 0x01 +#define FILE_FLAG_DIRECTORY 0x02 +#define FILE_FLAG_ASSOCIATED 0x04 +#define FILE_FLAG_RECORD 0x08 +#define FILE_FLAG_PROTECTION 0x10 +#define FILE_FLAG_MULTI_EXTENT 0x80 + +static const char rrip_identifier[] = + "RRIP_1991A"; +static const char rrip_descriptor[] = + "THE ROCK RIDGE INTERCHANGE PROTOCOL PROVIDES SUPPORT FOR " + "POSIX FILE SYSTEM SEMANTICS"; +static const char rrip_source[] = + "PLEASE CONTACT DISC PUBLISHER FOR SPECIFICATION SOURCE. " + "SEE PUBLISHER IDENTIFIER IN PRIMARY VOLUME DESCRIPTOR FOR " + "CONTACT INFORMATION."; +#define RRIP_ER_ID_SIZE (sizeof(rrip_identifier)-1) +#define RRIP_ER_DSC_SIZE (sizeof(rrip_descriptor)-1) +#define RRIP_ER_SRC_SIZE (sizeof(rrip_source)-1) +#define RRIP_ER_SIZE (8 + RRIP_ER_ID_SIZE + \ + RRIP_ER_DSC_SIZE + RRIP_ER_SRC_SIZE) + +static const unsigned char zisofs_magic[8] = { + 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 +}; + +#define ZF_HEADER_SIZE 16 /* zisofs header size. */ +#define ZF_LOG2_BS 15 /* log2 block size; 32K bytes. */ +#define ZF_BLOCK_SIZE (1UL << ZF_LOG2_BS) + +/* + * Manage extra records. + */ +struct extr_rec { + int location; + int offset; + unsigned char buf[LOGICAL_BLOCK_SIZE]; + struct extr_rec *next; +}; + +struct ctl_extr_rec { + int use_extr; + unsigned char *bp; + struct isoent *isoent; + unsigned char *ce_ptr; + int cur_len; + int dr_len; + int limit; + int extr_off; + int extr_loc; +}; +#define DR_SAFETY RR_CE_SIZE +#define DR_LIMIT (254 - DR_SAFETY) + +/* + * The relation of struct isofile and isoent and archive_entry. + * + * Primary volume tree --> struct isoent + * | + * v + * struct isofile --> archive_entry + * ^ + * | + * Joliet volume tree --> struct isoent + * + * struct isoent has specific information for volume. + */ + +struct isofile { + /* Used for managing struct isofile list. */ + struct isofile *allnext; + struct isofile *datanext; + /* Used for managing a hardlined struct isofile list. */ + struct isofile *hlnext; + struct isofile *hardlink_target; + + struct archive_entry *entry; + + /* + * Used for making a directory tree. + */ + struct archive_string parentdir; + struct archive_string basename; + struct archive_string basename_utf16; + struct archive_string symlink; + int dircnt; /* The number of elements of + * its parent directory */ + + /* + * Used for a Directory Record. + */ + struct content { + int64_t offset_of_temp; + int64_t size; + int blocks; + uint32_t location; + /* + * One extent equals one content. + * If this entry has multi extent, `next' variable points + * next content data. + */ + struct content *next; /* next content */ + } content, *cur_content; + int write_content; + + enum { + NO = 0, + BOOT_CATALOG, + BOOT_IMAGE, + } boot; + + /* + * Used for a zisofs. + */ + struct { + unsigned char header_size; + unsigned char log2_bs; + uint32_t uncompressed_size; + } zisofs; +}; + +struct isoent { + /* Keep `rbnode' at the first member of struct isoent. */ + struct archive_rb_node rbnode; + + struct isofile *file; + + struct isoent *parent; + /* A list of children.(use chnext) */ + struct { + struct isoent *first; + struct isoent **last; + int cnt; + } children; + struct archive_rb_tree rbtree; + + /* A list of sub directories.(use drnext) */ + struct { + struct isoent *first; + struct isoent **last; + int cnt; + } subdirs; + /* A sorted list of sub directories. */ + struct isoent **children_sorted; + /* Used for managing struct isoent list. */ + struct isoent *chnext; + struct isoent *drnext; + struct isoent *ptnext; + + /* + * Used for making a Directory Record. + */ + int dir_number; + struct { + int vd; + int self; + int parent; + int normal; + } dr_len; + uint32_t dir_location; + int dir_block; + + /* + * Identifier: + * on primary, ISO9660 file/directory name. + * on joliet, UCS2 file/directory name. + * ext_off : offset of identifier extension. + * ext_len : length of identifier extension. + * id_len : byte size of identifier. + * on primary, this is ext_off + ext_len + version length. + * on joliet, this is ext_off + ext_len. + * mb_len : length of multibyte-character of identifier. + * on primary, mb_len and id_len are always the same. + * on joliet, mb_len and id_len are different. + */ + char *identifier; + int ext_off; + int ext_len; + int id_len; + int mb_len; + + /* + * Used for making a Rockridge extension. + * This is a part of Directory Records. + */ + struct isoent *rr_parent; + struct isoent *rr_child; + + /* Extra Record.(which we call in this source file) + * A maximum size of the Directory Record is 254. + * so, if generated RRIP data of a file cannot into a Directory + * Record because of its size, that surplus data relocate this + * Extra Record. + */ + struct { + struct extr_rec *first; + struct extr_rec **last; + struct extr_rec *current; + } extr_rec_list; + + int virtual:1; + /* If set to one, this file type is a directory. + * A convenience flag to be used as + * "archive_entry_filetype(isoent->file->entry) == AE_IFDIR". + */ + int dir:1; +}; + +struct hardlink { + struct archive_rb_node rbnode; + int nlink; + struct { + struct isofile *first; + struct isofile **last; + } file_list; +}; + +/* + * ISO writer options + */ +struct iso_option { + /* + * Usage : abstract-file= + * Type : string, max 37 bytes + * Default: Not specified + * COMPAT : mkisofs -abstract + * + * Specifies Abstract Filename. + * This file shall be described in the Root Directory + * and containing a abstract statement. + */ + unsigned int abstract_file:1; +#define OPT_ABSTRACT_FILE_DEFAULT 0 /* Not specified */ +#define ABSTRACT_FILE_SIZE 37 + + /* + * Usage : application-id= + * Type : string, max 128 bytes + * Default: Not specified + * COMPAT : mkisofs -A/-appid . + * + * Specifies Application Identifier. + * If the first byte is set to '_'(5F), the remaining + * bytes of this option shall specify an identifier + * for a file containing the identification of the + * application. + * This file shall be described in the Root Directory. + */ + unsigned int application_id:1; +#define OPT_APPLICATION_ID_DEFAULT 0 /* Use default identifier */ +#define APPLICATION_IDENTIFIER_SIZE 128 + + /* + * Usage : !allow-vernum + * Type : boolean + * Default: Enabled + * : Violates the ISO9660 standard if disable. + * COMPAT: mkisofs -N + * + * Allow filenames to use version numbers. + */ + unsigned int allow_vernum:1; +#define OPT_ALLOW_VERNUM_DEFAULT 1 /* Enabled */ + + /* + * Usage : biblio-file= + * Type : string, max 37 bytes + * Default: Not specified + * COMPAT : mkisofs -biblio + * + * Specifies Bibliographic Filename. + * This file shall be described in the Root Directory + * and containing bibliographic records. + */ + unsigned int biblio_file:1; +#define OPT_BIBLIO_FILE_DEFAULT 0 /* Not specified */ +#define BIBLIO_FILE_SIZE 37 + + /* + * Usage : boot= + * Type : string + * Default: Not specified + * COMPAT : mkisofs -b/-eltorito-boot + * + * Specifies "El Torito" boot image file to make + * a bootable CD. + */ + unsigned int boot:1; +#define OPT_BOOT_DEFAULT 0 /* Not specified */ + + /* + * Usage : boot-catalog= + * Type : string + * Default: "boot.catalog" + * COMPAT : mkisofs -c/-eltorito-catalog + * + * Specifies a fullpath of El Torito boot catalog. + */ + unsigned int boot_catalog:1; +#define OPT_BOOT_CATALOG_DEFAULT 0 /* Not specified */ + + /* + * Usage : boot-info-table + * Type : boolean + * Default: Disabled + * COMPAT : mkisofs -boot-info-table + * + * Modify the boot image file specified by `boot' + * option; ISO writer stores boot file information + * into the boot file in ISO image at offset 8 + * through offset 64. + */ + unsigned int boot_info_table:1; +#define OPT_BOOT_INFO_TABLE_DEFAULT 0 /* Disabled */ + + /* + * Usage : boot-load-seg= + * Type : hexadecimal + * Default: Not specified + * COMPAT : mkisofs -boot-load-seg + * + * Specifies a load segment for boot image. + * This is used with no-emulation mode. + */ + unsigned int boot_load_seg:1; +#define OPT_BOOT_LOAD_SEG_DEFAULT 0 /* Not specified */ + + /* + * Usage : boot-load-size= + * Type : decimal + * Default: Not specified + * COMPAT : mkisofs -boot-load-size + * + * Specifies a sector count for boot image. + * This is used with no-emulation mode. + */ + unsigned int boot_load_size:1; +#define OPT_BOOT_LOAD_SIZE_DEFAULT 0 /* Not specified */ + + /* + * Usage : boot-type= + * : 'no-emulation' : 'no emulation' image + * : 'fd' : floppy disk image + * : 'hard-disk' : hard disk image + * Type : string + * Default: Auto detect + * : We check a size of boot image; + * : If ths size is just 1.22M/1.44M/2.88M, + * : we assume boot_type is 'fd'; + * : otherwise boot_type is 'no-emulation'. + * COMPAT : + * boot=no-emulation + * mkisofs -no-emul-boot + * boot=fd + * This is a default on the mkisofs. + * boot=hard-disk + * mkisofs -hard-disk-boot + * + * Specifies a type of "El Torito" boot image. + */ + unsigned int boot_type:2; +#define OPT_BOOT_TYPE_AUTO 0 /* auto detect */ +#define OPT_BOOT_TYPE_NO_EMU 1 /* ``no emulation'' image */ +#define OPT_BOOT_TYPE_FD 2 /* floppy disk image */ +#define OPT_BOOT_TYPE_HARD_DISK 3 /* hard disk image */ +#define OPT_BOOT_TYPE_DEFAULT OPT_BOOT_TYPE_AUTO + + /* + * Usage : compression-level= + * Type : decimal + * Default: Not specified + * COMPAT : NONE + * + * Specifies compression level for option zisofs=direct. + */ + unsigned int compression_level:1; +#define OPT_COMPRESSION_LEVEL_DEFAULT 0 /* Not specified */ + + /* + * Usage : copyright-file= + * Type : string, max 37 bytes + * Default: Not specified + * COMPAT : mkisofs -copyright + * + * Specifies Copyright Filename. + * This file shall be described in the Root Directory + * and containing a copyright statement. + */ + unsigned int copyright_file:1; +#define OPT_COPYRIGHT_FILE_DEFAULT 0 /* Not specified */ +#define COPYRIGHT_FILE_SIZE 37 + + /* + * Usage : gid= + * Type : decimal + * Default: Not specified + * COMPAT : mkisofs -gid + * + * Specifies a group id to rewrite the group id of all files. + */ + unsigned int gid:1; +#define OPT_GID_DEFAULT 0 /* Not specified */ + + /* + * Usage : iso-level=[1234] + * Type : decimal + * Default: 1 + * COMPAT : mkisofs -iso-level + * + * Specifies ISO9600 Level. + * Level 1: [DEFAULT] + * - limits each file size less than 4Gi bytes; + * - a File Name shall not contain more than eight + * d-characters or eight d1-characters; + * - a File Name Extension shall not contain more than + * three d-characters or three d1-characters; + * - a Directory Identifier shall not contain more + * than eight d-characters or eight d1-characters. + * Level 2: + * - limits each file size less than 4Giga bytes; + * - a File Name shall not contain more than thirty + * d-characters or thirty d1-characters; + * - a File Name Extension shall not contain more than + * thirty d-characters or thirty d1-characters; + * - a Directory Identifier shall not contain more + * than thirty-one d-characters or thirty-one + * d1-characters. + * Level 3: + * - no limit of file size; use multi extent. + * Level 4: + * - this level 4 simulates mkisofs option + * '-iso-level 4'; + * - crate a enhanced volume as mkisofs doing; + * - allow a File Name to have leading dot; + * - allow a File Name to have all ASCII letters; + * - allow a File Name to have multiple dots; + * - allow more then 8 depths of directory trees; + * - disable a version number to a File Name; + * - disable a forced period to the tail of a File Name; + * - the maxinum length of files and directories is raised to 193. + * if rockridge option is disabled, raised to 207. + */ + unsigned int iso_level:3; +#define OPT_ISO_LEVEL_DEFAULT 1 /* ISO Level 1 */ + + /* + * Usage : joliet[=long] + * : !joliet + * : Do not generate Joliet Volume and Records. + * : joliet [DEFAULT] + * : Generates Joliet Volume and Directory Records. + * : [COMPAT: mkisofs -J/-joliet] + * : joliet=long + * : The joliet filenames are up to 103 Unicode + * : characters. + * : This option breaks the Joliet specification. + * : [COMPAT: mkisofs -J -joliet-long] + * Type : boolean/string + * Default: Enabled + * COMPAT : mkisofs -J / -joliet-long + * + * Generates Joliet Volume and Directory Records. + */ + unsigned int joliet:2; +#define OPT_JOLIET_DISABLE 0 /* Not generate Joliet Records. */ +#define OPT_JOLIET_ENABLE 1 /* Generate Joliet Records. */ +#define OPT_JOLIET_LONGNAME 2 /* Use long joliet filenames.*/ +#define OPT_JOLIET_DEFAULT OPT_JOLIET_ENABLE + + /* + * Usage : !limit-depth + * Type : boolean + * Default: Enabled + * : Violates the ISO9660 standard if disable. + * COMPAT : mkisofs -D/-disable-deep-relocation + * + * The number of levels in hierarchy cannot exceed eight. + */ + unsigned int limit_depth:1; +#define OPT_LIMIT_DEPTH_DEFAULT 1 /* Enabled */ + + /* + * Usage : !limit-dirs + * Type : boolean + * Default: Enabled + * : Violates the ISO9660 standard if disable. + * COMPAT : mkisofs -no-limit-pathtables + * + * Limits the number of directories less than 65536 due + * to the size of the Parent Directory Number of Path + * Table. + */ + unsigned int limit_dirs:1; +#define OPT_LIMIT_DIRS_DEFAULT 1 /* Enabled */ + + /* + * Usage : !pad + * Type : boolean + * Default: Enabled + * COMPAT : -pad/-no-pad + * + * Pads the end of the ISO image by null of 300Ki bytes. + */ + unsigned int pad:1; +#define OPT_PAD_DEFAULT 1 /* Enabled */ + + /* + * Usage : publisher= + * Type : string, max 128 bytes + * Default: Not specified + * COMPAT : mkisofs -publisher + * + * Specifies Publisher Identifier. + * If the first byte is set to '_'(5F), the remaining + * bytes of this option shall specify an identifier + * for a file containing the identification of the user. + * This file shall be described in the Root Directory. + */ + unsigned int publisher:1; +#define OPT_PUBLISHER_DEFAULT 0 /* Not specified */ +#define PUBLISHER_IDENTIFIER_SIZE 128 + + /* + * Usage : rockridge + * : !rockridge + * : disable to generate SUSP and RR records. + * : rockridge + * : the same as 'rockridge=useful'. + * : rockridge=strict + * : generate SUSP and RR records. + * : [COMPAT: mkisofs -R] + * : rockridge=useful [DEFAULT] + * : generate SUSP and RR records. + * : [COMPAT: mkisofs -r] + * : NOTE Our rockridge=useful option does not set a zero + * : to uid and gid, you should use application + * : option such as --gid,--gname,--uid and --uname + * : badtar options instead. + * Type : boolean/string + * Default: Enabled as rockridge=useful + * COMPAT : mkisofs -r / -R + * + * Generates SUSP and RR records. + */ + unsigned int rr:2; +#define OPT_RR_DISABLED 0 +#define OPT_RR_STRICT 1 +#define OPT_RR_USEFUL 2 +#define OPT_RR_DEFAULT OPT_RR_USEFUL + + /* + * Usage : volume-id= + * Type : string, max 32 bytes + * Default: Not specified + * COMPAT : mkisofs -V + * + * Specifies Volume Identifier. + */ + unsigned int volume_id:1; +#define OPT_VOLUME_ID_DEFAULT 0 /* Use default identifier */ +#define VOLUME_IDENTIFIER_SIZE 32 + + /* + * Usage : !zisofs [DEFAULT] + * : Disable to generate RRIP 'ZF' extension. + * : zisofs + * : Make files zisofs file and generate RRIP 'ZF' + * : extension. So you do not need mkzftree utility + * : for making zisofs. + * : When the file size is less than one Logical Block + * : size, that file will not zisofs'ed since it does + * : reduece an ISO-image size. + * : + * : When you specify option 'boot=', that + * : 'boot-image' file won't be converted to zisofs file. + * Type : boolean + * Default: Disabled + * + * Generates RRIP 'ZF' System Use Entry. + */ + unsigned int zisofs:1; +#define OPT_ZISOFS_DISABLED 0 +#define OPT_ZISOFS_DIRECT 1 +#define OPT_ZISOFS_DEFAULT OPT_ZISOFS_DISABLED + +}; + +struct iso9660 { + /* The creation time of ISO image. */ + time_t birth_time; + /* A file stream of a temporary file, which file contents + * save to until ISO iamge can be created. */ + int temp_fd; + + struct isofile *cur_file; + struct isoent *cur_dirent; + struct archive_string cur_dirstr; + uint64_t bytes_remaining; + int need_multi_extent; + + /* Temporary string buffer for Joliet extension. */ + struct archive_string utf16be; + struct archive_string mbs; + + struct archive_string_conv *sconv_to_utf16be; + struct archive_string_conv *sconv_from_utf16be; + + /* A list of all of struct isofile entries. */ + struct { + struct isofile *first; + struct isofile **last; + } all_file_list; + + /* A list of struct isofile entries which have its + * contents and are not a directory, a hardlined file + * and a symlink file. */ + struct { + struct isofile *first; + struct isofile **last; + } data_file_list; + + /* Used for managing to find hardlinking files. */ + struct archive_rb_tree hardlink_rbtree; + + /* Used for making the Path Table Record. */ + struct vdd { + /* the root of entry tree. */ + struct isoent *rootent; + enum vdd_type { + VDD_PRIMARY, + VDD_JOLIET, + VDD_ENHANCED + } vdd_type; + + struct path_table { + struct isoent *first; + struct isoent **last; + struct isoent **sorted; + int cnt; + } *pathtbl; + int max_depth; + + int path_table_block; + int path_table_size; + int location_type_L_path_table; + int location_type_M_path_table; + int total_dir_block; + } primary, joliet; + + /* Used for making a Volume Descriptor. */ + int volume_space_size; + int volume_sequence_number; + int total_file_block; + struct archive_string volume_identifier; + struct archive_string publisher_identifier; + struct archive_string data_preparer_identifier; + struct archive_string application_identifier; + struct archive_string copyright_file_identifier; + struct archive_string abstract_file_identifier; + struct archive_string bibliographic_file_identifier; + + /* Used for making rockridge extensions. */ + int location_rrip_er; + + /* Used for making zisofs. */ + struct { + int detect_magic:1; + int making:1; + int allzero:1; + unsigned char magic_buffer[64]; + int magic_cnt; + +#ifdef HAVE_ZLIB_H + /* + * Copy a compressed file to iso9660.zisofs.temp_fd + * and also copy a uncompressed file(original file) to + * iso9660.temp_fd . If the number of logical block + * of the compressed file is less than the number of + * logical block of the uncompressed file, use it and + * remove the copy of the uncompressed file. + * but if not, we use uncompressed file and remove + * the copy of the compressed file. + */ + uint32_t *block_pointers; + size_t block_pointers_allocated; + int block_pointers_cnt; + int block_pointers_idx; + int64_t total_size; + int64_t block_offset; + + z_stream stream; + int stream_valid; + int64_t remaining; + int compression_level; +#endif + } zisofs; + + struct isoent *directories_too_deep; + int dircnt_max; + + /* Write buffer. */ +#define wb_buffmax() (LOGICAL_BLOCK_SIZE * 32) +#define wb_remaining(a) (((struct iso9660 *)(a)->format_data)->wbuff_remaining) +#define wb_offset(a) (((struct iso9660 *)(a)->format_data)->wbuff_offset \ + + wb_buffmax() - wb_remaining(a)) + unsigned char wbuff[LOGICAL_BLOCK_SIZE * 32]; + size_t wbuff_remaining; + enum { + WB_TO_STREAM, + WB_TO_TEMP + } wbuff_type; + int64_t wbuff_offset; + int64_t wbuff_written; + int64_t wbuff_tail; + + /* 'El Torito' boot data. */ + struct { + /* boot catalog file */ + struct archive_string catalog_filename; + struct isoent *catalog; + /* boot image file */ + struct archive_string boot_filename; + struct isoent *boot; + + unsigned char platform_id; +#define BOOT_PLATFORM_X86 0 +#define BOOT_PLATFORM_PPC 1 +#define BOOT_PLATFORM_MAC 2 + struct archive_string id; + unsigned char media_type; +#define BOOT_MEDIA_NO_EMULATION 0 +#define BOOT_MEDIA_1_2M_DISKETTE 1 +#define BOOT_MEDIA_1_44M_DISKETTE 2 +#define BOOT_MEDIA_2_88M_DISKETTE 3 +#define BOOT_MEDIA_HARD_DISK 4 + unsigned char system_type; + uint16_t boot_load_seg; + uint16_t boot_load_size; +#define BOOT_LOAD_SIZE 4 + } el_torito; + + struct iso_option opt; +}; + +/* + * Types of Volume Descriptor + */ +enum VD_type { + VDT_BOOT_RECORD=0, /* Boot Record Volume Descriptor */ + VDT_PRIMARY=1, /* Primary Volume Descriptor */ + VDT_SUPPLEMENTARY=2, /* Supplementary Volume Descriptor */ + VDT_TERMINATOR=255 /* Volume Descriptor Set Terminator */ +}; + +/* + * Types of Directory Record + */ +enum dir_rec_type { + DIR_REC_VD, /* Stored in Volume Descriptor. */ + DIR_REC_SELF, /* Stored as Current Directory. */ + DIR_REC_PARENT, /* Stored as Parent Directory. */ + DIR_REC_NORMAL, /* Stored as Child. */ +}; + +/* + * Kinds of Volume Descriptor Character + */ +enum vdc { + VDC_STD, + VDC_LOWERCASE, + VDC_UCS2, + VDC_UCS2_DIRECT, +}; + +/* + * IDentifier Resolver. + * Used for resolving duplicated filenames. + */ +struct idr { + struct idrent { + struct archive_rb_node rbnode; + /* Used in wait_list. */ + struct idrent *wnext; + struct idrent *avail; + + struct isoent *isoent; + int weight; + int noff; + int rename_num; + } *idrent_pool; + + struct archive_rb_tree rbtree; + + struct { + struct idrent *first; + struct idrent **last; + } wait_list; + + int pool_size; + int pool_idx; + int num_size; + int null_size; + + char char_map[0x80]; +}; + +enum char_type { + A_CHAR, + D_CHAR, +}; + + +static int iso9660_options(struct archive_write *, + const char *, const char *); +static int iso9660_write_header(struct archive_write *, + struct archive_entry *); +static ssize_t iso9660_write_data(struct archive_write *, + const void *, size_t); +static int iso9660_finish_entry(struct archive_write *); +static int iso9660_close(struct archive_write *); +static int iso9660_free(struct archive_write *); + +static void get_system_identitier(char *, size_t); +static void set_str(unsigned char *, const char *, size_t, char, + const char *); +static inline int joliet_allowed_char(unsigned char, unsigned char); +static int set_str_utf16be(struct archive_write *, unsigned char *, + const char *, size_t, uint16_t, enum vdc); +static int set_str_a_characters_bp(struct archive_write *, + unsigned char *, int, int, const char *, enum vdc); +static int set_str_d_characters_bp(struct archive_write *, + unsigned char *, int, int, const char *, enum vdc); +static void set_VD_bp(unsigned char *, enum VD_type, unsigned char); +static inline void set_unused_field_bp(unsigned char *, int, int); + +static unsigned char *extra_open_record(unsigned char *, int, + struct isoent *, struct ctl_extr_rec *); +static void extra_close_record(struct ctl_extr_rec *, int); +static unsigned char * extra_next_record(struct ctl_extr_rec *, int); +static unsigned char *extra_get_record(struct isoent *, int *, int *, int *); +static void extra_tell_used_size(struct ctl_extr_rec *, int); +static int extra_setup_location(struct isoent *, int); +static int set_directory_record_rr(unsigned char *, int, + struct isoent *, struct iso9660 *, enum dir_rec_type); +static int set_directory_record(unsigned char *, size_t, + struct isoent *, struct iso9660 *, enum dir_rec_type, + enum vdd_type); +static inline int get_dir_rec_size(struct iso9660 *, struct isoent *, + enum dir_rec_type, enum vdd_type); +static inline unsigned char *wb_buffptr(struct archive_write *); +static int wb_write_out(struct archive_write *); +static int wb_consume(struct archive_write *, size_t); +#ifdef HAVE_ZLIB_H +static int wb_set_offset(struct archive_write *, int64_t); +#endif +static int write_null(struct archive_write *, size_t); +static int write_VD_terminator(struct archive_write *); +static int set_file_identifier(unsigned char *, int, int, enum vdc, + struct archive_write *, struct vdd *, + struct archive_string *, const char *, int, + enum char_type); +static int write_VD(struct archive_write *, struct vdd *); +static int write_VD_boot_record(struct archive_write *); +static int write_information_block(struct archive_write *); +static int write_path_table(struct archive_write *, int, + struct vdd *); +static int write_directory_descriptors(struct archive_write *, + struct vdd *); +static int write_file_descriptors(struct archive_write *); +static int write_rr_ER(struct archive_write *); +static void calculate_path_table_size(struct vdd *); + +static void isofile_init_entry_list(struct iso9660 *); +static void isofile_add_entry(struct iso9660 *, struct isofile *); +static void isofile_free_all_entries(struct iso9660 *); +static void isofile_init_entry_data_file_list(struct iso9660 *); +static void isofile_add_data_file(struct iso9660 *, struct isofile *); +static struct isofile * isofile_new(struct archive_write *, + struct archive_entry *); +static void isofile_free(struct isofile *); +static int isofile_gen_utility_names(struct archive_write *, + struct isofile *); +static int isofile_register_hardlink(struct archive_write *, + struct isofile *); +static void isofile_connect_hardlink_files(struct iso9660 *); +static void isofile_init_hardlinks(struct iso9660 *); +static void isofile_free_hardlinks(struct iso9660 *); + +static struct isoent *isoent_new(struct isofile *); +static int isoent_clone_tree(struct archive_write *, + struct isoent **, struct isoent *); +static void _isoent_free(struct isoent *isoent); +static void isoent_free_all(struct isoent *); +static struct isoent * isoent_create_virtual_dir(struct archive_write *, + struct iso9660 *, const char *); +static int isoent_cmp_node(const struct archive_rb_node *, + const struct archive_rb_node *); +static int isoent_cmp_key(const struct archive_rb_node *, + const void *); +static int isoent_add_child_head(struct isoent *, struct isoent *); +static int isoent_add_child_tail(struct isoent *, struct isoent *); +static void isoent_remove_child(struct isoent *, struct isoent *); +static void isoent_setup_directory_location(struct iso9660 *, + int, struct vdd *); +static void isoent_setup_file_location(struct iso9660 *, int); +static int get_path_component(char *, int, const char *); +static int isoent_tree(struct archive_write *, struct isoent **); +static struct isoent *isoent_find_child(struct isoent *, const char *); +static struct isoent *isoent_find_entry(struct isoent *, const char *); +static void idr_relaxed_filenames(char *); +static void idr_init(struct iso9660 *, struct vdd *, struct idr *); +static void idr_cleanup(struct idr *); +static int idr_ensure_poolsize(struct archive_write *, struct idr *, + int); +static int idr_start(struct archive_write *, struct idr *, + int, int, int, int, const struct archive_rb_tree_ops *); +static void idr_register(struct idr *, struct isoent *, int, + int); +static void idr_extend_identifier(struct idrent *, int, int); +static void idr_resolve(struct idr *, void (*)(unsigned char *, int)); +static void idr_set_num(unsigned char *, int); +static void idr_set_num_beutf16(unsigned char *, int); +static int isoent_gen_iso9660_identifier(struct archive_write *, + struct isoent *, struct idr *); +static int isoent_gen_joliet_identifier(struct archive_write *, + struct isoent *, struct idr *); +static int isoent_cmp_iso9660_identifier(const struct isoent *, + const struct isoent *); +static int isoent_cmp_node_iso9660(const struct archive_rb_node *, + const struct archive_rb_node *); +static int isoent_cmp_key_iso9660(const struct archive_rb_node *, + const void *); +static int isoent_cmp_joliet_identifier(const struct isoent *, + const struct isoent *); +static int isoent_cmp_node_joliet(const struct archive_rb_node *, + const struct archive_rb_node *); +static int isoent_cmp_key_joliet(const struct archive_rb_node *, + const void *); +static inline void path_table_add_entry(struct path_table *, struct isoent *); +static inline struct isoent * path_table_last_entry(struct path_table *); +static int isoent_make_path_table(struct archive_write *); +static int isoent_find_out_boot_file(struct archive_write *, + struct isoent *); +static int isoent_create_boot_catalog(struct archive_write *, + struct isoent *); +static size_t fd_boot_image_size(int); +static int make_boot_catalog(struct archive_write *); +static int setup_boot_information(struct archive_write *); + +static int zisofs_init(struct archive_write *, struct isofile *); +static void zisofs_detect_magic(struct archive_write *, + const void *, size_t); +static int zisofs_write_to_temp(struct archive_write *, + const void *, size_t); +static int zisofs_finish_entry(struct archive_write *); +static int zisofs_rewind_boot_file(struct archive_write *); +static int zisofs_free(struct archive_write *); + +int +archive_write_set_format_iso9660(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct iso9660 *iso9660; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_iso9660"); + + /* If another format was already registered, unregister it. */ + if (a->format_free != NULL) + (a->format_free)(a); + + iso9660 = calloc(1, sizeof(*iso9660)); + if (iso9660 == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate iso9660 data"); + return (ARCHIVE_FATAL); + } + iso9660->birth_time = 0; + iso9660->temp_fd = -1; + iso9660->cur_file = NULL; + iso9660->primary.max_depth = 0; + iso9660->primary.vdd_type = VDD_PRIMARY; + iso9660->primary.pathtbl = NULL; + iso9660->joliet.rootent = NULL; + iso9660->joliet.max_depth = 0; + iso9660->joliet.vdd_type = VDD_JOLIET; + iso9660->joliet.pathtbl = NULL; + isofile_init_entry_list(iso9660); + isofile_init_entry_data_file_list(iso9660); + isofile_init_hardlinks(iso9660); + iso9660->directories_too_deep = NULL; + iso9660->dircnt_max = 1; + iso9660->wbuff_remaining = wb_buffmax(); + iso9660->wbuff_type = WB_TO_TEMP; + iso9660->wbuff_offset = 0; + iso9660->wbuff_written = 0; + iso9660->wbuff_tail = 0; + archive_string_init(&(iso9660->utf16be)); + archive_string_init(&(iso9660->mbs)); + + /* + * Init Identifiers used for PVD and SVD. + */ + archive_string_init(&(iso9660->volume_identifier)); + archive_strcpy(&(iso9660->volume_identifier), "CDROM"); + archive_string_init(&(iso9660->publisher_identifier)); + archive_string_init(&(iso9660->data_preparer_identifier)); + archive_string_init(&(iso9660->application_identifier)); + archive_strcpy(&(iso9660->application_identifier), + archive_version_string()); + archive_string_init(&(iso9660->copyright_file_identifier)); + archive_string_init(&(iso9660->abstract_file_identifier)); + archive_string_init(&(iso9660->bibliographic_file_identifier)); + + /* + * Init El Torito bootable CD variables. + */ + archive_string_init(&(iso9660->el_torito.catalog_filename)); + iso9660->el_torito.catalog = NULL; + /* Set default file name of boot catalog */ + archive_strcpy(&(iso9660->el_torito.catalog_filename), + "boot.catalog"); + archive_string_init(&(iso9660->el_torito.boot_filename)); + iso9660->el_torito.boot = NULL; + iso9660->el_torito.platform_id = BOOT_PLATFORM_X86; + archive_string_init(&(iso9660->el_torito.id)); + iso9660->el_torito.boot_load_seg = 0; + iso9660->el_torito.boot_load_size = BOOT_LOAD_SIZE; + + /* + * Init zisofs variables. + */ +#ifdef HAVE_ZLIB_H + iso9660->zisofs.block_pointers = NULL; + iso9660->zisofs.block_pointers_allocated = 0; + iso9660->zisofs.stream_valid = 0; + iso9660->zisofs.compression_level = 9; + memset(&(iso9660->zisofs.stream), 0, + sizeof(iso9660->zisofs.stream)); +#endif + + /* + * Set default value of iso9660 options. + */ + iso9660->opt.abstract_file = OPT_ABSTRACT_FILE_DEFAULT; + iso9660->opt.application_id = OPT_APPLICATION_ID_DEFAULT; + iso9660->opt.allow_vernum = OPT_ALLOW_VERNUM_DEFAULT; + iso9660->opt.biblio_file = OPT_BIBLIO_FILE_DEFAULT; + iso9660->opt.boot = OPT_BOOT_DEFAULT; + iso9660->opt.boot_catalog = OPT_BOOT_CATALOG_DEFAULT; + iso9660->opt.boot_info_table = OPT_BOOT_INFO_TABLE_DEFAULT; + iso9660->opt.boot_load_seg = OPT_BOOT_LOAD_SEG_DEFAULT; + iso9660->opt.boot_load_size = OPT_BOOT_LOAD_SIZE_DEFAULT; + iso9660->opt.boot_type = OPT_BOOT_TYPE_DEFAULT; + iso9660->opt.compression_level = OPT_COMPRESSION_LEVEL_DEFAULT; + iso9660->opt.copyright_file = OPT_COPYRIGHT_FILE_DEFAULT; + iso9660->opt.iso_level = OPT_ISO_LEVEL_DEFAULT; + iso9660->opt.joliet = OPT_JOLIET_DEFAULT; + iso9660->opt.limit_depth = OPT_LIMIT_DEPTH_DEFAULT; + iso9660->opt.limit_dirs = OPT_LIMIT_DIRS_DEFAULT; + iso9660->opt.pad = OPT_PAD_DEFAULT; + iso9660->opt.publisher = OPT_PUBLISHER_DEFAULT; + iso9660->opt.rr = OPT_RR_DEFAULT; + iso9660->opt.volume_id = OPT_VOLUME_ID_DEFAULT; + iso9660->opt.zisofs = OPT_ZISOFS_DEFAULT; + + /* Create the root directory. */ + iso9660->primary.rootent = + isoent_create_virtual_dir(a, iso9660, ""); + if (iso9660->primary.rootent == NULL) { + free(iso9660); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + iso9660->primary.rootent->parent = iso9660->primary.rootent; + iso9660->cur_dirent = iso9660->primary.rootent; + archive_string_init(&(iso9660->cur_dirstr)); + archive_string_ensure(&(iso9660->cur_dirstr), 1); + iso9660->cur_dirstr.s[0] = 0; + iso9660->sconv_to_utf16be = NULL; + iso9660->sconv_from_utf16be = NULL; + + a->format_data = iso9660; + a->format_name = "iso9660"; + a->format_options = iso9660_options; + a->format_write_header = iso9660_write_header; + a->format_write_data = iso9660_write_data; + a->format_finish_entry = iso9660_finish_entry; + a->format_close = iso9660_close; + a->format_free = iso9660_free; + a->archive.archive_format = ARCHIVE_FORMAT_ISO9660; + a->archive.archive_format_name = "ISO9660"; + + return (ARCHIVE_OK); +} + +static int +get_str_opt(struct archive_write *a, struct archive_string *s, + size_t maxsize, const char *key, const char *value) +{ + + if (strlen(value) > maxsize) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Value is longer than %zu characters " + "for option ``%s''", maxsize, key); + return (ARCHIVE_FATAL); + } + archive_strcpy(s, value); + return (ARCHIVE_OK); +} + +static int +get_num_opt(struct archive_write *a, int *num, int high, int low, + const char *key, const char *value) +{ + const char *p = value; + int data = 0; + int neg = 0; + + if (p == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid value(empty) for option ``%s''", key); + return (ARCHIVE_FATAL); + } + if (*p == '-') { + neg = 1; + p++; + } + while (*p) { + if (*p >= '0' && *p <= '9') + data = data * 10 + *p - '0'; + else { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid value for option ``%s''", key); + return (ARCHIVE_FATAL); + } + if (data > high) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid value(over %d) for " + "option ``%s''", high, key); + return (ARCHIVE_FATAL); + } + if (data < low) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid value(under %d) for " + "option ``%s''", low, key); + return (ARCHIVE_FATAL); + } + p++; + } + if (neg) + data *= -1; + *num = data; + + return (ARCHIVE_OK); +} + +static int +iso9660_options(struct archive_write *a, const char *key, const char *value) +{ + struct iso9660 *iso9660 = a->format_data; + const char *p; + int r; + + switch (key[0]) { + case 'a': + if (strcmp(key, "abstract-file") == 0) { + r = get_str_opt(a, + &(iso9660->abstract_file_identifier), + ABSTRACT_FILE_SIZE, key, value); + iso9660->opt.abstract_file = r == ARCHIVE_OK; + return (r); + } + if (strcmp(key, "application-id") == 0) { + r = get_str_opt(a, + &(iso9660->application_identifier), + APPLICATION_IDENTIFIER_SIZE, key, value); + iso9660->opt.application_id = r == ARCHIVE_OK; + return (r); + } + if (strcmp(key, "allow-vernum") == 0) { + iso9660->opt.allow_vernum = value != NULL; + return (ARCHIVE_OK); + } + break; + case 'b': + if (strcmp(key, "biblio-file") == 0) { + r = get_str_opt(a, + &(iso9660->bibliographic_file_identifier), + BIBLIO_FILE_SIZE, key, value); + iso9660->opt.biblio_file = r == ARCHIVE_OK; + return (r); + } + if (strcmp(key, "boot") == 0) { + if (value == NULL) + iso9660->opt.boot = 0; + else { + iso9660->opt.boot = 1; + archive_strcpy( + &(iso9660->el_torito.boot_filename), + value); + } + return (ARCHIVE_OK); + } + if (strcmp(key, "boot-catalog") == 0) { + r = get_str_opt(a, + &(iso9660->el_torito.catalog_filename), + 1024, key, value); + iso9660->opt.boot_catalog = r == ARCHIVE_OK; + return (r); + } + if (strcmp(key, "boot-info-table") == 0) { + iso9660->opt.boot_info_table = value != NULL; + return (ARCHIVE_OK); + } + if (strcmp(key, "boot-load-seg") == 0) { + uint32_t seg; + + iso9660->opt.boot_load_seg = 0; + if (value == NULL) + goto invalid_value; + seg = 0; + p = value; + if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) + p += 2; + while (*p) { + if (seg) + seg <<= 4; + if (*p >= 'A' && *p <= 'F') + seg += *p - 'A' + 0x0a; + else if (*p >= 'a' && *p <= 'f') + seg += *p - 'a' + 0x0a; + else if (*p >= '0' && *p <= '9') + seg += *p - '0'; + else + goto invalid_value; + if (seg > 0xffff) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Invalid value(over 0xffff) for " + "option ``%s''", key); + return (ARCHIVE_FATAL); + } + p++; + } + iso9660->el_torito.boot_load_seg = (uint16_t)seg; + iso9660->opt.boot_load_seg = 1; + return (ARCHIVE_OK); + } + if (strcmp(key, "boot-load-size") == 0) { + int num = 0; + r = get_num_opt(a, &num, 0xffff, 1, key, value); + iso9660->opt.boot_load_size = r == ARCHIVE_OK; + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->el_torito.boot_load_size = (uint16_t)num; + return (ARCHIVE_OK); + } + if (strcmp(key, "boot-type") == 0) { + if (value == NULL) + goto invalid_value; + if (strcmp(value, "no-emulation") == 0) + iso9660->opt.boot_type = OPT_BOOT_TYPE_NO_EMU; + else if (strcmp(value, "fd") == 0) + iso9660->opt.boot_type = OPT_BOOT_TYPE_FD; + else if (strcmp(value, "hard-disk") == 0) + iso9660->opt.boot_type = OPT_BOOT_TYPE_HARD_DISK; + else + goto invalid_value; + return (ARCHIVE_OK); + } + break; + case 'c': + if (strcmp(key, "compression-level") == 0) { +#ifdef HAVE_ZLIB_H + if (value == NULL || + !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') + goto invalid_value; + iso9660->zisofs.compression_level = value[0] - '0'; + iso9660->opt.compression_level = 1; + return (ARCHIVE_OK); +#else + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Option ``%s'' " + "is not supported on this platform.", key); + return (ARCHIVE_FATAL); +#endif + } + if (strcmp(key, "copyright-file") == 0) { + r = get_str_opt(a, + &(iso9660->copyright_file_identifier), + COPYRIGHT_FILE_SIZE, key, value); + iso9660->opt.copyright_file = r == ARCHIVE_OK; + return (r); + } +#ifdef DEBUG + /* Specifies Volume creation date and time; + * year(4),month(2),day(2),hour(2),minute(2),second(2). + * e.g. "20090929033757" + */ + if (strcmp(key, "creation") == 0) { + struct tm tm; + char buf[5]; + + p = value; + if (p == NULL || strlen(p) < 14) + goto invalid_value; + memset(&tm, 0, sizeof(tm)); + memcpy(buf, p, 4); buf[4] = '\0'; p += 4; + tm.tm_year = strtol(buf, NULL, 10) - 1900; + memcpy(buf, p, 2); buf[2] = '\0'; p += 2; + tm.tm_mon = strtol(buf, NULL, 10) - 1; + memcpy(buf, p, 2); buf[2] = '\0'; p += 2; + tm.tm_mday = strtol(buf, NULL, 10); + memcpy(buf, p, 2); buf[2] = '\0'; p += 2; + tm.tm_hour = strtol(buf, NULL, 10); + memcpy(buf, p, 2); buf[2] = '\0'; p += 2; + tm.tm_min = strtol(buf, NULL, 10); + memcpy(buf, p, 2); buf[2] = '\0'; + tm.tm_sec = strtol(buf, NULL, 10); + iso9660->birth_time = mktime(&tm); + return (ARCHIVE_OK); + } +#endif + break; + case 'i': + if (strcmp(key, "iso-level") == 0) { + if (value != NULL && value[1] == '\0' && + (value[0] >= '1' && value[0] <= '4')) { + iso9660->opt.iso_level = value[0]-'0'; + return (ARCHIVE_OK); + } + goto invalid_value; + } + break; + case 'j': + if (strcmp(key, "joliet") == 0) { + if (value == NULL) + iso9660->opt.joliet = OPT_JOLIET_DISABLE; + else if (strcmp(value, "1") == 0) + iso9660->opt.joliet = OPT_JOLIET_ENABLE; + else if (strcmp(value, "long") == 0) + iso9660->opt.joliet = OPT_JOLIET_LONGNAME; + else + goto invalid_value; + return (ARCHIVE_OK); + } + break; + case 'l': + if (strcmp(key, "limit-depth") == 0) { + iso9660->opt.limit_depth = value != NULL; + return (ARCHIVE_OK); + } + if (strcmp(key, "limit-dirs") == 0) { + iso9660->opt.limit_dirs = value != NULL; + return (ARCHIVE_OK); + } + break; + case 'p': + if (strcmp(key, "pad") == 0) { + iso9660->opt.pad = value != NULL; + return (ARCHIVE_OK); + } + if (strcmp(key, "publisher") == 0) { + r = get_str_opt(a, + &(iso9660->publisher_identifier), + PUBLISHER_IDENTIFIER_SIZE, key, value); + iso9660->opt.publisher = r == ARCHIVE_OK; + return (r); + } + break; + case 'r': + if (strcmp(key, "rockridge") == 0 || + strcmp(key, "Rockridge") == 0) { + if (value == NULL) + iso9660->opt.rr = OPT_RR_DISABLED; + else if (strcmp(value, "1") == 0) + iso9660->opt.rr = OPT_RR_USEFUL; + else if (strcmp(value, "strict") == 0) + iso9660->opt.rr = OPT_RR_STRICT; + else if (strcmp(value, "useful") == 0) + iso9660->opt.rr = OPT_RR_USEFUL; + else + goto invalid_value; + return (ARCHIVE_OK); + } + break; + case 'v': + if (strcmp(key, "volume-id") == 0) { + r = get_str_opt(a, &(iso9660->volume_identifier), + VOLUME_IDENTIFIER_SIZE, key, value); + iso9660->opt.volume_id = r == ARCHIVE_OK; + return (r); + } + break; + case 'z': + if (strcmp(key, "zisofs") == 0) { + if (value == NULL) + iso9660->opt.zisofs = OPT_ZISOFS_DISABLED; + else { +#ifdef HAVE_ZLIB_H + iso9660->opt.zisofs = OPT_ZISOFS_DIRECT; +#else + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "``zisofs'' " + "is not supported on this platform."); + return (ARCHIVE_FATAL); +#endif + } + return (ARCHIVE_OK); + } + break; + } + +invalid_value: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid value for option ``%s''", key); + return (ARCHIVE_FAILED); +} + +static int +iso9660_write_header(struct archive_write *a, struct archive_entry *entry) +{ + struct iso9660 *iso9660; + struct isofile *file; + struct isoent *isoent; + int r, ret = ARCHIVE_OK; + + iso9660 = a->format_data; + + iso9660->cur_file = NULL; + iso9660->bytes_remaining = 0; + iso9660->need_multi_extent = 0; + if (archive_entry_filetype(entry) == AE_IFLNK + && iso9660->opt.rr == OPT_RR_DISABLED) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Ignore symlink file."); + iso9660->cur_file = NULL; + return (ARCHIVE_WARN); + } + if (archive_entry_filetype(entry) == AE_IFREG && + archive_entry_size(entry) >= MULTI_EXTENT_SIZE) { + if (iso9660->opt.iso_level < 3) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Ignore over %lld bytes file. " + "This file too large.", + MULTI_EXTENT_SIZE); + iso9660->cur_file = NULL; + return (ARCHIVE_WARN); + } + iso9660->need_multi_extent = 1; + } + + file = isofile_new(a, entry); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + return (ARCHIVE_FATAL); + } + r = isofile_gen_utility_names(a, file); + if (r < ARCHIVE_WARN) { + isofile_free(file); + return (r); + } + else if (r < ret) + ret = r; + + /* + * Ignore a path which looks like the top of directory name + * since we have already made the root directory of an ISO image. + */ + if (archive_strlen(&(file->parentdir)) == 0 && + archive_strlen(&(file->basename)) == 0) { + isofile_free(file); + return (r); + } + + isofile_add_entry(iso9660, file); + isoent = isoent_new(file); + if (isoent == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + return (ARCHIVE_FATAL); + } + if (isoent->file->dircnt > iso9660->dircnt_max) + iso9660->dircnt_max = isoent->file->dircnt; + + /* Add the current file into tree */ + r = isoent_tree(a, &isoent); + if (r != ARCHIVE_OK) + return (r); + + /* If there is the same file in tree and + * the current file is older than the file in tree. + * So we don't need the current file data anymore. */ + if (isoent->file != file) + return (ARCHIVE_OK); + + /* Non regular files contents are unneeded to be saved to + * temporary files. */ + if (archive_entry_filetype(file->entry) != AE_IFREG) + return (ret); + + /* + * Set the current file to cur_file to read its contents. + */ + iso9660->cur_file = file; + + if (archive_entry_nlink(file->entry) > 1) { + r = isofile_register_hardlink(a, file); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* + * Prepare to save the contents of the file. + */ + if (iso9660->temp_fd < 0) { + iso9660->temp_fd = __archive_mktemp(NULL); + if (iso9660->temp_fd < 0) { + archive_set_error(&a->archive, errno, + "Couldn't create temporary file"); + return (ARCHIVE_FATAL); + } + } + + /* Save an offset of current file in temporary file. */ + file->content.offset_of_temp = wb_offset(a); + file->cur_content = &(file->content); + r = zisofs_init(a, file); + if (r < ret) + ret = r; + iso9660->bytes_remaining = archive_entry_size(file->entry); + + return (ret); +} + +static int +write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + struct iso9660 *iso9660 = a->format_data; + ssize_t written; + const unsigned char *b; + + b = (const unsigned char *)buff; + while (s) { + written = write(iso9660->temp_fd, b, s); + if (written < 0) { + archive_set_error(&a->archive, errno, + "Can't write to temporary file"); + return (ARCHIVE_FATAL); + } + s -= written; + b += written; + } + return (ARCHIVE_OK); +} + +static int +wb_write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + const char *xp = buff; + size_t xs = s; + + /* + * If a written data size is big enough to use system-call + * and there is no waiting data, this calls write_to_temp() in + * order to reduce a extra memory copy. + */ + if (wb_remaining(a) == wb_buffmax() && s > (1024 * 16)) { + struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + xs = s % LOGICAL_BLOCK_SIZE; + iso9660->wbuff_offset += s - xs; + if (write_to_temp(a, buff, s - xs) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (xs == 0) + return (ARCHIVE_OK); + xp += s - xs; + } + + while (xs) { + size_t size = xs; + if (size > wb_remaining(a)) + size = wb_remaining(a); + memcpy(wb_buffptr(a), xp, size); + if (wb_consume(a, size) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + xs -= size; + xp += size; + } + return (ARCHIVE_OK); +} + +static int +wb_write_padding_to_temp(struct archive_write *a, int64_t csize) +{ + size_t ns; + int ret; + + ns = csize % LOGICAL_BLOCK_SIZE; + if (ns != 0) + ret = write_null(a, LOGICAL_BLOCK_SIZE - ns); + else + ret = ARCHIVE_OK; + return (ret); +} + +static ssize_t +write_iso9660_data(struct archive_write *a, const void *buff, size_t s) +{ + struct iso9660 *iso9660 = a->format_data; + size_t ws; + + if (iso9660->temp_fd < 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Couldn't create temporary file"); + return (ARCHIVE_FATAL); + } + + ws = s; + if (iso9660->need_multi_extent && + (iso9660->cur_file->cur_content->size + ws) >= + (MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE)) { + struct content *con; + size_t ts; + + ts = MULTI_EXTENT_SIZE - LOGICAL_BLOCK_SIZE - + iso9660->cur_file->cur_content->size; + + if (iso9660->zisofs.detect_magic) + zisofs_detect_magic(a, buff, ts); + + if (iso9660->zisofs.making) { + if (zisofs_write_to_temp(a, buff, ts) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + if (wb_write_to_temp(a, buff, ts) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->cur_file->cur_content->size += ts; + } + + /* Write padding. */ + if (wb_write_padding_to_temp(a, + iso9660->cur_file->cur_content->size) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Compute the logical block number. */ + iso9660->cur_file->cur_content->blocks = + (iso9660->cur_file->cur_content->size + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + + /* + * Make next extent. + */ + ws -= ts; + buff = (const void *)(((const unsigned char *)buff) + ts); + /* Make a content for next extent. */ + con = calloc(1, sizeof(*con)); + if (con == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate content data"); + return (ARCHIVE_FATAL); + } + con->offset_of_temp = wb_offset(a); + iso9660->cur_file->cur_content->next = con; + iso9660->cur_file->cur_content = con; +#ifdef HAVE_ZLIB_H + iso9660->zisofs.block_offset = 0; +#endif + } + + if (iso9660->zisofs.detect_magic) + zisofs_detect_magic(a, buff, ws); + + if (iso9660->zisofs.making) { + if (zisofs_write_to_temp(a, buff, ws) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + if (wb_write_to_temp(a, buff, ws) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->cur_file->cur_content->size += ws; + } + + return (s); +} + +static ssize_t +iso9660_write_data(struct archive_write *a, const void *buff, size_t s) +{ + struct iso9660 *iso9660 = a->format_data; + ssize_t r; + + if (iso9660->cur_file == NULL) + return (0); + if (archive_entry_filetype(iso9660->cur_file->entry) != AE_IFREG) + return (0); + if (s > iso9660->bytes_remaining) + s = iso9660->bytes_remaining; + if (s == 0) + return (0); + + r = write_iso9660_data(a, buff, s); + if (r > 0) + iso9660->bytes_remaining -= r; + return (r); +} + +static int +iso9660_finish_entry(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + + if (iso9660->cur_file == NULL) + return (ARCHIVE_OK); + if (archive_entry_filetype(iso9660->cur_file->entry) != AE_IFREG) + return (ARCHIVE_OK); + if (iso9660->cur_file->content.size == 0) + return (ARCHIVE_OK); + + /* If there are unwritten data, write null data instead. */ + while (iso9660->bytes_remaining > 0) { + size_t s; + + s = (iso9660->bytes_remaining > a->null_length)? + a->null_length: (size_t)iso9660->bytes_remaining; + if (write_iso9660_data(a, a->nulls, s) < 0) + return (ARCHIVE_FATAL); + iso9660->bytes_remaining -= s; + } + + if (iso9660->zisofs.making && zisofs_finish_entry(a) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write padding. */ + if (wb_write_padding_to_temp(a, iso9660->cur_file->cur_content->size) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Compute the logical block number. */ + iso9660->cur_file->cur_content->blocks = + (iso9660->cur_file->cur_content->size + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + + /* Add the current file to data file list. */ + isofile_add_data_file(iso9660, iso9660->cur_file); + + return (ARCHIVE_OK); +} + +static int +iso9660_close(struct archive_write *a) +{ + struct iso9660 *iso9660; + int ret, blocks; + + iso9660 = a->format_data; + + /* + * Write remaining data out to the temprary file. + */ + if (wb_remaining(a) > 0) { + ret = wb_write_out(a); + if (ret < 0) + return (ret); + } + + /* + * Preparations... + */ +#ifdef DEBUG + if (iso9660->birth_time == 0) +#endif + time(&(iso9660->birth_time)); + + /* + * Prepare a bootable ISO image. + */ + if (iso9660->opt.boot) { + /* Find out the boot file entry. */ + ret = isoent_find_out_boot_file(a, iso9660->primary.rootent); + if (ret < 0) + return (ret); + /* Reconvert the boot file from zisofs'ed form to + * plain form. */ + ret = zisofs_rewind_boot_file(a); + if (ret < 0) + return (ret); + /* Write remaining data out to the temprary file. */ + if (wb_remaining(a) > 0) { + ret = wb_write_out(a); + if (ret < 0) + return (ret); + } + /* Create the boot catalog. */ + ret = isoent_create_boot_catalog(a, iso9660->primary.rootent); + if (ret < 0) + return (ret); + } + + /* + * Prepare joliet extensions. + */ + if (iso9660->opt.joliet) { + /* Make a new tree for joliet. */ + ret = isoent_clone_tree(a, &(iso9660->joliet.rootent), + iso9660->primary.rootent); + if (ret < 0) + return (ret); + /* Make sure we have UTF-16BE convertors. + * if there is no file entry, convertors are still + * uninitilized. */ + if (iso9660->sconv_to_utf16be == NULL) { + iso9660->sconv_to_utf16be = + archive_string_conversion_to_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_to_utf16be == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FATAL); + iso9660->sconv_from_utf16be = + archive_string_conversion_from_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_from_utf16be == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FATAL); + } + } + + /* + * Make Path Tables. + */ + ret = isoent_make_path_table(a); + if (ret < 0) + return (ret); + + /* + * Calculate a total volume size and setup all locations of + * contents of an iso9660 image. + */ + blocks = SYSTEM_AREA_BLOCK + + PRIMARY_VOLUME_DESCRIPTOR_BLOCK + + VOLUME_DESCRIPTOR_SET_TERMINATOR_BLOCK + + NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK; + if (iso9660->opt.boot) + blocks += BOOT_RECORD_DESCRIPTOR_BLOCK; + if (iso9660->opt.joliet) + blocks += SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK; + if (iso9660->opt.iso_level == 4) + blocks += SUPPLEMENTARY_VOLUME_DESCRIPTOR_BLOCK; + + /* Setup the locations of Path Table. */ + iso9660->primary.location_type_L_path_table = blocks; + blocks += iso9660->primary.path_table_block; + iso9660->primary.location_type_M_path_table = blocks; + blocks += iso9660->primary.path_table_block; + if (iso9660->opt.joliet) { + iso9660->joliet.location_type_L_path_table = blocks; + blocks += iso9660->joliet.path_table_block; + iso9660->joliet.location_type_M_path_table = blocks; + blocks += iso9660->joliet.path_table_block; + } + + /* Setup the locations of directories. */ + isoent_setup_directory_location(iso9660, blocks, + &(iso9660->primary)); + blocks += iso9660->primary.total_dir_block; + if (iso9660->opt.joliet) { + isoent_setup_directory_location(iso9660, blocks, + &(iso9660->joliet)); + blocks += iso9660->joliet.total_dir_block; + } + + if (iso9660->opt.rr) { + iso9660->location_rrip_er = blocks; + blocks += RRIP_ER_BLOCK; + } + + /* Setup the locations of all file contents. */ + isoent_setup_file_location(iso9660, blocks); + blocks += iso9660->total_file_block; + if (iso9660->opt.boot && iso9660->opt.boot_info_table) { + ret = setup_boot_information(a); + if (ret < 0) + return (ret); + } + + /* Now we have a total volume size. */ + iso9660->volume_space_size = blocks; + if (iso9660->opt.pad) + iso9660->volume_space_size += PADDING_BLOCK; + iso9660->volume_sequence_number = 1; + + + /* + * Write an ISO 9660 image. + */ + + /* Switc to start using wbuff as file buffer. */ + iso9660->wbuff_remaining = wb_buffmax(); + iso9660->wbuff_type = WB_TO_STREAM; + iso9660->wbuff_offset = 0; + iso9660->wbuff_written = 0; + iso9660->wbuff_tail = 0; + + /* Write The System Area */ + ret = write_null(a, SYSTEM_AREA_BLOCK * LOGICAL_BLOCK_SIZE); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Primary Volume Descriptor */ + ret = write_VD(a, &(iso9660->primary)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + if (iso9660->opt.boot) { + /* Write Boot Record Volume Descriptor */ + ret = write_VD_boot_record(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + if (iso9660->opt.iso_level == 4) { + /* Write Enhanced Volume Descriptor */ + iso9660->primary.vdd_type = VDD_ENHANCED; + ret = write_VD(a, &(iso9660->primary)); + iso9660->primary.vdd_type = VDD_PRIMARY; + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + if (iso9660->opt.joliet) { + ret = write_VD(a, &(iso9660->joliet)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* Write Volume Descriptor Set Terminator */ + ret = write_VD_terminator(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Non-ISO File System Information */ + ret = write_information_block(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Type L Path Table */ + ret = write_path_table(a, 0, &(iso9660->primary)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Type M Path Table */ + ret = write_path_table(a, 1, &(iso9660->primary)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + if (iso9660->opt.joliet) { + /* Write Type L Path Table */ + ret = write_path_table(a, 0, &(iso9660->joliet)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Type M Path Table */ + ret = write_path_table(a, 1, &(iso9660->joliet)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* Write Directory Descriptors */ + ret = write_directory_descriptors(a, &(iso9660->primary)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + if (iso9660->opt.joliet) { + ret = write_directory_descriptors(a, &(iso9660->joliet)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + if (iso9660->opt.rr) { + /* Write Rockridge ER(Extensions Reference) */ + ret = write_rr_ER(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* Write File Descriptors */ + ret = write_file_descriptors(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Write Padding */ + if (iso9660->opt.pad) { + ret = write_null(a, PADDING_BLOCK * LOGICAL_BLOCK_SIZE); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + if (iso9660->directories_too_deep != NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: Directories too deep.", + archive_entry_pathname( + iso9660->directories_too_deep->file->entry)); + return (ARCHIVE_WARN); + } + + /* Write remaining data out. */ + ret = wb_write_out(a); + + return (ret); +} + +static int +iso9660_free(struct archive_write *a) +{ + struct iso9660 *iso9660; + int i, ret; + + iso9660 = a->format_data; + + /* Close the temporary file. */ + if (iso9660->temp_fd >= 0) + close(iso9660->temp_fd); + + /* Free some stuff for zisofs operations. */ + ret = zisofs_free(a); + + /* Remove directory entries in tree which includes file entries. */ + isoent_free_all(iso9660->primary.rootent); + for (i = 0; i < iso9660->primary.max_depth; i++) + free(iso9660->primary.pathtbl[i].sorted); + free(iso9660->primary.pathtbl); + + if (iso9660->opt.joliet) { + isoent_free_all(iso9660->joliet.rootent); + for (i = 0; i < iso9660->joliet.max_depth; i++) + free(iso9660->joliet.pathtbl[i].sorted); + free(iso9660->joliet.pathtbl); + } + + /* Remove isofile entries. */ + isofile_free_all_entries(iso9660); + isofile_free_hardlinks(iso9660); + + archive_string_free(&(iso9660->cur_dirstr)); + archive_string_free(&(iso9660->volume_identifier)); + archive_string_free(&(iso9660->publisher_identifier)); + archive_string_free(&(iso9660->data_preparer_identifier)); + archive_string_free(&(iso9660->application_identifier)); + archive_string_free(&(iso9660->copyright_file_identifier)); + archive_string_free(&(iso9660->abstract_file_identifier)); + archive_string_free(&(iso9660->bibliographic_file_identifier)); + archive_string_free(&(iso9660->el_torito.catalog_filename)); + archive_string_free(&(iso9660->el_torito.boot_filename)); + archive_string_free(&(iso9660->el_torito.id)); + archive_string_free(&(iso9660->utf16be)); + archive_string_free(&(iso9660->mbs)); + + free(iso9660); + a->format_data = NULL; + + return (ret); +} + +/* + * Get the System Identifier + */ +static void +get_system_identitier(char *system_id, size_t size) +{ +#if defined(HAVE_SYS_UTSNAME_H) + struct utsname u; + + uname(&u); + strncpy(system_id, u.sysname, size-1); + system_id[size-1] = '\0'; +#elif defined(_WIN32) && !defined(__CYGWIN__) + strncpy(system_id, "Windows", size-1); + system_id[size-1] = '\0'; +#else +#error no way to get the system identifier on your platform. +#endif +} + +static void +set_str(unsigned char *p, const char *s, size_t l, char f, const char *map) +{ + unsigned char c; + + if (s == NULL) + s = ""; + while ((c = *s++) != 0 && l > 0) { + if (c >= 0x80 || map[c] == 0) + { + /* illegal character */ + if (c >= 'a' && c <= 'z') { + /* convert c from a-z to A-Z */ + c -= 0x20; + } else + c = 0x5f; + } + *p++ = c; + l--; + } + /* If l isn't zero, fill p buffer by the character + * which indicated by f. */ + if (l > 0) + memset(p , f, l); +} + +static inline int +joliet_allowed_char(unsigned char high, unsigned char low) +{ + int utf16 = (high << 8) | low; + + if (utf16 <= 0x001F) + return (0); + + switch (utf16) { + case 0x002A: /* '*' */ + case 0x002F: /* '/' */ + case 0x003A: /* ':' */ + case 0x003B: /* ';' */ + case 0x003F: /* '?' */ + case 0x005C: /* '\' */ + return (0);/* Not allowed. */ + } + return (1); +} + +static int +set_str_utf16be(struct archive_write *a, unsigned char *p, const char *s, + size_t l, uint16_t uf, enum vdc vdc) +{ + size_t size, i; + int onepad; + + if (s == NULL) + s = ""; + if (l & 0x01) { + onepad = 1; + l &= ~1; + } else + onepad = 0; + if (vdc == VDC_UCS2) { + struct iso9660 *iso9660 = a->format_data; + if (archive_strncpy_in_locale(&iso9660->utf16be, s, strlen(s), + iso9660->sconv_to_utf16be) != 0 && errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for UTF-16BE"); + return (ARCHIVE_FATAL); + } + size = iso9660->utf16be.length; + if (size > l) + size = l; + memcpy(p, iso9660->utf16be.s, size); + } else { + const uint16_t *u16 = (const uint16_t *)s; + + size = 0; + while (*u16++) + size += 2; + if (size > l) + size = l; + memcpy(p, s, size); + } + for (i = 0; i < size; i += 2, p += 2) { + if (!joliet_allowed_char(p[0], p[1])) + archive_be16enc(p, 0x005F);/* '_' */ + } + l -= size; + while (l > 0) { + archive_be16enc(p, uf); + p += 2; + l -= 2; + } + if (onepad) + *p = 0; + return (ARCHIVE_OK); +} + +static const char a_characters_map[0x80] = { +/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */ + 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20-2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30-3F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 60-6F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 70-7F */ +}; + +static const char a1_characters_map[0x80] = { +/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */ + 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 20-2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 30-3F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60-6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,/* 70-7F */ +}; + +static const char d_characters_map[0x80] = { +/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 20-2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,/* 30-3F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 60-6F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 70-7F */ +}; + +static const char d1_characters_map[0x80] = { +/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 00-0F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 10-1F */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,/* 20-2F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,/* 30-3F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 40-4F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,/* 50-5F */ + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,/* 60-6F */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,/* 70-7F */ +}; + +static int +set_str_a_characters_bp(struct archive_write *a, unsigned char *bp, + int from, int to, const char *s, enum vdc vdc) +{ + int r; + + switch (vdc) { + case VDC_STD: + set_str(bp+from, s, to - from + 1, 0x20, + a_characters_map); + r = ARCHIVE_OK; + break; + case VDC_LOWERCASE: + set_str(bp+from, s, to - from + 1, 0x20, + a1_characters_map); + r = ARCHIVE_OK; + break; + case VDC_UCS2: + case VDC_UCS2_DIRECT: + r = set_str_utf16be(a, bp+from, s, to - from + 1, + 0x0020, vdc); + break; + default: + r = ARCHIVE_FATAL; + } + return (r); +} + +static int +set_str_d_characters_bp(struct archive_write *a, unsigned char *bp, + int from, int to, const char *s, enum vdc vdc) +{ + int r; + + switch (vdc) { + case VDC_STD: + set_str(bp+from, s, to - from + 1, 0x20, + d_characters_map); + r = ARCHIVE_OK; + break; + case VDC_LOWERCASE: + set_str(bp+from, s, to - from + 1, 0x20, + d1_characters_map); + r = ARCHIVE_OK; + break; + case VDC_UCS2: + case VDC_UCS2_DIRECT: + r = set_str_utf16be(a, bp+from, s, to - from + 1, + 0x0020, vdc); + break; + default: + r = ARCHIVE_FATAL; + } + return (r); +} + +static void +set_VD_bp(unsigned char *bp, enum VD_type type, unsigned char ver) +{ + + /* Volume Descriptor Type */ + bp[1] = (unsigned char)type; + /* Standard Identifier */ + memcpy(bp + 2, "CD001", 5); + /* Volume Descriptor Version */ + bp[7] = ver; +} + +static inline void +set_unused_field_bp(unsigned char *bp, int from, int to) +{ + memset(bp + from, 0, to - from + 1); +} + +/* + * 8-bit unsigned numerical values. + * ISO9660 Standard 7.1.1 + */ +static inline void +set_num_711(unsigned char *p, unsigned char value) +{ + *p = value; +} + +/* + * 8-bit signed numerical values. + * ISO9660 Standard 7.1.2 + */ +static inline void +set_num_712(unsigned char *p, char value) +{ + *((char *)p) = value; +} + +/* + * Least significant byte first. + * ISO9660 Standard 7.2.1 + */ +static inline void +set_num_721(unsigned char *p, uint16_t value) +{ + archive_le16enc(p, value); +} + +/* + * Most significant byte first. + * ISO9660 Standard 7.2.2 + */ +static inline void +set_num_722(unsigned char *p, uint16_t value) +{ + archive_be16enc(p, value); +} + +/* + * Both-byte orders. + * ISO9660 Standard 7.2.3 + */ +static void +set_num_723(unsigned char *p, uint16_t value) +{ + archive_le16enc(p, value); + archive_be16enc(p+2, value); +} + +/* + * Least significant byte first. + * ISO9660 Standard 7.3.1 + */ +static inline void +set_num_731(unsigned char *p, uint32_t value) +{ + archive_le32enc(p, value); +} + +/* + * Most significant byte first. + * ISO9660 Standard 7.3.2 + */ +static inline void +set_num_732(unsigned char *p, uint32_t value) +{ + archive_be32enc(p, value); +} + +/* + * Both-byte orders. + * ISO9660 Standard 7.3.3 + */ +static inline void +set_num_733(unsigned char *p, uint32_t value) +{ + archive_le32enc(p, value); + archive_be32enc(p+4, value); +} + +static void +set_digit(unsigned char *p, size_t s, int value) +{ + + while (s--) { + p[s] = '0' + (value % 10); + value /= 10; + } +} + +#if defined(HAVE_STRUCT_TM_TM_GMTOFF) +#define get_gmoffset(tm) ((tm)->tm_gmtoff) +#elif defined(HAVE_STRUCT_TM___TM_GMTOFF) +#define get_gmoffset(tm) ((tm)->__tm_gmtoff) +#else +static long +get_gmoffset(struct tm *tm) +{ + long offset; + +#if defined(HAVE__GET_TIMEZONE) + _get_timezone(&offset); +#elif defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__) + offset = _timezone; +#else + offset = timezone; +#endif + offset *= -1; + if (tm->tm_isdst) + offset += 3600; + return (offset); +} +#endif + +static void +get_tmfromtime(struct tm *tm, time_t *t) +{ +#if HAVE_LOCALTIME_R + tzset(); + localtime_r(t, tm); +#elif HAVE__LOCALTIME64_S + _localtime64_s(tm, t); +#else + memcpy(tm, localtime(t), sizeof(*tm)); +#endif +} + +/* + * Date and Time Format. + * ISO9660 Standard 8.4.26.1 + */ +static void +set_date_time(unsigned char *p, time_t t) +{ + struct tm tm; + + get_tmfromtime(&tm, &t); + set_digit(p, 4, tm.tm_year + 1900); + set_digit(p+4, 2, tm.tm_mon + 1); + set_digit(p+6, 2, tm.tm_mday); + set_digit(p+8, 2, tm.tm_hour); + set_digit(p+10, 2, tm.tm_min); + set_digit(p+12, 2, tm.tm_sec); + set_digit(p+14, 2, 0); + set_num_712(p+16, get_gmoffset(&tm)/(60*15)); +} + +static void +set_date_time_null(unsigned char *p) +{ + memset(p, '0', 16); + p[16] = 0; +} + +static void +set_time_915(unsigned char *p, time_t t) +{ + struct tm tm; + + get_tmfromtime(&tm, &t); + set_num_711(p+0, tm.tm_year); + set_num_711(p+1, tm.tm_mon+1); + set_num_711(p+2, tm.tm_mday); + set_num_711(p+3, tm.tm_hour); + set_num_711(p+4, tm.tm_min); + set_num_711(p+5, tm.tm_sec); + set_num_712(p+6, get_gmoffset(&tm)/(60*15)); +} + + +/* + * Write SUSP "CE" System Use Entry. + */ +static int +set_SUSP_CE(unsigned char *p, int location, int offset, int size) +{ + unsigned char *bp = p -1; + /* Extend the System Use Area + * "CE" Format: + * len ver + * +----+----+----+----+-----------+-----------+ + * | 'C'| 'E'| 1C | 01 | LOCATION1 | LOCATION2 | + * +----+----+----+----+-----------+-----------+ + * 0 1 2 3 4 12 20 + * +-----------+ + * | LOCATION3 | + * +-----------+ + * 20 28 + * LOCATION1 : Location of Continuation of System Use Area. + * LOCATION2 : Offset to Start of Continuation. + * LOCATION3 : Length of the Continuation. + */ + + bp[1] = 'C'; + bp[2] = 'E'; + bp[3] = RR_CE_SIZE; /* length */ + bp[4] = 1; /* version */ + set_num_733(bp+5, location); + set_num_733(bp+13, offset); + set_num_733(bp+21, size); + return (RR_CE_SIZE); +} + +/* + * The functions, which names are beginning with extra_, are used to + * control extra records. + * The maximum size of a Directory Record is 254. When a filename is + * very long, all of RRIP data of a file won't stored to the Directory + * Record and so remaining RRIP data store to an extra record instead. + */ +static unsigned char * +extra_open_record(unsigned char *bp, int dr_len, struct isoent *isoent, + struct ctl_extr_rec *ctl) +{ + ctl->bp = bp; + if (bp != NULL) + bp += dr_len; + ctl->use_extr = 0; + ctl->isoent = isoent; + ctl->ce_ptr = NULL; + ctl->cur_len = ctl->dr_len = dr_len; + ctl->limit = DR_LIMIT; + + return (bp); +} + +static void +extra_close_record(struct ctl_extr_rec *ctl, int ce_size) +{ + int padding = 0; + + if (ce_size > 0) + extra_tell_used_size(ctl, ce_size); + /* Padding. */ + if (ctl->cur_len & 0x01) { + ctl->cur_len++; + if (ctl->bp != NULL) + ctl->bp[ctl->cur_len] = 0; + padding = 1; + } + if (ctl->use_extr) { + if (ctl->ce_ptr != NULL) + set_SUSP_CE(ctl->ce_ptr, ctl->extr_loc, + ctl->extr_off, ctl->cur_len - padding); + } else + ctl->dr_len = ctl->cur_len; +} + +#define extra_space(ctl) ((ctl)->limit - (ctl)->cur_len) + +static unsigned char * +extra_next_record(struct ctl_extr_rec *ctl, int length) +{ + int cur_len = ctl->cur_len;/* save cur_len */ + + /* Close the current extra record or Directory Record. */ + extra_close_record(ctl, RR_CE_SIZE); + + /* Get a next extra record. */ + ctl->use_extr = 1; + if (ctl->bp != NULL) { + /* Storing data into an extra record. */ + unsigned char *p; + + /* Save the pointer where a CE extension will be + * stored to. */ + ctl->ce_ptr = &ctl->bp[cur_len+1]; + p = extra_get_record(ctl->isoent, + &ctl->limit, &ctl->extr_off, &ctl->extr_loc); + ctl->bp = p - 1;/* the base of bp offset is 1. */ + } else + /* Calculating the size of an extra record. */ + (void)extra_get_record(ctl->isoent, + &ctl->limit, NULL, NULL); + ctl->cur_len = 0; + /* Check if an extra record is almost full. + * If so, get a next one. */ + if (extra_space(ctl) < length) + (void)extra_next_record(ctl, length); + + return (ctl->bp); +} + +static inline struct extr_rec * +extra_last_record(struct isoent *isoent) +{ + if (isoent->extr_rec_list.first == NULL) + return (NULL); + return ((struct extr_rec *)(void *) + ((char *)(isoent->extr_rec_list.last) + - offsetof(struct extr_rec, next))); +} + +static unsigned char * +extra_get_record(struct isoent *isoent, int *space, int *off, int *loc) +{ + struct extr_rec *rec; + + isoent = isoent->parent; + if (off != NULL) { + /* Storing data into an extra record. */ + rec = isoent->extr_rec_list.current; + if (DR_SAFETY > LOGICAL_BLOCK_SIZE - rec->offset) + rec = rec->next; + } else { + /* Calculating the size of an extra record. */ + rec = extra_last_record(isoent); + if (rec == NULL || + DR_SAFETY > LOGICAL_BLOCK_SIZE - rec->offset) { + rec = malloc(sizeof(*rec)); + if (rec == NULL) + return (NULL); + rec->location = 0; + rec->offset = 0; + /* Insert `rec` into the tail of isoent->extr_rec_list */ + rec->next = NULL; + *isoent->extr_rec_list.last = rec; + isoent->extr_rec_list.last = &(rec->next); + } + } + *space = LOGICAL_BLOCK_SIZE - rec->offset - DR_SAFETY; + if (*space & 0x01) + *space -= 1;/* Keep padding space. */ + if (off != NULL) + *off = rec->offset; + if (loc != NULL) + *loc = rec->location; + isoent->extr_rec_list.current = rec; + + return (&rec->buf[rec->offset]); +} + +static void +extra_tell_used_size(struct ctl_extr_rec *ctl, int size) +{ + struct isoent *isoent; + struct extr_rec *rec; + + if (ctl->use_extr) { + isoent = ctl->isoent->parent; + rec = isoent->extr_rec_list.current; + if (rec != NULL) + rec->offset += size; + } + ctl->cur_len += size; +} + +static int +extra_setup_location(struct isoent *isoent, int location) +{ + struct extr_rec *rec; + int cnt; + + cnt = 0; + rec = isoent->extr_rec_list.first; + isoent->extr_rec_list.current = rec; + while (rec) { + cnt++; + rec->location = location++; + rec->offset = 0; + rec = rec->next; + } + return (cnt); +} + +/* + * Create the RRIP entries. + */ +static int +set_directory_record_rr(unsigned char *bp, int dr_len, + struct isoent *isoent, struct iso9660 *iso9660, enum dir_rec_type t) +{ + /* Flags(BP 5) of the Rockridge "RR" System Use Field */ + unsigned char rr_flag; +#define RR_USE_PX 0x01 +#define RR_USE_PN 0x02 +#define RR_USE_SL 0x04 +#define RR_USE_NM 0x08 +#define RR_USE_CL 0x10 +#define RR_USE_PL 0x20 +#define RR_USE_RE 0x40 +#define RR_USE_TF 0x80 + int length; + struct ctl_extr_rec ctl; + struct isoent *rr_parent, *pxent; + struct isofile *file; + + bp = extra_open_record(bp, dr_len, isoent, &ctl); + + if (t == DIR_REC_PARENT) { + rr_parent = isoent->rr_parent; + pxent = isoent->parent; + if (rr_parent != NULL) + isoent = rr_parent; + else + isoent = isoent->parent; + } else { + rr_parent = NULL; + pxent = isoent; + } + file = isoent->file; + + if (t != DIR_REC_NORMAL) { + rr_flag = RR_USE_PX | RR_USE_TF; + if (rr_parent != NULL) + rr_flag |= RR_USE_PL; + } else { + rr_flag = RR_USE_PX | RR_USE_NM | RR_USE_TF; + if (archive_entry_filetype(file->entry) == AE_IFLNK) + rr_flag |= RR_USE_SL; + if (isoent->rr_parent != NULL) + rr_flag |= RR_USE_RE; + if (isoent->rr_child != NULL) + rr_flag |= RR_USE_CL; + if (archive_entry_filetype(file->entry) == AE_IFCHR || + archive_entry_filetype(file->entry) == AE_IFBLK) + rr_flag |= RR_USE_PN; +#ifdef COMPAT_MKISOFS + /* + * mkisofs 2.01.01a63 records "RE" extension to + * the entry of "rr_moved" directory. + * I don't understand this behavior. + */ + if (isoent->virtual && + isoent->parent == iso9660->primary.rootent && + strcmp(isoent->file->basename.s, "rr_moved") == 0) + rr_flag |= RR_USE_RE; +#endif + } + + /* Write "SP" System Use Entry. */ + if (t == DIR_REC_SELF && isoent == isoent->parent) { + length = 7; + if (bp != NULL) { + bp[1] = 'S'; + bp[2] = 'P'; + bp[3] = length; + bp[4] = 1; /* version */ + bp[5] = 0xBE; /* Check Byte */ + bp[6] = 0xEF; /* Check Byte */ + bp[7] = 0; + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "RR" System Use Entry. */ + length = 5; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'R'; + bp[2] = 'R'; + bp[3] = length; + bp[4] = 1; /* version */ + bp[5] = rr_flag; + bp += length; + } + extra_tell_used_size(&ctl, length); + + /* Write "NM" System Use Entry. */ + if (rr_flag & RR_USE_NM) { + /* + * "NM" Format: + * e.g. a basename is 'foo' + * len ver flg + * +----+----+----+----+----+----+----+----+ + * | 'N'| 'M'| 08 | 01 | 00 | 'f'| 'o'| 'o'| + * +----+----+----+----+----+----+----+----+ + * <----------------- len -----------------> + */ + size_t nmlen = file->basename.length; + const char *nm = file->basename.s; + size_t nmmax; + + if (extra_space(&ctl) < 6) + bp = extra_next_record(&ctl, 6); + if (bp != NULL) { + bp[1] = 'N'; + bp[2] = 'M'; + bp[4] = 1; /* version */ + } + nmmax = extra_space(&ctl); + if (nmmax > 0xff) + nmmax = 0xff; + while (nmlen + 5 > nmmax) { + length = nmmax; + if (bp != NULL) { + bp[3] = length; + bp[5] = 0x01;/* Alternate Name continues + * in next "NM" field */ + memcpy(bp+6, nm, length - 5); + bp += length; + } + nmlen -= length - 5; + nm += length - 5; + extra_tell_used_size(&ctl, length); + if (extra_space(&ctl) < 6) { + bp = extra_next_record(&ctl, 6); + nmmax = extra_space(&ctl); + if (nmmax > 0xff) + nmmax = 0xff; + } + if (bp != NULL) { + bp[1] = 'N'; + bp[2] = 'M'; + bp[4] = 1; /* version */ + } + } + length = 5 + nmlen; + if (bp != NULL) { + bp[3] = length; + bp[5] = 0; + memcpy(bp+6, nm, nmlen); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "PX" System Use Entry. */ + if (rr_flag & RR_USE_PX) { + /* + * "PX" Format: + * len ver + * +----+----+----+----+-----------+-----------+ + * | 'P'| 'X'| 2C | 01 | FILE MODE | LINKS | + * +----+----+----+----+-----------+-----------+ + * 0 1 2 3 4 12 20 + * +-----------+-----------+------------------+ + * | USER ID | GROUP ID |FILE SERIAL NUMBER| + * +-----------+-----------+------------------+ + * 20 28 36 44 + */ + length = 44; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + mode_t mode; + uid_t uid; + gid_t gid; + + mode = archive_entry_mode(file->entry); + uid = archive_entry_uid(file->entry); + gid = archive_entry_gid(file->entry); + if (iso9660->opt.rr == OPT_RR_USEFUL) { + /* + * This action is simular mkisofs -r option + * but our rockridge=useful option does not + * set a zero to uid and gid. + */ + /* set all read bit ON */ + mode |= 0444; +#if !defined(_WIN32) && !defined(__CYGWIN__) + if (mode & 0111) +#endif + /* set all exec bit ON */ + mode |= 0111; + /* clear all write bits. */ + mode &= ~0222; + /* clear setuid,setgid,sticky bits. */ + mode &= ~07000; + } + + bp[1] = 'P'; + bp[2] = 'X'; + bp[3] = length; + bp[4] = 1; /* version */ + /* file mode */ + set_num_733(bp+5, mode); + /* file links (stat.st_nlink) */ + set_num_733(bp+13, + archive_entry_nlink(file->entry)); + set_num_733(bp+21, uid); + set_num_733(bp+29, gid); + /* File Serial Number */ + if (pxent->dir) + set_num_733(bp+37, pxent->dir_location); + else if (file->hardlink_target != NULL) + set_num_733(bp+37, + file->hardlink_target->cur_content->location); + else + set_num_733(bp+37, + file->cur_content->location); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "SL" System Use Entry. */ + if (rr_flag & RR_USE_SL) { + /* + * "SL" Format: + * e.g. a symbolic name is 'foo/bar' + * len ver flg + * +----+----+----+----+----+------------+ + * | 'S'| 'L'| 0F | 01 | 00 | components | + * +----+----+----+----+----+-----+------+ + * 0 1 2 3 4 5 ...|... 15 + * <----------------- len --------+------> + * components : | + * cflg clen | + * +----+----+----+----+----+ | + * | 00 | 03 | 'f'| 'o'| 'o'| <---+ + * +----+----+----+----+----+ | + * 5 6 7 8 9 10 | + * cflg clen | + * +----+----+----+----+----+ | + * | 00 | 03 | 'b'| 'a'| 'r'| <---+ + * +----+----+----+----+----+ + * 10 11 12 13 14 15 + * + * - cflg : flag of componet + * - clen : length of componet + */ + const char *sl; + char sl_last; + + if (extra_space(&ctl) < 7) + bp = extra_next_record(&ctl, 7); + sl = file->symlink.s; + sl_last = '\0'; + if (bp != NULL) { + bp[1] = 'S'; + bp[2] = 'L'; + bp[4] = 1; /* version */ + } + for (;;) { + unsigned char *nc, *cf, *cl, cldmy = 0; + int sllen, slmax; + + slmax = extra_space(&ctl); + if (slmax > 0xff) + slmax = 0xff; + if (bp != NULL) + nc = &bp[6]; + else + nc = NULL; + cf = cl = NULL; + sllen = 0; + while (*sl && sllen + 11 < slmax) { + if (sl_last == '\0' && sl[0] == '/') { + /* + * flg len + * +----+----+ + * | 08 | 00 | ROOT component. + * +----+----+ ("/") + * + * Root component has to appear + * at the first component only. + */ + if (nc != NULL) { + cf = nc++; + *cf = 0x08; /* ROOT */ + *nc++ = 0; + } + sllen += 2; + sl++; + sl_last = '/'; + cl = NULL; + continue; + } + if (((sl_last == '\0' || sl_last == '/') && + sl[0] == '.' && sl[1] == '.' && + (sl[2] == '/' || sl[2] == '\0')) || + (sl[0] == '/' && + sl[1] == '.' && sl[2] == '.' && + (sl[3] == '/' || sl[3] == '\0'))) { + /* + * flg len + * +----+----+ + * | 04 | 00 | PARENT component. + * +----+----+ ("..") + */ + if (nc != NULL) { + cf = nc++; + *cf = 0x04; /* PARENT */ + *nc++ = 0; + } + sllen += 2; + if (sl[0] == '/') + sl += 3;/* skip "/.." */ + else + sl += 2;/* skip ".." */ + sl_last = '.'; + cl = NULL; + continue; + } + if (((sl_last == '\0' || sl_last == '/') && + sl[0] == '.' && + (sl[1] == '/' || sl[1] == '\0')) || + (sl[0] == '/' && sl[1] == '.' && + (sl[2] == '/' || sl[2] == '\0'))) { + /* + * flg len + * +----+----+ + * | 02 | 00 | CURREENT component. + * +----+----+ (".") + */ + if (nc != NULL) { + cf = nc++; + *cf = 0x02; /* CURRENT */ + *nc++ = 0; + } + sllen += 2; + if (sl[0] == '/') + sl += 2;/* skip "/." */ + else + sl ++; /* skip "." */ + sl_last = '.'; + cl = NULL; + continue; + } + if (sl[0] == '/' || cl == NULL) { + if (nc != NULL) { + cf = nc++; + *cf = 0; + cl = nc++; + *cl = 0; + } else + cl = &cldmy; + sllen += 2; + if (sl[0] == '/') { + sl_last = *sl++; + continue; + } + } + sl_last = *sl++; + if (nc != NULL) { + *nc++ = sl_last; + (*cl) ++; + } + sllen++; + } + if (*sl) { + length = 5 + sllen; + if (bp != NULL) { + /* + * Mark flg as CONTINUE component. + */ + *cf |= 0x01; + /* + * len ver flg + * +----+----+----+----+----+- + * | 'S'| 'L'| XX | 01 | 01 | + * +----+----+----+----+----+- + * ^ + * continues in next "SL" + */ + bp[3] = length; + bp[5] = 0x01;/* This Symbolic Link + * continues in next + * "SL" field */ + bp += length; + } + extra_tell_used_size(&ctl, length); + if (extra_space(&ctl) < 11) + bp = extra_next_record(&ctl, 11); + if (bp != NULL) { + /* Next 'SL' */ + bp[1] = 'S'; + bp[2] = 'L'; + bp[4] = 1; /* version */ + } + } else { + length = 5 + sllen; + if (bp != NULL) { + bp[3] = length; + bp[5] = 0; + bp += length; + } + extra_tell_used_size(&ctl, length); + break; + } + } + } + + /* Write "TF" System Use Entry. */ + if (rr_flag & RR_USE_TF) { + /* + * "TF" Format: + * len ver + * +----+----+----+----+-----+-------------+ + * | 'T'| 'F'| XX | 01 |FLAGS| TIME STAMPS | + * +----+----+----+----+-----+-------------+ + * 0 1 2 3 4 5 XX + * TIME STAMPS : ISO 9660 Standard 9.1.5. + * If TF_LONG_FORM FLAGS is set, + * use ISO9660 Standard 8.4.26.1. + */ +#define TF_CREATION 0x01 /* Creation time recorded */ +#define TF_MODIFY 0x02 /* Modification time recorded */ +#define TF_ACCESS 0x04 /* Last Access time recorded */ +#define TF_ATTRIBUTES 0x08 /* Last Attribute Change time recorded */ +#define TF_BACKUP 0x10 /* Last Backup time recorded */ +#define TF_EXPIRATION 0x20 /* Expiration time recorded */ +#define TF_EFFECTIVE 0x40 /* Effective time recorded */ +#define TF_LONG_FORM 0x80 /* ISO 9660 17-byte time format used */ + unsigned char tf_flags; + + length = 5; + tf_flags = 0; +#ifndef COMPAT_MKISOFS + if (archive_entry_birthtime_is_set(file->entry) && + archive_entry_birthtime(file->entry) <= + archive_entry_mtime(file->entry)) { + length += 7; + tf_flags |= TF_CREATION; + } +#endif + if (archive_entry_mtime_is_set(file->entry)) { + length += 7; + tf_flags |= TF_MODIFY; + } + if (archive_entry_atime_is_set(file->entry)) { + length += 7; + tf_flags |= TF_ACCESS; + } + if (archive_entry_ctime_is_set(file->entry)) { + length += 7; + tf_flags |= TF_ATTRIBUTES; + } + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'T'; + bp[2] = 'F'; + bp[3] = length; + bp[4] = 1; /* version */ + bp[5] = tf_flags; + bp += 5; + /* Creation time */ + if (tf_flags & TF_CREATION) { + set_time_915(bp+1, + archive_entry_birthtime(file->entry)); + bp += 7; + } + /* Modification time */ + if (tf_flags & TF_MODIFY) { + set_time_915(bp+1, + archive_entry_mtime(file->entry)); + bp += 7; + } + /* Last Access time */ + if (tf_flags & TF_ACCESS) { + set_time_915(bp+1, + archive_entry_atime(file->entry)); + bp += 7; + } + /* Last Attribute Change time */ + if (tf_flags & TF_ATTRIBUTES) { + set_time_915(bp+1, + archive_entry_ctime(file->entry)); + bp += 7; + } + } + extra_tell_used_size(&ctl, length); + } + + /* Write "RE" System Use Entry. */ + if (rr_flag & RR_USE_RE) { + /* + * "RE" Format: + * len ver + * +----+----+----+----+ + * | 'R'| 'E'| 04 | 01 | + * +----+----+----+----+ + * 0 1 2 3 4 + */ + length = 4; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'R'; + bp[2] = 'E'; + bp[3] = length; + bp[4] = 1; /* version */ + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "PL" System Use Entry. */ + if (rr_flag & RR_USE_PL) { + /* + * "PL" Format: + * len ver + * +----+----+----+----+------------+ + * | 'P'| 'L'| 0C | 01 | *LOCATION | + * +----+----+----+----+------------+ + * 0 1 2 3 4 12 + * *LOCATION: location of parent directory + */ + length = 12; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'P'; + bp[2] = 'L'; + bp[3] = length; + bp[4] = 1; /* version */ + set_num_733(bp + 5, + rr_parent->dir_location); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "CL" System Use Entry. */ + if (rr_flag & RR_USE_CL) { + /* + * "CL" Format: + * len ver + * +----+----+----+----+------------+ + * | 'C'| 'L'| 0C | 01 | *LOCATION | + * +----+----+----+----+------------+ + * 0 1 2 3 4 12 + * *LOCATION: location of child directory + */ + length = 12; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'C'; + bp[2] = 'L'; + bp[3] = length; + bp[4] = 1; /* version */ + set_num_733(bp + 5, + isoent->rr_child->dir_location); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "PN" System Use Entry. */ + if (rr_flag & RR_USE_PN) { + /* + * "PN" Format: + * len ver + * +----+----+----+----+------------+------------+ + * | 'P'| 'N'| 14 | 01 | dev_t high | dev_t low | + * +----+----+----+----+------------+------------+ + * 0 1 2 3 4 12 20 + */ + length = 20; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + uint64_t dev; + + bp[1] = 'P'; + bp[2] = 'N'; + bp[3] = length; + bp[4] = 1; /* version */ + dev = (uint64_t)archive_entry_rdev(file->entry); + set_num_733(bp + 5, dev >> 32); + set_num_733(bp + 13, dev & 0xFFFFFFFF); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "ZF" System Use Entry. */ + if (file->zisofs.header_size) { + /* + * "ZF" Format: + * len ver + * +----+----+----+----+----+----+-------------+ + * | 'Z'| 'F'| 10 | 01 | 'p'| 'z'| Header Size | + * +----+----+----+----+----+----+-------------+ + * 0 1 2 3 4 5 6 7 + * +--------------------+-------------------+ + * | Log2 of block Size | Uncompressed Size | + * +--------------------+-------------------+ + * 7 8 16 + */ + length = 16; + if (extra_space(&ctl) < length) + bp = extra_next_record(&ctl, length); + if (bp != NULL) { + bp[1] = 'Z'; + bp[2] = 'F'; + bp[3] = length; + bp[4] = 1; /* version */ + bp[5] = 'p'; + bp[6] = 'z'; + bp[7] = file->zisofs.header_size; + bp[8] = file->zisofs.log2_bs; + set_num_733(bp + 9, file->zisofs.uncompressed_size); + bp += length; + } + extra_tell_used_size(&ctl, length); + } + + /* Write "CE" System Use Entry. */ + if (t == DIR_REC_SELF && isoent == isoent->parent) { + length = RR_CE_SIZE; + if (bp != NULL) + set_SUSP_CE(bp+1, iso9660->location_rrip_er, + 0, RRIP_ER_SIZE); + extra_tell_used_size(&ctl, length); + } + + extra_close_record(&ctl, 0); + + return (ctl.dr_len); +} + +/* + * Write data of a Directory Record or calculate writing bytes itself. + * If parameter `p' is NULL, calculates the size of writing data, which + * a Directory Record needs to write, then it saved and return + * the calculated size. + * Parameter `n' is a remaining size of buffer. when parameter `p' is + * not NULL, check whether that `n' is not less than the saved size. + * if that `n' is small, return zero. + * + * This format of the Directory Record is according to + * ISO9660 Standard 9.1 + */ +static int +set_directory_record(unsigned char *p, size_t n, struct isoent *isoent, + struct iso9660 *iso9660, enum dir_rec_type t, + enum vdd_type vdd_type) +{ + unsigned char *bp; + size_t dr_len; + size_t fi_len; + + if (p != NULL) { + /* + * Check whether a write buffer size is less than the + * saved size which is needed to write this Directory + * Record. + */ + switch (t) { + case DIR_REC_VD: + dr_len = isoent->dr_len.vd; break; + case DIR_REC_SELF: + dr_len = isoent->dr_len.self; break; + case DIR_REC_PARENT: + dr_len = isoent->dr_len.parent; break; + case DIR_REC_NORMAL: + default: + dr_len = isoent->dr_len.normal; break; + } + if (dr_len > n) + return (0);/* Needs more buffer size. */ + } + + if (t == DIR_REC_NORMAL && isoent->identifier != NULL) + fi_len = isoent->id_len; + else + fi_len = 1; + + if (p != NULL) { + struct isoent *xisoent; + struct isofile *file; + unsigned char flag; + + if (t == DIR_REC_PARENT) + xisoent = isoent->parent; + else + xisoent = isoent; + file = isoent->file; + if (file->hardlink_target != NULL) + file = file->hardlink_target; + /* Make a file flag. */ + if (xisoent->dir) + flag = FILE_FLAG_DIRECTORY; + else { + if (file->cur_content->next != NULL) + flag = FILE_FLAG_MULTI_EXTENT; + else + flag = 0; + } + + bp = p -1; + /* Extended Attribute Record Length */ + set_num_711(bp+2, 0); + /* Location of Extent */ + if (xisoent->dir) + set_num_733(bp+3, xisoent->dir_location); + else + set_num_733(bp+3, file->cur_content->location); + /* Data Length */ + if (xisoent->dir) + set_num_733(bp+11, + xisoent->dir_block * LOGICAL_BLOCK_SIZE); + else + set_num_733(bp+11, file->cur_content->size); + /* Recording Date and Time */ + /* NOTE: + * If a file type is symbolic link, you are seeing this + * field value is different from a value mkisofs makes. + * libarchive uses lstat to get this one, but it + * seems mkisofs uses stat to get. + */ + set_time_915(bp+19, + archive_entry_mtime(xisoent->file->entry)); + /* File Flags */ + bp[26] = flag; + /* File Unit Size */ + set_num_711(bp+27, 0); + /* Interleave Gap Size */ + set_num_711(bp+28, 0); + /* Volume Sequence Number */ + set_num_723(bp+29, iso9660->volume_sequence_number); + /* Length of File Identifier */ + set_num_711(bp+33, fi_len); + /* File Identifier */ + switch (t) { + case DIR_REC_VD: + case DIR_REC_SELF: + set_num_711(bp+34, 0); + break; + case DIR_REC_PARENT: + set_num_711(bp+34, 1); + break; + case DIR_REC_NORMAL: + if (isoent->identifier != NULL) + memcpy(bp+34, isoent->identifier, fi_len); + else + set_num_711(bp+34, 0); + break; + } + } else + bp = NULL; + dr_len = 33 + fi_len; + /* Padding Field */ + if (dr_len & 0x01) { + dr_len ++; + if (p != NULL) + bp[dr_len] = 0; + } + + /* Volume Descriptor does not record extension. */ + if (t == DIR_REC_VD) { + if (p != NULL) + /* Length of Directory Record */ + set_num_711(p, dr_len); + else + isoent->dr_len.vd = dr_len; + return (dr_len); + } + + /* Rockridge */ + if (iso9660->opt.rr && vdd_type != VDD_JOLIET) + dr_len = set_directory_record_rr(bp, dr_len, + isoent, iso9660, t); + + if (p != NULL) + /* Length of Directory Record */ + set_num_711(p, dr_len); + else { + /* + * Save the size which is needed to write this + * Directory Record. + */ + switch (t) { + case DIR_REC_VD: + /* This case does not come, but compiler + * complains that DIR_REC_VD not handled + * in switch .... */ + break; + case DIR_REC_SELF: + isoent->dr_len.self = dr_len; break; + case DIR_REC_PARENT: + isoent->dr_len.parent = dr_len; break; + case DIR_REC_NORMAL: + isoent->dr_len.normal = dr_len; break; + } + } + + return (dr_len); +} + +/* + * Calculate the size of a directory record. + */ +static inline int +get_dir_rec_size(struct iso9660 *iso9660, struct isoent *isoent, + enum dir_rec_type t, enum vdd_type vdd_type) +{ + + return (set_directory_record(NULL, SIZE_MAX, + isoent, iso9660, t, vdd_type)); +} + +/* + * Manage to write ISO-image data with wbuff to reduce calling + * __archive_write_output() for performance. + */ + + +static inline unsigned char * +wb_buffptr(struct archive_write *a) +{ + struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + + return (&(iso9660->wbuff[sizeof(iso9660->wbuff) + - iso9660->wbuff_remaining])); +} + +static int +wb_write_out(struct archive_write *a) +{ + struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + size_t wsize, nw; + int r; + + wsize = sizeof(iso9660->wbuff) - iso9660->wbuff_remaining; + nw = wsize % LOGICAL_BLOCK_SIZE; + if (iso9660->wbuff_type == WB_TO_STREAM) + r = __archive_write_output(a, iso9660->wbuff, wsize - nw); + else + r = write_to_temp(a, iso9660->wbuff, wsize - nw); + /* Increase the offset. */ + iso9660->wbuff_offset += wsize - nw; + if (iso9660->wbuff_offset > iso9660->wbuff_written) + iso9660->wbuff_written = iso9660->wbuff_offset; + iso9660->wbuff_remaining = sizeof(iso9660->wbuff); + if (nw) { + iso9660->wbuff_remaining -= nw; + memmove(iso9660->wbuff, iso9660->wbuff + wsize - nw, nw); + } + return (r); +} + +static int +wb_consume(struct archive_write *a, size_t size) +{ + struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + + if (size > iso9660->wbuff_remaining || + iso9660->wbuff_remaining == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal Programing error: iso9660:wb_consume()" + " size=%jd, wbuff_remaining=%jd", + (intmax_t)size, (intmax_t)iso9660->wbuff_remaining); + return (ARCHIVE_FATAL); + } + iso9660->wbuff_remaining -= size; + if (iso9660->wbuff_remaining < LOGICAL_BLOCK_SIZE) + return (wb_write_out(a)); + return (ARCHIVE_OK); +} + +#ifdef HAVE_ZLIB_H + +static int +wb_set_offset(struct archive_write *a, int64_t off) +{ + struct iso9660 *iso9660 = (struct iso9660 *)a->format_data; + int64_t used, ext_bytes; + + if (iso9660->wbuff_type != WB_TO_TEMP) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal Programing error: iso9660:wb_set_offset()"); + return (ARCHIVE_FATAL); + } + + used = sizeof(iso9660->wbuff) - iso9660->wbuff_remaining; + if (iso9660->wbuff_offset + used > iso9660->wbuff_tail) + iso9660->wbuff_tail = iso9660->wbuff_offset + used; + if (iso9660->wbuff_offset < iso9660->wbuff_written) { + if (used > 0 && + write_to_temp(a, iso9660->wbuff, used) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->wbuff_offset = iso9660->wbuff_written; + lseek(iso9660->temp_fd, iso9660->wbuff_offset, SEEK_SET); + iso9660->wbuff_remaining = sizeof(iso9660->wbuff); + used = 0; + } + if (off < iso9660->wbuff_offset) { + /* + * Write out waiting data. + */ + if (used > 0) { + if (wb_write_out(a) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + lseek(iso9660->temp_fd, off, SEEK_SET); + iso9660->wbuff_offset = off; + iso9660->wbuff_remaining = sizeof(iso9660->wbuff); + } else if (off <= iso9660->wbuff_tail) { + iso9660->wbuff_remaining = + sizeof(iso9660->wbuff) - (off - iso9660->wbuff_offset); + } else { + ext_bytes = off - iso9660->wbuff_tail; + iso9660->wbuff_remaining = sizeof(iso9660->wbuff) + - (iso9660->wbuff_tail - iso9660->wbuff_offset); + while (ext_bytes >= iso9660->wbuff_remaining) { + if (write_null(a, (size_t)iso9660->wbuff_remaining) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + ext_bytes -= iso9660->wbuff_remaining; + } + if (ext_bytes > 0) { + if (write_null(a, (size_t)ext_bytes) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + } + return (ARCHIVE_OK); +} + +#endif /* HAVE_ZLIB_H */ + +static int +write_null(struct archive_write *a, size_t size) +{ + size_t remaining; + unsigned char *p, *old; + int r; + + remaining = wb_remaining(a); + p = wb_buffptr(a); + if (size <= remaining) { + memset(p, 0, size); + return (wb_consume(a, size)); + } + memset(p, 0, remaining); + r = wb_consume(a, remaining); + if (r != ARCHIVE_OK) + return (r); + size -= remaining; + old = p; + p = wb_buffptr(a); + memset(p, 0, old - p); + remaining = wb_remaining(a); + while (size) { + size_t wsize = size; + + if (wsize > remaining) + wsize = remaining; + r = wb_consume(a, wsize); + if (r != ARCHIVE_OK) + return (r); + size -= wsize; + } + return (ARCHIVE_OK); +} + +/* + * Write Volume Descriptor Set Terminator + */ +static int +write_VD_terminator(struct archive_write *a) +{ + unsigned char *bp; + + bp = wb_buffptr(a) -1; + set_VD_bp(bp, VDT_TERMINATOR, 1); + set_unused_field_bp(bp, 8, LOGICAL_BLOCK_SIZE); + + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +static int +set_file_identifier(unsigned char *bp, int from, int to, enum vdc vdc, + struct archive_write *a, struct vdd *vdd, struct archive_string *id, + const char *label, int leading_under, enum char_type char_type) +{ + char identifier[256]; + struct isoent *isoent; + const char *ids; + size_t len; + int r; + + if (id->length > 0 && leading_under && id->s[0] != '_') { + if (char_type == A_CHAR) + r = set_str_a_characters_bp(a, bp, from, to, id->s, vdc); + else + r = set_str_d_characters_bp(a, bp, from, to, id->s, vdc); + } else if (id->length > 0) { + ids = id->s; + if (leading_under) + ids++; + isoent = isoent_find_entry(vdd->rootent, ids); + if (isoent == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Not Found %s `%s'.", + label, ids); + return (ARCHIVE_FATAL); + } + len = isoent->ext_off + isoent->ext_len; + if (vdd->vdd_type == VDD_JOLIET) { + if (len > sizeof(identifier)-2) + len = sizeof(identifier)-2; + } else { + if (len > sizeof(identifier)-1) + len = sizeof(identifier)-1; + } + memcpy(identifier, isoent->identifier, len); + identifier[len] = '\0'; + if (vdd->vdd_type == VDD_JOLIET) { + identifier[len+1] = 0; + vdc = VDC_UCS2_DIRECT; + } + if (char_type == A_CHAR) + r = set_str_a_characters_bp(a, bp, from, to, + identifier, vdc); + else + r = set_str_d_characters_bp(a, bp, from, to, + identifier, vdc); + } else { + if (char_type == A_CHAR) + r = set_str_a_characters_bp(a, bp, from, to, NULL, vdc); + else + r = set_str_d_characters_bp(a, bp, from, to, NULL, vdc); + } + return (r); +} + +/* + * Write Primary/Supplementary Volume Descriptor + */ +static int +write_VD(struct archive_write *a, struct vdd *vdd) +{ + struct iso9660 *iso9660; + unsigned char *bp; + uint16_t volume_set_size = 1; + char identifier[256]; + enum VD_type vdt; + enum vdc vdc; + unsigned char vd_ver, fst_ver; + int r; + + iso9660 = a->format_data; + switch (vdd->vdd_type) { + case VDD_JOLIET: + vdt = VDT_SUPPLEMENTARY; + vd_ver = fst_ver = 1; + vdc = VDC_UCS2; + break; + case VDD_ENHANCED: + vdt = VDT_SUPPLEMENTARY; + vd_ver = fst_ver = 2; + vdc = VDC_LOWERCASE; + break; + case VDD_PRIMARY: + default: + vdt = VDT_PRIMARY; + vd_ver = fst_ver = 1; +#ifdef COMPAT_MKISOFS + vdc = VDC_LOWERCASE; +#else + vdc = VDC_STD; +#endif + break; + } + + bp = wb_buffptr(a) -1; + /* Volume Descriptor Type */ + set_VD_bp(bp, vdt, vd_ver); + /* Unused Field */ + set_unused_field_bp(bp, 8, 8); + /* System Identifier */ + get_system_identitier(identifier, sizeof(identifier)); + r = set_str_a_characters_bp(a, bp, 9, 40, identifier, vdc); + if (r != ARCHIVE_OK) + return (r); + /* Volume Identifier */ + r = set_str_d_characters_bp(a, bp, 41, 72, + iso9660->volume_identifier.s, vdc); + if (r != ARCHIVE_OK) + return (r); + /* Unused Field */ + set_unused_field_bp(bp, 73, 80); + /* Volume Space Size */ + set_num_733(bp+81, iso9660->volume_space_size); + if (vdd->vdd_type == VDD_JOLIET) { + /* Escape Sequences */ + bp[89] = 0x25;/* UCS-2 Level 3 */ + bp[90] = 0x2F; + bp[91] = 0x45; + memset(bp + 92, 0, 120 - 92 + 1); + } else { + /* Unused Field */ + set_unused_field_bp(bp, 89, 120); + } + /* Volume Set Size */ + set_num_723(bp+121, volume_set_size); + /* Volume Sequence Number */ + set_num_723(bp+125, iso9660->volume_sequence_number); + /* Logical Block Size */ + set_num_723(bp+129, LOGICAL_BLOCK_SIZE); + /* Path Table Size */ + set_num_733(bp+133, vdd->path_table_size); + /* Location of Occurrence of Type L Path Table */ + set_num_731(bp+141, vdd->location_type_L_path_table); + /* Location of Optional Occurrence of Type L Path Table */ + set_num_731(bp+145, 0); + /* Location of Occurrence of Type M Path Table */ + set_num_732(bp+149, vdd->location_type_M_path_table); + /* Location of Optional Occurrence of Type M Path Table */ + set_num_732(bp+153, 0); + /* Directory Record for Root Directory(BP 157 to 190) */ + set_directory_record(bp+157, 190-157+1, vdd->rootent, + iso9660, DIR_REC_VD, vdd->vdd_type); + /* Volume Set Identifier */ + r = set_str_d_characters_bp(a, bp, 191, 318, "", vdc); + if (r != ARCHIVE_OK) + return (r); + /* Publisher Identifier */ + r = set_file_identifier(bp, 319, 446, vdc, a, vdd, + &(iso9660->publisher_identifier), + "Publisher File", 1, A_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Data Preparer Identifier */ + r = set_file_identifier(bp, 447, 574, vdc, a, vdd, + &(iso9660->data_preparer_identifier), + "Data Preparer File", 1, A_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Application Identifier */ + r = set_file_identifier(bp, 575, 702, vdc, a, vdd, + &(iso9660->application_identifier), + "Application File", 1, A_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Copyright File Identifier */ + r = set_file_identifier(bp, 703, 739, vdc, a, vdd, + &(iso9660->copyright_file_identifier), + "Copyright File", 0, D_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Abstract File Identifier */ + r = set_file_identifier(bp, 740, 776, vdc, a, vdd, + &(iso9660->abstract_file_identifier), + "Abstract File", 0, D_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Bibliongraphic File Identifier */ + r = set_file_identifier(bp, 777, 813, vdc, a, vdd, + &(iso9660->bibliographic_file_identifier), + "Bibliongraphic File", 0, D_CHAR); + if (r != ARCHIVE_OK) + return (r); + /* Volume Creation Date and Time */ + set_date_time(bp+814, iso9660->birth_time); + /* Volume Modification Date and Time */ + set_date_time(bp+831, iso9660->birth_time); + /* Volume Expiration Date and Time(obsolete) */ + set_date_time_null(bp+848); + /* Volume Effective Date and Time */ + set_date_time(bp+865, iso9660->birth_time); + /* File Structure Version */ + bp[882] = fst_ver; + /* Reserved */ + bp[883] = 0; + /* Application Use */ + memset(bp + 884, 0x20, 1395 - 884 + 1); + /* Reserved */ + set_unused_field_bp(bp, 1396, LOGICAL_BLOCK_SIZE); + + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +/* + * Write Boot Record Volume Descriptor + */ +static int +write_VD_boot_record(struct archive_write *a) +{ + struct iso9660 *iso9660; + unsigned char *bp; + + iso9660 = a->format_data; + bp = wb_buffptr(a) -1; + /* Volume Descriptor Type */ + set_VD_bp(bp, VDT_BOOT_RECORD, 1); + /* Boot System Identifier */ + memcpy(bp+8, "EL TORITO SPECIFICATION", 23); + set_unused_field_bp(bp, 8+23, 39); + /* Unused */ + set_unused_field_bp(bp, 40, 71); + /* Absolute pointer to first sector of Boot Catalog */ + set_num_731(bp+72, + iso9660->el_torito.catalog->file->content.location); + /* Unused */ + set_unused_field_bp(bp, 76, LOGICAL_BLOCK_SIZE); + + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +enum keytype { + KEY_FLG, + KEY_STR, + KEY_INT, + KEY_HEX, +}; +static void +set_option_info(struct archive_string *info, int *opt, const char *key, + enum keytype type, ...) +{ + va_list ap; + char prefix; + const char *s; + int d; + + prefix = (*opt==0)? ' ':','; + va_start(ap, type); + switch (type) { + case KEY_FLG: + d = va_arg(ap, int); + archive_string_sprintf(info, "%c%s%s", + prefix, (d == 0)?"!":"", key); + break; + case KEY_STR: + s = va_arg(ap, const char *); + archive_string_sprintf(info, "%c%s=%s", + prefix, key, s); + break; + case KEY_INT: + d = va_arg(ap, int); + archive_string_sprintf(info, "%c%s=%d", + prefix, key, d); + break; + case KEY_HEX: + d = va_arg(ap, int); + archive_string_sprintf(info, "%c%s=%x", + prefix, key, d); + break; + } + va_end(ap); + + *opt = 1; +} + +/* + * Make Non-ISO File System Information + */ +static int +write_information_block(struct archive_write *a) +{ + struct iso9660 *iso9660; + char buf[128]; + const char *v; + int opt, r; + struct archive_string info; + size_t info_size = LOGICAL_BLOCK_SIZE * + NON_ISO_FILE_SYSTEM_INFORMATION_BLOCK; + + iso9660 = (struct iso9660 *)a->format_data; + if (info_size > wb_remaining(a)) { + r = wb_write_out(a); + if (r != ARCHIVE_OK) + return (r); + } + archive_string_init(&info); + if (archive_string_ensure(&info, info_size) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + memset(info.s, 0, info_size); + opt = 0; +#if defined(HAVE__CTIME64_S) + _ctime64_s(buf, sizeof(buf), &(iso9660->birth_time)); +#elif defined(HAVE_CTIME_R) + ctime_r(&(iso9660->birth_time), buf); +#else + strncpy(buf, ctime(&(iso9660->birth_time)), sizeof(buf)-1); + buf[sizeof(buf)-1] = '\0'; +#endif + archive_string_sprintf(&info, + "INFO %s%s", buf, archive_version_string()); + if (iso9660->opt.abstract_file != OPT_ABSTRACT_FILE_DEFAULT) + set_option_info(&info, &opt, "abstract-file", + KEY_STR, iso9660->abstract_file_identifier.s); + if (iso9660->opt.application_id != OPT_APPLICATION_ID_DEFAULT) + set_option_info(&info, &opt, "application-id", + KEY_STR, iso9660->application_identifier.s); + if (iso9660->opt.allow_vernum != OPT_ALLOW_VERNUM_DEFAULT) + set_option_info(&info, &opt, "allow-vernum", + KEY_FLG, iso9660->opt.allow_vernum); + if (iso9660->opt.biblio_file != OPT_BIBLIO_FILE_DEFAULT) + set_option_info(&info, &opt, "biblio-file", + KEY_STR, iso9660->bibliographic_file_identifier.s); + if (iso9660->opt.boot != OPT_BOOT_DEFAULT) + set_option_info(&info, &opt, "boot", + KEY_STR, iso9660->el_torito.boot_filename.s); + if (iso9660->opt.boot_catalog != OPT_BOOT_CATALOG_DEFAULT) + set_option_info(&info, &opt, "boot-catalog", + KEY_STR, iso9660->el_torito.catalog_filename.s); + if (iso9660->opt.boot_info_table != OPT_BOOT_INFO_TABLE_DEFAULT) + set_option_info(&info, &opt, "boot-info-table", + KEY_FLG, iso9660->opt.boot_info_table); + if (iso9660->opt.boot_load_seg != OPT_BOOT_LOAD_SEG_DEFAULT) + set_option_info(&info, &opt, "boot-load-seg", + KEY_HEX, iso9660->el_torito.boot_load_seg); + if (iso9660->opt.boot_load_size != OPT_BOOT_LOAD_SIZE_DEFAULT) + set_option_info(&info, &opt, "boot-load-size", + KEY_INT, iso9660->el_torito.boot_load_size); + if (iso9660->opt.boot_type != OPT_BOOT_TYPE_DEFAULT) { + v = "no-emulation"; + if (iso9660->opt.boot_type == OPT_BOOT_TYPE_FD) + v = "fd"; + if (iso9660->opt.boot_type == OPT_BOOT_TYPE_HARD_DISK) + v = "hard-disk"; + set_option_info(&info, &opt, "boot-type", + KEY_STR, v); + } +#ifdef HAVE_ZLIB_H + if (iso9660->opt.compression_level != OPT_COMPRESSION_LEVEL_DEFAULT) + set_option_info(&info, &opt, "compression-level", + KEY_INT, iso9660->zisofs.compression_level); +#endif + if (iso9660->opt.copyright_file != OPT_COPYRIGHT_FILE_DEFAULT) + set_option_info(&info, &opt, "copyright-file", + KEY_STR, iso9660->copyright_file_identifier.s); + if (iso9660->opt.iso_level != OPT_ISO_LEVEL_DEFAULT) + set_option_info(&info, &opt, "iso-level", + KEY_INT, iso9660->opt.iso_level); + if (iso9660->opt.joliet != OPT_JOLIET_DEFAULT) { + if (iso9660->opt.joliet == OPT_JOLIET_LONGNAME) + set_option_info(&info, &opt, "joliet", + KEY_STR, "long"); + else + set_option_info(&info, &opt, "joliet", + KEY_FLG, iso9660->opt.joliet); + } + if (iso9660->opt.limit_depth != OPT_LIMIT_DEPTH_DEFAULT) + set_option_info(&info, &opt, "limit-depth", + KEY_FLG, iso9660->opt.limit_depth); + if (iso9660->opt.limit_dirs != OPT_LIMIT_DIRS_DEFAULT) + set_option_info(&info, &opt, "limit-dirs", + KEY_FLG, iso9660->opt.limit_dirs); + if (iso9660->opt.pad != OPT_PAD_DEFAULT) + set_option_info(&info, &opt, "pad", + KEY_FLG, iso9660->opt.pad); + if (iso9660->opt.publisher != OPT_PUBLISHER_DEFAULT) + set_option_info(&info, &opt, "publisher", + KEY_STR, iso9660->publisher_identifier.s); + if (iso9660->opt.rr != OPT_RR_DEFAULT) { + if (iso9660->opt.rr == OPT_RR_DISABLED) + set_option_info(&info, &opt, "rockridge", + KEY_FLG, iso9660->opt.rr); + else if (iso9660->opt.rr == OPT_RR_STRICT) + set_option_info(&info, &opt, "rockridge", + KEY_STR, "strict"); + else if (iso9660->opt.rr == OPT_RR_USEFUL) + set_option_info(&info, &opt, "rockridge", + KEY_STR, "useful"); + } + if (iso9660->opt.volume_id != OPT_VOLUME_ID_DEFAULT) + set_option_info(&info, &opt, "volume-id", + KEY_STR, iso9660->volume_identifier.s); + if (iso9660->opt.zisofs != OPT_ZISOFS_DEFAULT) + set_option_info(&info, &opt, "zisofs", + KEY_FLG, iso9660->opt.zisofs); + + memcpy(wb_buffptr(a), info.s, info_size); + archive_string_free(&info); + return (wb_consume(a, info_size)); +} + +static int +write_rr_ER(struct archive_write *a) +{ + unsigned char *p; + + p = wb_buffptr(a); + + memset(p, 0, LOGICAL_BLOCK_SIZE); + p[0] = 'E'; + p[1] = 'R'; + p[3] = 0x01; + p[2] = RRIP_ER_SIZE; + p[4] = RRIP_ER_ID_SIZE; + p[5] = RRIP_ER_DSC_SIZE; + p[6] = RRIP_ER_SRC_SIZE; + p[7] = 0x01; + memcpy(&p[8], rrip_identifier, p[4]); + memcpy(&p[8+p[4]], rrip_descriptor, p[5]); + memcpy(&p[8+p[4]+p[5]], rrip_source, p[6]); + + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +static void +calculate_path_table_size(struct vdd *vdd) +{ + int depth, size; + struct path_table *pt; + + pt = vdd->pathtbl; + size = 0; + for (depth = 0; depth < vdd->max_depth; depth++) { + struct isoent **ptbl; + int i, cnt; + + if ((cnt = pt[depth].cnt) == 0) + break; + + ptbl = pt[depth].sorted; + for (i = 0; i < cnt; i++) { + int len; + + if (ptbl[i]->identifier == NULL) + len = 1; /* root directory */ + else + len = ptbl[i]->id_len; + if (len & 0x01) + len++; /* Padding Field */ + size += 8 + len; + } + } + vdd->path_table_size = size; + vdd->path_table_block = + ((size + PATH_TABLE_BLOCK_SIZE -1) / + PATH_TABLE_BLOCK_SIZE) * + (PATH_TABLE_BLOCK_SIZE / LOGICAL_BLOCK_SIZE); +} + +static int +_write_path_table(struct archive_write *a, int type_m, int depth, + struct vdd *vdd) +{ + unsigned char *bp, *wb; + struct isoent **ptbl; + size_t wbremaining; + int i, r, wsize; + + if (vdd->pathtbl[depth].cnt == 0) + return (0); + + wsize = 0; + wb = wb_buffptr(a); + wbremaining = wb_remaining(a); + bp = wb - 1; + ptbl = vdd->pathtbl[depth].sorted; + for (i = 0; i < vdd->pathtbl[depth].cnt; i++) { + struct isoent *np; + size_t len; + + np = ptbl[i]; + if (np->identifier == NULL) + len = 1; /* root directory */ + else + len = np->id_len; + if (wbremaining - ((bp+1) - wb) < (len + 1 + 8)) { + r = wb_consume(a, (bp+1) - wb); + if (r < 0) + return (r); + wb = wb_buffptr(a); + wbremaining = wb_remaining(a); + bp = wb -1; + } + /* Length of Directory Identifier */ + set_num_711(bp+1, len); + /* Extended Attribute Record Length */ + set_num_711(bp+2, 0); + /* Location of Extent */ + if (type_m) + set_num_732(bp+3, np->dir_location); + else + set_num_731(bp+3, np->dir_location); + /* Parent Directory Number */ + if (type_m) + set_num_722(bp+7, np->parent->dir_number); + else + set_num_721(bp+7, np->parent->dir_number); + /* Directory Identifier */ + if (np->identifier == NULL) + bp[9] = 0; + else + memcpy(&bp[9], np->identifier, len); + if (len & 0x01) { + /* Padding Field */ + bp[9+len] = 0; + len++; + } + wsize += 8 + len; + bp += 8 + len; + } + if ((bp + 1) > wb) { + r = wb_consume(a, (bp+1)-wb); + if (r < 0) + return (r); + } + return (wsize); +} + +static int +write_path_table(struct archive_write *a, int type_m, struct vdd *vdd) +{ + int depth, r; + size_t path_table_size; + + r = ARCHIVE_OK; + path_table_size = 0; + for (depth = 0; depth < vdd->max_depth; depth++) { + r = _write_path_table(a, type_m, depth, vdd); + if (r < 0) + return (r); + path_table_size += r; + } + + /* Write padding data. */ + path_table_size = path_table_size % PATH_TABLE_BLOCK_SIZE; + if (path_table_size > 0) + r = write_null(a, PATH_TABLE_BLOCK_SIZE - path_table_size); + return (r); +} + +static int +calculate_directory_descriptors(struct iso9660 *iso9660, struct vdd *vdd, + struct isoent *isoent, int depth) +{ + struct isoent **enttbl; + int bs, block, i; + + block = 1; + bs = get_dir_rec_size(iso9660, isoent, DIR_REC_SELF, vdd->vdd_type); + bs += get_dir_rec_size(iso9660, isoent, DIR_REC_PARENT, vdd->vdd_type); + + if (isoent->children.cnt <= 0 || (vdd->vdd_type != VDD_JOLIET && + !iso9660->opt.rr && depth + 1 >= vdd->max_depth)) + return (block); + + enttbl = isoent->children_sorted; + for (i = 0; i < isoent->children.cnt; i++) { + struct isoent *np = enttbl[i]; + struct isofile *file; + + file = np->file; + if (file->hardlink_target != NULL) + file = file->hardlink_target; + file->cur_content = &(file->content); + do { + int dr_l; + + dr_l = get_dir_rec_size(iso9660, np, DIR_REC_NORMAL, + vdd->vdd_type); + if ((bs + dr_l) > LOGICAL_BLOCK_SIZE) { + block ++; + bs = dr_l; + } else + bs += dr_l; + file->cur_content = file->cur_content->next; + } while (file->cur_content != NULL); + } + return (block); +} + +static int +_write_directory_descriptors(struct archive_write *a, struct vdd *vdd, + struct isoent *isoent, int depth) +{ + struct iso9660 *iso9660 = a->format_data; + struct isoent **enttbl; + unsigned char *p, *wb; + int i, r; + int dr_l; + + p = wb = wb_buffptr(a); +#define WD_REMAINING (LOGICAL_BLOCK_SIZE - (p - wb)) + p += set_directory_record(p, WD_REMAINING, isoent, + iso9660, DIR_REC_SELF, vdd->vdd_type); + p += set_directory_record(p, WD_REMAINING, isoent, + iso9660, DIR_REC_PARENT, vdd->vdd_type); + + if (isoent->children.cnt <= 0 || (vdd->vdd_type != VDD_JOLIET && + !iso9660->opt.rr && depth + 1 >= vdd->max_depth)) { + memset(p, 0, WD_REMAINING); + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); + } + + enttbl = isoent->children_sorted; + for (i = 0; i < isoent->children.cnt; i++) { + struct isoent *np = enttbl[i]; + struct isofile *file = np->file; + + if (file->hardlink_target != NULL) + file = file->hardlink_target; + file->cur_content = &(file->content); + do { + dr_l = set_directory_record(p, WD_REMAINING, + np, iso9660, DIR_REC_NORMAL, + vdd->vdd_type); + if (dr_l == 0) { + memset(p, 0, WD_REMAINING); + r = wb_consume(a, LOGICAL_BLOCK_SIZE); + if (r < 0) + return (r); + p = wb = wb_buffptr(a); + dr_l = set_directory_record(p, + WD_REMAINING, np, iso9660, + DIR_REC_NORMAL, vdd->vdd_type); + } + p += dr_l; + file->cur_content = file->cur_content->next; + } while (file->cur_content != NULL); + } + memset(p, 0, WD_REMAINING); + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +static int +write_directory_descriptors(struct archive_write *a, struct vdd *vdd) +{ + struct isoent *np; + int depth, r; + + depth = 0; + np = vdd->rootent; + do { + struct extr_rec *extr; + + r = _write_directory_descriptors(a, vdd, np, depth); + if (r < 0) + return (r); + if (vdd->vdd_type != VDD_JOLIET) { + /* + * This extract record is used by SUSP,RRIP. + * Not for joliet. + */ + for (extr = np->extr_rec_list.first; + extr != NULL; + extr = extr->next) { + unsigned char *wb; + + wb = wb_buffptr(a); + memcpy(wb, extr->buf, extr->offset); + memset(wb + extr->offset, 0, + LOGICAL_BLOCK_SIZE - extr->offset); + r = wb_consume(a, LOGICAL_BLOCK_SIZE); + if (r < 0) + return (r); + } + } + + if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) { + /* Enter to sub directories. */ + np = np->subdirs.first; + depth++; + continue; + } + while (np != np->parent) { + if (np->drnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + depth--; + } else { + np = np->drnext; + break; + } + } + } while (np != np->parent); + + return (ARCHIVE_OK); +} + +/* + * Read file contents from the temporary file, and write it. + */ +static int +write_file_contents(struct archive_write *a, int64_t offset, int64_t size) +{ + struct iso9660 *iso9660 = a->format_data; + int r; + + lseek(iso9660->temp_fd, offset, SEEK_SET); + + while (size) { + size_t rsize; + ssize_t rs; + unsigned char *wb; + + wb = wb_buffptr(a); + rsize = wb_remaining(a); + if (rsize > (size_t)size) + rsize = (size_t)size; + rs = read(iso9660->temp_fd, wb, rsize); + if (rs <= 0) { + archive_set_error(&a->archive, errno, + "Can't read temporary file(%jd)", (intmax_t)rs); + return (ARCHIVE_FATAL); + } + size -= rs; + r = wb_consume(a, rs); + if (r < 0) + return (r); + } + return (ARCHIVE_OK); +} + +static int +write_file_descriptors(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file; + int64_t blocks, offset; + int r; + + blocks = 0; + offset = 0; + + /* Make the boot catalog contents, and write it. */ + if (iso9660->el_torito.catalog != NULL) { + r = make_boot_catalog(a); + if (r < 0) + return (r); + } + + /* Write the boot file contents. */ + if (iso9660->el_torito.boot != NULL) { + struct isofile *file = iso9660->el_torito.boot->file; + + blocks = file->content.blocks; + offset = file->content.offset_of_temp; + if (offset != 0) { + r = write_file_contents(a, offset, + blocks << LOGICAL_BLOCK_BITS); + if (r < 0) + return (r); + blocks = 0; + offset = 0; + } + } + + /* Write out all file contents. */ + for (file = iso9660->data_file_list.first; + file != NULL; file = file->datanext) { + + if (!file->write_content) + continue; + + if ((offset + (blocks << LOGICAL_BLOCK_BITS)) < + file->content.offset_of_temp) { + if (blocks > 0) { + r = write_file_contents(a, offset, + blocks << LOGICAL_BLOCK_BITS); + if (r < 0) + return (r); + } + blocks = 0; + offset = file->content.offset_of_temp; + } + + file->cur_content = &(file->content); + do { + blocks += file->cur_content->blocks; + /* Next fragument */ + file->cur_content = file->cur_content->next; + } while (file->cur_content != NULL); + } + + /* Flush out remaining blocks. */ + if (blocks > 0) { + r = write_file_contents(a, offset, + blocks << LOGICAL_BLOCK_BITS); + if (r < 0) + return (r); + } + + return (ARCHIVE_OK); +} + +static void +isofile_init_entry_list(struct iso9660 *iso9660) +{ + iso9660->all_file_list.first = NULL; + iso9660->all_file_list.last = &(iso9660->all_file_list.first); +} + +static void +isofile_add_entry(struct iso9660 *iso9660, struct isofile *file) +{ + file->allnext = NULL; + *iso9660->all_file_list.last = file; + iso9660->all_file_list.last = &(file->allnext); +} + +static void +isofile_free_all_entries(struct iso9660 *iso9660) +{ + struct isofile *file, *file_next; + + file = iso9660->all_file_list.first; + while (file != NULL) { + file_next = file->allnext; + isofile_free(file); + file = file_next; + } +} + +static void +isofile_init_entry_data_file_list(struct iso9660 *iso9660) +{ + iso9660->data_file_list.first = NULL; + iso9660->data_file_list.last = &(iso9660->data_file_list.first); +} + +static void +isofile_add_data_file(struct iso9660 *iso9660, struct isofile *file) +{ + file->datanext = NULL; + *iso9660->data_file_list.last = file; + iso9660->data_file_list.last = &(file->datanext); +} + + +static struct isofile * +isofile_new(struct archive_write *a, struct archive_entry *entry) +{ + struct isofile *file; + + file = calloc(1, sizeof(*file)); + if (file == NULL) + return (NULL); + + if (entry != NULL) + file->entry = archive_entry_clone(entry); + else + file->entry = archive_entry_new2(&a->archive); + if (file->entry == NULL) { + free(file); + return (NULL); + } + archive_string_init(&(file->parentdir)); + archive_string_init(&(file->basename)); + archive_string_init(&(file->basename_utf16)); + archive_string_init(&(file->symlink)); + file->cur_content = &(file->content); + + return (file); +} + +static void +isofile_free(struct isofile *file) +{ + struct content *con, *tmp; + + con = file->content.next; + while (con != NULL) { + tmp = con; + con = con->next; + free(tmp); + } + archive_entry_free(file->entry); + archive_string_free(&(file->parentdir)); + archive_string_free(&(file->basename)); + archive_string_free(&(file->basename_utf16)); + archive_string_free(&(file->symlink)); + free(file); +} + +#if defined(_WIN32) || defined(__CYGWIN__) +static int +cleanup_backslash_1(char *p) +{ + int mb, dos; + + mb = dos = 0; + while (*p) { + if (*(unsigned char *)p > 127) + mb = 1; + if (*p == '\\') { + /* If we have not met any multi-byte characters, + * we can replace '\' with '/'. */ + if (!mb) + *p = '/'; + dos = 1; + } + p++; + } + if (!mb || !dos) + return (0); + return (-1); +} + +static void +cleanup_backslash_2(wchar_t *p) +{ + + /* Convert a path-separator from '\' to '/' */ + while (*p != L'\0') { + if (*p == L'\\') + *p = L'/'; + p++; + } +} +#endif + +/* + * Generate a parent directory name and a base name from a pathname. + */ +static int +isofile_gen_utility_names(struct archive_write *a, struct isofile *file) +{ + struct iso9660 *iso9660; + const char *pathname; + char *p, *dirname, *slash; + size_t len; + int ret = ARCHIVE_OK; + + iso9660 = a->format_data; + + archive_string_empty(&(file->parentdir)); + archive_string_empty(&(file->basename)); + archive_string_empty(&(file->basename_utf16)); + archive_string_empty(&(file->symlink)); + + pathname = archive_entry_pathname(file->entry); + if (pathname == NULL || pathname[0] == '\0') {/* virtual root */ + file->dircnt = 0; + return (ret); + } + + /* + * Make a UTF-16BE basename if Joliet extension enabled. + */ + if (iso9660->opt.joliet) { + const char *u16, *ulast; + size_t u16len, ulen_last; + + if (iso9660->sconv_to_utf16be == NULL) { + iso9660->sconv_to_utf16be = + archive_string_conversion_to_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_to_utf16be == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FATAL); + iso9660->sconv_from_utf16be = + archive_string_conversion_from_charset( + &(a->archive), "UTF-16BE", 1); + if (iso9660->sconv_from_utf16be == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FATAL); + } + + /* + * Converte a filename to UTF-16BE. + */ + if (0 > archive_entry_pathname_l(file->entry, &u16, &u16len, + iso9660->sconv_to_utf16be)) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for UTF-16BE"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "A filename cannot be converted to UTF-16BE;" + "You should disable making Joliet extension"); + ret = ARCHIVE_WARN; + } + + /* + * Make sure a path separator is not in the last; + * Remove trailing '/'. + */ + while (u16len >= 2) { +#if defined(_WIN32) || defined(__CYGWIN__) + if (u16[u16len-2] == 0 && + (u16[u16len-1] == '/' || u16[u16len-1] == '\\')) +#else + if (u16[u16len-2] == 0 && u16[u16len-1] == '/') +#endif + { + u16len -= 2; + } else + break; + } + + /* + * Find a basename in UTF-16BE. + */ + ulast = u16; + u16len >>= 1; + ulen_last = u16len; + while (u16len > 0) { +#if defined(_WIN32) || defined(__CYGWIN__) + if (u16[0] == 0 && (u16[1] == '/' || u16[1] == '\\')) +#else + if (u16[0] == 0 && u16[1] == '/') +#endif + { + ulast = u16 + 2; + ulen_last = u16len -1; + } + u16 += 2; + u16len --; + } + ulen_last <<= 1; + if (archive_string_ensure(&(file->basename_utf16), + ulen_last) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for UTF-16BE"); + return (ARCHIVE_FATAL); + } + + /* + * Set UTF-16BE basename. + */ + memcpy(file->basename_utf16.s, ulast, ulen_last); + file->basename_utf16.length = ulen_last; + } + + archive_strcpy(&(file->parentdir), pathname); +#if defined(_WIN32) || defined(__CYGWIN__) + /* + * Convert a path-separator from '\' to '/' + */ + if (cleanup_backslash_1(file->parentdir.s) != 0) { + const wchar_t *wp = archive_entry_pathname_w(file->entry); + struct archive_wstring ws; + + if (wp != NULL) { + archive_string_init(&ws); + archive_wstrcpy(&ws, wp); + cleanup_backslash_2(ws.s); + archive_string_empty(&(file->parentdir)); + archive_string_append_from_wcs(&(file->parentdir), + ws.s, ws.length); + archive_wstring_free(&ws); + } + } +#endif + + len = file->parentdir.length; + p = dirname = file->parentdir.s; + + /* + * Remove leading '/', '../' and './' elements + */ + while (*p) { + if (p[0] == '/') { + p++; + len--; + } else if (p[0] != '.') + break; + else if (p[1] == '.' && p[2] == '/') { + p += 3; + len -= 3; + } else if (p[1] == '/' || (p[1] == '.' && p[2] == '\0')) { + p += 2; + len -= 2; + } else if (p[1] == '\0') { + p++; + len--; + } else + break; + } + if (p != dirname) { + memmove(dirname, p, len+1); + p = dirname; + } + /* + * Remove "/","/." and "/.." elements from tail. + */ + while (len > 0) { + size_t ll = len; + + if (len > 0 && p[len-1] == '/') { + p[len-1] = '\0'; + len--; + } + if (len > 1 && p[len-2] == '/' && p[len-1] == '.') { + p[len-2] = '\0'; + len -= 2; + } + if (len > 2 && p[len-3] == '/' && p[len-2] == '.' && + p[len-1] == '.') { + p[len-3] = '\0'; + len -= 3; + } + if (ll == len) + break; + } + while (*p) { + if (p[0] == '/') { + if (p[1] == '/') + /* Convert '//' --> '/' */ + strcpy(p, p+1); + else if (p[1] == '.' && p[2] == '/') + /* Convert '/./' --> '/' */ + strcpy(p, p+2); + else if (p[1] == '.' && p[2] == '.' && p[3] == '/') { + /* Convert 'dir/dir1/../dir2/' + * --> 'dir/dir2/' + */ + char *rp = p -1; + while (rp >= dirname) { + if (*rp == '/') + break; + --rp; + } + if (rp > dirname) { + strcpy(rp, p+3); + p = rp; + } else { + strcpy(dirname, p+4); + p = dirname; + } + } else + p++; + } else + p++; + } + p = dirname; + len = strlen(p); + + if (archive_entry_filetype(file->entry) == AE_IFLNK) { + /* Convert symlink name too. */ + pathname = archive_entry_symlink(file->entry); + archive_strcpy(&(file->symlink), pathname); +#if defined(_WIN32) || defined(__CYGWIN__) + /* + * Convert a path-separator from '\' to '/' + */ + if (archive_strlen(&(file->symlink)) > 0 && + cleanup_backslash_1(file->symlink.s) != 0) { + const wchar_t *wp = + archive_entry_symlink_w(file->entry); + struct archive_wstring ws; + + if (wp != NULL) { + archive_string_init(&ws); + archive_wstrcpy(&ws, wp); + cleanup_backslash_2(ws.s); + archive_string_empty(&(file->symlink)); + archive_string_append_from_wcs( + &(file->symlink), + ws.s, ws.length); + archive_wstring_free(&ws); + } + } +#endif + } + /* + * - Count up directory elements. + * - Find out the position which points the last position of + * path separator('/'). + */ + slash = NULL; + file->dircnt = 0; + for (; *p != '\0'; p++) + if (*p == '/') { + slash = p; + file->dircnt++; + } + if (slash == NULL) { + /* The pathname doesn't have a parent directory. */ + file->parentdir.length = len; + archive_string_copy(&(file->basename), &(file->parentdir)); + archive_string_empty(&(file->parentdir)); + *file->parentdir.s = '\0'; + return (ret); + } + + /* Make a basename from dirname and slash */ + *slash = '\0'; + file->parentdir.length = slash - dirname; + archive_strcpy(&(file->basename), slash + 1); + if (archive_entry_filetype(file->entry) == AE_IFDIR) + file->dircnt ++; + return (ret); +} + +/* + * Register a entry to get a hardlink target. + */ +static int +isofile_register_hardlink(struct archive_write *a, struct isofile *file) +{ + struct iso9660 *iso9660 = a->format_data; + struct hardlink *hl; + const char *pathname; + + archive_entry_set_nlink(file->entry, 1); + pathname = archive_entry_hardlink(file->entry); + if (pathname == NULL) { + /* This `file` is a hardlink target. */ + hl = malloc(sizeof(*hl)); + if (hl == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + hl->nlink = 1; + /* A hardlink target must be the first position. */ + file->hlnext = NULL; + hl->file_list.first = file; + hl->file_list.last = &(file->hlnext); + __archive_rb_tree_insert_node(&(iso9660->hardlink_rbtree), + (struct archive_rb_node *)hl); + } else { + hl = (struct hardlink *)__archive_rb_tree_find_node( + &(iso9660->hardlink_rbtree), pathname); + if (hl != NULL) { + /* Insert `file` entry into the tail. */ + file->hlnext = NULL; + *hl->file_list.last = file; + hl->file_list.last = &(file->hlnext); + hl->nlink++; + } + archive_entry_unset_size(file->entry); + } + + return (ARCHIVE_OK); +} + +/* + * Hardlinked files have to have the same location of extent. + * We have to find out hardlink target entries for the entries + * which have a hardlink target name. + */ +static void +isofile_connect_hardlink_files(struct iso9660 *iso9660) +{ + struct archive_rb_node *n; + struct hardlink *hl; + struct isofile *target, *nf; + + ARCHIVE_RB_TREE_FOREACH(n, &(iso9660->hardlink_rbtree)) { + hl = (struct hardlink *)n; + + /* The first entry must be a hardlink target. */ + target = hl->file_list.first; + archive_entry_set_nlink(target->entry, hl->nlink); + /* Set a hardlink target to reference entries. */ + for (nf = target->hlnext; + nf != NULL; nf = nf->hlnext) { + nf->hardlink_target = target; + archive_entry_set_nlink(nf->entry, hl->nlink); + } + } +} + +static int +isofile_hd_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct hardlink *h1 = (const struct hardlink *)n1; + const struct hardlink *h2 = (const struct hardlink *)n2; + + return (strcmp(archive_entry_pathname(h1->file_list.first->entry), + archive_entry_pathname(h2->file_list.first->entry))); +} + +static int +isofile_hd_cmp_key(const struct archive_rb_node *n, const void *key) +{ + const struct hardlink *h = (const struct hardlink *)n; + + return (strcmp(archive_entry_pathname(h->file_list.first->entry), + (const char *)key)); +} + +static void +isofile_init_hardlinks(struct iso9660 *iso9660) +{ + static const struct archive_rb_tree_ops rb_ops = { + isofile_hd_cmp_node, isofile_hd_cmp_key, + }; + + __archive_rb_tree_init(&(iso9660->hardlink_rbtree), &rb_ops); +} + +static void +isofile_free_hardlinks(struct iso9660 *iso9660) +{ + struct archive_rb_node *n, *next; + + for (n = ARCHIVE_RB_TREE_MIN(&(iso9660->hardlink_rbtree)); n;) { + next = __archive_rb_tree_iterate(&(iso9660->hardlink_rbtree), + n, ARCHIVE_RB_DIR_RIGHT); + free(n); + n = next; + } +} + +static struct isoent * +isoent_new(struct isofile *file) +{ + struct isoent *isoent; + static const struct archive_rb_tree_ops rb_ops = { + isoent_cmp_node, isoent_cmp_key, + }; + + isoent = calloc(1, sizeof(*isoent)); + if (isoent == NULL) + return (NULL); + isoent->file = file; + isoent->children.first = NULL; + isoent->children.last = &(isoent->children.first); + __archive_rb_tree_init(&(isoent->rbtree), &rb_ops); + isoent->subdirs.first = NULL; + isoent->subdirs.last = &(isoent->subdirs.first); + isoent->extr_rec_list.first = NULL; + isoent->extr_rec_list.last = &(isoent->extr_rec_list.first); + isoent->extr_rec_list.current = NULL; + if (archive_entry_filetype(file->entry) == AE_IFDIR) + isoent->dir = 1; + + return (isoent); +} + +static inline struct isoent * +isoent_clone(struct isoent *src) +{ + return (isoent_new(src->file)); +} + +static void +_isoent_free(struct isoent *isoent) +{ + struct extr_rec *er, *er_next; + + free(isoent->children_sorted); + free(isoent->identifier); + er = isoent->extr_rec_list.first; + while (er != NULL) { + er_next = er->next; + free(er); + er = er_next; + } + free(isoent); +} + +static void +isoent_free_all(struct isoent *isoent) +{ + struct isoent *np, *np_temp; + + if (isoent == NULL) + return; + np = isoent; + for (;;) { + if (np->dir) { + if (np->children.first != NULL) { + /* Enter to sub directories. */ + np = np->children.first; + continue; + } + } + for (;;) { + np_temp = np; + if (np->chnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + _isoent_free(np_temp); + if (np == np_temp) + return; + } else { + np = np->chnext; + _isoent_free(np_temp); + break; + } + } + } +} + +static struct isoent * +isoent_create_virtual_dir(struct archive_write *a, struct iso9660 *iso9660, const char *pathname) +{ + struct isofile *file; + struct isoent *isoent; + + file = isofile_new(a, NULL); + if (file == NULL) + return (NULL); + archive_entry_set_pathname(file->entry, pathname); + archive_entry_unset_mtime(file->entry); + archive_entry_unset_atime(file->entry); + archive_entry_unset_ctime(file->entry); + archive_entry_set_uid(file->entry, getuid()); + archive_entry_set_gid(file->entry, getgid()); + archive_entry_set_mode(file->entry, 0555 | AE_IFDIR); + archive_entry_set_nlink(file->entry, 2); + if (isofile_gen_utility_names(a, file) < ARCHIVE_WARN) { + isofile_free(file); + return (NULL); + } + isofile_add_entry(iso9660, file); + + isoent = isoent_new(file); + if (isoent == NULL) + return (NULL); + isoent->dir = 1; + isoent->virtual = 1; + + return (isoent); +} + +static int +isoent_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct isoent *e1 = (const struct isoent *)n1; + const struct isoent *e2 = (const struct isoent *)n2; + + return (strcmp(e1->file->basename.s, e2->file->basename.s)); +} + +static int +isoent_cmp_key(const struct archive_rb_node *n, const void *key) +{ + const struct isoent *e = (const struct isoent *)n; + + return (strcmp(e->file->basename.s, (const char *)key)); +} + +static int +isoent_add_child_head(struct isoent *parent, struct isoent *child) +{ + + if (!__archive_rb_tree_insert_node( + &(parent->rbtree), (struct archive_rb_node *)child)) + return (0); + if ((child->chnext = parent->children.first) == NULL) + parent->children.last = &(child->chnext); + parent->children.first = child; + parent->children.cnt++; + child->parent = parent; + + /* Add a child to a sub-directory chain */ + if (child->dir) { + if ((child->drnext = parent->subdirs.first) == NULL) + parent->subdirs.last = &(child->drnext); + parent->subdirs.first = child; + parent->subdirs.cnt++; + child->parent = parent; + } else + child->drnext = NULL; + return (1); +} + +static int +isoent_add_child_tail(struct isoent *parent, struct isoent *child) +{ + + if (!__archive_rb_tree_insert_node( + &(parent->rbtree), (struct archive_rb_node *)child)) + return (0); + child->chnext = NULL; + *parent->children.last = child; + parent->children.last = &(child->chnext); + parent->children.cnt++; + child->parent = parent; + + /* Add a child to a sub-directory chain */ + child->drnext = NULL; + if (child->dir) { + *parent->subdirs.last = child; + parent->subdirs.last = &(child->drnext); + parent->subdirs.cnt++; + child->parent = parent; + } + return (1); +} + +static void +isoent_remove_child(struct isoent *parent, struct isoent *child) +{ + struct isoent *ent; + + /* Remove a child entry from children chain. */ + ent = parent->children.first; + while (ent->chnext != child) + ent = ent->chnext; + if ((ent->chnext = ent->chnext->chnext) == NULL) + parent->children.last = &(ent->chnext); + parent->children.cnt--; + + if (child->dir) { + /* Remove a child entry from sub-directory chain. */ + ent = parent->subdirs.first; + while (ent->drnext != child) + ent = ent->drnext; + if ((ent->drnext = ent->drnext->drnext) == NULL) + parent->subdirs.last = &(ent->drnext); + parent->subdirs.cnt--; + } + + __archive_rb_tree_remove_node(&(parent->rbtree), + (struct archive_rb_node *)child); +} + +static int +isoent_clone_tree(struct archive_write *a, struct isoent **nroot, + struct isoent *root) +{ + struct isoent *np, *xroot, *newent; + + np = root; + xroot = NULL; + do { + newent = isoent_clone(np); + if (newent == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + if (xroot == NULL) { + *nroot = xroot = newent; + newent->parent = xroot; + } else + isoent_add_child_tail(xroot, newent); + if (np->dir && np->children.first != NULL) { + /* Enter to sub directories. */ + np = np->children.first; + xroot = newent; + continue; + } + while (np != np->parent) { + if (np->chnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + xroot = xroot->parent; + } else { + np = np->chnext; + break; + } + } + } while (np != np->parent); + + return (ARCHIVE_OK); +} + +/* + * Setup directory locations. + */ +static void +isoent_setup_directory_location(struct iso9660 *iso9660, int location, + struct vdd *vdd) +{ + struct isoent *np; + int depth; + + vdd->total_dir_block = 0; + depth = 0; + np = vdd->rootent; + do { + int block; + + np->dir_block = calculate_directory_descriptors( + iso9660, vdd, np, depth); + vdd->total_dir_block += np->dir_block; + np->dir_location = location; + location += np->dir_block; + block = extra_setup_location(np, location); + vdd->total_dir_block += block; + location += block; + + if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) { + /* Enter to sub directories. */ + np = np->subdirs.first; + depth++; + continue; + } + while (np != np->parent) { + if (np->drnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + depth--; + } else { + np = np->drnext; + break; + } + } + } while (np != np->parent); +} + +static void +_isoent_file_location(struct iso9660 *iso9660, struct isoent *isoent, + int *symlocation) +{ + struct isoent **children; + int n; + + if (isoent->children.cnt == 0) + return; + + children = isoent->children_sorted; + for (n = 0; n < isoent->children.cnt; n++) { + struct isoent *np; + struct isofile *file; + + np = children[n]; + if (np->dir) + continue; + if (np == iso9660->el_torito.boot) + continue; + file = np->file; + if (file->boot || file->hardlink_target != NULL) + continue; + if (archive_entry_filetype(file->entry) == AE_IFLNK || + file->content.size == 0) { + /* + * Do not point a valid location. + * Make sure entry is not hardlink file. + */ + file->content.location = (*symlocation)--; + continue; + } + + file->write_content = 1; + } +} + +/* + * Setup file locations. + */ +static void +isoent_setup_file_location(struct iso9660 *iso9660, int location) +{ + struct isoent *isoent; + struct isoent *np; + struct isofile *file; + size_t size; + int block; + int depth; + int joliet; + int symlocation; + int total_block; + + iso9660->total_file_block = 0; + if ((isoent = iso9660->el_torito.catalog) != NULL) { + isoent->file->content.location = location; + block = (archive_entry_size(isoent->file->entry) + + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + location += block; + iso9660->total_file_block += block; + } + if ((isoent = iso9660->el_torito.boot) != NULL) { + isoent->file->content.location = location; + size = fd_boot_image_size(iso9660->el_torito.media_type); + if (size == 0) + size = archive_entry_size(isoent->file->entry); + block = (size + LOGICAL_BLOCK_SIZE -1) >> LOGICAL_BLOCK_BITS; + location += block; + iso9660->total_file_block += block; + isoent->file->content.blocks = block; + } + + depth = 0; + symlocation = -16; + if (!iso9660->opt.rr && iso9660->opt.joliet) { + joliet = 1; + np = iso9660->joliet.rootent; + } else { + joliet = 0; + np = iso9660->primary.rootent; + } + do { + _isoent_file_location(iso9660, np, &symlocation); + + if (np->subdirs.first != NULL && + (joliet || + ((iso9660->opt.rr == OPT_RR_DISABLED && + depth + 2 < iso9660->primary.max_depth) || + (iso9660->opt.rr && + depth + 1 < iso9660->primary.max_depth)))) { + /* Enter to sub directories. */ + np = np->subdirs.first; + depth++; + continue; + } + while (np != np->parent) { + if (np->drnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + depth--; + } else { + np = np->drnext; + break; + } + } + } while (np != np->parent); + + total_block = 0; + for (file = iso9660->data_file_list.first; + file != NULL; file = file->datanext) { + + if (!file->write_content) + continue; + + file->cur_content = &(file->content); + do { + file->cur_content->location = location; + location += file->cur_content->blocks; + total_block += file->cur_content->blocks; + /* Next fragument */ + file->cur_content = file->cur_content->next; + } while (file->cur_content != NULL); + } + iso9660->total_file_block += total_block; +} + +static int +get_path_component(char *name, int n, const char *fn) +{ + char *p; + int l; + + p = strchr(fn, '/'); + if (p == NULL) { + if ((l = strlen(fn)) == 0) + return (0); + } else + l = p - fn; + if (l > n -1) + return (-1); + memcpy(name, fn, l); + name[l] = '\0'; + + return (l); +} + +/* + * Add a new entry into the tree. + */ +static int +isoent_tree(struct archive_write *a, struct isoent **isoentpp) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char name[_MAX_FNAME];/* Included null terminator size. */ +#elif defined(NAME_MAX) && NAME_MAX >= 255 + char name[NAME_MAX+1]; +#else + char name[256]; +#endif + struct iso9660 *iso9660 = a->format_data; + struct isoent *dent, *isoent, *np; + struct isofile *f1, *f2; + const char *fn, *p; + int l; + + isoent = *isoentpp; + dent = iso9660->primary.rootent; + if (isoent->file->parentdir.length > 0) + fn = p = isoent->file->parentdir.s; + else + fn = p = ""; + + /* + * If the path of the parent directory of `isoent' entry is + * the same as the path of `cur_dirent', add isoent to + * `cur_dirent'. + */ + if (archive_strlen(&(iso9660->cur_dirstr)) + == archive_strlen(&(isoent->file->parentdir)) && + strcmp(iso9660->cur_dirstr.s, fn) == 0) { + if (!isoent_add_child_tail(iso9660->cur_dirent, isoent)) { + np = (struct isoent *)__archive_rb_tree_find_node( + &(iso9660->cur_dirent->rbtree), + isoent->file->basename.s); + goto same_entry; + } + return (ARCHIVE_OK); + } + + for (;;) { + l = get_path_component(name, sizeof(name), fn); + if (l == 0) { + np = NULL; + break; + } + if (l < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "A name buffer is too small"); + _isoent_free(isoent); + return (ARCHIVE_FATAL); + } + + np = isoent_find_child(dent, name); + if (np == NULL || fn[0] == '\0') + break; + + /* Find next subdirectory. */ + if (!np->dir) { + /* NOT Directory! */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "`%s' is not directory, we cannot insert `%s' ", + archive_entry_pathname(np->file->entry), + archive_entry_pathname(isoent->file->entry)); + _isoent_free(isoent); + *isoentpp = NULL; + return (ARCHIVE_FAILED); + } + fn += l; + if (fn[0] == '/') + fn++; + dent = np; + } + if (np == NULL) { + /* + * Create virtual parent directories. + */ + while (fn[0] != '\0') { + struct isoent *vp; + struct archive_string as; + + archive_string_init(&as); + archive_strncat(&as, p, fn - p + l); + if (as.s[as.length-1] == '/') { + as.s[as.length-1] = '\0'; + as.length--; + } + vp = isoent_create_virtual_dir(a, iso9660, as.s); + if (vp == NULL) { + archive_string_free(&as); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + _isoent_free(isoent); + *isoentpp = NULL; + return (ARCHIVE_FATAL); + } + archive_string_free(&as); + + if (vp->file->dircnt > iso9660->dircnt_max) + iso9660->dircnt_max = vp->file->dircnt; + isoent_add_child_tail(dent, vp); + np = vp; + + fn += l; + if (fn[0] == '/') + fn++; + l = get_path_component(name, sizeof(name), fn); + if (l < 0) { + archive_string_free(&as); + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "A name buffer is too small"); + _isoent_free(isoent); + *isoentpp = NULL; + return (ARCHIVE_FATAL); + } + dent = np; + } + + /* Found out the parent directory where isoent can be + * inserted. */ + iso9660->cur_dirent = dent; + archive_string_empty(&(iso9660->cur_dirstr)); + archive_string_ensure(&(iso9660->cur_dirstr), + archive_strlen(&(dent->file->parentdir)) + + archive_strlen(&(dent->file->basename)) + 2); + if (archive_strlen(&(dent->file->parentdir)) + + archive_strlen(&(dent->file->basename)) == 0) + iso9660->cur_dirstr.s[0] = 0; + else { + if (archive_strlen(&(dent->file->parentdir)) > 0) { + archive_string_copy(&(iso9660->cur_dirstr), + &(dent->file->parentdir)); + archive_strappend_char(&(iso9660->cur_dirstr), '/'); + } + archive_string_concat(&(iso9660->cur_dirstr), + &(dent->file->basename)); + } + + if (!isoent_add_child_tail(dent, isoent)) { + np = (struct isoent *)__archive_rb_tree_find_node( + &(dent->rbtree), isoent->file->basename.s); + goto same_entry; + } + return (ARCHIVE_OK); + } + +same_entry: + /* + * We have already has the entry the filename of which is + * the same. + */ + f1 = np->file; + f2 = isoent->file; + + /* If the file type of entries is different, + * we cannot handle it. */ + if (archive_entry_filetype(f1->entry) != + archive_entry_filetype(f2->entry)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Found duplicate entries `%s' and its file type is " + "different", + archive_entry_pathname(f1->entry)); + _isoent_free(isoent); + *isoentpp = NULL; + return (ARCHIVE_FAILED); + } + + /* Swap file entries. */ + np->file = f2; + isoent->file = f1; + np->virtual = 0; + + _isoent_free(isoent); + *isoentpp = np; + return (ARCHIVE_OK); +} + +/* + * Find a entry from `isoent' + */ +static struct isoent * +isoent_find_child(struct isoent *isoent, const char *child_name) +{ + struct isoent *np; + + np = (struct isoent *)__archive_rb_tree_find_node( + &(isoent->rbtree), child_name); + return (np); +} + +/* + * Find a entry full-path of which is specified by `fn' parameter, + * in the tree. + */ +static struct isoent * +isoent_find_entry(struct isoent *rootent, const char *fn) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char name[_MAX_FNAME];/* Included null terminator size. */ +#elif defined(NAME_MAX) && NAME_MAX >= 255 + char name[NAME_MAX+1]; +#else + char name[256]; +#endif + struct isoent *isoent, *np; + int l; + + isoent = rootent; + np = NULL; + for (;;) { + l = get_path_component(name, sizeof(name), fn); + if (l == 0) + break; + fn += l; + if (fn[0] == '/') + fn++; + + np = isoent_find_child(isoent, name); + if (np == NULL) + break; + if (fn[0] == '\0') + break;/* We found out the entry */ + + /* Try sub directory. */ + isoent = np; + np = NULL; + if (!isoent->dir) + break;/* Not directory */ + } + + return (np); +} + +/* + * Following idr_* functions are used for resolving duplicated filenames + * and unreceivable filenames to generate ISO9660/Joliet Identifiers. + */ + +static void +idr_relaxed_filenames(char *map) +{ + int i; + + for (i = 0x21; i <= 0x2F; i++) + map[i] = 1; + for (i = 0x3A; i <= 0x41; i++) + map[i] = 1; + for (i = 0x5B; i <= 0x5E; i++) + map[i] = 1; + map[0x60] = 1; + for (i = 0x7B; i <= 0x7E; i++) + map[i] = 1; +} + +static void +idr_init(struct iso9660 *iso9660, struct vdd *vdd, struct idr *idr) +{ + + idr->idrent_pool = NULL; + idr->pool_size = 0; + if (vdd->vdd_type != VDD_JOLIET) { + if (iso9660->opt.iso_level <= 3) { + memcpy(idr->char_map, d_characters_map, + sizeof(idr->char_map)); + } else { + memcpy(idr->char_map, d1_characters_map, + sizeof(idr->char_map)); + idr_relaxed_filenames(idr->char_map); + } + } +} + +static void +idr_cleanup(struct idr *idr) +{ + free(idr->idrent_pool); +} + +static int +idr_ensure_poolsize(struct archive_write *a, struct idr *idr, + int cnt) +{ + + if (idr->pool_size < cnt) { + const int bk = (1 << 7) - 1; + int psize; + + psize = (cnt + bk) & ~bk; + idr->idrent_pool = realloc(idr->idrent_pool, + sizeof(struct idrent) * psize); + if (idr->idrent_pool == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + idr->pool_size = psize; + } + return (ARCHIVE_OK); +} + +static int +idr_start(struct archive_write *a, struct idr *idr, int cnt, int ffmax, + int num_size, int null_size, const struct archive_rb_tree_ops *rbt_ops) +{ + int r; + + (void)ffmax; /* UNUSED */ + + r = idr_ensure_poolsize(a, idr, cnt); + if (r != ARCHIVE_OK) + return (r); + __archive_rb_tree_init(&(idr->rbtree), rbt_ops); + idr->wait_list.first = NULL; + idr->wait_list.last = &(idr->wait_list.first); + idr->pool_idx = 0; + idr->num_size = num_size; + idr->null_size = null_size; + return (ARCHIVE_OK); +} + +static void +idr_register(struct idr *idr, struct isoent *isoent, int weight, int noff) +{ + struct idrent *idrent, *n; + + idrent = &(idr->idrent_pool[idr->pool_idx++]); + idrent->wnext = idrent->avail = NULL; + idrent->isoent = isoent; + idrent->weight = weight; + idrent->noff = noff; + idrent->rename_num = 0; + + if (!__archive_rb_tree_insert_node(&(idr->rbtree), &(idrent->rbnode))) { + n = (struct idrent *)__archive_rb_tree_find_node( + &(idr->rbtree), idrent->isoent); + if (n != NULL) { + /* this `idrent' needs to rename. */ + idrent->avail = n; + *idr->wait_list.last = idrent; + idr->wait_list.last = &(idrent->wnext); + } + } +} + +static void +idr_extend_identifier(struct idrent *wnp, int numsize, int nullsize) +{ + unsigned char *p; + int wnp_ext_off; + + wnp_ext_off = wnp->isoent->ext_off; + if (wnp->noff + numsize != wnp_ext_off) { + p = (unsigned char *)wnp->isoent->identifier; + /* Extend the filename; foo.c --> foo___.c */ + memmove(p + wnp->noff + numsize, p + wnp_ext_off, + wnp->isoent->ext_len + nullsize); + wnp->isoent->ext_off = wnp_ext_off = wnp->noff + numsize; + wnp->isoent->id_len = wnp_ext_off + wnp->isoent->ext_len; + } +} + +static void +idr_resolve(struct idr *idr, void (*fsetnum)(unsigned char *p, int num)) +{ + struct idrent *n; + unsigned char *p; + + for (n = idr->wait_list.first; n != NULL; n = n->wnext) { + idr_extend_identifier(n, idr->num_size, idr->null_size); + p = (unsigned char *)n->isoent->identifier + n->noff; + do { + fsetnum(p, n->avail->rename_num++); + } while (!__archive_rb_tree_insert_node( + &(idr->rbtree), &(n->rbnode))); + } +} + +static void +idr_set_num(unsigned char *p, int num) +{ + static const char xdig[] = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', + 'U', 'V', 'W', 'X', 'Y', 'Z' + }; + + num %= sizeof(xdig) * sizeof(xdig) * sizeof(xdig); + p[0] = xdig[(num / (sizeof(xdig) * sizeof(xdig)))]; + num %= sizeof(xdig) * sizeof(xdig); + p[1] = xdig[ (num / sizeof(xdig))]; + num %= sizeof(xdig); + p[2] = xdig[num]; +} + +static void +idr_set_num_beutf16(unsigned char *p, int num) +{ + static const uint16_t xdig[] = { + 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, + 0x0036, 0x0037, 0x0038, 0x0039, + 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, + 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, + 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, + 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, + 0x0059, 0x005A + }; +#define XDIG_CNT (sizeof(xdig)/sizeof(xdig[0])) + + num %= XDIG_CNT * XDIG_CNT * XDIG_CNT; + archive_be16enc(p, xdig[(num / (XDIG_CNT * XDIG_CNT))]); + num %= XDIG_CNT * XDIG_CNT; + archive_be16enc(p+2, xdig[ (num / XDIG_CNT)]); + num %= XDIG_CNT; + archive_be16enc(p+4, xdig[num]); +} + +/* + * Generate ISO9660 Identifier. + */ +static int +isoent_gen_iso9660_identifier(struct archive_write *a, struct isoent *isoent, + struct idr *idr) +{ + struct iso9660 *iso9660; + struct isoent *np; + char *p; + int l, r; + const char *char_map; + char allow_ldots, allow_multidot, allow_period, allow_vernum; + int fnmax, ffmax, dnmax; + static const struct archive_rb_tree_ops rb_ops = { + isoent_cmp_node_iso9660, isoent_cmp_key_iso9660 + }; + + if (isoent->children.cnt == 0) + return (0); + + iso9660 = a->format_data; + char_map = idr->char_map; + if (iso9660->opt.iso_level <= 3) { + allow_ldots = 0; + allow_multidot = 0; + allow_period = 1; + allow_vernum = iso9660->opt.allow_vernum; + if (iso9660->opt.iso_level == 1) { + fnmax = 8; + ffmax = 12;/* fnmax + '.' + 3 */ + dnmax = 8; + } else { + fnmax = 30; + ffmax = 31; + dnmax = 31; + } + } else { + allow_ldots = allow_multidot = 1; + allow_period = allow_vernum = 0; + if (iso9660->opt.rr) + /* + * MDR : The maximum size of Directory Record(254). + * DRL : A Directory Record Length(33). + * CE : A size of SUSP CE System Use Entry(28). + * MDR - DRL - CE = 254 - 33 - 28 = 193. + */ + fnmax = ffmax = dnmax = 193; + else + /* + * XA : CD-ROM XA System Use Extension + * Information(14). + * MDR - DRL - XA = 254 - 33 -14 = 207. + */ + fnmax = ffmax = dnmax = 207; + } + + r = idr_start(a, idr, isoent->children.cnt, ffmax, 3, 1, &rb_ops); + if (r < 0) + return (r); + + for (np = isoent->children.first; np != NULL; np = np->chnext) { + char *dot, *xdot; + int ext_off, noff, weight; + + l = np->file->basename.length; + p = malloc(l+31+2+1); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + memcpy(p, np->file->basename.s, l); + p[l] = '\0'; + np->identifier = p; + + dot = xdot = NULL; + if (!allow_ldots) { + /* + * If there is a '.' character at the first byte, + * it has to be replaced by '_' character. + */ + if (*p == '.') + *p++ = '_'; + } + for (;*p; p++) { + if (*p & 0x80) { + *p = '_'; + continue; + } + if (char_map[(unsigned char)*p]) { + /* if iso-level is '4', a character '.' is + * allowed by char_map. */ + if (*p == '.') { + xdot = dot; + dot = p; + } + continue; + } + if (*p >= 'a' && *p <= 'z') { + *p -= 'a' - 'A'; + continue; + } + if (*p == '.') { + xdot = dot; + dot = p; + if (allow_multidot) + continue; + } + *p = '_'; + } + p = np->identifier; + weight = -1; + if (dot == NULL) { + int nammax; + + if (np->dir) + nammax = dnmax; + else + nammax = fnmax; + + if (l > nammax) { + p[nammax] = '\0'; + weight = nammax; + ext_off = nammax; + } else + ext_off = l; + } else { + *dot = '.'; + ext_off = dot - p; + + if (iso9660->opt.iso_level == 1) { + if (dot - p <= 8) { + if (strlen(dot) > 4) { + /* A length of a file extension + * must be less than 4 */ + dot[4] = '\0'; + weight = 0; + } + } else { + p[8] = dot[0]; + p[9] = dot[1]; + p[10] = dot[2]; + p[11] = dot[3]; + p[12] = '\0'; + weight = 8; + ext_off = 8; + } + } else if (np->dir) { + if (l > dnmax) { + p[dnmax] = '\0'; + weight = dnmax; + if (ext_off > dnmax) + ext_off = dnmax; + } + } else if (l > ffmax) { + int extlen = strlen(dot); + int xdoff; + + if (xdot != NULL) + xdoff = xdot - p; + else + xdoff = 0; + + if (extlen > 1 && xdoff < fnmax-1) { + int off; + + if (extlen > ffmax) + extlen = ffmax; + off = ffmax - extlen; + if (off == 0) { + /* A dot('.') character + * does't place to the first + * byte of identifier. */ + off ++; + extlen --; + } + memmove(p+off, dot, extlen); + p[ffmax] = '\0'; + ext_off = off; + weight = off; +#ifdef COMPAT_MKISOFS + } else if (xdoff >= fnmax-1) { + /* Simulate a bug(?) of mkisofs. */ + p[fnmax-1] = '\0'; + ext_off = fnmax-1; + weight = fnmax-1; +#endif + } else { + p[fnmax] = '\0'; + ext_off = fnmax; + weight = fnmax; + } + } + } + /* Save an offset of a file name extension to sort files. */ + np->ext_off = ext_off; + np->ext_len = strlen(&p[ext_off]); + np->id_len = l = ext_off + np->ext_len; + + /* Make an offset of the number which is used to be set + * hexadecimal number to avoid duplicate identififier. */ + if (iso9660->opt.iso_level == 1) { + if (ext_off >= 5) + noff = 5; + else + noff = ext_off; + } else { + if (l == ffmax) + noff = ext_off - 3; + else if (l == ffmax-1) + noff = ext_off - 2; + else if (l == ffmax-2) + noff = ext_off - 1; + else + noff = ext_off; + } + /* Register entry to the identifier resolver. */ + idr_register(idr, np, weight, noff); + } + + /* Resolve duplicate identifier. */ + idr_resolve(idr, idr_set_num); + + /* Add a period and a version number to identifiers. */ + for (np = isoent->children.first; np != NULL; np = np->chnext) { + if (!np->dir && np->rr_child == NULL) { + p = np->identifier + np->ext_off + np->ext_len; + if (np->ext_len == 0 && allow_period) { + *p++ = '.'; + np->ext_len = 1; + } + if (np->ext_len == 1 && !allow_period) { + *--p = '\0'; + np->ext_len = 0; + } + np->id_len = np->ext_off + np->ext_len; + if (allow_vernum) { + *p++ = ';'; + *p++ = '1'; + np->id_len += 2; + } + *p = '\0'; + } else + np->id_len = np->ext_off + np->ext_len; + np->mb_len = np->id_len; + } + return (ARCHIVE_OK); +} + +/* + * Generate Joliet Identifier. + */ +static int +isoent_gen_joliet_identifier(struct archive_write *a, struct isoent *isoent, + struct idr *idr) +{ + struct iso9660 *iso9660; + struct isoent *np; + unsigned char *p; + size_t l; + int r; + int ffmax, parent_len; + static const struct archive_rb_tree_ops rb_ops = { + isoent_cmp_node_joliet, isoent_cmp_key_joliet + }; + + if (isoent->children.cnt == 0) + return (0); + + iso9660 = a->format_data; + if (iso9660->opt.joliet == OPT_JOLIET_LONGNAME) + ffmax = 206; + else + ffmax = 128; + + r = idr_start(a, idr, isoent->children.cnt, ffmax, 6, 2, &rb_ops); + if (r < 0) + return (r); + + parent_len = 1; + for (np = isoent; np->parent != np; np = np->parent) + parent_len += np->mb_len + 1; + + for (np = isoent->children.first; np != NULL; np = np->chnext) { + unsigned char *dot; + int ext_off, noff, weight; + size_t lt; + + if ((int)(l = np->file->basename_utf16.length) > ffmax) + l = ffmax; + + p = malloc((l+1)*2); + if (p == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + memcpy(p, np->file->basename_utf16.s, l); + p[l] = 0; + p[l+1] = 0; + + np->identifier = (char *)p; + lt = l; + dot = p + l; + weight = 0; + while (lt > 0) { + if (!joliet_allowed_char(p[0], p[1])) + archive_be16enc(p, 0x005F); /* '_' */ + else if (p[0] == 0 && p[1] == 0x2E) /* '.' */ + dot = p; + p += 2; + lt -= 2; + } + ext_off = dot - (unsigned char *)np->identifier; + np->ext_off = ext_off; + np->ext_len = l - ext_off; + np->id_len = l; + + /* + * Get a length of MBS of a full-pathname. + */ + if ((int)np->file->basename_utf16.length > ffmax) { + archive_strncpy_in_locale(&iso9660->mbs, + (const char *)np->identifier, l, + iso9660->sconv_from_utf16be); + np->mb_len = iso9660->mbs.length; + if (np->mb_len != (int)np->file->basename.length) + weight = np->mb_len; + } else + np->mb_len = np->file->basename.length; + + /* If a length of full-pathname is longer than 240 bytes, + * it violates Joliet extensions regulation. */ + if (parent_len + np->mb_len > 240) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "The regulation of Joliet extensions;" + " A lenght of a full-pathname of `%s' is " + "longer than 240 bytes, (p=%d, b=%d)", + archive_entry_pathname(np->file->entry), + (int)parent_len, (int)np->mb_len); + return (ARCHIVE_FATAL); + } + + /* Make an offset of the number which is used to be set + * hexadecimal number to avoid duplicate identififier. */ + if ((int)l == ffmax) + noff = ext_off - 6; + else if ((int)l == ffmax-2) + noff = ext_off - 4; + else if ((int)l == ffmax-4) + noff = ext_off - 2; + else + noff = ext_off; + /* Register entry to the identifier resolver. */ + idr_register(idr, np, weight, noff); + } + + /* Resolve duplicate identifier with Joliet Volume. */ + idr_resolve(idr, idr_set_num_beutf16); + + return (ARCHIVE_OK); +} + +/* + * This comparing rule is acording to ISO9660 Standard 9.3 + */ +static int +isoent_cmp_iso9660_identifier(const struct isoent *p1, const struct isoent *p2) +{ + const char *s1, *s2; + int cmp; + int l; + + s1 = p1->identifier; + s2 = p2->identifier; + + /* Compare File Name */ + l = p1->ext_off; + if (l > p2->ext_off) + l = p2->ext_off; + cmp = memcmp(s1, s2, l); + if (cmp != 0) + return (cmp); + if (p1->ext_off < p2->ext_off) { + s2 += l; + l = p2->ext_off - p1->ext_off; + while (l--) + if (0x20 != *s2++) + return (0x20 + - *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_off > p2->ext_off) { + s1 += l; + l = p1->ext_off - p2->ext_off; + while (l--) + if (0x20 != *s1++) + return (*(const unsigned char *)(s1 - 1) + - 0x20); + } + /* Compare File Name Extension */ + if (p1->ext_len == 0 && p2->ext_len == 0) + return (0); + if (p1->ext_len == 1 && p2->ext_len == 1) + return (0); + if (p1->ext_len <= 1) + return (-1); + if (p2->ext_len <= 1) + return (1); + l = p1->ext_len; + if (l > p2->ext_len) + l = p2->ext_len; + s1 = p1->identifier + p1->ext_off; + s2 = p2->identifier + p2->ext_off; + if (l > 1) { + cmp = memcmp(s1, s2, l); + if (cmp != 0) + return (cmp); + } + if (p1->ext_len < p2->ext_len) { + s2 += l; + l = p2->ext_len - p1->ext_len; + while (l--) + if (0x20 != *s2++) + return (0x20 + - *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_len < p2->ext_len) { + s1 += l; + l = p1->ext_len - p2->ext_len; + while (l--) + if (0x20 != *s1++) + return (*(const unsigned char *)(s1 - 1) + - 0x20); + } + /* Compare File Version Number */ + /* No operation. The File Version Number is always one. */ + + return (cmp); +} + +static int +isoent_cmp_node_iso9660(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct idrent *e1 = (const struct idrent *)n1; + const struct idrent *e2 = (const struct idrent *)n2; + + return (isoent_cmp_iso9660_identifier(e2->isoent, e1->isoent)); +} + +static int +isoent_cmp_key_iso9660(const struct archive_rb_node *node, const void *key) +{ + const struct isoent *isoent = (const struct isoent *)key; + const struct idrent *idrent = (const struct idrent *)node; + + return (isoent_cmp_iso9660_identifier(isoent, idrent->isoent)); +} + +static int +isoent_cmp_joliet_identifier(const struct isoent *p1, const struct isoent *p2) +{ + const unsigned char *s1, *s2; + int cmp; + int l; + + s1 = (const unsigned char *)p1->identifier; + s2 = (const unsigned char *)p2->identifier; + + /* Compare File Name */ + l = p1->ext_off; + if (l > p2->ext_off) + l = p2->ext_off; + cmp = memcmp(s1, s2, l); + if (cmp != 0) + return (cmp); + if (p1->ext_off < p2->ext_off) { + s2 += l; + l = p2->ext_off - p1->ext_off; + while (l--) + if (0 != *s2++) + return (- *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_off > p2->ext_off) { + s1 += l; + l = p1->ext_off - p2->ext_off; + while (l--) + if (0 != *s1++) + return (*(const unsigned char *)(s1 - 1)); + } + /* Compare File Name Extension */ + if (p1->ext_len == 0 && p2->ext_len == 0) + return (0); + if (p1->ext_len == 2 && p2->ext_len == 2) + return (0); + if (p1->ext_len <= 2) + return (-1); + if (p2->ext_len <= 2) + return (1); + l = p1->ext_len; + if (l > p2->ext_len) + l = p2->ext_len; + s1 = (unsigned char *)(p1->identifier + p1->ext_off); + s2 = (unsigned char *)(p2->identifier + p2->ext_off); + if (l > 1) { + cmp = memcmp(s1, s2, l); + if (cmp != 0) + return (cmp); + } + if (p1->ext_len < p2->ext_len) { + s2 += l; + l = p2->ext_len - p1->ext_len; + while (l--) + if (0 != *s2++) + return (- *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_len < p2->ext_len) { + s1 += l; + l = p1->ext_len - p2->ext_len; + while (l--) + if (0 != *s1++) + return (*(const unsigned char *)(s1 - 1)); + } + /* Compare File Version Number */ + /* No operation. The File Version Number is always one. */ + + return (cmp); +} + +static int +isoent_cmp_node_joliet(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + const struct idrent *e1 = (const struct idrent *)n1; + const struct idrent *e2 = (const struct idrent *)n2; + + return (isoent_cmp_joliet_identifier(e2->isoent, e1->isoent)); +} + +static int +isoent_cmp_key_joliet(const struct archive_rb_node *node, const void *key) +{ + const struct isoent *isoent = (const struct isoent *)key; + const struct idrent *idrent = (const struct idrent *)node; + + return (isoent_cmp_joliet_identifier(isoent, idrent->isoent)); +} + +static int +isoent_make_sorted_files(struct archive_write *a, struct isoent *isoent, + struct idr *idr) +{ + struct archive_rb_node *rn; + struct isoent **children; + + children = malloc(isoent->children.cnt * sizeof(struct isoent *)); + if (children == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + isoent->children_sorted = children; + + ARCHIVE_RB_TREE_FOREACH(rn, &(idr->rbtree)) { + struct idrent *idrent = (struct idrent *)rn; + *children ++ = idrent->isoent; + } + return (ARCHIVE_OK); +} + +/* + * - Generate ISO9660 and Joliet identifiers from basenames. + * - Sort files by each directory. + */ +static int +isoent_traverse_tree(struct archive_write *a, struct vdd* vdd) +{ + struct iso9660 *iso9660 = a->format_data; + struct isoent *np; + struct idr idr; + int depth; + int r; + int (*genid)(struct archive_write *a, struct isoent *isoent, + struct idr *idr); + + idr_init(iso9660, vdd, &idr); + np = vdd->rootent; + depth = 0; + if (vdd->vdd_type == VDD_JOLIET) + genid = isoent_gen_joliet_identifier; + else + genid = isoent_gen_iso9660_identifier; + do { + if (np->virtual && + !archive_entry_mtime_is_set(np->file->entry)) { + /* Set properly times to virtual directory */ + archive_entry_set_mtime(np->file->entry, + iso9660->birth_time, 0); + archive_entry_set_atime(np->file->entry, + iso9660->birth_time, 0); + archive_entry_set_ctime(np->file->entry, + iso9660->birth_time, 0); + } + if (np->children.first != NULL) { + if (vdd->vdd_type != VDD_JOLIET && + !iso9660->opt.rr && depth + 1 >= vdd->max_depth) { + if (np->children.cnt > 0) + iso9660->directories_too_deep = np; + } else { + /* Generate Identifier */ + r = genid(a, np, &idr); + if (r < 0) + goto exit_traverse_tree; + r = isoent_make_sorted_files(a, np, &idr); + if (r < 0) + goto exit_traverse_tree; + + if (np->subdirs.first != NULL && + depth + 1 < vdd->max_depth) { + /* Enter to sub directories. */ + np = np->subdirs.first; + depth++; + continue; + } + } + } + while (np != np->parent) { + if (np->drnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + depth--; + } else { + np = np->drnext; + break; + } + } + } while (np != np->parent); + + r = ARCHIVE_OK; +exit_traverse_tree: + idr_cleanup(&idr); + + return (r); +} + +/* + * Collect directory entries into path_table by a directory depth. + */ +static int +isoent_collect_dirs(struct vdd *vdd, struct isoent *rootent, int depth) +{ + struct isoent *np; + + if (rootent == NULL) + rootent = vdd->rootent; + np = rootent; + do { + /* Register current directory to pathtable. */ + path_table_add_entry(&(vdd->pathtbl[depth]), np); + + if (np->subdirs.first != NULL && depth + 1 < vdd->max_depth) { + /* Enter to sub directories. */ + np = np->subdirs.first; + depth++; + continue; + } + while (np != rootent) { + if (np->drnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + depth--; + } else { + np = np->drnext; + break; + } + } + } while (np != rootent); + + return (ARCHIVE_OK); +} + +/* + * The entry whose number of levels in a directory hierarchy is + * large than eight relocate to rr_move directory. + */ +static int +isoent_rr_move_dir(struct archive_write *a, struct isoent **rr_moved, + struct isoent *curent, struct isoent **newent) +{ + struct iso9660 *iso9660 = a->format_data; + struct isoent *rrmoved, *mvent, *np; + + if ((rrmoved = *rr_moved) == NULL) { + struct isoent *rootent = iso9660->primary.rootent; + /* There isn't rr_move entry. + * Create rr_move entry and insert it into the root entry. + */ + rrmoved = isoent_create_virtual_dir(a, iso9660, "rr_moved"); + if (rrmoved == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + /* Add "rr_moved" entry to the root entry. */ + isoent_add_child_head(rootent, rrmoved); + archive_entry_set_nlink(rootent->file->entry, + archive_entry_nlink(rootent->file->entry) + 1); + /* Register "rr_moved" entry to second level pathtable. */ + path_table_add_entry(&(iso9660->primary.pathtbl[1]), rrmoved); + /* Save rr_moved. */ + *rr_moved = rrmoved; + } + /* + * Make a clone of curent which is going to be relocated + * to rr_moved. + */ + mvent = isoent_clone(curent); + if (mvent == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + /* linking.. and use for creating "CL", "PL" and "RE" */ + mvent->rr_parent = curent->parent; + curent->rr_child = mvent; + /* + * Move subdirectories from the curent to mvent + */ + if (curent->children.first != NULL) { + *mvent->children.last = curent->children.first; + mvent->children.last = curent->children.last; + } + for (np = mvent->children.first; np != NULL; np = np->chnext) + np->parent = mvent; + mvent->children.cnt = curent->children.cnt; + curent->children.cnt = 0; + curent->children.first = NULL; + curent->children.last = &curent->children.first; + + if (curent->subdirs.first != NULL) { + *mvent->subdirs.last = curent->subdirs.first; + mvent->subdirs.last = curent->subdirs.last; + } + mvent->subdirs.cnt = curent->subdirs.cnt; + curent->subdirs.cnt = 0; + curent->subdirs.first = NULL; + curent->subdirs.last = &curent->subdirs.first; + + /* + * The mvent becomes a child of the rr_moved entry. + */ + isoent_add_child_tail(rrmoved, mvent); + archive_entry_set_nlink(rrmoved->file->entry, + archive_entry_nlink(rrmoved->file->entry) + 1); + /* + * This entry which relocated to the rr_moved directory + * has to set the flag as a file. + * See also RRIP 4.1.5.1 Description of the "CL" System Use Entry. + */ + curent->dir = 0; + + *newent = mvent; + + return (ARCHIVE_OK); +} + +static int +isoent_rr_move(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + struct path_table *pt; + struct isoent *rootent, *rr_moved; + struct isoent *np, *last; + int r; + + pt = &(iso9660->primary.pathtbl[MAX_DEPTH-1]); + /* Theare aren't level 8 directories reaching a deepr level. */ + if (pt->cnt == 0) + return (ARCHIVE_OK); + + rootent = iso9660->primary.rootent; + /* If "rr_moved" directory is already existing, + * we have to use it. */ + rr_moved = isoent_find_child(rootent, "rr_moved"); + if (rr_moved != NULL && + rr_moved != rootent->children.first) { + /* + * It's necessary that rr_move is the first entry + * of the root. + */ + /* Remove "rr_moved" entry from children chain. */ + isoent_remove_child(rootent, rr_moved); + + /* Add "rr_moved" entry into the head of children chain. */ + isoent_add_child_head(rootent, rr_moved); + } + + /* + * Check level 8 path_table. + * If find out sub directory entries, that entries move to rr_move. + */ + np = pt->first; + while (np != NULL) { + last = path_table_last_entry(pt); + for (; np != NULL; np = np->ptnext) { + struct isoent *mvent; + struct isoent *newent; + + if (!np->dir) + continue; + for (mvent = np->subdirs.first; + mvent != NULL; mvent = mvent->drnext) { + r = isoent_rr_move_dir(a, &rr_moved, + mvent, &newent); + if (r < 0) + return (r); + isoent_collect_dirs(&(iso9660->primary), + newent, 2); + } + } + /* If new entries are added to level 8 path_talbe, + * its sub directory entries move to rr_move too. + */ + np = last->ptnext; + } + + return (ARCHIVE_OK); +} + +/* + * This comparing rule is according to ISO9660 Standard 6.9.1 + */ +static int +_compare_path_table(const void *v1, const void *v2) +{ + const struct isoent *p1, *p2; + const char *s1, *s2; + int cmp, l; + + p1 = *((const struct isoent **)(uintptr_t)v1); + p2 = *((const struct isoent **)(uintptr_t)v2); + + /* Compare parent directory number */ + cmp = p1->parent->dir_number - p2->parent->dir_number; + if (cmp != 0) + return (cmp); + + /* Compare indetifier */ + s1 = p1->identifier; + s2 = p2->identifier; + l = p1->ext_off; + if (l > p2->ext_off) + l = p2->ext_off; + cmp = strncmp(s1, s2, l); + if (cmp != 0) + return (cmp); + if (p1->ext_off < p2->ext_off) { + s2 += l; + l = p2->ext_off - p1->ext_off; + while (l--) + if (0x20 != *s2++) + return (0x20 + - *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_off > p2->ext_off) { + s1 += l; + l = p1->ext_off - p2->ext_off; + while (l--) + if (0x20 != *s1++) + return (*(const unsigned char *)(s1 - 1) + - 0x20); + } + return (0); +} + +static int +_compare_path_table_joliet(const void *v1, const void *v2) +{ + const struct isoent *p1, *p2; + const unsigned char *s1, *s2; + int cmp, l; + + p1 = *((const struct isoent **)(uintptr_t)v1); + p2 = *((const struct isoent **)(uintptr_t)v2); + + /* Compare parent directory number */ + cmp = p1->parent->dir_number - p2->parent->dir_number; + if (cmp != 0) + return (cmp); + + /* Compare indetifier */ + s1 = (const unsigned char *)p1->identifier; + s2 = (const unsigned char *)p2->identifier; + l = p1->ext_off; + if (l > p2->ext_off) + l = p2->ext_off; + cmp = memcmp(s1, s2, l); + if (cmp != 0) + return (cmp); + if (p1->ext_off < p2->ext_off) { + s2 += l; + l = p2->ext_off - p1->ext_off; + while (l--) + if (0 != *s2++) + return (- *(const unsigned char *)(s2 - 1)); + } else if (p1->ext_off > p2->ext_off) { + s1 += l; + l = p1->ext_off - p2->ext_off; + while (l--) + if (0 != *s1++) + return (*(const unsigned char *)(s1 - 1)); + } + return (0); +} + +static inline void +path_table_add_entry(struct path_table *pathtbl, struct isoent *ent) +{ + ent->ptnext = NULL; + *pathtbl->last = ent; + pathtbl->last = &(ent->ptnext); + pathtbl->cnt ++; +} + +static inline struct isoent * +path_table_last_entry(struct path_table *pathtbl) +{ + if (pathtbl->first == NULL) + return (NULL); + return (((struct isoent *)(void *) + ((char *)(pathtbl->last) - offsetof(struct isoent, ptnext)))); +} + +/* + * Sort directory entries in path_table + * and assign directory number to each entries. + */ +static int +isoent_make_path_table_2(struct archive_write *a, struct vdd *vdd, + int depth, int *dir_number) +{ + struct isoent *np; + struct isoent **enttbl; + struct path_table *pt; + int i; + + pt = &vdd->pathtbl[depth]; + if (pt->cnt == 0) { + pt->sorted = NULL; + return (ARCHIVE_OK); + } + enttbl = malloc(pt->cnt * sizeof(struct isoent *)); + if (enttbl == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + pt->sorted = enttbl; + for (np = pt->first; np != NULL; np = np->ptnext) + *enttbl ++ = np; + enttbl = pt->sorted; + + switch (vdd->vdd_type) { + case VDD_PRIMARY: + case VDD_ENHANCED: + qsort(enttbl, pt->cnt, sizeof(struct isoent *), + _compare_path_table); + break; + case VDD_JOLIET: + qsort(enttbl, pt->cnt, sizeof(struct isoent *), + _compare_path_table_joliet); + break; + } + for (i = 0; i < pt->cnt; i++) + enttbl[i]->dir_number = (*dir_number)++; + + return (ARCHIVE_OK); +} + +static int +isoent_alloc_path_table(struct archive_write *a, struct vdd *vdd, + int max_depth) +{ + int i; + + vdd->max_depth = max_depth; + vdd->pathtbl = malloc(sizeof(*vdd->pathtbl) * vdd->max_depth); + if (vdd->pathtbl == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + for (i = 0; i < vdd->max_depth; i++) { + vdd->pathtbl[i].first = NULL; + vdd->pathtbl[i].last = &(vdd->pathtbl[i].first); + vdd->pathtbl[i].sorted = NULL; + vdd->pathtbl[i].cnt = 0; + } + return (ARCHIVE_OK); +} + +/* + * Make Path Tables + */ +static int +isoent_make_path_table(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + int depth, r; + int dir_number; + + /* + * Init Path Table. + */ + if (iso9660->dircnt_max >= MAX_DEPTH && + (!iso9660->opt.limit_depth || iso9660->opt.iso_level == 4)) + r = isoent_alloc_path_table(a, &(iso9660->primary), + iso9660->dircnt_max + 1); + else + /* The number of levels in the hierarchy cannot exceed + * eight. */ + r = isoent_alloc_path_table(a, &(iso9660->primary), + MAX_DEPTH); + if (r < 0) + return (r); + if (iso9660->opt.joliet) { + r = isoent_alloc_path_table(a, &(iso9660->joliet), + iso9660->dircnt_max + 1); + if (r < 0) + return (r); + } + + /* Step 0. + * - Collect directories for primary and joliet. + */ + isoent_collect_dirs(&(iso9660->primary), NULL, 0); + if (iso9660->opt.joliet) + isoent_collect_dirs(&(iso9660->joliet), NULL, 0); + /* + * Rockridge; move deeper depth directories to rr_moved. + */ + if (iso9660->opt.rr) { + r = isoent_rr_move(a); + if (r < 0) + return (r); + } + + /* Update nlink. */ + isofile_connect_hardlink_files(iso9660); + + /* Step 1. + * - Renew a value of the depth of that directories. + * - Resolve hardlinks. + * - Convert pathnames to ISO9660 name or UCS2(joliet). + * - Sort files by each directory. + */ + r = isoent_traverse_tree(a, &(iso9660->primary)); + if (r < 0) + return (r); + if (iso9660->opt.joliet) { + r = isoent_traverse_tree(a, &(iso9660->joliet)); + if (r < 0) + return (r); + } + + /* Step 2. + * - Sort directories. + * - Assign all directory number. + */ + dir_number = 1; + for (depth = 0; depth < iso9660->primary.max_depth; depth++) { + r = isoent_make_path_table_2(a, &(iso9660->primary), + depth, &dir_number); + if (r < 0) + return (r); + } + if (iso9660->opt.joliet) { + dir_number = 1; + for (depth = 0; depth < iso9660->joliet.max_depth; depth++) { + r = isoent_make_path_table_2(a, &(iso9660->joliet), + depth, &dir_number); + if (r < 0) + return (r); + } + } + if (iso9660->opt.limit_dirs && dir_number > 0xffff) { + /* + * Maximum number of directories is 65535(0xffff) + * doe to size(16bit) of Parent Directory Number of + * the Path Table. + * See also ISO9660 Standard 9.4. + */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Too many directories(%d) over 65535.", dir_number); + return (ARCHIVE_FATAL); + } + + /* Get the size of the Path Table. */ + calculate_path_table_size(&(iso9660->primary)); + if (iso9660->opt.joliet) + calculate_path_table_size(&(iso9660->joliet)); + + return (ARCHIVE_OK); +} + +static int +isoent_find_out_boot_file(struct archive_write *a, struct isoent *rootent) +{ + struct iso9660 *iso9660 = a->format_data; + + /* Find a isoent of the boot file. */ + iso9660->el_torito.boot = isoent_find_entry(rootent, + iso9660->el_torito.boot_filename.s); + if (iso9660->el_torito.boot == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't find the boot image file ``%s''", + iso9660->el_torito.boot_filename.s); + return (ARCHIVE_FATAL); + } + iso9660->el_torito.boot->file->boot = BOOT_IMAGE; + return (ARCHIVE_OK); +} + +static int +isoent_create_boot_catalog(struct archive_write *a, struct isoent *rootent) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file; + struct isoent *isoent; + struct archive_entry *entry; + + (void)rootent; /* UNUSED */ + /* + * Create the entry which is the "boot.catalog" file. + */ + file = isofile_new(a, NULL); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + archive_entry_set_pathname(file->entry, + iso9660->el_torito.catalog_filename.s); + archive_entry_set_size(file->entry, LOGICAL_BLOCK_SIZE); + archive_entry_set_mtime(file->entry, iso9660->birth_time, 0); + archive_entry_set_atime(file->entry, iso9660->birth_time, 0); + archive_entry_set_ctime(file->entry, iso9660->birth_time, 0); + archive_entry_set_uid(file->entry, getuid()); + archive_entry_set_gid(file->entry, getgid()); + archive_entry_set_mode(file->entry, AE_IFREG | 0444); + archive_entry_set_nlink(file->entry, 1); + + if (isofile_gen_utility_names(a, file) < ARCHIVE_WARN) { + isofile_free(file); + return (ARCHIVE_FATAL); + } + file->boot = BOOT_CATALOG; + file->content.size = LOGICAL_BLOCK_SIZE; + isofile_add_entry(iso9660, file); + + isoent = isoent_new(file); + if (isoent == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + isoent->virtual = 1; + + /* Add the "boot.catalog" entry into tree */ + if (isoent_tree(a, &isoent) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + iso9660->el_torito.catalog = isoent; + /* + * Get a boot medai type. + */ + switch (iso9660->opt.boot_type) { + default: + case OPT_BOOT_TYPE_AUTO: + /* Try detecting a media type of the boot image. */ + entry = iso9660->el_torito.boot->file->entry; + if (archive_entry_size(entry) == FD_1_2M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_1_2M_DISKETTE; + else if (archive_entry_size(entry) == FD_1_44M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_1_44M_DISKETTE; + else if (archive_entry_size(entry) == FD_2_88M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_2_88M_DISKETTE; + else + /* We cannot decide whether the boot image is + * hard-disk. */ + iso9660->el_torito.media_type = + BOOT_MEDIA_NO_EMULATION; + break; + case OPT_BOOT_TYPE_NO_EMU: + iso9660->el_torito.media_type = BOOT_MEDIA_NO_EMULATION; + break; + case OPT_BOOT_TYPE_HARD_DISK: + iso9660->el_torito.media_type = BOOT_MEDIA_HARD_DISK; + break; + case OPT_BOOT_TYPE_FD: + entry = iso9660->el_torito.boot->file->entry; + if (archive_entry_size(entry) <= FD_1_2M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_1_2M_DISKETTE; + else if (archive_entry_size(entry) <= FD_1_44M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_1_44M_DISKETTE; + else if (archive_entry_size(entry) <= FD_2_88M_SIZE) + iso9660->el_torito.media_type = + BOOT_MEDIA_2_88M_DISKETTE; + else { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Boot image file(``%s'') size is too big " + "for fd type.", + iso9660->el_torito.boot_filename.s); + return (ARCHIVE_FATAL); + } + break; + } + + /* + * Get a system type. + * TODO: `El Torito' specification says "A copy of byte 5 from the + * Partition Table found in the boot image". + */ + iso9660->el_torito.system_type = 0; + + /* + * Get an ID. + */ + if (iso9660->opt.publisher) + archive_string_copy(&(iso9660->el_torito.id), + &(iso9660->publisher_identifier)); + + + return (ARCHIVE_OK); +} + +/* + * If a media type is floppy, return its image size. + * otherwise return 0. + */ +static size_t +fd_boot_image_size(int media_type) +{ + switch (media_type) { + case BOOT_MEDIA_1_2M_DISKETTE: + return (FD_1_2M_SIZE); + case BOOT_MEDIA_1_44M_DISKETTE: + return (FD_1_44M_SIZE); + case BOOT_MEDIA_2_88M_DISKETTE: + return (FD_2_88M_SIZE); + default: + return (0); + } +} + +/* + * Make a boot catalog image data. + */ +static int +make_boot_catalog(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + unsigned char *block; + unsigned char *p; + uint16_t sum, *wp; + + block = wb_buffptr(a); + memset(block, 0, LOGICAL_BLOCK_SIZE); + p = block; + /* + * Validation Entry + */ + /* Header ID */ + p[0] = 1; + /* Platform ID */ + p[1] = iso9660->el_torito.platform_id; + /* Reserved */ + p[2] = p[3] = 0; + /* ID */ + if (archive_strlen(&(iso9660->el_torito.id)) > 0) + strncpy((char *)p+4, iso9660->el_torito.id.s, 23); + p[27] = 0; + /* Checksum */ + p[28] = p[29] = 0; + /* Key */ + p[30] = 0x55; + p[31] = 0xAA; + + sum = 0; + wp = (uint16_t *)block; + while (wp < (uint16_t *)&block[32]) + sum += archive_le16dec(wp++); + set_num_721(&block[28], (~sum) + 1); + + /* + * Initial/Default Entry + */ + p = &block[32]; + /* Boot Indicator */ + p[0] = 0x88; + /* Boot media type */ + p[1] = iso9660->el_torito.media_type; + /* Load Segment */ + if (iso9660->el_torito.media_type == BOOT_MEDIA_NO_EMULATION) + set_num_721(&p[2], iso9660->el_torito.boot_load_seg); + else + set_num_721(&p[2], 0); + /* System Type */ + p[4] = iso9660->el_torito.system_type; + /* Unused */ + p[5] = 0; + /* Sector Count */ + if (iso9660->el_torito.media_type == BOOT_MEDIA_NO_EMULATION) + set_num_721(&p[6], iso9660->el_torito.boot_load_size); + else + set_num_721(&p[6], 1); + /* Load RBA */ + set_num_731(&p[8], + iso9660->el_torito.boot->file->content.location); + /* Unused */ + memset(&p[12], 0, 20); + + return (wb_consume(a, LOGICAL_BLOCK_SIZE)); +} + +static int +setup_boot_information(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + struct isoent *np; + int64_t size; + uint32_t sum; + unsigned char buff[4096]; + + np = iso9660->el_torito.boot; + lseek(iso9660->temp_fd, + np->file->content.offset_of_temp + 64, SEEK_SET); + size = archive_entry_size(np->file->entry) - 64; + if (size <= 0) { + archive_set_error(&a->archive, errno, + "Boot file(%jd) is too small", (intmax_t)size + 64); + return (ARCHIVE_FATAL); + } + sum = 0; + while (size > 0) { + size_t rsize; + ssize_t i, rs; + + if (size > sizeof(buff)) + rsize = sizeof(buff); + else + rsize = (size_t)size; + + rs = read(iso9660->temp_fd, buff, rsize); + if (rs <= 0) { + archive_set_error(&a->archive, errno, + "Can't read temporary file(%jd)", + (intmax_t)rs); + return (ARCHIVE_FATAL); + } + for (i = 0; i < rs; i += 4) + sum += archive_le32dec(buff + i); + size -= rs; + } + /* Set the location of Primary Volume Descriptor. */ + set_num_731(buff, SYSTEM_AREA_BLOCK); + /* Set the location of the boot file. */ + set_num_731(buff+4, np->file->content.location); + /* Set the size of the boot file. */ + size = fd_boot_image_size(iso9660->el_torito.media_type); + if (size == 0) + size = archive_entry_size(np->file->entry); + set_num_731(buff+8, (uint32_t)size); + /* Set the sum of the boot file. */ + set_num_731(buff+12, sum); + /* Clear reserved bytes. */ + memset(buff+16, 0, 40); + + /* Overwrite the boot file. */ + lseek(iso9660->temp_fd, + np->file->content.offset_of_temp + 8, SEEK_SET); + return (write_to_temp(a, buff, 56)); +} + +#ifdef HAVE_ZLIB_H + +static int +zisofs_init_zstream(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + int r; + + iso9660->zisofs.stream.next_in = NULL; + iso9660->zisofs.stream.avail_in = 0; + iso9660->zisofs.stream.total_in = 0; + iso9660->zisofs.stream.total_out = 0; + if (iso9660->zisofs.stream_valid) + r = deflateReset(&(iso9660->zisofs.stream)); + else { + r = deflateInit(&(iso9660->zisofs.stream), + iso9660->zisofs.compression_level); + iso9660->zisofs.stream_valid = 1; + } + switch (r) { + case Z_OK: + break; + default: + case Z_STREAM_ERROR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid setup parameter"); + return (ARCHIVE_FATAL); + case Z_MEM_ERROR: + archive_set_error(&a->archive, ENOMEM, + "Internal error initializing " + "compression library"); + return (ARCHIVE_FATAL); + case Z_VERSION_ERROR: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal error initializing " + "compression library: invalid library version"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +#endif /* HAVE_ZLIB_H */ + +static int +zisofs_init(struct archive_write *a, struct isofile *file) +{ + struct iso9660 *iso9660 = a->format_data; +#ifdef HAVE_ZLIB_H + uint64_t tsize; + size_t ceil, bpsize; + int r; +#endif + + iso9660->zisofs.detect_magic = 0; + iso9660->zisofs.making = 0; + + if (!iso9660->opt.rr || !iso9660->opt.zisofs) + return (ARCHIVE_OK); + + if (archive_entry_size(file->entry) >= 24 && + archive_entry_size(file->entry) < MULTI_EXTENT_SIZE) { + /* Acceptable file size for zisofs. */ + iso9660->zisofs.detect_magic = 1; + iso9660->zisofs.magic_cnt = 0; + } + if (!iso9660->zisofs.detect_magic) + return (ARCHIVE_OK); + +#ifdef HAVE_ZLIB_H + /* The number of Logical Blocks which uncompressed data + * will use in iso-image file is the same as the number of + * Logical Blocks which zisofs(compressed) data will use + * in ISO-image file. It won't reduce iso-image file size. */ + if (archive_entry_size(file->entry) <= LOGICAL_BLOCK_SIZE) + return (ARCHIVE_OK); + + /* Initialize compression library */ + r = zisofs_init_zstream(a); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Mark file->zisofs to create RRIP 'ZF' Use Entry. */ + file->zisofs.header_size = ZF_HEADER_SIZE >> 2; + file->zisofs.log2_bs = ZF_LOG2_BS; + file->zisofs.uncompressed_size = archive_entry_size(file->entry); + + /* Calculate a size of Block Pointers of zisofs. */ + ceil = (file->zisofs.uncompressed_size + ZF_BLOCK_SIZE -1) + >> file->zisofs.log2_bs; + iso9660->zisofs.block_pointers_cnt = ceil + 1; + iso9660->zisofs.block_pointers_idx = 0; + + /* Ensure a buffer size used for Block Pointers */ + bpsize = iso9660->zisofs.block_pointers_cnt * + sizeof(iso9660->zisofs.block_pointers[0]); + if (iso9660->zisofs.block_pointers_allocated < bpsize) { + free(iso9660->zisofs.block_pointers); + iso9660->zisofs.block_pointers = malloc(bpsize); + if (iso9660->zisofs.block_pointers == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + return (ARCHIVE_FATAL); + } + iso9660->zisofs.block_pointers_allocated = bpsize; + } + + /* + * Skip zisofs header and Block Pointers, which we will write + * after all compressed data of a file written to the temporary + * file. + */ + tsize = ZF_HEADER_SIZE + bpsize; + if (write_null(a, tsize) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* + * Initialize some variables to make zisofs. + */ + archive_le32enc(&(iso9660->zisofs.block_pointers[0]), tsize); + iso9660->zisofs.remaining = file->zisofs.uncompressed_size; + iso9660->zisofs.making = 1; + iso9660->zisofs.allzero = 1; + iso9660->zisofs.block_offset = tsize; + iso9660->zisofs.total_size = tsize; + iso9660->cur_file->cur_content->size = tsize; +#endif + + return (ARCHIVE_OK); +} + +static void +zisofs_detect_magic(struct archive_write *a, const void *buff, size_t s) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file = iso9660->cur_file; + const unsigned char *p, *endp; + const unsigned char *magic_buff; + uint32_t uncompressed_size; + unsigned char header_size; + unsigned char log2_bs; + size_t ceil, doff; + uint32_t bst, bed; + int magic_max; + int64_t entry_size; + + entry_size = archive_entry_size(file->entry); + if (sizeof(iso9660->zisofs.magic_buffer) > entry_size) + magic_max = entry_size; + else + magic_max = sizeof(iso9660->zisofs.magic_buffer); + + if (iso9660->zisofs.magic_cnt == 0 && s >= (size_t)magic_max) + /* It's unnecessary we copy buffer. */ + magic_buff = buff; + else { + if (iso9660->zisofs.magic_cnt < magic_max) { + size_t l; + + l = sizeof(iso9660->zisofs.magic_buffer) + - iso9660->zisofs.magic_cnt; + if (l > s) + l = s; + memcpy(iso9660->zisofs.magic_buffer + + iso9660->zisofs.magic_cnt, buff, l); + iso9660->zisofs.magic_cnt += l; + if (iso9660->zisofs.magic_cnt < magic_max) + return; + } + magic_buff = iso9660->zisofs.magic_buffer; + } + iso9660->zisofs.detect_magic = 0; + p = magic_buff; + + /* Check the magic code of zisofs. */ + if (memcmp(p, zisofs_magic, sizeof(zisofs_magic)) != 0) + /* This is not zisofs file which made by mkzftree. */ + return; + p += sizeof(zisofs_magic); + + /* Read a zisofs header. */ + uncompressed_size = archive_le32dec(p); + header_size = p[4]; + log2_bs = p[5]; + if (uncompressed_size < 24 || header_size != 4 || + log2_bs > 30 || log2_bs < 7) + return;/* Invalid or not supported header. */ + + /* Calculate a size of Block Pointers of zisofs. */ + ceil = (uncompressed_size + + (ARCHIVE_LITERAL_LL(1) << log2_bs) -1) >> log2_bs; + doff = (ceil + 1) * 4 + 16; + if (entry_size < doff) + return;/* Invalid data. */ + + /* Check every Block Pointer has valid value. */ + p = magic_buff + 16; + endp = magic_buff + magic_max; + while (ceil && p + 8 <= endp) { + bst = archive_le32dec(p); + if (bst != doff) + return;/* Invalid data. */ + p += 4; + bed = archive_le32dec(p); + if (bed < bst || bed > entry_size) + return;/* Invalid data. */ + doff += bed - bst; + ceil--; + } + + file->zisofs.uncompressed_size = uncompressed_size; + file->zisofs.header_size = header_size; + file->zisofs.log2_bs = log2_bs; + + /* Disable making a zisofs image. */ + iso9660->zisofs.making = 0; +} + +#ifdef HAVE_ZLIB_H + +/* + * Compress data and write it to a temporary file. + */ +static int +zisofs_write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file = iso9660->cur_file; + const unsigned char *b; + z_stream *zstrm; + size_t avail, csize; + int flush, r; + + zstrm = &(iso9660->zisofs.stream); + zstrm->next_out = wb_buffptr(a); + zstrm->avail_out = wb_remaining(a); + b = (const unsigned char *)buff; + do { + avail = ZF_BLOCK_SIZE - zstrm->total_in; + if (s < avail) { + avail = s; + flush = Z_NO_FLUSH; + } else + flush = Z_FINISH; + iso9660->zisofs.remaining -= avail; + if (iso9660->zisofs.remaining <= 0) + flush = Z_FINISH; + + zstrm->next_in = (Bytef *)(uintptr_t)(const void *)b; + zstrm->avail_in = avail; + + /* + * Check if current data block are all zero. + */ + if (iso9660->zisofs.allzero) { + const unsigned char *nonzero = b; + const unsigned char *nonzeroend = b + avail; + + while (nonzero < nonzeroend) + if (*nonzero++) { + iso9660->zisofs.allzero = 0; + break; + } + } + b += avail; + s -= avail; + + /* + * If current data block are all zero, we do not use + * compressed data. + */ + if (flush == Z_FINISH && iso9660->zisofs.allzero && + avail + zstrm->total_in == ZF_BLOCK_SIZE) { + if (iso9660->zisofs.block_offset != + file->cur_content->size) { + int64_t diff; + + r = wb_set_offset(a, + file->cur_content->offset_of_temp + + iso9660->zisofs.block_offset); + if (r != ARCHIVE_OK) + return (r); + diff = file->cur_content->size - + iso9660->zisofs.block_offset; + file->cur_content->size -= diff; + iso9660->zisofs.total_size -= diff; + } + zstrm->avail_in = 0; + } + + /* + * Compress file data. + */ + while (zstrm->avail_in > 0) { + csize = zstrm->total_out; + r = deflate(zstrm, flush); + switch (r) { + case Z_OK: + case Z_STREAM_END: + csize = zstrm->total_out - csize; + if (wb_consume(a, csize) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->zisofs.total_size += csize; + iso9660->cur_file->cur_content->size += csize; + zstrm->next_out = wb_buffptr(a); + zstrm->avail_out = wb_remaining(a); + break; + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Compression failed:" + " deflate() call returned status %d", + r); + return (ARCHIVE_FATAL); + } + } + + if (flush == Z_FINISH) { + /* + * Save the information of one zisofs block. + */ + iso9660->zisofs.block_pointers_idx ++; + archive_le32enc(&(iso9660->zisofs.block_pointers[ + iso9660->zisofs.block_pointers_idx]), + iso9660->zisofs.total_size); + r = zisofs_init_zstream(a); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + iso9660->zisofs.allzero = 1; + iso9660->zisofs.block_offset = file->cur_content->size; + } + } while (s); + + return (ARCHIVE_OK); +} + +static int +zisofs_finish_entry(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file = iso9660->cur_file; + unsigned char buff[16]; + size_t s; + int64_t tail; + + /* Direct temp file stream to zisofs temp file stream. */ + archive_entry_set_size(file->entry, iso9660->zisofs.total_size); + + /* + * Save a file pointer which points the end of current zisofs data. + */ + tail = wb_offset(a); + + /* + * Make a header. + * + * +-----------------+----------------+-----------------+ + * | Header 16 bytes | Block Pointers | Compressed data | + * +-----------------+----------------+-----------------+ + * 0 16 +X + * Block Pointers : + * 4 * (((Uncompressed file size + block_size -1) / block_size) + 1) + * + * Write zisofs header. + * Magic number + * +----+----+----+----+----+----+----+----+ + * | 37 | E4 | 53 | 96 | C9 | DB | D6 | 07 | + * +----+----+----+----+----+----+----+----+ + * 0 1 2 3 4 5 6 7 8 + * + * +------------------------+------------------+ + * | Uncompressed file size | header_size >> 2 | + * +------------------------+------------------+ + * 8 12 13 + * + * +-----------------+----------------+ + * | log2 block_size | Reserved(0000) | + * +-----------------+----------------+ + * 13 14 16 + */ + memcpy(buff, zisofs_magic, 8); + set_num_731(buff+8, file->zisofs.uncompressed_size); + buff[12] = file->zisofs.header_size; + buff[13] = file->zisofs.log2_bs; + buff[14] = buff[15] = 0;/* Reserved */ + + /* Move to the right position to write the header. */ + wb_set_offset(a, file->content.offset_of_temp); + + /* Write the header. */ + if (wb_write_to_temp(a, buff, 16) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* + * Write zisofs Block Pointers. + */ + s = iso9660->zisofs.block_pointers_cnt * + sizeof(iso9660->zisofs.block_pointers[0]); + if (wb_write_to_temp(a, iso9660->zisofs.block_pointers, s) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Set a file pointer back to the end of the temporary file. */ + wb_set_offset(a, tail); + + return (ARCHIVE_OK); +} + +static int +zisofs_free(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + int ret = ARCHIVE_OK; + + free(iso9660->zisofs.block_pointers); + if (iso9660->zisofs.stream_valid && + deflateEnd(&(iso9660->zisofs.stream)) != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + } + iso9660->zisofs.block_pointers = NULL; + iso9660->zisofs.stream_valid = 0; + return (ret); +} + +struct zisofs_extract { + int pz_log2_bs; /* Log2 of block size */ + uint64_t pz_uncompressed_size; + size_t uncompressed_buffer_size; + + int initialized:1; + int header_passed:1; + + uint32_t pz_offset; + unsigned char *block_pointers; + size_t block_pointers_size; + size_t block_pointers_avail; + size_t block_off; + uint32_t block_avail; + + z_stream stream; + int stream_valid; +}; + +static ssize_t +zisofs_extract_init(struct archive_write *a, struct zisofs_extract *zisofs, + const unsigned char *p, size_t bytes) +{ + size_t avail = bytes; + size_t ceil, xsize; + + /* Allocate block pointers buffer. */ + ceil = (zisofs->pz_uncompressed_size + + (((int64_t)1) << zisofs->pz_log2_bs) - 1) + >> zisofs->pz_log2_bs; + xsize = (ceil + 1) * 4; + if (zisofs->block_pointers == NULL) { + size_t alloc = ((xsize >> 10) + 1) << 10; + zisofs->block_pointers = malloc(alloc); + if (zisofs->block_pointers == NULL) { + archive_set_error(&a->archive, ENOMEM, + "No memory for zisofs decompression"); + return (ARCHIVE_FATAL); + } + } + zisofs->block_pointers_size = xsize; + + /* Allocate uncompressed data buffer. */ + zisofs->uncompressed_buffer_size = 1UL << zisofs->pz_log2_bs; + + /* + * Read the file header, and check the magic code of zisofs. + */ + if (!zisofs->header_passed) { + int err = 0; + if (avail < 16) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs file body"); + return (ARCHIVE_FATAL); + } + + if (memcmp(p, zisofs_magic, sizeof(zisofs_magic)) != 0) + err = 1; + else if (archive_le32dec(p + 8) != zisofs->pz_uncompressed_size) + err = 1; + else if (p[12] != 4 || p[13] != zisofs->pz_log2_bs) + err = 1; + if (err) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs file body"); + return (ARCHIVE_FATAL); + } + avail -= 16; + p += 16; + zisofs->header_passed = 1; + } + + /* + * Read block pointers. + */ + if (zisofs->header_passed && + zisofs->block_pointers_avail < zisofs->block_pointers_size) { + xsize = zisofs->block_pointers_size + - zisofs->block_pointers_avail; + if (avail < xsize) + xsize = avail; + memcpy(zisofs->block_pointers + + zisofs->block_pointers_avail, p, xsize); + zisofs->block_pointers_avail += xsize; + avail -= xsize; + if (zisofs->block_pointers_avail + == zisofs->block_pointers_size) { + /* We've got all block pointers and initialize + * related variables. */ + zisofs->block_off = 0; + zisofs->block_avail = 0; + /* Complete a initialization */ + zisofs->initialized = 1; + } + } + return ((ssize_t)avail); +} + +static ssize_t +zisofs_extract(struct archive_write *a, struct zisofs_extract *zisofs, + const unsigned char *p, size_t bytes) +{ + size_t avail; + int r; + + if (!zisofs->initialized) { + ssize_t rs = zisofs_extract_init(a, zisofs, p, bytes); + if (rs < 0) + return (rs); + if (!zisofs->initialized) { + /* We need more data. */ + zisofs->pz_offset += bytes; + return (bytes); + } + avail = rs; + p += bytes - avail; + } else + avail = bytes; + + /* + * Get block offsets from block pointers. + */ + if (zisofs->block_avail == 0) { + uint32_t bst, bed; + + if (zisofs->block_off + 4 >= zisofs->block_pointers_size) { + /* There isn't a pair of offsets. */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + bst = archive_le32dec( + zisofs->block_pointers + zisofs->block_off); + if (bst != zisofs->pz_offset + (bytes - avail)) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers(cannot seek)"); + return (ARCHIVE_FATAL); + } + bed = archive_le32dec( + zisofs->block_pointers + zisofs->block_off + 4); + if (bed < bst) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Illegal zisofs block pointers"); + return (ARCHIVE_FATAL); + } + zisofs->block_avail = bed - bst; + zisofs->block_off += 4; + + /* Initialize compression library for new block. */ + if (zisofs->stream_valid) + r = inflateReset(&zisofs->stream); + else + r = inflateInit(&zisofs->stream); + if (r != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't initialize zisofs decompression."); + return (ARCHIVE_FATAL); + } + zisofs->stream_valid = 1; + zisofs->stream.total_in = 0; + zisofs->stream.total_out = 0; + } + + /* + * Make uncompressed data. + */ + if (zisofs->block_avail == 0) { + /* + * It's basically 32K bytes NUL data. + */ + unsigned char *wb; + size_t size, wsize; + + size = zisofs->uncompressed_buffer_size; + while (size) { + wb = wb_buffptr(a); + if (size > wb_remaining(a)) + wsize = wb_remaining(a); + else + wsize = size; + memset(wb, 0, wsize); + r = wb_consume(a, wsize); + if (r < 0) + return (r); + size -= wsize; + } + } else { + zisofs->stream.next_in = (Bytef *)(uintptr_t)(const void *)p; + if (avail > zisofs->block_avail) + zisofs->stream.avail_in = zisofs->block_avail; + else + zisofs->stream.avail_in = avail; + zisofs->stream.next_out = wb_buffptr(a); + zisofs->stream.avail_out = wb_remaining(a); + + r = inflate(&zisofs->stream, 0); + switch (r) { + case Z_OK: /* Decompressor made some progress.*/ + case Z_STREAM_END: /* Found end of stream. */ + break; + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "zisofs decompression failed (%d)", r); + return (ARCHIVE_FATAL); + } + avail -= zisofs->stream.next_in - p; + zisofs->block_avail -= zisofs->stream.next_in - p; + r = wb_consume(a, wb_remaining(a) - zisofs->stream.avail_out); + if (r < 0) + return (r); + } + zisofs->pz_offset += bytes; + return (bytes - avail); +} + +static int +zisofs_rewind_boot_file(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + struct isofile *file; + unsigned char *rbuff; + ssize_t r; + size_t remaining, rbuff_size; + struct zisofs_extract zext; + int64_t read_offset, write_offset, new_offset; + int fd, ret = ARCHIVE_OK; + + file = iso9660->el_torito.boot->file; + /* + * There is nothing to do if this boot file does not have + * zisofs header. + */ + if (file->zisofs.header_size == 0) + return (ARCHIVE_OK); + + /* + * Uncompress the zisofs'ed file contents. + */ + memset(&zext, 0, sizeof(zext)); + zext.pz_uncompressed_size = file->zisofs.uncompressed_size; + zext.pz_log2_bs = file->zisofs.log2_bs; + + fd = iso9660->temp_fd; + new_offset = wb_offset(a); + read_offset = file->content.offset_of_temp; + remaining = file->content.size; + if (remaining > 1024 * 32) + rbuff_size = 1024 * 32; + else + rbuff_size = remaining; + + rbuff = malloc(rbuff_size); + if (rbuff == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + while (remaining) { + size_t rsize; + ssize_t rs; + + /* Get the current file pointer. */ + write_offset = lseek(fd, 0, SEEK_CUR); + + /* Change the file pointer to read. */ + lseek(fd, read_offset, SEEK_SET); + + rsize = rbuff_size; + if (rsize > remaining) + rsize = remaining; + rs = read(iso9660->temp_fd, rbuff, rsize); + if (rs <= 0) { + archive_set_error(&a->archive, errno, + "Can't read temporary file(%jd)", (intmax_t)rs); + ret = ARCHIVE_FATAL; + break; + } + remaining -= rs; + read_offset += rs; + + /* Put the file pointer back to write. */ + lseek(fd, write_offset, SEEK_SET); + + r = zisofs_extract(a, &zext, rbuff, rs); + if (r < 0) { + ret = (int)r; + break; + } + } + + if (ret == ARCHIVE_OK) { + /* + * Change the boot file content from zisofs'ed data + * to plain data. + */ + file->content.offset_of_temp = new_offset; + file->content.size = file->zisofs.uncompressed_size; + archive_entry_set_size(file->entry, file->content.size); + /* Set to be no zisofs. */ + file->zisofs.header_size = 0; + file->zisofs.log2_bs = 0; + file->zisofs.uncompressed_size = 0; + r = wb_write_padding_to_temp(a, file->content.size); + if (r < 0) + ret = ARCHIVE_FATAL; + } + + /* + * Free the resource we used in this function only. + */ + free(rbuff); + free(zext.block_pointers); + if (zext.stream_valid && inflateEnd(&(zext.stream)) != Z_OK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + ret = ARCHIVE_FATAL; + } + + return (ret); +} + +#else + +static int +zisofs_write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + (void)buff; /* UNUSED */ + (void)s; /* UNUSED */ + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Programing error"); + return (ARCHIVE_FATAL); +} + +static int +zisofs_rewind_boot_file(struct archive_write *a) +{ + struct iso9660 *iso9660 = a->format_data; + + if (iso9660->el_torito.boot->file->zisofs.header_size != 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "We cannot extract the zisofs imaged boot file;" + " this may not boot in being zisofs imaged"); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); +} + +static int +zisofs_finish_entry(struct archive_write *a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +} + +static int +zisofs_free(struct archive_write *a) +{ + (void)a; /* UNUSED */ + return (ARCHIVE_OK); +} + +#endif /* HAVE_ZLIB_H */ + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c index 68dc92b56..3802a25f3 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_mtree.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Michihiro NAKAJIMA + * Copyright (c) 2009,2011 Michihiro NAKAJIMA * Copyright (c) 2008 Joerg Sonnenberger * All rights reserved. * @@ -25,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_mtree.c 201171 2009-12-29 06:39:07Z kientzle $"); #ifdef HAVE_SYS_TYPES_H #include @@ -35,262 +35,335 @@ __FBSDID("$FreeBSD$"); #include #include "archive.h" +#include "archive_crypto_private.h" #include "archive_entry.h" #include "archive_private.h" #include "archive_write_private.h" -#include "archive_hash.h" +#define INDENTNAMELEN 15 +#define MAXLINELEN 80 +#define SET_KEYS \ + (F_FLAGS | F_GID | F_GNAME | F_MODE | F_TYPE | F_UID | F_UNAME) + +struct mtree_entry { + struct mtree_entry *next; + + char *pathname; + char *symlink; + unsigned int nlink; + mode_t filetype; + mode_t mode; + int64_t uid; + int64_t gid; + char *uname; + char *gname; + char *fflags_text; + unsigned long fflags_set; + unsigned long fflags_clear; + time_t mtime; + long mtime_nsec; + dev_t rdevmajor; + dev_t rdevminor; + int64_t size; + + 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 +}; -#define INDENTNAMELEN 15 -#define MAXLINELEN 80 +struct attr_counter { + struct attr_counter *prev; + struct attr_counter *next; + int count; + struct mtree_entry *m_entry; +}; struct mtree_writer { - struct archive_entry *entry; - struct archive_string ebuf; - struct archive_string buf; - int first; - uint64_t entry_bytes_remaining; - struct { - int output; - int processed; - struct archive_string parent; - mode_t type; - int keys; - uid_t uid; - gid_t gid; - mode_t mode; - unsigned long fflags_set; - unsigned long fflags_clear; - } set; - /* chekc sum */ - int compute_sum; - uint32_t crc; - uint64_t crc_len; + struct mtree_entry *mtree_entry; + struct archive_string ebuf; + struct archive_string buf; + int first; + uint64_t entry_bytes_remaining; + struct { + int output; + int processed; + struct archive_string parent; + mode_t type; + int keys; + int64_t uid; + int64_t gid; + mode_t mode; + unsigned long fflags_set; + unsigned long fflags_clear; + + struct attr_counter *uid_list; + struct attr_counter *gid_list; + struct attr_counter *mode_list; + struct attr_counter *flags_list; + struct mtree_entry *me_first; + struct mtree_entry **me_last; + } set; + /* check sum */ + int compute_sum; + uint32_t crc; + uint64_t crc_len; #ifdef ARCHIVE_HAS_MD5 - archive_md5_ctx md5ctx; + archive_md5_ctx md5ctx; #endif #ifdef ARCHIVE_HAS_RMD160 - archive_rmd160_ctx rmd160ctx; + archive_rmd160_ctx rmd160ctx; #endif #ifdef ARCHIVE_HAS_SHA1 - archive_sha1_ctx sha1ctx; + archive_sha1_ctx sha1ctx; #endif #ifdef ARCHIVE_HAS_SHA256 - archive_sha256_ctx sha256ctx; + archive_sha256_ctx sha256ctx; #endif #ifdef ARCHIVE_HAS_SHA384 - archive_sha384_ctx sha384ctx; + archive_sha384_ctx sha384ctx; #endif #ifdef ARCHIVE_HAS_SHA512 - archive_sha512_ctx sha512ctx; + archive_sha512_ctx sha512ctx; #endif - /* Keyword options */ - int keys; -#define F_CKSUM 0x00000001 /* check sum */ -#define F_DEV 0x00000002 /* device type */ -#define F_DONE 0x00000004 /* directory done */ -#define F_FLAGS 0x00000008 /* file flags */ -#define F_GID 0x00000010 /* gid */ -#define F_GNAME 0x00000020 /* group name */ -#define F_IGN 0x00000040 /* ignore */ -#define F_MAGIC 0x00000080 /* name has magic chars */ -#define F_MD5 0x00000100 /* MD5 digest */ -#define F_MODE 0x00000200 /* mode */ -#define F_NLINK 0x00000400 /* number of links */ -#define F_NOCHANGE 0x00000800 /* If owner/mode "wrong", do - * not change */ -#define F_OPT 0x00001000 /* existence optional */ -#define F_RMD160 0x00002000 /* RIPEMD160 digest */ -#define F_SHA1 0x00004000 /* SHA-1 digest */ -#define F_SIZE 0x00008000 /* size */ -#define F_SLINK 0x00010000 /* symbolic link */ -#define F_TAGS 0x00020000 /* tags */ -#define F_TIME 0x00040000 /* modification time */ -#define F_TYPE 0x00080000 /* file type */ -#define F_UID 0x00100000 /* uid */ -#define F_UNAME 0x00200000 /* user name */ -#define F_VISIT 0x00400000 /* file visited */ -#define F_SHA256 0x00800000 /* SHA-256 digest */ -#define F_SHA384 0x01000000 /* SHA-384 digest */ -#define F_SHA512 0x02000000 /* SHA-512 digest */ - - /* Options */ - int dironly; /* if the dironly is 1, ignore everything except - * directory type files. like mtree(8) -d option. - */ - int indent; /* if the indent is 1, indent writing data. */ + /* Keyword options */ + int keys; +#define F_CKSUM 0x00000001 /* check sum */ +#define F_DEV 0x00000002 /* device type */ +#define F_DONE 0x00000004 /* directory done */ +#define F_FLAGS 0x00000008 /* file flags */ +#define F_GID 0x00000010 /* gid */ +#define F_GNAME 0x00000020 /* group name */ +#define F_IGN 0x00000040 /* ignore */ +#define F_MAGIC 0x00000080 /* name has magic chars */ +#define F_MD5 0x00000100 /* MD5 digest */ +#define F_MODE 0x00000200 /* mode */ +#define F_NLINK 0x00000400 /* number of links */ +#define F_NOCHANGE 0x00000800 /* If owner/mode "wrong", do + * not change */ +#define F_OPT 0x00001000 /* existence optional */ +#define F_RMD160 0x00002000 /* RIPEMD160 digest */ +#define F_SHA1 0x00004000 /* SHA-1 digest */ +#define F_SIZE 0x00008000 /* size */ +#define F_SLINK 0x00010000 /* symbolic link */ +#define F_TAGS 0x00020000 /* tags */ +#define F_TIME 0x00040000 /* modification time */ +#define F_TYPE 0x00080000 /* file type */ +#define F_UID 0x00100000 /* uid */ +#define F_UNAME 0x00200000 /* user name */ +#define F_VISIT 0x00400000 /* file visited */ +#define F_SHA256 0x00800000 /* SHA-256 digest */ +#define F_SHA384 0x01000000 /* SHA-384 digest */ +#define F_SHA512 0x02000000 /* SHA-512 digest */ + + /* Options */ + int dironly; /* if the dironly is 1, ignore everything except + * directory type files. like mtree(8) -d option. + */ + int indent; /* if the indent is 1, indent writing data. */ }; -#define DEFAULT_KEYS (F_DEV | F_FLAGS | F_GID | F_GNAME | F_SLINK | F_MODE\ - | F_NLINK | F_SIZE | F_TIME | F_TYPE | F_UID\ - | F_UNAME) - -#define COMPUTE_CRC(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] +#define DEFAULT_KEYS (F_DEV | F_FLAGS | F_GID | F_GNAME | F_SLINK | F_MODE\ + | F_NLINK | F_SIZE | F_TIME | F_TYPE | F_UID\ + | F_UNAME) + +static struct attr_counter * new_attr_count(struct mtree_entry *, + struct attr_counter *); +static void free_attr_count(struct attr_counter **); +static int inc_attr_count(struct attr_counter **, struct attr_counter *, + struct attr_counter *, struct mtree_entry *); +static int collect_set_values(struct mtree_writer *, struct mtree_entry *); +static int get_keys(struct mtree_writer *, struct mtree_entry *); +static void sum_init(struct mtree_writer *); +static void sum_update(struct mtree_writer *, const void *, size_t); +static void sum_final(struct mtree_writer *, struct mtree_entry *); +static void sum_write(struct archive_string *, struct mtree_entry *); + +#define COMPUTE_CRC(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)] static const uint32_t crctab[] = { - 0x0, - 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, - 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, - 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, - 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, - 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, - 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, - 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, - 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, - 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, - 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, - 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, - 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, - 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, - 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, - 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, - 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, - 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, - 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, - 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, - 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, - 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, - 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, - 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, - 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, - 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, - 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, - 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, - 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, - 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, - 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, - 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, - 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, - 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, - 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 + 0x0, + 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, + 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, + 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, + 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, + 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, + 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, + 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, + 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, + 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, + 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, + 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, + 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, + 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, + 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, + 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, + 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, + 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, + 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, + 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, + 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, + 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, + 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, + 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, + 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, + 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, + 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, + 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, + 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, + 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, + 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, + 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, + 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, + 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, + 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, + 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, + 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, + 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, + 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, + 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, + 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, + 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, + 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, + 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, + 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, + 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, + 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 }; static int mtree_safe_char(char c) { - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) - return 1; - if (c >= '0' && c <= '9') - return 1; - if (c == 35 || c == 61 || c == 92) - return 0; /* #, = and \ are always quoted */ - - if (c >= 33 && c <= 47) /* !"$%&'()*+,-./ */ - return 1; - if (c >= 58 && c <= 64) /* :;<>?@ */ - return 1; - if (c >= 91 && c <= 96) /* []^_` */ - return 1; - if (c >= 123 && c <= 126) /* {|}~ */ - return 1; - return 0; + if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) + return 1; + if (c >= '0' && c <= '9') + return 1; + if (c == 35 || c == 61 || c == 92) + return 0; /* #, = and \ are always quoted */ + + if (c >= 33 && c <= 47) /* !"$%&'()*+,-./ */ + return 1; + if (c >= 58 && c <= 64) /* :;<>?@ */ + return 1; + if (c >= 91 && c <= 96) /* []^_` */ + return 1; + if (c >= 123 && c <= 126) /* {|}~ */ + return 1; + return 0; } static void mtree_quote(struct archive_string *s, const char *str) { - const char *start; - char buf[4]; - unsigned char c; - - for (start = str; *str != '\0'; ++str) { - if (mtree_safe_char(*str)) - continue; - if (start != str) - archive_strncat(s, start, str - start); - c = (unsigned char)*str; - buf[0] = '\\'; - buf[1] = (c / 64) + '0'; - buf[2] = (c / 8 % 8) + '0'; - buf[3] = (c % 8) + '0'; - archive_strncat(s, buf, 4); - start = str + 1; - } - - if (start != str) - archive_strncat(s, start, str - start); + const char *start; + char buf[4]; + unsigned char c; + + for (start = str; *str != '\0'; ++str) { + if (mtree_safe_char(*str)) + continue; + if (start != str) + archive_strncat(s, start, str - start); + c = (unsigned char)*str; + buf[0] = '\\'; + buf[1] = (c / 64) + '0'; + buf[2] = (c / 8 % 8) + '0'; + buf[3] = (c % 8) + '0'; + archive_strncat(s, buf, 4); + start = str + 1; + } + + if (start != str) + archive_strncat(s, start, str - start); } +/* + * Indent a line as mtree utility to be readable for people. + */ static void mtree_indent(struct mtree_writer *mtree) { - int i, fn; - const char *r, *s, *x; - - fn = 1; - s = r = mtree->ebuf.s; - x = NULL; - while (*r == ' ') - r++; - while ((r = strchr(r, ' ')) != NULL) { - if (fn) { - fn = 0; - archive_strncat(&mtree->buf, s, r - s); - if (r -s > INDENTNAMELEN) { - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - } else { - for (i = r -s; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - } - s = ++r; - x = NULL; - continue; - } - if (r - s <= MAXLINELEN - 3 - INDENTNAMELEN) - x = r++; - else { - if (x == NULL) - x = r; - archive_strncat(&mtree->buf, s, x - s); - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - s = r = ++x; - x = NULL; - } - } - if (x != NULL && strlen(s) > MAXLINELEN - 3 - INDENTNAMELEN) { - /* Last keyword is longer. */ - archive_strncat(&mtree->buf, s, x - s); - archive_strncat(&mtree->buf, " \\\n", 3); - for (i = 0; i < (INDENTNAMELEN + 1); i++) - archive_strappend_char(&mtree->buf, ' '); - s = ++x; - } - archive_strcat(&mtree->buf, s); - archive_string_empty(&mtree->ebuf); + int i, fn; + const char *r, *s, *x; + + fn = 1; + s = r = mtree->ebuf.s; + x = NULL; + while (*r == ' ') + r++; + while ((r = strchr(r, ' ')) != NULL) { + if (fn) { + fn = 0; + archive_strncat(&mtree->buf, s, r - s); + if (r -s > INDENTNAMELEN) { + archive_strncat(&mtree->buf, " \\\n", 3); + for (i = 0; i < (INDENTNAMELEN + 1); i++) + archive_strappend_char(&mtree->buf, ' '); + } else { + for (i = r -s; i < (INDENTNAMELEN + 1); i++) + archive_strappend_char(&mtree->buf, ' '); + } + s = ++r; + x = NULL; + continue; + } + if (r - s <= MAXLINELEN - 3 - INDENTNAMELEN) + x = r++; + else { + if (x == NULL) + x = r; + archive_strncat(&mtree->buf, s, x - s); + archive_strncat(&mtree->buf, " \\\n", 3); + for (i = 0; i < (INDENTNAMELEN + 1); i++) + archive_strappend_char(&mtree->buf, ' '); + s = r = ++x; + x = NULL; + } + } + if (x != NULL && strlen(s) > MAXLINELEN - 3 - INDENTNAMELEN) { + /* Last keyword is longer. */ + archive_strncat(&mtree->buf, s, x - s); + archive_strncat(&mtree->buf, " \\\n", 3); + for (i = 0; i < (INDENTNAMELEN + 1); i++) + archive_strappend_char(&mtree->buf, ' '); + s = ++x; + } + archive_strcat(&mtree->buf, s); + archive_string_empty(&mtree->ebuf); } #if !defined(_WIN32) || defined(__CYGWIN__) static size_t -dir_len(struct archive_entry *entry) +dir_len(struct mtree_entry *me) { - const char *path, *r; - - path = archive_entry_pathname(entry); - r = strrchr(path, '/'); - if (r == NULL) - return (0); - /* Include a separator size */ - return (r - path + 1); + const char *path, *r; + + path = me->pathname; + r = strrchr(path, '/'); + if (r == NULL) + return (0); + /* Include a separator size */ + return (r - path + 1); } #else /* _WIN32 && !__CYGWIN__ */ @@ -301,750 +374,1095 @@ dir_len(struct archive_entry *entry) * code. */ static size_t -dir_len(struct archive_entry *entry) +dir_len(struct mtree_entry *me) { - wchar_t wc; - const char *path; - const char *p, *rp; - size_t al, l, size; - - path = archive_entry_pathname(entry); - al = l = -1; - for (p = path; *p != '\0'; ++p) { - if (*p == '\\') - al = l = p - path; - else if (*p == '/') - al = p - path; - } - if (l == -1) - goto alen; - size = p - path; - rp = p = path; - while (*p != '\0') { - l = mbtowc(&wc, p, size); - if (l == -1) - goto alen; - if (l == 1 && (wc == L'/' || wc == L'\\')) - rp = p; - p += l; - size -= l; - } - return (rp - path + 1); + wchar_t wc; + const char *path; + const char *p, *rp; + size_t al, l, size; + + path = me->pathname; + al = l = -1; + for (p = path; *p != '\0'; ++p) { + if (*p == '\\') + al = l = p - path; + else if (*p == '/') + al = p - path; + } + if (l == -1) + goto alen; + size = p - path; + rp = p = path; + while (*p != '\0') { + l = mbtowc(&wc, p, size); + if (l == -1) + goto alen; + if (l == 1 && (wc == L'/' || wc == L'\\')) + rp = p; + p += l; + size -= l; + } + return (rp - path + 1); alen: - if (al == -1) - return (0); - return (al + 1); + if (al == -1) + return (0); + return (al + 1); } #endif /* _WIN32 && !__CYGWIN__ */ +/* + * Test if a parent directory of the current entry is changed. + */ static int -parent_dir_changed(struct archive_string *dir, struct archive_entry *entry) +parent_dir_changed(struct archive_string *dir, struct mtree_entry *me) { - const char *path; - size_t l; - - l = dir_len(entry); - path = archive_entry_pathname(entry); - if (archive_strlen(dir) > 0) { - if (l == 0) { - archive_string_empty(dir); - return (1); - } - if (strncmp(dir->s, path, l) == 0) - return (0); /* The parent directory is the same. */ - } else if (l == 0) - return (0); /* The parent directory is the same. */ - archive_strncpy(dir, path, l); - return (1); + const char *path; + size_t l; + + l = dir_len(me); + path = me->pathname; + if (archive_strlen(dir) > 0) { + if (l == 0) { + archive_string_empty(dir); + return (1); + } + if (strncmp(dir->s, path, l) == 0) + return (0); /* The parent directory is the same. */ + } else if (l == 0) + return (0); /* The parent directory is the same. */ + archive_strncpy(dir, path, l); + return (1); } /* - * Write /set keyword. It means set global datas. - * [directory-only mode] - * - It is only once to write /set keyword. It is using values of the - * first entry. - * [normal mode] - * - Write /set keyword. It is using values of the first entry whose - * filetype is a regular file. - * - When a parent directory of the entry whose filetype is the regular - * file is changed, check the global datas and write it again if its - * values are different from the entry's. + * Write /set keyword. + * Set most used value of uid,gid,mode and fflags, which are + * collected by collect_set_values() function. */ static void -set_global(struct mtree_writer *mtree, struct archive_entry *entry) +write_global(struct mtree_writer *mtree) { - struct archive_string setstr; - struct archive_string unsetstr; - const char *name; - int keys, oldkeys, effkeys; - mode_t set_type = 0; - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR: - case AE_IFBLK: case AE_IFIFO: - break; - case AE_IFDIR: - if (mtree->dironly) - set_type = AE_IFDIR; - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if (!mtree->dironly) - set_type = AE_IFREG; - break; - } - if (set_type == 0) - return; - if (mtree->set.processed && - !parent_dir_changed(&mtree->set.parent, entry)) - return; - /* At first, save a parent directory of the entry for following - * entries. */ - if (!mtree->set.processed && set_type == AE_IFREG) - parent_dir_changed(&mtree->set.parent, entry); - - archive_string_init(&setstr); - archive_string_init(&unsetstr); - keys = mtree->keys & (F_FLAGS | F_GID | F_GNAME | F_NLINK | F_MODE - | F_TYPE | F_UID | F_UNAME); - oldkeys = mtree->set.keys; - effkeys = keys; - if (mtree->set.processed) { - /* - * Check the global datas for whether it needs updating. - */ - effkeys &= ~F_TYPE; - if ((oldkeys & (F_UNAME | F_UID)) != 0 && - mtree->set.uid == archive_entry_uid(entry)) - effkeys &= ~(F_UNAME | F_UID); - if ((oldkeys & (F_GNAME | F_GID)) != 0 && - mtree->set.gid == archive_entry_gid(entry)) - effkeys &= ~(F_GNAME | F_GID); - if ((oldkeys & F_MODE) != 0 && - mtree->set.mode == (archive_entry_mode(entry) & 07777)) - effkeys &= ~F_MODE; - if ((oldkeys & F_FLAGS) != 0) { - unsigned long fflags_set; - unsigned long fflags_clear; - - archive_entry_fflags(entry, &fflags_set, &fflags_clear); - if (fflags_set == mtree->set.fflags_set && - fflags_clear == mtree->set.fflags_clear) - effkeys &= ~F_FLAGS; - } - } - if ((keys & effkeys & F_TYPE) != 0) { - mtree->set.type = set_type; - if (set_type == AE_IFDIR) - archive_strcat(&setstr, " type=dir"); - else - archive_strcat(&setstr, " type=file"); - } - if ((keys & effkeys & F_UNAME) != 0) { - if ((name = archive_entry_uname(entry)) != NULL) { - archive_strcat(&setstr, " uname="); - mtree_quote(&setstr, name); - } else if ((oldkeys & F_UNAME) != 0) - archive_strcat(&unsetstr, " uname"); - else - keys &= ~F_UNAME; - } - if ((keys & effkeys & F_UID) != 0) { - mtree->set.uid = archive_entry_uid(entry); - archive_string_sprintf(&setstr, " uid=%jd", - (intmax_t)mtree->set.uid); - } - if ((keys & effkeys & F_GNAME) != 0) { - if ((name = archive_entry_gname(entry)) != NULL) { - archive_strcat(&setstr, " gname="); - mtree_quote(&setstr, name); - } else if ((oldkeys & F_GNAME) != 0) - archive_strcat(&unsetstr, " gname"); - else - keys &= ~F_GNAME; - } - if ((keys & effkeys & F_GID) != 0) { - mtree->set.gid = archive_entry_gid(entry); - archive_string_sprintf(&setstr, " gid=%jd", - (intmax_t)mtree->set.gid); - } - if ((keys & effkeys & F_MODE) != 0) { - mtree->set.mode = archive_entry_mode(entry) & 07777; - archive_string_sprintf(&setstr, " mode=%o", mtree->set.mode); - } - if ((keys & effkeys & F_FLAGS) != 0) { - if ((name = archive_entry_fflags_text(entry)) != NULL) { - archive_strcat(&setstr, " flags="); - mtree_quote(&setstr, name); - archive_entry_fflags(entry, &mtree->set.fflags_set, - &mtree->set.fflags_clear); - } else if ((oldkeys & F_FLAGS) != 0) - archive_strcat(&unsetstr, " flags"); - else - keys &= ~F_FLAGS; - } - if (unsetstr.length > 0) - archive_string_sprintf(&mtree->buf, "/unset%s\n", unsetstr.s); - archive_string_free(&unsetstr); - if (setstr.length > 0) - archive_string_sprintf(&mtree->buf, "/set%s\n", setstr.s); - archive_string_free(&setstr); - mtree->set.keys = keys; - mtree->set.processed = 1; - /* On directory-only mode, it is only once to write /set keyword. */ - if (mtree->dironly) - mtree->set.output = 0; + struct archive_string setstr; + struct archive_string unsetstr; + const char *name; + int keys, oldkeys, effkeys; + struct attr_counter *ac; + + archive_string_init(&setstr); + archive_string_init(&unsetstr); + keys = mtree->keys & SET_KEYS; + oldkeys = mtree->set.keys; + effkeys = keys; + if (mtree->set.processed) { + /* + * Check if the global data needs updating. + */ + effkeys &= ~F_TYPE; + if (oldkeys & (F_UNAME | F_UID)) { + ac = mtree->set.uid_list; + do { + if (mtree->set.uid == ac->m_entry->uid) { + effkeys &= ~(F_UNAME | F_UID); + break; + } + if (ac->next != NULL && + ac->next->count == ac->count) + continue; + } while (0); + } + if (oldkeys & (F_GNAME | F_GID)) { + ac = mtree->set.gid_list; + do { + if (mtree->set.gid == ac->m_entry->gid) { + effkeys &= ~(F_GNAME | F_GID); + break; + } + if (ac->next != NULL && + ac->next->count == ac->count) + continue; + } while (0); + } + if (oldkeys & F_MODE) { + ac = mtree->set.mode_list; + do { + if (mtree->set.mode == ac->m_entry->mode) { + effkeys &= ~F_MODE; + break; + } + if (ac->next != NULL && + ac->next->count == ac->count) + continue; + } while (0); + } + if ((oldkeys & F_FLAGS) != 0) { + ac = mtree->set.flags_list; + do { + if (ac->m_entry->fflags_set == + mtree->set.fflags_set && + ac->m_entry->fflags_clear == + mtree->set.fflags_clear) { + effkeys &= ~F_FLAGS; + break; + } + if (ac->next != NULL && + ac->next->count == ac->count) + continue; + } while (0); + } + } + if ((keys & effkeys & F_TYPE) != 0) { + if (mtree->dironly) { + archive_strcat(&setstr, " type=dir"); + mtree->set.type = AE_IFDIR; + } else { + archive_strcat(&setstr, " type=file"); + mtree->set.type = AE_IFREG; + } + } + if ((keys & effkeys & F_UNAME) != 0) { + name = mtree->set.uid_list->m_entry->uname; + if (name != NULL) { + archive_strcat(&setstr, " uname="); + mtree_quote(&setstr, name); + } else { + keys &= ~F_UNAME; + if ((oldkeys & F_UNAME) != 0) + archive_strcat(&unsetstr, " uname"); + } + } + if ((keys & effkeys & F_UID) != 0) { + mtree->set.uid = mtree->set.uid_list->m_entry->uid; + archive_string_sprintf(&setstr, " uid=%jd", + (intmax_t)mtree->set.uid); + } + if ((keys & effkeys & F_GNAME) != 0) { + name = mtree->set.gid_list->m_entry->gname; + if (name != NULL) { + archive_strcat(&setstr, " gname="); + mtree_quote(&setstr, name); + } else { + keys &= ~F_GNAME; + if ((oldkeys & F_GNAME) != 0) + archive_strcat(&unsetstr, " gname"); + } + } + if ((keys & effkeys & F_GID) != 0) { + mtree->set.gid = mtree->set.gid_list->m_entry->gid; + archive_string_sprintf(&setstr, " gid=%jd", + (intmax_t)mtree->set.gid); + } + if ((keys & effkeys & F_MODE) != 0) { + mtree->set.mode = mtree->set.mode_list->m_entry->mode; + archive_string_sprintf(&setstr, " mode=%o", + (unsigned int)mtree->set.mode); + } + if ((keys & effkeys & F_FLAGS) != 0) { + name = mtree->set.flags_list->m_entry->fflags_text; + if (name != NULL) { + archive_strcat(&setstr, " flags="); + mtree_quote(&setstr, name); + mtree->set.fflags_set = + mtree->set.flags_list->m_entry->fflags_set; + mtree->set.fflags_clear = + mtree->set.flags_list->m_entry->fflags_clear; + } else { + keys &= ~F_FLAGS; + if ((oldkeys & F_FLAGS) != 0) + archive_strcat(&unsetstr, " flags"); + } + } + if (unsetstr.length > 0) + archive_string_sprintf(&mtree->buf, "/unset%s\n", unsetstr.s); + archive_string_free(&unsetstr); + if (setstr.length > 0) + archive_string_sprintf(&mtree->buf, "/set%s\n", setstr.s); + archive_string_free(&setstr); + mtree->set.keys = keys; + mtree->set.processed = 1; + + free_attr_count(&mtree->set.uid_list); + free_attr_count(&mtree->set.gid_list); + free_attr_count(&mtree->set.mode_list); + free_attr_count(&mtree->set.flags_list); +} + +static struct attr_counter * +new_attr_count(struct mtree_entry *me, struct attr_counter *prev) +{ + struct attr_counter *ac; + + ac = malloc(sizeof(*ac)); + if (ac != NULL) { + ac->prev = prev; + ac->next = NULL; + ac->count = 1; + ac->m_entry = me; + } + return (ac); +} + +static void +free_attr_count(struct attr_counter **top) +{ + struct attr_counter *ac, *tac; + + if (*top == NULL) + return; + ac = *top; + while (ac != NULL) { + tac = ac->next; + free(ac); + ac = tac; + } + *top = NULL; +} + +static int +inc_attr_count(struct attr_counter **top, struct attr_counter *ac, + struct attr_counter *last, struct mtree_entry *me) +{ + struct attr_counter *pac; + + if (ac != NULL) { + ac->count++; + if (*top == ac || ac->prev->count >= ac->count) + return (0); + for (pac = ac->prev; pac; pac = pac->prev) { + if (pac->count >= ac->count) + break; + } + ac->prev->next = ac->next; + if (ac->next != NULL) + ac->next->prev = ac->prev; + if (pac != NULL) { + ac->prev = pac; + ac->next = pac->next; + pac->next = ac; + if (ac->next != NULL) + ac->next->prev = ac; + } else { + ac->prev = NULL; + ac->next = *top; + *top = ac; + ac->next->prev = ac; + } + } else { + ac = new_attr_count(me, last); + if (ac == NULL) + return (-1); + last->next = ac; + } + return (0); } static int -get_keys(struct mtree_writer *mtree, struct archive_entry *entry) +collect_set_values(struct mtree_writer *mtree, struct mtree_entry *me) +{ + int keys = mtree->keys; + struct attr_counter *ac, *last; + + if (keys & (F_UNAME | F_UID)) { + if (mtree->set.uid_list == NULL) { + mtree->set.uid_list = new_attr_count(me, NULL); + if (mtree->set.uid_list == NULL) + return (-1); + } else { + last = NULL; + for (ac = mtree->set.uid_list; ac; ac = ac->next) { + if (ac->m_entry->uid == me->uid) + break; + last = ac; + } + if (inc_attr_count( + &mtree->set.uid_list, ac, last, me) < 0) + return (-1); + } + } + if (keys & (F_GNAME | F_GID)) { + if (mtree->set.gid_list == NULL) { + mtree->set.gid_list = new_attr_count(me, NULL); + if (mtree->set.gid_list == NULL) + return (-1); + } else { + last = NULL; + for (ac = mtree->set.gid_list; ac; ac = ac->next) { + if (ac->m_entry->gid == me->gid) + break; + last = ac; + } + if (inc_attr_count( + &mtree->set.gid_list, ac, last, me) < 0) + return (-1); + } + } + if (keys & F_MODE) { + if (mtree->set.mode_list == NULL) { + mtree->set.mode_list = new_attr_count(me, NULL); + if (mtree->set.mode_list == NULL) + return (-1); + } else { + last = NULL; + for (ac = mtree->set.mode_list; ac; ac = ac->next) { + if (ac->m_entry->mode == me->mode) + break; + last = ac; + } + if (inc_attr_count( + &mtree->set.mode_list, ac, last, me) < 0) + return (-1); + } + } + if (keys & F_FLAGS) { + if (mtree->set.flags_list == NULL) { + mtree->set.flags_list = new_attr_count(me, NULL); + if (mtree->set.flags_list == NULL) + return (-1); + } else { + last = NULL; + for (ac = mtree->set.flags_list; ac; ac = ac->next) { + if (ac->m_entry->fflags_set == me->fflags_set && + ac->m_entry->fflags_clear == me->fflags_clear) + break; + last = ac; + } + if (inc_attr_count( + &mtree->set.flags_list, ac, last, me) < 0) + return (-1); + } + } + + /* + * Save a entry. + */ + me->next = NULL; + *mtree->set.me_last = me; + mtree->set.me_last = &me->next; + return (0); +} + +static int +get_keys(struct mtree_writer *mtree, struct mtree_entry *me) +{ + int keys; + + keys = mtree->keys; + + /* + * If a keyword has been set by /set, we do not need to + * output it. + */ + if (mtree->set.keys == 0) + return (keys);/* /set is not used. */ + + if ((mtree->set.keys & (F_GNAME | F_GID)) != 0 && + mtree->set.gid == me->gid) + keys &= ~(F_GNAME | F_GID); + if ((mtree->set.keys & (F_UNAME | F_UID)) != 0 && + mtree->set.uid == me->uid) + keys &= ~(F_UNAME | F_UID); + if (mtree->set.keys & F_FLAGS) { + if (mtree->set.fflags_set == me->fflags_set && + mtree->set.fflags_clear == me->fflags_clear) + keys &= ~F_FLAGS; + } + if ((mtree->set.keys & F_MODE) != 0 && mtree->set.mode == me->mode) + keys &= ~F_MODE; + + switch (me->filetype) { + case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR: + case AE_IFBLK: case AE_IFIFO: + break; + case AE_IFDIR: + if ((mtree->set.keys & F_TYPE) != 0 && + mtree->set.type == AE_IFDIR) + keys &= ~F_TYPE; + break; + case AE_IFREG: + default: /* Handle unknown file types as regular files. */ + if ((mtree->set.keys & F_TYPE) != 0 && + mtree->set.type == AE_IFREG) + keys &= ~F_TYPE; + break; + } + + return (keys); +} + +static struct mtree_entry * +new_mtree_entry(struct archive_entry *entry) { - int keys; - - keys = mtree->keys; - if (mtree->set.keys == 0) - return (keys); - if ((mtree->set.keys & (F_GNAME | F_GID)) != 0 && - mtree->set.gid == archive_entry_gid(entry)) - keys &= ~(F_GNAME | F_GID); - if ((mtree->set.keys & (F_UNAME | F_UID)) != 0 && - mtree->set.uid == archive_entry_uid(entry)) - keys &= ~(F_UNAME | F_UID); - if (mtree->set.keys & F_FLAGS) { - unsigned long set, clear; - - archive_entry_fflags(entry, &set, &clear); - if (mtree->set.fflags_set == set && - mtree->set.fflags_clear == clear) - keys &= ~F_FLAGS; - } - if ((mtree->set.keys & F_MODE) != 0 && - mtree->set.mode == (archive_entry_mode(entry) & 07777)) - keys &= ~F_MODE; - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: case AE_IFSOCK: case AE_IFCHR: - case AE_IFBLK: case AE_IFIFO: - break; - case AE_IFDIR: - if ((mtree->set.keys & F_TYPE) != 0 && - mtree->set.type == AE_IFDIR) - keys &= ~F_TYPE; - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if ((mtree->set.keys & F_TYPE) != 0 && - mtree->set.type == AE_IFREG) - keys &= ~F_TYPE; - break; - } - - return (keys); + struct mtree_entry *me; + const char *s; + + me = calloc(1, sizeof(*me)); + if (me == NULL) + return (NULL); + me->pathname = strdup(archive_entry_pathname(entry)); + if ((s = archive_entry_symlink(entry)) != NULL) + me->symlink = strdup(s); + else + me->symlink = NULL; + me->nlink = archive_entry_nlink(entry); + me->filetype = archive_entry_filetype(entry); + me->mode = archive_entry_mode(entry) & 07777; + me->uid = archive_entry_uid(entry); + me->gid = archive_entry_gid(entry); + if ((s = archive_entry_uname(entry)) != NULL) + me->uname = strdup(s); + else + me->uname = NULL; + if ((s = archive_entry_gname(entry)) != NULL) + me->gname = strdup(s); + else + me->gname = NULL; + if ((s = archive_entry_fflags_text(entry)) != NULL) + me->fflags_text = strdup(s); + else + me->fflags_text = NULL; + archive_entry_fflags(entry, &me->fflags_set, &me->fflags_clear); + me->mtime = archive_entry_mtime(entry); + me->mtime_nsec = archive_entry_mtime_nsec(entry); + me->rdevmajor = archive_entry_rdevmajor(entry); + me->rdevminor = archive_entry_rdevminor(entry); + me->size = archive_entry_size(entry); + me->compute_sum = 0; + + return (me); +} + +static void +free_mtree_entry(struct mtree_entry *me) +{ + free(me->pathname); + free(me->symlink); + free(me->uname); + free(me->gname); + free(me->fflags_text); + free(me); } static int archive_write_mtree_header(struct archive_write *a, struct archive_entry *entry) { - struct mtree_writer *mtree= a->format_data; - struct archive_string *str; - const char *path; - - mtree->entry = archive_entry_clone(entry); - path = archive_entry_pathname(mtree->entry); - - if (mtree->first) { - mtree->first = 0; - archive_strcat(&mtree->buf, "#mtree\n"); - } - if (mtree->set.output) - set_global(mtree, entry); - - archive_string_empty(&mtree->ebuf); - str = (mtree->indent)? &mtree->ebuf : &mtree->buf; - if (!mtree->dironly || archive_entry_filetype(entry) == AE_IFDIR) - mtree_quote(str, path); - - mtree->entry_bytes_remaining = archive_entry_size(entry); - if ((mtree->keys & F_CKSUM) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_CKSUM; - mtree->crc = 0; - mtree->crc_len = 0; - } else - mtree->compute_sum &= ~F_CKSUM; + struct mtree_writer *mtree= a->format_data; + + if (mtree->first) { + mtree->first = 0; + archive_strcat(&mtree->buf, "#mtree\n"); + if ((mtree->keys & SET_KEYS) == 0) + mtree->set.output = 0;/* Disalbed. */ + } + + mtree->entry_bytes_remaining = archive_entry_size(entry); + if (mtree->dironly && archive_entry_filetype(entry) != AE_IFDIR) + return (ARCHIVE_OK); + + mtree->mtree_entry = new_mtree_entry(entry); + if (mtree->mtree_entry == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate mtree entry"); + return (ARCHIVE_FATAL); + } + + mtree->compute_sum = 0; + + /* If current file is not a regular file, we do not have to + * compute the sum of its content. */ + if (archive_entry_filetype(entry) != AE_IFREG) + return (ARCHIVE_OK); + + /* Initialize a bunch of sum check context. */ + sum_init(mtree); + + return (ARCHIVE_OK); +} + +static int +write_entry(struct archive_write *a, struct mtree_entry *me) +{ + struct mtree_writer *mtree = a->format_data; + struct archive_string *str; + int keys, ret; + + archive_string_empty(&mtree->ebuf); + str = (mtree->indent)? &mtree->ebuf : &mtree->buf; + mtree_quote(str, me->pathname); + keys = get_keys(mtree, me); + if ((keys & F_NLINK) != 0 && + me->nlink != 1 && me->filetype != AE_IFDIR) + archive_string_sprintf(str, " nlink=%u", me->nlink); + + if ((keys & F_GNAME) != 0 && me->gname != NULL) { + archive_strcat(str, " gname="); + mtree_quote(str, me->gname); + } + if ((keys & F_UNAME) != 0 && me->uname != NULL) { + archive_strcat(str, " uname="); + mtree_quote(str, me->uname); + } + if ((keys & F_FLAGS) != 0) { + if (me->fflags_text != NULL) { + archive_strcat(str, " flags="); + mtree_quote(str, me->fflags_text); + } else if (mtree->set.processed && + (mtree->set.keys & F_FLAGS) != 0) + /* Overwrite the global parameter. */ + archive_strcat(str, " flags=none"); + } + if ((keys & F_TIME) != 0) + archive_string_sprintf(str, " time=%jd.%jd", + (intmax_t)me->mtime, (intmax_t)me->mtime_nsec); + if ((keys & F_MODE) != 0) + archive_string_sprintf(str, " mode=%o", (unsigned int)me->mode); + if ((keys & F_GID) != 0) + archive_string_sprintf(str, " gid=%jd", (intmax_t)me->gid); + if ((keys & F_UID) != 0) + archive_string_sprintf(str, " uid=%jd", (intmax_t)me->uid); + + switch (me->filetype) { + case AE_IFLNK: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=link"); + if ((keys & F_SLINK) != 0) { + archive_strcat(str, " link="); + mtree_quote(str, me->symlink); + } + break; + case AE_IFSOCK: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=socket"); + break; + case AE_IFCHR: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=char"); + if ((keys & F_DEV) != 0) { + archive_string_sprintf(str, + " device=native,%ju,%ju", + (uintmax_t)me->rdevmajor, + (uintmax_t)me->rdevminor); + } + break; + case AE_IFBLK: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=block"); + if ((keys & F_DEV) != 0) { + archive_string_sprintf(str, + " device=native,%ju,%ju", + (uintmax_t)me->rdevmajor, + (uintmax_t)me->rdevminor); + } + break; + case AE_IFDIR: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=dir"); + break; + case AE_IFIFO: + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=fifo"); + break; + case AE_IFREG: + default: /* Handle unknown file types as regular files. */ + if ((keys & F_TYPE) != 0) + archive_strcat(str, " type=file"); + if ((keys & F_SIZE) != 0) + archive_string_sprintf(str, " size=%jd", + (intmax_t)me->size); + break; + } + + /* Write a bunch of sum. */ + if (me->filetype == AE_IFREG) + sum_write(str, me); + + archive_strcat(str, "\n"); + if (mtree->indent) + mtree_indent(mtree); + + if (mtree->buf.length > 32768) { + ret = __archive_write_output(a, mtree->buf.s, mtree->buf.length); + archive_string_empty(&mtree->buf); + } else + ret = ARCHIVE_OK; + return (ret); +} + +/* + * Write mtree entries saved at collect_set_values() function. + */ +static int +write_mtree_entries(struct archive_write *a) +{ + struct mtree_writer *mtree = a->format_data; + struct mtree_entry *me, *tme; + int ret; + + for (me = mtree->set.me_first; me; me = me->next) { + ret = write_entry(a, me); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + me = mtree->set.me_first; + while (me != NULL) { + tme = me->next; + free_mtree_entry(me); + me = tme; + } + mtree->set.me_first = NULL; + mtree->set.me_last = &mtree->set.me_first; + return (ARCHIVE_OK); +} + +static int +archive_write_mtree_finish_entry(struct archive_write *a) +{ + struct mtree_writer *mtree = a->format_data; + struct mtree_entry *me; + int ret; + + if ((me = mtree->mtree_entry) == NULL) + return (ARCHIVE_OK); + mtree->mtree_entry = NULL; + + if (me->filetype == AE_IFREG) + sum_final(mtree, me); + + if (mtree->set.output) { + if (!mtree->dironly) { + if (archive_strlen(&mtree->set.parent) == 0) + parent_dir_changed(&mtree->set.parent, me); + if (parent_dir_changed(&mtree->set.parent, me)) { + /* Write /set keyword */ + write_global(mtree); + /* Write entries saved by + * collect_set_values() function. */ + ret = write_mtree_entries(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + } + /* Tabulate uid,gid,mode and fflags of a entry + * in order to be used for /set. and, at this time + * we do not write a entry. */ + collect_set_values(mtree, me); + return (ARCHIVE_OK); + } else { + /* Write the current entry and free it. */ + ret = write_entry(a, me); + free_mtree_entry(me); + } + return (ret == ARCHIVE_OK ? ret : ARCHIVE_FATAL); +} + +static int +archive_write_mtree_close(struct archive_write *a) +{ + struct mtree_writer *mtree= a->format_data; + int ret; + + if (mtree->set.output && mtree->set.me_first != NULL) { + write_global(mtree); + ret = write_mtree_entries(a); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + archive_write_set_bytes_in_last_block(&a->archive, 1); + + return __archive_write_output(a, mtree->buf.s, mtree->buf.length); +} + +static ssize_t +archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) +{ + struct mtree_writer *mtree= a->format_data; + + if (n > mtree->entry_bytes_remaining) + n = mtree->entry_bytes_remaining; + mtree->entry_bytes_remaining -= n; + + /* We don't need to compute a regular file sum */ + if (mtree->mtree_entry == NULL) + return (n); + + if (mtree->mtree_entry->filetype == AE_IFREG) + sum_update(mtree, buff, n); + + return (n); +} + +static int +archive_write_mtree_free(struct archive_write *a) +{ + struct mtree_writer *mtree= a->format_data; + struct mtree_entry *me, *tme; + + if (mtree == NULL) + return (ARCHIVE_OK); + + /* Make sure we dot not leave any entries. */ + me = mtree->set.me_first; + while (me != NULL) { + tme = me->next; + free_mtree_entry(me); + me = tme; + } + archive_string_free(&mtree->ebuf); + archive_string_free(&mtree->buf); + archive_string_free(&mtree->set.parent); + free_attr_count(&mtree->set.uid_list); + free_attr_count(&mtree->set.gid_list); + free_attr_count(&mtree->set.mode_list); + free_attr_count(&mtree->set.flags_list); + free(mtree); + a->format_data = NULL; + return (ARCHIVE_OK); +} + +static int +archive_write_mtree_options(struct archive_write *a, const char *key, + const char *value) +{ + struct mtree_writer *mtree= a->format_data; + int keybit = 0; + + switch (key[0]) { + case 'a': + if (strcmp(key, "all") == 0) + keybit = ~0; + break; + case 'c': + if (strcmp(key, "cksum") == 0) + keybit = F_CKSUM; + break; + case 'd': + if (strcmp(key, "device") == 0) + keybit = F_DEV; + else if (strcmp(key, "dironly") == 0) { + mtree->dironly = (value != NULL)? 1: 0; + return (ARCHIVE_OK); + } + break; + case 'f': + if (strcmp(key, "flags") == 0) + keybit = F_FLAGS; + break; + case 'g': + if (strcmp(key, "gid") == 0) + keybit = F_GID; + else if (strcmp(key, "gname") == 0) + keybit = F_GNAME; + break; + case 'i': + if (strcmp(key, "indent") == 0) { + mtree->indent = (value != NULL)? 1: 0; + return (ARCHIVE_OK); + } + break; + case 'l': + if (strcmp(key, "link") == 0) + keybit = F_SLINK; + break; + case 'm': + if (strcmp(key, "md5") == 0 || + strcmp(key, "md5digest") == 0) + keybit = F_MD5; + if (strcmp(key, "mode") == 0) + keybit = F_MODE; + break; + case 'n': + if (strcmp(key, "nlink") == 0) + keybit = F_NLINK; + break; + case 'r': + if (strcmp(key, "ripemd160digest") == 0 || + strcmp(key, "rmd160") == 0 || + strcmp(key, "rmd160digest") == 0) + keybit = F_RMD160; + break; + case 's': + if (strcmp(key, "sha1") == 0 || + strcmp(key, "sha1digest") == 0) + keybit = F_SHA1; + if (strcmp(key, "sha256") == 0 || + strcmp(key, "sha256digest") == 0) + keybit = F_SHA256; + if (strcmp(key, "sha384") == 0 || + strcmp(key, "sha384digest") == 0) + keybit = F_SHA384; + if (strcmp(key, "sha512") == 0 || + strcmp(key, "sha512digest") == 0) + keybit = F_SHA512; + if (strcmp(key, "size") == 0) + keybit = F_SIZE; + break; + case 't': + if (strcmp(key, "time") == 0) + keybit = F_TIME; + else if (strcmp(key, "type") == 0) + keybit = F_TYPE; + break; + case 'u': + if (strcmp(key, "uid") == 0) + keybit = F_UID; + else if (strcmp(key, "uname") == 0) + keybit = F_UNAME; + else if (strcmp(key, "use-set") == 0) { + mtree->set.output = (value != NULL)? 1: 0; + return (ARCHIVE_OK); + } + break; + } + if (keybit != 0) { + if (value != NULL) + mtree->keys |= keybit; + else + mtree->keys &= ~keybit; + return (ARCHIVE_OK); + } + + return (ARCHIVE_FAILED); +} + +int +archive_write_set_format_mtree(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct mtree_writer *mtree; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_mtree"); + + if (a->format_free != NULL) + (a->format_free)(a); + + if ((mtree = calloc(1, sizeof(*mtree))) == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate mtree data"); + return (ARCHIVE_FATAL); + } + + mtree->mtree_entry = NULL; + mtree->first = 1; + memset(&(mtree->set), 0, sizeof(mtree->set)); + archive_string_init(&mtree->set.parent); + mtree->keys = DEFAULT_KEYS; + mtree->dironly = 0; + mtree->indent = 0; + archive_string_init(&mtree->ebuf); + archive_string_init(&mtree->buf); + mtree->set.me_first = NULL; + mtree->set.me_last = &mtree->set.me_first; + a->format_data = mtree; + a->format_free = archive_write_mtree_free; + a->format_name = "mtree"; + a->format_options = archive_write_mtree_options; + a->format_write_header = archive_write_mtree_header; + a->format_close = archive_write_mtree_close; + a->format_write_data = archive_write_mtree_data; + a->format_finish_entry = archive_write_mtree_finish_entry; + a->archive.archive_format = ARCHIVE_FORMAT_MTREE; + a->archive.archive_format_name = "mtree"; + + return (ARCHIVE_OK); +} + +static void +sum_init(struct mtree_writer *mtree) +{ + if (mtree->keys & F_CKSUM) { + mtree->compute_sum |= F_CKSUM; + mtree->crc = 0; + mtree->crc_len = 0; + } #ifdef ARCHIVE_HAS_MD5 - if ((mtree->keys & F_MD5) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_MD5; - archive_md5_init(&mtree->md5ctx); - } else - mtree->compute_sum &= ~F_MD5; + if (mtree->keys & F_MD5) { + if (archive_md5_init(&mtree->md5ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_MD5; + else + mtree->keys &= ~F_MD5;/* Not supported. */ + } #endif #ifdef ARCHIVE_HAS_RMD160 - if ((mtree->keys & F_RMD160) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_RMD160; - archive_rmd160_init(&mtree->rmd160ctx); - } else - mtree->compute_sum &= ~F_RMD160; + if (mtree->keys & F_RMD160) { + if (archive_rmd160_init(&mtree->rmd160ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_RMD160; + else + mtree->keys &= ~F_RMD160;/* Not supported. */ + } #endif #ifdef ARCHIVE_HAS_SHA1 - if ((mtree->keys & F_SHA1) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA1; - archive_sha1_init(&mtree->sha1ctx); - } else - mtree->compute_sum &= ~F_SHA1; + if (mtree->keys & F_SHA1) { + if (archive_sha1_init(&mtree->sha1ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_SHA1; + else + mtree->keys &= ~F_SHA1;/* Not supported. */ + } #endif #ifdef ARCHIVE_HAS_SHA256 - if ((mtree->keys & F_SHA256) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA256; - archive_sha256_init(&mtree->sha256ctx); - } else - mtree->compute_sum &= ~F_SHA256; + if (mtree->keys & F_SHA256) { + if (archive_sha256_init(&mtree->sha256ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_SHA256; + else + mtree->keys &= ~F_SHA256;/* Not supported. */ + } #endif #ifdef ARCHIVE_HAS_SHA384 - if ((mtree->keys & F_SHA384) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA384; - archive_sha384_init(&mtree->sha384ctx); - } else - mtree->compute_sum &= ~F_SHA384; + if (mtree->keys & F_SHA384) { + if (archive_sha384_init(&mtree->sha384ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_SHA384; + else + mtree->keys &= ~F_SHA384;/* Not supported. */ + } #endif #ifdef ARCHIVE_HAS_SHA512 - if ((mtree->keys & F_SHA512) != 0 && - archive_entry_filetype(entry) == AE_IFREG) { - mtree->compute_sum |= F_SHA512; - archive_sha512_init(&mtree->sha512ctx); - } else - mtree->compute_sum &= ~F_SHA512; + if (mtree->keys & F_SHA512) { + if (archive_sha512_init(&mtree->sha512ctx) == ARCHIVE_OK) + mtree->compute_sum |= F_SHA512; + else + mtree->keys &= ~F_SHA512;/* Not supported. */ + } #endif - - return (ARCHIVE_OK); } -#if defined(ARCHIVE_HAS_MD5) || defined(ARCHIVE_HAS_RMD160) || \ - defined(ARCHIVE_HAS_SHA1) || defined(ARCHIVE_HAS_SHA256) || \ - defined(ARCHIVE_HAS_SHA384) || defined(ARCHIVE_HAS_SHA512) static void -strappend_bin(struct archive_string *s, const unsigned char *bin, int n) -{ - static const char hex[] = "0123456789abcdef"; - int i; - - for (i = 0; i < n; i++) { - archive_strappend_char(s, hex[bin[i] >> 4]); - archive_strappend_char(s, hex[bin[i] & 0x0f]); - } -} -#endif - -static int -archive_write_mtree_finish_entry(struct archive_write *a) +sum_update(struct mtree_writer *mtree, const void *buff, size_t n) { - struct mtree_writer *mtree = a->format_data; - struct archive_entry *entry; - struct archive_string *str; - const char *name; - int keys, ret; - - entry = mtree->entry; - if (entry == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER, - "Finished entry without being open first."); - return (ARCHIVE_FATAL); - } - mtree->entry = NULL; - - if (mtree->dironly && archive_entry_filetype(entry) != AE_IFDIR) { - archive_entry_free(entry); - return (ARCHIVE_OK); - } - - str = (mtree->indent)? &mtree->ebuf : &mtree->buf; - keys = get_keys(mtree, entry); - if ((keys & F_NLINK) != 0 && - archive_entry_nlink(entry) != 1 && - archive_entry_filetype(entry) != AE_IFDIR) - archive_string_sprintf(str, - " nlink=%u", archive_entry_nlink(entry)); - - if ((keys & F_GNAME) != 0 && - (name = archive_entry_gname(entry)) != NULL) { - archive_strcat(str, " gname="); - mtree_quote(str, name); - } - if ((keys & F_UNAME) != 0 && - (name = archive_entry_uname(entry)) != NULL) { - archive_strcat(str, " uname="); - mtree_quote(str, name); - } - if ((keys & F_FLAGS) != 0 && - (name = archive_entry_fflags_text(entry)) != NULL) { - archive_strcat(str, " flags="); - mtree_quote(str, name); - } - if ((keys & F_TIME) != 0) - archive_string_sprintf(str, " time=%jd.%jd", - (intmax_t)archive_entry_mtime(entry), - (intmax_t)archive_entry_mtime_nsec(entry)); - if ((keys & F_MODE) != 0) - archive_string_sprintf(str, " mode=%o", - archive_entry_mode(entry) & 07777); - if ((keys & F_GID) != 0) - archive_string_sprintf(str, " gid=%jd", - (intmax_t)archive_entry_gid(entry)); - if ((keys & F_UID) != 0) - archive_string_sprintf(str, " uid=%jd", - (intmax_t)archive_entry_uid(entry)); - - switch (archive_entry_filetype(entry)) { - case AE_IFLNK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=link"); - if ((keys & F_SLINK) != 0) { - archive_strcat(str, " link="); - mtree_quote(str, archive_entry_symlink(entry)); - } - break; - case AE_IFSOCK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=socket"); - break; - case AE_IFCHR: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=char"); - if ((keys & F_DEV) != 0) { - archive_string_sprintf(str, - " device=native,%d,%d", - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - } - break; - case AE_IFBLK: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=block"); - if ((keys & F_DEV) != 0) { - archive_string_sprintf(str, - " device=native,%d,%d", - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - } - break; - case AE_IFDIR: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=dir"); - break; - case AE_IFIFO: - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=fifo"); - break; - case AE_IFREG: - default: /* Handle unknown file types as regular files. */ - if ((keys & F_TYPE) != 0) - archive_strcat(str, " type=file"); - if ((keys & F_SIZE) != 0) - archive_string_sprintf(str, " size=%jd", - (intmax_t)archive_entry_size(entry)); - break; - } - - if (mtree->compute_sum & F_CKSUM) { - uint64_t len; - /* Include the length of the file. */ - for (len = mtree->crc_len; len != 0; len >>= 8) - COMPUTE_CRC(mtree->crc, len & 0xff); - mtree->crc = ~mtree->crc; - archive_string_sprintf(str, " cksum=%ju", - (uintmax_t)mtree->crc); - } + if (mtree->compute_sum & F_CKSUM) { + /* + * Compute a POSIX 1003.2 checksum + */ + const unsigned char *p; + size_t nn; + + for (nn = n, p = buff; nn--; ++p) + COMPUTE_CRC(mtree->crc, *p); + mtree->crc_len += n; + } #ifdef ARCHIVE_HAS_MD5 - if (mtree->compute_sum & F_MD5) { - unsigned char buf[16]; - - archive_md5_final(&mtree->md5ctx, buf); - archive_strcat(str, " md5digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_MD5) + archive_md5_update(&mtree->md5ctx, buff, n); #endif #ifdef ARCHIVE_HAS_RMD160 - if (mtree->compute_sum & F_RMD160) { - unsigned char buf[20]; - - archive_rmd160_final(&mtree->rmd160ctx, buf); - archive_strcat(str, " rmd160digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_RMD160) + archive_rmd160_update(&mtree->rmd160ctx, buff, n); #endif #ifdef ARCHIVE_HAS_SHA1 - if (mtree->compute_sum & F_SHA1) { - unsigned char buf[20]; - - archive_sha1_final(&mtree->sha1ctx, buf); - archive_strcat(str, " sha1digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_SHA1) + archive_sha1_update(&mtree->sha1ctx, buff, n); #endif #ifdef ARCHIVE_HAS_SHA256 - if (mtree->compute_sum & F_SHA256) { - unsigned char buf[32]; - - archive_sha256_final(&mtree->sha256ctx, buf); - archive_strcat(str, " sha256digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_SHA256) + archive_sha256_update(&mtree->sha256ctx, buff, n); #endif #ifdef ARCHIVE_HAS_SHA384 - if (mtree->compute_sum & F_SHA384) { - unsigned char buf[48]; - - archive_sha384_final(&mtree->sha384ctx, buf); - archive_strcat(str, " sha384digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_SHA384) + archive_sha384_update(&mtree->sha384ctx, buff, n); #endif #ifdef ARCHIVE_HAS_SHA512 - if (mtree->compute_sum & F_SHA512) { - unsigned char buf[64]; - - archive_sha512_final(&mtree->sha512ctx, buf); - archive_strcat(str, " sha512digest="); - strappend_bin(str, buf, sizeof(buf)); - } + if (mtree->compute_sum & F_SHA512) + archive_sha512_update(&mtree->sha512ctx, buff, n); #endif - archive_strcat(str, "\n"); - if (mtree->indent) - mtree_indent(mtree); - - archive_entry_free(entry); - - if (mtree->buf.length > 32768) { - ret = (a->compressor.write)(a, mtree->buf.s, mtree->buf.length); - archive_string_empty(&mtree->buf); - } else - ret = ARCHIVE_OK; - - return (ret == ARCHIVE_OK ? ret : ARCHIVE_FATAL); } -static int -archive_write_mtree_finish(struct archive_write *a) +static void +sum_final(struct mtree_writer *mtree, struct mtree_entry *me) { - struct mtree_writer *mtree= a->format_data; - - archive_write_set_bytes_in_last_block(&a->archive, 1); - - return (a->compressor.write)(a, mtree->buf.s, mtree->buf.length); -} -static ssize_t -archive_write_mtree_data(struct archive_write *a, const void *buff, size_t n) -{ - struct mtree_writer *mtree= a->format_data; - - if (n > mtree->entry_bytes_remaining) - n = mtree->entry_bytes_remaining; - if (mtree->dironly) - /* We don't need compute a regular file sum */ - return (n); - if (mtree->compute_sum & F_CKSUM) { - /* - * Compute a POSIX 1003.2 checksum - */ - const unsigned char *p; - int nn; - - for (nn = n, p = buff; nn--; ++p) - COMPUTE_CRC(mtree->crc, *p); - mtree->crc_len += n; - } + if (mtree->compute_sum & F_CKSUM) { + uint64_t len; + /* Include the length of the file. */ + for (len = mtree->crc_len; len != 0; len >>= 8) + COMPUTE_CRC(mtree->crc, len & 0xff); + me->crc = ~mtree->crc; + } #ifdef ARCHIVE_HAS_MD5 - if (mtree->compute_sum & F_MD5) - archive_md5_update(&mtree->md5ctx, buff, n); + if (mtree->compute_sum & F_MD5) + archive_md5_final(&mtree->md5ctx, me->buf_md5); #endif #ifdef ARCHIVE_HAS_RMD160 - if (mtree->compute_sum & F_RMD160) - archive_rmd160_update(&mtree->rmd160ctx, buff, n); + if (mtree->compute_sum & F_RMD160) + archive_rmd160_final(&mtree->rmd160ctx, me->buf_rmd160); #endif #ifdef ARCHIVE_HAS_SHA1 - if (mtree->compute_sum & F_SHA1) - archive_sha1_update(&mtree->sha1ctx, buff, n); + if (mtree->compute_sum & F_SHA1) + archive_sha1_final(&mtree->sha1ctx, me->buf_sha1); #endif #ifdef ARCHIVE_HAS_SHA256 - if (mtree->compute_sum & F_SHA256) - archive_sha256_update(&mtree->sha256ctx, buff, n); + if (mtree->compute_sum & F_SHA256) + archive_sha256_final(&mtree->sha256ctx, me->buf_sha256); #endif #ifdef ARCHIVE_HAS_SHA384 - if (mtree->compute_sum & F_SHA384) - archive_sha384_update(&mtree->sha384ctx, buff, n); + if (mtree->compute_sum & F_SHA384) + archive_sha384_final(&mtree->sha384ctx, me->buf_sha384); #endif #ifdef ARCHIVE_HAS_SHA512 - if (mtree->compute_sum & F_SHA512) - archive_sha512_update(&mtree->sha512ctx, buff, n); + if (mtree->compute_sum & F_SHA512) + archive_sha512_final(&mtree->sha512ctx, me->buf_sha512); #endif - return (n); + /* Save what types of sum are computed. */ + me->compute_sum = mtree->compute_sum; } -static int -archive_write_mtree_destroy(struct archive_write *a) +#if defined(ARCHIVE_HAS_MD5) || defined(ARCHIVE_HAS_RMD160) || \ + defined(ARCHIVE_HAS_SHA1) || defined(ARCHIVE_HAS_SHA256) || \ + defined(ARCHIVE_HAS_SHA384) || defined(ARCHIVE_HAS_SHA512) +static void +strappend_bin(struct archive_string *s, const unsigned char *bin, int n) { - struct mtree_writer *mtree= a->format_data; - - if (mtree == NULL) - return (ARCHIVE_OK); - - archive_entry_free(mtree->entry); - archive_string_free(&mtree->ebuf); - archive_string_free(&mtree->buf); - archive_string_free(&mtree->set.parent); - free(mtree); - a->format_data = NULL; - return (ARCHIVE_OK); -} + static const char hex[] = "0123456789abcdef"; + int i; -static int -archive_write_mtree_options(struct archive_write *a, const char *key, - const char *value) -{ - struct mtree_writer *mtree= a->format_data; - int keybit = 0; - - switch (key[0]) { - case 'a': - if (strcmp(key, "all") == 0) - keybit = ~0; - break; - case 'c': - if (strcmp(key, "cksum") == 0) - keybit = F_CKSUM; - break; - case 'd': - if (strcmp(key, "device") == 0) - keybit = F_DEV; - else if (strcmp(key, "dironly") == 0) { - mtree->dironly = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - case 'f': - if (strcmp(key, "flags") == 0) - keybit = F_FLAGS; - break; - case 'g': - if (strcmp(key, "gid") == 0) - keybit = F_GID; - else if (strcmp(key, "gname") == 0) - keybit = F_GNAME; - break; - case 'i': - if (strcmp(key, "indent") == 0) { - mtree->indent = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - case 'l': - if (strcmp(key, "link") == 0) - keybit = F_SLINK; - break; - case 'm': - if (strcmp(key, "md5") == 0 || - strcmp(key, "md5digest") == 0) - keybit = F_MD5; - if (strcmp(key, "mode") == 0) - keybit = F_MODE; - break; - case 'n': - if (strcmp(key, "nlink") == 0) - keybit = F_NLINK; - break; - case 'r': - if (strcmp(key, "ripemd160digest") == 0 || - strcmp(key, "rmd160") == 0 || - strcmp(key, "rmd160digest") == 0) - keybit = F_RMD160; - break; - case 's': - if (strcmp(key, "sha1") == 0 || - strcmp(key, "sha1digest") == 0) - keybit = F_SHA1; - if (strcmp(key, "sha256") == 0 || - strcmp(key, "sha256digest") == 0) - keybit = F_SHA256; - if (strcmp(key, "sha384") == 0 || - strcmp(key, "sha384digest") == 0) - keybit = F_SHA384; - if (strcmp(key, "sha512") == 0 || - strcmp(key, "sha512digest") == 0) - keybit = F_SHA512; - if (strcmp(key, "size") == 0) - keybit = F_SIZE; - break; - case 't': - if (strcmp(key, "time") == 0) - keybit = F_TIME; - else if (strcmp(key, "type") == 0) - keybit = F_TYPE; - break; - case 'u': - if (strcmp(key, "uid") == 0) - keybit = F_UID; - else if (strcmp(key, "uname") == 0) - keybit = F_UNAME; - else if (strcmp(key, "use-set") == 0) { - mtree->set.output = (value != NULL)? 1: 0; - return (ARCHIVE_OK); - } - break; - } - if (keybit != 0) { - if (value != NULL) - mtree->keys |= keybit; - else - mtree->keys &= ~keybit; - return (ARCHIVE_OK); - } - - return (ARCHIVE_WARN); + for (i = 0; i < n; i++) { + archive_strappend_char(s, hex[bin[i] >> 4]); + archive_strappend_char(s, hex[bin[i] & 0x0f]); + } } +#endif -int -archive_write_set_format_mtree(struct archive *_a) +static void +sum_write(struct archive_string *str, struct mtree_entry *me) { - struct archive_write *a = (struct archive_write *)_a; - struct mtree_writer *mtree; - - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - if ((mtree = malloc(sizeof(*mtree))) == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate mtree data"); - return (ARCHIVE_FATAL); - } - - mtree->entry = NULL; - mtree->first = 1; - memset(&(mtree->set), 0, sizeof(mtree->set)); - archive_string_init(&mtree->set.parent); - mtree->keys = DEFAULT_KEYS; - mtree->dironly = 0; - mtree->indent = 0; - archive_string_init(&mtree->ebuf); - archive_string_init(&mtree->buf); - a->format_data = mtree; - a->format_destroy = archive_write_mtree_destroy; - - a->pad_uncompressed = 0; - a->format_name = "mtree"; - a->format_options = archive_write_mtree_options; - a->format_write_header = archive_write_mtree_header; - a->format_finish = archive_write_mtree_finish; - a->format_write_data = archive_write_mtree_data; - a->format_finish_entry = archive_write_mtree_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_MTREE; - a->archive.archive_format_name = "mtree"; - - return (ARCHIVE_OK); + + if (me->compute_sum & F_CKSUM) { + archive_string_sprintf(str, " cksum=%ju", + (uintmax_t)me->crc); + } +#ifdef ARCHIVE_HAS_MD5 + if (me->compute_sum & F_MD5) { + archive_strcat(str, " md5digest="); + strappend_bin(str, me->buf_md5, sizeof(me->buf_md5)); + } +#endif +#ifdef ARCHIVE_HAS_RMD160 + if (me->compute_sum & F_RMD160) { + archive_strcat(str, " rmd160digest="); + strappend_bin(str, me->buf_rmd160, sizeof(me->buf_rmd160)); + } +#endif +#ifdef ARCHIVE_HAS_SHA1 + if (me->compute_sum & F_SHA1) { + archive_strcat(str, " sha1digest="); + strappend_bin(str, me->buf_sha1, sizeof(me->buf_sha1)); + } +#endif +#ifdef ARCHIVE_HAS_SHA256 + if (me->compute_sum & F_SHA256) { + archive_strcat(str, " sha256digest="); + strappend_bin(str, me->buf_sha256, sizeof(me->buf_sha256)); + } +#endif +#ifdef ARCHIVE_HAS_SHA384 + if (me->compute_sum & F_SHA384) { + archive_strcat(str, " sha384digest="); + strappend_bin(str, me->buf_sha384, sizeof(me->buf_sha384)); + } +#endif +#ifdef ARCHIVE_HAS_SHA512 + if (me->compute_sum & F_SHA512) { + archive_strcat(str, " sha512digest="); + strappend_bin(str, me->buf_sha512, sizeof(me->buf_sha512)); + } +#endif } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c index ecd7871ad..8affb2c15 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_pax.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2010-2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_pax.c,v 1.49 2008/09/30 03:57:07 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_pax.c 201162 2009-12-29 05:47:46Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -38,39 +39,56 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_pax.c,v 1.49 200 #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_write_private.h" +struct sparse_block { + struct sparse_block *next; + int is_hole; + uint64_t offset; + uint64_t remaining; +}; + struct pax { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; - struct archive_string pax_header; + uint64_t entry_bytes_remaining; + uint64_t entry_padding; + struct archive_string l_url_encoded_name; + struct archive_string pax_header; + struct archive_string sparse_map; + size_t sparse_map_padding; + struct sparse_block *sparse_list; + struct sparse_block *sparse_tail; + struct archive_string_conv *sconv_utf8; + int opt_binary; }; -static void add_pax_attr(struct archive_string *, const char *key, - const char *value); -static void add_pax_attr_int(struct archive_string *, - const char *key, int64_t value); -static void add_pax_attr_time(struct archive_string *, - const char *key, int64_t sec, - unsigned long nanos); -static void add_pax_attr_w(struct archive_string *, - const char *key, const wchar_t *wvalue); -static ssize_t archive_write_pax_data(struct archive_write *, - const void *, size_t); -static int archive_write_pax_finish(struct archive_write *); -static int archive_write_pax_destroy(struct archive_write *); -static int archive_write_pax_finish_entry(struct archive_write *); -static int archive_write_pax_header(struct archive_write *, - struct archive_entry *); -static char *base64_encode(const char *src, size_t len); -static char *build_pax_attribute_name(char *dest, const char *src); -static char *build_ustar_entry_name(char *dest, const char *src, - size_t src_length, const char *insert); -static char *format_int(char *dest, int64_t); -static int has_non_ASCII(const wchar_t *); -static char *url_encode(const char *in); -static int write_nulls(struct archive_write *, size_t); +static void add_pax_attr(struct archive_string *, const char *key, + const char *value); +static void add_pax_attr_int(struct archive_string *, + const char *key, int64_t value); +static void add_pax_attr_time(struct archive_string *, + const char *key, int64_t sec, + unsigned long nanos); +static ssize_t archive_write_pax_data(struct archive_write *, + const void *, size_t); +static int archive_write_pax_close(struct archive_write *); +static int archive_write_pax_free(struct archive_write *); +static int archive_write_pax_finish_entry(struct archive_write *); +static int archive_write_pax_header(struct archive_write *, + struct archive_entry *); +static int archive_write_pax_options(struct archive_write *, + const char *, const char *); +static char *base64_encode(const char *src, size_t len); +static char *build_gnu_sparse_name(char *dest, const char *src); +static char *build_pax_attribute_name(char *dest, const char *src); +static char *build_ustar_entry_name(char *dest, const char *src, + size_t src_length, const char *insert); +static char *format_int(char *dest, int64_t); +static int has_non_ASCII(const char *); +static void sparse_list_clear(struct pax *); +static int sparse_list_add(struct pax *, int64_t, int64_t); +static char *url_encode(const char *in); /* * Set output format to 'restricted pax' format. @@ -82,12 +100,16 @@ static int write_nulls(struct archive_write *, size_t); int archive_write_set_format_pax_restricted(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - int r; - r = archive_write_set_format_pax(&a->archive); - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; - a->archive.archive_format_name = "restricted POSIX pax interchange"; - return (r); + struct archive_write *a = (struct archive_write *)_a; + int r; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_pax_restricted"); + + r = archive_write_set_format_pax(&a->archive); + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; + a->archive.archive_format_name = "restricted POSIX pax interchange"; + return (r); } /* @@ -96,30 +118,80 @@ archive_write_set_format_pax_restricted(struct archive *_a) int archive_write_set_format_pax(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct pax *pax; - - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - pax = (struct pax *)malloc(sizeof(*pax)); - if (pax == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate pax data"); - return (ARCHIVE_FATAL); - } - memset(pax, 0, sizeof(*pax)); - a->format_data = pax; - - a->pad_uncompressed = 1; - a->format_name = "pax"; - a->format_write_header = archive_write_pax_header; - a->format_write_data = archive_write_pax_data; - a->format_finish = archive_write_pax_finish; - a->format_destroy = archive_write_pax_destroy; - a->format_finish_entry = archive_write_pax_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; - a->archive.archive_format_name = "POSIX pax interchange"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct pax *pax; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_pax"); + + if (a->format_free != NULL) + (a->format_free)(a); + + pax = (struct pax *)malloc(sizeof(*pax)); + if (pax == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate pax data"); + return (ARCHIVE_FATAL); + } + memset(pax, 0, sizeof(*pax)); + a->format_data = pax; + a->format_name = "pax"; + a->format_options = archive_write_pax_options; + a->format_write_header = archive_write_pax_header; + a->format_write_data = archive_write_pax_data; + a->format_close = archive_write_pax_close; + a->format_free = archive_write_pax_free; + a->format_finish_entry = archive_write_pax_finish_entry; + a->archive.archive_format = ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE; + a->archive.archive_format_name = "POSIX pax interchange"; + return (ARCHIVE_OK); +} + +static int +archive_write_pax_options(struct archive_write *a, const char *key, + const char *val) +{ + struct pax *pax = (struct pax *)a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "hdrcharset") == 0) { + /* + * The character-set we can use are defined in + * IEEE Std 1003.1-2001 + */ + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "pax: hdrcharset option needs a character-set name"); + else if (strcmp(val, "BINARY") == 0 || + strcmp(val, "binary") == 0) { + /* + * Specify binary mode. We will not convert + * filenames, uname and gname to any charsets. + */ + pax->opt_binary = 1; + ret = ARCHIVE_OK; + } else if (strcmp(val, "UTF-8") == 0) { + /* + * Specify UTF-8 character-set to be used for + * filenames. This is almost the test that + * running platform supports the string conversion. + * Especially libarchive_test needs this trick for + * its test. + */ + pax->sconv_utf8 = archive_string_conversion_to_charset( + &(a->archive), "UTF-8", 0); + if (pax->sconv_utf8 == NULL) + ret = ARCHIVE_FATAL; + else + ret = ARCHIVE_OK; + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "pax: invalid charset name"); + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "pax: unknown keyword ``%s''", key); + + return (ret); } /* @@ -133,164 +205,63 @@ static void add_pax_attr_time(struct archive_string *as, const char *key, int64_t sec, unsigned long nanos) { - int digit, i; - char *t; - /* - * Note that each byte contributes fewer than 3 base-10 - * digits, so this will always be big enough. - */ - char tmp[1 + 3*sizeof(sec) + 1 + 3*sizeof(nanos)]; - - tmp[sizeof(tmp) - 1] = 0; - t = tmp + sizeof(tmp) - 1; - - /* Skip trailing zeros in the fractional part. */ - for (digit = 0, i = 10; i > 0 && digit == 0; i--) { - digit = nanos % 10; - nanos /= 10; - } - - /* Only format the fraction if it's non-zero. */ - if (i > 0) { - while (i > 0) { - *--t = "0123456789"[digit]; - digit = nanos % 10; - nanos /= 10; - i--; - } - *--t = '.'; - } - t = format_int(t, sec); - - add_pax_attr(as, key, t); + int digit, i; + char *t; + /* + * Note that each byte contributes fewer than 3 base-10 + * digits, so this will always be big enough. + */ + char tmp[1 + 3*sizeof(sec) + 1 + 3*sizeof(nanos)]; + + tmp[sizeof(tmp) - 1] = 0; + t = tmp + sizeof(tmp) - 1; + + /* Skip trailing zeros in the fractional part. */ + for (digit = 0, i = 10; i > 0 && digit == 0; i--) { + digit = nanos % 10; + nanos /= 10; + } + + /* Only format the fraction if it's non-zero. */ + if (i > 0) { + while (i > 0) { + *--t = "0123456789"[digit]; + digit = nanos % 10; + nanos /= 10; + i--; + } + *--t = '.'; + } + t = format_int(t, sec); + + add_pax_attr(as, key, t); } static char * format_int(char *t, int64_t i) { - int sign; - - if (i < 0) { - sign = -1; - i = -i; - } else - sign = 1; - - do { - *--t = "0123456789"[i % 10]; - } while (i /= 10); - if (sign < 0) - *--t = '-'; - return (t); + uint64_t ui; + + if (i < 0) + ui = (i == INT64_MIN) ? (uint64_t)(INT64_MAX) + 1 : (uint64_t)(-i); + else + ui = i; + + do { + *--t = "0123456789"[ui % 10]; + } while (ui /= 10); + if (i < 0) + *--t = '-'; + return (t); } static void add_pax_attr_int(struct archive_string *as, const char *key, int64_t value) { - char tmp[1 + 3 * sizeof(value)]; + char tmp[1 + 3 * sizeof(value)]; - tmp[sizeof(tmp) - 1] = 0; - add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value)); -} - -static char * -utf8_encode(const wchar_t *wval) -{ - int utf8len; - const wchar_t *wp; - unsigned long wc; - char *utf8_value, *p; - - utf8len = 0; - for (wp = wval; *wp != L'\0'; ) { - wc = *wp++; - - if (wc >= 0xd800 && wc <= 0xdbff - && *wp >= 0xdc00 && *wp <= 0xdfff) { - /* This is a surrogate pair. Combine into a - * full Unicode value before encoding into - * UTF-8. */ - wc = (wc - 0xd800) << 10; /* High 10 bits */ - wc += (*wp++ - 0xdc00); /* Low 10 bits */ - wc += 0x10000; /* Skip BMP */ - } - if (wc <= 0x7f) - utf8len++; - else if (wc <= 0x7ff) - utf8len += 2; - else if (wc <= 0xffff) - utf8len += 3; - else if (wc <= 0x1fffff) - utf8len += 4; - else if (wc <= 0x3ffffff) - utf8len += 5; - else if (wc <= 0x7fffffff) - utf8len += 6; - /* Ignore larger values; UTF-8 can't encode them. */ - } - - utf8_value = (char *)malloc(utf8len + 1); - if (utf8_value == NULL) { - __archive_errx(1, "Not enough memory for attributes"); - return (NULL); - } - - for (wp = wval, p = utf8_value; *wp != L'\0'; ) { - wc = *wp++; - if (wc >= 0xd800 && wc <= 0xdbff - && *wp >= 0xdc00 && *wp <= 0xdfff) { - /* Combine surrogate pair. */ - wc = (wc - 0xd800) << 10; - wc += *wp++ - 0xdc00 + 0x10000; - } - if (wc <= 0x7f) { - *p++ = (char)wc; - } else if (wc <= 0x7ff) { - p[0] = 0xc0 | ((wc >> 6) & 0x1f); - p[1] = 0x80 | (wc & 0x3f); - p += 2; - } else if (wc <= 0xffff) { - p[0] = 0xe0 | ((wc >> 12) & 0x0f); - p[1] = 0x80 | ((wc >> 6) & 0x3f); - p[2] = 0x80 | (wc & 0x3f); - p += 3; - } else if (wc <= 0x1fffff) { - p[0] = 0xf0 | ((wc >> 18) & 0x07); - p[1] = 0x80 | ((wc >> 12) & 0x3f); - p[2] = 0x80 | ((wc >> 6) & 0x3f); - p[3] = 0x80 | (wc & 0x3f); - p += 4; - } else if (wc <= 0x3ffffff) { - p[0] = 0xf8 | ((wc >> 24) & 0x03); - p[1] = 0x80 | ((wc >> 18) & 0x3f); - p[2] = 0x80 | ((wc >> 12) & 0x3f); - p[3] = 0x80 | ((wc >> 6) & 0x3f); - p[4] = 0x80 | (wc & 0x3f); - p += 5; - } else if (wc <= 0x7fffffff) { - p[0] = 0xfc | ((wc >> 30) & 0x01); - p[1] = 0x80 | ((wc >> 24) & 0x3f); - p[1] = 0x80 | ((wc >> 18) & 0x3f); - p[2] = 0x80 | ((wc >> 12) & 0x3f); - p[3] = 0x80 | ((wc >> 6) & 0x3f); - p[4] = 0x80 | (wc & 0x3f); - p += 6; - } - /* Ignore larger values; UTF-8 can't encode them. */ - } - *p = '\0'; - - return (utf8_value); -} - -static void -add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) -{ - char *utf8_value = utf8_encode(wval); - if (utf8_value == NULL) - return; - add_pax_attr(as, key, utf8_value); - free(utf8_value); + tmp[sizeof(tmp) - 1] = 0; + add_pax_attr(as, key, format_int(tmp + sizeof(tmp) - 1, value)); } /* @@ -300,93 +271,182 @@ add_pax_attr_w(struct archive_string *as, const char *key, const wchar_t *wval) static void add_pax_attr(struct archive_string *as, const char *key, const char *value) { - int digits, i, len, next_ten; - char tmp[1 + 3 * sizeof(int)]; /* < 3 base-10 digits per byte */ - - /*- - * PAX attributes have the following layout: - * <=> - */ - len = 1 + strlen(key) + 1 + strlen(value) + 1; - - /* - * The field includes the length of the field, so - * computing the correct length is tricky. I start by - * counting the number of base-10 digits in 'len' and - * computing the next higher power of 10. - */ - next_ten = 1; - digits = 0; - i = len; - while (i > 0) { - i = i / 10; - digits++; - next_ten = next_ten * 10; - } - /* - * For example, if string without the length field is 99 - * chars, then adding the 2 digit length "99" will force the - * total length past 100, requiring an extra digit. The next - * statement adjusts for this effect. - */ - if (len + digits >= next_ten) - digits++; - - /* Now, we have the right length so we can build the line. */ - tmp[sizeof(tmp) - 1] = 0; /* Null-terminate the work area. */ - archive_strcat(as, format_int(tmp + sizeof(tmp) - 1, len + digits)); - archive_strappend_char(as, ' '); - archive_strcat(as, key); - archive_strappend_char(as, '='); - archive_strcat(as, value); - archive_strappend_char(as, '\n'); + int digits, i, len, next_ten; + char tmp[1 + 3 * sizeof(int)]; /* < 3 base-10 digits per byte */ + + /*- + * PAX attributes have the following layout: + * <=> + */ + len = 1 + (int)strlen(key) + 1 + (int)strlen(value) + 1; + + /* + * The field includes the length of the field, so + * computing the correct length is tricky. I start by + * counting the number of base-10 digits in 'len' and + * computing the next higher power of 10. + */ + next_ten = 1; + digits = 0; + i = len; + while (i > 0) { + i = i / 10; + digits++; + next_ten = next_ten * 10; + } + /* + * For example, if string without the length field is 99 + * chars, then adding the 2 digit length "99" will force the + * total length past 100, requiring an extra digit. The next + * statement adjusts for this effect. + */ + if (len + digits >= next_ten) + digits++; + + /* Now, we have the right length so we can build the line. */ + tmp[sizeof(tmp) - 1] = 0; /* Null-terminate the work area. */ + archive_strcat(as, format_int(tmp + sizeof(tmp) - 1, len + digits)); + archive_strappend_char(as, ' '); + archive_strcat(as, key); + archive_strappend_char(as, '='); + archive_strcat(as, value); + archive_strappend_char(as, '\n'); } -static void -archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry) +static int +archive_write_pax_header_xattrs(struct archive_write *a, + struct pax *pax, struct archive_entry *entry) +{ + struct archive_string s; + int i = archive_entry_xattr_reset(entry); + + while (i--) { + const char *name; + const void *value; + char *encoded_value; + char *url_encoded_name = NULL, *encoded_name = NULL; + size_t size; + int r; + + archive_entry_xattr_next(entry, &name, &value, &size); + url_encoded_name = url_encode(name); + if (url_encoded_name != NULL) { + /* Convert narrow-character to UTF-8. */ + r = archive_strcpy_in_locale( + &(pax->l_url_encoded_name), + url_encoded_name, pax->sconv_utf8); + free(url_encoded_name); /* Done with this. */ + if (r == 0) + encoded_name = pax->l_url_encoded_name.s; + else if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + } + + encoded_value = base64_encode((const char *)value, size); + + if (encoded_name != NULL && encoded_value != NULL) { + archive_string_init(&s); + archive_strcpy(&s, "LIBARCHIVE.xattr."); + archive_strcat(&s, encoded_name); + add_pax_attr(&(pax->pax_header), s.s, encoded_value); + archive_string_free(&s); + } + free(encoded_value); + } + return (ARCHIVE_OK); +} + +static int +get_entry_hardlink(struct archive_write *a, struct archive_entry *entry, + const char **name, size_t *length, struct archive_string_conv *sc) +{ + int r; + + r = archive_entry_hardlink_l(entry, name, length, sc); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +get_entry_pathname(struct archive_write *a, struct archive_entry *entry, + const char **name, size_t *length, struct archive_string_conv *sc) +{ + int r; + + r = archive_entry_pathname_l(entry, name, length, sc); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +get_entry_uname(struct archive_write *a, struct archive_entry *entry, + const char **name, size_t *length, struct archive_string_conv *sc) +{ + int r; + + r = archive_entry_uname_l(entry, name, length, sc); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +get_entry_gname(struct archive_write *a, struct archive_entry *entry, + const char **name, size_t *length, struct archive_string_conv *sc) { - struct archive_string s; - int i = archive_entry_xattr_reset(entry); - - while (i--) { - const char *name; - const void *value; - char *encoded_value; - char *url_encoded_name = NULL, *encoded_name = NULL; - wchar_t *wcs_name = NULL; - size_t size; - - archive_entry_xattr_next(entry, &name, &value, &size); - /* Name is URL-encoded, then converted to wchar_t, - * then UTF-8 encoded. */ - url_encoded_name = url_encode(name); - if (url_encoded_name != NULL) { - /* Convert narrow-character to wide-character. */ - int wcs_length = strlen(url_encoded_name); - wcs_name = (wchar_t *)malloc((wcs_length + 1) * sizeof(wchar_t)); - if (wcs_name == NULL) - __archive_errx(1, "No memory for xattr conversion"); - mbstowcs(wcs_name, url_encoded_name, wcs_length); - wcs_name[wcs_length] = 0; - free(url_encoded_name); /* Done with this. */ - } - if (wcs_name != NULL) { - encoded_name = utf8_encode(wcs_name); - free(wcs_name); /* Done with wchar_t name. */ - } - - encoded_value = base64_encode((const char *)value, size); - - if (encoded_name != NULL && encoded_value != NULL) { - archive_string_init(&s); - archive_strcpy(&s, "LIBARCHIVE.xattr."); - archive_strcat(&s, encoded_name); - add_pax_attr(&(pax->pax_header), s.s, encoded_value); - archive_string_free(&s); - } - free(encoded_name); - free(encoded_value); - } + int r; + + r = archive_entry_gname_l(entry, name, length, sc); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); +} + +static int +get_entry_symlink(struct archive_write *a, struct archive_entry *entry, + const char **name, size_t *length, struct archive_string_conv *sc) +{ + int r; + + r = archive_entry_symlink_l(entry, name, length, sc); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_WARN); + } + return (ARCHIVE_OK); } /* @@ -394,596 +454,843 @@ archive_write_pax_header_xattrs(struct pax *pax, struct archive_entry *entry) * archive_entry so that clients can specify them. Also, consider * adding generic key/value tags so clients can add arbitrary * key/value data. + * + * TODO: Break up this 700-line function!!!! Yowza! */ static int archive_write_pax_header(struct archive_write *a, struct archive_entry *entry_original) { - struct archive_entry *entry_main; - const char *p; - char *t; - const wchar_t *wp; - const char *suffix; - int need_extension, r, ret; - struct pax *pax; - const char *hdrcharset = NULL; - const char *hardlink; - const char *path = NULL, *linkpath = NULL; - const char *uname = NULL, *gname = NULL; - const wchar_t *path_w = NULL, *linkpath_w = NULL; - const wchar_t *uname_w = NULL, *gname_w = NULL; - - char paxbuff[512]; - char ustarbuff[512]; - char ustar_entry_name[256]; - char pax_entry_name[256]; - - ret = ARCHIVE_OK; - need_extension = 0; - pax = (struct pax *)a->format_data; - - hardlink = archive_entry_hardlink(entry_original); - - /* Make sure this is a type of entry that we can handle here */ - if (hardlink == NULL) { - switch (archive_entry_filetype(entry_original)) { - case AE_IFBLK: - case AE_IFCHR: - case AE_IFIFO: - case AE_IFLNK: - case AE_IFREG: - break; - case AE_IFDIR: - /* - * Ensure a trailing '/'. Modify the original - * entry so the client sees the change. - */ - p = archive_entry_pathname(entry_original); - if (p[strlen(p) - 1] != '/') { - t = (char *)malloc(strlen(p) + 2); - if (t == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate pax data"); - return(ARCHIVE_FATAL); - } - strcpy(t, p); - strcat(t, "/"); - archive_entry_copy_pathname(entry_original, t); - free(t); - } - break; - case AE_IFSOCK: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive socket"); - return (ARCHIVE_WARN); - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive this (type=0%lo)", - (unsigned long)archive_entry_filetype(entry_original)); - return (ARCHIVE_WARN); - } - } - - /* Copy entry so we can modify it as needed. */ - entry_main = archive_entry_clone(entry_original); - archive_string_empty(&(pax->pax_header)); /* Blank our work area. */ - - /* - * First, check the name fields and see if any of them - * require binary coding. If any of them does, then all of - * them do. - */ - hdrcharset = NULL; - path = archive_entry_pathname(entry_main); - path_w = archive_entry_pathname_w(entry_main); - if (path != NULL && path_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate pathname '%s' to UTF-8", path); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - uname = archive_entry_uname(entry_main); - uname_w = archive_entry_uname_w(entry_main); - if (uname != NULL && uname_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate uname '%s' to UTF-8", uname); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - gname = archive_entry_gname(entry_main); - gname_w = archive_entry_gname_w(entry_main); - if (gname != NULL && gname_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate gname '%s' to UTF-8", gname); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - linkpath = hardlink; - if (linkpath != NULL) { - linkpath_w = archive_entry_hardlink_w(entry_main); - } else { - linkpath = archive_entry_symlink(entry_main); - if (linkpath != NULL) - linkpath_w = archive_entry_symlink_w(entry_main); - } - if (linkpath != NULL && linkpath_w == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, - "Can't translate linkpath '%s' to UTF-8", linkpath); - ret = ARCHIVE_WARN; - hdrcharset = "BINARY"; - } - - /* Store the header encoding first, to be nice to readers. */ - if (hdrcharset != NULL) - add_pax_attr(&(pax->pax_header), "hdrcharset", hdrcharset); - - - /* - * If name is too long, or has non-ASCII characters, add - * 'path' to pax extended attrs. (Note that an unconvertible - * name must have non-ASCII characters.) - */ - if (path == NULL) { - /* We don't have a narrow version, so we have to store - * the wide version. */ - add_pax_attr_w(&(pax->pax_header), "path", path_w); - archive_entry_set_pathname(entry_main, "@WidePath"); - need_extension = 1; - } else if (has_non_ASCII(path_w)) { - /* We have non-ASCII characters. */ - if (path_w == NULL || hdrcharset != NULL) { - /* Can't do UTF-8, so store it raw. */ - add_pax_attr(&(pax->pax_header), "path", path); - } else { - /* Store UTF-8 */ - add_pax_attr_w(&(pax->pax_header), - "path", path_w); - } - archive_entry_set_pathname(entry_main, - build_ustar_entry_name(ustar_entry_name, - path, strlen(path), NULL)); - need_extension = 1; - } else { - /* We have an all-ASCII path; we'd like to just store - * it in the ustar header if it will fit. Yes, this - * duplicates some of the logic in - * write_set_format_ustar.c - */ - if (strlen(path) <= 100) { - /* Fits in the old 100-char tar name field. */ - } else { - /* Find largest suffix that will fit. */ - /* Note: strlen() > 100, so strlen() - 100 - 1 >= 0 */ - suffix = strchr(path + strlen(path) - 100 - 1, '/'); - /* Don't attempt an empty prefix. */ - if (suffix == path) - suffix = strchr(suffix + 1, '/'); - /* We can put it in the ustar header if it's - * all ASCII and it's either <= 100 characters - * or can be split at a '/' into a prefix <= - * 155 chars and a suffix <= 100 chars. (Note - * the strchr() above will return NULL exactly - * when the path can't be split.) - */ - if (suffix == NULL /* Suffix > 100 chars. */ - || suffix[1] == '\0' /* empty suffix */ - || suffix - path > 155) /* Prefix > 155 chars */ - { - if (path_w == NULL || hdrcharset != NULL) { - /* Can't do UTF-8, so store it raw. */ - add_pax_attr(&(pax->pax_header), - "path", path); - } else { - /* Store UTF-8 */ - add_pax_attr_w(&(pax->pax_header), - "path", path_w); - } - archive_entry_set_pathname(entry_main, - build_ustar_entry_name(ustar_entry_name, - path, strlen(path), NULL)); - need_extension = 1; - } - } - } - - if (linkpath != NULL) { - /* If link name is too long or has non-ASCII characters, add - * 'linkpath' to pax extended attrs. */ - if (strlen(linkpath) > 100 || linkpath_w == NULL - || linkpath_w == NULL || has_non_ASCII(linkpath_w)) { - if (linkpath_w == NULL || hdrcharset != NULL) - /* If the linkpath is not convertible - * to wide, or we're encoding in - * binary anyway, store it raw. */ - add_pax_attr(&(pax->pax_header), - "linkpath", linkpath); - else - /* If the link is long or has a - * non-ASCII character, store it as a - * pax extended attribute. */ - add_pax_attr_w(&(pax->pax_header), - "linkpath", linkpath_w); - if (strlen(linkpath) > 100) { - if (hardlink != NULL) - archive_entry_set_hardlink(entry_main, - "././@LongHardLink"); - else - archive_entry_set_symlink(entry_main, - "././@LongSymLink"); - } - need_extension = 1; - } - } - - /* If file size is too large, add 'size' to pax extended attrs. */ - if (archive_entry_size(entry_main) >= (((int64_t)1) << 33)) { - add_pax_attr_int(&(pax->pax_header), "size", - archive_entry_size(entry_main)); - need_extension = 1; - } - - /* If numeric GID is too large, add 'gid' to pax extended attrs. */ - if ((unsigned int)archive_entry_gid(entry_main) >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "gid", - archive_entry_gid(entry_main)); - need_extension = 1; - } - - /* If group name is too large or has non-ASCII characters, add - * 'gname' to pax extended attrs. */ - if (gname != NULL) { - if (strlen(gname) > 31 - || gname_w == NULL - || has_non_ASCII(gname_w)) - { - if (gname_w == NULL || hdrcharset != NULL) { - add_pax_attr(&(pax->pax_header), - "gname", gname); - } else { - add_pax_attr_w(&(pax->pax_header), - "gname", gname_w); - } - need_extension = 1; - } - } - - /* If numeric UID is too large, add 'uid' to pax extended attrs. */ - if ((unsigned int)archive_entry_uid(entry_main) >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "uid", - archive_entry_uid(entry_main)); - need_extension = 1; - } - - /* Add 'uname' to pax extended attrs if necessary. */ - if (uname != NULL) { - if (strlen(uname) > 31 - || uname_w == NULL - || has_non_ASCII(uname_w)) - { - if (uname_w == NULL || hdrcharset != NULL) { - add_pax_attr(&(pax->pax_header), - "uname", uname); - } else { - add_pax_attr_w(&(pax->pax_header), - "uname", uname_w); - } - need_extension = 1; - } - } - - /* - * POSIX/SUSv3 doesn't provide a standard key for large device - * numbers. I use the same keys here that Joerg Schilling - * used for 'star.' (Which, somewhat confusingly, are called - * "devXXX" even though they code "rdev" values.) No doubt, - * other implementations use other keys. Note that there's no - * reason we can't write the same information into a number of - * different keys. - * - * Of course, this is only needed for block or char device entries. - */ - if (archive_entry_filetype(entry_main) == AE_IFBLK - || archive_entry_filetype(entry_main) == AE_IFCHR) { - /* - * If rdevmajor is too large, add 'SCHILY.devmajor' to - * extended attributes. - */ - dev_t rdevmajor, rdevminor; - rdevmajor = archive_entry_rdevmajor(entry_main); - rdevminor = archive_entry_rdevminor(entry_main); - if (rdevmajor >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "SCHILY.devmajor", - rdevmajor); - /* - * Non-strict formatting below means we don't - * have to truncate here. Not truncating improves - * the chance that some more modern tar archivers - * (such as GNU tar 1.13) can restore the full - * value even if they don't understand the pax - * extended attributes. See my rant below about - * file size fields for additional details. - */ - /* archive_entry_set_rdevmajor(entry_main, - rdevmajor & ((1 << 18) - 1)); */ - need_extension = 1; - } - - /* - * If devminor is too large, add 'SCHILY.devminor' to - * extended attributes. - */ - if (rdevminor >= (1 << 18)) { - add_pax_attr_int(&(pax->pax_header), "SCHILY.devminor", - rdevminor); - /* Truncation is not necessary here, either. */ - /* archive_entry_set_rdevminor(entry_main, - rdevminor & ((1 << 18) - 1)); */ - need_extension = 1; - } - } - - /* - * Technically, the mtime field in the ustar header can - * support 33 bits, but many platforms use signed 32-bit time - * values. The cutoff of 0x7fffffff here is a compromise. - * Yes, this check is duplicated just below; this helps to - * avoid writing an mtime attribute just to handle a - * high-resolution timestamp in "restricted pax" mode. - */ - if (!need_extension && - ((archive_entry_mtime(entry_main) < 0) - || (archive_entry_mtime(entry_main) >= 0x7fffffff))) - need_extension = 1; - - /* I use a star-compatible file flag attribute. */ - p = archive_entry_fflags_text(entry_main); - if (!need_extension && p != NULL && *p != '\0') - need_extension = 1; - - /* If there are non-trivial ACL entries, we need an extension. */ - if (!need_extension && archive_entry_acl_count(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS) > 0) - need_extension = 1; - - /* If there are non-trivial ACL entries, we need an extension. */ - if (!need_extension && archive_entry_acl_count(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) > 0) - need_extension = 1; - - /* If there are extended attributes, we need an extension */ - if (!need_extension && archive_entry_xattr_count(entry_original) > 0) - need_extension = 1; - - /* - * The following items are handled differently in "pax - * restricted" format. In particular, in "pax restricted" - * format they won't be added unless need_extension is - * already set (we're already generating an extended header, so - * may as well include these). - */ - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_RESTRICTED || - need_extension) { - - if (archive_entry_mtime(entry_main) < 0 || - archive_entry_mtime(entry_main) >= 0x7fffffff || - archive_entry_mtime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "mtime", - archive_entry_mtime(entry_main), - archive_entry_mtime_nsec(entry_main)); - - if (archive_entry_ctime(entry_main) != 0 || - archive_entry_ctime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "ctime", - archive_entry_ctime(entry_main), - archive_entry_ctime_nsec(entry_main)); - - if (archive_entry_atime(entry_main) != 0 || - archive_entry_atime_nsec(entry_main) != 0) - add_pax_attr_time(&(pax->pax_header), "atime", - archive_entry_atime(entry_main), - archive_entry_atime_nsec(entry_main)); - - /* Store birth/creationtime only if it's earlier than mtime */ - if (archive_entry_birthtime_is_set(entry_main) && - archive_entry_birthtime(entry_main) - < archive_entry_mtime(entry_main)) - add_pax_attr_time(&(pax->pax_header), - "LIBARCHIVE.creationtime", - archive_entry_birthtime(entry_main), - archive_entry_birthtime_nsec(entry_main)); - - /* I use a star-compatible file flag attribute. */ - p = archive_entry_fflags_text(entry_main); - if (p != NULL && *p != '\0') - add_pax_attr(&(pax->pax_header), "SCHILY.fflags", p); - - /* I use star-compatible ACL attributes. */ - wp = archive_entry_acl_text_w(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS | - ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID); - if (wp != NULL && *wp != L'\0') - add_pax_attr_w(&(pax->pax_header), - "SCHILY.acl.access", wp); - wp = archive_entry_acl_text_w(entry_original, - ARCHIVE_ENTRY_ACL_TYPE_DEFAULT | - ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID); - if (wp != NULL && *wp != L'\0') - add_pax_attr_w(&(pax->pax_header), - "SCHILY.acl.default", wp); - - /* Store extended attributes */ - archive_write_pax_header_xattrs(pax, entry_original); - } - - /* Only regular files have data. */ - if (archive_entry_filetype(entry_main) != AE_IFREG) - archive_entry_set_size(entry_main, 0); - - /* - * Pax-restricted does not store data for hardlinks, in order - * to improve compatibility with ustar. - */ - if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE && - hardlink != NULL) - archive_entry_set_size(entry_main, 0); - - /* - * XXX Full pax interchange format does permit a hardlink - * entry to have data associated with it. I'm not supporting - * that here because the client expects me to tell them whether - * or not this format expects data for hardlinks. If I - * don't check here, then every pax archive will end up with - * duplicated data for hardlinks. Someday, there may be - * need to select this behavior, in which case the following - * will need to be revisited. XXX - */ - if (hardlink != NULL) - archive_entry_set_size(entry_main, 0); - - /* Format 'ustar' header for main entry. - * - * The trouble with file size: If the reader can't understand - * the file size, they may not be able to locate the next - * entry and the rest of the archive is toast. Pax-compliant - * readers are supposed to ignore the file size in the main - * header, so the question becomes how to maximize portability - * for readers that don't support pax attribute extensions. - * For maximum compatibility, I permit numeric extensions in - * the main header so that the file size stored will always be - * correct, even if it's in a format that only some - * implementations understand. The technique used here is: - * - * a) If possible, follow the standard exactly. This handles - * files up to 8 gigabytes minus 1. - * - * b) If that fails, try octal but omit the field terminator. - * That handles files up to 64 gigabytes minus 1. - * - * c) Otherwise, use base-256 extensions. That handles files - * up to 2^63 in this implementation, with the potential to - * go up to 2^94. That should hold us for a while. ;-) - * - * The non-strict formatter uses similar logic for other - * numeric fields, though they're less critical. - */ - __archive_write_format_header_ustar(a, ustarbuff, entry_main, -1, 0); - - /* If we built any extended attributes, write that entry first. */ - if (archive_strlen(&(pax->pax_header)) > 0) { - struct archive_entry *pax_attr_entry; - time_t s; - uid_t uid; - gid_t gid; - mode_t mode; - long ns; - - pax_attr_entry = archive_entry_new(); - p = archive_entry_pathname(entry_main); - archive_entry_set_pathname(pax_attr_entry, - build_pax_attribute_name(pax_entry_name, p)); - archive_entry_set_size(pax_attr_entry, - archive_strlen(&(pax->pax_header))); - /* Copy uid/gid (but clip to ustar limits). */ - uid = archive_entry_uid(entry_main); - if ((unsigned int)uid >= 1 << 18) - uid = (uid_t)(1 << 18) - 1; - archive_entry_set_uid(pax_attr_entry, uid); - gid = archive_entry_gid(entry_main); - if ((unsigned int)gid >= 1 << 18) - gid = (gid_t)(1 << 18) - 1; - archive_entry_set_gid(pax_attr_entry, gid); - /* Copy mode over (but not setuid/setgid bits) */ - mode = archive_entry_mode(entry_main); + struct archive_entry *entry_main; + const char *p; + char *t; + const char *suffix; + int need_extension, r, ret; + int sparse_count; + uint64_t sparse_total, real_size; + struct pax *pax; + const char *hardlink; + const char *path = NULL, *linkpath = NULL; + const char *uname = NULL, *gname = NULL; + const void *mac_metadata; + size_t mac_metadata_size; + struct archive_string_conv *sconv; + size_t hardlink_length, path_length, linkpath_length; + size_t uname_length, gname_length; + + char paxbuff[512]; + char ustarbuff[512]; + char ustar_entry_name[256]; + char pax_entry_name[256]; + char gnu_sparse_name[256]; + struct archive_string entry_name; + + ret = ARCHIVE_OK; + need_extension = 0; + pax = (struct pax *)a->format_data; + + /* Sanity check. */ + if (archive_entry_pathname(entry_original) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't record entry in tar file without pathname"); + return (ARCHIVE_FAILED); + } + + /* + * Choose a header encoding. + */ + if (pax->opt_binary) + sconv = NULL;/* Binary mode. */ + else { + /* Header encoding is UTF-8. */ + if (pax->sconv_utf8 == NULL) { + /* Initialize the string conversion object + * we must need */ + pax->sconv_utf8 = archive_string_conversion_to_charset( + &(a->archive), "UTF-8", 1); + if (pax->sconv_utf8 == NULL) + /* Couldn't allocate memory */ + return (ARCHIVE_FAILED); + } + sconv = pax->sconv_utf8; + } + + r = get_entry_hardlink(a, entry_original, &hardlink, + &hardlink_length, sconv); + if (r == ARCHIVE_FATAL) + return (r); + else if (r != ARCHIVE_OK) { + r = get_entry_hardlink(a, entry_original, &hardlink, + &hardlink_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", hardlink, + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + sconv = NULL;/* The header charset switches to binary mode. */ + } + + /* Make sure this is a type of entry that we can handle here */ + if (hardlink == NULL) { + switch (archive_entry_filetype(entry_original)) { + case AE_IFBLK: + case AE_IFCHR: + case AE_IFIFO: + case AE_IFLNK: + case AE_IFREG: + break; + case AE_IFDIR: + /* + * Ensure a trailing '/'. Modify the original + * entry so the client sees the change. + */ + p = archive_entry_pathname(entry_original); + if (p[strlen(p) - 1] != '/') { + t = (char *)malloc(strlen(p) + 2); + if (t == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate pax data"); + return(ARCHIVE_FATAL); + } + strcpy(t, p); + strcat(t, "/"); + archive_entry_copy_pathname(entry_original, t); + free(t); + } + break; + case AE_IFSOCK: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive socket"); + return (ARCHIVE_FAILED); + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive this (type=0%lo)", + (unsigned long) + archive_entry_filetype(entry_original)); + return (ARCHIVE_FAILED); + } + } + + /* + * If Mac OS metadata blob is here, recurse to write that + * as a separate entry. This is realy a pretty poor design: + * In particular, it doubles the overhead for long filenames. + * TODO: Help Apple folks design something better and figure + * out how to transition from this legacy format. + * + * Note that this code is present on every platform; clients + * on non-Mac are unlikely to ever provide this data, but + * applications that copy entries from one archive to another + * should not lose data just because the local filesystem + * can't store it. + */ + mac_metadata = + archive_entry_mac_metadata(entry_original, &mac_metadata_size); + if (mac_metadata != NULL) { + const char *oname; + char *name, *bname; + size_t name_length; + struct archive_entry *extra = archive_entry_new2(&a->archive); + + oname = archive_entry_pathname(entry_original); + name_length = strlen(oname); + name = malloc(name_length + 3); + if (name == NULL) { + /* XXX error message */ + return (ARCHIVE_FAILED); + } + strcpy(name, oname); + /* Find last '/'; strip trailing '/' characters */ + bname = strrchr(name, '/'); + while (bname != NULL && bname[1] == '\0') { + *bname = '\0'; + bname = strrchr(name, '/'); + } + if (bname == NULL) { + memmove(name + 2, name, name_length + 1); + memmove(name, "._", 2); + } else { + bname += 1; + memmove(bname + 2, bname, strlen(bname) + 1); + memmove(bname, "._", 2); + } + archive_entry_copy_pathname(extra, name); + free(name); + + archive_entry_set_size(extra, mac_metadata_size); + archive_entry_set_filetype(extra, AE_IFREG); + archive_entry_set_perm(extra, + archive_entry_perm(entry_original)); + archive_entry_set_mtime(extra, + archive_entry_mtime(entry_original), + archive_entry_mtime_nsec(entry_original)); + archive_entry_set_gid(extra, + archive_entry_gid(entry_original)); + archive_entry_set_gname(extra, + archive_entry_gname(entry_original)); + archive_entry_set_uid(extra, + archive_entry_uid(entry_original)); + archive_entry_set_uname(extra, + archive_entry_uname(entry_original)); + + /* Recurse to write the special copyfile entry. */ + r = archive_write_pax_header(a, extra); + if (r < ARCHIVE_WARN) + return (r); + if (r < ret) + ret = r; + r = archive_write_pax_data(a, mac_metadata, mac_metadata_size); + if (r < ARCHIVE_WARN) + return (r); + if (r < ret) + ret = r; + r = archive_write_pax_finish_entry(a); + if (r < ARCHIVE_WARN) + return (r); + if (r < ret) + ret = r; + } + + /* Copy entry so we can modify it as needed. */ + entry_main = archive_entry_clone(entry_original); + archive_string_empty(&(pax->pax_header)); /* Blank our work area. */ + archive_string_empty(&(pax->sparse_map)); + sparse_total = 0; + sparse_list_clear(pax); + + if (hardlink == NULL && + archive_entry_filetype(entry_main) == AE_IFREG) + sparse_count = archive_entry_sparse_reset(entry_main); + else + sparse_count = 0; + if (sparse_count) { + int64_t offset, length, last_offset = 0; + /* Get the last entry of sparse block. */ + while (archive_entry_sparse_next( + entry_main, &offset, &length) == ARCHIVE_OK) + last_offset = offset + length; + + /* If the last sparse block does not reach the end of file, + * We have to add a empty sparse block as the last entry to + * manage storing file data. */ + if (last_offset < archive_entry_size(entry_main)) + archive_entry_sparse_add_entry(entry_main, + archive_entry_size(entry_main), 0); + sparse_count = archive_entry_sparse_reset(entry_main); + } + + /* + * First, check the name fields and see if any of them + * require binary coding. If any of them does, then all of + * them do. + */ + r = get_entry_pathname(a, entry_main, &path, &path_length, sconv); + if (r == ARCHIVE_FATAL) + return (r); + else if (r != ARCHIVE_OK) { + r = get_entry_pathname(a, entry_main, &path, + &path_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", path, + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + sconv = NULL;/* The header charset switches to binary mode. */ + } + r = get_entry_uname(a, entry_main, &uname, &uname_length, sconv); + if (r == ARCHIVE_FATAL) + return (r); + else if (r != ARCHIVE_OK) { + r = get_entry_uname(a, entry_main, &uname, &uname_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate uname '%s' to %s", uname, + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + sconv = NULL;/* The header charset switches to binary mode. */ + } + r = get_entry_gname(a, entry_main, &gname, &gname_length, sconv); + if (r == ARCHIVE_FATAL) + return (r); + else if (r != ARCHIVE_OK) { + r = get_entry_gname(a, entry_main, &gname, &gname_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate gname '%s' to %s", gname, + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + sconv = NULL;/* The header charset switches to binary mode. */ + } + linkpath = hardlink; + linkpath_length = hardlink_length; + if (linkpath == NULL) { + r = get_entry_symlink(a, entry_main, &linkpath, + &linkpath_length, sconv); + if (r == ARCHIVE_FATAL) + return (r); + else if (r != ARCHIVE_OK) { + r = get_entry_symlink(a, entry_main, &linkpath, + &linkpath_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", linkpath, + archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + sconv = NULL; + } + } + + /* If any string conversions failed, get all attributes + * in binary-mode. */ + if (sconv == NULL && !pax->opt_binary) { + if (hardlink != NULL) { + r = get_entry_hardlink(a, entry_main, &hardlink, + &hardlink_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + linkpath = hardlink; + linkpath_length = hardlink_length; + } + r = get_entry_pathname(a, entry_main, &path, + &path_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + r = get_entry_uname(a, entry_main, &uname, &uname_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + r = get_entry_gname(a, entry_main, &gname, &gname_length, NULL); + if (r == ARCHIVE_FATAL) + return (r); + } + + /* Store the header encoding first, to be nice to readers. */ + if (sconv == NULL) + add_pax_attr(&(pax->pax_header), "hdrcharset", "BINARY"); + + + /* + * If name is too long, or has non-ASCII characters, add + * 'path' to pax extended attrs. (Note that an unconvertible + * name must have non-ASCII characters.) + */ + if (has_non_ASCII(path)) { + /* We have non-ASCII characters. */ + add_pax_attr(&(pax->pax_header), "path", path); + archive_entry_set_pathname(entry_main, + build_ustar_entry_name(ustar_entry_name, + path, path_length, NULL)); + need_extension = 1; + } else { + /* We have an all-ASCII path; we'd like to just store + * it in the ustar header if it will fit. Yes, this + * duplicates some of the logic in + * archive_write_set_format_ustar.c + */ + if (path_length <= 100) { + /* Fits in the old 100-char tar name field. */ + } else { + /* Find largest suffix that will fit. */ + /* Note: strlen() > 100, so strlen() - 100 - 1 >= 0 */ + suffix = strchr(path + path_length - 100 - 1, '/'); + /* Don't attempt an empty prefix. */ + if (suffix == path) + suffix = strchr(suffix + 1, '/'); + /* We can put it in the ustar header if it's + * all ASCII and it's either <= 100 characters + * or can be split at a '/' into a prefix <= + * 155 chars and a suffix <= 100 chars. (Note + * the strchr() above will return NULL exactly + * when the path can't be split.) + */ + if (suffix == NULL /* Suffix > 100 chars. */ + || suffix[1] == '\0' /* empty suffix */ + || suffix - path > 155) /* Prefix > 155 chars */ + { + add_pax_attr(&(pax->pax_header), "path", path); + archive_entry_set_pathname(entry_main, + build_ustar_entry_name(ustar_entry_name, + path, path_length, NULL)); + need_extension = 1; + } + } + } + + if (linkpath != NULL) { + /* If link name is too long or has non-ASCII characters, add + * 'linkpath' to pax extended attrs. */ + if (linkpath_length > 100 || has_non_ASCII(linkpath)) { + add_pax_attr(&(pax->pax_header), "linkpath", linkpath); + if (linkpath_length > 100) { + if (hardlink != NULL) + archive_entry_set_hardlink(entry_main, + "././@LongHardLink"); + else + archive_entry_set_symlink(entry_main, + "././@LongSymLink"); + } + need_extension = 1; + } + } + /* Save a pathname since it will be renamed if `entry_main` has + * sparse blocks. */ + archive_string_init(&entry_name); + archive_strcpy(&entry_name, archive_entry_pathname(entry_main)); + + /* If file size is too large, add 'size' to pax extended attrs. */ + if (archive_entry_size(entry_main) >= (((int64_t)1) << 33)) { + add_pax_attr_int(&(pax->pax_header), "size", + archive_entry_size(entry_main)); + need_extension = 1; + } + + /* If numeric GID is too large, add 'gid' to pax extended attrs. */ + if ((unsigned int)archive_entry_gid(entry_main) >= (1 << 18)) { + add_pax_attr_int(&(pax->pax_header), "gid", + archive_entry_gid(entry_main)); + need_extension = 1; + } + + /* If group name is too large or has non-ASCII characters, add + * 'gname' to pax extended attrs. */ + if (gname != NULL) { + if (gname_length > 31 || has_non_ASCII(gname)) { + add_pax_attr(&(pax->pax_header), "gname", gname); + need_extension = 1; + } + } + + /* If numeric UID is too large, add 'uid' to pax extended attrs. */ + if ((unsigned int)archive_entry_uid(entry_main) >= (1 << 18)) { + add_pax_attr_int(&(pax->pax_header), "uid", + archive_entry_uid(entry_main)); + need_extension = 1; + } + + /* Add 'uname' to pax extended attrs if necessary. */ + if (uname != NULL) { + if (uname_length > 31 || has_non_ASCII(uname)) { + add_pax_attr(&(pax->pax_header), "uname", uname); + need_extension = 1; + } + } + + /* + * POSIX/SUSv3 doesn't provide a standard key for large device + * numbers. I use the same keys here that Joerg Schilling + * used for 'star.' (Which, somewhat confusingly, are called + * "devXXX" even though they code "rdev" values.) No doubt, + * other implementations use other keys. Note that there's no + * reason we can't write the same information into a number of + * different keys. + * + * Of course, this is only needed for block or char device entries. + */ + if (archive_entry_filetype(entry_main) == AE_IFBLK + || archive_entry_filetype(entry_main) == AE_IFCHR) { + /* + * If rdevmajor is too large, add 'SCHILY.devmajor' to + * extended attributes. + */ + int rdevmajor, rdevminor; + rdevmajor = archive_entry_rdevmajor(entry_main); + rdevminor = archive_entry_rdevminor(entry_main); + if (rdevmajor >= (1 << 18)) { + add_pax_attr_int(&(pax->pax_header), "SCHILY.devmajor", + rdevmajor); + /* + * Non-strict formatting below means we don't + * have to truncate here. Not truncating improves + * the chance that some more modern tar archivers + * (such as GNU tar 1.13) can restore the full + * value even if they don't understand the pax + * extended attributes. See my rant below about + * file size fields for additional details. + */ + /* archive_entry_set_rdevmajor(entry_main, + rdevmajor & ((1 << 18) - 1)); */ + need_extension = 1; + } + + /* + * If devminor is too large, add 'SCHILY.devminor' to + * extended attributes. + */ + if (rdevminor >= (1 << 18)) { + add_pax_attr_int(&(pax->pax_header), "SCHILY.devminor", + rdevminor); + /* Truncation is not necessary here, either. */ + /* archive_entry_set_rdevminor(entry_main, + rdevminor & ((1 << 18) - 1)); */ + need_extension = 1; + } + } + + /* + * Technically, the mtime field in the ustar header can + * support 33 bits, but many platforms use signed 32-bit time + * values. The cutoff of 0x7fffffff here is a compromise. + * Yes, this check is duplicated just below; this helps to + * avoid writing an mtime attribute just to handle a + * high-resolution timestamp in "restricted pax" mode. + */ + if (!need_extension && + ((archive_entry_mtime(entry_main) < 0) + || (archive_entry_mtime(entry_main) >= 0x7fffffff))) + need_extension = 1; + + /* I use a star-compatible file flag attribute. */ + p = archive_entry_fflags_text(entry_main); + if (!need_extension && p != NULL && *p != '\0') + need_extension = 1; + + /* If there are non-trivial ACL entries, we need an extension. */ + if (!need_extension && archive_entry_acl_count(entry_original, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS) > 0) + need_extension = 1; + + /* If there are non-trivial ACL entries, we need an extension. */ + if (!need_extension && archive_entry_acl_count(entry_original, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) > 0) + need_extension = 1; + + /* If there are extended attributes, we need an extension */ + if (!need_extension && archive_entry_xattr_count(entry_original) > 0) + need_extension = 1; + + /* If there are sparse info, we need an extension */ + if (!need_extension && sparse_count > 0) + need_extension = 1; + + /* + * The following items are handled differently in "pax + * restricted" format. In particular, in "pax restricted" + * format they won't be added unless need_extension is + * already set (we're already generating an extended header, so + * may as well include these). + */ + if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_RESTRICTED || + need_extension) { + + if (archive_entry_mtime(entry_main) < 0 || + archive_entry_mtime(entry_main) >= 0x7fffffff || + archive_entry_mtime_nsec(entry_main) != 0) + add_pax_attr_time(&(pax->pax_header), "mtime", + archive_entry_mtime(entry_main), + archive_entry_mtime_nsec(entry_main)); + + if (archive_entry_ctime(entry_main) != 0 || + archive_entry_ctime_nsec(entry_main) != 0) + add_pax_attr_time(&(pax->pax_header), "ctime", + archive_entry_ctime(entry_main), + archive_entry_ctime_nsec(entry_main)); + + if (archive_entry_atime(entry_main) != 0 || + archive_entry_atime_nsec(entry_main) != 0) + add_pax_attr_time(&(pax->pax_header), "atime", + archive_entry_atime(entry_main), + archive_entry_atime_nsec(entry_main)); + + /* Store birth/creationtime only if it's earlier than mtime */ + if (archive_entry_birthtime_is_set(entry_main) && + archive_entry_birthtime(entry_main) + < archive_entry_mtime(entry_main)) + add_pax_attr_time(&(pax->pax_header), + "LIBARCHIVE.creationtime", + archive_entry_birthtime(entry_main), + archive_entry_birthtime_nsec(entry_main)); + + /* I use a star-compatible file flag attribute. */ + p = archive_entry_fflags_text(entry_main); + if (p != NULL && *p != '\0') + add_pax_attr(&(pax->pax_header), "SCHILY.fflags", p); + + /* I use star-compatible ACL attributes. */ + r = archive_entry_acl_text_l(entry_original, + ARCHIVE_ENTRY_ACL_TYPE_ACCESS | + ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID, + &p, NULL, pax->sconv_utf8); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for " + "ACL.access"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate ACL.access to UTF-8"); + ret = ARCHIVE_WARN; + } else if (p != NULL && *p != '\0') { + add_pax_attr(&(pax->pax_header), + "SCHILY.acl.access", p); + } + r = archive_entry_acl_text_l(entry_original, + ARCHIVE_ENTRY_ACL_TYPE_DEFAULT | + ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID, + &p, NULL, pax->sconv_utf8); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for " + "ACL.default"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate ACL.default to UTF-8"); + ret = ARCHIVE_WARN; + } else if (p != NULL && *p != '\0') { + add_pax_attr(&(pax->pax_header), + "SCHILY.acl.default", p); + } + + /* We use GNU-tar-compatible sparse attributes. */ + if (sparse_count > 0) { + int64_t soffset, slength; + + add_pax_attr_int(&(pax->pax_header), + "GNU.sparse.major", 1); + add_pax_attr_int(&(pax->pax_header), + "GNU.sparse.minor", 0); + add_pax_attr(&(pax->pax_header), + "GNU.sparse.name", entry_name.s); + add_pax_attr_int(&(pax->pax_header), + "GNU.sparse.realsize", + archive_entry_size(entry_main)); + + /* Rename the file name which will be used for + * ustar header to a special name, which GNU + * PAX Format 1.0 requires */ + archive_entry_set_pathname(entry_main, + build_gnu_sparse_name(gnu_sparse_name, + entry_name.s)); + + /* + * - Make a sparse map, which will precede a file data. + * - Get the total size of available data of sparse. + */ + archive_string_sprintf(&(pax->sparse_map), "%d\n", + sparse_count); + while (archive_entry_sparse_next(entry_main, + &soffset, &slength) == ARCHIVE_OK) { + archive_string_sprintf(&(pax->sparse_map), + "%jd\n%jd\n", + (intmax_t)soffset, + (intmax_t)slength); + sparse_total += slength; + if (sparse_list_add(pax, soffset, slength) + != ARCHIVE_OK) { + archive_set_error(&a->archive, + ENOMEM, + "Can't allocate memory"); + archive_entry_free(entry_main); + archive_string_free(&entry_name); + return (ARCHIVE_FATAL); + } + } + } + + /* Store extended attributes */ + if (archive_write_pax_header_xattrs(a, pax, entry_original) + == ARCHIVE_FATAL) { + archive_entry_free(entry_main); + archive_string_free(&entry_name); + return (ARCHIVE_FATAL); + } + } + + /* Only regular files have data. */ + if (archive_entry_filetype(entry_main) != AE_IFREG) + archive_entry_set_size(entry_main, 0); + + /* + * Pax-restricted does not store data for hardlinks, in order + * to improve compatibility with ustar. + */ + if (a->archive.archive_format != ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE && + hardlink != NULL) + archive_entry_set_size(entry_main, 0); + + /* + * XXX Full pax interchange format does permit a hardlink + * entry to have data associated with it. I'm not supporting + * that here because the client expects me to tell them whether + * or not this format expects data for hardlinks. If I + * don't check here, then every pax archive will end up with + * duplicated data for hardlinks. Someday, there may be + * need to select this behavior, in which case the following + * will need to be revisited. XXX + */ + if (hardlink != NULL) + archive_entry_set_size(entry_main, 0); + + /* Save a real file size. */ + real_size = archive_entry_size(entry_main); + /* + * Overwrite a file size by the total size of sparse blocks and + * the size of sparse map info. That file size is the length of + * the data, which we will exactly store into an archive file. + */ + if (archive_strlen(&(pax->sparse_map))) { + size_t mapsize = archive_strlen(&(pax->sparse_map)); + pax->sparse_map_padding = 0x1ff & (-(ssize_t)mapsize); + archive_entry_set_size(entry_main, + mapsize + pax->sparse_map_padding + sparse_total); + } + + /* Format 'ustar' header for main entry. + * + * The trouble with file size: If the reader can't understand + * the file size, they may not be able to locate the next + * entry and the rest of the archive is toast. Pax-compliant + * readers are supposed to ignore the file size in the main + * header, so the question becomes how to maximize portability + * for readers that don't support pax attribute extensions. + * For maximum compatibility, I permit numeric extensions in + * the main header so that the file size stored will always be + * correct, even if it's in a format that only some + * implementations understand. The technique used here is: + * + * a) If possible, follow the standard exactly. This handles + * files up to 8 gigabytes minus 1. + * + * b) If that fails, try octal but omit the field terminator. + * That handles files up to 64 gigabytes minus 1. + * + * c) Otherwise, use base-256 extensions. That handles files + * up to 2^63 in this implementation, with the potential to + * go up to 2^94. That should hold us for a while. ;-) + * + * The non-strict formatter uses similar logic for other + * numeric fields, though they're less critical. + */ + if (__archive_write_format_header_ustar(a, ustarbuff, entry_main, -1, 0, + NULL) == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + /* If we built any extended attributes, write that entry first. */ + if (archive_strlen(&(pax->pax_header)) > 0) { + struct archive_entry *pax_attr_entry; + time_t s; + int64_t uid, gid; + int mode; + + pax_attr_entry = archive_entry_new2(&a->archive); + p = entry_name.s; + archive_entry_set_pathname(pax_attr_entry, + build_pax_attribute_name(pax_entry_name, p)); + archive_entry_set_size(pax_attr_entry, + archive_strlen(&(pax->pax_header))); + /* Copy uid/gid (but clip to ustar limits). */ + uid = archive_entry_uid(entry_main); + if (uid >= 1 << 18) + uid = (1 << 18) - 1; + archive_entry_set_uid(pax_attr_entry, uid); + gid = archive_entry_gid(entry_main); + if (gid >= 1 << 18) + gid = (1 << 18) - 1; + archive_entry_set_gid(pax_attr_entry, gid); + /* Copy mode over (but not setuid/setgid bits) */ + mode = archive_entry_mode(entry_main); #ifdef S_ISUID - mode &= ~S_ISUID; + mode &= ~S_ISUID; #endif #ifdef S_ISGID - mode &= ~S_ISGID; + mode &= ~S_ISGID; #endif #ifdef S_ISVTX - mode &= ~S_ISVTX; + mode &= ~S_ISVTX; #endif - archive_entry_set_mode(pax_attr_entry, mode); - - /* Copy uname/gname. */ - archive_entry_set_uname(pax_attr_entry, - archive_entry_uname(entry_main)); - archive_entry_set_gname(pax_attr_entry, - archive_entry_gname(entry_main)); - - /* Copy mtime, but clip to ustar limits. */ - s = archive_entry_mtime(entry_main); - ns = archive_entry_mtime_nsec(entry_main); - if (s < 0) { s = 0; ns = 0; } - if (s > 0x7fffffff) { s = 0x7fffffff; ns = 0; } - archive_entry_set_mtime(pax_attr_entry, s, ns); - - /* Ditto for atime. */ - s = archive_entry_atime(entry_main); - ns = archive_entry_atime_nsec(entry_main); - if (s < 0) { s = 0; ns = 0; } - if (s > 0x7fffffff) { s = 0x7fffffff; ns = 0; } - archive_entry_set_atime(pax_attr_entry, s, ns); - - /* Standard ustar doesn't support ctime. */ - archive_entry_set_ctime(pax_attr_entry, 0, 0); - - r = __archive_write_format_header_ustar(a, paxbuff, - pax_attr_entry, 'x', 1); - - archive_entry_free(pax_attr_entry); - - /* Note that the 'x' header shouldn't ever fail to format */ - if (r != 0) { - const char *msg = "archive_write_pax_header: " - "'x' header failed?! This can't happen.\n"; - size_t u = write(2, msg, strlen(msg)); - (void)u; /* UNUSED */ - exit(1); - } - r = (a->compressor.write)(a, paxbuff, 512); - if (r != ARCHIVE_OK) { - pax->entry_bytes_remaining = 0; - pax->entry_padding = 0; - return (ARCHIVE_FATAL); - } - - pax->entry_bytes_remaining = archive_strlen(&(pax->pax_header)); - pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); - - r = (a->compressor.write)(a, pax->pax_header.s, - archive_strlen(&(pax->pax_header))); - if (r != ARCHIVE_OK) { - /* If a write fails, we're pretty much toast. */ - return (ARCHIVE_FATAL); - } - /* Pad out the end of the entry. */ - r = write_nulls(a, pax->entry_padding); - if (r != ARCHIVE_OK) { - /* If a write fails, we're pretty much toast. */ - return (ARCHIVE_FATAL); - } - pax->entry_bytes_remaining = pax->entry_padding = 0; - } - - /* Write the header for main entry. */ - r = (a->compressor.write)(a, ustarbuff, 512); - if (r != ARCHIVE_OK) - return (r); - - /* - * Inform the client of the on-disk size we're using, so - * they can avoid unnecessarily writing a body for something - * that we're just going to ignore. - */ - archive_entry_set_size(entry_original, archive_entry_size(entry_main)); - pax->entry_bytes_remaining = archive_entry_size(entry_main); - pax->entry_padding = 0x1ff & (-(int64_t)pax->entry_bytes_remaining); - archive_entry_free(entry_main); - - return (ret); + archive_entry_set_mode(pax_attr_entry, mode); + + /* Copy uname/gname. */ + archive_entry_set_uname(pax_attr_entry, + archive_entry_uname(entry_main)); + archive_entry_set_gname(pax_attr_entry, + archive_entry_gname(entry_main)); + + /* Copy mtime, but clip to ustar limits. */ + s = archive_entry_mtime(entry_main); + if (s < 0) { s = 0; } + if (s >= 0x7fffffff) { s = 0x7fffffff; } + archive_entry_set_mtime(pax_attr_entry, s, 0); + + /* Standard ustar doesn't support atime. */ + archive_entry_set_atime(pax_attr_entry, 0, 0); + + /* Standard ustar doesn't support ctime. */ + archive_entry_set_ctime(pax_attr_entry, 0, 0); + + r = __archive_write_format_header_ustar(a, paxbuff, + pax_attr_entry, 'x', 1, NULL); + + archive_entry_free(pax_attr_entry); + + /* Note that the 'x' header shouldn't ever fail to format */ + if (r < ARCHIVE_WARN) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "archive_write_pax_header: " + "'x' header failed?! This can't happen.\n"); + return (ARCHIVE_FATAL); + } else if (r < ret) + ret = r; + r = __archive_write_output(a, paxbuff, 512); + if (r != ARCHIVE_OK) { + sparse_list_clear(pax); + pax->entry_bytes_remaining = 0; + pax->entry_padding = 0; + return (ARCHIVE_FATAL); + } + + pax->entry_bytes_remaining = archive_strlen(&(pax->pax_header)); + pax->entry_padding = + 0x1ff & (-(int64_t)pax->entry_bytes_remaining); + + r = __archive_write_output(a, pax->pax_header.s, + archive_strlen(&(pax->pax_header))); + if (r != ARCHIVE_OK) { + /* If a write fails, we're pretty much toast. */ + return (ARCHIVE_FATAL); + } + /* Pad out the end of the entry. */ + r = __archive_write_nulls(a, pax->entry_padding); + if (r != ARCHIVE_OK) { + /* If a write fails, we're pretty much toast. */ + return (ARCHIVE_FATAL); + } + pax->entry_bytes_remaining = pax->entry_padding = 0; + } + + /* Write the header for main entry. */ + r = __archive_write_output(a, ustarbuff, 512); + if (r != ARCHIVE_OK) + return (r); + + /* + * Inform the client of the on-disk size we're using, so + * they can avoid unnecessarily writing a body for something + * that we're just going to ignore. + */ + archive_entry_set_size(entry_original, real_size); + if (pax->sparse_list == NULL && real_size > 0) { + /* This is not a sparse file but we handle its data as + * a sparse block. */ + sparse_list_add(pax, 0, real_size); + sparse_total = real_size; + } + pax->entry_padding = 0x1ff & (-(int64_t)sparse_total); + archive_entry_free(entry_main); + archive_string_free(&entry_name); + + return (ret); } /* @@ -1015,109 +1322,109 @@ static char * build_ustar_entry_name(char *dest, const char *src, size_t src_length, const char *insert) { - const char *prefix, *prefix_end; - const char *suffix, *suffix_end; - const char *filename, *filename_end; - char *p; - int need_slash = 0; /* Was there a trailing slash? */ - size_t suffix_length = 99; - int insert_length; - - /* Length of additional dir element to be added. */ - if (insert == NULL) - insert_length = 0; - else - /* +2 here allows for '/' before and after the insert. */ - insert_length = strlen(insert) + 2; - - /* Step 0: Quick bailout in a common case. */ - if (src_length < 100 && insert == NULL) { - strncpy(dest, src, src_length); - dest[src_length] = '\0'; - return (dest); - } - - /* Step 1: Locate filename and enforce the length restriction. */ - filename_end = src + src_length; - /* Remove trailing '/' chars and '/.' pairs. */ - for (;;) { - if (filename_end > src && filename_end[-1] == '/') { - filename_end --; - need_slash = 1; /* Remember to restore trailing '/'. */ - continue; - } - if (filename_end > src + 1 && filename_end[-1] == '.' - && filename_end[-2] == '/') { - filename_end -= 2; - need_slash = 1; /* "foo/." will become "foo/" */ - continue; - } - break; - } - if (need_slash) - suffix_length--; - /* Find start of filename. */ - filename = filename_end - 1; - while ((filename > src) && (*filename != '/')) - filename --; - if ((*filename == '/') && (filename < filename_end - 1)) - filename ++; - /* Adjust filename_end so that filename + insert fits in 99 chars. */ - suffix_length -= insert_length; - if (filename_end > filename + suffix_length) - filename_end = filename + suffix_length; - /* Calculate max size for "suffix" section (#3 above). */ - suffix_length -= filename_end - filename; - - /* Step 2: Locate the "prefix" section of the dirname, including - * trailing '/'. */ - prefix = src; - prefix_end = prefix + 155; - if (prefix_end > filename) - prefix_end = filename; - while (prefix_end > prefix && *prefix_end != '/') - prefix_end--; - if ((prefix_end < filename) && (*prefix_end == '/')) - prefix_end++; - - /* Step 3: Locate the "suffix" section of the dirname, - * including trailing '/'. */ - suffix = prefix_end; - suffix_end = suffix + suffix_length; /* Enforce limit. */ - if (suffix_end > filename) - suffix_end = filename; - if (suffix_end < suffix) - suffix_end = suffix; - while (suffix_end > suffix && *suffix_end != '/') - suffix_end--; - if ((suffix_end < filename) && (*suffix_end == '/')) - suffix_end++; - - /* Step 4: Build the new name. */ - /* The OpenBSD strlcpy function is safer, but less portable. */ - /* Rather than maintain two versions, just use the strncpy version. */ - p = dest; - if (prefix_end > prefix) { - strncpy(p, prefix, prefix_end - prefix); - p += prefix_end - prefix; - } - if (suffix_end > suffix) { - strncpy(p, suffix, suffix_end - suffix); - p += suffix_end - suffix; - } - if (insert != NULL) { - /* Note: assume insert does not have leading or trailing '/' */ - strcpy(p, insert); - p += strlen(insert); - *p++ = '/'; - } - strncpy(p, filename, filename_end - filename); - p += filename_end - filename; - if (need_slash) - *p++ = '/'; - *p++ = '\0'; - - return (dest); + const char *prefix, *prefix_end; + const char *suffix, *suffix_end; + const char *filename, *filename_end; + char *p; + int need_slash = 0; /* Was there a trailing slash? */ + size_t suffix_length = 99; + size_t insert_length; + + /* Length of additional dir element to be added. */ + if (insert == NULL) + insert_length = 0; + else + /* +2 here allows for '/' before and after the insert. */ + insert_length = strlen(insert) + 2; + + /* Step 0: Quick bailout in a common case. */ + if (src_length < 100 && insert == NULL) { + strncpy(dest, src, src_length); + dest[src_length] = '\0'; + return (dest); + } + + /* Step 1: Locate filename and enforce the length restriction. */ + filename_end = src + src_length; + /* Remove trailing '/' chars and '/.' pairs. */ + for (;;) { + if (filename_end > src && filename_end[-1] == '/') { + filename_end --; + need_slash = 1; /* Remember to restore trailing '/'. */ + continue; + } + if (filename_end > src + 1 && filename_end[-1] == '.' + && filename_end[-2] == '/') { + filename_end -= 2; + need_slash = 1; /* "foo/." will become "foo/" */ + continue; + } + break; + } + if (need_slash) + suffix_length--; + /* Find start of filename. */ + filename = filename_end - 1; + while ((filename > src) && (*filename != '/')) + filename --; + if ((*filename == '/') && (filename < filename_end - 1)) + filename ++; + /* Adjust filename_end so that filename + insert fits in 99 chars. */ + suffix_length -= insert_length; + if (filename_end > filename + suffix_length) + filename_end = filename + suffix_length; + /* Calculate max size for "suffix" section (#3 above). */ + suffix_length -= filename_end - filename; + + /* Step 2: Locate the "prefix" section of the dirname, including + * trailing '/'. */ + prefix = src; + prefix_end = prefix + 155; + if (prefix_end > filename) + prefix_end = filename; + while (prefix_end > prefix && *prefix_end != '/') + prefix_end--; + if ((prefix_end < filename) && (*prefix_end == '/')) + prefix_end++; + + /* Step 3: Locate the "suffix" section of the dirname, + * including trailing '/'. */ + suffix = prefix_end; + suffix_end = suffix + suffix_length; /* Enforce limit. */ + if (suffix_end > filename) + suffix_end = filename; + if (suffix_end < suffix) + suffix_end = suffix; + while (suffix_end > suffix && *suffix_end != '/') + suffix_end--; + if ((suffix_end < filename) && (*suffix_end == '/')) + suffix_end++; + + /* Step 4: Build the new name. */ + /* The OpenBSD strlcpy function is safer, but less portable. */ + /* Rather than maintain two versions, just use the strncpy version. */ + p = dest; + if (prefix_end > prefix) { + strncpy(p, prefix, prefix_end - prefix); + p += prefix_end - prefix; + } + if (suffix_end > suffix) { + strncpy(p, suffix, suffix_end - suffix); + p += suffix_end - suffix; + } + if (insert != NULL) { + /* Note: assume insert does not have leading or trailing '/' */ + strcpy(p, insert); + p += strlen(insert); + *p++ = '/'; + } + strncpy(p, filename, filename_end - filename); + p += filename_end - filename; + if (need_slash) + *p++ = '/'; + *p = '\0'; + + return (dest); } /* @@ -1146,145 +1453,231 @@ build_ustar_entry_name(char *dest, const char *src, size_t src_length, static char * build_pax_attribute_name(char *dest, const char *src) { - char buff[64]; - const char *p; - - /* Handle the null filename case. */ - if (src == NULL || *src == '\0') { - strcpy(dest, "PaxHeader/blank"); - return (dest); - } - - /* Prune final '/' and other unwanted final elements. */ - p = src + strlen(src); - for (;;) { - /* Ends in "/", remove the '/' */ - if (p > src && p[-1] == '/') { - --p; - continue; - } - /* Ends in "/.", remove the '.' */ - if (p > src + 1 && p[-1] == '.' - && p[-2] == '/') { - --p; - continue; - } - break; - } - - /* Pathological case: After above, there was nothing left. - * This includes "/." "/./." "/.//./." etc. */ - if (p == src) { - strcpy(dest, "/PaxHeader/rootdir"); - return (dest); - } - - /* Convert unadorned "." into a suitable filename. */ - if (*src == '.' && p == src + 1) { - strcpy(dest, "PaxHeader/currentdir"); - return (dest); - } - - /* - * TODO: Push this string into the 'pax' structure to avoid - * recomputing it every time. That will also open the door - * to having clients override it. - */ + char buff[64]; + const char *p; + + /* Handle the null filename case. */ + if (src == NULL || *src == '\0') { + strcpy(dest, "PaxHeader/blank"); + return (dest); + } + + /* Prune final '/' and other unwanted final elements. */ + p = src + strlen(src); + for (;;) { + /* Ends in "/", remove the '/' */ + if (p > src && p[-1] == '/') { + --p; + continue; + } + /* Ends in "/.", remove the '.' */ + if (p > src + 1 && p[-1] == '.' + && p[-2] == '/') { + --p; + continue; + } + break; + } + + /* Pathological case: After above, there was nothing left. + * This includes "/." "/./." "/.//./." etc. */ + if (p == src) { + strcpy(dest, "/PaxHeader/rootdir"); + return (dest); + } + + /* Convert unadorned "." into a suitable filename. */ + if (*src == '.' && p == src + 1) { + strcpy(dest, "PaxHeader/currentdir"); + return (dest); + } + + /* + * TODO: Push this string into the 'pax' structure to avoid + * recomputing it every time. That will also open the door + * to having clients override it. + */ #if HAVE_GETPID && 0 /* Disable this for now; see above comment. */ - sprintf(buff, "PaxHeader.%d", getpid()); + sprintf(buff, "PaxHeader.%d", getpid()); #else - /* If the platform can't fetch the pid, don't include it. */ - strcpy(buff, "PaxHeader"); + /* If the platform can't fetch the pid, don't include it. */ + strcpy(buff, "PaxHeader"); #endif - /* General case: build a ustar-compatible name adding "/PaxHeader/". */ - build_ustar_entry_name(dest, src, p - src, buff); + /* General case: build a ustar-compatible name adding + * "/PaxHeader/". */ + build_ustar_entry_name(dest, src, p - src, buff); - return (dest); + return (dest); } -/* Write two null blocks for the end of archive */ -static int -archive_write_pax_finish(struct archive_write *a) +/* + * GNU PAX Format 1.0 requires the special name, which pattern is: + * /GNUSparseFile./ + * + * This function is used for only Sparse file, a file type of which + * is regular file. + */ +static char * +build_gnu_sparse_name(char *dest, const char *src) { - struct pax *pax; - int r; - - if (a->compressor.write == NULL) - return (ARCHIVE_OK); + char buff[64]; + const char *p; + + /* Handle the null filename case. */ + if (src == NULL || *src == '\0') { + strcpy(dest, "GNUSparseFile/blank"); + return (dest); + } + + /* Prune final '/' and other unwanted final elements. */ + p = src + strlen(src); + for (;;) { + /* Ends in "/", remove the '/' */ + if (p > src && p[-1] == '/') { + --p; + continue; + } + /* Ends in "/.", remove the '.' */ + if (p > src + 1 && p[-1] == '.' + && p[-2] == '/') { + --p; + continue; + } + break; + } + +#if HAVE_GETPID && 0 /* Disable this as pax attribute name. */ + sprintf(buff, "GNUSparseFile.%d", getpid()); +#else + /* If the platform can't fetch the pid, don't include it. */ + strcpy(buff, "GNUSparseFile"); +#endif + /* General case: build a ustar-compatible name adding + * "/GNUSparseFile/". */ + build_ustar_entry_name(dest, src, p - src, buff); - pax = (struct pax *)a->format_data; - r = write_nulls(a, 512 * 2); - return (r); + return (dest); } +/* Write two null blocks for the end of archive */ static int -archive_write_pax_destroy(struct archive_write *a) +archive_write_pax_close(struct archive_write *a) { - struct pax *pax; - - pax = (struct pax *)a->format_data; - if (pax == NULL) - return (ARCHIVE_OK); - - archive_string_free(&pax->pax_header); - free(pax); - a->format_data = NULL; - return (ARCHIVE_OK); + return (__archive_write_nulls(a, 512 * 2)); } static int -archive_write_pax_finish_entry(struct archive_write *a) +archive_write_pax_free(struct archive_write *a) { - struct pax *pax; - int ret; - - pax = (struct pax *)a->format_data; - ret = write_nulls(a, pax->entry_bytes_remaining + pax->entry_padding); - pax->entry_bytes_remaining = pax->entry_padding = 0; - return (ret); + struct pax *pax; + + pax = (struct pax *)a->format_data; + if (pax == NULL) + return (ARCHIVE_OK); + + archive_string_free(&pax->pax_header); + archive_string_free(&pax->sparse_map); + archive_string_free(&pax->l_url_encoded_name); + sparse_list_clear(pax); + free(pax); + a->format_data = NULL; + return (ARCHIVE_OK); } static int -write_nulls(struct archive_write *a, size_t padding) +archive_write_pax_finish_entry(struct archive_write *a) { - int ret, to_write; - - while (padding > 0) { - to_write = padding < a->null_length ? padding : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - padding -= to_write; - } - return (ARCHIVE_OK); + struct pax *pax; + uint64_t remaining; + int ret; + + pax = (struct pax *)a->format_data; + remaining = pax->entry_bytes_remaining; + if (remaining == 0) { + while (pax->sparse_list) { + struct sparse_block *sb; + remaining += pax->sparse_list->remaining; + sb = pax->sparse_list->next; + free(pax->sparse_list); + pax->sparse_list = sb; + } + } + ret = __archive_write_nulls(a, remaining + pax->entry_padding); + pax->entry_bytes_remaining = pax->entry_padding = 0; + return (ret); } static ssize_t archive_write_pax_data(struct archive_write *a, const void *buff, size_t s) { - struct pax *pax; - int ret; - - pax = (struct pax *)a->format_data; - if (s > pax->entry_bytes_remaining) - s = pax->entry_bytes_remaining; - - ret = (a->compressor.write)(a, buff, s); - pax->entry_bytes_remaining -= s; - if (ret == ARCHIVE_OK) - return (s); - else - return (ret); + struct pax *pax; + size_t ws; + size_t total; + int ret; + + pax = (struct pax *)a->format_data; + + /* + * According to GNU PAX format 1.0, write a sparse map + * before the body. + */ + if (archive_strlen(&(pax->sparse_map))) { + ret = __archive_write_output(a, pax->sparse_map.s, + archive_strlen(&(pax->sparse_map))); + if (ret != ARCHIVE_OK) + return (ret); + ret = __archive_write_nulls(a, pax->sparse_map_padding); + if (ret != ARCHIVE_OK) + return (ret); + archive_string_empty(&(pax->sparse_map)); + } + + total = 0; + while (total < s) { + const unsigned char *p; + + while (pax->sparse_list != NULL && + pax->sparse_list->remaining == 0) { + struct sparse_block *sb = pax->sparse_list->next; + free(pax->sparse_list); + pax->sparse_list = sb; + } + + if (pax->sparse_list == NULL) + return (total); + + p = ((const unsigned char *)buff) + total; + ws = s; + if (ws > pax->sparse_list->remaining) + ws = pax->sparse_list->remaining; + + if (pax->sparse_list->is_hole) { + /* Current block is hole thus we do not write + * the body. */ + pax->sparse_list->remaining -= ws; + total += ws; + continue; + } + + ret = __archive_write_output(a, p, ws); + pax->sparse_list->remaining -= ws; + total += ws; + if (ret != ARCHIVE_OK) + return (ret); + } + return (total); } static int -has_non_ASCII(const wchar_t *wp) +has_non_ASCII(const char *_p) { - if (wp == NULL) - return (1); - while (*wp != L'\0' && *wp < 128) - wp++; - return (*wp != L'\0'); + const unsigned char *p = (const unsigned char *)_p; + + if (p == NULL) + return (1); + while (*p != '\0' && *p < 128) + p++; + return (*p != '\0'); } /* @@ -1294,35 +1687,35 @@ has_non_ASCII(const wchar_t *wp) static char * url_encode(const char *in) { - const char *s; - char *d; - int out_len = 0; - char *out; - - for (s = in; *s != '\0'; s++) { - if (*s < 33 || *s > 126 || *s == '%' || *s == '=') - out_len += 3; - else - out_len++; - } - - out = (char *)malloc(out_len + 1); - if (out == NULL) - return (NULL); - - for (s = in, d = out; *s != '\0'; s++) { - /* encode any non-printable ASCII character or '%' or '=' */ - if (*s < 33 || *s > 126 || *s == '%' || *s == '=') { - /* URL encoding is '%' followed by two hex digits */ - *d++ = '%'; - *d++ = "0123456789ABCDEF"[0x0f & (*s >> 4)]; - *d++ = "0123456789ABCDEF"[0x0f & *s]; - } else { - *d++ = *s; - } - } - *d = '\0'; - return (out); + const char *s; + char *d; + int out_len = 0; + char *out; + + for (s = in; *s != '\0'; s++) { + if (*s < 33 || *s > 126 || *s == '%' || *s == '=') + out_len += 3; + else + out_len++; + } + + out = (char *)malloc(out_len + 1); + if (out == NULL) + return (NULL); + + for (s = in, d = out; *s != '\0'; s++) { + /* encode any non-printable ASCII character or '%' or '=' */ + if (*s < 33 || *s > 126 || *s == '%' || *s == '=') { + /* URL encoding is '%' followed by two hex digits */ + *d++ = '%'; + *d++ = "0123456789ABCDEF"[0x0f & (*s >> 4)]; + *d++ = "0123456789ABCDEF"[0x0f & *s]; + } else { + *d++ = *s; + } + } + *d = '\0'; + return (out); } /* @@ -1334,50 +1727,107 @@ url_encode(const char *in) static char * base64_encode(const char *s, size_t len) { - static const char digits[64] = - { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', - 'P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d', - 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s', - 't','u','v','w','x','y','z','0','1','2','3','4','5','6','7', - '8','9','+','/' }; - int v; - char *d, *out; - - /* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */ - out = (char *)malloc((len * 4 + 2) / 3 + 1); - if (out == NULL) - return (NULL); - d = out; - - /* Convert each group of 3 bytes into 4 characters. */ - while (len >= 3) { - v = (((int)s[0] << 16) & 0xff0000) - | (((int)s[1] << 8) & 0xff00) - | (((int)s[2]) & 0x00ff); - s += 3; - len -= 3; - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - *d++ = digits[(v >> 6) & 0x3f]; - *d++ = digits[(v) & 0x3f]; - } - /* Handle final group of 1 byte (2 chars) or 2 bytes (3 chars). */ - switch (len) { - case 0: break; - case 1: - v = (((int)s[0] << 16) & 0xff0000); - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - break; - case 2: - v = (((int)s[0] << 16) & 0xff0000) - | (((int)s[1] << 8) & 0xff00); - *d++ = digits[(v >> 18) & 0x3f]; - *d++ = digits[(v >> 12) & 0x3f]; - *d++ = digits[(v >> 6) & 0x3f]; - break; - } - /* Add trailing NUL character so output is a valid C string. */ - *d++ = '\0'; - return (out); + static const char digits[64] = + { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', + 'P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d', + 'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s', + 't','u','v','w','x','y','z','0','1','2','3','4','5','6','7', + '8','9','+','/' }; + int v; + char *d, *out; + + /* 3 bytes becomes 4 chars, but round up and allow for trailing NUL */ + out = (char *)malloc((len * 4 + 2) / 3 + 1); + if (out == NULL) + return (NULL); + d = out; + + /* Convert each group of 3 bytes into 4 characters. */ + while (len >= 3) { + v = (((int)s[0] << 16) & 0xff0000) + | (((int)s[1] << 8) & 0xff00) + | (((int)s[2]) & 0x00ff); + s += 3; + len -= 3; + *d++ = digits[(v >> 18) & 0x3f]; + *d++ = digits[(v >> 12) & 0x3f]; + *d++ = digits[(v >> 6) & 0x3f]; + *d++ = digits[(v) & 0x3f]; + } + /* Handle final group of 1 byte (2 chars) or 2 bytes (3 chars). */ + switch (len) { + case 0: break; + case 1: + v = (((int)s[0] << 16) & 0xff0000); + *d++ = digits[(v >> 18) & 0x3f]; + *d++ = digits[(v >> 12) & 0x3f]; + break; + case 2: + v = (((int)s[0] << 16) & 0xff0000) + | (((int)s[1] << 8) & 0xff00); + *d++ = digits[(v >> 18) & 0x3f]; + *d++ = digits[(v >> 12) & 0x3f]; + *d++ = digits[(v >> 6) & 0x3f]; + break; + } + /* Add trailing NUL character so output is a valid C string. */ + *d = '\0'; + return (out); } + +static void +sparse_list_clear(struct pax *pax) +{ + while (pax->sparse_list != NULL) { + struct sparse_block *sb = pax->sparse_list; + pax->sparse_list = sb->next; + free(sb); + } + pax->sparse_tail = NULL; +} + +static int +_sparse_list_add_block(struct pax *pax, int64_t offset, int64_t length, + int is_hole) +{ + struct sparse_block *sb; + + sb = (struct sparse_block *)malloc(sizeof(*sb)); + if (sb == NULL) + return (ARCHIVE_FATAL); + sb->next = NULL; + sb->is_hole = is_hole; + sb->offset = offset; + sb->remaining = length; + if (pax->sparse_list == NULL) + pax->sparse_list = pax->sparse_tail = sb; + else { + pax->sparse_tail->next = sb; + pax->sparse_tail = sb; + } + return (ARCHIVE_OK); +} + +static int +sparse_list_add(struct pax *pax, int64_t offset, int64_t length) +{ + int64_t last_offset; + int r; + + if (pax->sparse_tail == NULL) + last_offset = 0; + else { + last_offset = pax->sparse_tail->offset + + pax->sparse_tail->remaining; + } + if (last_offset < offset) { + /* Add a hole block. */ + r = _sparse_list_add_block(pax, last_offset, + offset - last_offset, 1); + if (r != ARCHIVE_OK) + return (r); + } + /* Add data block. */ + return (_sparse_list_add_block(pax, offset, length, 0)); +} + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c index 0ee46320f..9ec15f915 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_shar.c @@ -25,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_shar.c,v 1.20 2008/08/31 07:10:40 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_shar.c 189438 2009-03-06 05:58:56Z kientzle $"); #ifdef HAVE_ERRNO_H #include @@ -44,30 +44,30 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_shar.c,v 1.20 20 #include "archive_write_private.h" struct shar { - int dump; - int end_of_line; - struct archive_entry *entry; - int has_data; - char *last_dir; - - /* Line buffer for uuencoded dump format */ - char outbuff[45]; - size_t outpos; - - int wrote_header; - struct archive_string work; - struct archive_string quoted_name; + int dump; + int end_of_line; + struct archive_entry *entry; + int has_data; + char *last_dir; + + /* Line buffer for uuencoded dump format */ + char outbuff[45]; + size_t outpos; + + int wrote_header; + struct archive_string work; + struct archive_string quoted_name; }; -static int archive_write_shar_finish(struct archive_write *); -static int archive_write_shar_destroy(struct archive_write *); -static int archive_write_shar_header(struct archive_write *, - struct archive_entry *); -static ssize_t archive_write_shar_data_sed(struct archive_write *, - const void * buff, size_t); -static ssize_t archive_write_shar_data_uuencode(struct archive_write *, - const void * buff, size_t); -static int archive_write_shar_finish_entry(struct archive_write *); +static int archive_write_shar_close(struct archive_write *); +static int archive_write_shar_free(struct archive_write *); +static int archive_write_shar_header(struct archive_write *, + struct archive_entry *); +static ssize_t archive_write_shar_data_sed(struct archive_write *, + const void * buff, size_t); +static ssize_t archive_write_shar_data_uuencode(struct archive_write *, + const void * buff, size_t); +static int archive_write_shar_finish_entry(struct archive_write *); /* * Copy the given string to the buffer, quoting all shell meta characters @@ -76,25 +76,25 @@ static int archive_write_shar_finish_entry(struct archive_write *); static void shar_quote(struct archive_string *buf, const char *str, int in_shell) { - static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; - size_t len; - - while (*str != '\0') { - if ((len = strcspn(str, meta)) != 0) { - archive_strncat(buf, str, len); - str += len; - } else if (*str == '\n') { - if (in_shell) - archive_strcat(buf, "\"\n\""); - else - archive_strcat(buf, "\\n"); - ++str; - } else { - archive_strappend_char(buf, '\\'); - archive_strappend_char(buf, *str); - ++str; - } - } + static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~"; + size_t len; + + while (*str != '\0') { + if ((len = strcspn(str, meta)) != 0) { + archive_strncat(buf, str, len); + str += len; + } else if (*str == '\n') { + if (in_shell) + archive_strcat(buf, "\"\n\""); + else + archive_strcat(buf, "\\n"); + ++str; + } else { + archive_strappend_char(buf, '\\'); + archive_strappend_char(buf, *str); + ++str; + } + } } /* @@ -103,33 +103,34 @@ shar_quote(struct archive_string *buf, const char *str, int in_shell) int archive_write_set_format_shar(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct shar *shar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - shar = (struct shar *)malloc(sizeof(*shar)); - if (shar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data"); - return (ARCHIVE_FATAL); - } - memset(shar, 0, sizeof(*shar)); - archive_string_init(&shar->work); - archive_string_init(&shar->quoted_name); - a->format_data = shar; - - a->pad_uncompressed = 0; - a->format_name = "shar"; - a->format_write_header = archive_write_shar_header; - a->format_finish = archive_write_shar_finish; - a->format_destroy = archive_write_shar_destroy; - a->format_write_data = archive_write_shar_data_sed; - a->format_finish_entry = archive_write_shar_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE; - a->archive.archive_format_name = "shar"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct shar *shar; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_shar"); + + /* If someone else was already registered, unregister them. */ + if (a->format_free != NULL) + (a->format_free)(a); + + shar = (struct shar *)malloc(sizeof(*shar)); + if (shar == NULL) { + archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data"); + return (ARCHIVE_FATAL); + } + memset(shar, 0, sizeof(*shar)); + archive_string_init(&shar->work); + archive_string_init(&shar->quoted_name); + a->format_data = shar; + a->format_name = "shar"; + a->format_write_header = archive_write_shar_header; + a->format_close = archive_write_shar_close; + a->format_free = archive_write_shar_free; + a->format_write_data = archive_write_shar_data_sed; + a->format_finish_entry = archive_write_shar_finish_entry; + a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE; + a->archive.archive_format_name = "shar"; + return (ARCHIVE_OK); } /* @@ -141,486 +142,501 @@ archive_write_set_format_shar(struct archive *_a) int archive_write_set_format_shar_dump(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct shar *shar; - - archive_write_set_format_shar(&a->archive); - shar = (struct shar *)a->format_data; - shar->dump = 1; - a->format_write_data = archive_write_shar_data_uuencode; - a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP; - a->archive.archive_format_name = "shar dump"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct shar *shar; + + archive_write_set_format_shar(&a->archive); + shar = (struct shar *)a->format_data; + shar->dump = 1; + a->format_write_data = archive_write_shar_data_uuencode; + a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP; + a->archive.archive_format_name = "shar dump"; + return (ARCHIVE_OK); } static int archive_write_shar_header(struct archive_write *a, struct archive_entry *entry) { - const char *linkname; - const char *name; - char *p, *pp; - struct shar *shar; - - shar = (struct shar *)a->format_data; - if (!shar->wrote_header) { - archive_strcat(&shar->work, "#!/bin/sh\n"); - archive_strcat(&shar->work, "# This is a shell archive\n"); - shar->wrote_header = 1; - } - - /* Save the entry for the closing. */ - if (shar->entry) - archive_entry_free(shar->entry); - shar->entry = archive_entry_clone(entry); - name = archive_entry_pathname(entry); - - /* Handle some preparatory issues. */ - switch(archive_entry_filetype(entry)) { - case AE_IFREG: - /* Only regular files have non-zero size. */ - break; - case AE_IFDIR: - archive_entry_set_size(entry, 0); - /* Don't bother trying to recreate '.' */ - if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0) - return (ARCHIVE_OK); - break; - case AE_IFIFO: - case AE_IFCHR: - case AE_IFBLK: - /* All other file types have zero size in the archive. */ - archive_entry_set_size(entry, 0); - break; - default: - archive_entry_set_size(entry, 0); - if (archive_entry_hardlink(entry) == NULL && - archive_entry_symlink(entry) == NULL) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "shar format cannot archive this"); - return (ARCHIVE_WARN); - } - } - - archive_string_empty(&shar->quoted_name); - shar_quote(&shar->quoted_name, name, 1); - - /* Stock preparation for all file types. */ - archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s); - - if (archive_entry_filetype(entry) != AE_IFDIR) { - /* Try to create the dir. */ - p = strdup(name); - pp = strrchr(p, '/'); - /* If there is a / character, try to create the dir. */ - if (pp != NULL) { - *pp = '\0'; - - /* Try to avoid a lot of redundant mkdir commands. */ - if (strcmp(p, ".") == 0) { - /* Don't try to "mkdir ." */ - free(p); - } else if (shar->last_dir == NULL) { - archive_strcat(&shar->work, "mkdir -p "); - shar_quote(&shar->work, p, 1); - archive_strcat(&shar->work, - " > /dev/null 2>&1\n"); - shar->last_dir = p; - } else if (strcmp(p, shar->last_dir) == 0) { - /* We've already created this exact dir. */ - free(p); - } else if (strlen(p) < strlen(shar->last_dir) && - strncmp(p, shar->last_dir, strlen(p)) == 0) { - /* We've already created a subdir. */ - free(p); - } else { - archive_strcat(&shar->work, "mkdir -p "); - shar_quote(&shar->work, p, 1); - archive_strcat(&shar->work, - " > /dev/null 2>&1\n"); - shar->last_dir = p; - } - } else { - free(p); - } - } - - /* Handle file-type specific issues. */ - shar->has_data = 0; - if ((linkname = archive_entry_hardlink(entry)) != NULL) { - archive_strcat(&shar->work, "ln -f "); - shar_quote(&shar->work, linkname, 1); - archive_string_sprintf(&shar->work, " %s\n", - shar->quoted_name.s); - } else if ((linkname = archive_entry_symlink(entry)) != NULL) { - archive_strcat(&shar->work, "ln -fs "); - shar_quote(&shar->work, linkname, 1); - archive_string_sprintf(&shar->work, " %s\n", - shar->quoted_name.s); - } else { - switch(archive_entry_filetype(entry)) { - case AE_IFREG: - if (archive_entry_size(entry) == 0) { - /* More portable than "touch." */ - archive_string_sprintf(&shar->work, - "test -e \"%s\" || :> \"%s\"\n", - shar->quoted_name.s, shar->quoted_name.s); - } else { - if (shar->dump) { - archive_string_sprintf(&shar->work, - "uudecode -p > %s << 'SHAR_END'\n", - shar->quoted_name.s); - archive_string_sprintf(&shar->work, - "begin %o ", - archive_entry_mode(entry) & 0777); - shar_quote(&shar->work, name, 0); - archive_strcat(&shar->work, "\n"); - } else { - archive_string_sprintf(&shar->work, - "sed 's/^X//' > %s << 'SHAR_END'\n", - shar->quoted_name.s); - } - shar->has_data = 1; - shar->end_of_line = 1; - shar->outpos = 0; - } - break; - case AE_IFDIR: - archive_string_sprintf(&shar->work, - "mkdir -p %s > /dev/null 2>&1\n", - shar->quoted_name.s); - /* Record that we just created this directory. */ - if (shar->last_dir != NULL) - free(shar->last_dir); - - shar->last_dir = strdup(name); - /* Trim a trailing '/'. */ - pp = strrchr(shar->last_dir, '/'); - if (pp != NULL && pp[1] == '\0') - *pp = '\0'; - /* - * TODO: Put dir name/mode on a list to be fixed - * up at end of archive. - */ - break; - case AE_IFIFO: - archive_string_sprintf(&shar->work, - "mkfifo %s\n", shar->quoted_name.s); - break; - case AE_IFCHR: - archive_string_sprintf(&shar->work, - "mknod %s c %d %d\n", shar->quoted_name.s, - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - break; - case AE_IFBLK: - archive_string_sprintf(&shar->work, - "mknod %s b %d %d\n", shar->quoted_name.s, - archive_entry_rdevmajor(entry), - archive_entry_rdevminor(entry)); - break; - default: - return (ARCHIVE_WARN); - } - } - - return (ARCHIVE_OK); + const char *linkname; + const char *name; + char *p, *pp; + struct shar *shar; + + shar = (struct shar *)a->format_data; + if (!shar->wrote_header) { + archive_strcat(&shar->work, "#!/bin/sh\n"); + archive_strcat(&shar->work, "# This is a shell archive\n"); + shar->wrote_header = 1; + } + + /* Save the entry for the closing. */ + if (shar->entry) + archive_entry_free(shar->entry); + shar->entry = archive_entry_clone(entry); + name = archive_entry_pathname(entry); + + /* Handle some preparatory issues. */ + switch(archive_entry_filetype(entry)) { + case AE_IFREG: + /* Only regular files have non-zero size. */ + break; + case AE_IFDIR: + archive_entry_set_size(entry, 0); + /* Don't bother trying to recreate '.' */ + if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0) + return (ARCHIVE_OK); + break; + case AE_IFIFO: + case AE_IFCHR: + case AE_IFBLK: + /* All other file types have zero size in the archive. */ + archive_entry_set_size(entry, 0); + break; + default: + archive_entry_set_size(entry, 0); + if (archive_entry_hardlink(entry) == NULL && + archive_entry_symlink(entry) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "shar format cannot archive this"); + return (ARCHIVE_WARN); + } + } + + archive_string_empty(&shar->quoted_name); + shar_quote(&shar->quoted_name, name, 1); + + /* Stock preparation for all file types. */ + archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s); + + if (archive_entry_filetype(entry) != AE_IFDIR) { + /* Try to create the dir. */ + p = strdup(name); + pp = strrchr(p, '/'); + /* If there is a / character, try to create the dir. */ + if (pp != NULL) { + *pp = '\0'; + + /* Try to avoid a lot of redundant mkdir commands. */ + if (strcmp(p, ".") == 0) { + /* Don't try to "mkdir ." */ + free(p); + } else if (shar->last_dir == NULL) { + archive_strcat(&shar->work, "mkdir -p "); + shar_quote(&shar->work, p, 1); + archive_strcat(&shar->work, + " > /dev/null 2>&1\n"); + shar->last_dir = p; + } else if (strcmp(p, shar->last_dir) == 0) { + /* We've already created this exact dir. */ + free(p); + } else if (strlen(p) < strlen(shar->last_dir) && + strncmp(p, shar->last_dir, strlen(p)) == 0) { + /* We've already created a subdir. */ + free(p); + } else { + archive_strcat(&shar->work, "mkdir -p "); + shar_quote(&shar->work, p, 1); + archive_strcat(&shar->work, + " > /dev/null 2>&1\n"); + shar->last_dir = p; + } + } else { + free(p); + } + } + + /* Handle file-type specific issues. */ + shar->has_data = 0; + if ((linkname = archive_entry_hardlink(entry)) != NULL) { + archive_strcat(&shar->work, "ln -f "); + shar_quote(&shar->work, linkname, 1); + archive_string_sprintf(&shar->work, " %s\n", + shar->quoted_name.s); + } else if ((linkname = archive_entry_symlink(entry)) != NULL) { + archive_strcat(&shar->work, "ln -fs "); + shar_quote(&shar->work, linkname, 1); + archive_string_sprintf(&shar->work, " %s\n", + shar->quoted_name.s); + } else { + switch(archive_entry_filetype(entry)) { + case AE_IFREG: + if (archive_entry_size(entry) == 0) { + /* More portable than "touch." */ + archive_string_sprintf(&shar->work, + "test -e \"%s\" || :> \"%s\"\n", + shar->quoted_name.s, shar->quoted_name.s); + } else { + if (shar->dump) { + unsigned int mode = archive_entry_mode(entry) & 0777; + archive_string_sprintf(&shar->work, + "uudecode -p > %s << 'SHAR_END'\n", + shar->quoted_name.s); + archive_string_sprintf(&shar->work, + "begin %o ", mode); + shar_quote(&shar->work, name, 0); + archive_strcat(&shar->work, "\n"); + } else { + archive_string_sprintf(&shar->work, + "sed 's/^X//' > %s << 'SHAR_END'\n", + shar->quoted_name.s); + } + shar->has_data = 1; + shar->end_of_line = 1; + shar->outpos = 0; + } + break; + case AE_IFDIR: + archive_string_sprintf(&shar->work, + "mkdir -p %s > /dev/null 2>&1\n", + shar->quoted_name.s); + /* Record that we just created this directory. */ + if (shar->last_dir != NULL) + free(shar->last_dir); + + shar->last_dir = strdup(name); + /* Trim a trailing '/'. */ + pp = strrchr(shar->last_dir, '/'); + if (pp != NULL && pp[1] == '\0') + *pp = '\0'; + /* + * TODO: Put dir name/mode on a list to be fixed + * up at end of archive. + */ + break; + case AE_IFIFO: + archive_string_sprintf(&shar->work, + "mkfifo %s\n", shar->quoted_name.s); + break; + case AE_IFCHR: + archive_string_sprintf(&shar->work, + "mknod %s c %ju %ju\n", shar->quoted_name.s, + (uintmax_t)archive_entry_rdevmajor(entry), + (uintmax_t)archive_entry_rdevminor(entry)); + break; + case AE_IFBLK: + archive_string_sprintf(&shar->work, + "mknod %s b %ju %ju\n", shar->quoted_name.s, + (uintmax_t)archive_entry_rdevmajor(entry), + (uintmax_t)archive_entry_rdevminor(entry)); + break; + default: + return (ARCHIVE_WARN); + } + } + + return (ARCHIVE_OK); } static ssize_t archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n) { - static const size_t ensured = 65533; - struct shar *shar; - const char *src; - char *buf, *buf_end; - int ret; - size_t written = n; - - shar = (struct shar *)a->format_data; - if (!shar->has_data || n == 0) - return (0); - - src = (const char *)buff; - - /* - * ensure is the number of bytes in buffer before expanding the - * current character. Each operation writes the current character - * and optionally the start-of-new-line marker. This can happen - * twice before entering the loop, so make sure three additional - * bytes can be written. - */ - if (archive_string_ensure(&shar->work, ensured + 3) == NULL) - __archive_errx(1, "Out of memory"); - - if (shar->work.length > ensured) { - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - } - buf = shar->work.s + shar->work.length; - buf_end = shar->work.s + ensured; - - if (shar->end_of_line) { - *buf++ = 'X'; - shar->end_of_line = 0; - } - - while (n-- != 0) { - if ((*buf++ = *src++) == '\n') { - if (n == 0) - shar->end_of_line = 1; - else - *buf++ = 'X'; - } - - if (buf >= buf_end) { - shar->work.length = buf - shar->work.s; - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - buf = shar->work.s; - } - } - - shar->work.length = buf - shar->work.s; - - return (written); + static const size_t ensured = 65533; + struct shar *shar; + const char *src; + char *buf, *buf_end; + int ret; + size_t written = n; + + shar = (struct shar *)a->format_data; + if (!shar->has_data || n == 0) + return (0); + + src = (const char *)buff; + + /* + * ensure is the number of bytes in buffer before expanding the + * current character. Each operation writes the current character + * and optionally the start-of-new-line marker. This can happen + * twice before entering the loop, so make sure three additional + * bytes can be written. + */ + if (archive_string_ensure(&shar->work, ensured + 3) == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + + if (shar->work.length > ensured) { + ret = __archive_write_output(a, shar->work.s, + shar->work.length); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + archive_string_empty(&shar->work); + } + buf = shar->work.s + shar->work.length; + buf_end = shar->work.s + ensured; + + if (shar->end_of_line) { + *buf++ = 'X'; + shar->end_of_line = 0; + } + + while (n-- != 0) { + if ((*buf++ = *src++) == '\n') { + if (n == 0) + shar->end_of_line = 1; + else + *buf++ = 'X'; + } + + if (buf >= buf_end) { + shar->work.length = buf - shar->work.s; + ret = __archive_write_output(a, shar->work.s, + shar->work.length); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + archive_string_empty(&shar->work); + buf = shar->work.s; + } + } + + shar->work.length = buf - shar->work.s; + + return (written); } -#define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`') +#define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`') static void uuencode_group(const char _in[3], char out[4]) { - const unsigned char *in = (const unsigned char *)_in; - int t; - - t = (in[0] << 16) | (in[1] << 8) | in[2]; - out[0] = UUENC( 0x3f & (t >> 18) ); - out[1] = UUENC( 0x3f & (t >> 12) ); - out[2] = UUENC( 0x3f & (t >> 6) ); - out[3] = UUENC( 0x3f & t ); + const unsigned char *in = (const unsigned char *)_in; + int t; + + t = (in[0] << 16) | (in[1] << 8) | in[2]; + out[0] = UUENC( 0x3f & (t >> 18) ); + out[1] = UUENC( 0x3f & (t >> 12) ); + out[2] = UUENC( 0x3f & (t >> 6) ); + out[3] = UUENC( 0x3f & t ); } -static void -uuencode_line(struct shar *shar, const char *inbuf, size_t len) +static int +_uuencode_line(struct archive_write *a, struct shar *shar, const char *inbuf, size_t len) { - char tmp_buf[3], *buf; - size_t alloc_len; - - /* len <= 45 -> expanded to 60 + len byte + new line */ - alloc_len = shar->work.length + 62; - if (archive_string_ensure(&shar->work, alloc_len) == NULL) - __archive_errx(1, "Out of memory"); - - buf = shar->work.s + shar->work.length; - *buf++ = UUENC(len); - while (len >= 3) { - uuencode_group(inbuf, buf); - len -= 3; - inbuf += 3; - buf += 4; - } - if (len != 0) { - tmp_buf[0] = inbuf[0]; - if (len == 1) - tmp_buf[1] = '\0'; - else - tmp_buf[1] = inbuf[1]; - tmp_buf[2] = '\0'; - uuencode_group(inbuf, buf); - buf += 4; - } - *buf++ = '\n'; - if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) - __archive_errx(1, "Buffer overflow"); - shar->work.length = buf - shar->work.s; + char *buf; + size_t alloc_len; + + /* len <= 45 -> expanded to 60 + len byte + new line */ + alloc_len = shar->work.length + 62; + if (archive_string_ensure(&shar->work, alloc_len) == NULL) { + archive_set_error(&a->archive, ENOMEM, "Out of memory"); + return (ARCHIVE_FATAL); + } + + buf = shar->work.s + shar->work.length; + *buf++ = UUENC(len); + while (len >= 3) { + uuencode_group(inbuf, buf); + len -= 3; + inbuf += 3; + buf += 4; + } + if (len != 0) { + char tmp_buf[3]; + tmp_buf[0] = inbuf[0]; + if (len == 1) + tmp_buf[1] = '\0'; + else + tmp_buf[1] = inbuf[1]; + tmp_buf[2] = '\0'; + uuencode_group(tmp_buf, buf); + buf += 4; + } + *buf++ = '\n'; + if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, "Buffer overflow"); + return (ARCHIVE_FATAL); + } + shar->work.length = buf - shar->work.s; + return (ARCHIVE_OK); } +#define uuencode_line(__a, __shar, __inbuf, __len) \ + do { \ + int r = _uuencode_line(__a, __shar, __inbuf, __len); \ + if (r != ARCHIVE_OK) \ + return (ARCHIVE_FATAL); \ + } while (0) + static ssize_t archive_write_shar_data_uuencode(struct archive_write *a, const void *buff, size_t length) { - struct shar *shar; - const char *src; - size_t n; - int ret; - - shar = (struct shar *)a->format_data; - if (!shar->has_data) - return (ARCHIVE_OK); - src = (const char *)buff; - - if (shar->outpos != 0) { - n = 45 - shar->outpos; - if (n > length) - n = length; - memcpy(shar->outbuff + shar->outpos, src, n); - if (shar->outpos + n < 45) { - shar->outpos += n; - return length; - } - uuencode_line(shar, shar->outbuff, 45); - src += n; - n = length - n; - } else { - n = length; - } - - while (n >= 45) { - uuencode_line(shar, src, 45); - src += 45; - n -= 45; - - if (shar->work.length < 65536) - continue; - ret = (*a->compressor.write)(a, shar->work.s, - shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - } - if (n != 0) { - memcpy(shar->outbuff, src, n); - shar->outpos = n; - } - return (length); + struct shar *shar; + const char *src; + size_t n; + int ret; + + shar = (struct shar *)a->format_data; + if (!shar->has_data) + return (ARCHIVE_OK); + src = (const char *)buff; + + if (shar->outpos != 0) { + n = 45 - shar->outpos; + if (n > length) + n = length; + memcpy(shar->outbuff + shar->outpos, src, n); + if (shar->outpos + n < 45) { + shar->outpos += n; + return length; + } + uuencode_line(a, shar, shar->outbuff, 45); + src += n; + n = length - n; + } else { + n = length; + } + + while (n >= 45) { + uuencode_line(a, shar, src, 45); + src += 45; + n -= 45; + + if (shar->work.length < 65536) + continue; + ret = __archive_write_output(a, shar->work.s, + shar->work.length); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + archive_string_empty(&shar->work); + } + if (n != 0) { + memcpy(shar->outbuff, src, n); + shar->outpos = n; + } + return (length); } static int archive_write_shar_finish_entry(struct archive_write *a) { - const char *g, *p, *u; - struct shar *shar; - int ret; - - shar = (struct shar *)a->format_data; - if (shar->entry == NULL) - return (0); - - if (shar->dump) { - /* Finish uuencoded data. */ - if (shar->has_data) { - if (shar->outpos > 0) - uuencode_line(shar, shar->outbuff, - shar->outpos); - archive_strcat(&shar->work, "`\nend\n"); - archive_strcat(&shar->work, "SHAR_END\n"); - } - /* Restore file mode, owner, flags. */ - /* - * TODO: Don't immediately restore mode for - * directories; defer that to end of script. - */ - archive_string_sprintf(&shar->work, "chmod %o ", - archive_entry_mode(shar->entry) & 07777); - shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - - u = archive_entry_uname(shar->entry); - g = archive_entry_gname(shar->entry); - if (u != NULL || g != NULL) { - archive_strcat(&shar->work, "chown "); - if (u != NULL) - shar_quote(&shar->work, u, 1); - if (g != NULL) { - archive_strcat(&shar->work, ":"); - shar_quote(&shar->work, g, 1); - } - shar_quote(&shar->work, - archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - } - - if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { - archive_string_sprintf(&shar->work, "chflags %s ", - p, archive_entry_pathname(shar->entry)); - shar_quote(&shar->work, - archive_entry_pathname(shar->entry), 1); - archive_strcat(&shar->work, "\n"); - } - - /* TODO: restore ACLs */ - - } else { - if (shar->has_data) { - /* Finish sed-encoded data: ensure last line ends. */ - if (!shar->end_of_line) - archive_strappend_char(&shar->work, '\n'); - archive_strcat(&shar->work, "SHAR_END\n"); - } - } - - archive_entry_free(shar->entry); - shar->entry = NULL; - - if (shar->work.length < 65536) - return (ARCHIVE_OK); - - ret = (*a->compressor.write)(a, shar->work.s, shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - archive_string_empty(&shar->work); - - return (ARCHIVE_OK); + const char *g, *p, *u; + struct shar *shar; + int ret; + + shar = (struct shar *)a->format_data; + if (shar->entry == NULL) + return (0); + + if (shar->dump) { + /* Finish uuencoded data. */ + if (shar->has_data) { + if (shar->outpos > 0) + uuencode_line(a, shar, shar->outbuff, + shar->outpos); + archive_strcat(&shar->work, "`\nend\n"); + archive_strcat(&shar->work, "SHAR_END\n"); + } + /* Restore file mode, owner, flags. */ + /* + * TODO: Don't immediately restore mode for + * directories; defer that to end of script. + */ + archive_string_sprintf(&shar->work, "chmod %o ", + (unsigned int)(archive_entry_mode(shar->entry) & 07777)); + shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); + archive_strcat(&shar->work, "\n"); + + u = archive_entry_uname(shar->entry); + g = archive_entry_gname(shar->entry); + if (u != NULL || g != NULL) { + archive_strcat(&shar->work, "chown "); + if (u != NULL) + shar_quote(&shar->work, u, 1); + if (g != NULL) { + archive_strcat(&shar->work, ":"); + shar_quote(&shar->work, g, 1); + } + shar_quote(&shar->work, + archive_entry_pathname(shar->entry), 1); + archive_strcat(&shar->work, "\n"); + } + + if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { + archive_string_sprintf(&shar->work, "chflags %s ", p); + shar_quote(&shar->work, + archive_entry_pathname(shar->entry), 1); + archive_strcat(&shar->work, "\n"); + } + + /* TODO: restore ACLs */ + + } else { + if (shar->has_data) { + /* Finish sed-encoded data: ensure last line ends. */ + if (!shar->end_of_line) + archive_strappend_char(&shar->work, '\n'); + archive_strcat(&shar->work, "SHAR_END\n"); + } + } + + archive_entry_free(shar->entry); + shar->entry = NULL; + + if (shar->work.length < 65536) + return (ARCHIVE_OK); + + ret = __archive_write_output(a, shar->work.s, shar->work.length); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + archive_string_empty(&shar->work); + + return (ARCHIVE_OK); } static int -archive_write_shar_finish(struct archive_write *a) +archive_write_shar_close(struct archive_write *a) { - struct shar *shar; - int ret; - - /* - * TODO: Accumulate list of directory names/modes and - * fix them all up at end-of-archive. - */ - - shar = (struct shar *)a->format_data; - - /* - * Only write the end-of-archive markers if the archive was - * actually started. This avoids problems if someone sets - * shar format, then sets another format (which would invoke - * shar_finish to free the format-specific data). - */ - if (shar->wrote_header == 0) - return (ARCHIVE_OK); - - archive_strcat(&shar->work, "exit\n"); - - ret = (*a->compressor.write)(a, shar->work.s, shar->work.length); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* Shar output is never padded. */ - archive_write_set_bytes_in_last_block(&a->archive, 1); - /* - * TODO: shar should also suppress padding of - * uncompressed data within gzip/bzip2 streams. - */ - - return (ARCHIVE_OK); + struct shar *shar; + int ret; + + /* + * TODO: Accumulate list of directory names/modes and + * fix them all up at end-of-archive. + */ + + shar = (struct shar *)a->format_data; + + /* + * Only write the end-of-archive markers if the archive was + * actually started. This avoids problems if someone sets + * shar format, then sets another format (which would invoke + * shar_finish to free the format-specific data). + */ + if (shar->wrote_header == 0) + return (ARCHIVE_OK); + + archive_strcat(&shar->work, "exit\n"); + + ret = __archive_write_output(a, shar->work.s, shar->work.length); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + + /* Shar output is never padded. */ + archive_write_set_bytes_in_last_block(&a->archive, 1); + /* + * TODO: shar should also suppress padding of + * uncompressed data within gzip/bzip2 streams. + */ + + return (ARCHIVE_OK); } static int -archive_write_shar_destroy(struct archive_write *a) +archive_write_shar_free(struct archive_write *a) { - struct shar *shar; - - shar = (struct shar *)a->format_data; - if (shar == NULL) - return (ARCHIVE_OK); - - archive_entry_free(shar->entry); - free(shar->last_dir); - archive_string_free(&(shar->work)); - archive_string_free(&(shar->quoted_name)); - free(shar); - a->format_data = NULL; - return (ARCHIVE_OK); + struct shar *shar; + + shar = (struct shar *)a->format_data; + if (shar == NULL) + return (ARCHIVE_OK); + + archive_entry_free(shar->entry); + free(shar->last_dir); + archive_string_free(&(shar->work)); + archive_string_free(&(shar->quoted_name)); + free(shar); + a->format_data = NULL; + return (ARCHIVE_OK); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c index 5fe7a4361..4b96ac23c 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_ustar.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,7 +25,7 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_ustar.c,v 1.27 2008/05/26 17:00:23 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_ustar.c 191579 2009-04-27 18:35:03Z kientzle $"); #ifdef HAVE_ERRNO_H @@ -40,118 +41,124 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_write_set_format_ustar.c,v 1.27 2 #include "archive.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_write_private.h" struct ustar { - uint64_t entry_bytes_remaining; - uint64_t entry_padding; + uint64_t entry_bytes_remaining; + uint64_t entry_padding; + + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; }; /* * Define structure of POSIX 'ustar' tar header. */ -#define USTAR_name_offset 0 -#define USTAR_name_size 100 -#define USTAR_mode_offset 100 -#define USTAR_mode_size 6 -#define USTAR_mode_max_size 8 -#define USTAR_uid_offset 108 -#define USTAR_uid_size 6 -#define USTAR_uid_max_size 8 -#define USTAR_gid_offset 116 -#define USTAR_gid_size 6 -#define USTAR_gid_max_size 8 -#define USTAR_size_offset 124 -#define USTAR_size_size 11 -#define USTAR_size_max_size 12 -#define USTAR_mtime_offset 136 -#define USTAR_mtime_size 11 -#define USTAR_mtime_max_size 11 -#define USTAR_checksum_offset 148 -#define USTAR_checksum_size 8 -#define USTAR_typeflag_offset 156 -#define USTAR_typeflag_size 1 -#define USTAR_linkname_offset 157 -#define USTAR_linkname_size 100 -#define USTAR_magic_offset 257 -#define USTAR_magic_size 6 -#define USTAR_version_offset 263 -#define USTAR_version_size 2 -#define USTAR_uname_offset 265 -#define USTAR_uname_size 32 -#define USTAR_gname_offset 297 -#define USTAR_gname_size 32 -#define USTAR_rdevmajor_offset 329 -#define USTAR_rdevmajor_size 6 -#define USTAR_rdevmajor_max_size 8 -#define USTAR_rdevminor_offset 337 -#define USTAR_rdevminor_size 6 -#define USTAR_rdevminor_max_size 8 -#define USTAR_prefix_offset 345 -#define USTAR_prefix_size 155 -#define USTAR_padding_offset 500 -#define USTAR_padding_size 12 +#define USTAR_name_offset 0 +#define USTAR_name_size 100 +#define USTAR_mode_offset 100 +#define USTAR_mode_size 6 +#define USTAR_mode_max_size 8 +#define USTAR_uid_offset 108 +#define USTAR_uid_size 6 +#define USTAR_uid_max_size 8 +#define USTAR_gid_offset 116 +#define USTAR_gid_size 6 +#define USTAR_gid_max_size 8 +#define USTAR_size_offset 124 +#define USTAR_size_size 11 +#define USTAR_size_max_size 12 +#define USTAR_mtime_offset 136 +#define USTAR_mtime_size 11 +#define USTAR_mtime_max_size 11 +#define USTAR_checksum_offset 148 +#define USTAR_checksum_size 8 +#define USTAR_typeflag_offset 156 +#define USTAR_typeflag_size 1 +#define USTAR_linkname_offset 157 +#define USTAR_linkname_size 100 +#define USTAR_magic_offset 257 +#define USTAR_magic_size 6 +#define USTAR_version_offset 263 +#define USTAR_version_size 2 +#define USTAR_uname_offset 265 +#define USTAR_uname_size 32 +#define USTAR_gname_offset 297 +#define USTAR_gname_size 32 +#define USTAR_rdevmajor_offset 329 +#define USTAR_rdevmajor_size 6 +#define USTAR_rdevmajor_max_size 8 +#define USTAR_rdevminor_offset 337 +#define USTAR_rdevminor_size 6 +#define USTAR_rdevminor_max_size 8 +#define USTAR_prefix_offset 345 +#define USTAR_prefix_size 155 +#define USTAR_padding_offset 500 +#define USTAR_padding_size 12 /* * A filled-in copy of the header for initialization. */ static const char template_header[] = { - /* name: 100 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0, - /* Mode, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* uid, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* gid, space-null termination: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* size, space termation: 12 bytes */ - '0','0','0','0','0','0','0','0','0','0','0', ' ', - /* mtime, space termation: 12 bytes */ - '0','0','0','0','0','0','0','0','0','0','0', ' ', - /* Initial checksum value: 8 spaces */ - ' ',' ',' ',' ',' ',' ',' ',' ', - /* Typeflag: 1 byte */ - '0', /* '0' = regular file */ - /* Linkname: 100 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0, - /* Magic: 6 bytes, Version: 2 bytes */ - 'u','s','t','a','r','\0', '0','0', - /* Uname: 32 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - /* Gname: 32 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - /* rdevmajor + space/null padding: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* rdevminor + space/null padding: 8 bytes */ - '0','0','0','0','0','0', ' ','\0', - /* Prefix: 155 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0, - /* Padding: 12 bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0 + /* name: 100 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0, + /* Mode, space-null termination: 8 bytes */ + '0','0','0','0','0','0', ' ','\0', + /* uid, space-null termination: 8 bytes */ + '0','0','0','0','0','0', ' ','\0', + /* gid, space-null termination: 8 bytes */ + '0','0','0','0','0','0', ' ','\0', + /* size, space termation: 12 bytes */ + '0','0','0','0','0','0','0','0','0','0','0', ' ', + /* mtime, space termation: 12 bytes */ + '0','0','0','0','0','0','0','0','0','0','0', ' ', + /* Initial checksum value: 8 spaces */ + ' ',' ',' ',' ',' ',' ',' ',' ', + /* Typeflag: 1 byte */ + '0', /* '0' = regular file */ + /* Linkname: 100 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0, + /* Magic: 6 bytes, Version: 2 bytes */ + 'u','s','t','a','r','\0', '0','0', + /* Uname: 32 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + /* Gname: 32 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + /* rdevmajor + space/null padding: 8 bytes */ + '0','0','0','0','0','0', ' ','\0', + /* rdevminor + space/null padding: 8 bytes */ + '0','0','0','0','0','0', ' ','\0', + /* Prefix: 155 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0, + /* Padding: 12 bytes */ + 0,0,0,0,0,0,0,0, 0,0,0,0 }; -static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff, - size_t s); -static int archive_write_ustar_destroy(struct archive_write *); -static int archive_write_ustar_finish(struct archive_write *); -static int archive_write_ustar_finish_entry(struct archive_write *); -static int archive_write_ustar_header(struct archive_write *, - struct archive_entry *entry); -static int format_256(int64_t, char *, int); -static int format_number(int64_t, char *, int size, int max, int strict); -static int format_octal(int64_t, char *, int); -static int write_nulls(struct archive_write *a, size_t); +static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff, + size_t s); +static int archive_write_ustar_free(struct archive_write *); +static int archive_write_ustar_close(struct archive_write *); +static int archive_write_ustar_finish_entry(struct archive_write *); +static int archive_write_ustar_header(struct archive_write *, + struct archive_entry *entry); +static int archive_write_ustar_options(struct archive_write *, + const char *, const char *); +static int format_256(int64_t, char *, int); +static int format_number(int64_t, char *, int size, int max, int strict); +static int format_octal(int64_t, char *, int); /* * Set output format to 'ustar' format. @@ -159,88 +166,139 @@ static int write_nulls(struct archive_write *a, size_t); int archive_write_set_format_ustar(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct ustar *ustar; - - /* If someone else was already registered, unregister them. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - /* Basic internal sanity test. */ - if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", sizeof(template_header)); - return (ARCHIVE_FATAL); - } - - ustar = (struct ustar *)malloc(sizeof(*ustar)); - if (ustar == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate ustar data"); - return (ARCHIVE_FATAL); - } - memset(ustar, 0, sizeof(*ustar)); - a->format_data = ustar; - - a->pad_uncompressed = 1; /* Mimic gtar in this respect. */ - a->format_name = "ustar"; - a->format_write_header = archive_write_ustar_header; - a->format_write_data = archive_write_ustar_data; - a->format_finish = archive_write_ustar_finish; - a->format_destroy = archive_write_ustar_destroy; - a->format_finish_entry = archive_write_ustar_finish_entry; - a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; - a->archive.archive_format_name = "POSIX ustar"; - return (ARCHIVE_OK); + struct archive_write *a = (struct archive_write *)_a; + struct ustar *ustar; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_ustar"); + + /* If someone else was already registered, unregister them. */ + if (a->format_free != NULL) + (a->format_free)(a); + + /* Basic internal sanity test. */ + if (sizeof(template_header) != 512) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Internal: template_header wrong size: %zu should be 512", + sizeof(template_header)); + return (ARCHIVE_FATAL); + } + + ustar = (struct ustar *)malloc(sizeof(*ustar)); + if (ustar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate ustar data"); + return (ARCHIVE_FATAL); + } + memset(ustar, 0, sizeof(*ustar)); + a->format_data = ustar; + a->format_name = "ustar"; + a->format_options = archive_write_ustar_options; + a->format_write_header = archive_write_ustar_header; + a->format_write_data = archive_write_ustar_data; + a->format_close = archive_write_ustar_close; + a->format_free = archive_write_ustar_free; + a->format_finish_entry = archive_write_ustar_finish_entry; + a->archive.archive_format = ARCHIVE_FORMAT_TAR_USTAR; + a->archive.archive_format_name = "POSIX ustar"; + return (ARCHIVE_OK); +} + +static int +archive_write_ustar_options(struct archive_write *a, const char *key, + const char *val) +{ + struct ustar *ustar = (struct ustar *)a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: hdrcharset option needs a character-set name", + a->format_name); + else { + ustar->opt_sconv = archive_string_conversion_to_charset( + &a->archive, val, 0); + if (ustar->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: unknown keyword ``%s''", a->format_name, key); + + return (ret); } static int archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry) { - char buff[512]; - int ret, ret2; - struct ustar *ustar; - - ustar = (struct ustar *)a->format_data; - - /* Only regular files (not hardlinks) have data. */ - if (archive_entry_hardlink(entry) != NULL || - archive_entry_symlink(entry) != NULL || - !(archive_entry_filetype(entry) == AE_IFREG)) - archive_entry_set_size(entry, 0); - - if (AE_IFDIR == archive_entry_filetype(entry)) { - const char *p; - char *t; - /* - * Ensure a trailing '/'. Modify the entry so - * the client sees the change. - */ - p = archive_entry_pathname(entry); - if (p[strlen(p) - 1] != '/') { - t = (char *)malloc(strlen(p) + 2); - if (t == NULL) { - archive_set_error(&a->archive, ENOMEM, - "Can't allocate ustar data"); - return(ARCHIVE_FATAL); - } - strcpy(t, p); - strcat(t, "/"); - archive_entry_copy_pathname(entry, t); - free(t); - } - } - - ret = __archive_write_format_header_ustar(a, buff, entry, -1, 1); - if (ret < ARCHIVE_WARN) - return (ret); - ret2 = (a->compressor.write)(a, buff, 512); - if (ret2 < ARCHIVE_WARN) - return (ret2); - if (ret2 < ret) - ret = ret2; - - ustar->entry_bytes_remaining = archive_entry_size(entry); - ustar->entry_padding = 0x1ff & (-(int64_t)ustar->entry_bytes_remaining); - return (ret); + char buff[512]; + int ret, ret2; + struct ustar *ustar; + struct archive_string_conv *sconv; + + ustar = (struct ustar *)a->format_data; + + /* Setup default string conversion. */ + if (ustar->opt_sconv == NULL) { + if (!ustar->init_default_conversion) { + ustar->sconv_default = + archive_string_default_conversion_for_write(&(a->archive)); + ustar->init_default_conversion = 1; + } + sconv = ustar->sconv_default; + } else + sconv = ustar->opt_sconv; + + /* Sanity check. */ + if (archive_entry_pathname(entry) == NULL) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Can't record entry in tar file without pathname"); + return (ARCHIVE_FAILED); + } + + /* Only regular files (not hardlinks) have data. */ + if (archive_entry_hardlink(entry) != NULL || + archive_entry_symlink(entry) != NULL || + !(archive_entry_filetype(entry) == AE_IFREG)) + archive_entry_set_size(entry, 0); + + if (AE_IFDIR == archive_entry_filetype(entry)) { + const char *p; + char *t; + /* + * Ensure a trailing '/'. Modify the entry so + * the client sees the change. + */ + p = archive_entry_pathname(entry); + if (p[strlen(p) - 1] != '/') { + t = (char *)malloc(strlen(p) + 2); + if (t == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate ustar data"); + return(ARCHIVE_FATAL); + } + strcpy(t, p); + strcat(t, "/"); + archive_entry_copy_pathname(entry, t); + free(t); + } + } + + ret = __archive_write_format_header_ustar(a, buff, entry, -1, 1, sconv); + if (ret < ARCHIVE_WARN) + return (ret); + ret2 = __archive_write_output(a, buff, 512); + if (ret2 < ARCHIVE_WARN) + return (ret2); + if (ret2 < ret) + ret = ret2; + + ustar->entry_bytes_remaining = archive_entry_size(entry); + ustar->entry_padding = 0x1ff & (-(int64_t)ustar->entry_bytes_remaining); + return (ret); } /* @@ -255,186 +313,255 @@ archive_write_ustar_header(struct archive_write *a, struct archive_entry *entry) */ int __archive_write_format_header_ustar(struct archive_write *a, char h[512], - struct archive_entry *entry, int tartype, int strict) + struct archive_entry *entry, int tartype, int strict, + struct archive_string_conv *sconv) { - unsigned int checksum; - int i, ret; - size_t copy_length; - const char *p, *pp; - int mytartype; - - ret = 0; - mytartype = -1; - /* - * The "template header" already includes the "ustar" - * signature, various end-of-field markers and other required - * elements. - */ - memcpy(h, &template_header, 512); - - /* - * Because the block is already null-filled, and strings - * are allowed to exactly fill their destination (without null), - * I use memcpy(dest, src, strlen()) here a lot to copy strings. - */ - - pp = archive_entry_pathname(entry); - if (strlen(pp) <= USTAR_name_size) - memcpy(h + USTAR_name_offset, pp, strlen(pp)); - else { - /* Store in two pieces, splitting at a '/'. */ - p = strchr(pp + strlen(pp) - USTAR_name_size - 1, '/'); - /* - * Look for the next '/' if we chose the first character - * as the separator. (ustar format doesn't permit - * an empty prefix.) - */ - if (p == pp) - p = strchr(p + 1, '/'); - /* Fail if the name won't fit. */ - if (!p) { - /* No separator. */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else if (p[1] == '\0') { - /* - * The only feasible separator is a final '/'; - * this would result in a non-empty prefix and - * an empty name, which POSIX doesn't - * explicity forbid, but it just feels wrong. - */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else if (p > pp + USTAR_prefix_size) { - /* Prefix is too long. */ - archive_set_error(&a->archive, ENAMETOOLONG, - "Pathname too long"); - ret = ARCHIVE_FAILED; - } else { - /* Copy prefix and remainder to appropriate places */ - memcpy(h + USTAR_prefix_offset, pp, p - pp); - memcpy(h + USTAR_name_offset, p + 1, pp + strlen(pp) - p - 1); - } - } - - p = archive_entry_hardlink(entry); - if (p != NULL) - mytartype = '1'; - else - p = archive_entry_symlink(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (copy_length > USTAR_linkname_size) { - archive_set_error(&a->archive, ENAMETOOLONG, - "Link contents too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_linkname_size; - } - memcpy(h + USTAR_linkname_offset, p, copy_length); - } - - p = archive_entry_uname(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (copy_length > USTAR_uname_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Username too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_uname_size; - } - memcpy(h + USTAR_uname_offset, p, copy_length); - } - - p = archive_entry_gname(entry); - if (p != NULL && p[0] != '\0') { - copy_length = strlen(p); - if (strlen(p) > USTAR_gname_size) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Group name too long"); - ret = ARCHIVE_FAILED; - copy_length = USTAR_gname_size; - } - memcpy(h + USTAR_gname_offset, p, copy_length); - } - - if (format_number(archive_entry_mode(entry) & 07777, h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric mode too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_uid(entry), h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric user ID too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_gid(entry), h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "Numeric group ID too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_size(entry), h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, "File size out of range"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_mtime(entry), h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "File modification time too large"); - ret = ARCHIVE_FAILED; - } - - if (archive_entry_filetype(entry) == AE_IFBLK - || archive_entry_filetype(entry) == AE_IFCHR) { - if (format_number(archive_entry_rdevmajor(entry), h + USTAR_rdevmajor_offset, - USTAR_rdevmajor_size, USTAR_rdevmajor_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "Major device number too large"); - ret = ARCHIVE_FAILED; - } - - if (format_number(archive_entry_rdevminor(entry), h + USTAR_rdevminor_offset, - USTAR_rdevminor_size, USTAR_rdevminor_max_size, strict)) { - archive_set_error(&a->archive, ERANGE, - "Minor device number too large"); - ret = ARCHIVE_FAILED; - } - } - - if (tartype >= 0) { - h[USTAR_typeflag_offset] = tartype; - } else if (mytartype >= 0) { - h[USTAR_typeflag_offset] = mytartype; - } else { - switch (archive_entry_filetype(entry)) { - case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break; - case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break; - case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break; - case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break; - case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break; - case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break; - case AE_IFSOCK: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive socket"); - return (ARCHIVE_FAILED); - default: - archive_set_error(&a->archive, - ARCHIVE_ERRNO_FILE_FORMAT, - "tar format cannot archive this (mode=0%lo)", - (unsigned long)archive_entry_mode(entry)); - ret = ARCHIVE_FAILED; - } - } - - checksum = 0; - for (i = 0; i < 512; i++) - checksum += 255 & (unsigned int)h[i]; - h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */ - /* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */ - format_octal(checksum, h + USTAR_checksum_offset, 6); - return (ret); + unsigned int checksum; + int i, r, ret; + size_t copy_length; + const char *p, *pp; + int mytartype; + + ret = 0; + mytartype = -1; + /* + * The "template header" already includes the "ustar" + * signature, various end-of-field markers and other required + * elements. + */ + memcpy(h, &template_header, 512); + + /* + * Because the block is already null-filled, and strings + * are allowed to exactly fill their destination (without null), + * I use memcpy(dest, src, strlen()) here a lot to copy strings. + */ + r = archive_entry_pathname_l(entry, &pp, ©_length, sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", + pp, archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + if (copy_length <= USTAR_name_size) + memcpy(h + USTAR_name_offset, pp, copy_length); + else { + /* Store in two pieces, splitting at a '/'. */ + p = strchr(pp + copy_length - USTAR_name_size - 1, '/'); + /* + * Look for the next '/' if we chose the first character + * as the separator. (ustar format doesn't permit + * an empty prefix.) + */ + if (p == pp) + p = strchr(p + 1, '/'); + /* Fail if the name won't fit. */ + if (!p) { + /* No separator. */ + archive_set_error(&a->archive, ENAMETOOLONG, + "Pathname too long"); + ret = ARCHIVE_FAILED; + } else if (p[1] == '\0') { + /* + * The only feasible separator is a final '/'; + * this would result in a non-empty prefix and + * an empty name, which POSIX doesn't + * explicitly forbid, but it just feels wrong. + */ + archive_set_error(&a->archive, ENAMETOOLONG, + "Pathname too long"); + ret = ARCHIVE_FAILED; + } else if (p > pp + USTAR_prefix_size) { + /* Prefix is too long. */ + archive_set_error(&a->archive, ENAMETOOLONG, + "Pathname too long"); + ret = ARCHIVE_FAILED; + } else { + /* Copy prefix and remainder to appropriate places */ + memcpy(h + USTAR_prefix_offset, pp, p - pp); + memcpy(h + USTAR_name_offset, p + 1, + pp + copy_length - p - 1); + } + } + + r = archive_entry_hardlink_l(entry, &p, ©_length, sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + p, archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + if (copy_length > 0) + mytartype = '1'; + else { + r = archive_entry_symlink_l(entry, &p, ©_length, sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate linkname '%s' to %s", + p, archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + } + if (copy_length > 0) { + if (copy_length > USTAR_linkname_size) { + archive_set_error(&a->archive, ENAMETOOLONG, + "Link contents too long"); + ret = ARCHIVE_FAILED; + copy_length = USTAR_linkname_size; + } + memcpy(h + USTAR_linkname_offset, p, copy_length); + } + + r = archive_entry_uname_l(entry, &p, ©_length, sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate uname '%s' to %s", + p, archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + if (copy_length > 0) { + if (copy_length > USTAR_uname_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Username too long"); + ret = ARCHIVE_FAILED; + copy_length = USTAR_uname_size; + } + memcpy(h + USTAR_uname_offset, p, copy_length); + } + + r = archive_entry_gname_l(entry, &p, ©_length, sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate gname '%s' to %s", + p, archive_string_conversion_charset_name(sconv)); + ret = ARCHIVE_WARN; + } + if (copy_length > 0) { + if (strlen(p) > USTAR_gname_size) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Group name too long"); + ret = ARCHIVE_FAILED; + copy_length = USTAR_gname_size; + } + memcpy(h + USTAR_gname_offset, p, copy_length); + } + + if (format_number(archive_entry_mode(entry) & 07777, + h + USTAR_mode_offset, USTAR_mode_size, USTAR_mode_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "Numeric mode too large"); + ret = ARCHIVE_FAILED; + } + + if (format_number(archive_entry_uid(entry), + h + USTAR_uid_offset, USTAR_uid_size, USTAR_uid_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "Numeric user ID too large"); + ret = ARCHIVE_FAILED; + } + + if (format_number(archive_entry_gid(entry), + h + USTAR_gid_offset, USTAR_gid_size, USTAR_gid_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "Numeric group ID too large"); + ret = ARCHIVE_FAILED; + } + + if (format_number(archive_entry_size(entry), + h + USTAR_size_offset, USTAR_size_size, USTAR_size_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "File size out of range"); + ret = ARCHIVE_FAILED; + } + + if (format_number(archive_entry_mtime(entry), + h + USTAR_mtime_offset, USTAR_mtime_size, USTAR_mtime_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "File modification time too large"); + ret = ARCHIVE_FAILED; + } + + if (archive_entry_filetype(entry) == AE_IFBLK + || archive_entry_filetype(entry) == AE_IFCHR) { + if (format_number(archive_entry_rdevmajor(entry), + h + USTAR_rdevmajor_offset, USTAR_rdevmajor_size, + USTAR_rdevmajor_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "Major device number too large"); + ret = ARCHIVE_FAILED; + } + + if (format_number(archive_entry_rdevminor(entry), + h + USTAR_rdevminor_offset, USTAR_rdevminor_size, + USTAR_rdevminor_max_size, strict)) { + archive_set_error(&a->archive, ERANGE, + "Minor device number too large"); + ret = ARCHIVE_FAILED; + } + } + + if (tartype >= 0) { + h[USTAR_typeflag_offset] = tartype; + } else if (mytartype >= 0) { + h[USTAR_typeflag_offset] = mytartype; + } else { + switch (archive_entry_filetype(entry)) { + case AE_IFREG: h[USTAR_typeflag_offset] = '0' ; break; + case AE_IFLNK: h[USTAR_typeflag_offset] = '2' ; break; + case AE_IFCHR: h[USTAR_typeflag_offset] = '3' ; break; + case AE_IFBLK: h[USTAR_typeflag_offset] = '4' ; break; + case AE_IFDIR: h[USTAR_typeflag_offset] = '5' ; break; + case AE_IFIFO: h[USTAR_typeflag_offset] = '6' ; break; + case AE_IFSOCK: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive socket"); + return (ARCHIVE_FAILED); + default: + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "tar format cannot archive this (mode=0%lo)", + (unsigned long)archive_entry_mode(entry)); + ret = ARCHIVE_FAILED; + } + } + + checksum = 0; + for (i = 0; i < 512; i++) + checksum += 255 & (unsigned int)h[i]; + h[USTAR_checksum_offset + 6] = '\0'; /* Can't be pre-set in the template. */ + /* h[USTAR_checksum_offset + 7] = ' '; */ /* This is pre-set in the template. */ + format_octal(checksum, h + USTAR_checksum_offset, 6); + return (ret); } /* @@ -443,31 +570,31 @@ __archive_write_format_header_ustar(struct archive_write *a, char h[512], static int format_number(int64_t v, char *p, int s, int maxsize, int strict) { - int64_t limit; - - limit = ((int64_t)1 << (s*3)); - - /* "Strict" only permits octal values with proper termination. */ - if (strict) - return (format_octal(v, p, s)); - - /* - * In non-strict mode, we allow the number to overwrite one or - * more bytes of the field termination. Even old tar - * implementations should be able to handle this with no - * problem. - */ - if (v >= 0) { - while (s <= maxsize) { - if (v < limit) - return (format_octal(v, p, s)); - s++; - limit <<= 3; - } - } - - /* Base-256 can handle any number, positive or negative. */ - return (format_256(v, p, maxsize)); + int64_t limit; + + limit = ((int64_t)1 << (s*3)); + + /* "Strict" only permits octal values with proper termination. */ + if (strict) + return (format_octal(v, p, s)); + + /* + * In non-strict mode, we allow the number to overwrite one or + * more bytes of the field termination. Even old tar + * implementations should be able to handle this with no + * problem. + */ + if (v >= 0) { + while (s <= maxsize) { + if (v < limit) + return (format_octal(v, p, s)); + s++; + limit <<= 3; + } + } + + /* Base-256 can handle any number, positive or negative. */ + return (format_256(v, p, maxsize)); } /* @@ -476,13 +603,13 @@ format_number(int64_t v, char *p, int s, int maxsize, int strict) static int format_256(int64_t v, char *p, int s) { - p += s; - while (s-- > 0) { - *--p = (char)(v & 0xff); - v >>= 8; - } - *p |= 0x80; /* Set the base-256 marker bit. */ - return (0); + p += s; + while (s-- > 0) { + *--p = (char)(v & 0xff); + v >>= 8; + } + *p |= 0x80; /* Set the base-256 marker bit. */ + return (0); } /* @@ -491,97 +618,75 @@ format_256(int64_t v, char *p, int s) static int format_octal(int64_t v, char *p, int s) { - int len; + int len; - len = s; + len = s; - /* Octal values can't be negative, so use 0. */ - if (v < 0) { - while (len-- > 0) - *p++ = '0'; - return (-1); - } + /* Octal values can't be negative, so use 0. */ + if (v < 0) { + while (len-- > 0) + *p++ = '0'; + return (-1); + } - p += s; /* Start at the end and work backwards. */ - while (s-- > 0) { - *--p = (char)('0' + (v & 7)); - v >>= 3; - } + p += s; /* Start at the end and work backwards. */ + while (s-- > 0) { + *--p = (char)('0' + (v & 7)); + v >>= 3; + } - if (v == 0) - return (0); + if (v == 0) + return (0); - /* If it overflowed, fill field with max value. */ - while (len-- > 0) - *p++ = '7'; + /* If it overflowed, fill field with max value. */ + while (len-- > 0) + *p++ = '7'; - return (-1); + return (-1); } static int -archive_write_ustar_finish(struct archive_write *a) +archive_write_ustar_close(struct archive_write *a) { - int r; - - if (a->compressor.write == NULL) - return (ARCHIVE_OK); - - r = write_nulls(a, 512*2); - return (r); + return (__archive_write_nulls(a, 512*2)); } static int -archive_write_ustar_destroy(struct archive_write *a) +archive_write_ustar_free(struct archive_write *a) { - struct ustar *ustar; + struct ustar *ustar; - ustar = (struct ustar *)a->format_data; - free(ustar); - a->format_data = NULL; - return (ARCHIVE_OK); + ustar = (struct ustar *)a->format_data; + free(ustar); + a->format_data = NULL; + return (ARCHIVE_OK); } static int archive_write_ustar_finish_entry(struct archive_write *a) { - struct ustar *ustar; - int ret; - - ustar = (struct ustar *)a->format_data; - ret = write_nulls(a, - ustar->entry_bytes_remaining + ustar->entry_padding); - ustar->entry_bytes_remaining = ustar->entry_padding = 0; - return (ret); -} - -static int -write_nulls(struct archive_write *a, size_t padding) -{ - int ret; - size_t to_write; - - while (padding > 0) { - to_write = padding < a->null_length ? padding : a->null_length; - ret = (a->compressor.write)(a, a->nulls, to_write); - if (ret != ARCHIVE_OK) - return (ret); - padding -= to_write; - } - return (ARCHIVE_OK); + struct ustar *ustar; + int ret; + + ustar = (struct ustar *)a->format_data; + ret = __archive_write_nulls(a, + ustar->entry_bytes_remaining + ustar->entry_padding); + ustar->entry_bytes_remaining = ustar->entry_padding = 0; + return (ret); } static ssize_t archive_write_ustar_data(struct archive_write *a, const void *buff, size_t s) { - struct ustar *ustar; - int ret; - - ustar = (struct ustar *)a->format_data; - if (s > ustar->entry_bytes_remaining) - s = ustar->entry_bytes_remaining; - ret = (a->compressor.write)(a, buff, s); - ustar->entry_bytes_remaining -= s; - if (ret != ARCHIVE_OK) - return (ret); - return (s); + struct ustar *ustar; + int ret; + + ustar = (struct ustar *)a->format_data; + if (s > ustar->entry_bytes_remaining) + s = ustar->entry_bytes_remaining; + ret = __archive_write_output(a, buff, s); + ustar->entry_bytes_remaining -= s; + if (ret != ARCHIVE_OK) + return (ret); + return (s); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c new file mode 100644 index 000000000..96b7b2f92 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_xar.c @@ -0,0 +1,3171 @@ +/*- + * Copyright (c) 2010-2011 Michihiro NAKAJIMA + * 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$"); + +#ifdef HAVE_ERRNO_H +#include +#endif +#ifdef HAVE_LIMITS_H +#include +#endif +#include +#if HAVE_LIBXML_XMLWRITER_H +#include +#endif +#ifdef HAVE_BZLIB_H +#include +#endif +#if HAVE_LZMA_H +#include +#endif +#ifdef HAVE_ZLIB_H +#include +#endif + +#include "archive.h" +#include "archive_crypto_private.h" +#include "archive_endian.h" +#include "archive_entry.h" +#include "archive_entry_locale.h" +#include "archive_private.h" +#include "archive_rb.h" +#include "archive_string.h" +#include "archive_write_private.h" + +/* + * Differences to xar utility. + * - Subdocument is not supported yet. + * - ACL is not supported yet. + * - When writing an XML element , + * which is a file type a symbolic link is referencing is always marked + * as "broken". Xar utility uses stat(2) to get the file type, but, in + * libarcive format writer, we should not use it; if it is needed, we + * should get about it at archive_read_disk.c. + * - It is possible to appear both and elements. + * Xar utility generates on BSD platform and on Linux + * platform. + * + */ + +#if !(defined(HAVE_LIBXML_XMLWRITER_H) && defined(LIBXML_VERSION) &&\ + LIBXML_VERSION >= 20703) ||\ + !defined(HAVE_ZLIB_H) || \ + !defined(ARCHIVE_HAS_MD5) || !defined(ARCHIVE_HAS_SHA1) +/* + * xar needs several external libraries. + * o libxml2 + * o openssl or MD5/SHA1 hash function + * o zlib + * o bzlib2 (option) + * o liblzma (option) + */ +int +archive_write_set_format_xar(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Xar not supported on this platform"); + return (ARCHIVE_WARN); +} + +#else /* Support xar format */ + +/*#define DEBUG_PRINT_TOC 1 */ + +#define HEADER_MAGIC 0x78617221 +#define HEADER_SIZE 28 +#define HEADER_VERSION 1 + +enum sumalg { + CKSUM_NONE = 0, + CKSUM_SHA1 = 1, + CKSUM_MD5 = 2 +}; + +#define MD5_SIZE 16 +#define SHA1_SIZE 20 +#define MAX_SUM_SIZE 20 +#define MD5_NAME "md5" +#define SHA1_NAME "sha1" + +enum enctype { + NONE, + GZIP, + BZIP2, + LZMA, + XZ, +}; + +struct chksumwork { + enum sumalg alg; +#ifdef ARCHIVE_HAS_MD5 + archive_md5_ctx md5ctx; +#endif +#ifdef ARCHIVE_HAS_SHA1 + archive_sha1_ctx sha1ctx; +#endif +}; + +enum la_zaction { + ARCHIVE_Z_FINISH, + ARCHIVE_Z_RUN +}; + +/* + * Universal zstream. + */ +struct la_zstream { + const unsigned char *next_in; + size_t avail_in; + uint64_t total_in; + + unsigned char *next_out; + size_t avail_out; + uint64_t total_out; + + int valid; + void *real_stream; + int (*code) (struct archive *a, + struct la_zstream *lastrm, + enum la_zaction action); + int (*end)(struct archive *a, + struct la_zstream *lastrm); +}; + +struct chksumval { + enum sumalg alg; + size_t len; + unsigned char val[MAX_SUM_SIZE]; +}; + +struct heap_data { + int id; + struct heap_data *next; + uint64_t temp_offset; + uint64_t length; /* archived size. */ + uint64_t size; /* extracted size. */ + enum enctype compression; + struct chksumval a_sum; /* archived checksum. */ + struct chksumval e_sum; /* extracted checksum. */ +}; + +struct file { + struct archive_rb_node rbnode; + + int id; + struct archive_entry *entry; + + struct archive_rb_tree rbtree; + struct file *next; + struct file *chnext; + struct file *hlnext; + /* For hardlinked files. + * Use only when archive_entry_nlink() > 1 */ + struct file *hardlink_target; + struct file *parent; /* parent directory entry */ + /* + * To manage sub directory files. + * We use 'chnext' a menber of struct file to chain. + */ + struct { + struct file *first; + struct file **last; + } children; + + /* For making a directory tree. */ + struct archive_string parentdir; + struct archive_string basename; + struct archive_string symlink; + + int ea_idx; + struct { + struct heap_data *first; + struct heap_data **last; + } xattr; + struct heap_data data; + struct archive_string script; + + int virtual:1; + int dir:1; +}; + +struct hardlink { + struct archive_rb_node rbnode; + int nlink; + struct { + struct file *first; + struct file **last; + } file_list; +}; + +struct xar { + int temp_fd; + uint64_t temp_offset; + + int file_idx; + struct file *root; + struct file *cur_dirent; + struct archive_string cur_dirstr; + struct file *cur_file; + uint64_t bytes_remaining; + struct archive_string tstr; + struct archive_string vstr; + + enum sumalg opt_toc_sumalg; + enum sumalg opt_sumalg; + enum enctype opt_compression; + int opt_compression_level; + + struct chksumwork a_sumwrk; /* archived checksum. */ + struct chksumwork e_sumwrk; /* extracted checksum. */ + struct la_zstream stream; + struct archive_string_conv *sconv; + /* + * Compressed data buffer. + */ + unsigned char wbuff[1024 * 64]; + size_t wbuff_remaining; + + struct heap_data toc; + /* + * The list of all file entries is used to manage struct file + * objects. + * We use 'next' a menber of struct file to chain. + */ + struct { + struct file *first; + struct file **last; + } file_list; + /* + * The list of hard-linked file entries. + * We use 'hlnext' a menber of struct file to chain. + */ + struct archive_rb_tree hardlink_rbtree; +}; + +static int xar_options(struct archive_write *, + const char *, const char *); +static int xar_write_header(struct archive_write *, + struct archive_entry *); +static ssize_t xar_write_data(struct archive_write *, + const void *, size_t); +static int xar_finish_entry(struct archive_write *); +static int xar_close(struct archive_write *); +static int xar_free(struct archive_write *); + +static struct file *file_new(struct archive_write *a, struct archive_entry *); +static void file_free(struct file *); +static struct file *file_create_virtual_dir(struct archive_write *a, struct xar *, + const char *); +static int file_add_child_tail(struct file *, struct file *); +static struct file *file_find_child(struct file *, const char *); +static int file_gen_utility_names(struct archive_write *, + struct file *); +static int get_path_component(char *, int, const char *); +static int file_tree(struct archive_write *, struct file **); +static void file_register(struct xar *, struct file *); +static void file_init_register(struct xar *); +static void file_free_register(struct xar *); +static int file_register_hardlink(struct archive_write *, + struct file *); +static void file_connect_hardlink_files(struct xar *); +static void file_init_hardlinks(struct xar *); +static void file_free_hardlinks(struct xar *); + +static void checksum_init(struct chksumwork *, enum sumalg); +static void checksum_update(struct chksumwork *, const void *, size_t); +static void checksum_final(struct chksumwork *, struct chksumval *); +static int compression_init_encoder_gzip(struct archive *, + struct la_zstream *, int, int); +static int compression_code_gzip(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_gzip(struct archive *, struct la_zstream *); +static int compression_init_encoder_bzip2(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int compression_code_bzip2(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_bzip2(struct archive *, struct la_zstream *); +#endif +static int compression_init_encoder_lzma(struct archive *, + struct la_zstream *, int); +static int compression_init_encoder_xz(struct archive *, + struct la_zstream *, int); +#if defined(HAVE_LZMA_H) +static int compression_code_lzma(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end_lzma(struct archive *, struct la_zstream *); +#endif +static int xar_compression_init_encoder(struct archive_write *); +static int compression_code(struct archive *, + struct la_zstream *, enum la_zaction); +static int compression_end(struct archive *, + struct la_zstream *); +static int save_xattrs(struct archive_write *, struct file *); +static int getalgsize(enum sumalg); +static const char *getalgname(enum sumalg); + +int +archive_write_set_format_xar(struct archive *_a) +{ + struct archive_write *a = (struct archive_write *)_a; + struct xar *xar; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_xar"); + + /* If another format was already registered, unregister it. */ + if (a->format_free != NULL) + (a->format_free)(a); + + xar = calloc(1, sizeof(*xar)); + if (xar == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate xar data"); + return (ARCHIVE_FATAL); + } + xar->temp_fd = -1; + file_init_register(xar); + file_init_hardlinks(xar); + archive_string_init(&(xar->tstr)); + archive_string_init(&(xar->vstr)); + + /* + * Create the root directory. + */ + xar->root = file_create_virtual_dir(a, xar, ""); + if (xar->root == NULL) { + free(xar); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate xar data"); + return (ARCHIVE_FATAL); + } + xar->root->parent = xar->root; + file_register(xar, xar->root); + xar->cur_dirent = xar->root; + archive_string_init(&(xar->cur_dirstr)); + archive_string_ensure(&(xar->cur_dirstr), 1); + xar->cur_dirstr.s[0] = 0; + + /* + * Initialize option. + */ + /* Set default checksum type. */ + xar->opt_toc_sumalg = CKSUM_SHA1; + xar->opt_sumalg = CKSUM_SHA1; + /* Set default compression type and level. */ + xar->opt_compression = GZIP; + xar->opt_compression_level = 6; + + a->format_data = xar; + + a->format_name = "xar"; + a->format_options = xar_options; + a->format_write_header = xar_write_header; + a->format_write_data = xar_write_data; + a->format_finish_entry = xar_finish_entry; + a->format_close = xar_close; + a->format_free = xar_free; + a->archive.archive_format = ARCHIVE_FORMAT_XAR; + a->archive.archive_format_name = "xar"; + + return (ARCHIVE_OK); +} + +static int +xar_options(struct archive_write *a, const char *key, const char *value) +{ + struct xar *xar; + + xar = (struct xar *)a->format_data; + + if (strcmp(key, "checksum") == 0) { + if (value == NULL) + xar->opt_sumalg = CKSUM_NONE; + else if (strcmp(value, "sha1") == 0) + xar->opt_sumalg = CKSUM_SHA1; + else if (strcmp(value, "md5") == 0) + xar->opt_sumalg = CKSUM_MD5; + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unkonwn checksum name: `%s'", + value); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); + } + if (strcmp(key, "compression") == 0) { + const char *name = NULL; + + if (value == NULL) + xar->opt_compression = NONE; + else if (strcmp(value, "gzip") == 0) + xar->opt_compression = GZIP; + else if (strcmp(value, "bzip2") == 0) +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) + xar->opt_compression = BZIP2; +#else + name = "bzip2"; +#endif + else if (strcmp(value, "lzma") == 0) +#if HAVE_LZMA_H + xar->opt_compression = LZMA; +#else + name = "lzma"; +#endif + else if (strcmp(value, "xz") == 0) +#if HAVE_LZMA_H + xar->opt_compression = XZ; +#else + name = "xz"; +#endif + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unkonwn compression name: `%s'", + value); + return (ARCHIVE_FAILED); + } + if (name != NULL) { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "`%s' compression not supported " + "on this platform", + name); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); + } + if (strcmp(key, "compression-level") == 0) { + if (value == NULL || + !(value[0] >= '0' && value[0] <= '9') || + value[1] != '\0') { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Illeagal value `%s'", + value); + return (ARCHIVE_FAILED); + } + xar->opt_compression_level = value[0] - '0'; + return (ARCHIVE_OK); + } + if (strcmp(key, "toc-checksum") == 0) { + if (value == NULL) + xar->opt_toc_sumalg = CKSUM_NONE; + else if (strcmp(value, "sha1") == 0) + xar->opt_toc_sumalg = CKSUM_SHA1; + else if (strcmp(value, "md5") == 0) + xar->opt_toc_sumalg = CKSUM_MD5; + else { + archive_set_error(&(a->archive), + ARCHIVE_ERRNO_MISC, + "Unkonwn checksum name: `%s'", + value); + return (ARCHIVE_FAILED); + } + return (ARCHIVE_OK); + } + + return (ARCHIVE_FAILED); +} + +static int +xar_write_header(struct archive_write *a, struct archive_entry *entry) +{ + struct xar *xar; + struct file *file; + struct archive_entry *file_entry; + int r, r2; + + xar = (struct xar *)a->format_data; + xar->cur_file = NULL; + xar->bytes_remaining = 0; + + if (xar->sconv == NULL) { + xar->sconv = archive_string_conversion_to_charset( + &a->archive, "UTF-8", 1); + if (xar->sconv == NULL) + return (ARCHIVE_FATAL); + } + + file = file_new(a, entry); + if (file == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate data"); + return (ARCHIVE_FATAL); + } + r2 = file_gen_utility_names(a, file); + if (r2 < ARCHIVE_WARN) + return (r2); + + /* + * Ignore a path which looks like the top of directory name + * since we have already made the root directory of an Xar archive. + */ + if (archive_strlen(&(file->parentdir)) == 0 && + archive_strlen(&(file->basename)) == 0) { + file_free(file); + return (r2); + } + + /* Add entry into tree */ + file_entry = file->entry; + r = file_tree(a, &file); + if (r != ARCHIVE_OK) + return (r); + /* There is the same file in tree and + * the current file is older than the file in tree. + * So we don't need the current file data anymore. */ + if (file->entry != file_entry) + return (r2); + if (file->id == 0) + file_register(xar, file); + + /* A virtual file, which is a directory, does not have + * any contents and we won't store it into a archive + * file other than its name. */ + if (file->virtual) + return (r2); + + /* + * Prepare to save the contents of the file. + */ + if (xar->temp_fd == -1) { + int algsize; + xar->temp_offset = 0; + xar->temp_fd = __archive_mktemp(NULL); + if (xar->temp_fd < 0) { + archive_set_error(&a->archive, errno, + "Couldn't create temporary file"); + return (ARCHIVE_FATAL); + } + algsize = getalgsize(xar->opt_toc_sumalg); + if (algsize > 0) { + if (lseek(xar->temp_fd, algsize, SEEK_SET) < 0) { + archive_set_error(&(a->archive), errno, + "lseek failed"); + return (ARCHIVE_FATAL); + } + xar->temp_offset = algsize; + } + } + + if (archive_entry_hardlink(file->entry) == NULL) { + r = save_xattrs(a, file); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + + /* Non regular files contents are unneeded to be saved to + * a temporary file. */ + if (archive_entry_filetype(file->entry) != AE_IFREG) + return (r2); + + /* + * Set the current file to cur_file to read its contents. + */ + xar->cur_file = file; + + if (archive_entry_nlink(file->entry) > 1) { + r = file_register_hardlink(a, file); + if (r != ARCHIVE_OK) + return (r); + if (archive_entry_hardlink(file->entry) != NULL) { + archive_entry_unset_size(file->entry); + return (r2); + } + } + + /* Save a offset of current file in temporary file. */ + file->data.temp_offset = xar->temp_offset; + file->data.size = archive_entry_size(file->entry); + file->data.compression = xar->opt_compression; + xar->bytes_remaining = archive_entry_size(file->entry); + checksum_init(&(xar->a_sumwrk), xar->opt_sumalg); + checksum_init(&(xar->e_sumwrk), xar->opt_sumalg); + r = xar_compression_init_encoder(a); + + if (r != ARCHIVE_OK) + return (r); + else + return (r2); +} + +static int +write_to_temp(struct archive_write *a, const void *buff, size_t s) +{ + struct xar *xar; + unsigned char *p; + ssize_t ws; + + xar = (struct xar *)a->format_data; + p = (unsigned char *)buff; + while (s) { + ws = write(xar->temp_fd, p, s); + if (ws < 0) { + archive_set_error(&(a->archive), errno, + "fwrite function failed"); + return (ARCHIVE_FATAL); + } + s -= ws; + p += ws; + xar->temp_offset += ws; + } + return (ARCHIVE_OK); +} + +static ssize_t +xar_write_data(struct archive_write *a, const void *buff, size_t s) +{ + struct xar *xar; + enum la_zaction run; + size_t size, rsize; + int r; + + xar = (struct xar *)a->format_data; + + if (s > xar->bytes_remaining) + s = xar->bytes_remaining; + if (s == 0 || xar->cur_file == NULL) + return (0); + if (xar->cur_file->data.compression == NONE) { + checksum_update(&(xar->e_sumwrk), buff, s); + checksum_update(&(xar->a_sumwrk), buff, s); + size = rsize = s; + } else { + xar->stream.next_in = (const unsigned char *)buff; + xar->stream.avail_in = s; + if (xar->bytes_remaining > s) + run = ARCHIVE_Z_RUN; + else + run = ARCHIVE_Z_FINISH; + /* Compress file data. */ + r = compression_code(&(a->archive), &(xar->stream), run); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) + return (ARCHIVE_FATAL); + rsize = s - xar->stream.avail_in; + checksum_update(&(xar->e_sumwrk), buff, rsize); + size = sizeof(xar->wbuff) - xar->stream.avail_out; + checksum_update(&(xar->a_sumwrk), xar->wbuff, size); + } +#if !defined(_WIN32) || defined(__CYGWIN__) + if (xar->bytes_remaining == + archive_entry_size(xar->cur_file->entry)) { + /* + * Get the path of a shell script if so. + */ + const unsigned char *b = (const unsigned char *)buff; + + archive_string_empty(&(xar->cur_file->script)); + if (rsize > 2 && b[0] == '#' && b[1] == '!') { + size_t i, end, off; + + off = 2; + if (b[off] == ' ') + off++; +#ifdef PATH_MAX + if ((rsize - off) > PATH_MAX) + end = off + PATH_MAX; + else +#endif + end = rsize; + /* Find the end of a script path. */ + for (i = off; i < end && b[i] != '\0' && + b[i] != '\n' && b[i] != '\r' && + b[i] != ' ' && b[i] != '\t'; i++) + ; + archive_strncpy(&(xar->cur_file->script), b + off, + i - off); + } + } +#endif + + if (xar->cur_file->data.compression == NONE) { + if (write_to_temp(a, buff, size) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } else { + if (write_to_temp(a, xar->wbuff, size) != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + xar->bytes_remaining -= rsize; + xar->cur_file->data.length += size; + + return (rsize); +} + +static int +xar_finish_entry(struct archive_write *a) +{ + struct xar *xar; + struct file *file; + size_t s; + ssize_t w; + + xar = (struct xar *)a->format_data; + if (xar->cur_file == NULL) + return (ARCHIVE_OK); + + while (xar->bytes_remaining > 0) { + s = xar->bytes_remaining; + if (s > a->null_length) + s = a->null_length; + w = xar_write_data(a, a->nulls, s); + if (w > 0) + xar->bytes_remaining -= w; + else + return (w); + } + file = xar->cur_file; + checksum_final(&(xar->e_sumwrk), &(file->data.e_sum)); + checksum_final(&(xar->a_sumwrk), &(file->data.a_sum)); + xar->cur_file = NULL; + + return (ARCHIVE_OK); +} + +static int +xmlwrite_string_attr(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, const char *value, + const char *attrkey, const char *attrvalue) +{ + int r; + + r = xmlTextWriterStartElement(writer, BAD_CAST(key)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + if (attrkey != NULL && attrvalue != NULL) { + r = xmlTextWriterWriteAttribute(writer, + BAD_CAST(attrkey), BAD_CAST(attrvalue)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + if (value != NULL) { + r = xmlTextWriterWriteString(writer, BAD_CAST(value)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteString() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static int +xmlwrite_string(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, const char *value) +{ + int r; + + if (value == NULL) + return (ARCHIVE_OK); + + r = xmlTextWriterStartElement(writer, BAD_CAST(key)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + if (value != NULL) { + r = xmlTextWriterWriteString(writer, BAD_CAST(value)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteString() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static int +xmlwrite_fstring(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, const char *fmt, ...) +{ + struct xar *xar; + va_list ap; + + xar = (struct xar *)a->format_data; + va_start(ap, fmt); + archive_string_empty(&xar->vstr); + archive_string_vsprintf(&xar->vstr, fmt, ap); + va_end(ap); + return (xmlwrite_string(a, writer, key, xar->vstr.s)); +} + +static int +xmlwrite_time(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, time_t t, int z) +{ + char timestr[100]; + struct tm tm; + +#if defined(HAVE_GMTIME_R) + gmtime_r(&t, &tm); +#elif defined(HAVE__GMTIME64_S) + _gmtime64_s(&tm, &t); +#else + memcpy(&tm, gmtime(&t), sizeof(tm)); +#endif + memset(×tr, 0, sizeof(timestr)); + /* Do not use %F and %T for portability. */ + strftime(timestr, sizeof(timestr), "%Y-%m-%dT%H:%M:%S", &tm); + if (z) + strcat(timestr, "Z"); + return (xmlwrite_string(a, writer, key, timestr)); +} + +static int +xmlwrite_mode(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, mode_t mode) +{ + char ms[5]; + + ms[0] = '0'; + ms[1] = '0' + ((mode >> 6) & 07); + ms[2] = '0' + ((mode >> 3) & 07); + ms[3] = '0' + (mode & 07); + ms[4] = '\0'; + + return (xmlwrite_string(a, writer, key, ms)); +} + +static int +xmlwrite_sum(struct archive_write *a, xmlTextWriterPtr writer, + const char *key, struct chksumval *sum) +{ + const char *algname; + int algsize; + char buff[MAX_SUM_SIZE*2 + 1]; + char *p; + unsigned char *s; + int i, r; + + if (sum->len > 0) { + algname = getalgname(sum->alg); + algsize = getalgsize(sum->alg); + if (algname != NULL) { + const char *hex = "0123456789abcdef"; + p = buff; + s = sum->val; + for (i = 0; i < algsize; i++) { + *p++ = hex[(*s >> 4)]; + *p++ = hex[(*s & 0x0f)]; + s++; + } + *p = '\0'; + r = xmlwrite_string_attr(a, writer, + key, buff, + "style", algname); + if (r < 0) + return (ARCHIVE_FATAL); + } + } + return (ARCHIVE_OK); +} + +static int +xmlwrite_heap(struct archive_write *a, xmlTextWriterPtr writer, + struct heap_data *heap) +{ + const char *encname; + int r; + + r = xmlwrite_fstring(a, writer, "length", "%ju", heap->length); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_fstring(a, writer, "offset", "%ju", heap->temp_offset); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_fstring(a, writer, "size", "%ju", heap->size); + if (r < 0) + return (ARCHIVE_FATAL); + switch (heap->compression) { + case GZIP: + encname = "application/x-gzip"; break; + case BZIP2: + encname = "application/x-bzip2"; break; + case LZMA: + encname = "application/x-lzma"; break; + case XZ: + encname = "application/x-xz"; break; + default: + encname = "application/octet-stream"; break; + } + r = xmlwrite_string_attr(a, writer, "encoding", NULL, + "style", encname); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_sum(a, writer, "archived-checksum", &(heap->a_sum)); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_sum(a, writer, "extracted-checksum", &(heap->e_sum)); + if (r < 0) + return (ARCHIVE_FATAL); + return (ARCHIVE_OK); +} + +/* + * xar utility records fflags as following xml elements: + * + * + * ..... + * + * or + * + * + * ..... + * + * If xar is running on BSD platform, records ..; + * if xar is running on linux platform, records ..; + * otherwise does not record. + * + * Our implements records both and if it's necessary. + */ +static int +make_fflags_entry(struct archive_write *a, xmlTextWriterPtr writer, + const char *element, const char *fflags_text) +{ + static const struct flagentry { + const char *name; + const char *xarname; + } + flagbsd[] = { + { "sappnd", "SystemAppend"}, + { "sappend", "SystemAppend"}, + { "arch", "SystemArchived"}, + { "archived", "SystemArchived"}, + { "schg", "SystemImmutable"}, + { "schange", "SystemImmutable"}, + { "simmutable", "SystemImmutable"}, + { "nosunlnk", "SystemNoUnlink"}, + { "nosunlink", "SystemNoUnlink"}, + { "snapshot", "SystemSnapshot"}, + { "uappnd", "UserAppend"}, + { "uappend", "UserAppend"}, + { "uchg", "UserImmutable"}, + { "uchange", "UserImmutable"}, + { "uimmutable", "UserImmutable"}, + { "nodump", "UserNoDump"}, + { "noopaque", "UserOpaque"}, + { "nouunlnk", "UserNoUnlink"}, + { "nouunlink", "UserNoUnlink"}, + { NULL, NULL} + }, + flagext2[] = { + { "sappnd", "AppendOnly"}, + { "sappend", "AppendOnly"}, + { "schg", "Immutable"}, + { "schange", "Immutable"}, + { "simmutable", "Immutable"}, + { "nodump", "NoDump"}, + { "nouunlnk", "Undelete"}, + { "nouunlink", "Undelete"}, + { "btree", "BTree"}, + { "comperr", "CompError"}, + { "compress", "Compress"}, + { "noatime", "NoAtime"}, + { "compdirty", "CompDirty"}, + { "comprblk", "CompBlock"}, + { "dirsync", "DirSync"}, + { "hashidx", "HashIndexed"}, + { "imagic", "iMagic"}, + { "journal", "Journaled"}, + { "securedeletion", "SecureDeletion"}, + { "sync", "Synchronous"}, + { "notail", "NoTail"}, + { "topdir", "TopDir"}, + { "reserved", "Reserved"}, + { NULL, NULL} + }; + const struct flagentry *fe, *flagentry; +#define FLAGENTRY_MAXSIZE ((sizeof(flagbsd)+sizeof(flagext2))/sizeof(flagbsd)) + const struct flagentry *avail[FLAGENTRY_MAXSIZE]; + const char *p; + int i, n, r; + + if (strcmp(element, "ext2") == 0) + flagentry = flagext2; + else + flagentry = flagbsd; + n = 0; + p = fflags_text; + do { + const char *cp; + + cp = strchr(p, ','); + if (cp == NULL) + cp = p + strlen(p); + + for (fe = flagentry; fe->name != NULL; fe++) { + if (fe->name[cp - p] != '\0' + || p[0] != fe->name[0]) + continue; + if (strncmp(p, fe->name, cp - p) == 0) { + avail[n++] = fe; + break; + } + } + if (*cp == ',') + p = cp + 1; + else + p = NULL; + } while (p != NULL); + + if (n > 0) { + r = xmlTextWriterStartElement(writer, BAD_CAST(element)); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + for (i = 0; i < n; i++) { + r = xmlwrite_string(a, writer, + avail[i]->xarname, NULL); + if (r != ARCHIVE_OK) + return (r); + } + + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + return (ARCHIVE_OK); +} + +static int +make_file_entry(struct archive_write *a, xmlTextWriterPtr writer, + struct file *file) +{ + struct xar *xar; + const char *filetype, *filelink, *fflags; + struct archive_string linkto; + struct heap_data *heap; + unsigned char *tmp; + const char *p; + size_t len; + int r, r2, l, ll; + + xar = (struct xar *)a->format_data; + r2 = ARCHIVE_OK; + + /* + * Make a file name entry, "". + */ + l = ll = archive_strlen(&(file->basename)); + tmp = malloc(l); + if (tmp == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + r = UTF8Toisolat1(tmp, &l, BAD_CAST(file->basename.s), &ll); + free(tmp); + if (r < 0) { + r = xmlTextWriterStartElement(writer, BAD_CAST("name")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlTextWriterWriteAttribute(writer, + BAD_CAST("enctype"), BAD_CAST("base64")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlTextWriterWriteBase64(writer, file->basename.s, + 0, archive_strlen(&(file->basename))); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteBase64() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + } else { + r = xmlwrite_string(a, writer, "name", file->basename.s); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a file type entry, "". + */ + filelink = NULL; + archive_string_init(&linkto); + switch (archive_entry_filetype(file->entry)) { + case AE_IFDIR: + filetype = "directory"; break; + case AE_IFLNK: + filetype = "symlink"; break; + case AE_IFCHR: + filetype = "character special"; break; + case AE_IFBLK: + filetype = "block special"; break; + case AE_IFSOCK: + filetype = "socket"; break; + case AE_IFIFO: + filetype = "fifo"; break; + case AE_IFREG: + default: + if (file->hardlink_target != NULL) { + filetype = "hardlink"; + filelink = "link"; + if (file->hardlink_target == file) + archive_strcpy(&linkto, "original"); + else + archive_string_sprintf(&linkto, "%d", + file->hardlink_target->id); + } else + filetype = "file"; + break; + } + r = xmlwrite_string_attr(a, writer, "type", filetype, + filelink, linkto.s); + archive_string_free(&linkto); + if (r < 0) + return (ARCHIVE_FATAL); + + /* + * On a virtual directory, we record "name" and "type" only. + */ + if (file->virtual) + return (ARCHIVE_OK); + + switch (archive_entry_filetype(file->entry)) { + case AE_IFLNK: + /* + * xar utility has checked a file type, which + * a symblic-link file has referenced. + * For example: + * ../ref/ + * The symlink target file is "../ref/" and its + * file type is a directory. + * + * ../f + * The symlink target file is "../f" and its + * file type is a regular file. + * + * But our implemention cannot do it, and then we + * always record that a attribute "type" is "borken", + * for example: + * foo/bar + * It means "foo/bar" is not reachable. + */ + r = xmlwrite_string_attr(a, writer, "link", + file->symlink.s, + "type", "broken"); + if (r < 0) + return (ARCHIVE_FATAL); + break; + case AE_IFCHR: + case AE_IFBLK: + r = xmlTextWriterStartElement(writer, BAD_CAST("device")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlwrite_fstring(a, writer, "major", + "%d", archive_entry_rdevmajor(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_fstring(a, writer, "minor", + "%d", archive_entry_rdevminor(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + break; + default: + break; + } + + /* + * Make a inode entry, "". + */ + r = xmlwrite_fstring(a, writer, "inode", + "%jd", archive_entry_ino64(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + if (archive_entry_dev(file->entry) != 0) { + r = xmlwrite_fstring(a, writer, "deviceno", + "%d", archive_entry_dev(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a file mode entry, "". + */ + r = xmlwrite_mode(a, writer, "mode", + archive_entry_mode(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + + /* + * Make a user entry, "" and ". + */ + r = xmlwrite_fstring(a, writer, "uid", + "%d", archive_entry_uid(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + r = archive_entry_uname_l(file->entry, &p, &len, xar->sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Uname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate uname '%s' to UTF-8", + archive_entry_uname(file->entry)); + r2 = ARCHIVE_WARN; + } + if (len > 0) { + r = xmlwrite_string(a, writer, "user", p); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a group entry, "" and ". + */ + r = xmlwrite_fstring(a, writer, "gid", + "%d", archive_entry_gid(file->entry)); + if (r < 0) + return (ARCHIVE_FATAL); + r = archive_entry_gname_l(file->entry, &p, &len, xar->sconv); + if (r != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Gname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate gname '%s' to UTF-8", + archive_entry_gname(file->entry)); + r2 = ARCHIVE_WARN; + } + if (len > 0) { + r = xmlwrite_string(a, writer, "group", p); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a ctime entry, "". + */ + if (archive_entry_ctime_is_set(file->entry)) { + r = xmlwrite_time(a, writer, "ctime", + archive_entry_ctime(file->entry), 1); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a mtime entry, "". + */ + if (archive_entry_mtime_is_set(file->entry)) { + r = xmlwrite_time(a, writer, "mtime", + archive_entry_mtime(file->entry), 1); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make a atime entry, "". + */ + if (archive_entry_atime_is_set(file->entry)) { + r = xmlwrite_time(a, writer, "atime", + archive_entry_atime(file->entry), 1); + if (r < 0) + return (ARCHIVE_FATAL); + } + + /* + * Make fflags entries, "" and "". + */ + fflags = archive_entry_fflags_text(file->entry); + if (fflags != NULL) { + r = make_fflags_entry(a, writer, "flags", fflags); + if (r < 0) + return (r); + r = make_fflags_entry(a, writer, "ext2", fflags); + if (r < 0) + return (r); + } + + /* + * Make extended attribute entries, "". + */ + archive_entry_xattr_reset(file->entry); + for (heap = file->xattr.first; heap != NULL; heap = heap->next) { + const char *name; + const void *value; + size_t size; + + archive_entry_xattr_next(file->entry, + &name, &value, &size); + r = xmlTextWriterStartElement(writer, BAD_CAST("ea")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlTextWriterWriteFormatAttribute(writer, + BAD_CAST("id"), "%d", heap->id); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() failed: %d", r); + return (ARCHIVE_FATAL); + } + r = xmlwrite_heap(a, writer, heap); + if (r < 0) + return (ARCHIVE_FATAL); + r = xmlwrite_string(a, writer, "name", name); + if (r < 0) + return (ARCHIVE_FATAL); + + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + + /* + * Make a file data entry, "". + */ + if (file->data.length > 0) { + r = xmlTextWriterStartElement(writer, BAD_CAST("data")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + + r = xmlwrite_heap(a, writer, &(file->data)); + if (r < 0) + return (ARCHIVE_FATAL); + + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + + if (archive_strlen(&file->script) > 0) { + r = xmlTextWriterStartElement(writer, BAD_CAST("content")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + + r = xmlwrite_string(a, writer, + "interpreter", file->script.s); + if (r < 0) + return (ARCHIVE_FATAL); + + r = xmlwrite_string(a, writer, "type", "script"); + if (r < 0) + return (ARCHIVE_FATAL); + + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + return (ARCHIVE_FATAL); + } + } + + return (r2); +} + +/* + * Make the TOC + */ +static int +make_toc(struct archive_write *a) +{ + struct xar *xar; + struct file *np; + xmlBufferPtr bp; + xmlTextWriterPtr writer; + int algsize; + int r, ret; + + xar = (struct xar *)a->format_data; + + ret = ARCHIVE_FATAL; + + /* + * Initialize xml writer. + */ + writer = NULL; + bp = xmlBufferCreate(); + if (bp == NULL) { + archive_set_error(&a->archive, ENOMEM, + "xmlBufferCreate() " + "couldn't create xml buffer"); + goto exit_toc; + } + writer = xmlNewTextWriterMemory(bp, 0); + if (writer == NULL) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlNewTextWriterMemory() " + "couldn't create xml writer"); + goto exit_toc; + } + r = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartDocument() failed: %d", r); + goto exit_toc; + } + r = xmlTextWriterSetIndent(writer, 4); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterSetIndent() failed: %d", r); + goto exit_toc; + } + + /* + * Start recoding TOC + */ + r = xmlTextWriterStartElement(writer, BAD_CAST("xar")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + goto exit_toc; + } + r = xmlTextWriterStartElement(writer, BAD_CAST("toc")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartDocument() failed: %d", r); + goto exit_toc; + } + + /* + * Record the creation time of the archive file. + */ + r = xmlwrite_time(a, writer, "creation-time", time(NULL), 0); + if (r < 0) + goto exit_toc; + + /* + * Record the checksum value of TOC + */ + algsize = getalgsize(xar->opt_toc_sumalg); + if (algsize) { + /* + * Record TOC checksum + */ + r = xmlTextWriterStartElement(writer, BAD_CAST("checksum")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() failed: %d", r); + goto exit_toc; + } + r = xmlTextWriterWriteAttribute(writer, BAD_CAST("style"), + BAD_CAST(getalgname(xar->opt_toc_sumalg))); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() failed: %d", r); + goto exit_toc; + } + + /* + * Record the offset of the value of checksum of TOC + */ + r = xmlwrite_string(a, writer, "offset", "0"); + if (r < 0) + goto exit_toc; + + /* + * Record the size of the value of checksum of TOC + */ + r = xmlwrite_fstring(a, writer, "size", "%d", algsize); + if (r < 0) + goto exit_toc; + + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() failed: %d", r); + goto exit_toc; + } + } + + np = xar->root; + do { + if (np != np->parent) { + r = make_file_entry(a, writer, np); + if (r != ARCHIVE_OK) + goto exit_toc; + } + + if (np->dir && np->children.first != NULL) { + /* Enter to sub directories. */ + np = np->children.first; + r = xmlTextWriterStartElement(writer, + BAD_CAST("file")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() " + "failed: %d", r); + goto exit_toc; + } + r = xmlTextWriterWriteFormatAttribute( + writer, BAD_CAST("id"), "%d", np->id); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() " + "failed: %d", r); + goto exit_toc; + } + continue; + } + while (np != np->parent) { + r = xmlTextWriterEndElement(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndElement() " + "failed: %d", r); + goto exit_toc; + } + if (np->chnext == NULL) { + /* Return to the parent directory. */ + np = np->parent; + } else { + np = np->chnext; + r = xmlTextWriterStartElement(writer, + BAD_CAST("file")); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterStartElement() " + "failed: %d", r); + goto exit_toc; + } + r = xmlTextWriterWriteFormatAttribute( + writer, BAD_CAST("id"), "%d", np->id); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterWriteAttribute() " + "failed: %d", r); + goto exit_toc; + } + break; + } + } + } while (np != np->parent); + + r = xmlTextWriterEndDocument(writer); + if (r < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "xmlTextWriterEndDocument() failed: %d", r); + goto exit_toc; + } +#if DEBUG_PRINT_TOC + fprintf(stderr, "\n---TOC-- %d bytes --\n%s\n", + strlen((const char *)bp->content), bp->content); +#endif + + /* + * Compress the TOC and calculate the sum of the TOC. + */ + xar->toc.temp_offset = xar->temp_offset; + xar->toc.size = bp->use; + checksum_init(&(xar->a_sumwrk), xar->opt_toc_sumalg); + + r = compression_init_encoder_gzip(&(a->archive), + &(xar->stream), 6, 1); + if (r != ARCHIVE_OK) + goto exit_toc; + xar->stream.next_in = bp->content; + xar->stream.avail_in = bp->use; + xar->stream.total_in = 0; + xar->stream.next_out = xar->wbuff; + xar->stream.avail_out = sizeof(xar->wbuff); + xar->stream.total_out = 0; + for (;;) { + size_t size; + + r = compression_code(&(a->archive), + &(xar->stream), ARCHIVE_Z_FINISH); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) + goto exit_toc; + size = sizeof(xar->wbuff) - xar->stream.avail_out; + checksum_update(&(xar->a_sumwrk), xar->wbuff, size); + if (write_to_temp(a, xar->wbuff, size) != ARCHIVE_OK) + goto exit_toc; + if (r == ARCHIVE_EOF) + break; + xar->stream.next_out = xar->wbuff; + xar->stream.avail_out = sizeof(xar->wbuff); + } + r = compression_end(&(a->archive), &(xar->stream)); + if (r != ARCHIVE_OK) + goto exit_toc; + xar->toc.length = xar->stream.total_out; + xar->toc.compression = GZIP; + checksum_final(&(xar->a_sumwrk), &(xar->toc.a_sum)); + + ret = ARCHIVE_OK; +exit_toc: + if (writer) + xmlFreeTextWriter(writer); + if (bp) + xmlBufferFree(bp); + + return (ret); +} + +static int +flush_wbuff(struct archive_write *a) +{ + struct xar *xar; + int r; + size_t s; + + xar = (struct xar *)a->format_data; + s = sizeof(xar->wbuff) - xar->wbuff_remaining; + r = __archive_write_output(a, xar->wbuff, s); + if (r != ARCHIVE_OK) + return (r); + xar->wbuff_remaining = sizeof(xar->wbuff); + return (r); +} + +static int +copy_out(struct archive_write *a, uint64_t offset, uint64_t length) +{ + struct xar *xar; + int r; + + xar = (struct xar *)a->format_data; + if (lseek(xar->temp_fd, offset, SEEK_SET) < 0) { + archive_set_error(&(a->archive), errno, "lseek failed"); + return (ARCHIVE_FATAL); + } + while (length) { + size_t rsize; + ssize_t rs; + unsigned char *wb; + + if (length > xar->wbuff_remaining) + rsize = xar->wbuff_remaining; + else + rsize = (size_t)length; + wb = xar->wbuff + (sizeof(xar->wbuff) - xar->wbuff_remaining); + rs = read(xar->temp_fd, wb, rsize); + if (rs < 0) { + archive_set_error(&(a->archive), errno, + "Can't read temporary file(%jd)", + (intmax_t)rs); + return (ARCHIVE_FATAL); + } + if (rs == 0) { + archive_set_error(&(a->archive), 0, + "Truncated xar archive"); + return (ARCHIVE_FATAL); + } + xar->wbuff_remaining -= rs; + length -= rs; + if (xar->wbuff_remaining == 0) { + r = flush_wbuff(a); + if (r != ARCHIVE_OK) + return (r); + } + } + return (ARCHIVE_OK); +} + +static int +xar_close(struct archive_write *a) +{ + struct xar *xar; + unsigned char *wb; + uint64_t length; + int r; + + xar = (struct xar *)a->format_data; + + /* Empty! */ + if (xar->root->children.first == NULL) + return (ARCHIVE_OK); + + /* Save the length of all file extended attributes and contents. */ + length = xar->temp_offset; + + /* Connect hardlinked files */ + file_connect_hardlink_files(xar); + + /* Make the TOC */ + r = make_toc(a); + if (r != ARCHIVE_OK) + return (r); + /* + * Make the xar header on wbuff(write buffer). + */ + wb = xar->wbuff; + xar->wbuff_remaining = sizeof(xar->wbuff); + archive_be32enc(&wb[0], HEADER_MAGIC); + archive_be16enc(&wb[4], HEADER_SIZE); + archive_be16enc(&wb[6], HEADER_VERSION); + archive_be64enc(&wb[8], xar->toc.length); + archive_be64enc(&wb[16], xar->toc.size); + archive_be32enc(&wb[24], xar->toc.a_sum.alg); + xar->wbuff_remaining -= HEADER_SIZE; + + /* + * Write the TOC + */ + r = copy_out(a, xar->toc.temp_offset, xar->toc.length); + if (r != ARCHIVE_OK) + return (r); + + /* Write the checksum value of the TOC. */ + if (xar->toc.a_sum.len) { + if (xar->wbuff_remaining < xar->toc.a_sum.len) { + r = flush_wbuff(a); + if (r != ARCHIVE_OK) + return (r); + } + wb = xar->wbuff + (sizeof(xar->wbuff) - xar->wbuff_remaining); + memcpy(wb, xar->toc.a_sum.val, xar->toc.a_sum.len); + xar->wbuff_remaining -= xar->toc.a_sum.len; + } + + /* + * Write all file extended attributes and contents. + */ + r = copy_out(a, xar->toc.a_sum.len, length); + if (r != ARCHIVE_OK) + return (r); + r = flush_wbuff(a); + return (r); +} + +static int +xar_free(struct archive_write *a) +{ + struct xar *xar; + + xar = (struct xar *)a->format_data; + archive_string_free(&(xar->cur_dirstr)); + archive_string_free(&(xar->tstr)); + archive_string_free(&(xar->vstr)); + file_free_hardlinks(xar); + file_free_register(xar); + compression_end(&(a->archive), &(xar->stream)); + free(xar); + + return (ARCHIVE_OK); +} + +static int +file_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + struct file *f1 = (struct file *)n1; + struct file *f2 = (struct file *)n2; + + return (strcmp(f1->basename.s, f2->basename.s)); +} + +static int +file_cmp_key(const struct archive_rb_node *n, const void *key) +{ + struct file *f = (struct file *)n; + + return (strcmp(f->basename.s, (const char *)key)); +} + +static struct file * +file_new(struct archive_write *a, struct archive_entry *entry) +{ + struct file *file; + static const struct archive_rb_tree_ops rb_ops = { + file_cmp_node, file_cmp_key + }; + + file = calloc(1, sizeof(*file)); + if (file == NULL) + return (NULL); + + if (entry != NULL) + file->entry = archive_entry_clone(entry); + else + file->entry = archive_entry_new2(&a->archive); + if (file->entry == NULL) { + free(file); + return (NULL); + } + __archive_rb_tree_init(&(file->rbtree), &rb_ops); + file->children.first = NULL; + file->children.last = &(file->children.first); + file->xattr.first = NULL; + file->xattr.last = &(file->xattr.first); + archive_string_init(&(file->parentdir)); + archive_string_init(&(file->basename)); + archive_string_init(&(file->symlink)); + archive_string_init(&(file->script)); + if (entry != NULL && archive_entry_filetype(entry) == AE_IFDIR) + file->dir = 1; + + return (file); +} + +static void +file_free(struct file *file) +{ + struct heap_data *heap, *next_heap; + + heap = file->xattr.first; + while (heap != NULL) { + next_heap = heap->next; + free(heap); + heap = next_heap; + } + archive_string_free(&(file->parentdir)); + archive_string_free(&(file->basename)); + archive_string_free(&(file->symlink)); + archive_string_free(&(file->script)); + free(file); +} + +static struct file * +file_create_virtual_dir(struct archive_write *a, struct xar *xar, + const char *pathname) +{ + struct file *file; + + file = file_new(a, NULL); + if (file == NULL) + return (NULL); + archive_entry_set_pathname(file->entry, pathname); + archive_entry_set_mode(file->entry, 0555 | AE_IFDIR); + + file->dir = 1; + file->virtual = 1; + + return (file); +} + +static int +file_add_child_tail(struct file *parent, struct file *child) +{ + if (!__archive_rb_tree_insert_node( + &(parent->rbtree), (struct archive_rb_node *)child)) + return (0); + child->chnext = NULL; + *parent->children.last = child; + parent->children.last = &(child->chnext); + child->parent = parent; + return (1); +} + +/* + * Find a entry from `parent' + */ +static struct file * +file_find_child(struct file *parent, const char *child_name) +{ + struct file *np; + + np = (struct file *)__archive_rb_tree_find_node( + &(parent->rbtree), child_name); + return (np); +} + +#if defined(_WIN32) || defined(__CYGWIN__) +static void +cleanup_backslash(char *utf8, size_t len) +{ + + /* Convert a path-separator from '\' to '/' */ + while (*utf8 != '\0' && len) { + if (*utf8 == '\\') + *utf8 = '/'; + ++utf8; + --len; + } +} +#else +#define cleanup_backslash(p, len) /* nop */ +#endif + +/* + * Generate a parent directory name and a base name from a pathname. + */ +static int +file_gen_utility_names(struct archive_write *a, struct file *file) +{ + struct xar *xar; + const char *pp; + char *p, *dirname, *slash; + size_t len; + int r = ARCHIVE_OK; + + xar = (struct xar *)a->format_data; + archive_string_empty(&(file->parentdir)); + archive_string_empty(&(file->basename)); + archive_string_empty(&(file->symlink)); + + if (file->parent == file)/* virtual root */ + return (ARCHIVE_OK); + + if (archive_entry_pathname_l(file->entry, &pp, &len, xar->sconv) + != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to UTF-8", + archive_entry_pathname(file->entry)); + r = ARCHIVE_WARN; + } + archive_strncpy(&(file->parentdir), pp, len); + len = file->parentdir.length; + p = dirname = file->parentdir.s; + /* + * Convert a path-separator from '\' to '/' + */ + cleanup_backslash(p, len); + + /* + * Remove leading '/', '../' and './' elements + */ + while (*p) { + if (p[0] == '/') { + p++; + len--; + } else if (p[0] != '.') + break; + else if (p[1] == '.' && p[2] == '/') { + p += 3; + len -= 3; + } else if (p[1] == '/' || (p[1] == '.' && p[2] == '\0')) { + p += 2; + len -= 2; + } else if (p[1] == '\0') { + p++; + len--; + } else + break; + } + if (p != dirname) { + memmove(dirname, p, len+1); + p = dirname; + } + /* + * Remove "/","/." and "/.." elements from tail. + */ + while (len > 0) { + size_t ll = len; + + if (len > 0 && p[len-1] == '/') { + p[len-1] = '\0'; + len--; + } + if (len > 1 && p[len-2] == '/' && p[len-1] == '.') { + p[len-2] = '\0'; + len -= 2; + } + if (len > 2 && p[len-3] == '/' && p[len-2] == '.' && + p[len-1] == '.') { + p[len-3] = '\0'; + len -= 3; + } + if (ll == len) + break; + } + while (*p) { + if (p[0] == '/') { + if (p[1] == '/') + /* Convert '//' --> '/' */ + strcpy(p, p+1); + else if (p[1] == '.' && p[2] == '/') + /* Convert '/./' --> '/' */ + strcpy(p, p+2); + else if (p[1] == '.' && p[2] == '.' && p[3] == '/') { + /* Convert 'dir/dir1/../dir2/' + * --> 'dir/dir2/' + */ + char *rp = p -1; + while (rp >= dirname) { + if (*rp == '/') + break; + --rp; + } + if (rp > dirname) { + strcpy(rp, p+3); + p = rp; + } else { + strcpy(dirname, p+4); + p = dirname; + } + } else + p++; + } else + p++; + } + p = dirname; + len = strlen(p); + + if (archive_entry_filetype(file->entry) == AE_IFLNK) { + size_t len2; + /* Convert symlink name too. */ + if (archive_entry_symlink_l(file->entry, &pp, &len2, + xar->sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Linkname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate symlink '%s' to UTF-8", + archive_entry_symlink(file->entry)); + r = ARCHIVE_WARN; + } + archive_strncpy(&(file->symlink), pp, len2); + cleanup_backslash(file->symlink.s, file->symlink.length); + } + /* + * - Count up directory elements. + * - Find out the position which points the last position of + * path separator('/'). + */ + slash = NULL; + for (; *p != '\0'; p++) + if (*p == '/') + slash = p; + if (slash == NULL) { + /* The pathname doesn't have a parent directory. */ + file->parentdir.length = len; + archive_string_copy(&(file->basename), &(file->parentdir)); + archive_string_empty(&(file->parentdir)); + file->parentdir.s = '\0'; + return (r); + } + + /* Make a basename from dirname and slash */ + *slash = '\0'; + file->parentdir.length = slash - dirname; + archive_strcpy(&(file->basename), slash + 1); + return (r); +} + +static int +get_path_component(char *name, int n, const char *fn) +{ + char *p; + int l; + + p = strchr(fn, '/'); + if (p == NULL) { + if ((l = strlen(fn)) == 0) + return (0); + } else + l = p - fn; + if (l > n -1) + return (-1); + memcpy(name, fn, l); + name[l] = '\0'; + + return (l); +} + +/* + * Add a new entry into the tree. + */ +static int +file_tree(struct archive_write *a, struct file **filepp) +{ +#if defined(_WIN32) && !defined(__CYGWIN__) + char name[_MAX_FNAME];/* Included null terminator size. */ +#elif defined(NAME_MAX) && NAME_MAX >= 255 + char name[NAME_MAX+1]; +#else + char name[256]; +#endif + struct xar *xar = (struct xar *)a->format_data; + struct file *dent, *file, *np; + struct archive_entry *ent; + const char *fn, *p; + int l; + + file = *filepp; + dent = xar->root; + if (file->parentdir.length > 0) + fn = p = file->parentdir.s; + else + fn = p = ""; + + /* + * If the path of the parent directory of `file' entry is + * the same as the path of `cur_dirent', add isoent to + * `cur_dirent'. + */ + if (archive_strlen(&(xar->cur_dirstr)) + == archive_strlen(&(file->parentdir)) && + strcmp(xar->cur_dirstr.s, fn) == 0) { + if (!file_add_child_tail(xar->cur_dirent, file)) { + np = (struct file *)__archive_rb_tree_find_node( + &(xar->cur_dirent->rbtree), + file->basename.s); + goto same_entry; + } + return (ARCHIVE_OK); + } + + for (;;) { + l = get_path_component(name, sizeof(name), fn); + if (l == 0) { + np = NULL; + break; + } + if (l < 0) { + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "A name buffer is too small"); + file_free(file); + *filepp = NULL; + return (ARCHIVE_FATAL); + } + + np = file_find_child(dent, name); + if (np == NULL || fn[0] == '\0') + break; + + /* Find next subdirectory. */ + if (!np->dir) { + /* NOT Directory! */ + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "`%s' is not directory, we cannot insert `%s' ", + archive_entry_pathname(np->entry), + archive_entry_pathname(file->entry)); + file_free(file); + *filepp = NULL; + return (ARCHIVE_FAILED); + } + fn += l; + if (fn[0] == '/') + fn++; + dent = np; + } + if (np == NULL) { + /* + * Create virtual parent directories. + */ + while (fn[0] != '\0') { + struct file *vp; + struct archive_string as; + + archive_string_init(&as); + archive_strncat(&as, p, fn - p + l); + if (as.s[as.length-1] == '/') { + as.s[as.length-1] = '\0'; + as.length--; + } + vp = file_create_virtual_dir(a, xar, as.s); + if (vp == NULL) { + archive_string_free(&as); + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + file_free(file); + *filepp = NULL; + return (ARCHIVE_FATAL); + } + archive_string_free(&as); + if (file_gen_utility_names(a, vp) <= ARCHIVE_FAILED) + return (ARCHIVE_FATAL); + file_add_child_tail(dent, vp); + file_register(xar, vp); + np = vp; + + fn += l; + if (fn[0] == '/') + fn++; + l = get_path_component(name, sizeof(name), fn); + if (l < 0) { + archive_string_free(&as); + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "A name buffer is too small"); + file_free(file); + *filepp = NULL; + return (ARCHIVE_FATAL); + } + dent = np; + } + + /* Found out the parent directory where isoent can be + * inserted. */ + xar->cur_dirent = dent; + archive_string_empty(&(xar->cur_dirstr)); + archive_string_ensure(&(xar->cur_dirstr), + archive_strlen(&(dent->parentdir)) + + archive_strlen(&(dent->basename)) + 2); + if (archive_strlen(&(dent->parentdir)) + + archive_strlen(&(dent->basename)) == 0) + xar->cur_dirstr.s[0] = 0; + else { + if (archive_strlen(&(dent->parentdir)) > 0) { + archive_string_copy(&(xar->cur_dirstr), + &(dent->parentdir)); + archive_strappend_char(&(xar->cur_dirstr), '/'); + } + archive_string_concat(&(xar->cur_dirstr), + &(dent->basename)); + } + + if (!file_add_child_tail(dent, file)) { + np = (struct file *)__archive_rb_tree_find_node( + &(dent->rbtree), file->basename.s); + goto same_entry; + } + return (ARCHIVE_OK); + } + +same_entry: + /* + * We have already has the entry the filename of which is + * the same. + */ + if (archive_entry_filetype(np->entry) != + archive_entry_filetype(file->entry)) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Found duplicate entries `%s' and its file type is " + "different", + archive_entry_pathname(np->entry)); + file_free(file); + *filepp = NULL; + return (ARCHIVE_FAILED); + } + + /* Swap files. */ + ent = np->entry; + np->entry = file->entry; + file->entry = ent; + np->virtual = 0; + + file_free(file); + *filepp = np; + return (ARCHIVE_OK); +} + +static void +file_register(struct xar *xar, struct file *file) +{ + file->id = xar->file_idx++; + file->next = NULL; + *xar->file_list.last = file; + xar->file_list.last = &(file->next); +} + +static void +file_init_register(struct xar *xar) +{ + xar->file_list.first = NULL; + xar->file_list.last = &(xar->file_list.first); +} + +static void +file_free_register(struct xar *xar) +{ + struct file *file, *file_next; + + file = xar->file_list.first; + while (file != NULL) { + file_next = file->next; + file_free(file); + file = file_next; + } +} + +/* + * Register entry to get a hardlink target. + */ +static int +file_register_hardlink(struct archive_write *a, struct file *file) +{ + struct xar *xar = (struct xar *)a->format_data; + struct hardlink *hl; + const char *pathname; + + archive_entry_set_nlink(file->entry, 1); + pathname = archive_entry_hardlink(file->entry); + if (pathname == NULL) { + /* This `file` is a hardlink target. */ + hl = malloc(sizeof(*hl)); + if (hl == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory"); + return (ARCHIVE_FATAL); + } + hl->nlink = 1; + /* A hardlink target must be the first position. */ + file->hlnext = NULL; + hl->file_list.first = file; + hl->file_list.last = &(file->hlnext); + __archive_rb_tree_insert_node(&(xar->hardlink_rbtree), + (struct archive_rb_node *)hl); + } else { + hl = (struct hardlink *)__archive_rb_tree_find_node( + &(xar->hardlink_rbtree), pathname); + if (hl != NULL) { + /* Insert `file` entry into the tail. */ + file->hlnext = NULL; + *hl->file_list.last = file; + hl->file_list.last = &(file->hlnext); + hl->nlink++; + } + archive_entry_unset_size(file->entry); + } + + return (ARCHIVE_OK); +} + +/* + * Hardlinked files have to have the same location of extent. + * We have to find out hardlink target entries for entries which + * have a hardlink target name. + */ +static void +file_connect_hardlink_files(struct xar *xar) +{ + struct archive_rb_node *n; + struct hardlink *hl; + struct file *target, *nf; + + ARCHIVE_RB_TREE_FOREACH(n, &(xar->hardlink_rbtree)) { + hl = (struct hardlink *)n; + + /* The first entry must be a hardlink target. */ + target = hl->file_list.first; + archive_entry_set_nlink(target->entry, hl->nlink); + if (hl->nlink > 1) + /* It means this file is a hardlink + * targe itself. */ + target->hardlink_target = target; + for (nf = target->hlnext; + nf != NULL; nf = nf->hlnext) { + nf->hardlink_target = target; + archive_entry_set_nlink(nf->entry, hl->nlink); + } + } +} + +static int +file_hd_cmp_node(const struct archive_rb_node *n1, + const struct archive_rb_node *n2) +{ + struct hardlink *h1 = (struct hardlink *)n1; + struct hardlink *h2 = (struct hardlink *)n2; + + return (strcmp(archive_entry_pathname(h1->file_list.first->entry), + archive_entry_pathname(h2->file_list.first->entry))); +} + +static int +file_hd_cmp_key(const struct archive_rb_node *n, const void *key) +{ + struct hardlink *h = (struct hardlink *)n; + + return (strcmp(archive_entry_pathname(h->file_list.first->entry), + (const char *)key)); +} + + +static void +file_init_hardlinks(struct xar *xar) +{ + static const struct archive_rb_tree_ops rb_ops = { + file_hd_cmp_node, file_hd_cmp_key, + }; + + __archive_rb_tree_init(&(xar->hardlink_rbtree), &rb_ops); +} + +static void +file_free_hardlinks(struct xar *xar) +{ + struct archive_rb_node *n, *next; + + for (n = ARCHIVE_RB_TREE_MIN(&(xar->hardlink_rbtree)); n;) { + next = __archive_rb_tree_iterate(&(xar->hardlink_rbtree), + n, ARCHIVE_RB_DIR_RIGHT); + free(n); + n = next; + } +} + +static void +checksum_init(struct chksumwork *sumwrk, enum sumalg sum_alg) +{ + sumwrk->alg = sum_alg; + switch (sum_alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_init(&(sumwrk->sha1ctx)); + break; + case CKSUM_MD5: + archive_md5_init(&(sumwrk->md5ctx)); + break; + } +} + +static void +checksum_update(struct chksumwork *sumwrk, const void *buff, size_t size) +{ + + switch (sumwrk->alg) { + case CKSUM_NONE: + break; + case CKSUM_SHA1: + archive_sha1_update(&(sumwrk->sha1ctx), buff, size); + break; + case CKSUM_MD5: + archive_md5_update(&(sumwrk->md5ctx), buff, size); + break; + } +} + +static void +checksum_final(struct chksumwork *sumwrk, struct chksumval *sumval) +{ + + switch (sumwrk->alg) { + case CKSUM_NONE: + sumval->len = 0; + break; + case CKSUM_SHA1: + archive_sha1_final(&(sumwrk->sha1ctx), sumval->val); + sumval->len = SHA1_SIZE; + break; + case CKSUM_MD5: + archive_md5_final(&(sumwrk->md5ctx), sumval->val); + sumval->len = MD5_SIZE; + break; + } + sumval->alg = sumwrk->alg; +} + +#if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR) || !defined(HAVE_LZMA_H) +static int +compression_unsupported_encoder(struct archive *a, + struct la_zstream *lastrm, const char *name) +{ + + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "%s compression not supported on this platform", name); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_FAILED); +} +#endif + +static int +compression_init_encoder_gzip(struct archive *a, + struct la_zstream *lastrm, int level, int withheader) +{ + z_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for gzip stream"); + return (ARCHIVE_FATAL); + } + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + if (deflateInit2(strm, level, Z_DEFLATED, + (withheader)?15:-15, + 8, Z_DEFAULT_STRATEGY) != Z_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_gzip; + lastrm->end = compression_end_gzip; + return (ARCHIVE_OK); +} + +static int +compression_code_gzip(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + /* zlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (Bytef *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + r = deflate(strm, + (action == ARCHIVE_Z_FINISH)? Z_FINISH: Z_NO_FLUSH); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case Z_OK: + return (ARCHIVE_OK); + case Z_STREAM_END: + return (ARCHIVE_EOF); + default: + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "GZip compression failed:" + " deflate() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_gzip(struct archive *a, struct la_zstream *lastrm) +{ + z_stream *strm; + int r; + + strm = (z_stream *)lastrm->real_stream; + r = deflateEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != Z_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +#if defined(HAVE_BZLIB_H) && defined(BZ_CONFIG_ERROR) +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + bz_stream *strm; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for bzip2 stream"); + return (ARCHIVE_FATAL); + } + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + if (BZ2_bzCompressInit(strm, level, 0, 30) != BZ_OK) { + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_bzip2; + lastrm->end = compression_end_bzip2; + return (ARCHIVE_OK); +} + +static int +compression_code_bzip2(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + /* bzlib.h is not const-correct, so we need this one bit + * of ugly hackery to convert a const * pointer to + * a non-const pointer. */ + strm->next_in = (char *)(uintptr_t)(const void *)lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in_lo32 = (uint32_t)(lastrm->total_in & 0xffffffff); + strm->total_in_hi32 = (uint32_t)(lastrm->total_in >> 32); + strm->next_out = (char *)lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out_lo32 = (uint32_t)(lastrm->total_out & 0xffffffff); + strm->total_out_hi32 = (uint32_t)(lastrm->total_out >> 32); + r = BZ2_bzCompress(strm, + (action == ARCHIVE_Z_FINISH)? BZ_FINISH: BZ_RUN); + lastrm->next_in = (const unsigned char *)strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = + (((uint64_t)(uint32_t)strm->total_in_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_in_lo32; + lastrm->next_out = (unsigned char *)strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = + (((uint64_t)(uint32_t)strm->total_out_hi32) << 32) + + (uint64_t)(uint32_t)strm->total_out_lo32; + switch (r) { + case BZ_RUN_OK: /* Non-finishing */ + case BZ_FINISH_OK: /* Finishing: There's more work to do */ + return (ARCHIVE_OK); + case BZ_STREAM_END: /* Finishing: all done */ + /* Only occurs in finishing case */ + return (ARCHIVE_EOF); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Bzip2 compression failed:" + " BZ2_bzCompress() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_bzip2(struct archive *a, struct la_zstream *lastrm) +{ + bz_stream *strm; + int r; + + strm = (bz_stream *)lastrm->real_stream; + r = BZ2_bzCompressEnd(strm); + free(strm); + lastrm->real_stream = NULL; + lastrm->valid = 0; + if (r != BZ_OK) { + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Failed to clean up compressor"); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +#else +static int +compression_init_encoder_bzip2(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "bzip2")); +} +#endif + +#if defined(HAVE_LZMA_H) +static int +compression_init_encoder_lzma(struct archive *a, + struct la_zstream *lastrm, int level) +{ + static const lzma_stream lzma_init_data = LZMA_STREAM_INIT; + lzma_stream *strm; + lzma_options_lzma lzma_opt; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + if (lzma_lzma_preset(&lzma_opt, level)) { + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + strm = calloc(1, sizeof(*strm)); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for lzma stream"); + return (ARCHIVE_FATAL); + } + *strm = lzma_init_data; + r = lzma_alone_encoder(strm, &lzma_opt); + switch (r) { + case LZMA_OK: + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_lzma; + lastrm->end = compression_end_lzma; + r = ARCHIVE_OK; + break; + case LZMA_MEM_ERROR: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library: " + "Cannot allocate memory"); + r = ARCHIVE_FATAL; + break; + default: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "It's a bug in liblzma"); + r = ARCHIVE_FATAL; + break; + } + return (r); +} + +static int +compression_init_encoder_xz(struct archive *a, + struct la_zstream *lastrm, int level) +{ + static const lzma_stream lzma_init_data = LZMA_STREAM_INIT; + lzma_stream *strm; + lzma_filter *lzmafilters; + lzma_options_lzma lzma_opt; + int r; + + if (lastrm->valid) + compression_end(a, lastrm); + strm = calloc(1, sizeof(*strm) + sizeof(*lzmafilters) * 2); + if (strm == NULL) { + archive_set_error(a, ENOMEM, + "Can't allocate memory for xz stream"); + return (ARCHIVE_FATAL); + } + lzmafilters = (lzma_filter *)(strm+1); + if (level > 6) + level = 6; + if (lzma_lzma_preset(&lzma_opt, level)) { + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library"); + return (ARCHIVE_FATAL); + } + lzmafilters[0].id = LZMA_FILTER_LZMA2; + lzmafilters[0].options = &lzma_opt; + lzmafilters[1].id = LZMA_VLI_UNKNOWN;/* Terminate */ + + *strm = lzma_init_data; + r = lzma_stream_encoder(strm, lzmafilters, LZMA_CHECK_CRC64); + switch (r) { + case LZMA_OK: + lastrm->real_stream = strm; + lastrm->valid = 1; + lastrm->code = compression_code_lzma; + lastrm->end = compression_end_lzma; + r = ARCHIVE_OK; + break; + case LZMA_MEM_ERROR: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ENOMEM, + "Internal error initializing compression library: " + "Cannot allocate memory"); + r = ARCHIVE_FATAL; + break; + default: + free(strm); + lastrm->real_stream = NULL; + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "Internal error initializing compression library: " + "It's a bug in liblzma"); + r = ARCHIVE_FATAL; + break; + } + return (r); +} + +static int +compression_code_lzma(struct archive *a, + struct la_zstream *lastrm, enum la_zaction action) +{ + lzma_stream *strm; + int r; + + strm = (lzma_stream *)lastrm->real_stream; + strm->next_in = lastrm->next_in; + strm->avail_in = lastrm->avail_in; + strm->total_in = lastrm->total_in; + strm->next_out = lastrm->next_out; + strm->avail_out = lastrm->avail_out; + strm->total_out = lastrm->total_out; + r = lzma_code(strm, + (action == ARCHIVE_Z_FINISH)? LZMA_FINISH: LZMA_RUN); + lastrm->next_in = strm->next_in; + lastrm->avail_in = strm->avail_in; + lastrm->total_in = strm->total_in; + lastrm->next_out = strm->next_out; + lastrm->avail_out = strm->avail_out; + lastrm->total_out = strm->total_out; + switch (r) { + case LZMA_OK: + /* Non-finishing case */ + return (ARCHIVE_OK); + case LZMA_STREAM_END: + /* This return can only occur in finishing case. */ + return (ARCHIVE_EOF); + case LZMA_MEMLIMIT_ERROR: + archive_set_error(a, ENOMEM, + "lzma compression error:" + " %ju MiB would have been needed", + (uintmax_t)((lzma_memusage(strm) + 1024 * 1024 -1) + / (1024 * 1024))); + return (ARCHIVE_FATAL); + default: + /* Any other return value indicates an error */ + archive_set_error(a, ARCHIVE_ERRNO_MISC, + "lzma compression failed:" + " lzma_code() call returned status %d", r); + return (ARCHIVE_FATAL); + } +} + +static int +compression_end_lzma(struct archive *a, struct la_zstream *lastrm) +{ + lzma_stream *strm; + + (void)a; /* UNUSED */ + strm = (lzma_stream *)lastrm->real_stream; + lzma_end(strm); + free(strm); + lastrm->valid = 0; + lastrm->real_stream = NULL; + return (ARCHIVE_OK); +} +#else +static int +compression_init_encoder_lzma(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "lzma")); +} +static int +compression_init_encoder_xz(struct archive *a, + struct la_zstream *lastrm, int level) +{ + + (void) level; /* UNUSED */ + if (lastrm->valid) + compression_end(a, lastrm); + return (compression_unsupported_encoder(a, lastrm, "xz")); +} +#endif + +static int +xar_compression_init_encoder(struct archive_write *a) +{ + struct xar *xar; + int r; + + xar = (struct xar *)a->format_data; + switch (xar->opt_compression) { + case GZIP: + r = compression_init_encoder_gzip( + &(a->archive), &(xar->stream), + xar->opt_compression_level, 1); + break; + case BZIP2: + r = compression_init_encoder_bzip2( + &(a->archive), &(xar->stream), + xar->opt_compression_level); + break; + case LZMA: + r = compression_init_encoder_lzma( + &(a->archive), &(xar->stream), + xar->opt_compression_level); + break; + case XZ: + r = compression_init_encoder_xz( + &(a->archive), &(xar->stream), + xar->opt_compression_level); + break; + default: + r = ARCHIVE_OK; + break; + } + if (r == ARCHIVE_OK) { + xar->stream.total_in = 0; + xar->stream.next_out = xar->wbuff; + xar->stream.avail_out = sizeof(xar->wbuff); + xar->stream.total_out = 0; + } + + return (r); +} + +static int +compression_code(struct archive *a, struct la_zstream *lastrm, + enum la_zaction action) +{ + if (lastrm->valid) + return (lastrm->code(a, lastrm, action)); + return (ARCHIVE_OK); +} + +static int +compression_end(struct archive *a, struct la_zstream *lastrm) +{ + if (lastrm->valid) + return (lastrm->end(a, lastrm)); + return (ARCHIVE_OK); +} + + +static int +save_xattrs(struct archive_write *a, struct file *file) +{ + struct xar *xar; + const char *name; + const void *value; + struct heap_data *heap; + size_t size; + int count, r; + + xar = (struct xar *)a->format_data; + count = archive_entry_xattr_reset(file->entry); + if (count == 0) + return (ARCHIVE_OK); + while (count--) { + archive_entry_xattr_next(file->entry, + &name, &value, &size); + checksum_init(&(xar->a_sumwrk), xar->opt_sumalg); + checksum_init(&(xar->e_sumwrk), xar->opt_sumalg); + + heap = calloc(1, sizeof(*heap)); + if (heap == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for xattr"); + return (ARCHIVE_FATAL); + } + heap->id = file->ea_idx++; + heap->temp_offset = xar->temp_offset; + heap->size = size;/* save a extracted size */ + heap->compression = xar->opt_compression; + /* Get a extracted sumcheck value. */ + checksum_update(&(xar->e_sumwrk), value, size); + checksum_final(&(xar->e_sumwrk), &(heap->e_sum)); + + /* + * Not compression to xattr is simple way. + */ + if (heap->compression == NONE) { + checksum_update(&(xar->a_sumwrk), value, size); + checksum_final(&(xar->a_sumwrk), &(heap->a_sum)); + if (write_to_temp(a, value, size) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + heap->length = size; + /* Add heap to the tail of file->xattr. */ + heap->next = NULL; + *file->xattr.last = heap; + file->xattr.last = &(heap->next); + /* Next xattr */ + continue; + } + + /* + * Init compression library. + */ + r = xar_compression_init_encoder(a); + if (r != ARCHIVE_OK) { + free(heap); + return (ARCHIVE_FATAL); + } + + xar->stream.next_in = (const unsigned char *)value; + xar->stream.avail_in = size; + for (;;) { + r = compression_code(&(a->archive), + &(xar->stream), ARCHIVE_Z_FINISH); + if (r != ARCHIVE_OK && r != ARCHIVE_EOF) { + free(heap); + return (ARCHIVE_FATAL); + } + size = sizeof(xar->wbuff) - xar->stream.avail_out; + checksum_update(&(xar->a_sumwrk), + xar->wbuff, size); + if (write_to_temp(a, xar->wbuff, size) + != ARCHIVE_OK) + return (ARCHIVE_FATAL); + if (r == ARCHIVE_OK) { + xar->stream.next_out = xar->wbuff; + xar->stream.avail_out = sizeof(xar->wbuff); + } else { + checksum_final(&(xar->a_sumwrk), + &(heap->a_sum)); + heap->length = xar->stream.total_out; + /* Add heap to the tail of file->xattr. */ + heap->next = NULL; + *file->xattr.last = heap; + file->xattr.last = &(heap->next); + break; + } + } + /* Clean up compression library. */ + r = compression_end(&(a->archive), &(xar->stream)); + if (r != ARCHIVE_OK) + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); +} + +static int +getalgsize(enum sumalg sumalg) +{ + switch (sumalg) { + default: + case CKSUM_NONE: + return (0); + case CKSUM_SHA1: + return (SHA1_SIZE); + case CKSUM_MD5: + return (MD5_SIZE); + } +} + +static const char * +getalgname(enum sumalg sumalg) +{ + switch (sumalg) { + default: + case CKSUM_NONE: + return (NULL); + case CKSUM_SHA1: + return (SHA1_NAME); + case CKSUM_MD5: + return (MD5_NAME); + } +} + +#endif /* Support xar format */ + diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c index d4e6f5bc3..11fbd45b5 100644 --- a/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_format_zip.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2008 Anselm Strauss * Copyright (c) 2009 Joerg Sonnenberger + * Copyright (c) 2011 Michihiro NAKAJIMA * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -47,12 +48,14 @@ */ #include "archive_platform.h" -__FBSDID("$FreeBSD$"); +__FBSDID("$FreeBSD: head/lib/libarchive/archive_write_set_format_zip.c 201168 2009-12-29 06:15:32Z kientzle $"); #ifdef HAVE_ERRNO_H #include #endif -#include +#ifdef HAVE_LANGINFO_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif @@ -66,6 +69,7 @@ __FBSDID("$FreeBSD$"); #include "archive.h" #include "archive_endian.h" #include "archive_entry.h" +#include "archive_entry_locale.h" #include "archive_private.h" #include "archive_write_private.h" @@ -78,590 +82,739 @@ __FBSDID("$FreeBSD$"); #define ZIP_SIGNATURE_FILE_HEADER 0x02014b50 #define ZIP_SIGNATURE_CENTRAL_DIRECTORY_END 0x06054b50 #define ZIP_SIGNATURE_EXTRA_TIMESTAMP 0x5455 -#define ZIP_SIGNATURE_EXTRA_UNIX 0x7855 +#define ZIP_SIGNATURE_EXTRA_NEW_UNIX 0x7875 #define ZIP_VERSION_EXTRACT 0x0014 /* ZIP version 2.0 is needed. */ #define ZIP_VERSION_BY 0x0314 /* Made by UNIX, using ZIP version 2.0. */ #define ZIP_FLAGS 0x08 /* Flagging bit 3 (count from 0) for using data descriptor. */ +#define ZIP_FLAGS_UTF8_NAME (1 << 11) enum compression { - COMPRESSION_STORE = 0 + COMPRESSION_STORE = 0 #ifdef HAVE_ZLIB_H - , - COMPRESSION_DEFLATE = 8 + , + COMPRESSION_DEFLATE = 8 #endif }; -static ssize_t archive_write_zip_data(struct archive_write *, const void *buff, size_t s); -static int archive_write_zip_finish(struct archive_write *); -static int archive_write_zip_destroy(struct archive_write *); +static ssize_t archive_write_zip_data(struct archive_write *, + const void *buff, size_t s); +static int archive_write_zip_close(struct archive_write *); +static int archive_write_zip_free(struct archive_write *); static int archive_write_zip_finish_entry(struct archive_write *); -static int archive_write_zip_header(struct archive_write *, struct archive_entry *); +static int archive_write_zip_header(struct archive_write *, + struct archive_entry *); +static int archive_write_zip_options(struct archive_write *, + const char *, const char *); static unsigned int dos_time(const time_t); static size_t path_length(struct archive_entry *); static int write_path(struct archive_entry *, struct archive_write *); struct zip_local_file_header { - char signature[4]; - char version[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; + char signature[4]; + char version[2]; + char flags[2]; + char compression[2]; + char timedate[4]; + char crc32[4]; + char compressed_size[4]; + char uncompressed_size[4]; + char filename_length[2]; + char extra_length[2]; }; struct zip_file_header { - char signature[4]; - char version_by[2]; - char version_extract[2]; - char flags[2]; - char compression[2]; - char timedate[4]; - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; - char filename_length[2]; - char extra_length[2]; - char comment_length[2]; - char disk_number[2]; - char attributes_internal[2]; - char attributes_external[4]; - char offset[4]; + char signature[4]; + char version_by[2]; + char version_extract[2]; + char flags[2]; + char compression[2]; + char timedate[4]; + char crc32[4]; + char compressed_size[4]; + char uncompressed_size[4]; + char filename_length[2]; + char extra_length[2]; + char comment_length[2]; + char disk_number[2]; + char attributes_internal[2]; + char attributes_external[4]; + char offset[4]; }; struct zip_data_descriptor { - char signature[4]; /* Not mandatory, but recommended by specification. */ - char crc32[4]; - char compressed_size[4]; - char uncompressed_size[4]; + char signature[4]; /* Not mandatory, but recommended by specification. */ + char crc32[4]; + char compressed_size[4]; + char uncompressed_size[4]; }; struct zip_extra_data_local { - char time_id[2]; - char time_size[2]; - char time_flag[1]; - char mtime[4]; - char atime[4]; - char ctime[4]; - char unix_id[2]; - char unix_size[2]; - char unix_uid[2]; - char unix_gid[2]; + char time_id[2]; + char time_size[2]; + char time_flag[1]; + char mtime[4]; + char atime[4]; + char ctime[4]; + char unix_id[2]; + char unix_size[2]; + char unix_version; + char unix_uid_size; + char unix_uid[4]; + char unix_gid_size; + char unix_gid[4]; }; struct zip_extra_data_central { - char time_id[2]; - char time_size[2]; - char time_flag[1]; - char mtime[4]; - char unix_id[2]; - char unix_size[2]; + char time_id[2]; + char time_size[2]; + char time_flag[1]; + char mtime[4]; + char unix_id[2]; + char unix_size[2]; }; struct zip_file_header_link { - struct zip_file_header_link *next; - struct archive_entry *entry; - off_t offset; - unsigned long crc32; - off_t compressed_size; - enum compression compression; + struct zip_file_header_link *next; + struct archive_entry *entry; + int64_t offset; + unsigned long crc32; + int64_t compressed_size; + enum compression compression; + int flags; }; struct zip { - struct zip_data_descriptor data_descriptor; - struct zip_file_header_link *central_directory; - struct zip_file_header_link *central_directory_end; - int64_t offset; - int64_t written_bytes; - int64_t remaining_data_bytes; - enum compression compression; + struct zip_data_descriptor data_descriptor; + struct zip_file_header_link *central_directory; + struct zip_file_header_link *central_directory_end; + int64_t offset; + int64_t written_bytes; + int64_t remaining_data_bytes; + enum compression compression; + int flags; + struct archive_string_conv *opt_sconv; + struct archive_string_conv *sconv_default; + int init_default_conversion; #ifdef HAVE_ZLIB_H - z_stream stream; - size_t len_buf; - unsigned char *buf; + z_stream stream; + size_t len_buf; + unsigned char *buf; #endif }; struct zip_central_directory_end { - char signature[4]; - char disk[2]; - char start_disk[2]; - char entries_disk[2]; - char entries[2]; - char size[4]; - char offset[4]; - char comment_length[2]; + char signature[4]; + char disk[2]; + char start_disk[2]; + char entries_disk[2]; + char entries[2]; + char size[4]; + char offset[4]; + char comment_length[2]; }; static int archive_write_zip_options(struct archive_write *a, const char *key, - const char *value) + const char *val) { - struct zip *zip = a->format_data; - - if (strcmp(key, "compression") == 0) { - if (strcmp(value, "deflate") == 0) { + struct zip *zip = a->format_data; + int ret = ARCHIVE_FAILED; + + if (strcmp(key, "compression") == 0) { + if (val == NULL || val[0] == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: compression option needs a compression name", + a->format_name); + } else if (strcmp(val, "deflate") == 0) { #ifdef HAVE_ZLIB_H - zip->compression = COMPRESSION_DEFLATE; + zip->compression = COMPRESSION_DEFLATE; + ret = ARCHIVE_OK; #else - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "deflate compression not supported"); - return ARCHIVE_WARN; + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "deflate compression not supported"); #endif - } else if (strcmp(value, "store") == 0) - zip->compression = COMPRESSION_STORE; - else - return (ARCHIVE_WARN); - return (ARCHIVE_OK); - } - return (ARCHIVE_WARN); + } else if (strcmp(val, "store") == 0) { + zip->compression = COMPRESSION_STORE; + ret = ARCHIVE_OK; + } + } else if (strcmp(key, "hdrcharset") == 0) { + if (val == NULL || val[0] == 0) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: hdrcharset option needs a character-set name", + a->format_name); + } else { + zip->opt_sconv = archive_string_conversion_to_charset( + &a->archive, val, 0); + if (zip->opt_sconv != NULL) + ret = ARCHIVE_OK; + else + ret = ARCHIVE_FATAL; + } + } else + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "%s: unknown keyword ``%s''", a->format_name, key); + return (ret); } int archive_write_set_format_zip(struct archive *_a) { - struct archive_write *a = (struct archive_write *)_a; - struct zip *zip; - - /* If another format was already registered, unregister it. */ - if (a->format_destroy != NULL) - (a->format_destroy)(a); - - zip = (struct zip *) malloc(sizeof(*zip)); - if (zip == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip data"); - return (ARCHIVE_FATAL); - } - zip->central_directory = NULL; - zip->central_directory_end = NULL; - zip->offset = 0; - zip->written_bytes = 0; - zip->remaining_data_bytes = 0; + struct archive_write *a = (struct archive_write *)_a; + struct zip *zip; + + archive_check_magic(_a, ARCHIVE_WRITE_MAGIC, + ARCHIVE_STATE_NEW, "archive_write_set_format_zip"); + + /* If another format was already registered, unregister it. */ + if (a->format_free != NULL) + (a->format_free)(a); + + zip = (struct zip *) calloc(1, sizeof(*zip)); + if (zip == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip data"); + return (ARCHIVE_FATAL); + } + zip->central_directory = NULL; + zip->central_directory_end = NULL; + zip->offset = 0; + zip->written_bytes = 0; + zip->remaining_data_bytes = 0; #ifdef HAVE_ZLIB_H - zip->compression = COMPRESSION_DEFLATE; - zip->len_buf = 65536; - zip->buf = malloc(zip->len_buf); - if (zip->buf == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate compression buffer"); - return (ARCHIVE_FATAL); - } + zip->compression = COMPRESSION_DEFLATE; + zip->len_buf = 65536; + zip->buf = malloc(zip->len_buf); + if (zip->buf == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate compression buffer"); + return (ARCHIVE_FATAL); + } #else - zip->compression = COMPRESSION_STORE; + zip->compression = COMPRESSION_STORE; #endif - a->format_data = zip; - - a->pad_uncompressed = 0; /* Actually not needed for now, since no compression support yet. */ - a->format_name = "zip"; - a->format_options = archive_write_zip_options; - a->format_write_header = archive_write_zip_header; - a->format_write_data = archive_write_zip_data; - a->format_finish_entry = archive_write_zip_finish_entry; - a->format_finish = archive_write_zip_finish; - a->format_destroy = archive_write_zip_destroy; - a->archive.archive_format = ARCHIVE_FORMAT_ZIP; - a->archive.archive_format_name = "ZIP"; + a->format_data = zip; + a->format_name = "zip"; + a->format_options = archive_write_zip_options; + a->format_write_header = archive_write_zip_header; + a->format_write_data = archive_write_zip_data; + a->format_finish_entry = archive_write_zip_finish_entry; + a->format_close = archive_write_zip_close; + a->format_free = archive_write_zip_free; + a->archive.archive_format = ARCHIVE_FORMAT_ZIP; + a->archive.archive_format_name = "ZIP"; + + archive_le32enc(&zip->data_descriptor.signature, + ZIP_SIGNATURE_DATA_DESCRIPTOR); + + return (ARCHIVE_OK); +} - archive_le32enc(&zip->data_descriptor.signature, - ZIP_SIGNATURE_DATA_DESCRIPTOR); +static int +is_all_ascii(const char *p) +{ + const unsigned char *pp = (const unsigned char *)p; - return (ARCHIVE_OK); + while (*pp) { + if (*pp++ > 127) + return (0); + } + return (1); } static int archive_write_zip_header(struct archive_write *a, struct archive_entry *entry) { - struct zip *zip; - struct zip_local_file_header h; - struct zip_extra_data_local e; - struct zip_data_descriptor *d; - struct zip_file_header_link *l; - int ret; - int64_t size; - mode_t type; - - /* Entries other than a regular file or a folder are skipped. */ - type = archive_entry_filetype(entry); - if ((type != AE_IFREG) & (type != AE_IFDIR)) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Filetype not supported"); - return ARCHIVE_FAILED; - }; - - /* Directory entries should have a size of 0. */ - if (type == AE_IFDIR) - archive_entry_set_size(entry, 0); - - zip = a->format_data; - d = &zip->data_descriptor; - size = archive_entry_size(entry); - zip->remaining_data_bytes = size; - - /* Append archive entry to the central directory data. */ - l = (struct zip_file_header_link *) malloc(sizeof(*l)); - if (l == NULL) { - archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data"); - return (ARCHIVE_FATAL); - } - l->entry = archive_entry_clone(entry); - /* Initialize the CRC variable and potentially the local crc32(). */ - l->crc32 = crc32(0, NULL, 0); - l->compression = zip->compression; - l->compressed_size = 0; - l->next = NULL; - if (zip->central_directory == NULL) { - zip->central_directory = l; - } else { - zip->central_directory_end->next = l; - } - zip->central_directory_end = l; - - /* Store the offset of this header for later use in central directory. */ - l->offset = zip->written_bytes; - - memset(&h, 0, sizeof(h)); - archive_le32enc(&h.signature, ZIP_SIGNATURE_LOCAL_FILE_HEADER); - archive_le16enc(&h.version, ZIP_VERSION_EXTRACT); - archive_le16enc(&h.flags, ZIP_FLAGS); - archive_le16enc(&h.compression, zip->compression); - archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(entry))); - archive_le16enc(&h.filename_length, path_length(entry)); - - switch (zip->compression) { - case COMPRESSION_STORE: - /* Setting compressed and uncompressed sizes even when specification says - * to set to zero when using data descriptors. Otherwise the end of the - * data for an entry is rather difficult to find. */ - archive_le32enc(&h.compressed_size, size); - archive_le32enc(&h.uncompressed_size, size); - break; + struct zip *zip; + struct zip_local_file_header h; + struct zip_extra_data_local e; + struct zip_data_descriptor *d; + struct zip_file_header_link *l; + struct archive_string_conv *sconv; + int ret, ret2 = ARCHIVE_OK; + int64_t size; + mode_t type; + + /* Entries other than a regular file or a folder are skipped. */ + type = archive_entry_filetype(entry); + if (type != AE_IFREG && type != AE_IFDIR && type != AE_IFLNK) { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Filetype not supported"); + return ARCHIVE_FAILED; + }; + + /* Directory entries should have a size of 0. */ + if (type == AE_IFDIR) + archive_entry_set_size(entry, 0); + + zip = a->format_data; + /* Setup default conversion. */ + if (zip->opt_sconv == NULL && !zip->init_default_conversion) { + zip->sconv_default = + archive_string_default_conversion_for_write(&(a->archive)); + zip->init_default_conversion = 1; + } + + if (zip->flags == 0) { + /* Initialize the general purpose flags. */ + zip->flags = ZIP_FLAGS; + if (zip->opt_sconv != NULL) { + if (strcmp(archive_string_conversion_charset_name( + zip->opt_sconv), "UTF-8") == 0) + zip->flags |= ZIP_FLAGS_UTF8_NAME; +#if HAVE_NL_LANGINFO + } else if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) { + zip->flags |= ZIP_FLAGS_UTF8_NAME; +#endif + } + } + d = &zip->data_descriptor; + size = archive_entry_size(entry); + zip->remaining_data_bytes = size; + + /* Append archive entry to the central directory data. */ + l = (struct zip_file_header_link *) malloc(sizeof(*l)); + if (l == NULL) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate zip header data"); + return (ARCHIVE_FATAL); + } + l->entry = archive_entry_clone(entry); + l->flags = zip->flags; + if (zip->opt_sconv != NULL) + sconv = zip->opt_sconv; + else + sconv = zip->sconv_default; + if (sconv != NULL) { + const char *p; + size_t len; + + if (archive_entry_pathname_l(entry, &p, &len, sconv) != 0) { + if (errno == ENOMEM) { + archive_set_error(&a->archive, ENOMEM, + "Can't allocate memory for Pathname"); + return (ARCHIVE_FATAL); + } + archive_set_error(&a->archive, + ARCHIVE_ERRNO_FILE_FORMAT, + "Can't translate pathname '%s' to %s", + archive_entry_pathname(entry), + archive_string_conversion_charset_name(sconv)); + ret2 = ARCHIVE_WARN; + } + if (len > 0) + archive_entry_set_pathname(l->entry, p); + } + /* If all character of a filename is ASCII, Reset UTF-8 Name flag. */ + if ((l->flags & ZIP_FLAGS_UTF8_NAME) != 0 && + is_all_ascii(archive_entry_pathname(l->entry))) + l->flags &= ~ZIP_FLAGS_UTF8_NAME; + + /* Initialize the CRC variable and potentially the local crc32(). */ + l->crc32 = crc32(0, NULL, 0); + if (type == AE_IFLNK) { + const char *p = archive_entry_symlink(l->entry); + if (p != NULL) + size = strlen(p); + else + size = 0; + zip->remaining_data_bytes = 0; + archive_entry_set_size(l->entry, size); + l->compression = COMPRESSION_STORE; + l->compressed_size = size; + } else { + l->compression = zip->compression; + l->compressed_size = 0; + } + l->next = NULL; + if (zip->central_directory == NULL) { + zip->central_directory = l; + } else { + zip->central_directory_end->next = l; + } + zip->central_directory_end = l; + + /* Store the offset of this header for later use in central + * directory. */ + l->offset = zip->written_bytes; + + memset(&h, 0, sizeof(h)); + archive_le32enc(&h.signature, ZIP_SIGNATURE_LOCAL_FILE_HEADER); + archive_le16enc(&h.version, ZIP_VERSION_EXTRACT); + archive_le16enc(&h.flags, l->flags); + archive_le16enc(&h.compression, l->compression); + archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(entry))); + archive_le16enc(&h.filename_length, (uint16_t)path_length(l->entry)); + + switch (l->compression) { + case COMPRESSION_STORE: + /* Setting compressed and uncompressed sizes even when + * specification says to set to zero when using data + * descriptors. Otherwise the end of the data for an + * entry is rather difficult to find. */ + archive_le32enc(&h.compressed_size, size); + archive_le32enc(&h.uncompressed_size, size); + break; #ifdef HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - archive_le32enc(&h.uncompressed_size, size); - - zip->stream.zalloc = Z_NULL; - zip->stream.zfree = Z_NULL; - zip->stream.opaque = Z_NULL; - zip->stream.next_out = zip->buf; - zip->stream.avail_out = zip->len_buf; - if (deflateInit2(&zip->stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, - -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) { - archive_set_error(&a->archive, ENOMEM, "Can't init deflate compressor"); - return (ARCHIVE_FATAL); - } - break; + case COMPRESSION_DEFLATE: + archive_le32enc(&h.uncompressed_size, size); + + zip->stream.zalloc = Z_NULL; + zip->stream.zfree = Z_NULL; + zip->stream.opaque = Z_NULL; + zip->stream.next_out = zip->buf; + zip->stream.avail_out = zip->len_buf; + if (deflateInit2(&zip->stream, Z_DEFAULT_COMPRESSION, + Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK) { + archive_set_error(&a->archive, ENOMEM, + "Can't init deflate compressor"); + return (ARCHIVE_FATAL); + } + break; #endif - } - - /* Formatting extra data. */ - archive_le16enc(&h.extra_length, sizeof(e)); - archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); - archive_le16enc(&e.time_size, sizeof(e.time_flag) + - sizeof(e.mtime) + sizeof(e.atime) + sizeof(e.ctime)); - e.time_flag[0] = 0x07; - archive_le32enc(&e.mtime, archive_entry_mtime(entry)); - archive_le32enc(&e.atime, archive_entry_atime(entry)); - archive_le32enc(&e.ctime, archive_entry_ctime(entry)); - - archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_UNIX); - archive_le16enc(&e.unix_size, sizeof(e.unix_uid) + sizeof(e.unix_gid)); - archive_le16enc(&e.unix_uid, archive_entry_uid(entry)); - archive_le16enc(&e.unix_gid, archive_entry_gid(entry)); - - archive_le32enc(&d->uncompressed_size, size); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(h); - - ret = write_path(entry, a); - if (ret <= ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += ret; - - ret = (a->compressor.write)(a, &e, sizeof(e)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(e); - - return (ARCHIVE_OK); + } + + /* Formatting extra data. */ + archive_le16enc(&h.extra_length, sizeof(e)); + archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); + archive_le16enc(&e.time_size, sizeof(e.time_flag) + + sizeof(e.mtime) + sizeof(e.atime) + sizeof(e.ctime)); + e.time_flag[0] = 0x07; + archive_le32enc(&e.mtime, archive_entry_mtime(entry)); + archive_le32enc(&e.atime, archive_entry_atime(entry)); + archive_le32enc(&e.ctime, archive_entry_ctime(entry)); + + archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_NEW_UNIX); + archive_le16enc(&e.unix_size, sizeof(e.unix_version) + + sizeof(e.unix_uid_size) + sizeof(e.unix_uid) + + sizeof(e.unix_gid_size) + sizeof(e.unix_gid)); + e.unix_version = 1; + e.unix_uid_size = 4; + archive_le32enc(&e.unix_uid, archive_entry_uid(entry)); + e.unix_gid_size = 4; + archive_le32enc(&e.unix_gid, archive_entry_gid(entry)); + + archive_le32enc(&d->uncompressed_size, size); + + ret = __archive_write_output(a, &h, sizeof(h)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(h); + + ret = write_path(l->entry, a); + if (ret <= ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += ret; + + ret = __archive_write_output(a, &e, sizeof(e)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(e); + + if (type == AE_IFLNK) { + const unsigned char *p; + + p = (const unsigned char *)archive_entry_symlink(l->entry); + ret = __archive_write_output(a, p, size); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += size; + l->crc32 = crc32(l->crc32, p, size); + } + + if (ret2 != ARCHIVE_OK) + return (ret2); + return (ARCHIVE_OK); } static ssize_t archive_write_zip_data(struct archive_write *a, const void *buff, size_t s) { - int ret; - struct zip *zip = a->format_data; - struct zip_file_header_link *l = zip->central_directory_end; - - if (s > (size_t)zip->remaining_data_bytes) - s = (size_t)zip->remaining_data_bytes; - - if (s == 0) return 0; - - switch (zip->compression) { - case COMPRESSION_STORE: - ret = (a->compressor.write)(a, buff, s); - if (ret != ARCHIVE_OK) return (ret); - zip->written_bytes += s; - zip->remaining_data_bytes -= s; - l->compressed_size += s; - l->crc32 = crc32(l->crc32, buff, s); - return (s); + int ret; + struct zip *zip = a->format_data; + struct zip_file_header_link *l = zip->central_directory_end; + + if ((int64_t)s > zip->remaining_data_bytes) + s = (size_t)zip->remaining_data_bytes; + + if (s == 0) return 0; + + switch (l->compression) { + case COMPRESSION_STORE: + ret = __archive_write_output(a, buff, s); + if (ret != ARCHIVE_OK) return (ret); + zip->written_bytes += s; + zip->remaining_data_bytes -= s; + l->compressed_size += s; + l->crc32 = crc32(l->crc32, buff, s); + return (s); #if HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - zip->stream.next_in = (unsigned char*)(uintptr_t)buff; - zip->stream.avail_in = s; - do { - ret = deflate(&zip->stream, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) - return (ARCHIVE_FATAL); - if (zip->stream.avail_out == 0) { - ret = (a->compressor.write)(a, zip->buf, zip->len_buf); - if (ret != ARCHIVE_OK) - return (ret); - l->compressed_size += zip->len_buf; - zip->written_bytes += zip->len_buf; - zip->stream.next_out = zip->buf; - zip->stream.avail_out = zip->len_buf; - } - } while (zip->stream.avail_in != 0); - zip->remaining_data_bytes -= s; - /* If we have it, use zlib's fast crc32() */ - l->crc32 = crc32(l->crc32, buff, s); - return (s); + case COMPRESSION_DEFLATE: + zip->stream.next_in = (unsigned char*)(uintptr_t)buff; + zip->stream.avail_in = s; + do { + ret = deflate(&zip->stream, Z_NO_FLUSH); + if (ret == Z_STREAM_ERROR) + return (ARCHIVE_FATAL); + if (zip->stream.avail_out == 0) { + ret = __archive_write_output(a, zip->buf, + zip->len_buf); + if (ret != ARCHIVE_OK) + return (ret); + l->compressed_size += zip->len_buf; + zip->written_bytes += zip->len_buf; + zip->stream.next_out = zip->buf; + zip->stream.avail_out = zip->len_buf; + } + } while (zip->stream.avail_in != 0); + zip->remaining_data_bytes -= s; + /* If we have it, use zlib's fast crc32() */ + l->crc32 = crc32(l->crc32, buff, s); + return (s); #endif - default: - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Invalid ZIP compression type"); - return ARCHIVE_FATAL; - } + default: + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Invalid ZIP compression type"); + return ARCHIVE_FATAL; + } } static int archive_write_zip_finish_entry(struct archive_write *a) { - /* Write the data descripter after file data has been written. */ - int ret; - struct zip *zip = a->format_data; - struct zip_data_descriptor *d = &zip->data_descriptor; - struct zip_file_header_link *l = zip->central_directory_end; + /* Write the data descripter after file data has been written. */ + int ret; + struct zip *zip = a->format_data; + struct zip_data_descriptor *d = &zip->data_descriptor; + struct zip_file_header_link *l = zip->central_directory_end; #if HAVE_ZLIB_H - size_t reminder; + size_t reminder; #endif - switch(zip->compression) { - case COMPRESSION_STORE: - break; + switch(l->compression) { + case COMPRESSION_STORE: + break; #if HAVE_ZLIB_H - case COMPRESSION_DEFLATE: - for (;;) { - ret = deflate(&zip->stream, Z_FINISH); - if (ret == Z_STREAM_ERROR) - return (ARCHIVE_FATAL); - reminder = zip->len_buf - zip->stream.avail_out; - ret = (a->compressor.write)(a, zip->buf, reminder); - if (ret != ARCHIVE_OK) - return (ret); - l->compressed_size += reminder; - zip->written_bytes += reminder; - zip->stream.next_out = zip->buf; - if (zip->stream.avail_out != 0) - break; - zip->stream.avail_out = zip->len_buf; - } - deflateEnd(&zip->stream); - break; + case COMPRESSION_DEFLATE: + for (;;) { + ret = deflate(&zip->stream, Z_FINISH); + if (ret == Z_STREAM_ERROR) + return (ARCHIVE_FATAL); + reminder = zip->len_buf - zip->stream.avail_out; + ret = __archive_write_output(a, zip->buf, reminder); + if (ret != ARCHIVE_OK) + return (ret); + l->compressed_size += reminder; + zip->written_bytes += reminder; + zip->stream.next_out = zip->buf; + if (zip->stream.avail_out != 0) + break; + zip->stream.avail_out = zip->len_buf; + } + deflateEnd(&zip->stream); + break; #endif - } - - archive_le32enc(&d->crc32, l->crc32); - archive_le32enc(&d->compressed_size, l->compressed_size); - ret = (a->compressor.write)(a, d, sizeof(*d)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(*d); - return (ARCHIVE_OK); + } + + archive_le32enc(&d->crc32, l->crc32); + archive_le32enc(&d->compressed_size, l->compressed_size); + ret = __archive_write_output(a, d, sizeof(*d)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(*d); + return (ARCHIVE_OK); } static int -archive_write_zip_finish(struct archive_write *a) +archive_write_zip_close(struct archive_write *a) { - struct zip *zip; - struct zip_file_header_link *l; - struct zip_file_header h; - struct zip_central_directory_end end; - struct zip_extra_data_central e; - off_t offset_start, offset_end; - int entries; - int ret; - - zip = a->format_data; - l = zip->central_directory; - - /* - * Formatting central directory file header fields that are fixed for all entries. - * Fields not used (and therefor 0) are: - * - * - comment_length - * - disk_number - * - attributes_internal - */ - memset(&h, 0, sizeof(h)); - archive_le32enc(&h.signature, ZIP_SIGNATURE_FILE_HEADER); - archive_le16enc(&h.version_by, ZIP_VERSION_BY); - archive_le16enc(&h.version_extract, ZIP_VERSION_EXTRACT); - archive_le16enc(&h.flags, ZIP_FLAGS); - - entries = 0; - offset_start = zip->written_bytes; - - /* Formatting individual header fields per entry and - * writing each entry. */ - while (l != NULL) { - archive_le16enc(&h.compression, l->compression); - archive_le32enc(&h.timedate, dos_time(archive_entry_mtime(l->entry))); - archive_le32enc(&h.crc32, l->crc32); - archive_le32enc(&h.compressed_size, l->compressed_size); - archive_le32enc(&h.uncompressed_size, archive_entry_size(l->entry)); - archive_le16enc(&h.filename_length, path_length(l->entry)); - archive_le16enc(&h.extra_length, sizeof(e)); - archive_le16enc(&h.attributes_external[2], archive_entry_mode(l->entry)); - archive_le32enc(&h.offset, l->offset); - - /* Formatting extra data. */ - archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); - archive_le16enc(&e.time_size, sizeof(e.mtime) + sizeof(e.time_flag)); - e.time_flag[0] = 0x07; - archive_le32enc(&e.mtime, archive_entry_mtime(l->entry)); - archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_UNIX); - archive_le16enc(&e.unix_size, 0x0000); - - ret = (a->compressor.write)(a, &h, sizeof(h)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(h); - - ret = write_path(l->entry, a); - if (ret <= ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += ret; - - ret = (a->compressor.write)(a, &e, sizeof(e)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(e); - - l = l->next; - entries++; - } - offset_end = zip->written_bytes; - - /* Formatting end of central directory. */ - memset(&end, 0, sizeof(end)); - archive_le32enc(&end.signature, ZIP_SIGNATURE_CENTRAL_DIRECTORY_END); - archive_le16enc(&end.entries_disk, entries); - archive_le16enc(&end.entries, entries); - archive_le32enc(&end.size, offset_end - offset_start); - archive_le32enc(&end.offset, offset_start); - - /* Writing end of central directory. */ - ret = (a->compressor.write)(a, &end, sizeof(end)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - zip->written_bytes += sizeof(end); - return (ARCHIVE_OK); + struct zip *zip; + struct zip_file_header_link *l; + struct zip_file_header h; + struct zip_central_directory_end end; + struct zip_extra_data_central e; + int64_t offset_start, offset_end; + int entries; + int ret; + + zip = a->format_data; + l = zip->central_directory; + + /* + * Formatting central directory file header fields that are + * fixed for all entries. + * Fields not used (and therefor 0) are: + * + * - comment_length + * - disk_number + * - attributes_internal + */ + memset(&h, 0, sizeof(h)); + archive_le32enc(&h.signature, ZIP_SIGNATURE_FILE_HEADER); + archive_le16enc(&h.version_by, ZIP_VERSION_BY); + archive_le16enc(&h.version_extract, ZIP_VERSION_EXTRACT); + + entries = 0; + offset_start = zip->written_bytes; + + /* Formatting individual header fields per entry and + * writing each entry. */ + while (l != NULL) { + archive_le16enc(&h.flags, l->flags); + archive_le16enc(&h.compression, l->compression); + archive_le32enc(&h.timedate, + dos_time(archive_entry_mtime(l->entry))); + archive_le32enc(&h.crc32, l->crc32); + archive_le32enc(&h.compressed_size, l->compressed_size); + archive_le32enc(&h.uncompressed_size, + archive_entry_size(l->entry)); + archive_le16enc(&h.filename_length, + (uint16_t)path_length(l->entry)); + archive_le16enc(&h.extra_length, sizeof(e)); + archive_le16enc(&h.attributes_external[2], + archive_entry_mode(l->entry)); + archive_le32enc(&h.offset, l->offset); + + /* Formatting extra data. */ + archive_le16enc(&e.time_id, ZIP_SIGNATURE_EXTRA_TIMESTAMP); + archive_le16enc(&e.time_size, + sizeof(e.mtime) + sizeof(e.time_flag)); + e.time_flag[0] = 0x07; + archive_le32enc(&e.mtime, archive_entry_mtime(l->entry)); + archive_le16enc(&e.unix_id, ZIP_SIGNATURE_EXTRA_NEW_UNIX); + archive_le16enc(&e.unix_size, 0x0000); + + ret = __archive_write_output(a, &h, sizeof(h)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(h); + + ret = write_path(l->entry, a); + if (ret <= ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += ret; + + ret = __archive_write_output(a, &e, sizeof(e)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(e); + + l = l->next; + entries++; + } + offset_end = zip->written_bytes; + + /* Formatting end of central directory. */ + memset(&end, 0, sizeof(end)); + archive_le32enc(&end.signature, ZIP_SIGNATURE_CENTRAL_DIRECTORY_END); + archive_le16enc(&end.entries_disk, entries); + archive_le16enc(&end.entries, entries); + archive_le32enc(&end.size, offset_end - offset_start); + archive_le32enc(&end.offset, offset_start); + + /* Writing end of central directory. */ + ret = __archive_write_output(a, &end, sizeof(end)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + zip->written_bytes += sizeof(end); + return (ARCHIVE_OK); } static int -archive_write_zip_destroy(struct archive_write *a) +archive_write_zip_free(struct archive_write *a) { - struct zip *zip; - struct zip_file_header_link *l; - - zip = a->format_data; - while (zip->central_directory != NULL) { - l = zip->central_directory; - zip->central_directory = l->next; - archive_entry_free(l->entry); - free(l); - } + struct zip *zip; + struct zip_file_header_link *l; + + zip = a->format_data; + while (zip->central_directory != NULL) { + l = zip->central_directory; + zip->central_directory = l->next; + archive_entry_free(l->entry); + free(l); + } #ifdef HAVE_ZLIB_H - free(zip->buf); + free(zip->buf); #endif - free(zip); - a->format_data = NULL; - return (ARCHIVE_OK); + free(zip); + a->format_data = NULL; + return (ARCHIVE_OK); } /* Convert into MSDOS-style date/time. */ static unsigned int dos_time(const time_t unix_time) { - struct tm *t; - unsigned int dt; - - /* This will not preserve time when creating/extracting the archive - * on two systems with different time zones. */ - t = localtime(&unix_time); - - dt = 0; - dt += ((t->tm_year - 80) & 0x7f) << 9; - dt += ((t->tm_mon + 1) & 0x0f) << 5; - dt += (t->tm_mday & 0x1f); - dt <<= 16; - dt += (t->tm_hour & 0x1f) << 11; - dt += (t->tm_min & 0x3f) << 5; - dt += (t->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds. */ - return dt; + struct tm *t; + unsigned int dt; + + /* This will not preserve time when creating/extracting the archive + * on two systems with different time zones. */ + t = localtime(&unix_time); + + /* MSDOS-style date/time is only between 1980-01-01 and 2107-12-31 */ + if (t->tm_year < 1980 - 1900) + /* Set minimum date/time '1980-01-01 00:00:00'. */ + dt = 0x00210000U; + else if (t->tm_year > 2107 - 1900) + /* Set maximum date/time '2107-12-31 23:59:58'. */ + dt = 0xff9fbf7dU; + else { + dt = 0; + dt += ((t->tm_year - 80) & 0x7f) << 9; + dt += ((t->tm_mon + 1) & 0x0f) << 5; + dt += (t->tm_mday & 0x1f); + dt <<= 16; + dt += (t->tm_hour & 0x1f) << 11; + dt += (t->tm_min & 0x3f) << 5; + dt += (t->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds. */ + } + return dt; } static size_t path_length(struct archive_entry *entry) { - mode_t type; - const char *path; + mode_t type; + const char *path; - type = archive_entry_filetype(entry); - path = archive_entry_pathname(entry); + type = archive_entry_filetype(entry); + path = archive_entry_pathname(entry); - if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { - return strlen(path) + 1; - } else { - return strlen(path); - } + if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { + return strlen(path) + 1; + } else { + return strlen(path); + } } static int write_path(struct archive_entry *entry, struct archive_write *archive) { - int ret; - const char *path; - mode_t type; - size_t written_bytes; - - path = archive_entry_pathname(entry); - type = archive_entry_filetype(entry); - written_bytes = 0; - - ret = (archive->compressor.write)(archive, path, strlen(path)); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - written_bytes += strlen(path); - - /* Folders are recognized by a traling slash. */ - if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { - ret = (archive->compressor.write)(archive, "/", 1); - if (ret != ARCHIVE_OK) - return (ARCHIVE_FATAL); - written_bytes += 1; - } - - return written_bytes; + int ret; + const char *path; + mode_t type; + size_t written_bytes; + + path = archive_entry_pathname(entry); + type = archive_entry_filetype(entry); + written_bytes = 0; + + ret = __archive_write_output(archive, path, strlen(path)); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + written_bytes += strlen(path); + + /* Folders are recognized by a traling slash. */ + if ((type == AE_IFDIR) & (path[strlen(path) - 1] != '/')) { + ret = __archive_write_output(archive, "/", 1); + if (ret != ARCHIVE_OK) + return (ARCHIVE_FATAL); + written_bytes += 1; + } + + return ((int)written_bytes); } diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 new file mode 100644 index 000000000..9a8ea3dbf --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.3 @@ -0,0 +1,437 @@ +.\" Copyright (c) 2003-2010 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: head/lib/libarchive/archive_write.3 201110 2009-12-28 03:31:29Z kientzle $ +.\" +.Dd Feb 27, 2010 +.Dt ARCHIVE_WRITE_OPTIONS 3 +.Os +.Sh NAME +.Nm archive_write_set_filter_option , +.Nm archive_write_set_format_option , +.Nm archive_write_set_option , +.Nm archive_write_set_options +.Nd functions controlling options for reading archives +.Sh SYNOPSIS +.\" +.Sh SYNOPSIS +.Ft int +.Fo archive_write_set_filter_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_write_set_format_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_write_set_option +.Fa "struct archive *" +.Fa "const char *module" +.Fa "const char *option" +.Fa "const char *value" +.Fc +.Ft int +.Fo archive_write_set_options +.Fa "struct archive *" +.Fa "const char *options" +.Fc +.Sh DESCRIPTION +These functions provide a way for libarchive clients to configure +specific write modules. +.Bl -tag -width indent +.It Xo +.Fn archive_write_set_filter_option , +.Fn archive_write_set_format_option +.Xc +Specifies an option that will be passed to currently-registered +filters (including decompression filters) or format readers. +.Pp +If +.Ar option +and +.Ar value +are both +.Dv NULL , +these functions will do nothing and +.Cm ARCHIVE_OK +will be returned. +If +.Ar option +is +.Dv NULL +but +.Ar value +is not, these functions will do nothing and +.Cm ARCHIVE_FAILED +will be returned. +.Pp +If +.Ar module +is not +.Dv NULL , +.Ar option +and +.Ar value +will be provided to the filter or reader named +.Ar module . +The return value will be that of the module. +If there is no such module, +.Cm ARCHIVE_FAILED +will be returned. +.Pp +If +.Ar module +is +.Dv NULL , +.Ar option +and +.Ar value +will be provided to every registered module. +If any module returns +.Cm ARCHIVE_FATAL , +this value will be returned immediately. +Otherwise, +.Cm ARCHIVE_OK +will be returned if any module accepts the option, and +.Cm ARCHIVE_FAILED +in all other cases. +.\" +.It Xo +.Fn archive_write_set_option +.Xc +Calls +.Fn archive_write_set_format_option , +then +.Fn archive_write_set_filter_option . +If either function returns +.Cm ARCHIVE_FATAL , +.Cm ARCHIVE_FATAL +will be returned +immediately. +Otherwise, greater of the two values will be returned. +.\" +.It Xo +.Fn archive_write_set_options +.Xc +.Ar options +is a comma-separated list of options. +If +.Ar options +is +.Dv NULL +or empty, +.Cm ARCHIVE_OK +will be returned immediately. +.Pp +Individual options have one of the following forms: +.Bl -tag -compact -width indent +.It Ar option=value +The option/value pair will be provided to every module. +Modules that do not accept an option with this name will ignore it. +.It Ar option +The option will be provided to every module with a value of +.Dq 1 . +.It Ar !option +The option will be provided to every module with a NULL value. +.It Ar module:option=value , Ar module:option , Ar module:!option +As above, but the corresponding option and value will be provided +only to modules whose name matches +.Ar module . +.El +.El +.\" +.Sh OPTIONS +.Bl -tag -compact -width indent +.It Filter gzip +.Bl -tag -compact -width indent +.It Cm compression-level +The value is interpreted as a decimal integer specifying the +gzip compression level. +.El +.It Filter xz +.Bl -tag -compact -width indent +.It Cm compression-level +The value is interpreted as a decimal integer specifying the +compression level. +.El +.It Format mtree +.Bl -tag -compact -width indent +.It Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname +Enable a particular keyword in the mtree output. +Prefix with an exclamation mark to disable the corresponding keyword. +The default is equivalent to +.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . +.It Cm all +Enables all of the above keywords. +.It Cm use-set +Enables generation of +.Cm /set +lines that specify default values for the following files and/or directories. +.It Cm indent +XXX needs explanation XXX +.El +.It Format iso9660 - volume metadata +These options are used to set standard ISO9660 metadata. +.Bl -tag -compact -width indent +.It Cm abstract-file Ns = Ns Ar filename +The file with the specified name will be identified in the ISO9660 metadata +as holding the abstract for this volume. Default: none. +.It Cm application-id Ns = Ns Ar filename +The file with the specified name will be identified in the ISO9660 metadata +as holding the application identifier for this volume. Default: none. +.It Cm biblio-file Ns = Ns Ar filename +The file with the specified name will be identified in the ISO9660 metadata +as holding the bibliography for this volume. Default: none. +.It Cm copyright-file Ns = Ns Ar filename +The file with the specified name will be identified in the ISO9660 metadata +as holding the copyright for this volume. Default: none. +.It Cm publisher Ns = Ns Ar filename +The file with the specified name will be identified in the ISO9660 metadata +as holding the publisher information for this volume. Default: none. +.It Cm volume-id Ns = Ns Ar string +The specified string will be used as the Volume Identifier in the ISO9660 metadata. +It is limited to 32 bytes. Default: none. +.El +.It Format iso9660 - boot support +These options are used to make an ISO9660 image that can be directly +booted on various systems. +.Bl -tag -compact -width indent +.It Cm boot Ns = Ns Ar filename +The file matching this name will be used as the El Torito boot image file. +.It Cm boot-catalog Ns = Ns Ar name +The name that will be used for the El Torito boot catalog. +Default: +.Ar boot.catalog +.It Cm boot-info-table +The boot image file provided by the +.Cm boot Ns = Ns Ar filename +option will be edited with appropriate boot information in bytes 8 through 64. +Default: disabled +.It Cm boot-load-seg Ns = Ns Ar hexadecimal-number +The load segment for a no-emulation boot image. +.It Cm boot-load-size Ns = Ns Ar decimal-number +The number of "virtual" 512-byte sectors to be loaded from a no-emulation boot image. +Some very old BIOSes can only load very small images, setting this +value to 4 will often allow such BIOSes to load the first part of +the boot image (which will then need to be intelligent enough to +load the rest of itself). +This should not be needed unless you are trying to support systems with very old BIOSes. +This defaults to the full size of the image. +.It Cm boot-type Ns = Ns Ar value +Specifies the boot semantics used by the El Torito boot image: +If the +.Ar value +is +.Cm fd , +then the boot image is assumed to be a bootable floppy image. +If the +.Ar value +is +.Cm hd , +then the the boot image is assumed to be a bootable hard disk image. +If the +.Ar value +is +.Cm no-emulation , +the boot image is used without floppy or hard disk emulation. +If the boot image is exactly 1.2MB, 1.44MB, or 2.88MB, then +the default is +.Cm fd , +otherwise the default is +.Cm no-emulation. +.El +.It Format iso9660 - filename and size extensions +Various extensions to the base ISO9660 format. +.Bl -tag -compact -width indent +.It Cm allow-ldots +If enabled, allows filenames to begin with a leading period. +If disabled, filenames that begin with a leading period will have +that period replaced by an underscore character in the standard ISO9660 +namespace. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: disabled. +.It Cm allow-lowercase +If enabled, allows filenames to contain lowercase characters. +If disabled, filenames will be forced to uppercase. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: disabled. +.It Cm allow-multidot +If enabled, allows filenames to contain multiple period characters, in violation of the ISO9660 specification. +If disabled, additional periods will be converted to underscore characters. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: disabled. +.It Cm allow-period +If enabled, allows filenames to contain trailing period characters, in violation of the ISO9660 specification. +If disabled,trailing periods will be converted to underscore characters. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: disabled. +.It Cm allow-pvd-lowercase +If enabled, the Primary Volume Descriptor may contain lowercase ASCII characters, in violation of the ISO9660 specification. +If disabled, characters will be converted to uppercase ASCII. +Default: disabled. +.It Cm allow-sharp-tilde +If enabled, sharp and tilde characters will be permitted in filenames, in violation if the ISO9660 specification. +If disabled, such characters will be converted to underscore characters. +Default: disabled. +.It Cm allow-vernum +If enabled, version numbers will be included with files. +If disabled, version numbers will be suppressed, in violation of the ISO9660 standard. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: enabled. +.It Cm iso-level +This enables support for file size and file name extensions in the +core ISO9660 area. +The name extensions specified here do not affect the names stored in the Rockridge or Joliet extension areas. +.Bl -tag -compact -width indent +.It Cm iso-level=1 +The most compliant form of ISO9660 image. +Filenames are limited to 8.3 uppercase format, +directory names are limited to 8 uppercase characters, +files are limited to 4 GiB, +the complete ISO9660 image cannot exceed 4 GiB. +.It Cm iso-level=2 +Filenames are limited to 30 uppercase characters with a 30-character extension, +directory names are limited to 30 characters, +files are limited to 4 GiB. +.It Cm iso-level=3 +As with +.Cm iso-level=2 , +except that files may exceed 4 GiB. +.It Cm iso-level=4 +As with +.Cm iso-level=3 , +except that filenames may be up to 193 characters +and may include arbitrary 8-bit characters. +.El +.It Cm joliet +Microsoft's Joliet extensions store a completely separate set of directory information about each file. +In particular, this information includes Unicode filenames of up to 255 characters. +Default: enabled. +.It Cm limit-depth +If enabled, libarchive will use directory relocation records to ensure that +no pathname exceeds the ISO9660 limit of 8 directory levels. +If disabled, no relocation will occur. +Default: enabled. +.It Cm limit-dirs +If enabled, libarchive will cause an error if there are more than +65536 directories. +If disabled, there is no limit on the number of directories. +Default: enabled +.It Cm pad +If enabled, 300 kiB of zero bytes will be appended to the end of the archive. +Default: enabled +.It Cm relaxed-filenames +If enabled, all 7-bit ASCII characters are permitted in filenames +(except lowercase characters unless +.Cm allow-lowercase +is also specified). +This violates ISO9660 standards. +This does not impact names stored in the Rockridge or Joliet extension area. +Default: disabled. +.It Cm rockridge +The Rockridge extensions store an additional set of POSIX-style file +information with each file, including mtime, atime, ctime, permissions, +and long filenames with arbitrary 8-bit characters. +These extensions also support symbolic links and other POSIX file types. +Default: enabled. +.El +.It Format iso9660 - zisofs support +The zisofs extensions permit each file to be independently compressed +using a gzip-compatible compression. +This can provide significant size savings, but requires the reading +system to have support for these extensions. +These extensions are disabled by default. +.Bl -tag -compact -width indent +.It Cm compression-level Ns = Ns number +The compression level used by the deflate compressor. +Ranges from 0 (least effort) to 9 (most effort). +Default: 6 +.It Cm zisofs +Synonym for +.Cm zisofs=direct . +.It Cm zisofs=direct +Compress each file in the archive. +Unlike +.Cm zisofs=indirect , +this is handled entirely within libarchive and does not require a +separate utility. +For best results, libarchive tests each file and will store +the file uncompressed if the compression does not actually save any space. +In particular, files under 2k will never be compressed. +Note that boot image files are never compressed. +.It Cm zisofs=indirect +Recognizes files that have already been compressed with the +.Cm mkzftree +utility and sets up the necessary file metadata so that +readers will correctly identify these as zisofs-compressed files. +.It Cm zisofs-exclude Ns = Ns Ar filename +Specifies a filename that should not be compressed when using +.Cm zisofs=direct . +This option can be provided multiple times to suppress compression +on many files. +.El +.El +.Sh EXAMPLES +The following example creates an archive write handle to +create a gzip-compressed ISO9660 format image. +The two options here specify that the ISO9660 archive will use +.Ar kernel.img +as the boot image for El Torito booting, and that the gzip +compressor should use the maximum compression level. +.Bd -literal -offset indent +a = archive_write_new(); +archive_write_add_filter_gzip(a); +archive_write_set_format_iso9660(a); +archive_write_set_options(a, "boot=kernel.img,compression=9"); +archive_write_open_filename(a, filename, blocksize); +.Ed +.\" +.Sh ERRORS +Detailed error codes and textual descriptions are available from the +.Fn archive_errno +and +.Fn archive_error_string +functions. +.\" +.Sh SEE ALSO +.Xr tar 1 , +.Xr libarchive 3 , +.Xr archive_read_set_options 3 , +.Xr archive_write 3 +.Sh HISTORY +The +.Nm libarchive +library first appeared in +.Fx 5.3 . +.Sh AUTHORS +.An -nosplit +The options support for libarchive was originally implemented by +.An Michihiro NAKAJIMA . +.Sh BUGS diff --git a/Utilities/cmlibarchive/libarchive/archive_write_set_options.c b/Utilities/cmlibarchive/libarchive/archive_write_set_options.c new file mode 100644 index 000000000..a8c2d23dd --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/archive_write_set_options.c @@ -0,0 +1,124 @@ +/*- + * Copyright (c) 2003-2010 Tim Kientzle + * 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_write_private.h" +#include "archive_options_private.h" + +static int archive_set_format_option(struct archive *a, + const char *m, const char *o, const char *v); +static int archive_set_filter_option(struct archive *a, + const char *m, const char *o, const char *v); +static int archive_set_option(struct archive *a, + const char *m, const char *o, const char *v); + +int +archive_write_set_format_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_WRITE_MAGIC, "archive_write_set_format_option", + archive_set_format_option); +} + +int +archive_write_set_filter_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_WRITE_MAGIC, "archive_write_set_filter_option", + archive_set_filter_option); +} + +int +archive_write_set_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_option(a, m, o, v, + ARCHIVE_WRITE_MAGIC, "archive_write_set_option", + archive_set_option); +} + +int +archive_write_set_options(struct archive *a, const char *options) +{ + return _archive_set_options(a, options, + ARCHIVE_WRITE_MAGIC, "archive_write_set_options", + archive_set_option); +} + +static int +archive_set_format_option(struct archive *_a, const char *m, const char *o, + const char *v) +{ + struct archive_write *a = (struct archive_write *)_a; + + if (a->format_name == NULL) + return (ARCHIVE_FAILED); + if (m != NULL && strcmp(m, a->format_name) != 0) + return (ARCHIVE_FAILED); + if (a->format_options == NULL) + return (ARCHIVE_FAILED); + return a->format_options(a, o, v); +} + +static int +archive_set_filter_option(struct archive *_a, const char *m, const char *o, + const char *v) +{ + struct archive_write *a = (struct archive_write *)_a; + struct archive_write_filter *filter; + int r, rv = ARCHIVE_FAILED; + + for (filter = a->filter_first; filter != NULL; filter = filter->next_filter) { + if (filter->options == NULL) + continue; + if (m != NULL && strcmp(filter->name, m) != 0) + continue; + + r = filter->options(filter, o, v); + + if (r == ARCHIVE_FATAL) + return (ARCHIVE_FATAL); + + if (m != NULL) + return (r); + + if (r == ARCHIVE_OK) + rv = ARCHIVE_OK; + } + return (rv); +} + +static int +archive_set_option(struct archive *a, const char *m, const char *o, + const char *v) +{ + return _archive_set_either_option(a, m, o, v, + archive_set_format_option, + archive_set_filter_option); +} diff --git a/Utilities/cmlibarchive/libarchive/config_freebsd.h b/Utilities/cmlibarchive/libarchive/config_freebsd.h index 4f4646b61..207343163 100644 --- a/Utilities/cmlibarchive/libarchive/config_freebsd.h +++ b/Utilities/cmlibarchive/libarchive/config_freebsd.h @@ -22,128 +22,139 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/config_freebsd.h,v 1.15 2008/09/30 03:53:03 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/config_freebsd.h 201079 2009-12-28 02:01:42Z kientzle $ */ /* FreeBSD 5.0 and later have ACL and extattr support. */ #if __FreeBSD__ > 4 -#define HAVE_ACL_CREATE_ENTRY 1 -#define HAVE_ACL_GET_LINK_NP 1 -#define HAVE_ACL_GET_PERM_NP 1 -#define HAVE_ACL_INIT 1 -#define HAVE_ACL_SET_FD 1 -#define HAVE_ACL_SET_FD_NP 1 -#define HAVE_ACL_SET_FILE 1 -#define HAVE_ACL_USER 1 -#define HAVE_EXTATTR_GET_FILE 1 -#define HAVE_EXTATTR_LIST_FILE 1 -#define HAVE_EXTATTR_SET_FD 1 -#define HAVE_EXTATTR_SET_FILE 1 -#define HAVE_SYS_ACL_H 1 -#define HAVE_SYS_EXTATTR_H 1 +#define HAVE_ACL_CREATE_ENTRY 1 +#define HAVE_ACL_GET_LINK_NP 1 +#define HAVE_ACL_GET_PERM_NP 1 +#define HAVE_ACL_INIT 1 +#define HAVE_ACL_SET_FD 1 +#define HAVE_ACL_SET_FD_NP 1 +#define HAVE_ACL_SET_FILE 1 +#define HAVE_ACL_USER 1 +#define HAVE_EXTATTR_GET_FILE 1 +#define HAVE_EXTATTR_LIST_FILE 1 +#define HAVE_EXTATTR_SET_FD 1 +#define HAVE_EXTATTR_SET_FILE 1 +#define HAVE_SYS_ACL_H 1 +#define HAVE_SYS_EXTATTR_H 1 #endif -#define HAVE_BZLIB_H 1 -#define HAVE_CHFLAGS 1 -#define HAVE_CHOWN 1 -#define HAVE_DECL_INT64_MAX 1 -#define HAVE_DECL_INT64_MIN 1 -#define HAVE_DECL_SIZE_MAX 1 -#define HAVE_DECL_SSIZE_MAX 1 -#define HAVE_DECL_STRERROR_R 1 -#define HAVE_DECL_UINT32_MAX 1 -#define HAVE_DECL_UINT64_MAX 1 -#define HAVE_DIRENT_H 1 -#define HAVE_EFTYPE 1 -#define HAVE_EILSEQ 1 -#define HAVE_ERRNO_H 1 -#define HAVE_FCHDIR 1 -#define HAVE_FCHFLAGS 1 -#define HAVE_FCHMOD 1 -#define HAVE_FCHOWN 1 -#define HAVE_FCNTL 1 -#define HAVE_FCNTL_H 1 -#define HAVE_FSEEKO 1 -#define HAVE_FSTAT 1 -#define HAVE_FTRUNCATE 1 -#define HAVE_FUTIMES 1 -#define HAVE_GETEUID 1 -#define HAVE_GETPID 1 -#define HAVE_GRP_H 1 -#define HAVE_INTTYPES_H 1 -#define HAVE_LCHFLAGS 1 -#define HAVE_LCHMOD 1 -#define HAVE_LCHOWN 1 -#define HAVE_LIMITS_H 1 -#define HAVE_LINK 1 -#define HAVE_LSTAT 1 -#define HAVE_LUTIMES 1 -#define HAVE_MALLOC 1 -#define HAVE_MD5 1 -#define HAVE_MD5_H 1 -#define HAVE_MEMMOVE 1 -#define HAVE_MKDIR 1 -#define HAVE_MKFIFO 1 -#define HAVE_MKNOD 1 -#define HAVE_OPENSSL_MD5_H 1 -#define HAVE_OPENSSL_RIPEMD_H 1 -#define HAVE_OPENSSL_SHA_H 1 -#define HAVE_PIPE 1 -#define HAVE_POLL 1 -#define HAVE_POLL_H 1 -#define HAVE_PWD_H 1 -#define HAVE_READLINK 1 -#define HAVE_RMD160 1 -#define HAVE_SELECT 1 -#define HAVE_SETENV 1 -#define HAVE_SHA_H 1 -#define HAVE_SHA1 1 -#define HAVE_SHA256 1 -#define HAVE_SHA256_H 1 -#define HAVE_SHA384 1 -#define HAVE_SHA512 1 -#define HAVE_SIGNAL_H 1 -#define HAVE_STDINT_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRCHR 1 -#define HAVE_STRDUP 1 -#define HAVE_STRERROR 1 -#define HAVE_STRERROR_R 1 -#define HAVE_STRINGS_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRRCHR 1 -#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 -#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 -#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 -#define HAVE_STRUCT_STAT_ST_FLAGS 1 -#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 -#define HAVE_SYMLINK 1 -#define HAVE_SYS_IOCTL_H 1 -#define HAVE_SYS_SELECT_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TIME_H 1 -#define HAVE_SYS_TYPES_H 1 -#undef HAVE_SYS_UTIME_H -#define HAVE_SYS_WAIT_H 1 -#define HAVE_TIMEGM 1 -#define HAVE_TZSET 1 -#define HAVE_UNISTD_H 1 -#define HAVE_UNSETENV 1 -#define HAVE_UTIME 1 -#define HAVE_UTIMES 1 -#define HAVE_UTIME_H 1 -#define HAVE_VFORK 1 -#define HAVE_WCHAR_H 1 -#define HAVE_WCSCPY 1 -#define HAVE_WCSLEN 1 -#define HAVE_WCTOMB 1 -#define HAVE_WMEMCMP 1 -#define HAVE_WMEMCPY 1 -#define HAVE_ZLIB_H 1 -#define TIME_WITH_SYS_TIME 1 +#ifdef WITH_OPENSSL +#define HAVE_OPENSSL_MD5_H 1 +#define HAVE_OPENSSL_RIPEMD_H 1 +#define HAVE_OPENSSL_SHA_H 1 +#define HAVE_SHA384 1 +#define HAVE_SHA512 1 +#endif + +#define HAVE_BSDXML_H 1 +#define HAVE_BZLIB_H 1 +#define HAVE_CHFLAGS 1 +#define HAVE_CHOWN 1 +#define HAVE_DECL_INT64_MAX 1 +#define HAVE_DECL_INT64_MIN 1 +#define HAVE_DECL_SIZE_MAX 1 +#define HAVE_DECL_SSIZE_MAX 1 +#define HAVE_DECL_STRERROR_R 1 +#define HAVE_DECL_UINT32_MAX 1 +#define HAVE_DECL_UINT64_MAX 1 +#define HAVE_DIRENT_H 1 +#define HAVE_EFTYPE 1 +#define HAVE_EILSEQ 1 +#define HAVE_ERRNO_H 1 +#define HAVE_FCHDIR 1 +#define HAVE_FCHFLAGS 1 +#define HAVE_FCHMOD 1 +#define HAVE_FCHOWN 1 +#define HAVE_FCNTL 1 +#define HAVE_FCNTL_H 1 +#define HAVE_FSEEKO 1 +#define HAVE_FSTAT 1 +#define HAVE_FTRUNCATE 1 +#define HAVE_FUTIMES 1 +#define HAVE_GETEUID 1 +#define HAVE_GETGRGID_R 1 +#define HAVE_GETPID 1 +#define HAVE_GETPWUID_R 1 +#define HAVE_GRP_H 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_LCHFLAGS 1 +#define HAVE_LCHMOD 1 +#define HAVE_LCHOWN 1 +#define HAVE_LIMITS_H 1 +#define HAVE_LINK 1 +#define HAVE_LSTAT 1 +#define HAVE_LUTIMES 1 +#define HAVE_MALLOC 1 +#define HAVE_MD5 1 +#define HAVE_MD5_H 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MKDIR 1 +#define HAVE_MKFIFO 1 +#define HAVE_MKNOD 1 +#define HAVE_PIPE 1 +#define HAVE_POLL 1 +#define HAVE_POLL_H 1 +#define HAVE_PWD_H 1 +#define HAVE_READLINK 1 +#define HAVE_RMD160 1 +#define HAVE_SELECT 1 +#define HAVE_SETENV 1 +#define HAVE_SHA_H 1 +#define HAVE_SHA1 1 +#define HAVE_SHA256 1 +#define HAVE_SHA256_H 1 +#define HAVE_SIGNAL_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRCHR 1 +#define HAVE_STRDUP 1 +#define HAVE_STRERROR 1 +#define HAVE_STRERROR_R 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRRCHR 1 +#define HAVE_STRUCT_STAT_ST_BLKSIZE 1 +#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 +#define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 +#define HAVE_STRUCT_STAT_ST_FLAGS 1 +#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 +#define HAVE_STRUCT_TM_TM_GMTOFF 1 +#define HAVE_SYMLINK 1 +#define HAVE_SYS_CDEFS_H 1 +#define HAVE_SYS_IOCTL_H 1 +#define HAVE_SYS_MOUNT_H 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TIME_H 1 +#define HAVE_SYS_TYPES_H 1 +#undef HAVE_SYS_UTIME_H +#define HAVE_SYS_UTSNAME_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_TIMEGM 1 +#define HAVE_TZSET 1 +#define HAVE_UNISTD_H 1 +#define HAVE_UNSETENV 1 +#define HAVE_UTIME 1 +#define HAVE_UTIMES 1 +#define HAVE_UTIME_H 1 +#define HAVE_VFORK 1 +#define HAVE_WCHAR_H 1 +#define HAVE_WCSCPY 1 +#define HAVE_WCSLEN 1 +#define HAVE_WCTOMB 1 +#define HAVE_WMEMCMP 1 +#define HAVE_WMEMCPY 1 +#define HAVE_ZLIB_H 1 +#define TIME_WITH_SYS_TIME 1 /* FreeBSD 4 and earlier lack intmax_t/uintmax_t */ #if __FreeBSD__ < 5 -#define intmax_t int64_t -#define uintmax_t uint64_t +#define intmax_t int64_t +#define uintmax_t uint64_t #endif diff --git a/Utilities/cmlibarchive/libarchive/config_windows.h b/Utilities/cmlibarchive/libarchive/config_windows.h deleted file mode 100644 index cbbaccfbc..000000000 --- a/Utilities/cmlibarchive/libarchive/config_windows.h +++ /dev/null @@ -1,576 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -#ifndef __LIBARCHIVE_BUILD -#error This header is only to be used internally to libarchive. -#endif - -#ifndef CONFIG_H_INCLUDED -#define CONFIG_H_INCLUDED -/* -/////////////////////////////////////////////////////////////////////////// -// Check for Watcom and Microsoft Visual C compilers (WIN32 only) /////// -/////////////////////////////////////////////////////////////////////////// -*/ -#if (defined(__WIN32__) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__) - #define IS_WIN32 1 - - #if defined(__TURBOC__) || defined(__BORLANDC__) /* Borland compilers */ - #elif defined( __WATCOMC__ ) || defined(__WATCOMCPP__) /* Watcom compilers */ - #define IS_WATCOM 1 - /* Define to 1 if __INT64 is defined */ - #elif defined(__IBMC__) || defined(__IBMCPP__) /* IBM compilers */ - #elif defined( __SC__ ) /* Symantec C++ compilers */ - #elif defined( M_I86 ) && defined( MSDOS ) /* Microsoft DOS/Win 16 compilers */ - #elif defined( _M_IX86 ) || defined( _68K_ ) /* Microsoft Win32 compilers */ - #define IS_VISUALC 1 - /* Define to 1 if __INT64 is defined */ - #else - #endif - - /* Define to 1 if UID should be unsigned */ - #define USE_UNSIGNED_UID 1 - - /* Define to 1 if UID should be unsigned */ - #define USE_UNSIGNED_GID 1 -#endif -/*/////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////*/ - -/* Define to 1 if you have the `acl_create_entry' function. */ -/* #undef HAVE_ACL_CREATE_ENTRY */ - -/* Define to 1 if you have the `acl_get_perm' function. */ -/* #undef HAVE_ACL_GET_PERM */ - -/* Define to 1 if you have the `acl_get_perm_np' function. */ -/* #undef HAVE_ACL_GET_PERM_NP */ - -/* Define to 1 if you have the `acl_init' function. */ -/* #undef HAVE_ACL_INIT */ - -/* Define to 1 if the system has the type `acl_permset_t'. */ -/* #undef HAVE_ACL_PERMSET_T */ - -/* Define to 1 if you have the `acl_set_fd' function. */ -/* #undef HAVE_ACL_SET_FD */ - -/* Define to 1 if you have the `acl_set_fd_np' function. */ -/* #undef HAVE_ACL_SET_FD_NP */ - -/* Define to 1 if you have the `acl_set_file' function. */ -/* #undef HAVE_ACL_SET_FILE */ - -/* True for systems with POSIX ACL support */ -/* #undef HAVE_ACL_USER */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ATTR_XATTR_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_BZLIB_H */ - -/* Define to 1 if you have the `chflags' function. */ -/* #undef HAVE_CHFLAGS */ - -/* Define to 1 if you have the `chown' function. */ -/* #undef HAVE_CHOWN */ - -/* Define to 1 if you have the declaration of `INT64_MAX', and to 0 if you - don't. */ -#if defined(_MSC_VER) -/* #undef HAVE_DECL_INT64_MAX */ -#else -#define HAVE_DECL_INT64_MAX 1 -#endif - -/* Define to 1 if you have the declaration of `INT64_MIN', and to 0 if you - don't. */ -#if defined(_MSC_VER) -/* #undef HAVE_DECL_INT64_MIN */ -#else -#define HAVE_DECL_INT64_MIN 1 -#endif - -/* Define to 1 if you have the declaration of `optarg', and to 0 if you don't. - */ -/* #undef HAVE_DECL_OPTARG */ - -/* Define to 1 if you have the declaration of `optind', and to 0 if you don't. - */ -/* #undef HAVE_DECL_OPTIND */ - -/* Define to 1 if you have the declaration of `SIZE_MAX', and to 0 if you - don't. */ -#if defined(_MSC_VER) - #if _MSC_VER >= 1400 - #define HAVE_DECL_SIZE_MAX 1 - #else - /* #undef HAVE_DECL_SIZE_MAX */ - #endif -#else -#define HAVE_DECL_SIZE_MAX 1 -#endif - -/* Define to 1 if you have the declaration of `SSIZE_MAX', and to 0 if you - don't. */ -/* #undef HAVE_DECL_SSIZE_MAX */ - -/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you - don't. */ -/* #undef HAVE_DECL_STRERROR_R */ - -/* Define to 1 if you have the declaration of `UINT32_MAX', and to 0 if you - don't. */ -#if defined(_MSC_VER) -/* #undef HAVE_DECL_UINT32_MAX */ -#else -#define HAVE_DECL_UINT32_MAX 1 -#endif - -/* Define to 1 if you have the declaration of `UINT64_MAX', and to 0 if you - don't. */ -#if defined(_MSC_VER) -/* #undef HAVE_DECL_UINT64_MAX */ -#else -#define HAVE_DECL_UINT64_MAX 1 -#endif - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -/* #undef HAVE_DIRENT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_DLFCN_H */ - -/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ -/* #undef HAVE_DOPRNT */ - -/* Define to 1 if nl_langinfo supports D_MD_ORDER */ -/* #undef HAVE_D_MD_ORDER */ - -/* A possible errno value for invalid file format errors */ -/* #undef HAVE_EFTYPE */ - -/* A possible errno value for invalid file format errors */ -#define HAVE_EILSEQ 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ERRNO_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_EXT2FS_EXT2_FS_H */ - -/* Define to 1 if you have the `fchdir' function. */ -/* #undef HAVE_FCHDIR */ - -/* Define to 1 if you have the `fchflags' function. */ -/* #undef HAVE_FCHFLAGS */ - -/* Define to 1 if you have the `fchmod' function. */ -/* #undef HAVE_FCHMOD */ - -/* Define to 1 if you have the `fchown' function. */ -/* #undef HAVE_FCHOWN */ - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if you have the fcntl() function. */ -/* #undef HAVE_FCNTL_FN */ - -/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ -/* #undef HAVE_FSEEKO */ - -/* Define to 1 if you have the `fsetxattr' function. */ -/* #undef HAVE_FSETXATTR */ - -/* Define to 1 if you have the `ftruncate' function. */ -#define HAVE_FTRUNCATE 1 - -/* Define to 1 if you have the `futimes' function. */ -#define HAVE_FUTIMES 1 - -/* Define to 1 if you have the `geteuid' function. */ -/* #undef HAVE_GETEUID */ - -/* Define to 1 if you have the `getxattr' function. */ -/* #undef HAVE_GETXATTR */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_GRP_H */ - -/* Define to 1 if the system has the type `intmax_t'. */ -/* #undef HAVE_INTMAX_T */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_INTTYPES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LANGINFO_H */ - -/* Define to 1 if you have the `lchflags' function. */ -/* #undef HAVE_LCHFLAGS */ - -/* Define to 1 if you have the `lchmod' function. */ -/* #undef HAVE_LCHMOD */ - -/* Define to 1 if you have the `lchown' function. */ -/* #undef HAVE_LCHOWN */ - -/* Define to 1 if you have the `lgetxattr' function. */ -/* #undef HAVE_LGETXATTR */ - -/* Define to 1 if you have the `acl' library (-lacl). */ -/* #undef HAVE_LIBACL */ - -/* Define to 1 if you have the `attr' library (-lattr). */ -/* #undef HAVE_LIBATTR */ - -/* Define to 1 if you have the `bz2' library (-lbz2). */ -/* #undef HAVE_LIBBZ2 */ - -/* Define to 1 if you have the `z' library (-lz). */ -/* #undef HAVE_LIBZ */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_EXT2_FS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_FS_H */ - -/* Define to 1 if you have the `listxattr' function. */ -/* #undef HAVE_LISTXATTR */ - -/* Define to 1 if you have the `llistxattr' function. */ -/* #undef HAVE_LLISTXATTR */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LOCALE_H 1 - -/* Define to 1 if the system has the type `long long int'. */ -#define HAVE_LONG_LONG_INT 1 - -/* Define to 1 if you have the `lsetxattr' function. */ -/* #undef HAVE_LSETXATTR */ - -/* Define to 1 if `lstat' has the bug that it succeeds when given the - zero-length file name argument. */ -/* #undef HAVE_LSTAT_EMPTY_STRING_BUG */ - -/* Define to 1 if you have the `lutimes' function. */ -/* #undef HAVE_LUTIMES */ - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `mkdir' function. */ -#define HAVE_MKDIR 1 - -/* Define to 1 if you have the `mkfifo' function. */ -/* #undef HAVE_MKFIFO */ - -/* Define to 1 if you have the `mknod' function. */ -/* #undef HAVE_MKNOD */ - -/* Define to 1 if you have the header file, and it defines `DIR'. */ -/* #undef HAVE_NDIR_H */ - -/* Define to 1 if you have the `nl_langinfo' function. */ -/* #undef HAVE_NL_LANGINFO */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PATHS_H */ - -/* Define to 1 if you have the `poll' function. */ -/* #undef HAVE_POLL */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_POLL_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_PWD_H */ - -/* Define to 1 if you have the `select' function. */ -/* #undef HAVE_SELECT */ - -/* Define to 1 if you have the `setlocale' function. */ -#define HAVE_SETLOCALE 1 - -/* Define to 1 if `stat' has the bug that it succeeds when given the - zero-length file name argument. */ -/* #undef HAVE_STAT_EMPTY_STRING_BUG */ - -/* Define to 1 if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define to 1 if you have the header file. */ -#if defined(_MSC_VER) -/* #undef HAVE_STDINT_H */ -#else -#define HAVE_STDINT_H 1 -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strchr' function. */ -#define HAVE_STRCHR 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the `strerror_r' function. */ -/* #undef HAVE_STRERROR_R */ - -/* Define to 1 if you have the `strftime' function. */ -#define HAVE_STRFTIME 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strrchr' function. */ -#define HAVE_STRRCHR 1 - -/* Define to 1 if `st_mtimespec.tv_nsec' is member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC */ - -/* Define to 1 if `st_mtim.tv_nsec' is member of `struct stat'. */ -/* #undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_ACL_H */ - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -/* #undef HAVE_SYS_DIR_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_IOCTL_H */ - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -/* #undef HAVE_SYS_NDIR_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_PARAM_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_POLL_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_SELECT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#if defined(_MSC_VER) -/* #undef HAVE_SYS_TIME_H */ -#else -#define HAVE_SYS_TIME_H 1 -#endif - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_UTIME_H 1 - -/* Define to 1 if you have that is POSIX.1 compatible. */ -/* #undef HAVE_SYS_WAIT_H */ - -/* Define to 1 if you have the `timegm' function. */ -/* #undef HAVE_TIMEGM */ - -/* Define to 1 if you have the header file. */ -#define HAVE_TIME_H 1 - -/* Define to 1 if the system has the type `uintmax_t'. */ -#if defined(_MSC_VER) -/* #undef HAVE_UINTMAX_T */ -#else -#define HAVE_UINTMAX_T 1 -#endif - -/* Define to 1 if you have the header file. */ -#if defined(_MSC_VER) -/* #undef HAVE_UNISTD_H */ -#else -#define HAVE_UNISTD_H 1 -#endif - -/* Define to 1 if the system has the type `unsigned long long'. */ -#define HAVE_UNSIGNED_LONG_LONG 1 - -/* Define to 1 if the system has the type `unsigned long long int'. */ -#define HAVE_UNSIGNED_LONG_LONG_INT 1 - -/* Define to 1 if you have the `utime' function. */ -#define HAVE_UTIME 1 - -/* Define to 1 if you have the `utimes' function. */ -#define HAVE_UTIMES 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_UTIME_H */ - -/* Define to 1 if you have the `vprintf' function. */ -#define HAVE_VPRINTF 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_WCHAR_H 1 - -/* Define to 1 if you have the `wcscpy' function. */ -#define HAVE_WCSCPY 1 - -/* Define to 1 if you have the `wcslen' function. */ -#define HAVE_WCSLEN 1 - -/* Define to 1 if you have the `wctomb' function. */ -#define HAVE_WCTOMB 1 - -/* Define to 1 if you have the `wmemcmp' function. */ -/* #undef HAVE_WMEMCMP */ - -/* Define to 1 if you have the `wmemcpy' function. */ -/* #undef HAVE_WMEMCPY */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_ZLIB_H */ - -/* Define to 1 if `lstat' dereferences a symlink specified with a trailing - slash. */ -/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */ - -/* Define to 1 if `major', `minor', and `makedev' are declared in . - */ -/* #undef MAJOR_IN_MKDEV */ - -/* Define to 1 if `major', `minor', and `makedev' are declared in - . */ -/* #undef MAJOR_IN_SYSMACROS */ - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -/* #undef NO_MINUS_C_MINUS_O */ - -/* Define to 1 if strerror_r returns char *. */ -/* #undef STRERROR_R_CHAR_P */ - -/* Define to 1 if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* Number of bits in a file offset, on hosts where this is settable. */ -/* #undef _FILE_OFFSET_BITS */ - -/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ -/* #undef _LARGEFILE_SOURCE */ - -/* Define for large files, on AIX-style hosts. */ -/* #undef _LARGE_FILES */ - -/* Define for Solaris 2.5.1 so the uint64_t typedef from , - , or is not used. If the typedef was allowed, the - #define below would cause a syntax error. */ -/* #undef _UINT64_T */ - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define to `int' if doesn't define. */ -#if (USE_UNSIGNED_GID) -#define gid_t unsigned int -#else -#define gid_t int -#endif - -/* Define to `unsigned long' if does not define. */ -#define id_t int - -/* Define to the type of a signed integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -#if defined(_MSC_VER) -#define int64_t __int64 -#else -/* #undef int64_t */ -#endif - -/* Define to the widest signed integer type if and do - not define. */ -#if defined(_MSC_VER) -#define intmax_t long long -#else -/* #undef intmax_t */ -#endif - -/* Define to `int' if does not define. */ -#if defined(_MSC_VER) -#define mode_t unsigned short -#else -/* #undef mode_t */ -#endif - -/* Define to `long long' if does not define. */ -/* #undef off_t */ - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if doesn't define. */ -#if (USE_UNSIGNED_UID) -#define uid_t unsigned int -#else -#define uid_t int -#endif - -/* Define to the type of an unsigned integer type of width exactly 64 bits if - such a type exists and the standard includes do not define it. */ -#if defined(_MSC_VER) -#define uint64_t unsigned __int64 -#else -/* #undef uint64_t */ -#endif - -/* Define to the widest unsigned integer type if and - do not define. */ -#if defined(_MSC_VER) -#define uintmax_t unsigned long long -#else -/* #undef uintmax_t */ -#endif - -/* Define to `unsigned int' if does not define. */ -/* #undef uintptr_t */ - -/* Define to `unsigned int' if does not define. */ -#if defined(_MSC_VER) -#define pid_t unsigned int -#else -/* #undef pid_t */ -#endif - -#if defined(_MSC_VER) -#define uint32_t unsigned long -#define uint16_t unsigned short - #ifdef _WIN64 - #define ssize_t __int64 - #else - #define ssize_t long - #endif -#endif - -#include "archive_windows.h" - -#endif /* CONFIG_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/libarchive/cpio.5 b/Utilities/cmlibarchive/libarchive/cpio.5 index 12ab7d451..13a4445b7 100644 --- a/Utilities/cmlibarchive/libarchive/cpio.5 +++ b/Utilities/cmlibarchive/libarchive/cpio.5 @@ -72,9 +72,9 @@ struct header_old_cpio { unsigned short c_gid; unsigned short c_nlink; unsigned short c_rdev; - unsigned short c_mtime[2]; + unsigned short c_mtime[2]; unsigned short c_namesize; - unsigned short c_filesize[2]; + unsigned short c_filesize[2]; }; .Ed .Pp @@ -268,31 +268,6 @@ data, including ACLs and extended attributes, as special entries in cpio archives. .Pp XXX Others? XXX -.Sh BUGS -The -.Dq CRC -format is mis-named, as it uses a simple checksum and -not a cyclic redundancy check. -.Pp -The old binary format is limited to 16 bits for user id, -group id, device, and inode numbers. -It is limited to 4 gigabyte file sizes. -.Pp -The old ASCII format is limited to 18 bits for -the user id, group id, device, and inode numbers. -It is limited to 8 gigabyte file sizes. -.Pp -The new ASCII format is limited to 4 gigabyte file sizes. -.Pp -None of the cpio formats store user or group names, -which are essential when moving files between systems with -dissimilar user or group numbering. -.Pp -Especially when writing older cpio variants, it may be necessary -to map actual device/inode values to synthesized values that -fit the available fields. -With very large filesystems, this may be necessary even for -the newer formats. .Sh SEE ALSO .Xr cpio 1 , .Xr tar 5 @@ -323,3 +298,28 @@ license. The character format was adopted as part of .St -p1003.1-88 . XXX when did "newc" appear? Who invented it? When did HP come out with their variant? When did Sun introduce ACLs and extended attributes? XXX +.Sh BUGS +The +.Dq CRC +format is mis-named, as it uses a simple checksum and +not a cyclic redundancy check. +.Pp +The old binary format is limited to 16 bits for user id, +group id, device, and inode numbers. +It is limited to 4 gigabyte file sizes. +.Pp +The old ASCII format is limited to 18 bits for +the user id, group id, device, and inode numbers. +It is limited to 8 gigabyte file sizes. +.Pp +The new ASCII format is limited to 4 gigabyte file sizes. +.Pp +None of the cpio formats store user or group names, +which are essential when moving files between systems with +dissimilar user or group numbering. +.Pp +Especially when writing older cpio variants, it may be necessary +to map actual device/inode values to synthesized values that +fit the available fields. +With very large filesystems, this may be necessary even for +the newer formats. diff --git a/Utilities/cmlibarchive/libarchive/filter_fork.c b/Utilities/cmlibarchive/libarchive/filter_fork.c index 4127878b6..d160524b0 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork.c +++ b/Utilities/cmlibarchive/libarchive/filter_fork.c @@ -29,9 +29,9 @@ #if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \ (defined(HAVE_FORK) || defined(HAVE_VFORK)) -__FBSDID("$FreeBSD: src/lib/libarchive/filter_fork.c,v 1.5 2008/09/12 05:33:00 kientzle Exp $"); +__FBSDID("$FreeBSD: head/lib/libarchive/filter_fork.c 182958 2008-09-12 05:33:00Z kientzle $"); -#if defined(HAVE_POLL) +#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) # if defined(HAVE_POLL_H) # include # elif defined(HAVE_SYS_POLL_H) @@ -56,105 +56,105 @@ __FBSDID("$FreeBSD: src/lib/libarchive/filter_fork.c,v 1.5 2008/09/12 05:33:00 k pid_t __archive_create_child(const char *path, int *child_stdin, int *child_stdout) { - pid_t child; - int stdin_pipe[2], stdout_pipe[2], tmp; - - if (pipe(stdin_pipe) == -1) - goto state_allocated; - if (stdin_pipe[0] == 1 /* stdout */) { - if ((tmp = dup(stdin_pipe[0])) == -1) - goto stdin_opened; - close(stdin_pipe[0]); - stdin_pipe[0] = tmp; - } - if (pipe(stdout_pipe) == -1) - goto stdin_opened; - if (stdout_pipe[1] == 0 /* stdin */) { - if ((tmp = dup(stdout_pipe[1])) == -1) - goto stdout_opened; - close(stdout_pipe[1]); - stdout_pipe[1] = tmp; - } + pid_t child; + int stdin_pipe[2], stdout_pipe[2], tmp; + + if (pipe(stdin_pipe) == -1) + goto state_allocated; + if (stdin_pipe[0] == 1 /* stdout */) { + if ((tmp = dup(stdin_pipe[0])) == -1) + goto stdin_opened; + close(stdin_pipe[0]); + stdin_pipe[0] = tmp; + } + if (pipe(stdout_pipe) == -1) + goto stdin_opened; + if (stdout_pipe[1] == 0 /* stdin */) { + if ((tmp = dup(stdout_pipe[1])) == -1) + goto stdout_opened; + close(stdout_pipe[1]); + stdout_pipe[1] = tmp; + } #if HAVE_VFORK - switch ((child = vfork())) { + switch ((child = vfork())) { #else - switch ((child = fork())) { + switch ((child = fork())) { #endif - case -1: - goto stdout_opened; - case 0: - close(stdin_pipe[1]); - close(stdout_pipe[0]); - if (dup2(stdin_pipe[0], 0 /* stdin */) == -1) - _exit(254); - if (stdin_pipe[0] != 0 /* stdin */) - close(stdin_pipe[0]); - if (dup2(stdout_pipe[1], 1 /* stdout */) == -1) - _exit(254); - if (stdout_pipe[1] != 1 /* stdout */) - close(stdout_pipe[1]); - execlp(path, path, (char *)NULL); - _exit(254); - default: - close(stdin_pipe[0]); - close(stdout_pipe[1]); - - *child_stdin = stdin_pipe[1]; - fcntl(*child_stdin, F_SETFL, O_NONBLOCK); - *child_stdout = stdout_pipe[0]; - fcntl(*child_stdout, F_SETFL, O_NONBLOCK); - } - - return child; + case -1: + goto stdout_opened; + case 0: + close(stdin_pipe[1]); + close(stdout_pipe[0]); + if (dup2(stdin_pipe[0], 0 /* stdin */) == -1) + _exit(254); + if (stdin_pipe[0] != 0 /* stdin */) + close(stdin_pipe[0]); + if (dup2(stdout_pipe[1], 1 /* stdout */) == -1) + _exit(254); + if (stdout_pipe[1] != 1 /* stdout */) + close(stdout_pipe[1]); + execlp(path, path, (char *)NULL); + _exit(254); + default: + close(stdin_pipe[0]); + close(stdout_pipe[1]); + + *child_stdin = stdin_pipe[1]; + fcntl(*child_stdin, F_SETFL, O_NONBLOCK); + *child_stdout = stdout_pipe[0]; + fcntl(*child_stdout, F_SETFL, O_NONBLOCK); + } + + return child; stdout_opened: - close(stdout_pipe[0]); - close(stdout_pipe[1]); + close(stdout_pipe[0]); + close(stdout_pipe[1]); stdin_opened: - close(stdin_pipe[0]); - close(stdin_pipe[1]); + close(stdin_pipe[0]); + close(stdin_pipe[1]); state_allocated: - return -1; + return -1; } void __archive_check_child(int in, int out) { -#if defined(HAVE_POLL) - struct pollfd fds[2]; - int idx; - - idx = 0; - if (in != -1) { - fds[idx].fd = in; - fds[idx].events = POLLOUT; - ++idx; - } - if (out != -1) { - fds[idx].fd = out; - fds[idx].events = POLLIN; - ++idx; - } - - poll(fds, idx, -1); /* -1 == INFTIM, wait forever */ +#if defined(HAVE_POLL) && (defined(HAVE_POLL_H) || defined(HAVE_SYS_POLL_H)) + struct pollfd fds[2]; + int idx; + + idx = 0; + if (in != -1) { + fds[idx].fd = in; + fds[idx].events = POLLOUT; + ++idx; + } + if (out != -1) { + fds[idx].fd = out; + fds[idx].events = POLLIN; + ++idx; + } + + poll(fds, idx, -1); /* -1 == INFTIM, wait forever */ #elif defined(HAVE_SELECT) - fd_set fds_in, fds_out, fds_error; - - FD_ZERO(&fds_in); - FD_ZERO(&fds_out); - FD_ZERO(&fds_error); - if (out != -1) { - FD_SET(out, &fds_in); - FD_SET(out, &fds_error); - } - if (in != -1) { - FD_SET(in, &fds_out); - FD_SET(in, &fds_error); - } - select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL); + fd_set fds_in, fds_out, fds_error; + + FD_ZERO(&fds_in); + FD_ZERO(&fds_out); + FD_ZERO(&fds_error); + if (out != -1) { + FD_SET(out, &fds_in); + FD_SET(out, &fds_error); + } + if (in != -1) { + FD_SET(in, &fds_out); + FD_SET(in, &fds_error); + } + select(in < out ? out + 1 : in + 1, &fds_in, &fds_out, &fds_error, NULL); #else - sleep(1); + sleep(1); #endif } diff --git a/Utilities/cmlibarchive/libarchive/filter_fork.h b/Utilities/cmlibarchive/libarchive/filter_fork.h index 3eb446eeb..453d032d1 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork.h +++ b/Utilities/cmlibarchive/libarchive/filter_fork.h @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libarchive/filter_fork.h,v 1.1 2007/05/29 01:00:20 kientzle Exp $ + * $FreeBSD: head/lib/libarchive/filter_fork.h 201087 2009-12-28 02:18:26Z kientzle $ */ #ifndef __LIBARCHIVE_BUILD diff --git a/Utilities/cmlibarchive/libarchive/filter_fork_windows.c b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c index dfee28c5e..272e56c6b 100644 --- a/Utilities/cmlibarchive/libarchive/filter_fork_windows.c +++ b/Utilities/cmlibarchive/libarchive/filter_fork_windows.c @@ -24,7 +24,6 @@ */ #include "archive_platform.h" -#include "archive_private.h" #if defined(_WIN32) && !defined(__CYGWIN__) @@ -33,80 +32,86 @@ pid_t __archive_create_child(const char *path, int *child_stdin, int *child_stdout) { - HANDLE childStdout[2], childStdin[2], childStdinWr, childStdoutRd; - SECURITY_ATTRIBUTES secAtts; - STARTUPINFO staInfo; - PROCESS_INFORMATION childInfo; - char cmd[MAX_PATH]; - DWORD mode; + HANDLE childStdout[2], childStdin[2],childStderr; + SECURITY_ATTRIBUTES secAtts; + STARTUPINFO staInfo; + PROCESS_INFORMATION childInfo; + char cmd[MAX_PATH]; - secAtts.nLength = sizeof(SECURITY_ATTRIBUTES); - secAtts.bInheritHandle = TRUE; - secAtts.lpSecurityDescriptor = NULL; - if (CreatePipe(&childStdout[0], &childStdout[1], &secAtts, 0) == 0) - goto fail; - if (DuplicateHandle(GetCurrentProcess(), childStdout[0], - GetCurrentProcess(), &childStdoutRd, 0, FALSE, - DUPLICATE_SAME_ACCESS) == 0) { - CloseHandle(childStdout[0]); - CloseHandle(childStdout[1]); - goto fail; - } - CloseHandle(childStdout[0]); + secAtts.nLength = sizeof(SECURITY_ATTRIBUTES); + secAtts.bInheritHandle = TRUE; + secAtts.lpSecurityDescriptor = NULL; + if (CreatePipe(&childStdout[0], &childStdout[1], &secAtts, 0) == 0) + goto fail; + if (!SetHandleInformation(childStdout[0], HANDLE_FLAG_INHERIT, 0)) + { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + goto fail; + } + if (CreatePipe(&childStdin[0], &childStdin[1], &secAtts, 0) == 0) { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + goto fail; + } + if (!SetHandleInformation(childStdin[1], HANDLE_FLAG_INHERIT, 0)) + { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); + CloseHandle(childStdin[1]); + goto fail; + } + if (DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), + GetCurrentProcess(), &childStderr, 0, TRUE, + DUPLICATE_SAME_ACCESS) == 0) { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); + CloseHandle(childStdin[1]); + goto fail; + } - if (CreatePipe(&childStdin[0], &childStdin[1], &secAtts, 0) == 0) { - CloseHandle(childStdoutRd); - CloseHandle(childStdout[1]); - goto fail; - } + memset(&staInfo, 0, sizeof(staInfo)); + staInfo.cb = sizeof(staInfo); + staInfo.hStdError = childStderr; + staInfo.hStdOutput = childStdout[1]; + staInfo.hStdInput = childStdin[0]; + staInfo.wShowWindow = SW_HIDE; + staInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + strncpy(cmd, path, sizeof(cmd)-1); + cmd[sizeof(cmd)-1] = '\0'; + if (CreateProcessA(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, + &staInfo, &childInfo) == 0) { + CloseHandle(childStdout[0]); + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); + CloseHandle(childStdin[1]); + CloseHandle(childStderr); + goto fail; + } + WaitForInputIdle(childInfo.hProcess, INFINITE); + CloseHandle(childInfo.hProcess); + CloseHandle(childInfo.hThread); - if (DuplicateHandle(GetCurrentProcess(), childStdin[1], - GetCurrentProcess(), &childStdinWr, 0, FALSE, - DUPLICATE_SAME_ACCESS) == 0) { - CloseHandle(childStdoutRd); - CloseHandle(childStdout[1]); - CloseHandle(childStdin[0]); - CloseHandle(childStdin[1]); - goto fail; - } - CloseHandle(childStdin[1]); + *child_stdout = _open_osfhandle((intptr_t)childStdout[0], _O_RDONLY); + *child_stdin = _open_osfhandle((intptr_t)childStdin[1], _O_WRONLY); + + CloseHandle(childStdout[1]); + CloseHandle(childStdin[0]); - memset(&staInfo, 0, sizeof(staInfo)); - staInfo.cb = sizeof(staInfo); - staInfo.hStdOutput = childStdout[1]; - staInfo.hStdInput = childStdin[0]; - staInfo.wShowWindow = SW_HIDE; - staInfo.dwFlags = STARTF_USEFILLATTRIBUTE | STARTF_USECOUNTCHARS | - STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; - strncpy(cmd, path, sizeof(cmd)-1); - cmd[sizeof(cmd)-1] = '\0'; - if (CreateProcessA(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, - &staInfo, &childInfo) == 0) { - CloseHandle(childStdoutRd); - CloseHandle(childStdout[1]); - CloseHandle(childStdin[0]); - CloseHandle(childStdinWr); - goto fail; - } - WaitForInputIdle(childInfo.hProcess, INFINITE); - CloseHandle(childInfo.hProcess); - CloseHandle(childInfo.hThread); - - mode = PIPE_NOWAIT; - SetNamedPipeHandleState(childStdoutRd, &mode, NULL, NULL); - *child_stdout = _open_osfhandle((intptr_t)childStdoutRd, _O_RDONLY); - *child_stdin = _open_osfhandle((intptr_t)childStdinWr, _O_WRONLY); - - return (childInfo.dwProcessId); + return (childInfo.dwProcessId); fail: - return (-1); + return (-1); } void __archive_check_child(int in, int out) { - Sleep(100); + (void)in; /* UNSED */ + (void)out; /* UNSED */ + Sleep(100); } #endif /* _WIN32 && !__CYGWIN__ */ diff --git a/Utilities/cmlibarchive/libarchive/libarchive-formats.5 b/Utilities/cmlibarchive/libarchive/libarchive-formats.5 index 2022531d1..d223bf853 100644 --- a/Utilities/cmlibarchive/libarchive/libarchive-formats.5 +++ b/Utilities/cmlibarchive/libarchive/libarchive-formats.5 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle +.\" Copyright (c) 2003-2009 Tim Kientzle .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -22,10 +22,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/libarchive-formats.5,v 1.16 2008/05/26 17:00:23 kientzle Exp $ +.\" $FreeBSD: head/lib/libarchive/libarchive-formats.5 201077 2009-12-28 01:50:23Z kientzle $ .\" -.Dd July 17, 2009 -.Dt libarchive-formats 5 +.Dd December 27, 2009 +.Dt LIBARCHIVE-FORMATS 5 .Os .Sh NAME .Nm libarchive-formats @@ -132,21 +132,30 @@ This name is limited to 100 bytes. Extended attributes, file flags, and other extended security information cannot be stored. .It -Archive entries are limited to 2 gigabytes in size. +Archive entries are limited to 8 gigabytes in size. .El Note that the pax interchange format has none of these restrictions. .El +.Pp +The libarchive library also reads a variety of commonly-used extensions to +the basic tar format. +These extensions are recognized automatically whenever they appear. +.Bl -tag -width indent +.It Numeric extensions. +The POSIX standards require fixed-length numeric fields to be written with +some character position reserved for terminators. +Libarchive allows these fields to be written without terminator characters. +This extends the allowable range; in particular, ustar archives with this +extension can support entries up to 64 gigabytes in size. +Libarchive also recognizes base-256 values in most numeric fields. +This essentially removes all limitations on file size, modification time, +and device numbers. .It Solaris extensions Libarchive recognizes ACL and extended attribute records written by Solaris tar. Currently, libarchive only has support for old-style ACLs; the newer NFSv4 ACLs are recognized but discarded. -.Pp -The libarchive library can also read a variety of commonly-used extensions to -the basic tar format. -In particular, it supports base-256 values in certain numeric fields. -This essentially removes the limitations on file size, modification time, -and device numbers. +.El .Pp The first tar program appeared in Seventh Edition Unix in 1979. The first official standard for the tar file format was the @@ -333,6 +342,12 @@ using libarchive. If it cannot locate and open the file on disk, libarchive will return an error for any attempt to read the entry body. +.Ss RAR +libarchive has limited support to read files in RAR format. Currently, +libarchive can read single RAR files in RARv3 format which have been either +created uncompressed, or compressed using any of the compression methods +supported by the RARv3 format. libarchive can also extract RAR files which have +been created as self-extracting RAR files. .Sh SEE ALSO .Xr ar 1 , .Xr cpio 1 , diff --git a/Utilities/cmlibarchive/libarchive/libarchive.3 b/Utilities/cmlibarchive/libarchive/libarchive.3 index 8c19d008a..d655404b8 100644 --- a/Utilities/cmlibarchive/libarchive/libarchive.3 +++ b/Utilities/cmlibarchive/libarchive/libarchive.3 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD: src/lib/libarchive/libarchive.3,v 1.11 2007/01/09 08:05:56 kientzle Exp $ .\" -.Dd August 19, 2006 +.Dd February 6, 2010 .Dt LIBARCHIVE 3 .Os .Sh NAME @@ -36,10 +36,13 @@ The .Nm library provides a flexible interface for reading and writing -streaming archive files such as tar and cpio. +archives in various formats such as tar and cpio. +.Nm +also supports reading and writing archives compressed using +various compression filters such as gzip and bzip2. The library is inherently stream-oriented; readers serially iterate through the archive, writers serially add things to the archive. -In particular, note that there is no built-in support for +In particular, note that there is currently no built-in support for random access nor for in-place modification. .Pp When reading an archive, the library automatically detects the @@ -61,13 +64,14 @@ GNU-format tar archives, .It most common cpio archive formats, .It -ISO9660 CD images (with or without RockRidge extensions), +ISO9660 CD images (including RockRidge and Joliet extensions), .It Zip archives. .El The library automatically detects archives compressed with .Xr gzip 1 , .Xr bzip2 1 , +.Xr xz 1 , or .Xr compress 1 and decompresses them transparently. @@ -87,6 +91,8 @@ archives, .It POSIX octet-oriented cpio archives, .It +Zip archive, +.It two different variants of shar archives. .El Pax interchange format is an extension of the tar archive format that @@ -111,131 +117,37 @@ The rest of this manual page provides an overview of the library operation. More detailed information can be found in the individual manual pages for each API or utility function. +.\" .Sh READING AN ARCHIVE -To read an archive, you must first obtain an initialized -.Tn struct archive -object from -.Fn archive_read_new . -You can then modify this object for the desired operations with the -various -.Fn archive_read_set_XXX -and -.Fn archive_read_support_XXX -functions. -In particular, you will need to invoke appropriate -.Fn archive_read_support_XXX -functions to enable the corresponding compression and format -support. -Note that these latter functions perform two distinct operations: -they cause the corresponding support code to be linked into your -program, and they enable the corresponding auto-detect code. -Unless you have specific constraints, you will generally want -to invoke -.Fn archive_read_support_compression_all -and -.Fn archive_read_support_format_all -to enable auto-detect for all formats and compression types -currently supported by the library. -.Pp -Once you have prepared the -.Tn struct archive -object, you call -.Fn archive_read_open -to actually open the archive and prepare it for reading. -There are several variants of this function; -the most basic expects you to provide pointers to several -functions that can provide blocks of bytes from the archive. -There are convenience forms that allow you to -specify a filename, file descriptor, -.Ft "FILE *" -object, or a block of memory from which to read the archive data. -Note that the core library makes no assumptions about the -size of the blocks read; -callback functions are free to read whatever block size is -most appropriate for the medium. -.Pp -Each archive entry consists of a header followed by a certain -amount of data. -You can obtain the next header with -.Fn archive_read_next_header , -which returns a pointer to an -.Tn struct archive_entry -structure with information about the current archive element. -If the entry is a regular file, then the header will be followed -by the file data. -You can use -.Fn archive_read_data -(which works much like the -.Xr read 2 -system call) -to read this data from the archive. -You may prefer to use the higher-level -.Fn archive_read_data_skip , -which reads and discards the data for this entry, -.Fn archive_read_data_to_buffer , -which reads the data into an in-memory buffer, -.Fn archive_read_data_to_file , -which copies the data to the provided file descriptor, or -.Fn archive_read_extract , -which recreates the specified entry on disk and copies data -from the archive. -In particular, note that -.Fn archive_read_extract -uses the -.Tn struct archive_entry -structure that you provide it, which may differ from the -entry just read from the archive. -In particular, many applications will want to override the -pathname, file permissions, or ownership. -.Pp -Once you have finished reading data from the archive, you -should call -.Fn archive_read_close -to close the archive, then call -.Fn archive_read_finish -to release all resources, including all memory allocated by the library. -.Pp -The -.Xr archive_read 3 -manual page provides more detailed calling information for this API. +See +.Xr libarchive_read 3 . +.\" .Sh WRITING AN ARCHIVE -You use a similar process to write an archive. +See +.Xr libarchive_write 3 . +.\" +.Sh WRITING ENTRIES TO DISK The -.Fn archive_write_new -function creates an archive object useful for writing, -the various -.Fn archive_write_set_XXX -functions are used to set parameters for writing the archive, and -.Fn archive_write_open -completes the setup and opens the archive for writing. -.Pp -Individual archive entries are written in a three-step -process: -You first initialize a -.Tn struct archive_entry -structure with information about the new entry. -At a minimum, you should set the pathname of the -entry and provide a -.Va struct stat -with a valid -.Va st_mode -field, which specifies the type of object and -.Va st_size -field, which specifies the size of the data portion of the object. +.Xr archive_write_disk 3 +API allows you to write +.Xr archive_entry 3 +objects to disk using the same API used by +.Xr archive_write 3 . The -.Fn archive_write_header -function actually writes the header data to the archive. -You can then use -.Fn archive_write_data -to write the actual data. -.Pp -After all entries have been written, use the -.Fn archive_write_finish -function to release all resources. -.Pp +.Xr archive_write_disk 3 +API is used internally by +.Fn archive_read_extract ; +using it directly can provide greater control over how entries +get written to disk. +This API also makes it possible to share code between +archive-to-archive copy and archive-to-disk extraction +operations. +.Sh READING ENTRIES FROM DISK The -.Xr archive_write 3 -manual page provides more detailed calling information for this API. +.Xr archive_read_disk 3 +provides some support for populating +.Xr archive_entry 3 +objects from information in the filesystem. .Sh DESCRIPTION Detailed descriptions of each function are provided by the corresponding manual pages. @@ -259,7 +171,9 @@ In particular, pax interchange format can easily accommodate pathnames in arbitrary character sets that exceed .Va PATH_MAX . .Sh RETURN VALUES -Most functions return zero on success, non-zero on error. +Most functions return +.Cm ARCHIVE_OK +(zero) on success, non-zero on error. The return value indicates the general severity of the error, ranging from .Cm ARCHIVE_WARN , @@ -329,3 +243,14 @@ stored in an is supported by all formats. For example, cpio formats do not support nanosecond timestamps; old tar formats do not support large device numbers. +.Pp +The +.Xr archive_read_disk 3 +API should support iterating over filesystems; +that would make it possible to share code among +disk-to-archive, archive-to-archive, archive-to-disk, +and disk-to-disk operations. +Currently, it only supports reading the +information for a single file. +(Which is still quite useful, as it hides a lot +of system-specific details.) diff --git a/Utilities/cmlibarchive/libarchive/libarchive_changes.3 b/Utilities/cmlibarchive/libarchive/libarchive_changes.3 new file mode 100644 index 000000000..6ee6af245 --- /dev/null +++ b/Utilities/cmlibarchive/libarchive/libarchive_changes.3 @@ -0,0 +1,341 @@ +.\" Copyright (c) 2011 Tim Kientzle +.\" 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 AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 27, 2011 +.Dt LIBARCHIVE_CHANGES 3 +.Os +.Sh NAME +.Nm changes in libarchive interface +.\" +.Sh CHANGES IN LIBARCHIVE 3 +This page describes user-visible changes in libarchive3, and lists +public functions and other symbols changed, deprecated or removed +in libarchive3, along with their replacements if any. +.Pp +.\" +.Ss Multiple Filters +.\" +Libarchive2 permitted a single (input or output) filter active +on an archive. +Libarchive3 extends this into a variable-length stack. +Where +.Fn archive_write_set_compression_XXX +would replace any existing filter, +.Fn archive_write_add_filter_XXX +extends the write pipeline with another filter. +.\" +.Ss Character Set Handling +.\" +Libarchive2 assumed that the local platform uses +.Tn Unicode +as the native +.Tn wchar_t +encoding, which is true on +.Tn Windows , +modern +.Tn Linux , +and a few other systems, but is certainly not universal. +As a result, pax format archives were written incorrectly on some +systems, since pax format requires +.Tn UTF-8 +and libarchive 2 incorrectly +assumed that +.Tn wchar_t +strings can be easily converted to +.Tn UTF-8 . +.Pp +Libarchive3 uses the standard iconv library to convert between character +sets and is introducing the notion of a +.Dq default character set for the archive . +To support this, +.Tn archive_entry +objects can now be bound to a particular archive when they are created. +The automatic character set conversions performed by +.Tn archive_entry +objects when reading and writing filenames, usernames, and other strings +will now use an appropriate default character set: +.Pp +If the +.Tn archive_entry +object is bound to an archive, it will use the +default character set for that archive. +.Pp +The platform default character encoding (as returned by +.Fn nl_langinfo CHARSET ) +will be used if nothing else is specified. +.Pp +Libarchive3 also introduces charset options to many of the archive +readers and writers to control the character set that will be used for +filenames written in those archives. +When possible, this will be set automatically based on information in +the archive itself. +Combining this with the notion of a default character set for the +archive should allow you to configure libarchive to read archives from +other platforms and have the filenames and other information +transparently converted to the character encoding suitable for your +application. +.\" +.Ss Prototype Changes +.\" +These changes break binary compatibility; libarchive3 has a new shared +library version to reflect these changes. +The library now uses portable wide types such as +.Tn int64_t +instead of less-portable types such as +.Tn off_t , +.Tn gid_t , +.Tn uid_t , +and +.Tn ino_t . +.Pp +There are a few cases where these changes will affect your source code: +.Bl -bullet -width ind +.It +In some cases, libarchive's wider types will introduce the possibility +of truncation: for example, on a system with a 16-bit +.Tn uid_t , you risk having uid +.Li 65536 +be truncated to uid +.Li 0 , +which can cause serious security problems. +.It +Typedef function pointer types will be incompatible. +For example, if you define custom skip callbacks, you may have to use +code similar to the following if you want to support building against +libarchive2 and libarchive3: +.Bd -literal +#if ARCHIVE_VERSION_NUMBER < 3000000 +typedef off_t myoff_t; +#else +typedef int64_t myoff_t; +#endif + +myoff_t +my_skip_function(struct archive *a, void *v, myoff_t o) +{ + ... implementation ... +} +.Ed +.El +.Pp +Affected functions: +.Pp +.Bl -bullet -compact +.It +.Xo +.Fn archive_entry_gid , +.Fn archive_entry_set_gid +.Xc +.It +.Xo +.Fn archive_entry_uid , +.Fn archive_entry_set_uid +.Xc +.It +.Xo +.Fn archive_entry_ino , +.Fn archive_entry_set_ino +.Xc +.It +.Xo +.Fn archive_read_data_block , +.Fn archive_write_data_block +.Xc +.It +.Xo +.Fn archive_read_disk_gname , +.Fn archive_read_disk_uname +.Xc +.It +.Xo +.Fn archive_read_disk_set_gname_lookup , +.Fn archive_read_disk_set_group_lookup , +.Fn archive_read_disk_set_uname_lookup , +.Fn archive_read_disk_set_user_lookup +.Xc +.It +.Fn archive_skip_callback +.It +.Xo +.Fn archive_read_extract_set_skip_file , +.Fn archive_write_disk_set_skip_file , +.Fn archive_write_set_skip_file +.Xc +.It +.Xo +.Fn archive_write_disk_set_group_lookup , +.Fn archive_write_disk_set_user_lookup +.Xc +.El +.Pp +Where these functions or their arguments took or returned +.Tn gid_t , +.Tn ino_t , +.Tn off_t , +or +.Tn uid_t +they now take or return +.Tn int64_t +or equivalent. +.\" +.Ss Deprecated Symbols +.\" +Symbols deprecated in libarchive3 will be removed in libarchive4. +These symbols, along with their replacements if any, are listed below: +.\" +.Bl -tag -width ind +.It Fn archive_position_compressed , Fn archive_position_uncompressed +.Fn archive_filter_bytes +.It Fn archive_compression +.Fn archive_filter_code +.It Fn archive_compression_name +.Fn archive_filter_name +.It Fn archive_read_finish , Fn archive_write_finish +.Fn archive_read_free , +.Fn archive_write_free +.It Fn archive_read_open_file , Fn archive_write_open_file +.Fn archive_read_open_filename , +.Fn archive_write_open_filename +.It Fn archive_read_support_compression_all +.\" archive_read_support_compression_* -> archive_read_support_filter_* +.Fn archive_read_support_filter_all +.It Fn archive_read_support_compression_bzip2 +.Fn archive_read_support_filter_bzip2 +.It Fn archive_read_support_compression_compress +.Fn archive_read_support_filter_compress +.It Fn archive_read_support_compression_gzip +.Fn archive_read_support_filter_gzip +.It Fn archive_read_support_compression_lzip +.Fn archive_read_support_filter_lzip +.It Fn archive_read_support_compression_lzma +.Fn archive_read_support_filter_lzma +.It Fn archive_read_support_compression_none +.Fn archive_read_support_filter_none +.It Fn archive_read_support_compression_program +.Fn archive_read_support_filter_program +.It Fn archive_read_support_compression_program_signature +.Fn archive_read_support_filter_program_signature +.It Fn archive_read_support_compression_rpm +.Fn archive_read_support_filter_rpm +.It Fn archive_read_support_compression_uu +.Fn archive_read_support_filter_uu +.It Fn archive_read_support_compression_xz +.Fn archive_read_support_filter_xz +.\" archive_write_set_compression_* -> archive_write_add_filter_* +.It Fn archive_write_set_compression_bzip2 +.Fn archive_write_add_filter_bzip2 +.It Fn archive_write_set_compression_compress +.Fn archive_write_add_filter_compress +.It Fn archive_write_set_compression_gzip +.Fn archive_write_add_filter_gzip +.It Fn archive_write_set_compression_lzip +.Fn archive_write_add_filter_lzip +.It Fn archive_write_set_compression_lzma +.Fn archive_write_add_filter_lzma +.It Fn archive_write_set_compression_none +.Fn archive_write_add_filter_none +.It Fn archive_write_set_compression_program +.Fn archive_write_add_filter_program +.It Fn archive_write_set_compression_filter +.Fn archive_write_add_filter_filter +.El +.\" +.Ss Removed Symbols +.\" +These symbols, listed below along with their replacements if any, +were deprecated in libarchive2, and are not part of libarchive3. +.\" +.Bl -tag -width ind +.It Fn archive_api_feature +.Fn archive_version_number +.It Fn archive_api_version +.Fn archive_version_number +.It Fn archive_version +.Fn archive_version_string +.It Fn archive_version_stamp +.Fn archive_version_number +.It Fn archive_read_set_filter_options +.Fn archive_read_set_options +or +.Fn archive_read_set_filter_option +.It Fn archive_read_set_format_options +.Fn archive_read_set_options +or +.Fn archive_read_set_format_option +.It Fn archive_write_set_filter_options +.Fn archive_write_set_options +or +.Fn archive_write_set_filter_option +.It Fn archive_write_set_format_options +.Fn archive_write_set_options +or +.Fn archive_write_set_format_option +.It Dv ARCHIVE_API_FEATURE +.Dv ARCHIVE_VERSION_NUMBER +.It Dv ARCHIVE_API_VERSION +.Dv ARCHIVE_VERSION_NUMBER +.It Dv ARCHIVE_VERSION_STAMP +.Dv ARCHIVE_VERSION_NUMBER +.It Dv ARCHIVE_LIBRARY_VERSION +.Dv ARCHIVE_VERSION_STRING +.\" +.It Dv ARCHIVE_COMPRESSION_NONE +.Dv ARCHIVE_FILTER_NONE +.It Dv ARCHIVE_COMPRESSION_GZIP +.Dv ARCHIVE_FILTER_GZIP +.It Dv ARCHIVE_COMPRESSION_BZIP2 +.Dv ARCHIVE_FILTER_BZIP2 +.It Dv ARCHIVE_COMPRESSION_COMPRESS +.Dv ARCHIVE_FILTER_COMPRESS +.It Dv ARCHIVE_COMPRESSION_PROGRAM +.Dv ARCHIVE_FILTER_PROGRAM +.It Dv ARCHIVE_COMPRESSION_LZMA +.Dv ARCHIVE_FILTER_LZMA +.It Dv ARCHIVE_COMPRESSION_XZ +.Dv ARCHIVE_FILTER_XZ +.It Dv ARCHIVE_COMPRESSION_UU +.Dv ARCHIVE_FILTER_UU +.It Dv ARCHIVE_COMPRESSION_RPM +.Dv ARCHIVE_FILTER_RPM +.It Dv ARCHIVE_COMPRESSION_LZIP +.Dv ARCHIVE_FILTER_LZIP +.\" +.It Dv ARCHIVE_BYTES_PER_RECORD +.Li 512 +.It Dv ARCHIVE_DEFAULT_BYTES_PER_BLOCK +.Li 10240 +.El +.Sh SEE ALSO +.Xr libarchive 3 , +.Xr archive_read 3 , +.Xr archive_read_filter 3 , +.Xr archive_read_format 3 , +.Xr archive_read_set_options 3 , +.Xr archive_write 3 , +.Xr archive_write_filter 3 , +.Xr archive_write_format 3 , +.Xr archive_write_set_options 3 , +.Xr archive_util 3 diff --git a/Utilities/cmlibarchive/libarchive/libarchive_internals.3 b/Utilities/cmlibarchive/libarchive/libarchive_internals.3 index 9a42b76d4..776f4c351 100644 --- a/Utilities/cmlibarchive/libarchive/libarchive_internals.3 +++ b/Utilities/cmlibarchive/libarchive/libarchive_internals.3 @@ -41,15 +41,15 @@ make it easy to add new archive and compression formats. Externally, libarchive exposes most operations through an opaque, object-style interface. The -.Xr archive_entry 1 +.Xr archive_entry 3 objects store information about a single filesystem object. The rest of the library provides facilities to write -.Xr archive_entry 1 +.Xr archive_entry 3 objects to archive files, read them from archive files, and write them to disk. (There are plans to add a facility to read -.Xr archive_entry 1 +.Xr archive_entry 3 objects from disk as well.) .Pp The read and write APIs each have four layers: a public API @@ -363,4 +363,3 @@ The .Nm libarchive library was written by .An Tim Kientzle Aq kientzle@acm.org . -.Sh BUGS diff --git a/Utilities/cmlibarchive/libarchive/o2 b/Utilities/cmlibarchive/libarchive/o2 deleted file mode 100644 index 580c9c34e..000000000 --- a/Utilities/cmlibarchive/libarchive/o2 +++ /dev/null @@ -1,483 +0,0 @@ -archive_write(3) BSD Library Functions Manual archive_write(3) - -NAME - archive_write_new, archive_write_set_format_cpio, - archive_write_set_format_pax, archive_write_set_format_pax_restricted, - archive_write_set_format_shar, archive_write_set_format_shar_binary, - archive_write_set_format_ustar, archive_write_get_bytes_per_block, - archive_write_set_bytes_per_block, archive_write_set_bytes_in_last_block, - archive_write_set_compression_bzip2, - archive_write_set_compression_compress, - archive_write_set_compression_gzip, archive_write_set_compression_none, - archive_write_set_compression_program, - archive_write_set_compressor_options, archive_write_set_format_options, - archive_write_set_options, archive_write_open, archive_write_open_fd, - archive_write_open_FILE, archive_write_open_filename, - archive_write_open_memory, archive_write_header, archive_write_data, - archive_write_finish_entry, archive_write_close, archive_write_finish -- - functions for creating archives - -SYNOPSIS - #include  - - struct archive * - archive_write_new(void); - - int - archive_write_get_bytes_per_block(struct archive *); - - int - archive_write_set_bytes_per_block(struct archive *, int bytes_per_block); - - int - archive_write_set_bytes_in_last_block(struct archive *, int); - - int - archive_write_set_compression_bzip2(struct archive *); - - int - archive_write_set_compression_compress(struct archive *); - - int - archive_write_set_compression_gzip(struct archive *); - - int - archive_write_set_compression_none(struct archive *); - - int - archive_write_set_compression_program(struct archive *, - const char * cmd); - - int - archive_write_set_format_cpio(struct archive *); - - int - archive_write_set_format_pax(struct archive *); - - int - archive_write_set_format_pax_restricted(struct archive *); - - int - archive_write_set_format_shar(struct archive *); - - int - archive_write_set_format_shar_binary(struct archive *); - - int - archive_write_set_format_ustar(struct archive *); - - int - archive_write_set_format_options(struct archive *, const char *); - - int - archive_write_set_compressor_options(struct archive *, const char *); - - int - archive_write_set_options(struct archive *, const char *); - - int - archive_write_open(struct archive *, void *client_data, - archive_open_callback *, archive_write_callback *, - archive_close_callback *); - - int - archive_write_open_fd(struct archive *, int fd); - - int - archive_write_open_FILE(struct archive *, FILE *file); - - int - archive_write_open_filename(struct archive *, const char *filename); - - int - archive_write_open_memory(struct archive *, void *buffer, - size_t bufferSize, size_t *outUsed); - - int - archive_write_header(struct archive *, struct archive_entry *); - - ssize_t - archive_write_data(struct archive *, const void *, size_t); - - int - archive_write_finish_entry(struct archive *); - - int - archive_write_close(struct archive *); - - int - archive_write_finish(struct archive *); - -DESCRIPTION - These functions provide a complete API for creating streaming archive - files. The general process is to first create the struct archive object, - set any desired options, initialize the archive, append entries, then - close the archive and release all resources. The following summary - describes the functions in approximately the order they are ordinarily - used: - - archive_write_new() - Allocates and initializes a struct archive object suitable for - writing a tar archive. - - archive_write_set_bytes_per_block() - Sets the block size used for writing the archive data. Every - call to the write callback function, except possibly the last - one, will use this value for the length. The third parameter is - a boolean that specifies whether or not the final block written - will be padded to the full block size. If it is zero, the last - block will not be padded. If it is non-zero, padding will be - added both before and after compression. The default is to use a - block size of 10240 bytes and to pad the last block. Note that a - block size of zero will suppress internal blocking and cause - writes to be sent directly to the write callback as they occur. - - archive_write_get_bytes_per_block() - Retrieve the block size to be used for writing. A value of -1 - here indicates that the library should use default values. A - value of zero indicates that internal blocking is suppressed. - - archive_write_set_bytes_in_last_block() - Sets the block size used for writing the last block. If this - value is zero, the last block will be padded to the same size as - the other blocks. Otherwise, the final block will be padded to a - multiple of this size. In particular, setting it to 1 will cause - the final block to not be padded. For compressed output, any - padding generated by this option is applied only after the com- - pression. The uncompressed data is always unpadded. The default - is to pad the last block to the full block size (note that - archive_write_open_filename() will set this based on the file - type). Unlike the other ``set'' functions, this function can be - called after the archive is opened. - - archive_write_get_bytes_in_last_block() - Retrieve the currently-set value for last block size. A value of - -1 here indicates that the library should use default values. - - archive_write_set_format_cpio(), archive_write_set_format_pax(), - archive_write_set_format_pax_restricted(), - archive_write_set_format_shar(), - archive_write_set_format_shar_binary(), - archive_write_set_format_ustar() - Sets the format that will be used for the archive. The library - can write POSIX octet-oriented cpio format archives, POSIX-stan- - dard ``pax interchange'' format archives, traditional ``shar'' - archives, enhanced ``binary'' shar archives that store a variety - of file attributes and handle binary files, and POSIX-standard - ``ustar'' archives. The pax interchange format is a backwards- - compatible tar format that adds key/value attributes to each - entry and supports arbitrary filenames, linknames, uids, sizes, - etc. ``Restricted pax interchange format'' is the library - default; this is the same as pax format, but suppresses the pax - extended header for most normal files. In most cases, this will - result in ordinary ustar archives. - - archive_write_set_compression_bzip2(), - archive_write_set_compression_compress(), - archive_write_set_compression_gzip(), - archive_write_set_compression_none() - The resulting archive will be compressed as specified. Note that - the compressed output is always properly blocked. - - archive_write_set_compression_program() - The archive will be fed into the specified compression program. - The output of that program is blocked and written to the client - write callbacks. - - archive_write_set_compressor_options(), - archive_write_set_format_options(), archive_write_set_options() - Specifies options that will be passed to the currently-enabled - compressor and/or format writer. The argument is a comma-sepa- - rated list of individual options. Individual options have one of - the following forms: - option=value - The option/value pair will be provided to every module. - Modules that do not accept an option with this name will - ignore it. - option The option will be provided to every module with a value - of ``1''. - !option - The option will be provided to every module with a NULL - value. - module:option=value, module:option, module:!option - As above, but the corresponding option and value will be - provided only to modules whose name matches module. - The return value will be ARCHIVE_OK if any module accepts the - option, or ARCHIVE_WARN if no module accepted the option, or - ARCHIVE_FATAL if there was a fatal error while attempting to - process the option. - - The currently supported options are: - Compressor gzip - compression-level - The value is interpreted as a decimal integer - specifying the gzip compression level. - Compressor xz - compression-level - The value is interpreted as a decimal integer - specifying the compression level. - Format mtree - cksum, device, flags, gid, gname, indent, link, md5, - mode, nlink, rmd160, sha1, sha256, sha384, - sha512, size, time, uid, uname - Enable a particular keyword in the mtree output. - Prefix with an exclamation mark to disable the - corresponding keyword. The default is equivalent - to ``device, flags, gid, gname, link, mode, - nlink, size, time, type, uid, uname''. - all Enables all of the above keywords. - use-set - Enables generation of /set lines that specify - default values for the following files and/or - directories. - indent XXX needs explanation XXX - - archive_write_open() - Freeze the settings, open the archive, and prepare for writing - entries. 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 ar- - chive. - - archive_write_open_fd() - A convenience form of archive_write_open() that accepts a file - descriptor. The archive_write_open_fd() function is safe for use - with tape drives or other block-oriented devices. - - archive_write_open_FILE() - A convenience form of archive_write_open() that accepts a FILE * - pointer. Note that archive_write_open_FILE() is not safe for - writing to tape drives or other devices that require correct - blocking. - - archive_write_open_file() - A deprecated synonym for archive_write_open_filename(). - - archive_write_open_filename() - A convenience form of archive_write_open() that accepts a file- - name. A NULL argument indicates that the output should be writ- - ten to standard output; an argument of ``-'' will open a file - with that name. If you have not invoked - archive_write_set_bytes_in_last_block(), then - archive_write_open_filename() will adjust the last-block padding - depending on the file: it will enable padding when writing to - standard output or to a character or block device node, it will - disable padding otherwise. You can override this by manually - invoking archive_write_set_bytes_in_last_block() before calling - archive_write_open(). The archive_write_open_filename() function - is safe for use with tape drives or other block-oriented devices. - - archive_write_open_memory() - A convenience form of archive_write_open() that accepts a pointer - to a block of memory that will receive the archive. The final - size_t * argument points to a variable that will be updated after - each write to reflect how much of the buffer is currently in use. - You should be careful to ensure that this variable remains allo- - cated until after the archive is closed. - - archive_write_header() - Build and write a header using the data in the provided struct - archive_entry structure. See archive_entry(3) for information on - creating and populating struct archive_entry objects. - - archive_write_data() - Write data corresponding to the header just written. Returns - number of bytes written or -1 on error. - - archive_write_finish_entry() - Close out the entry just written. In particular, this writes out - the final padding required by some formats. Ordinarily, clients - never need to call this, as it is called automatically by - archive_write_next_header() and archive_write_close() as needed. - - archive_write_close() - Complete the archive and invoke the close callback. - - archive_write_finish() - Invokes archive_write_close() if it was not invoked manually, - then releases all resources. Note that this function was - declared to return void in libarchive 1.x, which made it impossi- - ble to detect errors when archive_write_close() was invoked - implicitly from this function. This is corrected beginning with - libarchive 2.0. - More information about the struct archive object and the overall design - of the library can be found in the libarchive(3) overview. - -IMPLEMENTATION - Compression support is built-in to libarchive, which uses zlib and bzlib - to handle gzip and bzip2 compression, respectively. - -CLIENT CALLBACKS - To use this library, you will need to define and register callback func- - tions that will be invoked to write data to the resulting archive. These - functions are registered by calling archive_write_open(): - - typedef int archive_open_callback(struct archive *, void - *client_data) - - The open callback is invoked by archive_write_open(). It should return - ARCHIVE_OK if the underlying file or data source is successfully opened. - If the open fails, it should call archive_set_error() to register an - error code and message and return ARCHIVE_FATAL. - - typedef ssize_t archive_write_callback(struct archive *, - void *client_data, const void *buffer, size_t length) - - The write callback is invoked whenever the library needs to write raw - bytes to the archive. For correct blocking, each call to the write call- - back function should translate into a single write(2) system call. This - is especially critical when writing archives to tape drives. On success, - the write callback should return the number of bytes actually written. - On error, the callback should invoke archive_set_error() to register an - error code and message and return -1. - - typedef int archive_close_callback(struct archive *, void - *client_data) - - The close callback is invoked by archive_close when the archive process- - ing is complete. The callback should return ARCHIVE_OK on success. On - failure, the callback should invoke archive_set_error() to register an - error code and message and return ARCHIVE_FATAL. - -EXAMPLE - The following sketch illustrates basic usage of the library. In this - example, the callback functions are simply wrappers around the standard - open(2), write(2), and close(2) system calls. - - #include - #include - #include - #include - #include - #include - - struct mydata { - const char *name; - int fd; - }; - - int - myopen(struct archive *a, void *client_data) - { - struct mydata *mydata = client_data; - - mydata->fd = open(mydata->name, O_WRONLY | O_CREAT, 0644); - if (mydata->fd >= 0) - return (ARCHIVE_OK); - else - return (ARCHIVE_FATAL); - } - - ssize_t - mywrite(struct archive *a, void *client_data, const void *buff, size_t n) - { - struct mydata *mydata = client_data; - - return (write(mydata->fd, buff, n)); - } - - int - myclose(struct archive *a, void *client_data) - { - struct mydata *mydata = client_data; - - if (mydata->fd > 0) - close(mydata->fd); - return (0); - } - - void - write_archive(const char *outname, const char **filename) - { - struct mydata *mydata = malloc(sizeof(struct mydata)); - struct archive *a; - struct archive_entry *entry; - struct stat st; - char buff[8192]; - int len; - int fd; - - a = archive_write_new(); - mydata->name = outname; - archive_write_set_compression_gzip(a); - archive_write_set_format_ustar(a); - archive_write_open(a, mydata, myopen, mywrite, myclose); - while (*filename) { - stat(*filename, &st); - entry = archive_entry_new(); - archive_entry_copy_stat(entry, &st); - archive_entry_set_pathname(entry, *filename); - archive_write_header(a, entry); - fd = open(*filename, O_RDONLY); - len = read(fd, buff, sizeof(buff)); - while ( len > 0 ) { - archive_write_data(a, buff, len); - len = read(fd, buff, sizeof(buff)); - } - archive_entry_free(entry); - filename++; - } - archive_write_finish(a); - } - - int main(int argc, const char **argv) - { - const char *outname; - argv++; - outname = argv++; - write_archive(outname, argv); - return 0; - } - -RETURN VALUES - Most functions return ARCHIVE_OK (zero) on success, or one of several - non-zero error codes for errors. Specific error codes include: - ARCHIVE_RETRY for operations that might succeed if retried, ARCHIVE_WARN - for unusual conditions that do not prevent further operations, and - ARCHIVE_FATAL for serious errors that make remaining operations impossi- - ble. The archive_errno() and archive_error_string() functions can be - used to retrieve an appropriate error code and a textual error message. - - archive_write_new() returns a pointer to a newly-allocated struct archive - object. - - archive_write_data() returns a count of the number of bytes actually - written. On error, -1 is returned and the archive_errno() and - archive_error_string() functions will return appropriate values. Note - that if the client-provided write callback function returns a non-zero - value, that error will be propagated back to the caller through whatever - API function resulted in that call, which may include - archive_write_header(), archive_write_data(), archive_write_close(), or - archive_write_finish(). The client callback can call archive_set_error() - to provide values that can then be retrieved by archive_errno() and - archive_error_string(). - -SEE ALSO - tar(1), libarchive(3), tar(5) - -HISTORY - The libarchive library first appeared in FreeBSD 5.3. - -AUTHORS - The libarchive library was written by Tim Kientzle . - -BUGS - There are many peculiar bugs in historic tar implementations that may - cause certain programs to reject archives written by this library. For - example, several historic implementations calculated header checksums - incorrectly and will thus reject valid archives; GNU tar does not fully - support pax interchange format; some old tar implementations required - specific field terminations. - - The default pax interchange format eliminates most of the historic tar - limitations and provides a generic key/value attribute facility for ven- - dor-defined extensions. One oversight in POSIX is the failure to provide - a standard attribute for large device numbers. This library uses - ``SCHILY.devminor'' and ``SCHILY.devmajor'' for device numbers that - exceed the range supported by the backwards-compatible ustar header. - These keys are compatible with Joerg Schilling's star archiver. Other - implementations may not recognize these keys and will thus be unable to - correctly restore device nodes with large device numbers from archives - created by this library. - -BSD May 11, 2008 BSD diff --git a/Utilities/cmlibarchive/libarchive/out b/Utilities/cmlibarchive/libarchive/out deleted file mode 100644 index 7de16c668..000000000 --- a/Utilities/cmlibarchive/libarchive/out +++ /dev/null @@ -1,185 +0,0 @@ -LIBARCHIVE(3) BSD Library Functions Manual LIBARCHIVE(3) - -NAME - libarchive -- functions for reading and writing streaming archives - -LIBRARY - library ``libarchive'' - -OVERVIEW - The libarchive library provides a flexible interface for reading and - writing streaming archive files such as tar and cpio. The library is - inherently stream-oriented; readers serially iterate through the archive, - writers serially add things to the archive. In particular, note that - there is no built-in support for random access nor for in-place modifica- - tion. - - When reading an archive, the library automatically detects the format and - the compression. The library currently has read support for: - +o old-style tar archives, - +o most variants of the POSIX ``ustar'' format, - +o the POSIX ``pax interchange'' format, - +o GNU-format tar archives, - +o most common cpio archive formats, - +o ISO9660 CD images (with or without RockRidge extensions), - +o Zip archives. - The library automatically detects archives compressed with gzip(1), - bzip2(1), or compress(1) and decompresses them transparently. - - When writing an archive, you can specify the compression to be used and - the format to use. The library can write - +o POSIX-standard ``ustar'' archives, - +o POSIX ``pax interchange format'' archives, - +o POSIX octet-oriented cpio archives, - +o two different variants of shar archives. - Pax interchange format is an extension of the tar archive format that - eliminates essentially all of the limitations of historic tar formats in - a standard fashion that is supported by POSIX-compliant pax(1) implemen- - tations on many systems as well as several newer implementations of - tar(1). Note that the default write format will suppress the pax - extended attributes for most entries; explicitly requesting pax format - will enable those attributes for all entries. - - The read and write APIs are accessed through the archive_read_XXX() func- - tions and the archive_write_XXX() functions, respectively, and either can - be used independently of the other. - - The rest of this manual page provides an overview of the library opera- - tion. More detailed information can be found in the individual manual - pages for each API or utility function. - -READING AN ARCHIVE - To read an archive, you must first obtain an initialized struct archive - object from archive_read_new(). You can then modify this object for the - desired operations with the various archive_read_set_XXX() and - archive_read_support_XXX() functions. In particular, you will need to - invoke appropriate archive_read_support_XXX() functions to enable the - corresponding compression and format support. Note that these latter - functions perform two distinct operations: they cause the corresponding - support code to be linked into your program, and they enable the corre- - sponding auto-detect code. Unless you have specific constraints, you - will generally want to invoke archive_read_support_compression_all() and - archive_read_support_format_all() to enable auto-detect for all formats - and compression types currently supported by the library. - - Once you have prepared the struct archive object, you call - archive_read_open() to actually open the archive and prepare it for read- - ing. There are several variants of this function; the most basic expects - you to provide pointers to several functions that can provide blocks of - bytes from the archive. There are convenience forms that allow you to - specify a filename, file descriptor, FILE * object, or a block of memory - from which to read the archive data. Note that the core library makes no - assumptions about the size of the blocks read; callback functions are - free to read whatever block size is most appropriate for the medium. - - Each archive entry consists of a header followed by a certain amount of - data. You can obtain the next header with archive_read_next_header(), - which returns a pointer to an struct archive_entry structure with infor- - mation about the current archive element. If the entry is a regular - file, then the header will be followed by the file data. You can use - archive_read_data() (which works much like the read(2) system call) to - read this data from the archive. You may prefer to use the higher-level - archive_read_data_skip(), which reads and discards the data for this - entry, archive_read_data_to_buffer(), which reads the data into an in- - memory buffer, archive_read_data_to_file(), which copies the data to the - provided file descriptor, or archive_read_extract(), which recreates the - specified entry on disk and copies data from the archive. In particular, - note that archive_read_extract() uses the struct archive_entry structure - that you provide it, which may differ from the entry just read from the - archive. In particular, many applications will want to override the - pathname, file permissions, or ownership. - - Once you have finished reading data from the archive, you should call - archive_read_close() to close the archive, then call - archive_read_finish() to release all resources, including all memory - allocated by the library. - - The archive_read(3) manual page provides more detailed calling informa- - tion for this API. - -WRITING AN ARCHIVE - You use a similar process to write an archive. The archive_write_new() - function creates an archive object useful for writing, the various - archive_write_set_XXX() functions are used to set parameters for writing - the archive, and archive_write_open() completes the setup and opens the - archive for writing. - - Individual archive entries are written in a three-step process: You first - initialize a struct archive_entry structure with information about the - new entry. At a minimum, you should set the pathname of the entry and - provide a struct stat with a valid st_mode field, which specifies the - type of object and st_size field, which specifies the size of the data - portion of the object. The archive_write_header() function actually - writes the header data to the archive. You can then use - archive_write_data() to write the actual data. - - After all entries have been written, use the archive_write_finish() func- - tion to release all resources. - - The archive_write(3) manual page provides more detailed calling informa- - tion for this API. - -DESCRIPTION - Detailed descriptions of each function are provided by the corresponding - manual pages. - - All of the functions utilize an opaque struct archive datatype that pro- - vides access to the archive contents. - - The struct archive_entry structure contains a complete description of a - single archive entry. It uses an opaque interface that is fully docu- - mented in archive_entry(3). - - Users familiar with historic formats should be aware that the newer vari- - ants have eliminated most restrictions on the length of textual fields. - Clients should not assume that filenames, link names, user names, or - group names are limited in length. In particular, pax interchange format - can easily accommodate pathnames in arbitrary character sets that exceed - PATH_MAX. - -RETURN VALUES - Most functions return zero on success, non-zero on error. The return - value indicates the general severity of the error, ranging from - ARCHIVE_WARN, which indicates a minor problem that should probably be - reported to the user, to ARCHIVE_FATAL, which indicates a serious problem - that will prevent any further operations on this archive. On error, the - archive_errno() function can be used to retrieve a numeric error code - (see errno(2)). The archive_error_string() returns a textual error mes- - sage suitable for display. - - archive_read_new() and archive_write_new() return pointers to an allo- - cated and initialized struct archive object. - - archive_read_data() and archive_write_data() return a count of the number - of bytes actually read or written. A value of zero indicates the end of - the data for this entry. A negative value indicates an error, in which - case the archive_errno() and archive_error_string() functions can be used - to obtain more information. - -ENVIRONMENT - There are character set conversions within the archive_entry(3) functions - that are impacted by the currently-selected locale. - -SEE ALSO - tar(1), archive_entry(3), archive_read(3), archive_util(3), - archive_write(3), tar(5) - -HISTORY - The libarchive library first appeared in FreeBSD 5.3. - -AUTHORS - The libarchive library was written by Tim Kientzle . - -BUGS - Some archive formats support information that is not supported by struct - archive_entry. Such information cannot be fully archived or restored - using this library. This includes, for example, comments, character - sets, or the arbitrary key/value pairs that can appear in pax interchange - format archives. - - Conversely, of course, not all of the information that can be stored in - an struct archive_entry is supported by all formats. For example, cpio - formats do not support nanosecond timestamps; old tar formats do not sup- - port large device numbers. - -BSD August 19, 2006 BSD diff --git a/Utilities/cmlibarchive/libarchive/tar.5 b/Utilities/cmlibarchive/libarchive/tar.5 index 853ddab03..65875bd61 100644 --- a/Utilities/cmlibarchive/libarchive/tar.5 +++ b/Utilities/cmlibarchive/libarchive/tar.5 @@ -22,10 +22,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/lib/libarchive/tar.5,v 1.18 2008/05/26 17:00:23 kientzle Exp $ +.\" $FreeBSD: head/lib/libarchive/tar.5 201077 2009-12-28 01:50:23Z kientzle $ .\" -.Dd April 19, 2009 -.Dt tar 5 +.Dd December 27, 2009 +.Dt TAR 5 .Os .Sh NAME .Nm tar @@ -55,8 +55,11 @@ number of records with each I/O operation. These .Dq blocks are always a multiple of the record size. -The most common block size\(emand the maximum supported by historic -implementations\(emis 10240 bytes or 20 records. +The maximum block size supported by early +implementations was 10240 bytes or 20 records. +This is still the default for most implementations +although block sizes of 1MiB (2048 records) or larger are +commonly used with modern high-speed tape drives. (Note: the terms .Dq block and @@ -78,16 +81,16 @@ The header record for an old-style archive consists of the following: .Bd -literal -offset indent struct header_old_tar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char linkflag[1]; - char linkname[100]; - char pad[255]; + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char checksum[8]; + char linkflag[1]; + char linkname[100]; + char pad[255]; }; .Ed All unused bytes in the header record are filled with nulls. @@ -168,9 +171,9 @@ These archives generally follow the POSIX ustar format described below with the following variations: .Bl -bullet -compact -width indent .It -The magic value is -.Dq ustar\ \& -(note the following space). +The magic value consists of the five characters +.Dq ustar +followed by a space. The version field contains a space character followed by a null. .It The numeric fields are generally filled with leading spaces @@ -193,23 +196,23 @@ in the header. It extends the historic format with new fields: .Bd -literal -offset indent struct header_posix_ustar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[6]; - char version[2]; - char uname[32]; - char gname[32]; - char devmajor[8]; - char devminor[8]; - char prefix[155]; - char pad[12]; + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char checksum[8]; + char typeflag[1]; + char linkname[100]; + char magic[6]; + char version[2]; + char uname[32]; + char gname[32]; + char devmajor[8]; + char devminor[8]; + char prefix[155]; + char pad[12]; }; .Ed .Bl -tag -width indent @@ -272,16 +275,19 @@ when they are set and the corresponding names exist on the system. .It Va devmajor , Va devminor Major and minor numbers for character device or block device entry. -.It Va prefix -First part of pathname. +.It Va name , Va prefix If the pathname is too long to fit in the 100 bytes provided by the standard format, it can be split at any .Pa / -character with the first portion going here. +character with the first portion going into the prefix field. If the prefix field is not empty, the reader will prepend the prefix value and a .Pa / character to the regular name field to obtain the full pathname. +The standard does not require a trailing +.Pa / +character on directory names, though most implementations still +include this for compatibility reasons. .El .Pp Note that all unused bytes must be set to @@ -308,7 +314,7 @@ unless they fill the entire field. happens to have a .Pa / as the 156th character.) -POSIX requires numeric fields to be zero-padded in the front, and allows +POSIX requires numeric fields to be zero-padded in the front, and requires them to be terminated with either space or .Dv NUL characters. @@ -316,6 +322,39 @@ characters. Currently, most tar implementations comply with the ustar format, occasionally extending it by adding new fields to the blank area at the end of the header record. +.Ss Numeric Extensions +There have been several attempts to extend the range of sizes +or times supported by modifying how numbers are stored in the +header. +.Pp +One obvious extension to increase the size of files is to +eliminate the terminating characters from the various +numeric fields. +For example, the standard only allows the size field to contain +11 octal digits, reserving the twelfth byte for a trailing +NUL character. +Allowing 12 octal digits allows file sizes up to 64 GB. +.Pp +Another extension, utilized by GNU tar, star, and other newer +.Nm +implementations, permits binary numbers in the standard numeric fields. +This is flagged by setting the high bit of the first byte. +The remainder of the field is treated as a signed twos-complement +value. +This permits 95-bit values for the length and time fields +and 63-bit values for the uid, gid, and device numbers. +In particular, this provides a consistent way to handle +negative time values. +GNU tar supports this extension for the +length, mtime, ctime, and atime fields. +Joerg Schilling's star program and the libarchive library support +this extension for all numeric fields. +Note that this extension is largely obsoleted by the extended +attribute record provided by the pax interchange format. +.Pp +Another early GNU extension allowed base-64 values rather than octal. +This extension was short-lived and is no longer supported by any +implementation. .Ss Pax Interchange Format There are many attributes that cannot be portably stored in a POSIX ustar archive. @@ -359,6 +398,27 @@ A description of some common keys follows: .It Cm atime , Cm ctime , Cm mtime File access, inode change, and modification times. These fields can be negative or include a decimal point and a fractional value. +.It Cm hdrcharset +The character set used by the pax extension values. +By default, all textual values in the pax extended attributes +are assumed to be in UTF-8, including pathnames, user names, +and group names. +In some cases, it is not possible to translate local +conventions into UTF-8. +If this key is present and the value is the six-character ASCII string +.Dq BINARY , +then all textual values are assumed to be in a platform-dependent +multi-byte encoding. +Note that there are only two valid values for this key: +.Dq BINARY +or +.Dq ISO-IR\ 10646\ 2000\ UTF-8 . +No other values are permitted by the standard, and +the latter value should generally not be used as it is the +default when this key is not specified. +In particular, this flag should not be used as a general +mechanism to allow filenames to be stored in arbitrary +encodings. .It Cm uname , Cm uid , Cm gname , Cm gid User name, group name, and numeric UID and GID values. The user name and group name stored here are encoded in UTF8 @@ -402,6 +462,16 @@ Schilling's .Cm SCHILY.* extensions can store all of the data from .Va struct stat . +.It Cm LIBARCHIVE.* +Vendor-specific attributes used by the +.Nm libarchive +library and programs that use it. +.It Cm LIBARCHIVE.creationtime +The time when the file was created. +(This should not be confused with the POSIX +.Dq ctime +attribute, which refers to the time when the file +metadata was last changed.) .It Cm LIBARCHIVE.xattr. Ns Ar namespace Ns . Ns Ar key Libarchive stores POSIX.1e-style extended attributes using keys of this form. @@ -479,33 +549,33 @@ more lenient POSIX-compliant readers can successfully extract most GNU tar archives. .Bd -literal -offset indent struct header_gnu_tar { - char name[100]; - char mode[8]; - char uid[8]; - char gid[8]; - char size[12]; - char mtime[12]; - char checksum[8]; - char typeflag[1]; - char linkname[100]; - char magic[6]; - char version[2]; - char uname[32]; - char gname[32]; - char devmajor[8]; - char devminor[8]; - char atime[12]; - char ctime[12]; - char offset[12]; - char longnames[4]; - char unused[1]; - struct { - char offset[12]; - char numbytes[12]; - } sparse[4]; - char isextended[1]; - char realsize[12]; - char pad[17]; + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char checksum[8]; + char typeflag[1]; + char linkname[100]; + char magic[6]; + char version[2]; + char uname[32]; + char gname[32]; + char devmajor[8]; + char devminor[8]; + char atime[12]; + char ctime[12]; + char offset[12]; + char longnames[4]; + char unused[1]; + struct { + char offset[12]; + char numbytes[12]; + } sparse[4]; + char isextended[1]; + char realsize[12]; + char pad[17]; }; .Ed .Bl -tag -width indent @@ -629,12 +699,12 @@ Each such record contains information about as many as 21 additional sparse blocks as shown here: .Bd -literal -offset indent struct gnu_sparse_header { - struct { - char offset[12]; - char numbytes[12]; - } sparse[21]; - char isextended[1]; - char padding[7]; + struct { + char offset[12]; + char numbytes[12]; + } sparse[21]; + char isextended[1]; + char padding[7]; }; .Ed .It Va realsize @@ -653,8 +723,11 @@ GNU tar 1.14 (XXX check this XXX) and later will write pax interchange format archives when you specify the .Fl -posix flag. -This format uses custom keywords to store sparse file information. -There have been three iterations of this support, referred to +This format follows the pax interchange format closely, +using some +.Cm SCHILY +tags and introducing new keywords to store sparse file information. +There have been three iterations of the sparse file support, referred to as .Dq 0.0 , .Dq 0.1 , @@ -729,7 +802,7 @@ entry. .It An additional .Cm A -entry is used to store an ACL for the following regular entry. +header is used to store an ACL for the following regular entry. The body of this entry contains a seven-digit octal number followed by a zero byte, followed by the textual ACL description. @@ -739,46 +812,95 @@ for POSIX.1e ACLs and 03000000 for NFSv4 ACLs. .El .Ss AIX Tar XXX More details needed XXX +.Pp +AIX Tar uses a ustar-formatted header with the type +.Cm A +for storing coded ACL information. +Unlike the Solaris format, AIX tar writes this header after the +regular file body to which it applies. +The pathname in this header is either +.Cm NFS4 +or +.Cm AIXC +to indicate the type of ACL stored. +The actual ACL is stored in platform-specific binary format. .Ss Mac OS X Tar The tar distributed with Apple's Mac OS X stores most regular files -as two separate entries in the tar archive. -The two entries have the same name except that the first +as two separate files in the tar archive. +The two files have the same name except that the first one has .Dq ._ -added to the beginning of the name. -This first entry stores the -.Dq resource fork -with additional attributes for the file. -The Mac OS X -.Fn CopyFile -API is used to separate a file on disk into separate -resource and data streams and to reassemble those separate -streams when the file is restored to disk. -.Ss Other Extensions -One obvious extension to increase the size of files is to -eliminate the terminating characters from the various -numeric fields. -For example, the standard only allows the size field to contain -11 octal digits, reserving the twelfth byte for a trailing -NUL character. -Allowing 12 octal digits allows file sizes up to 64 GB. +prepended to the last path element. +This special file stores an AppleDouble-encoded +binary blob with additional metadata about the second file, +including ACL, extended attributes, and resources. +To recreate the original file on disk, each +separate file can be extracted and the Mac OS X +.Fn copyfile +function can be used to unpack the separate +metadata file and apply it to th regular file. +Conversely, the same function provides a +.Dq pack +option to encode the extended metadata from +a file into a separate file whose contents +can then be put into a tar archive. .Pp -Another extension, utilized by GNU tar, star, and other newer -.Nm -implementations, permits binary numbers in the standard numeric fields. -This is flagged by setting the high bit of the first byte. -This permits 95-bit values for the length and time fields -and 63-bit values for the uid, gid, and device numbers. -GNU tar supports this extension for the -length, mtime, ctime, and atime fields. -Joerg Schilling's star program supports this extension for -all numeric fields. -Note that this extension is largely obsoleted by the extended attribute -record provided by the pax interchange format. -.Pp -Another early GNU extension allowed base-64 values rather than octal. -This extension was short-lived and is no longer supported by any -implementation. +Note that the Apple extended attributes interact +badly with long filenames. +Since each file is stored with the full name, +a separate set of extensions needs to be included +in the archive for each one, doubling the overhead +required for files with long names. +.Ss Summary of tar type codes +The following list is a condensed summary of the type codes +used in tar header records generated by different tar implementations. +More details about specific implementations can be found above: +.Bl -tag -compact -width XXX +.It NUL +Early tar programs stored a zero byte for regular files. +.It Cm 0 +POSIX standard type code for a regular file. +.It Cm 1 +POSIX standard type code for a hard link description. +.It Cm 2 +POSIX standard type code for a symbolic link description. +.It Cm 3 +POSIX standard type code for a character device node. +.It Cm 4 +POSIX standard type code for a block device node. +.It Cm 5 +POSIX standard type code for a directory. +.It Cm 6 +POSIX standard type code for a FIFO. +.It Cm 7 +POSIX reserved. +.It Cm 7 +GNU tar used for pre-allocated files on some systems. +.It Cm A +Solaris tar ACL description stored prior to a regular file header. +.It Cm A +AIX tar ACL description stored after the file body. +.It Cm D +GNU tar directory dump. +.It Cm K +GNU tar long linkname for the following header. +.It Cm L +GNU tar long pathname for the following header. +.It Cm M +GNU tar multivolume marker, indicating the file is a continuation of a file from the previous volume. +.It Cm N +GNU tar long filename support. Deprecated. +.It Cm S +GNU tar sparse regular file. +.It Cm V +GNU tar tape/volume header name. +.It Cm X +Solaris tar general-purpose extension header. +.It Cm g +POSIX pax interchange format global extensions. +.It Cm x +POSIX pax interchange format per-file extensions. +.El .Sh SEE ALSO .Xr ar 1 , .Xr pax 1 , @@ -809,9 +931,17 @@ John Gilmore's .Nm pdtar public-domain implementation (circa 1987) was highly influential and formed the basis of -.Nm GNU tar . +.Nm GNU tar +(circa 1988). Joerg Shilling's .Nm star archiver is another open-source (GPL) archiver (originally developed circa 1985) which features complete support for pax interchange format. +.Pp +This documentation was written as part of the +.Nm libarchive +and +.Nm bsdtar +project by +.An Tim Kientzle Aq kientzle@FreeBSD.org . diff --git a/Utilities/cmlibarchive/libarchive/test/.cvsignore b/Utilities/cmlibarchive/libarchive/test/.cvsignore deleted file mode 100644 index b71f5a0db..000000000 --- a/Utilities/cmlibarchive/libarchive/test/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -*.tar -*.tar.gz -*.tgz -*.zip -.depend -.deps -.dirstamp -archive.h -libarchive_test -list.h diff --git a/Utilities/cmlibarchive/libarchive/test/CMakeLists.txt b/Utilities/cmlibarchive/libarchive/test/CMakeLists.txt deleted file mode 100644 index 654c39829..000000000 --- a/Utilities/cmlibarchive/libarchive/test/CMakeLists.txt +++ /dev/null @@ -1,145 +0,0 @@ -############################################ -# -# How to build libarchive_test -# -############################################ -IF(ENABLE_TEST) - FOREACH (_src ${libarchive_SOURCES}) - LIST(APPEND parent_libarchive_SOURCES "../${_src}") - ENDFOREACH(_src) - - SET(libarchive_test_SOURCES - ${parent_libarchive_SOURCES} - main.c - read_open_memory.c - test.h - test_acl_basic.c - test_acl_freebsd.c - test_acl_pax.c - test_archive_api_feature.c - test_bad_fd.c - test_compat_bzip2.c - test_compat_gtar.c - test_compat_gzip.c - test_compat_solaris_tar_acl.c - test_compat_tar_hardlink.c - test_compat_xz.c - test_compat_zip.c - test_empty_write.c - test_entry.c - test_entry_strmode.c - test_extattr_freebsd.c - test_fuzz.c - test_link_resolver.c - test_open_fd.c - test_open_file.c - test_open_filename.c - test_pax_filename_encoding.c - test_read_compress_program.c - test_read_data_large.c - test_read_disk.c - test_read_disk_entry_from_file.c - test_read_extract.c - test_read_file_nonexistent.c - test_read_format_ar.c - test_read_format_cpio_bin.c - test_read_format_cpio_bin_Z.c - test_read_format_cpio_bin_be.c - test_read_format_cpio_bin_bz2.c - test_read_format_cpio_bin_gz.c - test_read_format_cpio_bin_xz.c - test_read_format_cpio_odc.c - test_read_format_cpio_svr4_gzip.c - test_read_format_cpio_svr4c_Z.c - test_read_format_empty.c - test_read_format_gtar_gz.c - test_read_format_gtar_lzma.c - test_read_format_gtar_sparse.c - test_read_format_iso_gz.c - test_read_format_isojoliet_bz2.c - test_read_format_isojoliet_long.c - test_read_format_isojoliet_rr.c - test_read_format_isorr_bz2.c - test_read_format_isorr_new_bz2.c - test_read_format_isozisofs_bz2.c - test_read_format_mtree.c - test_read_format_pax_bz2.c - test_read_format_raw.c - test_read_format_tar.c - test_read_format_tar_empty_filename.c - test_read_format_tbz.c - test_read_format_tgz.c - test_read_format_txz.c - test_read_format_tz.c - test_read_format_zip.c - test_read_large.c - test_read_pax_truncated.c - test_read_position.c - test_read_truncated.c - test_tar_filenames.c - test_tar_large.c - test_ustar_filenames.c - test_write_compress.c - test_write_compress_bzip2.c - test_write_compress_gzip.c - test_write_compress_lzma.c - test_write_compress_program.c - test_write_compress_xz.c - test_write_disk.c - test_write_disk_failures.c - test_write_disk_hardlink.c - test_write_disk_perms.c - test_write_disk_secure.c - test_write_disk_sparse.c - test_write_disk_symlink.c - test_write_disk_times.c - test_write_format_ar.c - test_write_format_cpio.c - test_write_format_cpio_empty.c - test_write_format_cpio_odc.c - test_write_format_cpio_newc.c - test_write_format_mtree.c - test_write_format_pax.c - test_write_format_shar_empty.c - test_write_format_tar.c - test_write_format_tar_empty.c - test_write_format_tar_ustar.c - test_write_format_zip.c - test_write_format_zip_empty.c - test_write_format_zip_no_compression.c - test_write_open_memory.c - ) - - # - # Generate the list.h - # - GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h - ${CMAKE_CURRENT_LIST_FILE} ${libarchive_test_SOURCES}) - SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_BINARY_DIR}) - # - # Register target - # - ADD_EXECUTABLE(libarchive_test ${libarchive_test_SOURCES}) - TARGET_LINK_LIBRARIES(libarchive_test ${ADDITIONAL_LIBS}) - SET_PROPERTY(TARGET libarchive_test PROPERTY COMPILE_DEFINITIONS - LIBARCHIVE_STATIC LIST_H) - - # Register ADD_TEST() for each separate test - SET(num 0) - FOREACH(test ${libarchive_test_SOURCES}) - IF(test MATCHES "^test_[^/]+[.]c$") - STRING(REGEX REPLACE "^(test_[^/]+)[.]c$" "\\1" testname ${test}) - ADD_TEST("libarchive_${testname}" libarchive_test - -q -r ${CMAKE_CURRENT_SOURCE_DIR} ${num}) - MATH(EXPR num "${num} + 1") - ENDIF(test MATCHES "^test_[^/]+[.]c$") - ENDFOREACH(test) - - - # Experimental new test handling - ADD_CUSTOM_TARGET(run_libarchive_test - COMMAND libarchive_test -r ${CMAKE_CURRENT_SOURCE_DIR}) - ADD_DEPENDENCIES(run_all_tests run_libarchive_test) -ENDIF(ENABLE_TEST) - diff --git a/Utilities/cmlibarchive/libarchive/test/README b/Utilities/cmlibarchive/libarchive/test/README deleted file mode 100644 index 235a70b02..000000000 --- a/Utilities/cmlibarchive/libarchive/test/README +++ /dev/null @@ -1,63 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/README,v 1.3 2008/01/01 22:28:04 kientzle Exp $ - -This is the test harness for libarchive. - -It compiles into a single program "libarchive_test" that is intended -to exercise as much of the library as possible. It is, of course, -very much a work in progress. - -Each test is a function named test_foo in a file named test_foo.c. -Note that the file name is the same as the function name. -Each file must start with this line: - - #include "test.h" - -The test function must be declared with a line of this form - - DEFINE_TEST(test_foo) - -Nothing else should appear on that line. - -When you add a test, please update the Makefile to add your -file to the list of tests. The Makefile and main.c use various -macro trickery to automatically collect a list of test functions -to be invoked. - -Each test function can rely on the following: - - * The current directory will be a freshly-created empty directory - suitable for that test. (The top-level main() creates a - directory for each separate test and chdir()s to that directory - before running the test.) - - * The test function should use assert(), assertA() and similar macros - defined in test.h. If you need to add new macros of this form, feel - free to do so. The current macro set includes assertEqualInt() and - assertEqualString() that print out additional detail about their - arguments if the assertion does fail. 'A' versions also accept - a struct archive * and display any error message from there on - failure. - - * You are encouraged to document each assertion with a failure() call - just before the assert. The failure() function is a printf-like - function whose text is displayed only if the assertion fails. It - can be used to display additional information relevant to the failure: - - failure("The data read from file %s did not match the data written to that file.", filename); - assert(strcmp(buff1, buff2) == 0); - - * Tests are encouraged to be economical with their memory and disk usage, - though this is not essential. The test is occasionally run under - a memory debugger to try to locate memory leaks in the library; - as a result, tests should be careful to release any memory they - allocate. - - * Disable tests on specific platforms as necessary. Please don't - use config.h to adjust feature requirements, as I want the tests - to also serve as a check on the configure process. The following - form is appropriate: - -#if !defined(__PLATFORM) && !defined(__Platform2__) - assert(xxxx) -#endif - diff --git a/Utilities/cmlibarchive/libarchive/test/main.c b/Utilities/cmlibarchive/libarchive/test/main.c deleted file mode 100644 index be5cb7998..000000000 --- a/Utilities/cmlibarchive/libarchive/test/main.c +++ /dev/null @@ -1,2043 +0,0 @@ -/* - * Copyright (c) 2003-2009 Tim Kientzle - * 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 -#include -#include -#include -#include "test.h" - -/* - * This same file is used pretty much verbatim for all test harnesses. - * - * The next few lines are the only differences. - * TODO: Move this into a separate configuration header, have all test - * suites share one copy of this file. - */ -__FBSDID("$FreeBSD: src/lib/libarchive/test/main.c,v 1.17 2008/12/21 00:13:50 kientzle Exp $"); -#define KNOWNREF "test_compat_gtar_1.tar.uu" -#define ENVBASE "LIBARCHIVE" /* Prefix for environment variables. */ -#undef PROGRAM /* Testing a library, not a program. */ -#define LIBRARY "libarchive" -#define EXTRA_DUMP(x) archive_error_string((struct archive *)(x)) -#define EXTRA_VERSION archive_version() - -/* - * - * Windows support routines - * - * Note: Configuration is a tricky issue. Using HAVE_* feature macros - * in the test harness is dangerous because they cover up - * configuration errors. The classic example of this is omitting a - * configure check. If libarchive and libarchive_test both look for - * the same feature macro, such errors are hard to detect. Platform - * macros (e.g., _WIN32 or __GNUC__) are a little better, but can - * easily lead to very messy code. It's best to limit yourself - * to only the most generic programming techniques in the test harness - * and thus avoid conditionals altogether. Where that's not possible, - * try to minimize conditionals by grouping platform-specific tests in - * one place (e.g., test_acl_freebsd) or by adding new assert() - * functions (e.g., assertMakeHardlink()) to cover up platform - * differences. Platform-specific coding in libarchive_test is often - * a symptom that some capability is missing from libarchive itself. - */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#if !defined(__GNUC__) -#include -#endif -#include -#include -#ifndef F_OK -#define F_OK (0) -#endif -#ifndef S_ISDIR -#define S_ISDIR(m) ((m) & _S_IFDIR) -#endif -#ifndef S_ISREG -#define S_ISREG(m) ((m) & _S_IFREG) -#endif -#define access _access -#define chdir _chdir -#ifndef fileno -#define fileno _fileno -#endif -/*#define fstat _fstat64*/ -#define getcwd _getcwd -#define lstat stat -/*#define lstat _stat64*/ -/*#define stat _stat64*/ -#define rmdir _rmdir -#define strdup _strdup -#define umask _umask -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -void *GetFunctionKernel32(const char *name) -{ - static HINSTANCE lib; - static int set; - if (!set) { - set = 1; - lib = LoadLibrary("kernel32.dll"); - } - if (lib == NULL) { - fprintf(stderr, "Can't load kernel32.dll?!\n"); - exit(1); - } - return (void *)GetProcAddress(lib, name); -} - -static int -my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateSymbolicLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, flags); -} - -static int -my_CreateHardLinkA(const char *linkname, const char *target) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, NULL); -} - -int -my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) -{ - HANDLE h; - int r; - - h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) - return (0); - r = GetFileInformationByHandle(h, bhfi); - CloseHandle(h); - return (r); -} -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) -static void -invalid_parameter_handler(const wchar_t * expression, - const wchar_t * function, const wchar_t * file, - unsigned int line, uintptr_t pReserved) -{ - /* nop */ -} -#endif - -/* - * - * OPTIONS FLAGS - * - */ - -/* Enable core dump on failure. */ -static int dump_on_failure = 0; -/* Default is to remove temp dirs and log data for successful tests. */ -static int keep_temp_files = 0; -/* Default is to just report pass/fail for each test. */ -static int verbosity = 0; -#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ -#define VERBOSITY_PASSFAIL 0 /* Default */ -#define VERBOSITY_LIGHT_REPORT 1 /* -v */ -#define VERBOSITY_FULL 2 /* -vv */ -/* A few places generate even more output for verbosity > VERBOSITY_FULL, - * mostly for debugging the test harness itself. */ -/* Cumulative count of assertion failures. */ -static int failures = 0; -/* Cumulative count of reported skips. */ -static int skips = 0; -/* Cumulative count of assertions checked. */ -static int assertions = 0; - -/* Directory where uuencoded reference files can be found. */ -static const char *refdir; - -/* - * Report log information selectively to console and/or disk log. - */ -static int log_console = 0; -static FILE *logfile; -static void -vlogprintf(const char *fmt, va_list ap) -{ - if (log_console) - vfprintf(stdout, fmt, ap); - if (logfile != NULL) - vfprintf(logfile, fmt, ap); -} - -static void -logprintf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vlogprintf(fmt, ap); - va_end(ap); -} - -/* Set up a message to display only if next assertion fails. */ -static char msgbuff[4096]; -static const char *msg, *nextmsg; -void -failure(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); - va_end(ap); - nextmsg = msgbuff; -} - -/* - * Copy arguments into file-local variables. - * This was added to permit vararg assert() functions without needing - * variadic wrapper macros. Turns out that the vararg capability is almost - * never used, so almost all of the vararg assertions can be simplified - * by removing the vararg capability and reworking the wrapper macro to - * pass __FILE__, __LINE__ directly into the function instead of using - * this hook. I suspect this machinery is used so rarely that we - * would be better off just removing it entirely. That would simplify - * the code here noticably. - */ -static const char *test_filename; -static int test_line; -static void *test_extra; -void assertion_setup(const char *filename, int line) -{ - test_filename = filename; - test_line = line; -} - -/* Called at the beginning of each assert() function. */ -static void -assertion_count(const char *file, int line) -{ - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - ++assertions; - /* Proper handling of "failure()" message. */ - msg = nextmsg; - nextmsg = NULL; - /* Uncomment to print file:line after every assertion. - * Verbose, but occasionally useful in tracking down crashes. */ - /* printf("Checked %s:%d\n", file, line); */ -} - -/* - * For each test source file, we remember how many times each - * assertion was reported. Cleared before each new test, - * used by test_summarize(). - */ -static struct line { - int count; - int skip; -} failed_lines[10000]; - -/* Count this failure, setup up log destination and handle initial report. */ -static void -failure_start(const char *filename, int line, const char *fmt, ...) -{ - va_list ap; - - /* Record another failure for this line. */ - ++failures; - test_filename = filename; - failed_lines[line].count++; - - /* Determine whether to log header to console. */ - switch (verbosity) { - case VERBOSITY_FULL: - log_console = 1; - break; - case VERBOSITY_LIGHT_REPORT: - log_console = (failed_lines[line].count < 2); - break; - default: - log_console = 0; - } - - /* Log file:line header for this failure */ - va_start(ap, fmt); -#if _MSC_VER - logprintf("%s(%d): ", filename, line); -#else - logprintf("%s:%d: ", filename, line); -#endif - vlogprintf(fmt, ap); - va_end(ap); - logprintf("\n"); - - if (msg != NULL && msg[0] != '\0') { - logprintf(" Description: %s\n", msg); - msg = NULL; - } - - /* Determine whether to log details to console. */ - if (verbosity == VERBOSITY_LIGHT_REPORT) - log_console = 0; -} - -/* Complete reporting of failed tests. */ -/* - * The 'extra' hook here is used by libarchive to include libarchive - * error messages with assertion failures. It could also be used - * to add strerror() output, for example. Just define the EXTRA_DUMP() - * macro appropriately. - */ -static void -failure_finish(void *extra) -{ - (void)extra; /* UNUSED (maybe) */ -#ifdef EXTRA_DUMP - if (extra != NULL) - logprintf(" detail: %s\n", EXTRA_DUMP(extra)); -#endif - - if (dump_on_failure) { - fprintf(stderr, - " *** forcing core dump so failure can be debugged ***\n"); - *(char *)(NULL) = 0; - exit(1); - } -} - -/* Inform user that we're skipping some checks. */ -void -test_skipping(const char *fmt, ...) -{ - char buff[1024]; - va_list ap; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - va_end(ap); - /* failure_start() isn't quite right, but is awfully convenient. */ - failure_start(test_filename, test_line, "SKIPPING: %s", buff); - --failures; /* Undo failures++ in failure_start() */ - /* Don't failure_finish() here. */ - /* Mark as skip, so doesn't count as failed test. */ - failed_lines[test_line].skip = 1; - ++skips; -} - -/* - * - * ASSERTIONS - * - */ - -/* Generic assert() just displays the failed condition. */ -int -assertion_assert(const char *file, int line, int value, - const char *condition, void *extra) -{ - assertion_count(file, line); - if (!value) { - failure_start(file, line, "Assertion failed: %s", condition); - failure_finish(extra); - } - return (value); -} - -/* chdir() and report any errors */ -int -assertion_chdir(const char *file, int line, const char *pathname) -{ - assertion_count(file, line); - if (chdir(pathname) == 0) - return (1); - failure_start(file, line, "chdir(\"%s\")", pathname); - failure_finish(NULL); - return (0); - -} - -/* Verify two integers are equal. */ -int -assertion_equal_int(const char *file, int line, - long long v1, const char *e1, long long v2, const char *e2, void *extra) -{ - assertion_count(file, line); - if (v1 == v2) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); - failure_finish(extra); - return (0); -} - -static void strdump(const char *e, const char *p) -{ - logprintf(" %s = ", e); - if (p == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*p != '\0') { - unsigned int c = 0xff & *p++; - switch (c) { - case '\a': printf("\a"); break; - case '\b': printf("\b"); break; - case '\n': printf("\n"); break; - case '\r': printf("\r"); break; - default: - if (c >= 32 && c < 127) - logprintf("%c", c); - else - logprintf("\\x%02X", c); - } - } - logprintf("\""); - logprintf(" (length %d)\n", p == NULL ? 0 : (int)strlen(p)); -} - -/* Verify two strings are equal, dump them if not. */ -int -assertion_equal_string(const char *file, int line, - const char *v1, const char *e1, - const char *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || strcmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - strdump(e1, v1); - strdump(e2, v2); - failure_finish(extra); - return (0); -} - -static void -wcsdump(const char *e, const wchar_t *w) -{ - logprintf(" %s = ", e); - if (w == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*w != L'\0') { - unsigned int c = *w++; - if (c >= 32 && c < 127) - logprintf("%c", c); - else if (c < 256) - logprintf("\\x%02X", c); - else if (c < 0x10000) - logprintf("\\u%04X", c); - else - logprintf("\\U%08X", c); - } - logprintf("\"\n"); -} - -/* Verify that two wide strings are equal, dump them if not. */ -int -assertion_equal_wstring(const char *file, int line, - const wchar_t *v1, const char *e1, - const wchar_t *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - wcsdump(e1, v1); - wcsdump(e2, v2); - failure_finish(extra); - return (0); -} - -/* - * Pretty standard hexdump routine. As a bonus, if ref != NULL, then - * any bytes in p that differ from ref will be highlighted with '_' - * before and after the hex value. - */ -static void -hexdump(const char *p, const char *ref, size_t l, size_t offset) -{ - size_t i, j; - char sep; - - for(i=0; i < l; i+=16) { - logprintf("%04x", (unsigned)(i + offset)); - sep = ' '; - for (j = 0; j < 16 && i + j < l; j++) { - if (ref != NULL && p[i + j] != ref[i + j]) - sep = '_'; - logprintf("%c%02x", sep, 0xff & (int)p[i+j]); - if (ref != NULL && p[i + j] == ref[i + j]) - sep = ' '; - } - for (; j < 16; j++) { - logprintf("%c ", sep); - sep = ' '; - } - logprintf("%c", sep); - for (j=0; j < 16 && i + j < l; j++) { - int c = p[i + j]; - if (c >= ' ' && c <= 126) - logprintf("%c", c); - else - logprintf("."); - } - logprintf("\n"); - } -} - -/* Verify that two blocks of memory are the same, display the first - * block of differences if they're not. */ -int -assertion_equal_mem(const char *file, int line, - const void *_v1, const char *e1, - const void *_v2, const char *e2, - size_t l, const char *ld, void *extra) -{ - const char *v1 = (const char *)_v1; - const char *v2 = (const char *)_v2; - size_t offset; - - assertion_count(file, line); - if (v1 == v2 || memcmp(v1, v2, l) == 0) - return (1); - - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" size %s = %d\n", ld, (int)l); - /* Dump 48 bytes (3 lines) so that the first difference is - * in the second line. */ - offset = 0; - while (l > 64 && memcmp(v1, v2, 32) == 0) { - /* Two lines agree, so step forward one line. */ - v1 += 16; - v2 += 16; - l -= 16; - offset += 16; - } - logprintf(" Dump of %s\n", e1); - hexdump(v1, v2, l < 64 ? l : 64, offset); - logprintf(" Dump of %s\n", e2); - hexdump(v2, v1, l < 64 ? l : 64, offset); - logprintf("\n"); - failure_finish(extra); - return (0); -} - -/* Verify that the named file exists and is empty. */ -int -assertion_empty_file(const char *f1fmt, ...) -{ - char buff[1024]; - char f1[1024]; - struct stat st; - va_list ap; - ssize_t s; - FILE *f; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) - return (1); - - failure_start(test_filename, test_line, "File should be empty: %s", f1); - logprintf(" File size: %d\n", (int)st.st_size); - logprintf(" Contents:\n"); - f = fopen(f1, "rb"); - if (f == NULL) { - logprintf(" Unable to open %s\n", f1); - } else { - s = ((off_t)sizeof(buff) < st.st_size) ? - (ssize_t)sizeof(buff) : (ssize_t)st.st_size; - s = fread(buff, 1, s, f); - hexdump(buff, NULL, s, 0); - fclose(f); - } - failure_finish(NULL); - return (0); -} - -/* Verify that the named file exists and is not empty. */ -int -assertion_non_empty_file(const char *f1fmt, ...) -{ - char f1[1024]; - struct stat st; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) { - failure_start(test_filename, test_line, "File empty: %s", f1); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify that two files have the same contents. */ -/* TODO: hexdump the first bytes that actually differ. */ -int -assertion_equal_file(const char *fn1, const char *f2pattern, ...) -{ - char fn2[1024]; - va_list ap; - char buff1[1024]; - char buff2[1024]; - FILE *f1, *f2; - int n1, n2; - - assertion_count(test_filename, test_line); - va_start(ap, f2pattern); - vsprintf(fn2, f2pattern, ap); - va_end(ap); - - f1 = fopen(fn1, "rb"); - f2 = fopen(fn2, "rb"); - for (;;) { - n1 = fread(buff1, 1, sizeof(buff1), f1); - n2 = fread(buff2, 1, sizeof(buff2), f2); - if (n1 != n2) - break; - if (n1 == 0 && n2 == 0) { - fclose(f1); - fclose(f2); - return (1); - } - if (memcmp(buff1, buff2, n1) != 0) - break; - } - fclose(f1); - fclose(f2); - failure_start(test_filename, test_line, "Files not identical"); - logprintf(" file1=\"%s\"\n", fn1); - logprintf(" file2=\"%s\"\n", fn2); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file does exist. */ -int -assertion_file_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (!_access(f, 0)) - return (1); -#else - if (!access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file doesn't exist. */ -int -assertion_file_not_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (_access(f, 0)) - return (1); -#else - if (access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should not exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Compare the contents of a file to a block of memory. */ -int -assertion_file_contents(const void *buff, int s, const char *fpattern, ...) -{ - char fn[1024]; - va_list ap; - char *contents; - FILE *f; - int n; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(fn, fpattern, ap); - va_end(ap); - - f = fopen(fn, "rb"); - if (f == NULL) { - failure_start(test_filename, test_line, - "File should exist: %s", fn); - failure_finish(test_extra); - return (0); - } - contents = malloc(s * 2); - n = fread(contents, 1, s * 2, f); - fclose(f); - if (n == s && memcmp(buff, contents, s) == 0) { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "File contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n > 512 ? 512 : 0, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s > 512 ? 512 : 0, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Check the contents of a text file, being tolerant of line endings. */ -int -assertion_text_file_contents(const char *buff, const char *fn) -{ - char *contents; - const char *btxt, *ftxt; - FILE *f; - int n, s; - - assertion_count(test_filename, test_line); - f = fopen(fn, "r"); - s = strlen(buff); - contents = malloc(s * 2 + 128); - n = fread(contents, 1, s * 2 + 128 - 1, f); - if (n >= 0) - contents[n] = '\0'; - fclose(f); - /* Compare texts. */ - btxt = buff; - ftxt = (const char *)contents; - while (*btxt != '\0' && *ftxt != '\0') { - if (*btxt == *ftxt) { - ++btxt; - ++ftxt; - continue; - } - if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { - /* Pass over different new line characters. */ - ++btxt; - ftxt += 2; - continue; - } - break; - } - if (*btxt == '\0' && *ftxt == '\0') { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "Contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Test that two paths point to the same file. */ -/* As a side-effect, asserts that both files exist. */ -static int -is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(path1, &bhfi1); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path1); - failure_finish(NULL); - return (0); - } - r = my_GetFileInformationByName(path2, &bhfi2); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path2); - failure_finish(NULL); - return (0); - } - return (bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh - && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); -#else - struct stat st1, st2; - int r; - - assertion_count(file, line); - r = lstat(path1, &st1); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path1); - failure_finish(NULL); - return (0); - } - r = lstat(path2, &st2); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path2); - failure_finish(NULL); - return (0); - } - return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); -#endif -} - -int -assertion_is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s are not hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -int -assertion_is_not_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (!is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s should not be hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -/* Verify a/b/mtime of 'pathname'. */ -/* If 'recent', verify that it's within last 10 seconds. */ -static int -assertion_file_time(const char *file, int line, - const char *pathname, long t, long nsec, char type, int recent) -{ - long long filet, filet_nsec; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define EPOC_TIME (116444736000000000ULL) - FILETIME ftime, fbirthtime, fatime, fmtime; - ULARGE_INTEGER wintm; - HANDLE h; - ftime.dwLowDateTime = 0; - ftime.dwHighDateTime = 0; - - assertion_count(file, line); - h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - failure_start(file, line, "Can't access %s\n", pathname); - failure_finish(NULL); - return (0); - } - r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); - switch (type) { - case 'a': ftime = fatime; break; - case 'b': ftime = fbirthtime; break; - case 'm': ftime = fmtime; break; - } - CloseHandle(h); - if (r == 0) { - failure_start(file, line, "Can't GetFileTime %s\n", pathname); - failure_finish(NULL); - return (0); - } - wintm.LowPart = ftime.dwLowDateTime; - wintm.HighPart = ftime.dwHighDateTime; - filet = (wintm.QuadPart - EPOC_TIME) / 10000000; - filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; - nsec = (nsec / 100) * 100; /* Round the request */ -#else - struct stat st; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Can't stat %s\n", pathname); - failure_finish(NULL); - return (0); - } - switch (type) { - case 'a': filet = st.st_atime; break; - case 'm': filet = st.st_mtime; break; - case 'b': filet = 0; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } -#if defined(__FreeBSD__) - switch (type) { - case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; - case 'b': filet = st.st_birthtime; - filet_nsec = st.st_birthtimespec.tv_nsec; break; - case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } - /* FreeBSD generally only stores to microsecond res, so round. */ - filet_nsec = (filet_nsec / 1000) * 1000; - nsec = (nsec / 1000) * 1000; -#else - filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ - if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ -#endif -#endif - if (recent) { - /* Check that requested time is up-to-date. */ - time_t now = time(NULL); - if (filet < now - 10 || filet > now + 1) { - failure_start(file, line, - "File %s has %ctime %ld, %ld seconds ago\n", - pathname, type, filet, now - filet); - failure_finish(NULL); - return (0); - } - } else if (filet != t || filet_nsec != nsec) { - failure_start(file, line, - "File %s has %ctime %ld.%09ld, expected %ld.%09ld", - pathname, type, filet, filet_nsec, t, nsec); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify atime of 'pathname'. */ -int -assertion_file_atime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); -} - -/* Verify atime of 'pathname' is up-to-date. */ -int -assertion_file_atime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); -} - -/* Verify birthtime of 'pathname'. */ -int -assertion_file_birthtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); -} - -/* Verify birthtime of 'pathname' is up-to-date. */ -int -assertion_file_birthtime_recent(const char *file, int line, - const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); -} - -/* Verify mtime of 'pathname'. */ -int -assertion_file_mtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); -} - -/* Verify mtime of 'pathname' is up-to-date. */ -int -assertion_file_mtime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); -} - -/* Verify number of links to 'pathname'. */ -int -assertion_file_nlinks(const char *file, int line, - const char *pathname, int nlinks) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(pathname, &bhfi); - if (r != 0 && bhfi.nNumberOfLinks == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, bhfi.nNumberOfLinks, nlinks); - failure_finish(NULL); - return (0); -#else - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_nlink == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, st.st_nlink, nlinks); - failure_finish(NULL); - return (0); -#endif -} - -/* Verify size of 'pathname'. */ -int -assertion_file_size(const char *file, int line, const char *pathname, long size) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_size == size) - return (1); - failure_start(file, line, "File %s has size %ld, expected %ld", - pathname, (long)st.st_size, (long)size); - failure_finish(NULL); - return (0); -} - -/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ -int -assertion_is_dir(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Dir should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISDIR(st.st_mode)) { - failure_start(file, line, "%s is not a dir", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "Dir %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, - * verify that too. */ -int -assertion_is_reg(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0 || !S_ISREG(st.st_mode)) { - failure_start(file, line, "File should exist: %s", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "File %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Check whether 'pathname' is a symbolic link. If 'contents' is - * non-NULL, verify that the symlink has those contents. */ -static int -is_symlink(const char *file, int line, - const char *pathname, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - assertion_count(file, line); - return (0); -#else - char buff[300]; - struct stat st; - ssize_t linklen; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, - "Symlink should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISLNK(st.st_mode)) - return (0); - if (contents == NULL) - return (1); - linklen = readlink(pathname, buff, sizeof(buff)); - if (linklen < 0) { - failure_start(file, line, "Can't read symlink %s", pathname); - failure_finish(NULL); - return (0); - } - buff[linklen] = '\0'; - if (strcmp(buff, contents) != 0) - return (0); - return (1); -#endif -} - -/* Assert that path is a symlink that (optionally) contains contents. */ -int -assertion_is_symlink(const char *file, int line, - const char *path, const char *contents) -{ - if (is_symlink(file, line, path, contents)) - return (1); - if (contents) - failure_start(file, line, "File %s is not a symlink to %s", - path, contents); - else - failure_start(file, line, "File %s is not a symlink", path); - failure_finish(NULL); - return (0); -} - - -/* Create a directory and report any errors. */ -int -assertion_make_dir(const char *file, int line, const char *dirname, int mode) -{ - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - if (0 == _mkdir(dirname)) - return (1); -#else - if (0 == mkdir(dirname, mode)) - return (1); -#endif - failure_start(file, line, "Could not create directory %s", dirname); - failure_finish(NULL); - return(0); -} - -/* Create a file with the specified contents and report any failures. */ -int -assertion_make_file(const char *file, int line, - const char *path, int mode, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: Rework this to set file mode as well. */ - FILE *f; - assertion_count(file, line); - f = fopen(path, "wb"); - if (f == NULL) { - failure_start(file, line, "Could not create file %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if (strlen(contents) - != fwrite(contents, 1, strlen(contents), f)) { - fclose(f); - failure_start(file, line, - "Could not write file %s", path); - failure_finish(NULL); - return (0); - } - } - fclose(f); - return (1); -#else - int fd; - assertion_count(file, line); - fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); - if (fd < 0) { - failure_start(file, line, "Could not create %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if ((ssize_t)strlen(contents) - != write(fd, contents, strlen(contents))) { - close(fd); - failure_start(file, line, "Could not write to %s", path); - failure_finish(NULL); - return (0); - } - } - close(fd); - return (1); -#endif -} - -/* Create a hardlink and report any failures. */ -int -assertion_make_hardlink(const char *file, int line, - const char *newpath, const char *linkto) -{ - int succeeded; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = my_CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK - succeeded = !link(linkto, newpath); -#else - succeeded = 0; -#endif - if (succeeded) - return (1); - failure_start(file, line, "Could not create hardlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Create a symlink and report any failures. */ -int -assertion_make_symlink(const char *file, int line, - const char *newpath, const char *linkto) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - int targetIsDir = 0; /* TODO: Fix this */ - assertion_count(file, line); - if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) - return (1); -#elif HAVE_SYMLINK - assertion_count(file, line); - if (0 == symlink(linkto, newpath)) - return (1); -#endif - failure_start(file, line, "Could not create symlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Set umask, report failures. */ -int -assertion_umask(const char *file, int line, int mask) -{ - assertion_count(file, line); - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - umask(mask); - return (1); -} - -/* - * - * UTILITIES for use by tests. - * - */ - -/* - * Check whether platform supports symlinks. This is intended - * for tests to use in deciding whether to bother testing symlink - * support; if the platform doesn't support symlinks, there's no point - * in checking whether the program being tested can create them. - */ -int -canSymlink(void) -{ - /* Remember the test result */ - static int value = 0, tested = 0; - if (tested) - return (value); - - ++tested; - assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); -#if defined(_WIN32) && !defined(__CYGWIN__) - value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) - && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); -#elif HAVE_SYMLINK - value = (0 == symlink("canSymlink.0", "canSymlink.1")) - && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); -#endif - return (value); -} - -/* - * Can this platform run the gzip program? - */ -/* Platform-dependent options for hiding the output of a subcommand. */ -#if defined(_WIN32) && !defined(__CYGWIN__) -static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ -#else -static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ -#endif -int -canGzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Can this platform run the gunzip program? - */ -int -canGunzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gunzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Sleep as needed; useful for verifying disk timestamp changes by - * ensuring that the wall-clock time has actually changed before we - * go back to re-read something from disk. - */ -void -sleepUntilAfter(time_t t) -{ - while (t >= time(NULL)) -#if defined(_WIN32) && !defined(__CYGWIN__) - Sleep(500); -#else - sleep(1); -#endif -} - -/* - * Call standard system() call, but build up the command line using - * sprintf() conventions. - */ -int -systemf(const char *fmt, ...) -{ - char buff[8192]; - va_list ap; - int r; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - if (verbosity > VERBOSITY_FULL) - logprintf("Cmd: %s\n", buff); - r = system(buff); - va_end(ap); - return (r); -} - -/* - * Slurp a file into memory for ease of comparison and testing. - * Returns size of file in 'sizep' if non-NULL, null-terminates - * data in memory for ease of use. - */ -char * -slurpfile(size_t * sizep, const char *fmt, ...) -{ - char filename[8192]; - struct stat st; - va_list ap; - char *p; - ssize_t bytes_read; - FILE *f; - int r; - - va_start(ap, fmt); - vsprintf(filename, fmt, ap); - va_end(ap); - - f = fopen(filename, "rb"); - if (f == NULL) { - /* Note: No error; non-existent file is okay here. */ - return (NULL); - } - r = fstat(fileno(f), &st); - if (r != 0) { - logprintf("Can't stat file %s\n", filename); - fclose(f); - return (NULL); - } - p = malloc((size_t)st.st_size + 1); - if (p == NULL) { - logprintf("Can't allocate %ld bytes of memory to read file %s\n", - (long int)st.st_size, filename); - fclose(f); - return (NULL); - } - bytes_read = fread(p, 1, (size_t)st.st_size, f); - if (bytes_read < st.st_size) { - logprintf("Can't read file %s\n", filename); - fclose(f); - free(p); - return (NULL); - } - p[st.st_size] = '\0'; - if (sizep != NULL) - *sizep = (size_t)st.st_size; - fclose(f); - return (p); -} - -/* Read a uuencoded file from the reference directory, decode, and - * write the result into the current directory. */ -#define UUDECODE(c) (((c) - 0x20) & 0x3f) -void -extract_reference_file(const char *name) -{ - char buff[1024]; - FILE *in, *out; - - sprintf(buff, "%s/%s.uu", refdir, name); - in = fopen(buff, "r"); - failure("Couldn't open reference file %s", buff); - assert(in != NULL); - if (in == NULL) - return; - /* Read up to and including the 'begin' line. */ - for (;;) { - if (fgets(buff, sizeof(buff), in) == NULL) { - /* TODO: This is a failure. */ - return; - } - if (memcmp(buff, "begin ", 6) == 0) - break; - } - /* Now, decode the rest and write it. */ - /* Not a lot of error checking here; the input better be right. */ - out = fopen(name, "wb"); - while (fgets(buff, sizeof(buff), in) != NULL) { - char *p = buff; - int bytes; - - if (memcmp(buff, "end", 3) == 0) - break; - - bytes = UUDECODE(*p++); - while (bytes > 0) { - int n = 0; - /* Write out 1-3 bytes from that. */ - if (bytes > 0) { - n = UUDECODE(*p++) << 18; - n |= UUDECODE(*p++) << 12; - fputc(n >> 16, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++) << 6; - fputc((n >> 8) & 0xFF, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++); - fputc(n & 0xFF, out); - --bytes; - } - } - } - fclose(out); - fclose(in); -} - -/* - * - * TEST management - * - */ - -/* - * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has - * a line like - * DEFINE_TEST(test_function) - * for each test. - */ - -/* Use "list.h" to declare all of the test functions. */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); -#include "list.h" - -/* Use "list.h" to create a list of all tests (functions and names). */ -#undef DEFINE_TEST -#define DEFINE_TEST(n) { n, #n, 0 }, -struct { void (*func)(void); const char *name; int failures; } tests[] = { - #include "list.h" -}; - -/* - * Summarize repeated failures in the just-completed test. - */ -static void -test_summarize(const char *filename, int failed) -{ - unsigned int i; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: - printf(failed ? "E" : "."); - fflush(stdout); - break; - case VERBOSITY_PASSFAIL: - printf(failed ? "FAIL\n" : "ok\n"); - break; - } - - log_console = (verbosity == VERBOSITY_LIGHT_REPORT); - - for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { - if (failed_lines[i].count > 1 && !failed_lines[i].skip) - logprintf("%s:%d: Summary: Failed %d times\n", - filename, i, failed_lines[i].count); - } - /* Clear the failure history for the next file. */ - memset(failed_lines, 0, sizeof(failed_lines)); -} - -/* - * Actually run a single test, with appropriate setup and cleanup. - */ -static int -test_run(int i, const char *tmpdir) -{ - char logfilename[64]; - int failures_before = failures; - int oldumask; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ - break; - case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ - printf("%3d: %-50s", i, tests[i].name); - fflush(stdout); - break; - default: /* Title of test, details will follow */ - printf("%3d: %s\n", i, tests[i].name); - } - - /* Chdir to the top-level work directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, - "ERROR: Can't chdir to top work dir %s\n", tmpdir); - exit(1); - } - /* Create a log file for this test. */ - sprintf(logfilename, "%s.log", tests[i].name); - logfile = fopen(logfilename, "w"); - fprintf(logfile, "%s\n\n", tests[i].name); - /* Chdir() to a work dir for this specific test. */ - if (!assertMakeDir(tests[i].name, 0755) - || !assertChdir(tests[i].name)) { - fprintf(stderr, - "ERROR: Can't chdir to work dir %s/%s\n", - tmpdir, tests[i].name); - exit(1); - } - /* Explicitly reset the locale before each test. */ - setlocale(LC_ALL, "C"); - /* Record the umask before we run the test. */ - umask(oldumask = umask(0)); - /* - * Run the actual test. - */ - (*tests[i].func)(); - /* - * Clean up and report afterwards. - */ - /* Restore umask */ - umask(oldumask); - /* Reset locale. */ - setlocale(LC_ALL, "C"); - /* Reset directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", - tmpdir); - exit(1); - } - /* Report per-test summaries. */ - tests[i].failures = failures - failures_before; - test_summarize(test_filename, tests[i].failures); - /* Close the per-test log file. */ - fclose(logfile); - logfile = NULL; - /* If there were no failures, we can remove the work dir and logfile. */ - if (tests[i].failures == 0) { - if (!keep_temp_files && assertChdir(tmpdir)) { -#if defined(_WIN32) && !defined(__CYGWIN__) - systemf("rmdir /S /Q %s", tests[i].name); - systemf("del %s", logfilename); -#else - systemf("rm -rf %s", tests[i].name); - systemf("rm %s", logfilename); -#endif - } - } - /* Return appropriate status. */ - return (tests[i].failures); -} - -/* - * - * - * MAIN and support routines. - * - * - */ - -static void -usage(const char *program) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i; - - printf("Usage: %s [options] ...\n", program); - printf("Default is to run all tests.\n"); - printf("Otherwise, specify the numbers of the tests you wish to run.\n"); - printf("Options:\n"); - printf(" -d Dump core after any failure, for debugging.\n"); - printf(" -k Keep all temp files.\n"); - printf(" Default: temp files for successful tests deleted.\n"); -#ifdef PROGRAM - printf(" -p Path to executable to be tested.\n"); - printf(" Default: path taken from " ENVBASE " environment variable.\n"); -#endif - printf(" -q Quiet.\n"); - printf(" -r Path to dir containing reference files.\n"); - printf(" Default: Current directory.\n"); - printf(" -v Verbose.\n"); - printf("Available tests:\n"); - for (i = 0; i < limit; i++) - printf(" %d: %s\n", i, tests[i].name); - exit(1); -} - -static char * -get_refdir(const char *d) -{ - char tried[512] = { '\0' }; - char buff[128]; - char *pwd, *p; - - /* If a dir was specified, try that */ - if (d != NULL) { - pwd = NULL; - snprintf(buff, sizeof(buff), "%s", d); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - goto failure; - } - - /* Get the current dir. */ - pwd = getcwd(NULL, 0); - while (pwd[strlen(pwd) - 1] == '\n') - pwd[strlen(pwd) - 1] = '\0'; - - /* Look for a known file. */ - snprintf(buff, sizeof(buff), "%s", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - -#if defined(LIBRARY) - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); -#else - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); -#endif - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - if (memcmp(pwd, "/usr/obj", 8) == 0) { - snprintf(buff, sizeof(buff), "%s", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - } - -failure: - printf("Unable to locate known reference file %s\n", KNOWNREF); - printf(" Checked following directories:\n%s\n", tried); -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - DebugBreak(); -#endif - exit(1); - -success: - free(p); - free(pwd); - return strdup(buff); -} - -int -main(int argc, char **argv) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i, tests_run = 0, tests_failed = 0, option; - time_t now; - char *refdir_alloc = NULL; - const char *progname; - const char *tmp, *option_arg, *p; - char tmpdir[256]; - char tmpdir_timestamp[256]; - - (void)argc; /* UNUSED */ - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) - /* To stop to run the default invalid parameter handler. */ - _set_invalid_parameter_handler(invalid_parameter_handler); - /* Disable annoying assertion message box. */ - _CrtSetReportMode(_CRT_ASSERT, 0); -#endif - - /* - * Name of this program, used to build root of our temp directory - * tree. - */ - progname = p = argv[0]; - while (*p != '\0') { - /* Support \ or / dir separators for Windows compat. */ - if (*p == '/' || *p == '\\') - progname = p + 1; - ++p; - } - -#ifdef PROGRAM - /* Get the target program from environment, if available. */ - testprogfile = getenv(ENVBASE); -#endif - - if (getenv("TMPDIR") != NULL) - tmp = getenv("TMPDIR"); - else if (getenv("TMP") != NULL) - tmp = getenv("TMP"); - else if (getenv("TEMP") != NULL) - tmp = getenv("TEMP"); - else if (getenv("TEMPDIR") != NULL) - tmp = getenv("TEMPDIR"); - else - tmp = "/tmp"; - - /* Allow -d to be controlled through the environment. */ - if (getenv(ENVBASE "_DEBUG") != NULL) - dump_on_failure = 1; - - /* Get the directory holding test files from environment. */ - refdir = getenv(ENVBASE "_TEST_FILES"); - - /* - * Parse options, without using getopt(), which isn't available - * on all platforms. - */ - ++argv; /* Skip program name */ - while (*argv != NULL) { - if (**argv != '-') - break; - p = *argv++; - ++p; /* Skip '-' */ - while (*p != '\0') { - option = *p++; - option_arg = NULL; - /* If 'opt' takes an argument, parse that. */ - if (option == 'p' || option == 'r') { - if (*p != '\0') - option_arg = p; - else if (*argv == NULL) { - fprintf(stderr, - "Option -%c requires argument.\n", - option); - usage(progname); - } else - option_arg = *argv++; - p = ""; /* End of this option word. */ - } - - /* Now, handle the option. */ - switch (option) { - case 'd': - dump_on_failure = 1; - break; - case 'k': - keep_temp_files = 1; - break; - case 'p': -#ifdef PROGRAM - testprogfile = option_arg; -#else - usage(progname); -#endif - break; - case 'q': - verbosity--; - break; - case 'r': - refdir = option_arg; - break; - case 'v': - verbosity++; - break; - default: - usage(progname); - } - } - } - - /* - * Sanity-check that our options make sense. - */ -#ifdef PROGRAM - if (testprogfile == NULL) - usage(progname); - { - char *testprg; -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Command.com sometimes rejects '/' separators. */ - testprg = strdup(testprogfile); - for (i = 0; testprg[i] != '\0'; i++) { - if (testprg[i] == '/') - testprg[i] = '\\'; - } - testprogfile = testprg; -#endif - /* Quote the name that gets put into shell command lines. */ - testprg = malloc(strlen(testprogfile) + 3); - strcpy(testprg, "\""); - strcat(testprg, testprogfile); - strcat(testprg, "\""); - testprog = testprg; - } -#endif - - /* - * Create a temp directory for the following tests. - * Include the time the tests started as part of the name, - * to make it easier to track the results of multiple tests. - */ - now = time(NULL); - for (i = 0; ; i++) { - strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), - "%Y-%m-%dT%H.%M.%S", - localtime(&now)); - sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, - tmpdir_timestamp, i); - if (assertMakeDir(tmpdir,0755)) - break; - if (i >= 999) { - fprintf(stderr, - "ERROR: Unable to create temp directory %s\n", - tmpdir); - exit(1); - } - } - - /* - * If the user didn't specify a directory for locating - * reference files, try to find the reference files in - * the "usual places." - */ - refdir = refdir_alloc = get_refdir(refdir); - - /* - * Banner with basic information. - */ - printf("\n"); - printf("If tests fail or crash, details will be in:\n"); - printf(" %s\n", tmpdir); - printf("\n"); - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("Reference files will be read from: %s\n", refdir); -#ifdef PROGRAM - printf("Running tests on: %s\n", testprog); -#endif - printf("Exercising: "); - fflush(stdout); - printf("%s\n", EXTRA_VERSION); - } else { - printf("Running "); - fflush(stdout); - } - - /* - * Run some or all of the individual tests. - */ - if (*argv == NULL) { - /* Default: Run all tests. */ - for (i = 0; i < limit; i++) { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - } - } else { - while (*(argv) != NULL) { - if (**argv >= '0' && **argv <= '9') { - i = atoi(*argv); - if (i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } else { - for (i = 0; i < limit; ++i) { - if (strcmp(*argv, tests[i].name) == 0) - break; - } - if (i >= limit) { - printf("*** INVALID Test ``%s''\n", - *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - argv++; - } - } - - /* - * Report summary statistics. - */ - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("\n"); - printf("Totals:\n"); - printf(" Tests run: %8d\n", tests_run); - printf(" Tests failed: %8d\n", tests_failed); - printf(" Assertions checked:%8d\n", assertions); - printf(" Assertions failed: %8d\n", failures); - printf(" Skips reported: %8d\n", skips); - } - if (failures) { - printf("\n"); - printf("Failing tests:\n"); - for (i = 0; i < limit; ++i) { - if (tests[i].failures) - printf(" %d: %s (%d failures)\n", i, - tests[i].name, tests[i].failures); - } - printf("\n"); - printf("Details for failing tests: %s\n", tmpdir); - printf("\n"); - } else { - if (verbosity == VERBOSITY_SUMMARY_ONLY) - printf("\n"); - printf("%d tests passed, no failures\n", tests_run); - } - - free(refdir_alloc); - - /* If the final tmpdir is empty, we can remove it. */ - /* This should be the usual case when all tests succeed. */ - assertChdir(".."); - rmdir(tmpdir); - - return (tests_failed ? 1 : 0); -} diff --git a/Utilities/cmlibarchive/libarchive/test/read_open_memory.c b/Utilities/cmlibarchive/libarchive/test/read_open_memory.c deleted file mode 100644 index ac889adab..000000000 --- a/Utilities/cmlibarchive/libarchive/test/read_open_memory.c +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/read_open_memory.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -#include -#include -#include - -/* - * Read an archive from a block of memory. - * - * This is identical to archive_read_open_memory(), except - * that it goes out of its way to be a little bit unpleasant, - * in order to better test the libarchive internals. - */ - -struct read_memory_data { - unsigned char *buffer; - unsigned char *end; - size_t read_size; - size_t copy_buff_size; - char *copy_buff; -}; - -static int memory_read_close(struct archive *, void *); -static int memory_read_open(struct archive *, void *); -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t memory_read_skip(struct archive *, void *, size_t request); -#else -static off_t memory_read_skip(struct archive *, void *, off_t request); -#endif -static ssize_t memory_read(struct archive *, void *, const void **buff); -static int read_open_memory_internal(struct archive *a, void *buff, - size_t size, size_t read_size, int fullapi); - - -int -read_open_memory(struct archive *a, void *buff, size_t size, size_t read_size) -{ - return read_open_memory_internal(a, buff, size, read_size, 1); -} - -/* - * As above, but don't register any optional part of the API, to verify - * that internals work correctly with just the minimal entry points. - */ -int -read_open_memory2(struct archive *a, void *buff, size_t size, size_t read_size) -{ - return read_open_memory_internal(a, buff, size, read_size, 0); -} - -static int -read_open_memory_internal(struct archive *a, void *buff, - size_t size, size_t read_size, int fullapi) -{ - struct read_memory_data *mine; - - mine = (struct read_memory_data *)malloc(sizeof(*mine)); - if (mine == NULL) { - archive_set_error(a, ENOMEM, "No memory"); - return (ARCHIVE_FATAL); - } - memset(mine, 0, sizeof(*mine)); - mine->buffer = (unsigned char *)buff; - mine->end = mine->buffer + size; - mine->read_size = read_size; - mine->copy_buff_size = read_size + 64; - mine->copy_buff = malloc(mine->copy_buff_size); - if (fullapi) - return (archive_read_open2(a, mine, memory_read_open, - memory_read, memory_read_skip, memory_read_close)); - else - return (archive_read_open2(a, mine, NULL, - memory_read, NULL, memory_read_close)); -} - -/* - * There's nothing to open. - */ -static int -memory_read_open(struct archive *a, void *client_data) -{ - (void)a; /* UNUSED */ - (void)client_data; /* UNUSED */ - return (ARCHIVE_OK); -} - -/* - * In order to exercise libarchive's internal read-combining logic, - * we deliberately copy data for each read to a separate buffer. - * That way, code that runs off the end of the provided data - * will screw up. - */ -static ssize_t -memory_read(struct archive *a, void *client_data, const void **buff) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - size_t size; - - (void)a; /* UNUSED */ - size = mine->end - mine->buffer; - if (size > mine->read_size) - size = mine->read_size; - memset(mine->copy_buff, 0xA5, mine->copy_buff_size); - memcpy(mine->copy_buff, mine->buffer, size); - *buff = mine->copy_buff; - - mine->buffer += size; - return ((ssize_t)size); -} - -/* - * How mean can a skip() routine be? Let's try to find out. - */ -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t -memory_read_skip(struct archive *a, void *client_data, size_t skip) -#else -static off_t -memory_read_skip(struct archive *a, void *client_data, off_t skip) -#endif -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - - (void)a; /* UNUSED */ - /* We can't skip by more than is available. */ - if ((off_t)skip > (off_t)(mine->end - mine->buffer)) - skip = mine->end - mine->buffer; - /* Always do small skips by prime amounts. */ - if (skip > 71) - skip = 71; - mine->buffer += skip; - return (skip); -} - -/* - * Close is just cleaning up our one small bit of data. - */ -static int -memory_read_close(struct archive *a, void *client_data) -{ - struct read_memory_data *mine = (struct read_memory_data *)client_data; - (void)a; /* UNUSED */ - free(mine->copy_buff); - free(mine); - return (ARCHIVE_OK); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test.h b/Utilities/cmlibarchive/libarchive/test/test.h deleted file mode 100644 index 6022f7e3d..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2003-2006 Tim Kientzle - * 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. - * - * $FreeBSD: src/lib/libarchive/test/test.h,v 1.10 2008/06/15 10:35:22 kientzle Exp $ - */ - -/* Every test program should #include "test.h" as the first thing. */ - -/* - * The goal of this file (and the matching test.c) is to - * simplify the very repetitive test-*.c test programs. - */ -#if defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "config.h" -#elif defined(__FreeBSD__) -/* Building as part of FreeBSD system requires a pre-built config.h. */ -#include "config_freebsd.h" -#elif defined(_WIN32) && !defined(__CYGWIN__) -/* Win32 can't run the 'configure' script. */ -#include "config_windows.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in test.h. -#endif - -#include /* Windows requires this before sys/stat.h */ -#include - -#ifdef USE_DMALLOC -#include -#endif -#if HAVE_DIRENT_H -#include -#else -#include -#define dirent direct -#endif -#include -#include -#ifdef HAVE_IO_H -#include -#endif -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_WINDOWS_H -#include -#endif - -/* - * System-specific tweaks. We really want to minimize these - * as much as possible, since they make it harder to understand - * the mainline code. - */ - -/* Windows (including Visual Studio and MinGW but not Cygwin) */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#define strdup _strdup -#define LOCALE_DE "deu" -#else -#define LOCALE_DE "de_DE.UTF-8" -#endif - -/* Visual Studio */ -#ifdef _MSC_VER -#define snprintf sprintf_s -#endif - -/* Cygwin */ -#if defined(__CYGWIN__) -/* Cygwin-1.7.x is lazy about populating nlinks, so don't - * expect it to be accurate. */ -# define NLINKS_INACCURATE_FOR_DIRS -#endif - -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Redefine DEFINE_TEST for use in defining the test functions. - */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); void name(void) - -/* An implementation of the standard assert() macro */ -#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) -/* chdir() and error if it fails */ -#define assertChdir(path) \ - assertion_chdir(__FILE__, __LINE__, path) -/* Assert two integers are the same. Reports value of each one if not. */ -#define assertEqualInt(v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* Assert two strings are the same. Reports value of each one if not. */ -#define assertEqualString(v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but v1 and v2 are wchar_t * */ -#define assertEqualWString(v1,v2) \ - assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but raw blocks of bytes. */ -#define assertEqualMem(v1, v2, l) \ - assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) -/* Assert two files are the same; allow printf-style expansion of second name. - * See below for comments about variable arguments here... - */ -#define assertEqualFile \ - assertion_setup(__FILE__, __LINE__);assertion_equal_file -/* Assert that a file is empty; supports printf-style arguments. */ -#define assertEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_empty_file -/* Assert that a file is not empty; supports printf-style arguments. */ -#define assertNonEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_non_empty_file -#define assertFileAtime(pathname, sec, nsec) \ - assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileAtimeRecent(pathname) \ - assertion_file_atime_recent(__FILE__, __LINE__, pathname) -#define assertFileBirthtime(pathname, sec, nsec) \ - assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileBirthtimeRecent(pathname) \ - assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_exists -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileNotExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_not_exists -/* Assert that file contents match a string; supports printf-style arguments. */ -#define assertFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_file_contents -#define assertFileMtime(pathname, sec, nsec) \ - assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileMtimeRecent(pathname) \ - assertion_file_mtime_recent(__FILE__, __LINE__, pathname) -#define assertFileNLinks(pathname, nlinks) \ - assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) -#define assertFileSize(pathname, size) \ - assertion_file_size(__FILE__, __LINE__, pathname, size) -#define assertTextFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_text_file_contents -#define assertIsDir(pathname, mode) \ - assertion_is_dir(__FILE__, __LINE__, pathname, mode) -#define assertIsHardlink(path1, path2) \ - assertion_is_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsNotHardlink(path1, path2) \ - assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsReg(pathname, mode) \ - assertion_is_reg(__FILE__, __LINE__, pathname, mode) -#define assertIsSymlink(pathname, contents) \ - assertion_is_symlink(__FILE__, __LINE__, pathname, contents) -/* Create a directory, report error if it fails. */ -#define assertMakeDir(dirname, mode) \ - assertion_make_dir(__FILE__, __LINE__, dirname, mode) -#define assertMakeFile(path, mode, contents) \ - assertion_make_file(__FILE__, __LINE__, path, mode, contents) -#define assertMakeHardlink(newfile, oldfile) \ - assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) -#define assertMakeSymlink(newfile, linkto) \ - assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) -#define assertUmask(mask) \ - assertion_umask(__FILE__, __LINE__, mask) - -/* - * This would be simple with C99 variadic macros, but I don't want to - * require that. Instead, I insert a function call before each - * skipping() call to pass the file and line information down. Crude, - * but effective. - */ -#define skipping \ - assertion_setup(__FILE__, __LINE__);test_skipping - -/* Function declarations. These are defined in test_utility.c. */ -void failure(const char *fmt, ...); -int assertion_assert(const char *, int, int, const char *, void *); -int assertion_chdir(const char *, int, const char *); -int assertion_empty_file(const char *, ...); -int assertion_equal_file(const char *, const char *, ...); -int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); -int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); -int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); -int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); -int assertion_file_atime(const char *, int, const char *, long, long); -int assertion_file_atime_recent(const char *, int, const char *); -int assertion_file_birthtime(const char *, int, const char *, long, long); -int assertion_file_birthtime_recent(const char *, int, const char *); -int assertion_file_contents(const void *, int, const char *, ...); -int assertion_file_exists(const char *, ...); -int assertion_file_mtime(const char *, int, const char *, long, long); -int assertion_file_mtime_recent(const char *, int, const char *); -int assertion_file_nlinks(const char *, int, const char *, int); -int assertion_file_not_exists(const char *, ...); -int assertion_file_size(const char *, int, const char *, long); -int assertion_is_dir(const char *, int, const char *, int); -int assertion_is_hardlink(const char *, int, const char *, const char *); -int assertion_is_not_hardlink(const char *, int, const char *, const char *); -int assertion_is_reg(const char *, int, const char *, int); -int assertion_is_symlink(const char *, int, const char *, const char *); -int assertion_make_dir(const char *, int, const char *, int); -int assertion_make_file(const char *, int, const char *, int, const char *); -int assertion_make_hardlink(const char *, int, const char *newpath, const char *); -int assertion_make_symlink(const char *, int, const char *newpath, const char *); -int assertion_non_empty_file(const char *, ...); -int assertion_text_file_contents(const char *buff, const char *f); -int assertion_umask(const char *, int, int); -void assertion_setup(const char *, int); - -void test_skipping(const char *fmt, ...); - -/* Like sprintf, then system() */ -int systemf(const char * fmt, ...); - -/* Delay until time() returns a value after this. */ -void sleepUntilAfter(time_t); - -/* Return true if this platform can create symlinks. */ -int canSymlink(void); - -/* Return true if this platform can run the "gzip" program. */ -int canGzip(void); - -/* Return true if this platform can run the "gunzip" program. */ -int canGunzip(void); - -/* Suck file into string allocated via malloc(). Call free() when done. */ -/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ -char *slurpfile(size_t *, const char *fmt, ...); - -/* Extracts named reference file to the current directory. */ -void extract_reference_file(const char *); - -/* - * Special interfaces for libarchive test harness. - */ - -#include "archive.h" -#include "archive_entry.h" - -/* Special customized read-from-memory interface. */ -int read_open_memory(struct archive *, void *, size_t, size_t); -/* "2" version exercises a slightly different set of libarchive APIs. */ -int read_open_memory2(struct archive *, void *, size_t, size_t); - -/* Versions of above that accept an archive argument for additional info. */ -#define assertA(e) assertion_assert(__FILE__, __LINE__, (e), #e, (a)) -#define assertEqualIntA(a,v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) -#define assertEqualStringA(a,v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (a)) diff --git a/Utilities/cmlibarchive/libarchive/test/test_acl_basic.c b/Utilities/cmlibarchive/libarchive/test/test_acl_basic.c deleted file mode 100644 index ba82f113e..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_acl_basic.c +++ /dev/null @@ -1,229 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_acl_basic.c,v 1.6 2008/10/19 00:13:57 kientzle Exp $"); - -/* - * Exercise the system-independent portion of the ACL support. - * Check that archive_entry objects can save and restore ACL data. - * - * This should work on all systems, regardless of whether local - * filesystems support ACLs or not. - */ - -struct acl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct acl_t acls0[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, -}; - -static struct acl_t acls1[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static struct acl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static void -set_acls(struct archive_entry *ae, struct acl_t *acls, int n) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; i < n; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) -{ - if (type != acl->type) - return (0); - if (permset != acl->permset) - return (0); - if (tag != acl->tag) - return (0); - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_OTHER) - return (1); - if (qual != acl->qual) - return (0); - if (name == NULL) { - if (acl->name == NULL || acl->name[0] == '\0') - return (1); - } - if (acl->name == NULL) { - if (name[0] == '\0') - return (1); - } - return (0 == strcmp(name, acl->name)); -} - -static void -compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) -{ - int *marker = malloc(sizeof(marker[0]) * n); - int i; - int r; - int type, permset, tag, qual; - int matched; - const char *name; - - for (i = 0; i < n; i++) - marker[i] = i; - - while (0 == (r = archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name))) { - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(&acls[marker[i]], type, permset, - tag, qual, name)) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { - if (!matched) printf("No match for user_obj perm\n"); - failure("USER_OBJ permset (%02o) != user mode (%02o)", - permset, 07 & (mode >> 6)); - assert((permset << 6) == (mode & 0700)); - } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { - if (!matched) printf("No match for group_obj perm\n"); - failure("GROUP_OBJ permset %02o != group mode %02o", - permset, 07 & (mode >> 3)); - assert((permset << 3) == (mode & 0070)); - } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { - if (!matched) printf("No match for other perm\n"); - failure("OTHER permset (%02o) != other mode (%02o)", - permset, mode & 07); - assert((permset << 0) == (mode & 0007)); - } else { - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - type, permset, tag, qual, name); - assert(matched == 1); - } - } -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Known broken before 1.9.0. */ - skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); -#else - assertEqualInt(ARCHIVE_EOF, r); -#endif - assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - acls[marker[0]].type, acls[marker[0]].permset, - acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); - assert(n == 0); /* Number of ACLs not matched should == 0 */ - free(marker); -} - -DEFINE_TEST(test_acl_basic) -{ - struct archive_entry *ae; - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0777); - - /* Basic owner/owning group should just update mode bits. */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - - /* With any extended ACL entry, we should read back a full set. */ - set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); - failure("One extended ACL should flag all ACLs to be returned."); - assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - - /* A more extensive set of ACLs. */ - set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); - assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); - failure("Basic ACLs should set mode to 0543, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0543); - - /* - * Check that clearing ACLs gets rid of them all by repeating - * the first test. - */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - archive_entry_free(ae); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_acl_freebsd.c b/Utilities/cmlibarchive/libarchive/test/test_acl_freebsd.c deleted file mode 100644 index 2a84d8f55..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_acl_freebsd.c +++ /dev/null @@ -1,255 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_acl_freebsd.c,v 1.2 2008/11/17 21:06:17 kientzle Exp $"); - -#if defined(__FreeBSD__) && __FreeBSD__ > 4 -#include - -struct myacl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct myacl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_READ | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_MASK, -1, "" }, - { 0, 0, 0, 0, NULL } -}; - -static void -set_acls(struct archive_entry *ae, struct myacl_t *acls) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; acls[i].name != NULL; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(acl_entry_t aclent, struct myacl_t *myacl) -{ - gid_t g, *gp; - uid_t u, *up; - acl_tag_t tag_type; - acl_permset_t opaque_ps; - int permset = 0; - - acl_get_tag_type(aclent, &tag_type); - - /* translate the silly opaque permset to a bitmap */ - acl_get_permset(aclent, &opaque_ps); - if (acl_get_perm_np(opaque_ps, ACL_EXECUTE)) - permset |= ARCHIVE_ENTRY_ACL_EXECUTE; - if (acl_get_perm_np(opaque_ps, ACL_WRITE)) - permset |= ARCHIVE_ENTRY_ACL_WRITE; - if (acl_get_perm_np(opaque_ps, ACL_READ)) - permset |= ARCHIVE_ENTRY_ACL_READ; - - if (permset != myacl->permset) - return (0); - - switch (tag_type) { - case ACL_USER_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER_OBJ) return (0); - break; - case ACL_USER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_USER) - return (0); - up = acl_get_qualifier(aclent); - u = *up; - acl_free(up); - if ((uid_t)myacl->qual != u) - return (0); - break; - case ACL_GROUP_OBJ: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP_OBJ) return (0); - break; - case ACL_GROUP: - if (myacl->tag != ARCHIVE_ENTRY_ACL_GROUP) - return (0); - gp = acl_get_qualifier(aclent); - g = *gp; - acl_free(gp); - if ((gid_t)myacl->qual != g) - return (0); - break; - case ACL_MASK: - if (myacl->tag != ARCHIVE_ENTRY_ACL_MASK) return (0); - break; - case ACL_OTHER: - if (myacl->tag != ARCHIVE_ENTRY_ACL_OTHER) return (0); - break; - } - return (1); -} - -static void -compare_acls(acl_t acl, struct myacl_t *myacls) -{ - int *marker; - int entry_id = ACL_FIRST_ENTRY; - int matched; - int i, n; - acl_entry_t acl_entry; - - /* Count ACL entries in myacls array and allocate an indirect array. */ - for (n = 0; myacls[n].name != NULL; ++n) - continue; - marker = malloc(sizeof(marker[0]) * n); - for (i = 0; i < n; i++) - marker[i] = i; - - /* - * Iterate over acls in system acl object, try to match each - * one with an item in the myacls array. - */ - while (1 == acl_get_entry(acl, entry_id, &acl_entry)) { - /* After the first time... */ - entry_id = ACL_NEXT_ENTRY; - - /* Search for a matching entry (tag and qualifier) */ - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(acl_entry, &myacls[marker[i]])) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - - /* TODO: Print out more details in this case. */ - failure("ACL entry on file that shouldn't be there"); - assert(matched == 1); - } - - /* Dump entries in the myacls array that weren't in the system acl. */ - for (i = 0; i < n; ++i) { - failure(" ACL entry missing from file: " - "type=%d,permset=%d,tag=%d,qual=%d,name=``%s''\n", - myacls[marker[i]].type, myacls[marker[i]].permset, - myacls[marker[i]].tag, myacls[marker[i]].qual, - myacls[marker[i]].name); - assert(0); /* Record this as a failure. */ - } - free(marker); -} - -#endif - - -/* - * Verify ACL restore-to-disk. This test is FreeBSD-specific. - */ - -DEFINE_TEST(test_acl_freebsd) -{ -#if !defined(__FreeBSD__) - skipping("FreeBSD-specific ACL restore test"); -#elif __FreeBSD__ < 5 - skipping("ACL restore supported only on FreeBSD 5.0 and later"); -#else - struct stat st; - struct archive *a; - struct archive_entry *ae; - int n, fd; - acl_t acl; - - /* - * First, do a quick manual set/read of ACL data to - * verify that the local filesystem does support ACLs. - * If it doesn't, we'll simply skip the remaining tests. - */ - acl = acl_from_text("u::rwx,u:1:rw,g::rwx,g:15:rx,o::rwx,m::rwx"); - assert((void *)acl != NULL); - /* Create a test file and try to set an ACL on it. */ - fd = open("pretest", O_WRONLY | O_CREAT | O_EXCL, 0777); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) { - acl_free(acl); - return; - } - - n = acl_set_fd(fd, acl); - acl_free(acl); - if (n != 0 && errno == EOPNOTSUPP) { - close(fd); - skipping("ACL tests require that ACL support be enabled on the filesystem"); - return; - } - failure("acl_set_fd(): errno = %d (%s)", - errno, strerror(errno)); - assertEqualInt(0, n); - close(fd); - - /* Create a write-to-disk object. */ - assert(NULL != (a = archive_write_disk_new())); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL); - - /* Populate an archive entry with some metadata, including ACL info */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test0"); - archive_entry_set_mtime(ae, 123456, 7890); - archive_entry_set_size(ae, 0); - set_acls(ae, acls2); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test0", &st)); - assertEqualInt(st.st_mtime, 123456); - acl = acl_get_file("test0", ACL_TYPE_ACCESS); - assert(acl != (acl_t)NULL); - compare_acls(acl, acls2); - acl_free(acl); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_acl_pax.c b/Utilities/cmlibarchive/libarchive/test/test_acl_pax.c deleted file mode 100644 index 1377c21db..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_acl_pax.c +++ /dev/null @@ -1,517 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_acl_pax.c,v 1.6 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Exercise the system-independent portion of the ACL support. - * Check that pax archive can save and restore ACL data. - * - * This should work on all systems, regardless of whether local - * filesystems support ACLs or not. - */ - -static unsigned char buff[16384]; - -static unsigned char reference[] = { -'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7',0,' ', -'x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10, -'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ', -'S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ', -'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','1','7','2', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','1', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'7','2',' ','S','C','H','I','L','Y','.','a','c','l','.', -'a','c','c','e','s','s','=','u','s','e','r',':',':','-','-','x',',','g','r', -'o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w','-', -',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7','7', -10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0',10,'1','6', -' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8',' ','S','C', -'H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ',0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0','0', -'0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6',0,' ','0', -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','2','4','3', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','7','5', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'1','1','3',' ','S','C','H','I','L','Y','.','a','c','l', -'.','a','c','c','e','s','s','=','u','s','e','r',':',':','r','-','x',',','g', -'r','o','u','p',':',':','r','-','-',',','o','t','h','e','r',':',':','-','w', -'x',',','u','s','e','r',':','u','s','e','r','7','7',':','r','-','-',':','7', -'7',',','u','s','e','r',':','u','s','e','r','7','8',':','-','-','-',':','7', -'8',',','g','r','o','u','p',':','g','r','o','u','p','7','8',':','r','w','x', -':','7','8',10,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=','0', -10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1','8', -' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,'0','0','0','5','4','3',' ',0,'0','0','0','0','0','0',' ',0,'0','0', -'0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','0', -'0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','1','3',0,' ', -'0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r', -0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,'P','a','x','H','e','a','d','e','r','/','f','i','l','e',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','6','2', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','1','7','6','7', -0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,'1','6',' ','S','C','H','I','L','Y','.','d','e','v','=', -'0',10,'1','6',' ','S','C','H','I','L','Y','.','i','n','o','=','0',10,'1', -'8',' ','S','C','H','I','L','Y','.','n','l','i','n','k','=','0',10,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'f','i','l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,'0','0','0','1','4','2',' ',0,'0','0','0','0','0','0',' ', -0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0','0','0','0','0','0', -' ','0','0','0','0','0','0','0','0','0','0','0',' ','0','1','0','0','0','6', -0,' ','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t', -'a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' ',0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - - -struct acl_t { - int type; /* Type of ACL: "access" or "default" */ - int permset; /* Permissions for this class of users. */ - int tag; /* Owner, User, Owning group, group, other, etc. */ - int qual; /* GID or UID of user/group, depending on tag. */ - const char *name; /* Name of user/group, depending on tag. */ -}; - -static struct acl_t acls0[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, 0, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, 0, "" }, -}; - -static struct acl_t acls1[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static struct acl_t acls2[] = { - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_EXECUTE | ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_USER, 77, "user77" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0, - ARCHIVE_ENTRY_ACL_USER, 78, "user78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_READ, - ARCHIVE_ENTRY_ACL_GROUP_OBJ, -1, "" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, 0007, - ARCHIVE_ENTRY_ACL_GROUP, 78, "group78" }, - { ARCHIVE_ENTRY_ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_WRITE | ARCHIVE_ENTRY_ACL_EXECUTE, - ARCHIVE_ENTRY_ACL_OTHER, -1, "" }, -}; - -static void -set_acls(struct archive_entry *ae, struct acl_t *acls, int n) -{ - int i; - - archive_entry_acl_clear(ae); - for (i = 0; i < n; i++) { - archive_entry_acl_add_entry(ae, - acls[i].type, acls[i].permset, acls[i].tag, acls[i].qual, - acls[i].name); - } -} - -static int -acl_match(struct acl_t *acl, int type, int permset, int tag, int qual, const char *name) -{ - if (type != acl->type) - return (0); - if (permset != acl->permset) - return (0); - if (tag != acl->tag) - return (0); - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) - return (1); - if (tag == ARCHIVE_ENTRY_ACL_OTHER) - return (1); - if (qual != acl->qual) - return (0); - if (name == NULL) - return (acl->name == NULL || acl->name[0] == '\0'); - if (acl->name == NULL) - return (name == NULL || name[0] == '\0'); - return (0 == strcmp(name, acl->name)); -} - -static void -compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode) -{ - int *marker = malloc(sizeof(marker[0]) * n); - int i; - int r; - int type, permset, tag, qual; - int matched; - const char *name; - - for (i = 0; i < n; i++) - marker[i] = i; - - while (0 == (r = archive_entry_acl_next(ae, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name))) { - for (i = 0, matched = 0; i < n && !matched; i++) { - if (acl_match(&acls[marker[i]], type, permset, - tag, qual, name)) { - /* We found a match; remove it. */ - marker[i] = marker[n - 1]; - n--; - matched = 1; - } - } - if (tag == ARCHIVE_ENTRY_ACL_USER_OBJ) { - if (!matched) printf("No match for user_obj perm\n"); - failure("USER_OBJ permset (%02o) != user mode (%02o)", - permset, 07 & (mode >> 6)); - assert((permset << 6) == (mode & 0700)); - } else if (tag == ARCHIVE_ENTRY_ACL_GROUP_OBJ) { - if (!matched) printf("No match for group_obj perm\n"); - failure("GROUP_OBJ permset %02o != group mode %02o", - permset, 07 & (mode >> 3)); - assert((permset << 3) == (mode & 0070)); - } else if (tag == ARCHIVE_ENTRY_ACL_OTHER) { - if (!matched) printf("No match for other perm\n"); - failure("OTHER permset (%02o) != other mode (%02o)", - permset, mode & 07); - assert((permset << 0) == (mode & 0007)); - } else { - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - type, permset, tag, qual, name); - assert(matched == 1); - } - } -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Known broken before 1.9.0. */ - skipping("archive_entry_acl_next() exits with ARCHIVE_EOF"); -#else - assertEqualInt(ARCHIVE_EOF, r); -#endif - assert((mode & 0777) == (archive_entry_mode(ae) & 0777)); - failure("Could not find match for ACL " - "(type=%d,permset=%d,tag=%d,qual=%d,name=``%s'')", - acls[marker[0]].type, acls[marker[0]].permset, - acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name); - assert(n == 0); /* Number of ACLs not matched should == 0 */ - free(marker); -} - -DEFINE_TEST(test_acl_pax) -{ - struct archive *a; - struct archive_entry *ae; - size_t used; - FILE *f; - - /* Write an archive to memory. */ - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Write a series of files to the archive with different ACL info. */ - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0777); - - /* Basic owner/owning group should just update mode bits. */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - assertA(0 == archive_write_header(a, ae)); - - /* With any extended ACL entry, we should read back a full set. */ - set_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0])); - assertA(0 == archive_write_header(a, ae)); - - - /* A more extensive set of ACLs. */ - set_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0])); - assertA(0 == archive_write_header(a, ae)); - - /* - * Check that clearing ACLs gets rid of them all by repeating - * the first test. - */ - set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0])); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Write out the data we generated to a file for manual inspection. */ - assert(NULL != (f = fopen("testout", "wb"))); - assertEqualInt(used, (size_t)fwrite(buff, 1, (unsigned int)used, f)); - fclose(f); - - /* Write out the reference data to a file for manual inspection. */ - assert(NULL != (f = fopen("reference", "wb"))); - assert(sizeof(reference) == fwrite(reference, 1, sizeof(reference), f)); - fclose(f); - - /* Assert that the generated data matches the built-in reference data.*/ - failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); - assertEqualMem(buff, reference, sizeof(reference)); - failure("Generated pax archive does not match reference; check 'testout' and 'reference' files."); - assertEqualInt((int)used, sizeof(reference)); - - /* Read back each entry and check that the ACL data is right. */ - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - /* First item has no ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Second item has a few ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("One extended ACL should flag all ACLs to be returned."); - assert(4 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls1, sizeof(acls1)/sizeof(acls1[0]), 0142); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Third item has pretty extensive ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualInt(6, archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - compare_acls(ae, acls2, sizeof(acls2)/sizeof(acls2[0]), 0543); - failure("Basic ACLs should set mode to 0543, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0543); - - /* Fourth item has no ACLs */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("Basic ACLs shouldn't be stored as extended ACLs"); - assert(0 == archive_entry_acl_reset(ae, ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - failure("Basic ACLs should set mode to 0142, not %04o", - archive_entry_mode(ae)&0777); - assert((archive_entry_mode(ae) & 0777) == 0142); - - /* Close the archive. */ - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_archive_api_feature.c b/Utilities/cmlibarchive/libarchive/test/test_archive_api_feature.c deleted file mode 100644 index ad842543e..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_archive_api_feature.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_archive_api_feature.c,v 1.5 2008/05/26 17:00:24 kientzle Exp $"); - -DEFINE_TEST(test_archive_api_feature) -{ - char buff[128]; - const char *p; - - /* This is the (hopefully) final versioning API. */ - assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number()); - sprintf(buff, "libarchive %d.%d.%d", - archive_version_number() / 1000000, - (archive_version_number() / 1000) % 1000, - archive_version_number() % 1000); - failure("Version string is: %s, computed is: %s", - archive_version_string(), buff); - assert(memcmp(buff, archive_version_string(), strlen(buff)) == 0); - if (strlen(buff) < strlen(archive_version_string())) { - p = archive_version_string() + strlen(buff); - failure("Version string is: %s", archive_version_string()); - assert(*p == 'a' || *p == 'b' || *p == 'c' || *p == 'd'); - ++p; - failure("Version string is: %s", archive_version_string()); - assert(*p == '\0'); - } - -/* This is all scheduled to disappear in libarchive 3.0 */ -#if ARCHIVE_VERSION_NUMBER < 3000000 - assertEqualInt(ARCHIVE_VERSION_STAMP, ARCHIVE_VERSION_NUMBER); - assertEqualInt(ARCHIVE_API_FEATURE, archive_api_feature()); - assertEqualInt(ARCHIVE_API_VERSION, archive_api_version()); - /* - * Even though ARCHIVE_VERSION_STAMP only appears in - * archive.h after 1.9.0 and 2.2.3, the macro is synthesized - * in test.h, so this test is always valid. - */ - assertEqualInt(ARCHIVE_VERSION_STAMP / 1000, ARCHIVE_API_VERSION * 1000 + ARCHIVE_API_FEATURE); - /* - * The function, however, isn't always available. It appeared - * sometime in the middle of 2.2.3, but the synthesized value - * never has a release version, so the following conditional - * exactly determines whether the current library has the - * function. - */ -#if ARCHIVE_VERSION_STAMP / 1000 == 1009 || ARCHIVE_VERSION_STAMP > 2002000 - assertEqualInt(ARCHIVE_VERSION_STAMP, archive_version_stamp()); -#else - skipping("archive_version_stamp()"); -#endif - assertEqualString(ARCHIVE_LIBRARY_VERSION, archive_version()); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_bad_fd.c b/Utilities/cmlibarchive/libarchive/test/test_bad_fd.c deleted file mode 100644 index 0bcfa6977..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_bad_fd.c +++ /dev/null @@ -1,41 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_bad_fd.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -/* Verify that attempting to open an invalid fd returns correct error. */ -DEFINE_TEST(test_bad_fd) -{ - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(ARCHIVE_FATAL == archive_read_open_fd(a, -1, 1024)); - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2.c b/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2.c deleted file mode 100644 index 810b044fd..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2.c +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Verify our ability to read sample files compatibly with bunzip2. - * - * In particular: - * * bunzip2 will read multiple bzip2 streams, concatenating the output - * * bunzip2 will stop at the end of a stream if the following data - * doesn't start with a bzip2 signature. - */ - -/* - * All of the sample files have the same contents; they're just - * compressed in different ways. - */ -static void -compat_bzip2(const char *name) -{ - const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; - struct archive_entry *ae; - struct archive *a; - int i; - - assert((a = archive_read_new()) != NULL); - if (ARCHIVE_OK != archive_read_support_compression_bzip2(a)) { - skipping("Unsupported bzip2"); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - /* Read entries, match up names with list above. */ - for (i = 0; i < 6; ++i) { - failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(n[i], archive_entry_pathname(ae)); - } - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualString(archive_compression_name(a), "bzip2"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - -DEFINE_TEST(test_compat_bzip2) -{ - compat_bzip2("test_compat_bzip2_1.tbz"); - compat_bzip2("test_compat_bzip2_2.tbz"); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_1.tbz.uu b/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_1.tbz.uu deleted file mode 100644 index ffdce8867..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_1.tbz.uu +++ /dev/null @@ -1,24 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_compat_bzip2_1.tbz.uu,v 1.1 2008/12/06 07:08:08 kientzle Exp $ - -begin 644 test_compat_bzip2_1.tbz -M0EIH.3%!62936;12^)(``#-;D=$00`!_@``!8RT>$`0`$```""``5#5/*'J> -MD#(&30_5!H4_5-ZH`T``327U4@&L('"(9-%8<7&$I,`:7FXH+*\GV#JF<`PK29-8'OPDG36S\7HR&C(T:/U0:$U'I -MJ!ZC0`#VECO\[$10H'-Z@F*:6A1$H$V("2G0Q(U0(8=(7AK$S04#!)RXOAP% -MP:D%#Q;NO)\4UL23'2[\7````6YC1 -M$$`$?X```6,M'A`$`!````@@`'4-4S*,U!HT!HT?J@T)E-I--!H`![60EIH.3%!629364RNM^,```#?L-$00`#_@`0```AG -M+1X0`!`$```((`!U#5-,:1IH`TT,1^J#)&H]3U`T``!CX[_.[`F40.64EC"D -M()+?KX6,VP?6Y;F%5$XR[Y/D#*9),K3^+N2*<*$@9@ -MX6(`0EIH.3%!62936>ZM4*4```);D-$00`#O@``(9ST>$`0```@@`'0:IFC2 -M&F@!B:/U0:$R&H:&@`"KS^U=Y`BC`#FY2*9-8%%&13E$@%8ZF(&J!##]!#E` -MKVL'2LUW2.*C08`$)::#DQ05DF -?4UDI/)=P````0!!```0`(``A`(*#%W)%.%"0*3R7<``` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_2.tbz.uu b/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_2.tbz.uu deleted file mode 100644 index e307e4e61..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_bzip2_2.tbz.uu +++ /dev/null @@ -1,11 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_compat_bzip2_2.tbz.uu,v 1.1 2008/12/06 07:08:08 kientzle Exp $ - -begin 644 test_compat_bzip2_2.tbz -M0EIH.3%!629361HI1P<``4#;D-$00`#_@``)9RT>$`0``!@P`/@#&$Q,F`F` -M`,83$R8"8``1133"1/2-J-#$/U3@;XVF9V'`Y3882XA$*KO6\WTL`]QU&J"8 -M$-=*Q$\@=`=QJ,TQ;3UH,NPT$-(!"HV&!ZO5D&@P-1D&1@'L<8&209QV9'G` -MW&PRZ0Q(-BT%&DG*DE.!U*#J.P]*#%-P9G`W9+34:#S&M`;@^1R^![C]:Y)U -MDF9/(\AR/@?P@^@I_B[DBG"A(#12C@X!3;VUE(&UOV=QL!06ER26`1T2G9F:EY)54XJ -MN>9`/*(`IX<(2#/D&F@GC`(Z``#S57',@'E&`TT,$I!EQ -M#;031@$5`0`Q!<\4Z`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A$0!3@\1D&;,-=!.&`5D``#7L]HO -MZ`,``!^+"`B8OB))``-T97-T+7-P;&ET+G1A57',@'E&`TT,$I!ER#;031@$>``"Y*#OBZ`,``!^+"`B8 -MOB))``-T97-T+7-P;&ET+G1A@ALXPP`]CXF=Q&A<:-UX>EN)C5M,AL;P -MO@V[0A=_.E39F2.B'*.?5QX2?Z\?XGE&27)F]L0)V>E_'7YY07\>OZ)Y1W6Q\!-J3!?H^Z_J7TG]%_"QK0?\]4[/>HZS^_^T\! -M_;>@@OY[=N2]6E\!JOH/P])_2OC^-X'YOV]+_]97@*K^A4K_C/Y;P/S?MZ5_ -MZRM`7?]<^L?_OR8P_P,`].D%,XR2*0`<``!4:&ES(&ES('5N#HW,2QU#HQ,#`P+&=R;W5P.CIR+2TL;6%S:SIR+69I;&4M=VET:"UP -M;W-I>"UA8VQS```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````P -M,#`P-C0T`#`P,#$W-3``,#`P,#`P,``P,#`P,#`P,#`P,``Q,3$W-#8P-#$U -M-P`P,#$U,30T`#`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````=7-T87(`,#!T@`````````````` -M`````````````````````')O;W0````````````````````````````````` -M````,#`P,#(Q,``P,#`P,#$P```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -H```````````````````````````````````````````````````````` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink.c b/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink.c deleted file mode 100644 index 1975b5513..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_compat_tar_hardlink.c,v 1.3 2008/08/11 01:19:36 kientzle Exp $"); - -/* - * Background: There are two written standards for the tar file format. - * The first is the POSIX 1988 "ustar" format, the second is the 2001 - * "pax extended" format that builds on the "ustar" format by adding - * support for generic additional attributes. Buried in the details - * is one frustrating incompatibility: The 1988 standard says that - * tar readers MUST ignore the size field on hardlink entries; the - * 2001 standard says that tar readers MUST obey the size field on - * hardlink entries. libarchive tries to navigate this particular - * minefield by using auto-detect logic to guess whether it should - * or should not obey the size field. - * - * This test tries to probe the boundaries of such handling; the test - * archives here were adapted from real archives created by real - * tar implementations that are (as of early 2008) apparently still - * in use. - */ - -static void -test_compat_tar_hardlink_1(void) -{ - char name[] = "test_compat_tar_hardlink_1.tar"; - struct archive_entry *ae; - struct archive *a; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); - - /* Read first entry, which is a regular file. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("xmcd-3.3.2/docs_d/READMf", - archive_entry_pathname(ae)); - assertEqualString(NULL, archive_entry_hardlink(ae)); - assertEqualInt(321, archive_entry_size(ae)); - assertEqualInt(1082575645, archive_entry_mtime(ae)); - assertEqualInt(1851, archive_entry_uid(ae)); - assertEqualInt(3, archive_entry_gid(ae)); - assertEqualInt(0100444, archive_entry_mode(ae)); - - /* Read second entry, which is a hard link at the end of archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("xmcd-3.3.2/README", - archive_entry_pathname(ae)); - assertEqualString( - "xmcd-3.3.2/docs_d/READMf", - archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1082575645, archive_entry_mtime(ae)); - assertEqualInt(1851, archive_entry_uid(ae)); - assertEqualInt(3, archive_entry_gid(ae)); - assertEqualInt(0100444, archive_entry_mode(ae)); - - /* Verify the end-of-archive. */ - /* - * This failed in libarchive 2.4.12 because the tar reader - * tried to obey the size field for the hard link and ended - * up running past the end of the file. - */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_compat_tar_hardlink) -{ - test_compat_tar_hardlink_1(); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink_1.tar.uu b/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink_1.tar.uu deleted file mode 100644 index 95dba54c2..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_tar_hardlink_1.tar.uu +++ /dev/null @@ -1,39 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_compat_tar_hardlink_1.tar.uu,v 1.1 2008/01/31 07:47:38 kientzle Exp $ -begin 644 test_compat_tar_hardlink_1.tar -M>&UC9"TS+C,N,B]D;V-S7V0O4D5!1$UF```````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"`@(#0T-"``("`S-#'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'AX -M>'AX>'AX>'AX>'AX>'AX>'AX>'AX>'@````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````'AM8V0M,RXS+C(O -M4D5!1$U%```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````@ -M("`T-#0@`"`@,S0W,R``("`@("`S(``@("`@("`@(#4P,2`Q,#`T,34T-30S -M-2`@,3(R,#<`(#%X;6-D+3,N,RXR+V1O8W-?9"]214%$368````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -&```````` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_xz.c b/Utilities/cmlibarchive/libarchive/test/test_compat_xz.c deleted file mode 100644 index 3475007ac..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_xz.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Verify our ability to read sample files compatibly with unxz. - * - * In particular: - * * unxz will read multiple xz streams, concatenating the output - */ - -/* - * All of the sample files have the same contents; they're just - * compressed in different ways. - */ -static void -compat_xz(const char *name) -{ - const char *n[7] = { "f1", "f2", "f3", "d1/f1", "d1/f2", "d1/f3", NULL }; - struct archive_entry *ae; - struct archive *a; - int i, r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 2)); - - /* Read entries, match up names with list above. */ - for (i = 0; i < 6; ++i) { - failure("Could not read file %d (%s) from %s", i, n[i], name); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualString(n[i], archive_entry_pathname(ae)); - } - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); - assertEqualString(archive_compression_name(a), "xz"); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - -DEFINE_TEST(test_compat_xz) -{ - compat_xz("test_compat_xz_1.txz"); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_compat_xz_1.txz.uu b/Utilities/cmlibarchive/libarchive/test/test_compat_xz_1.txz.uu deleted file mode 100644 index ea5d1e54d..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_compat_xz_1.txz.uu +++ /dev/null @@ -1,12 +0,0 @@ -begin 644 test_compat_gzip_1.txz -M_3=Z6%H```3FUK1&`@`A`18```!T+^6CX`^?`(-=`#,,/!NGC#0&C6L"2_R2 -M/O9*^(7KX=WM^(=KA(RH"\09$$)!Q_+JUHQ*`]R;ITL_F3/I6:^Q0550A&)B -MHS@=K]7@K1-9FOIP#PU!I?E5&IHH&Q=N>_C&G -M-$G]+L[\,B<7%8&$NO5K31*Y>"D^*ZG,Z=H```"KU50H$1^1S``!GP&@'P`` -MLZ042+'$9_L"``````196OTW>EA:```$YM:T1@(`(0$6````="_EH^`,7P!I -M70``;IBIKOMK%/A?-TZV0266G?2,[/?\,JE6` -M__C/SA[W1?*2J9Z!O$&YKI)!H8*&L&E>0J^FIJ\7+Q<`%!+!PAHTY\490```'$```!02P,$%``(``@`"(2# -M-P````````````````D```!T;7`N8VQA"%3```%!+!P@+ -M(*8V:````'8```!02P$"%``4``@`"``(A(,W:-.?%&4```!Q````%``````` -M````````````````345402U)3D8O34%.249%4U0N34902P$"%``4``@`"``( -MA(,W"R"F-F@```!V````"0````````````````"G````=&UP+F-L87-S4$L% -J!@`````"``(`>0```$8!```7`%!R;T=U87)D+"!V97)S:6]N(#0N,"XQ -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_empty_write.c b/Utilities/cmlibarchive/libarchive/test/test_empty_write.c deleted file mode 100644 index 8a0069ca8..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_empty_write.c +++ /dev/null @@ -1,120 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_empty_write.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -DEFINE_TEST(test_empty_write) -{ - char buff[32768]; - struct archive_entry *ae; - struct archive *a; - size_t used; - int r; - - /* - * Exercise a zero-byte write to a gzip-compressed archive. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_gzip(a); - if (r == ARCHIVE_FATAL) { - skipping("Empty write to gzip-compressed archive"); - } else { - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - /* This used to crash. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - } - - /* - * Again, with bzip2 compression. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_bzip2(a); - if (r == ARCHIVE_FATAL) { - skipping("Empty write to bzip2-compressed archive"); - } else { - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - } - - /* - * For good measure, one more time with no compression. - */ - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - /* Write a file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 0); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* THE TEST: write zero bytes to this entry. */ - assertEqualIntA(a, 0, archive_write_data(a, "", 0)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_entry.c b/Utilities/cmlibarchive/libarchive/test/test_entry.c deleted file mode 100644 index d8361bae8..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_entry.c +++ /dev/null @@ -1,890 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_entry.c,v 1.10 2008/09/30 04:13:21 kientzle Exp $"); - -#include - -/* - * Most of these tests are system-independent, though a few depend on - * features of the local system. Such tests are conditionalized on - * the platform name. On unsupported platforms, only the - * system-independent features will be tested. - * - * No, I don't want to use config.h in the test files because I want - * the tests to also serve as a check on the correctness of config.h. - * A mis-configured library build should cause tests to fail. - */ - -DEFINE_TEST(test_entry) -{ - char buff[128]; - wchar_t wbuff[128]; - struct stat st; - struct archive_entry *e, *e2; - const struct stat *pst; - unsigned long set, clear; /* For fflag testing. */ - int type, permset, tag, qual; /* For ACL testing. */ - const char *name; /* For ACL testing. */ - const char *xname; /* For xattr tests. */ - const void *xval; /* For xattr tests. */ - size_t xsize; /* For xattr tests. */ - int c; - wchar_t wc; - long l; - - assert((e = archive_entry_new()) != NULL); - - /* - * Verify that the AE_IF* defines match S_IF* defines - * on this platform. See comments in archive_entry.h. - */ -#ifdef S_IFREG - assertEqualInt(S_IFREG, AE_IFREG); -#endif -#ifdef S_IFLNK - assertEqualInt(S_IFLNK, AE_IFLNK); -#endif -#ifdef S_IFSOCK - assertEqualInt(S_IFSOCK, AE_IFSOCK); -#endif -#ifdef S_IFCHR - assertEqualInt(S_IFCHR, AE_IFCHR); -#endif -#ifdef S_IFBLK - assertEqualInt(S_IFBLK, AE_IFBLK); -#endif -#ifdef S_IFDIR - assertEqualInt(S_IFDIR, AE_IFDIR); -#endif -#ifdef S_IFIFO - assertEqualInt(S_IFIFO, AE_IFIFO); -#endif - - /* - * Basic set/read tests for all fields. - * We should be able to set any field and read - * back the same value. - * - * For methods that "copy" a string, we should be able - * to overwrite the original passed-in string without - * changing the value in the entry. - * - * The following tests are ordered alphabetically by the - * name of the field. - */ - - /* atime */ - archive_entry_set_atime(e, 13579, 24680); - assertEqualInt(archive_entry_atime(e), 13579); - assertEqualInt(archive_entry_atime_nsec(e), 24680); - archive_entry_unset_atime(e); - assertEqualInt(archive_entry_atime(e), 0); - assertEqualInt(archive_entry_atime_nsec(e), 0); - assert(!archive_entry_atime_is_set(e)); - - /* birthtime */ - archive_entry_set_birthtime(e, 17579, 24990); - assertEqualInt(archive_entry_birthtime(e), 17579); - assertEqualInt(archive_entry_birthtime_nsec(e), 24990); - archive_entry_unset_birthtime(e); - assertEqualInt(archive_entry_birthtime(e), 0); - assertEqualInt(archive_entry_birthtime_nsec(e), 0); - assert(!archive_entry_birthtime_is_set(e)); - - /* ctime */ - archive_entry_set_ctime(e, 13580, 24681); - assertEqualInt(archive_entry_ctime(e), 13580); - assertEqualInt(archive_entry_ctime_nsec(e), 24681); - archive_entry_unset_ctime(e); - assertEqualInt(archive_entry_ctime(e), 0); - assertEqualInt(archive_entry_ctime_nsec(e), 0); - assert(!archive_entry_ctime_is_set(e)); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* dev */ - archive_entry_set_dev(e, 235); - assertEqualInt(archive_entry_dev(e), 235); -#else - skipping("archive_entry_dev()"); -#endif - /* devmajor/devminor are tested specially below. */ - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* filetype */ - archive_entry_set_filetype(e, AE_IFREG); - assertEqualInt(archive_entry_filetype(e), AE_IFREG); -#else - skipping("archive_entry_filetype()"); -#endif - - /* fflags are tested specially below */ - - /* gid */ - archive_entry_set_gid(e, 204); - assertEqualInt(archive_entry_gid(e), 204); - - /* gname */ - archive_entry_set_gname(e, "group"); - assertEqualString(archive_entry_gname(e), "group"); - wcscpy(wbuff, L"wgroup"); - archive_entry_copy_gname_w(e, wbuff); - assertEqualWString(archive_entry_gname_w(e), L"wgroup"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_gname_w(e), L"wgroup"); - - /* hardlink */ - archive_entry_set_hardlink(e, "hardlinkname"); - assertEqualString(archive_entry_hardlink(e), "hardlinkname"); - strcpy(buff, "hardlinkname2"); - archive_entry_copy_hardlink(e, buff); - assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_hardlink(e), "hardlinkname2"); - archive_entry_copy_hardlink(e, NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualWString(archive_entry_hardlink_w(e), NULL); - wcscpy(wbuff, L"whardlink"); - archive_entry_copy_hardlink_w(e, wbuff); - assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_hardlink_w(e), L"whardlink"); - archive_entry_copy_hardlink_w(e, NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualWString(archive_entry_hardlink_w(e), NULL); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* ino */ - archive_entry_set_ino(e, 8593); - assertEqualInt(archive_entry_ino(e), 8593); -#else - skipping("archive_entry_ino()"); -#endif - - /* link */ - archive_entry_set_hardlink(e, "hardlinkname"); - archive_entry_set_symlink(e, NULL); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), "link"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_link(e, "link2"); - assertEqualString(archive_entry_hardlink(e), "link2"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_link_w(e, L"link3"); - assertEqualString(archive_entry_hardlink(e), "link3"); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_set_hardlink(e, NULL); - archive_entry_set_symlink(e, "symlink"); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link"); - archive_entry_copy_link(e, "link2"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link2"); - archive_entry_copy_link_w(e, L"link3"); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualString(archive_entry_symlink(e), "link3"); - /* Arbitrarily override symlink if both hardlink and symlink set. */ - archive_entry_set_hardlink(e, "hardlink"); - archive_entry_set_symlink(e, "symlink"); - archive_entry_set_link(e, "link"); - assertEqualString(archive_entry_hardlink(e), "hardlink"); - assertEqualString(archive_entry_symlink(e), "link"); - - /* mode */ - archive_entry_set_mode(e, 0123456); - assertEqualInt(archive_entry_mode(e), 0123456); - - /* mtime */ - archive_entry_set_mtime(e, 13581, 24682); - assertEqualInt(archive_entry_mtime(e), 13581); - assertEqualInt(archive_entry_mtime_nsec(e), 24682); - archive_entry_unset_mtime(e); - assertEqualInt(archive_entry_mtime(e), 0); - assertEqualInt(archive_entry_mtime_nsec(e), 0); - assert(!archive_entry_mtime_is_set(e)); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* nlink */ - archive_entry_set_nlink(e, 736); - assertEqualInt(archive_entry_nlink(e), 736); -#else - skipping("archive_entry_nlink()"); -#endif - - /* pathname */ - archive_entry_set_pathname(e, "path"); - assertEqualString(archive_entry_pathname(e), "path"); - archive_entry_set_pathname(e, "path"); - assertEqualString(archive_entry_pathname(e), "path"); - strcpy(buff, "path2"); - archive_entry_copy_pathname(e, buff); - assertEqualString(archive_entry_pathname(e), "path2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_pathname(e), "path2"); - wcscpy(wbuff, L"wpath"); - archive_entry_copy_pathname_w(e, wbuff); - assertEqualWString(archive_entry_pathname_w(e), L"wpath"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_pathname_w(e), L"wpath"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - /* rdev */ - archive_entry_set_rdev(e, 532); - assertEqualInt(archive_entry_rdev(e), 532); -#else - skipping("archive_entry_rdev()"); -#endif - /* rdevmajor/rdevminor are tested specially below. */ - - /* size */ - archive_entry_set_size(e, 987654321); - assertEqualInt(archive_entry_size(e), 987654321); - archive_entry_unset_size(e); - assertEqualInt(archive_entry_size(e), 0); - assert(!archive_entry_size_is_set(e)); - - /* sourcepath */ - archive_entry_copy_sourcepath(e, "path1"); - assertEqualString(archive_entry_sourcepath(e), "path1"); - - /* symlink */ - archive_entry_set_symlink(e, "symlinkname"); - assertEqualString(archive_entry_symlink(e), "symlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - strcpy(buff, "symlinkname2"); - archive_entry_copy_symlink(e, buff); - assertEqualString(archive_entry_symlink(e), "symlinkname2"); - memset(buff, 0, sizeof(buff)); - assertEqualString(archive_entry_symlink(e), "symlinkname2"); -#endif - archive_entry_copy_symlink_w(e, NULL); - assertEqualWString(archive_entry_symlink_w(e), NULL); - assertEqualString(archive_entry_symlink(e), NULL); - archive_entry_copy_symlink_w(e, L"wsymlink"); - assertEqualWString(archive_entry_symlink_w(e), L"wsymlink"); - archive_entry_copy_symlink(e, NULL); - assertEqualWString(archive_entry_symlink_w(e), NULL); - assertEqualString(archive_entry_symlink(e), NULL); - - /* uid */ - archive_entry_set_uid(e, 83); - assertEqualInt(archive_entry_uid(e), 83); - - /* uname */ - archive_entry_set_uname(e, "user"); - assertEqualString(archive_entry_uname(e), "user"); - wcscpy(wbuff, L"wuser"); - archive_entry_copy_gname_w(e, wbuff); - assertEqualWString(archive_entry_gname_w(e), L"wuser"); - memset(wbuff, 0, sizeof(wbuff)); - assertEqualWString(archive_entry_gname_w(e), L"wuser"); - - /* Test fflags interface. */ - archive_entry_set_fflags(e, 0x55, 0xAA); - archive_entry_fflags(e, &set, &clear); - failure("Testing set/get of fflags data."); - assertEqualInt(set, 0x55); - failure("Testing set/get of fflags data."); - assertEqualInt(clear, 0xAA); -#ifdef __FreeBSD__ - /* Converting fflags bitmap to string is currently system-dependent. */ - /* TODO: Make this system-independent. */ - assertEqualString(archive_entry_fflags_text(e), - "uappnd,nouchg,nodump,noopaque,uunlnk"); - /* Test archive_entry_copy_fflags_text_w() */ - archive_entry_copy_fflags_text_w(e, L" ,nouappnd, nouchg, dump,uunlnk"); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(16, set); - assertEqualInt(7, clear); - /* Test archive_entry_copy_fflags_text() */ - archive_entry_copy_fflags_text(e, " ,nouappnd, nouchg, dump,uunlnk"); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(16, set); - assertEqualInt(7, clear); -#endif - - /* See test_acl_basic.c for tests of ACL set/get consistency. */ - - /* Test xattrs set/get consistency. */ - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); - assertEqualInt(1, archive_entry_xattr_reset(e)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, "xattr1"); - assertEqualString(xval, "xattrvalue1"); - assertEqualInt((int)xsize, 12); - assertEqualInt(1, archive_entry_xattr_count(e)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - archive_entry_xattr_clear(e); - assertEqualInt(0, archive_entry_xattr_reset(e)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue1", 12); - assertEqualInt(1, archive_entry_xattr_reset(e)); - archive_entry_xattr_add_entry(e, "xattr2", "xattrvalue2", 12); - assertEqualInt(2, archive_entry_xattr_reset(e)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualInt(0, archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); - - - /* - * Test clone() implementation. - */ - - /* Set values in 'e' */ - archive_entry_clear(e); - archive_entry_set_atime(e, 13579, 24680); - archive_entry_set_birthtime(e, 13779, 24990); - archive_entry_set_ctime(e, 13580, 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 235); -#endif - archive_entry_set_fflags(e, 0x55, 0xAA); - archive_entry_set_gid(e, 204); - archive_entry_set_gname(e, "group"); - archive_entry_set_hardlink(e, "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 8593); -#endif - archive_entry_set_mode(e, 0123456); - archive_entry_set_mtime(e, 13581, 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 736); -#endif - archive_entry_set_pathname(e, "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_rdev(e, 532); -#endif - archive_entry_set_size(e, 987654321); - archive_entry_copy_sourcepath(e, "source"); - archive_entry_set_symlink(e, "symlinkname"); - archive_entry_set_uid(e, 83); - archive_entry_set_uname(e, "user"); - /* Add an ACL entry. */ - archive_entry_acl_add_entry(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - ARCHIVE_ENTRY_ACL_READ, ARCHIVE_ENTRY_ACL_USER, 77, "user77"); - /* Add an extended attribute. */ - archive_entry_xattr_add_entry(e, "xattr1", "xattrvalue", 11); - - /* Make a clone. */ - e2 = archive_entry_clone(e); - - /* Clone should have same contents. */ - assertEqualInt(archive_entry_atime(e2), 13579); - assertEqualInt(archive_entry_atime_nsec(e2), 24680); - assertEqualInt(archive_entry_birthtime(e2), 13779); - assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); - assertEqualInt(archive_entry_ctime(e2), 13580); - assertEqualInt(archive_entry_ctime_nsec(e2), 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_dev(e2), 235); -#endif - archive_entry_fflags(e, &set, &clear); - assertEqualInt(clear, 0xAA); - assertEqualInt(set, 0x55); - assertEqualInt(archive_entry_gid(e2), 204); - assertEqualString(archive_entry_gname(e2), "group"); - assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_ino(e2), 8593); -#endif - assertEqualInt(archive_entry_mode(e2), 0123456); - assertEqualInt(archive_entry_mtime(e2), 13581); - assertEqualInt(archive_entry_mtime_nsec(e2), 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e2), 736); -#endif - assertEqualString(archive_entry_pathname(e2), "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_rdev(e2), 532); -#endif - assertEqualInt(archive_entry_size(e2), 987654321); - assertEqualString(archive_entry_sourcepath(e2), "source"); - assertEqualString(archive_entry_symlink(e2), "symlinkname"); - assertEqualInt(archive_entry_uid(e2), 83); - assertEqualString(archive_entry_uname(e2), "user"); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ACL preserved by archive_entry_clone()"); -#else - /* Verify ACL was copied. */ - assertEqualInt(4, c = archive_entry_acl_reset(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - /* First three are standard permission bits. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 4); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 5); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 6); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - /* Fourth is custom one. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); - assertEqualInt(qual, 77); - assertEqualString(name, "user77"); -#endif -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("xattr data preserved by archive_entry_clone"); -#else - /* Verify xattr was copied. */ - assertEqualInt(1, c = archive_entry_xattr_reset(e2)); - assertEqualInt(0, archive_entry_xattr_next(e2, &xname, &xval, &xsize)); - assertEqualString(xname, "xattr1"); - assertEqualString(xval, "xattrvalue"); - assertEqualInt((int)xsize, 11); - assertEqualInt(ARCHIVE_WARN, - archive_entry_xattr_next(e2, &xname, &xval, &xsize)); - assertEqualString(xname, NULL); - assertEqualString(xval, NULL); - assertEqualInt((int)xsize, 0); -#endif - - /* Change the original */ - archive_entry_set_atime(e, 13580, 24690); - archive_entry_set_birthtime(e, 13980, 24999); - archive_entry_set_ctime(e, 13590, 24691); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 245); -#endif - archive_entry_set_fflags(e, 0x85, 0xDA); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_filetype(e, AE_IFLNK); -#endif - archive_entry_set_gid(e, 214); - archive_entry_set_gname(e, "grouper"); - archive_entry_set_hardlink(e, "hardlinkpath"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 8763); -#endif - archive_entry_set_mode(e, 0123654); - archive_entry_set_mtime(e, 18351, 28642); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 73); -#endif - archive_entry_set_pathname(e, "pathest"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_rdev(e, 132); -#endif - archive_entry_set_size(e, 987456321); - archive_entry_copy_sourcepath(e, "source2"); - archive_entry_set_symlink(e, "symlinkpath"); - archive_entry_set_uid(e, 93); - archive_entry_set_uname(e, "username"); - archive_entry_acl_clear(e); - archive_entry_xattr_clear(e); - - /* Clone should still have same contents. */ - assertEqualInt(archive_entry_atime(e2), 13579); - assertEqualInt(archive_entry_atime_nsec(e2), 24680); - assertEqualInt(archive_entry_birthtime(e2), 13779); - assertEqualInt(archive_entry_birthtime_nsec(e2), 24990); - assertEqualInt(archive_entry_ctime(e2), 13580); - assertEqualInt(archive_entry_ctime_nsec(e2), 24681); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_dev(e2), 235); -#endif - archive_entry_fflags(e2, &set, &clear); - assertEqualInt(clear, 0xAA); - assertEqualInt(set, 0x55); - assertEqualInt(archive_entry_gid(e2), 204); - assertEqualString(archive_entry_gname(e2), "group"); - assertEqualString(archive_entry_hardlink(e2), "hardlinkname"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_ino(e2), 8593); -#endif - assertEqualInt(archive_entry_mode(e2), 0123456); - assertEqualInt(archive_entry_mtime(e2), 13581); - assertEqualInt(archive_entry_mtime_nsec(e2), 24682); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e2), 736); -#endif - assertEqualString(archive_entry_pathname(e2), "path"); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_rdev(e2), 532); -#endif - assertEqualInt(archive_entry_size(e2), 987654321); - assertEqualString(archive_entry_sourcepath(e2), "source"); - assertEqualString(archive_entry_symlink(e2), "symlinkname"); - assertEqualInt(archive_entry_uid(e2), 83); - assertEqualString(archive_entry_uname(e2), "user"); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ACL held by clone of archive_entry"); -#else - /* Verify ACL was unchanged. */ - assertEqualInt(4, c = archive_entry_acl_reset(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS)); - /* First three are standard permission bits. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 4); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 5); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_GROUP_OBJ); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, 6); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_OTHER); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); - /* Fourth is custom one. */ - assertEqualInt(0, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, ARCHIVE_ENTRY_ACL_TYPE_ACCESS); - assertEqualInt(permset, ARCHIVE_ENTRY_ACL_READ); - assertEqualInt(tag, ARCHIVE_ENTRY_ACL_USER); - assertEqualInt(qual, 77); - assertEqualString(name, "user77"); - assertEqualInt(1, archive_entry_acl_next(e2, - ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - &type, &permset, &tag, &qual, &name)); - assertEqualInt(type, 0); - assertEqualInt(permset, 0); - assertEqualInt(tag, 0); - assertEqualInt(qual, -1); - assertEqualString(name, NULL); -#endif -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("xattr preserved in archive_entry copy"); -#else - /* Verify xattr was unchanged. */ - assertEqualInt(1, archive_entry_xattr_reset(e2)); -#endif - - /* Release clone. */ - archive_entry_free(e2); - - /* - * Test clear() implementation. - */ - archive_entry_clear(e); - assertEqualInt(archive_entry_atime(e), 0); - assertEqualInt(archive_entry_atime_nsec(e), 0); - assertEqualInt(archive_entry_birthtime(e), 0); - assertEqualInt(archive_entry_birthtime_nsec(e), 0); - assertEqualInt(archive_entry_ctime(e), 0); - assertEqualInt(archive_entry_ctime_nsec(e), 0); - assertEqualInt(archive_entry_dev(e), 0); - archive_entry_fflags(e, &set, &clear); - assertEqualInt(clear, 0); - assertEqualInt(set, 0); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_filetype(e), 0); -#endif - assertEqualInt(archive_entry_gid(e), 0); - assertEqualString(archive_entry_gname(e), NULL); - assertEqualString(archive_entry_hardlink(e), NULL); - assertEqualInt(archive_entry_ino(e), 0); - assertEqualInt(archive_entry_mode(e), 0); - assertEqualInt(archive_entry_mtime(e), 0); - assertEqualInt(archive_entry_mtime_nsec(e), 0); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e), 0); -#endif - assertEqualString(archive_entry_pathname(e), NULL); - assertEqualInt(archive_entry_rdev(e), 0); - assertEqualInt(archive_entry_size(e), 0); - assertEqualString(archive_entry_symlink(e), NULL); - assertEqualInt(archive_entry_uid(e), 0); - assertEqualString(archive_entry_uname(e), NULL); - /* ACLs should be cleared. */ - assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_ACCESS), 0); - assertEqualInt(archive_entry_acl_count(e, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT), 0); - /* Extended attributes should be cleared. */ - assertEqualInt(archive_entry_xattr_count(e), 0); - - /* - * Test archive_entry_copy_stat(). - */ - memset(&st, 0, sizeof(st)); - /* Set all of the standard 'struct stat' fields. */ - st.st_atime = 456789; - st.st_ctime = 345678; - st.st_dev = 123; - st.st_gid = 34; - st.st_ino = 234; - st.st_mode = 077777; - st.st_mtime = 234567; - st.st_nlink = 345; - st.st_size = 123456789; - st.st_uid = 23; -#ifdef __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - st.st_atimespec.tv_nsec = 6543210; - st.st_ctimespec.tv_nsec = 5432109; - st.st_mtimespec.tv_nsec = 3210987; - st.st_birthtimespec.tv_nsec = 7459386; -#endif - /* Copy them into the entry. */ - archive_entry_copy_stat(e, &st); - /* Read each one back separately and compare. */ - assertEqualInt(archive_entry_atime(e), 456789); - assertEqualInt(archive_entry_ctime(e), 345678); - assertEqualInt(archive_entry_dev(e), 123); - assertEqualInt(archive_entry_gid(e), 34); - assertEqualInt(archive_entry_ino(e), 234); - assertEqualInt(archive_entry_mode(e), 077777); - assertEqualInt(archive_entry_mtime(e), 234567); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(archive_entry_nlink(e), 345); -#endif - assertEqualInt(archive_entry_size(e), 123456789); - assertEqualInt(archive_entry_uid(e), 23); -#if __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - assertEqualInt(archive_entry_atime_nsec(e), 6543210); - assertEqualInt(archive_entry_ctime_nsec(e), 5432109); - assertEqualInt(archive_entry_mtime_nsec(e), 3210987); - assertEqualInt(archive_entry_birthtime_nsec(e), 7459386); -#endif - - /* - * Test archive_entry_stat(). - */ - /* First, clear out any existing stat data. */ - memset(&st, 0, sizeof(st)); - archive_entry_copy_stat(e, &st); - /* Set a bunch of fields individually. */ - archive_entry_set_atime(e, 456789, 321); - archive_entry_set_ctime(e, 345678, 432); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 123); -#endif - archive_entry_set_gid(e, 34); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 234); -#endif - archive_entry_set_mode(e, 012345); - archive_entry_set_mode(e, 012345); - archive_entry_set_mtime(e, 234567, 543); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 345); -#endif - archive_entry_set_size(e, 123456789); - archive_entry_set_uid(e, 23); - /* Retrieve a stat structure. */ - assert((pst = archive_entry_stat(e)) != NULL); - /* Check that the values match. */ - assertEqualInt(pst->st_atime, 456789); - assertEqualInt(pst->st_ctime, 345678); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_dev, 123); -#endif - assertEqualInt(pst->st_gid, 34); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_ino, 234); -#endif - assertEqualInt(pst->st_mode, 012345); - assertEqualInt(pst->st_mtime, 234567); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - assertEqualInt(pst->st_nlink, 345); -#endif - assertEqualInt(pst->st_size, 123456789); - assertEqualInt(pst->st_uid, 23); -#ifdef __FreeBSD__ - /* On FreeBSD, high-res timestamp data should come through. */ - assertEqualInt(pst->st_atimespec.tv_nsec, 321); - assertEqualInt(pst->st_ctimespec.tv_nsec, 432); - assertEqualInt(pst->st_mtimespec.tv_nsec, 543); -#endif - - /* Changing any one value should update struct stat. */ - archive_entry_set_atime(e, 456788, 0); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_atime, 456788); - archive_entry_set_ctime(e, 345677, 431); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_ctime, 345677); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 122); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_dev, 122); -#endif - archive_entry_set_gid(e, 33); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_gid, 33); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_ino(e, 233); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_ino, 233); -#endif - archive_entry_set_mode(e, 012344); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_mode, 012344); - archive_entry_set_mtime(e, 234566, 542); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_mtime, 234566); -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_nlink(e, 344); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_nlink, 344); -#endif - archive_entry_set_size(e, 123456788); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_size, 123456788); - archive_entry_set_uid(e, 22); - assert((pst = archive_entry_stat(e)) != NULL); - assertEqualInt(pst->st_uid, 22); - /* We don't need to check high-res fields here. */ - - /* - * Test dev/major/minor interfaces. Setting 'dev' or 'rdev' - * should change the corresponding major/minor values, and - * vice versa. - * - * The test here is system-specific because it assumes that - * makedev(), major(), and minor() are defined in sys/stat.h. - * I'm not too worried about it, though, because the code is - * simple. If it works on FreeBSD, it's unlikely to be broken - * anywhere else. Note: The functionality is present on every - * platform even if these tests only run some places; - * libarchive's more extensive configuration logic should find - * the necessary definitions on every platform. - */ -#if __FreeBSD__ -#if ARCHIVE_VERSION_NUMBER >= 1009000 - archive_entry_set_dev(e, 0x12345678); - assertEqualInt(archive_entry_devmajor(e), major(0x12345678)); - assertEqualInt(archive_entry_devminor(e), minor(0x12345678)); - assertEqualInt(archive_entry_dev(e), 0x12345678); - archive_entry_set_devmajor(e, 0xfe); - archive_entry_set_devminor(e, 0xdcba98); - assertEqualInt(archive_entry_devmajor(e), 0xfe); - assertEqualInt(archive_entry_devminor(e), 0xdcba98); - assertEqualInt(archive_entry_dev(e), makedev(0xfe, 0xdcba98)); - archive_entry_set_rdev(e, 0x12345678); - assertEqualInt(archive_entry_rdevmajor(e), major(0x12345678)); - assertEqualInt(archive_entry_rdevminor(e), minor(0x12345678)); - assertEqualInt(archive_entry_rdev(e), 0x12345678); - archive_entry_set_rdevmajor(e, 0xfe); - archive_entry_set_rdevminor(e, 0xdcba98); - assertEqualInt(archive_entry_rdevmajor(e), 0xfe); - assertEqualInt(archive_entry_rdevminor(e), 0xdcba98); - assertEqualInt(archive_entry_rdev(e), makedev(0xfe, 0xdcba98)); -#endif -#endif - - /* - * Exercise the character-conversion logic, if we can. - */ - if (NULL == setlocale(LC_ALL, LOCALE_DE)) { - skipping("Can't exercise charset-conversion logic without" - " a suitable locale."); - } else { - /* A filename that cannot be converted to wide characters. */ - archive_entry_copy_pathname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_pathname_w(e)); - //failure("Converting invalid chars to UTF-8 should fail."); - //assert(NULL == archive_entry_pathname_utf8(e)); - - /* A group name that cannot be converted. */ - archive_entry_copy_gname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_gname_w(e)); - - /* A user name that cannot be converted. */ - archive_entry_copy_uname(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_uname_w(e)); - - /* A hardlink target that cannot be converted. */ - archive_entry_copy_hardlink(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_hardlink_w(e)); - - /* A symlink target that cannot be converted. */ - archive_entry_copy_symlink(e, "abc\314\214mno\374xyz"); - failure("Converting invalid chars to Unicode should fail."); - assert(NULL == archive_entry_symlink_w(e)); - } - - l = 0x12345678L; - wc = (wchar_t)l; /* Wide character too big for UTF-8. */ - if (NULL == setlocale(LC_ALL, "C") || (long)wc != l) { - skipping("Testing charset conversion failure requires 32-bit wchar_t and support for \"C\" locale."); - } else { - /* - * Build the string L"xxx\U12345678yyy\u5678zzz" without - * using C99 \u#### syntax, which isn't uniformly - * supported. (GCC 3.4.6, for instance, defaults to - * "c89 plus GNU extensions.") - */ - wcscpy(wbuff, L"xxxAyyyBzzz"); - wbuff[3] = (wchar_t)0x12345678; - wbuff[7] = (wchar_t)0x5678; - /* A wide filename that cannot be converted to narrow. */ - archive_entry_copy_pathname_w(e, wbuff); - failure("Converting wide characters from Unicode should fail."); - assertEqualString(NULL, archive_entry_pathname(e)); - } - - /* Release the experimental entry. */ - archive_entry_free(e); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_entry_strmode.c b/Utilities/cmlibarchive/libarchive/test/test_entry_strmode.c deleted file mode 100644 index d262ce25a..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_entry_strmode.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_entry_strmode.c,v 1.1 2008/01/01 22:28:04 kientzle Exp $"); - -DEFINE_TEST(test_entry_strmode) -{ - struct archive_entry *entry; - - assert((entry = archive_entry_new()) != NULL); - - archive_entry_set_mode(entry, AE_IFREG | 0642); - assertEqualString(archive_entry_strmode(entry), "-rw-r---w- "); - - /* Regular file + hardlink still shows as regular file. */ - archive_entry_set_mode(entry, AE_IFREG | 0644); - archive_entry_set_hardlink(entry, "link"); - assertEqualString(archive_entry_strmode(entry), "-rw-r--r-- "); - - archive_entry_set_mode(entry, 0640); - archive_entry_set_hardlink(entry, "link"); - assertEqualString(archive_entry_strmode(entry), "hrw-r----- "); - archive_entry_set_hardlink(entry, NULL); - - archive_entry_set_mode(entry, AE_IFDIR | 0777); - assertEqualString(archive_entry_strmode(entry), "drwxrwxrwx "); - - archive_entry_set_mode(entry, AE_IFBLK | 03642); - assertEqualString(archive_entry_strmode(entry), "brw-r-S-wT "); - - archive_entry_set_mode(entry, AE_IFCHR | 05777); - assertEqualString(archive_entry_strmode(entry), "crwsrwxrwt "); - - archive_entry_set_mode(entry, AE_IFSOCK | 0222); - assertEqualString(archive_entry_strmode(entry), "s-w--w--w- "); - - archive_entry_set_mode(entry, AE_IFIFO | 0444); - assertEqualString(archive_entry_strmode(entry), "pr--r--r-- "); - - archive_entry_set_mode(entry, AE_IFLNK | 04000); - assertEqualString(archive_entry_strmode(entry), "l--S------ "); - - archive_entry_acl_add_entry(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS, - 0007, ARCHIVE_ENTRY_ACL_GROUP, 78, "group78"); - assertEqualString(archive_entry_strmode(entry), "l--S------+"); - - /* Release the experimental entry. */ - archive_entry_free(entry); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_extattr_freebsd.c b/Utilities/cmlibarchive/libarchive/test/test_extattr_freebsd.c deleted file mode 100644 index 023c9fc88..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_extattr_freebsd.c +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * Copyright (c) 2003-2009 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(__FreeBSD__) && __FreeBSD__ > 4 -#include -#endif - -/* - * Verify extended attribute restore-to-disk. This test is FreeBSD-specific. - */ - -DEFINE_TEST(test_extattr_freebsd) -{ -#if !defined(__FreeBSD__) - skipping("FreeBSD-specific extattr restore test"); -#elif __FreeBSD__ < 5 - skipping("extattr restore supported only on FreeBSD 5.0 and later"); -#else - char buff[64]; - const char *xname; - const void *xval; - size_t xsize; - struct stat st; - struct archive *a; - struct archive_entry *ae; - int n, fd; - int extattr_privilege_bug = 0; - - /* - * First, do a quick manual set/read of an extended attribute - * to verify that the local filesystem does support it. If it - * doesn't, we'll simply skip the remaining tests. - */ - /* Create a test file and try to set an ACL on it. */ - fd = open("pretest", O_RDWR | O_CREAT, 0777); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) - return; - - errno = 0; - n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); - if (n != 4 && errno == EOPNOTSUPP) { - close(fd); - skipping("extattr tests require that extattr support be enabled on the filesystem"); - return; - } - failure("extattr_set_fd(): errno=%d (%s)", errno, strerror(errno)); - assertEqualInt(4, n); - close(fd); - - /* - * Repeat the above, but with file permissions set to 0000. - * This should work (extattr_set_fd() should follow fd - * permissions, not file permissions), but is known broken on - * some versions of FreeBSD. - */ - fd = open("pretest2", O_RDWR | O_CREAT, 00000); - failure("Could not create test file?!"); - if (!assert(fd >= 0)) - return; - - n = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, "testattr", "1234", 4); - if (n != 4) { - skipping("Restoring xattr to an unwritable file seems to be broken on this platform"); - extattr_privilege_bug = 1; - } - close(fd); - - /* Create a write-to-disk object. */ - assert(NULL != (a = archive_write_disk_new())); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_XATTR); - - /* Populate an archive entry with an extended attribute. */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test0"); - archive_entry_set_mtime(ae, 123456, 7890); - archive_entry_set_size(ae, 0); - archive_entry_set_mode(ae, 0755); - archive_entry_xattr_add_entry(ae, "user.foo", "12345", 5); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Another entry; similar but with mode = 0. */ - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_pathname(ae, "test1"); - archive_entry_set_mtime(ae, 12345678, 7890); - archive_entry_set_size(ae, 0); - archive_entry_set_mode(ae, 0); - archive_entry_xattr_add_entry(ae, "user.bar", "123456", 6); - if (extattr_privilege_bug) - /* If the bug is here, write_header will return warning. */ - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_header(a, ae)); - else - assertEqualIntA(a, ARCHIVE_OK, - archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test0", &st)); - assertEqualInt(st.st_mtime, 123456); - /* Verify extattr */ - n = extattr_get_file("test0", EXTATTR_NAMESPACE_USER, - "foo", buff, sizeof(buff)); - if (assertEqualInt(n, 5)) { - buff[n] = '\0'; - assertEqualString(buff, "12345"); - } - - /* Verify the data on disk. */ - assertEqualInt(0, stat("test1", &st)); - assertEqualInt(st.st_mtime, 12345678); - /* Verify extattr */ - n = extattr_get_file("test1", EXTATTR_NAMESPACE_USER, - "bar", buff, sizeof(buff)); - if (extattr_privilege_bug) { - /* If we have the bug, the extattr won't have been written. */ - assertEqualInt(n, -1); - } else { - if (assertEqualInt(n, 6)) { - buff[n] = '\0'; - assertEqualString(buff, "123456"); - } - } - - /* Use libarchive APIs to read the file back into an entry and - * verify that the extattr was read correctly. */ - assert((a = archive_read_disk_new()) != NULL); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "test0"); - assertEqualInt(ARCHIVE_OK, - archive_read_disk_entry_from_file(a, ae, -1, NULL)); - assertEqualInt(1, archive_entry_xattr_reset(ae)); - assertEqualInt(ARCHIVE_OK, - archive_entry_xattr_next(ae, &xname, &xval, &xsize)); - assertEqualString(xname, "user.foo"); - assertEqualInt(xsize, 5); - assertEqualMem(xval, "12345", xsize); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - archive_entry_free(ae); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_fuzz.c b/Utilities/cmlibarchive/libarchive/test/test_fuzz.c deleted file mode 100644 index 1860b4deb..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_fuzz.c +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_fuzz.c,v 1.1 2008/12/06 07:08:08 kientzle Exp $"); - -/* - * This was inspired by an ISO fuzz tester written by Michal Zalewski - * and posted to the "vulnwatch" mailing list on March 17, 2005: - * http://seclists.org/vulnwatch/2005/q1/0088.html - * - * This test simply reads each archive image into memory, pokes - * random values into it and runs it through libarchive. It tries - * to damage about 1% of each file and repeats the exercise 100 times - * with each file. - * - * Unlike most other tests, this test does not verify libarchive's - * responses other than to ensure that libarchive doesn't crash. - * - * Due to the deliberately random nature of this test, it may be hard - * to reproduce failures. Because this test deliberately attempts to - * induce crashes, there's little that can be done in the way of - * post-failure diagnostics. - */ - -/* Because this works for any archive, I can just re-use the archives - * developed for other tests. I've not included all of the compressed - * archives here, though; I don't want to spend all of my test time - * testing zlib and bzlib. */ -static const char * -files[] = { - "test_fuzz_1.iso", - "test_compat_bzip2_1.tbz", - "test_compat_gtar_1.tar", - "test_compat_tar_hardlink_1.tar", - "test_compat_zip_1.zip", - "test_read_format_gtar_sparse_1_17_posix10_modified.tar", - "test_read_format_tar_empty_filename.tar", - "test_read_format_zip.zip", - NULL -}; - -#define UnsupportedCompress(r, a) \ - (r != ARCHIVE_OK && \ - (strcmp(archive_error_string(a), \ - "Unrecognized archive format") == 0 && \ - archive_compression(a) == ARCHIVE_COMPRESSION_NONE)) - -DEFINE_TEST(test_fuzz) -{ - const char **filep; - const void *blk; - size_t blk_size; - off_t blk_offset; - - for (filep = files; *filep != NULL; ++filep) { - struct archive_entry *ae; - struct archive *a; - char *rawimage, *image; - size_t size; - int i; - - extract_reference_file(*filep); - rawimage = slurpfile(&size, *filep); - assert(rawimage != NULL); - image = malloc(size); - assert(image != NULL); - srand((unsigned)time(NULL)); - - for (i = 0; i < 100; ++i) { - FILE *f; - int j, numbytes; - - /* Fuzz < 1% of the bytes in the archive. */ - memcpy(image, rawimage, size); - numbytes = (int)(rand() % (size / 100)); - for (j = 0; j < numbytes; ++j) - image[rand() % size] = (char)rand(); - - /* Save the messed-up image to a file. - * If we crash, that file will be useful. */ - f = fopen("after.test.failure.send.this.file." - "to.libarchive.maintainers.with.system.details", "wb"); - fwrite(image, 1, (size_t)size, f); - fclose(f); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - - if (0 == archive_read_open_memory(a, image, size)) { - while(0 == archive_read_next_header(a, &ae)) { - while (0 == archive_read_data_block(a, - &blk, &blk_size, &blk_offset)) - continue; - } - archive_read_close(a); - archive_read_finish(a); - } - } - free(image); - free(rawimage); - } -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_fuzz_1.iso.uu b/Utilities/cmlibarchive/libarchive/test/test_fuzz_1.iso.uu deleted file mode 100644 index c7a7edb8c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_fuzz_1.iso.uu +++ /dev/null @@ -1,26993 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_fuzz_1.iso.uu,v 1.1 2008/12/06 07:08:08 kientzle Exp $ -begin 644 test_fuzz_1.iso -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````!0T0P,#$!`$9R965"4T0@("`@("`@("`@("`@("`@("`@("`@ -M("`@0T123TT@("`@("`@("`@("`@("`@("`@("`@("`@("```````````%$" -M``````)1```````````````````````````````````````````!```!`0`` -M`0`("`"B"``````(HA0`````````````%@`````B`!P````````<``@````` -M"`!L"Q8)#`W@`@```0```0$`("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@34M) -M4T]&4R!)4T\@.38V,"](1E,@1DE,15-94U1%32!"54E,1$52("8@0T1214-/ -M4D0@0T0M4B]$5D0@0U)%051/4B`H0RD@,3DY,R!%+EE/54Y'1$%,12`H0RD@ -M,3DY-R!*+E!%05)33TXO2BY30TA)3$Q)3D<@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`R,#`X,3$R,C`Y,3(Q,S`PX#(P,#@Q,3(R,#DQ,C$S,##@ -M,#`P,#`P,#`P,#`P,#`P,``R,#`X,3$R,C`Y,3(Q,S`PX`$`("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````)#1#`P,0$``$8`<@!E -M`&4`0@!3`$0`(``@`"``(``@`"``(``@`"``0P!$`%(`3P!-`"``(``@`"`` -M(``@`"``(``@`"``(```````````40(``````E$E+T4````````````````` -M``````````````````````$```$!```!``@(`'()``````ER&``````````` -M```:`````"(`[@```````.X`"``````(`&P+%@D,#>`"```!```!`0``(``@ -M`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"`` -M(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@ -M`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"`` -M(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@ -M`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"`` -M(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@ -M`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"`` -M(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@ -M`"``(``@`"``(``@`"``(``@`"``30!+`$D`4P!/`$8`4P`@`$D`4P!/`"`` -M.0`V`#8`,`!?`$@`1@!3`"``1@!)`$P`10!3`%D`4P!4`$4`30`@`$(`50!) -M`$P`1`!%`%(`(``F`"``0P!$`%(`10!#`$\`4@!$`"``0P!$`"T`4@!?`$0` -M5@!$`"``0P!2`$4`00`@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@ -M`"``(```(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`"```"`` -M(``@`"``(``@`"``(``@`"``(``@`"``(``@`"``(``@`#(P,#@Q,3(R,#DQ -M,C$S,##@,C`P.#$Q,C(P.3$R,3,P,.`P,#`P,#`P,#`P,#`P,#`P`#(P,#@Q -M,3(R,#DQ,C$S,##@`0`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ -M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(``````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````_T-$,#`Q`0`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!-2TD@4V%T($YO=B`R -M,B`P.3HQ,CHQ,R`R,#`X"FUK:7-O9G,@,BXP,2`M52`M4B`M2B`M;R!C9"YI -M`$$` -M`0!8````'P!!``$`4@```"``00`!`$P````A`$$``0!&````(@!!``$`0``` -M`",`00`!`#H````D`$$``0`T````)0!!``$`+@```"8`00`!`"@````G`$$` -M`0#E````*`!!``$`(P```"H`00`!`-T````K`$$``0#7````+`!!``$`T0`` -M`"T`00`!`,L````N`$$``0#%````+P!!``$`OP```#``00`!`+D````Q`$$` -M`0"S````,@!!``$`K0```#,`00`!`*<````T`$$``0"A````-0!!``$`FP`` -M`#8`00`!`)4````W`$$``0"/````.`!!``$`B0```#D`00`!`(,````Z`$$` -M`0!]````.P!!``$`=P```#P`00`!`'$````]`$$``0!K````/@!!``$`90`` -M`#\`00`!`%\```!``$$``0!9````00!!``$`4P```$(`00`!`$T```!#`$$` -M`0!'````1`!!``$`00```$4`00`!`#L```!&`$$``0`U````1P!!``$`+P`` -M`$@`00`!`"D```!)`$$``0#F````2@!!``$`)````$L`00`!`-X```!,`$$` -M`0#8````30!!``$`T@```$X`00`!`,P```!/`$$``0#&````4`!!``$`P``` -M`%$`00`!`+H```!2`$$``0"T````4P!!``$`K@```%0`00`!`*@```!5`$$` -M`0"B````5@!!``$`G````%<`00`!`)8```!8`$$``0"0````60!!``$`B@`` -M`%H`00`!`(0```!;`$$``0!^````7`!!``$`>````%T`00`!`'(```!>`$$` -M`0!L````7P!!``$`9@```&``00`!`&````!A`$$``0!:````8@!!``$`5``` -M`&,`00`!`$X```!D`$$``0!(````90!!``$`0@```&8`00`!`#P```!G`$$` -M`0`V````:`!!``$`,````&D`00`!`"H```!J`$$``0#G````:P!!``$`)0`` -M`&P`00`!`-\```!M`$$``0#9````;@!!``$`TP```&\`00`!`,T```!P`$$` -M`0#'````<0!!``$`P0```'(`00`!`+L```!S`$$``0"U````=`!!``$`KP`` -M`'4`00`!`*D```!V`$$``0"C````=P!!``$`G0```'@`00`!`)<```!Y`$$` -M`0"1````>@!!``$`BP```'L`00`!`(4```!\`$$``0!_````?0!!``$`>0`` -M`'X`00`!`',```!_`$$``0!M````@`!!``$`9P```($`00`!`&$```""`$$` -M`0!;````@P!!``$`50```(0`00`!`$\```"%`$$``0!)````A@!!``$`0P`` -M`(<`00`!`#T```"(`$$``0`W````B0!!``$`,0```(H`00`!`"L```"+`$$` -M`0#H````C`!!``$`)@```(T`00`!`.````".`$$``0#:````CP!!``$`U``` -M`)``00`!`,X```"1`$$``0#(````D@!!``$`P@```),`00`!`+P```"4`$$` -M`0"V````E0!!``$`L````)8`00`!`*H```"7`$$``0"D````F`!!``$`G@`` -M`)D`00`!`)@```":`$$``0"2````FP!!``$`C````)P`00`!`(8```"=`$$` -M`0"`````G@!!``$`>@```)\`00`!`'0```"@`$$``0!N````H0!!``$`:``` -M`*(`00`!`&(```"C`$$``0!<````I`!!``$`5@```*4`00`!`%````"F`$$` -M`0!*````IP!!``$`1````*@`00`!`#X```"I`$$``0`X````J@!!``$`,@`` -M`*L`00`!`"P```"L`$$````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````!`````!P``0```0````#B``%!`!\`````Z0`!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!00`(`````!X``7)R7VUO=F5D`0`` -M``#C``)!`!\`````ZP`#04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M00`!`````"$`!$$`!`````#A``1!,#`P!`````#;``1!,#`Q!`````#5``1! -M,#`R!`````#/``1!,#`S!`````#)``1!,#`T!`````##``1!,#`U!`````"] -M``1!,#`V!`````"W``1!,#`W!`````"Q``1!,#`X!`````"K``1!,#`Y!``` -M``"E``1!,#!!!`````"?``1!,#!"!`````"9``1!,#!#!`````"3``1!,#!$ -M!`````"-``1!,#!%!`````"'``1!,#!&!`````"!``1!,#!'!`````![``1! -M,#!(!`````!U``1!,#!)!`````!O``1!,#!*!`````!I``1!,#!+!`````!C -M``1!,#!,!`````!=``1!,#!-!`````!7``1!,#!.!`````!1``1!,#!/!``` -M``!+``1!,#!0!`````!%``1!,#!1!``````_``1!,#!2!``````Y``1!,#!3 -M!``````S``1!,#!4!``````M``1!,#!5!``````G``1!,#!6`0````#D``5! -M`!\`````[0`&04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!00`!```` -M`"(`!T$``0````#<``E!``$`````U@`*00`!`````-``"T$``0````#*``Q! -M``$`````Q``-00`!`````+X`#D$``0````"X``]!``$`````L@`000`!```` -M`*P`$4$``0````"F`!)!``$`````H``300`!`````)H`%$$``0````"4`!5! -M``$`````C@`600`!`````(@`%T$``0````""`!A!``$`````?``900`!```` -M`'8`&D$``0````!P`!M!``$`````:@`<00`!`````&0`'4$``0````!>`!Y! -M``$`````6``?00`!`````%(`($$``0````!,`"%!``$`````1@`B00`!```` -M`$``(T$``0`````Z`"1!``$`````-``E00`!`````"X`)D$``0`````H`"=! -M``$`````Y0`H00`!`````",`*D$``0````#=`"M!``$`````UP`L00`!```` -M`-$`+4$``0````#+`"Y!``$`````Q0`O00`!`````+\`,$$``0````"Y`#%! -M``$`````LP`R00`!`````*T`,T$``0````"G`#1!``$`````H0`U00`!```` -M`)L`-D$``0````"5`#=!``$`````CP`X00`!`````(D`.4$``0````"#`#I! -M``$`````?0`[00`!`````'<`/$$``0````!Q`#U!``$`````:P`^00`!```` -M`&4`/T$``0````!?`$!!``$`````60!!00`!`````%,`0D$``0````!-`$-! -M``$`````1P!$00`!`````$$`14$``0`````[`$9!``$`````-0!'00`!```` -M`"\`2$$``0`````I`$E!``$`````Y@!*00`!`````"0`2T$``0````#>`$Q! -M``$`````V`!-00`!`````-(`3D$``0````#,`$]!``$`````Q@!000`!```` -M`,``44$``0````"Z`%)!``$`````M`!300`!`````*X`5$$``0````"H`%5! -M``$`````H@!600`!`````)P`5T$``0````"6`%A!``$`````D`!900`!```` -M`(H`6D$``0````"$`%M!``$`````?@!<00`!`````'@`74$``0````!R`%Y! -M``$`````;`!?00`!`````&8`8$$``0````!@`&%!``$`````6@!B00`!```` -M`%0`8T$``0````!.`&1!``$`````2`!E00`!`````$(`9D$``0`````\`&=! -M``$`````-@!H00`!`````#``:4$``0`````J`&I!``$`````YP!K00`!```` -M`"4`;$$``0````#?`&U!``$`````V0!N00`!`````-,`;T$``0````#-`'!! -M``$`````QP!Q00`!`````,$`$$``0````"7`'E! -M``$`````D0!Z00`!`````(L`>T$``0````"%`'Q!``$`````?P!]00`!```` -M`'D`?D$``0````!S`']!``$`````;0"`00`!`````&<`@4$``0````!A`()! -M``$`````6P"#00`!`````%4`A$$``0````!/`(5!``$`````20"&00`!```` -M`$,`AT$``0`````]`(A!``$`````-P")00`!`````#$`BD$``0`````K`(M! -M``$`````Z`",00`!`````"8`C4$``0````#@`(Y!``$`````V@"/00`!```` -M`-0`D$$``0````#.`)%!``$`````R`"200`!`````,(`DT$``0````"\`)1! -M``$`````M@"500`!`````+``ED$``0````"J`)=!``$`````I`"800`!```` -M`)X`F4$``0````"8`)I!``$`````D@";00`!`````(P`G$$``0````"&`)U! -M``$`````@`">00`!`````'H`GT$``0````!T`*!!``$`````;@"A00`!```` -M`&@`HD$``0````!B`*-!``$`````7`"D00`!`````%8`I4$``0````!0`*9! -M``$`````2@"G00`!`````$0`J$$``0`````^`*E!``$`````.`"J00`!```` -M`#(`JT$``0`````L`*Q!```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````0#N`````0````(`L`$```$``$&``+```00(`70$``'D``$$"`%X!``!Z``!! -M`@!?`0``>P``00(`8`$``'P``$$"`&$!``!]``!!`@!B`0``?@``00(`8P$` -M`'\``$$"`&0!``"```!!`@!E`0``@0``00(`9@$``((``$$"`&`$``)0``$$"`'D!``"5``!! -M`@!Z`0``E@``00(`>P$``)<``$$"`'P!``"8``!!`@!]`0``F0``00(`?@$` -M`)H``$$"`'\!``";``!!`@"``0``G```00(`@0$``)T``$$"`((!``">``!! -M`@"#`0``GP``00(`A`$``*```$$"`(4!``"A``!!`@"&`0``H@``00(`AP$` -M`*,``$$"`(@!``"D``!!`@")`0``I0``00(`B@$``*8``$$"`(L!``"G``!! -M`@",`0``J```00(`C0$``*D``$$"`(X!``"J``!!`@"/`0``JP``00(`D`$` -M`*P``$$"`)$!``"M``!!`@"2`0``K@``00(`DP$``*\``$$"`)0!``"P``!! -M`@"5`0``L0``00(`E@$``+(``$$"`)`0``N@``00(`GP$``+L``$$"`*`!``"\``!!`@"A`0``O0``00(`H@$` -M`+X``$$"`*,!``"_``!!`@"D`0``P```00(`I0$``,$``$$"`*8!``#"``!! -M`@"G`0``PP``00(`J`$``,0``$$"`*D!``#%``!!`@"J`0``Q@``00(`JP$` -M`,<``$$"`*P!``#(``!!`@"M`0``R0``00(`K@$``,H``$$"`*\!``#+``!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````$`````[@`!```"`````;```0!!@`````&W``$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00(````!L0`"`$&` -M`````;@``P!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`@````&R``0`08`````!N0`%`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$"`````;,`!@!!`@````&T``@`00(````!M0`)`$$"```` -M`;8`"@!!`@````#O``L`00(`````\``,`$$"`````/$`#0!!`@````#R``X` -M00(`````\P`/`$$"`````/0`$`!!`@````#U`!$`00(`````]@`2`$$"```` -M`/<`$P!!`@````#X`!0`00(`````^0`5`$$"`````/H`%@!!`@````#[`!<` -M00(`````_``8`$$"`````/T`&0!!`@````#^`!H`00(`````_P`;`$$"```` -M`0``'`!!`@````$!`!T`00(````!`@`>`$$"`````0,`'P!!`@````$$`"`` -M00(````!!0`A`$$"`````08`(@!!`@````$'`",`00(````!"``D`$$"```` -M`0D`)0!!`@````$*`"8`00(````!"P`G`$$"`````0P`*`!!`@````$-`"D` -M00(````!#@`J`$$"`````0\`*P!!`@````$0`"P`00(````!$0`M`$$"```` -M`1(`+@!!`@````$3`"\`00(````!%``P`$$"`````14`,0!!`@````$6`#(` -M00(````!%P`S`$$"`````1@`-`!!`@````$9`#4`00(````!&@`V`$$"```` -M`1L`-P!!`@````$<`#@`00(````!'0`Y`$$"`````1X`.@!!`@````$?`#L` -M00(````!(``\`$$"`````2$`/0!!`@````$B`#X`00(````!(P`_`$$"```` -M`20`0`!!`@````$E`$$`00(````!)@!"`$$"`````2<`0P!!`@````$H`$0` -M00(````!*0!%`$$"`````2H`1@!!`@````$K`$<`00(````!+`!(`$$"```` -M`2T`20!!`@````$N`$H`00(````!+P!+`$$"`````3``3`!!`@````$Q`$T` -M00(````!,@!.`$$"`````3,`3P!!`@````$T`%``00(````!-0!1`$$"```` -M`38`4@!!`@````$W`%,`00(````!.`!4`$$"`````3D`50!!`@````$Z`%8` -M00(````!.P!7`$$"`````3P`6`!!`@````$]`%D`00(````!/@!:`$$"```` -M`3\`6P!!`@````%``%P`00(````!00!=`$$"`````4(`7@!!`@````%#`%\` -M00(````!1`!@`$$"`````44`80!!`@````%&`&(`00(````!1P!C`$$"```` -M`4@`9`!!`@````%)`&4`00(````!2@!F`$$"`````4L`9P!!`@````%,`&@` -M00(````!30!I`$$"`````4X`:@!!`@````%/`&L`00(````!4`!L`$$"```` -M`5$`;0!!`@````%2`&X`00(````!4P!O`$$"`````50`<`!!`@````%5`'$` -M00(````!5@!R`$$"`````5<`0!!`@````%>`'H` -M00(````!7P![`$$"`````6``?`!!`@````%A`'T`00(````!8@!^`$$"```` -M`6,`?P!!`@````%D`(``00(````!90"!`$$"`````68`@@!!`@````%G`(,` -M00(````!:`"$`$$"`````6D`A0!!`@````%J`(8`00(````!:P"'`$$"```` -M`6P`B`!!`@````%M`(D`00(````!;@"*`$$"`````6\`BP!!`@````%P`(P` -M00(````!<0"-`$$"`````7(`C@!!`@````%S`(\`00(````!=`"0`$$"```` -M`74`D0!!`@````%V`)(`00(````!=P"3`$$"`````7@`E`!!`@````%Y`)4` -M00(````!>@"6`$$"`````7L`EP!!`@````%\`)@`00(````!?0"9`$$"```` -M`7X`F@!!`@````%_`)L`00(````!@`"<`$$"`````8$`G0!!`@````&"`)X` -M00(````!@P"?`$$"`````80`H`!!`@````&%`*$`00(````!A@"B`$$"```` -M`8<`HP!!`@````&(`*0`00(````!B0"E`$$"`````8H`I@!!`@````&+`*<` -M00(````!C`"H`$$"`````8T`J0!!`@````&.`*H`00(````!CP"K`$$"```` -M`9``K`!!`@````&1`*T`00(````!D@"N`$$"`````9,`KP!!`@````&4`+`` -M00(````!E0"Q`$$"`````98`L@!!`@````&7`+,`00(````!F`"T`$$"```` -M`9D`M0!!`@````&:`+8`00(````!FP"W`$$"`````9P`N`!!`@````&=`+D` -M00(````!G@"Z`$$"`````9\`NP!!`@````&@`+P`00(````!H0"]`$$"```` -M`:(`O@!!`@````&C`+\`00(````!I`#``$$"`````:4`P0!!`@````&F`,(` -M00(````!IP##`$$"`````:@`Q`!!`@````&I`,4`00(````!J@#&`$$"```` -M`:L`QP!!`@````&L`,@`00(````!K0#)`$$"`````:X`R@!!`@````&O`,L` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````"(`!P````````<``@`````"`!L"Q8)#`W@`@```0`` -M`0$`4U`'`;[O`%)2!0&!4%@D`>U!`````$'M!0````````7H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!#11P!N@$``````;H` -M`````````.T```````#M9@`<````````'``(``````@`;`L6"0P-X`(```$` -M``$!`5)2!0&!4%@D`>U!`````$'M!0````````7H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#B````````X@`(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M^`#I````````Z0`(``````@`;`L6"0P-X`(```$```$?04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!05)2!0&)3DV7`0%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04-%'`$= -M````````'0``````````L````````+!Z`!X````````>`!@`````&`!L"Q8) -M#`W@`@```0```0AR!L"Q8) -M#`W@;`L6"0P-X``````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````$Y-<@$`04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!05!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````9@`>````````'@`8`````!@`;`L6"0P-X`(```$` -M``$!`%)2!0&!4%@D`6U!`````$%M(P```````"/H`P`````#Z.@#``````/H -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`<````````'``(``````@` -M;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M!0````````7H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<``A```` -M````(0`(``````@`;`L6"0P-X`(```$```$!05)2!0')3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>!2100!`'0`X0```````.$`"``````(`&P+%@D,#>`"```! -M```!!$$P,#``4E(%`T"`````````N@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=`#; -M````````VP`(``````@`;`L6"0P-X`(```$```$$03`P,0!24@4!R4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T`-4```````#5``@`````"`!L"Q8) -M#`W@`@```0```01!,#`R`%)2!0')3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!2 -M100!`'0`SP```````,\`"``````(`&P+%@D,#>`"```!```!!$$P,#,`4E(% -M`T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=`#)````````R0`(```` -M``@`;`L6"0P-X`(```$```$$03`P-`!24@4!R4Y-!@$`05!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@4D4$`0!T`,,```````##``@`````"`!L"Q8)#`W@`@```0```01! -M,#`U`%)2!0')3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!2100!`'0`O0`````` -M`+T`"``````(`&P+%@D,#>`"```!```!!$$P,#8`4E(%`T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X%)%!`$`=`"W````````MP`(``````@`;`L6"0P-X`(` -M``$```$$03`P-P!24@4!R4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T -M`+$```````"Q``@`````"`!L"Q8)#`W@`@```0```01!,#`X`%)2!0')3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>!2100!`'0`JP```````*L`"``````(`&P+ -M%@D,#>`"```!```!!$$P,#D`4E(%`T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX%)%!`$`=`"E````````I0`(``````@`;`L6"0P-X`(```$```$$03`P00!2 -M4@4!R4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T`)\```````"?``@` -M````"`!L"Q8)#`W@`@```0```01!,#!"`%)2!0')3DT&`0!!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>!2100!`'0`F0```````)D`"``````(`&P+%@D,#>`"```!```! -M!$$P,$,`4E(%`T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=`"3```` -M````DP`(``````@`;`L6"0P-X`(```$```$$03`P1`!24@4!R4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@4D4$`0`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!T`(T````` -M``"-``@`````"`!L"Q8)#`W@`@```0```01!,#!%`%)2!0')3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>!2100!`'0`AP```````(<`"``````(`&P+%@D,#>`" -M```!```!!$$P,$8`4E(%`T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$` -M=`"!````````@0`(``````@`;`L6"0P-X`(```$```$$03`P1P!24@4!R4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T`'L```````![``@`````"`!L -M"Q8)#`W@`@```0```01!,#!(`%)2!0')3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>!2100!`'0`=0```````'4`"``````(`&P+%@D,#>`"```!```!!$$P,$D` -M4E(%`T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=`!O````````;P`( -M``````@`;`L6"0P-X`(```$```$$03`P2@!24@4!R4Y-!@$`05!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@4D4$`0!T`&D```````!I``@`````"`!L"Q8)#`W@`@```0`` -M`01!,#!+`%)2!0')3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!2100!`'0`8P`` -M`````&,`"``````(`&P+%@D,#>`"```!```!!$$P,$P`4E(%`T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=`!=````````70`(``````@`;`L6"0P- -MX`(```$```$$03`P30!24@4!R4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@4D4$ -M`0!T`%<```````!7``@`````"`!L"Q8)#`W@`@```0```01!,#!.`%)2!0') -M3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!2100!`'0`40```````%$`"``````( -M`&P+%@D,#>`"```!```!!$$P,$\`4E(%`T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X%)%!`$`=`!+````````2P`(``````@`;`L6"0P-X`(```$```$$03`P -M4`!24@4!R4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T`$4```````!% -M``@`````"`!L"Q8)#`W@`@```0```01!,#!1`%)2!0')3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>!2100!`'0`/P```````#\`"``````(`&P+%@D,#>`"```! -M```!!$$P,%(`4E(%`T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$`=``Y -M````````.0`(``````@`;`L6"0P-X`(```$```$$03`P4P!24@4!R4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@4D4$`0!T`#,````````S``@`````"`!L"Q8) -M#`W@`@```0```01!,#!4`%)2!0')3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!2 -M100!`'0`+0```````"T`"``````(`&P+%@D,#>`"```!```!!$$P,%4`4E(% -M`T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````'0`)P```````"<`"``````(`&P+%@D,#>`"```! -M```!!$$P,%8`4E(%`T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X%)%!`$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````9@`A```` -M````(0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A -M4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>!03`P!Z````````.@`;``B````````(@`(```` -M``@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````!F`"(````````B``@`````"`!L"Q8)#`W@`@`` -M`0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`"$````````A``@````` -M"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`",` -M```````C``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X``````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````&8`(P`` -M`````",`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&8`(@```````"(`"``````(`&P+%@D,#>`"```!```!`0%24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&P`)````````"0`"``````(`&P+%@D,#>`" -M```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````9@`D````````)``(``````@`;`L6"0P-X`(` -M``$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`C````````(P`(```` -M``@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;``E -M````````)0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!F`"4` -M```````E``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!F`"0````````D``@`````"`!L"Q8)#`W@`@```0```0$!4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`"8````````F``@`````"`!L"Q8)#`W@ -M`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````&8`)@```````"8`"``````(`&P+%@D,#>`" -M```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`)0```````"4`"``` -M```(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@` -MNP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@0TP,`2<````````G```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````9@`G -M````````)P`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2 -M!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!)@```````"8`;``H````````*``( -M``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````!F`"@````````H``@`````"`!L"Q8)#`W@ -M`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`"<````````G``@` -M````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L -M`"D````````I``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````&8` -M*0```````"D`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&8`*````````"@`"``````(`&P+%@D,#>`"```!```!`0%2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`*@```````"H`"``````(`&P+%@D, -M#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````9@`J````````*@`(``````@`;`L6"0P- -MX`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`I````````*0`( -M``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M;``K````````*P`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!F -M`"L````````K``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!F`"H````````J``@`````"`!L"Q8)#`W@`@```0```0$! -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`"P````````L``@`````"`!L"Q8) -M#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````&8`+````````"P`"``````(`&P+%@D, -M#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`*P```````"L` -M"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`2T````````M```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M9@`M````````+0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$! -M`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!+````````"P`;``N```````` -M+@`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````!F`"X````````N``@`````"`!L"Q8) -M#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`"T````````M -M``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!L`"\````````O``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308! -M`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`&8`+P```````"\`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&8`+@```````"X`"``````(`&P+%@D,#>`"```!```! -M`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`,````````#``"``````(`&P+ -M%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````9@`P````````,``(``````@`;`L6 -M"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`O```````` -M+P`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``;``Q````````,0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``!F`#$````````Q``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!F`#`````````P``@`````"`!L"Q8)#`W@`@```0`` -M`0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`#(````````R``@`````"`!L -M"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````&8`,@```````#(`"``````(`&P+ -M%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`,0`````` -M`#$`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`3,````````S```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````9@`S````````,P`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$` -M``$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!,@```````#(`;``T```` -M````-``(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````!F`#0````````T``@`````"`!L -M"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`#,````` -M```S``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!L`#4````````U``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E. -M308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````&8`-0```````#4`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&8`-````````#0`"``````(`&P+%@D,#>`"```! -M```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`-@```````#8`"``````( -M`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````9@`V````````-@`(``````@` -M;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`U```` -M````-0`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``;``W````````-P`(``````@`;`L6"0P-X`(```$```$!05)2!0&) -M3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````!F`#<````````W``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!F`#8````````V``@`````"`!L"Q8)#`W@`@`` -M`0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`#@````````X``@````` -M"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX``````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````&8`.````````#@`"``````( -M`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`-P`` -M`````#<`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4! -MF4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`3D````````Y```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````9@`Y````````.0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(` -M``$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!.````````#@`;``Z -M````````.@`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!F`#H````````Z``@````` -M"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`#D` -M```````Y``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!L`#L````````[``@`````"`!L"Q8)#`W@`@```0```0%!4E(% -M`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````&8`.P```````#L`"``````(`&P+%@D,#>`"```!```!`0!24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&8`.@```````#H`"``````(`&P+%@D,#>`" -M```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`/````````#P`"``` -M```(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````9@`\````````/``(```` -M``@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@`[ -M````````.P`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``;``]````````/0`(``````@`;`L6"0P-X`(```$```$!05)2 -M!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````!F`#T````````]``@`````"`!L"Q8)#`W@`@```0```0$`4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`#P````````\``@`````"`!L"Q8)#`W@ -M`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`#X````````^``@` -M````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X``````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````&8`/@```````#X`"``` -M```(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8` -M/0```````#T`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%2 -M4@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`3\````````_```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````9@`_````````/P`(``````@`;`L6"0P-X`(```$```$!`%)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P- -MX`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!/@```````#X` -M;`!`````````0``(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!F`$````````!```@` -M````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F -M`#\````````_``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!L`$$```````!!``@`````"`!L"Q8)#`W@`@```0```0%! -M4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````&8`00```````$$`"``````(`&P+%@D,#>`"```!```!`0!2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`0````````$``"``````(`&P+%@D, -M#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`0@```````$(` -M"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````9@!"````````0@`( -M``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M9@!!````````00`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``;`!#````````0P`(``````@`;`L6"0P-X`(```$```$! -M05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````!F`$,```````!#``@`````"`!L"Q8)#`W@`@```0```0$` -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`$(```````!"``@`````"`!L"Q8) -M#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`$0```````!$ -M``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X``````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&8`1````````$0` -M"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&8`0P```````$,`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```! -M`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`44```````!%```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````9@!%````````10`(``````@`;`L6"0P-X`(```$```$! -M`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6 -M"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!1``````` -M`$0`;`!&````````1@`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````!F`$8```````!& -M``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!F`$4```````!%``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!L`$<```````!'``@`````"`!L"Q8)#`W@`@```0`` -M`0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````&8`1P```````$<`"``````(`&P+%@D,#>`"```!```! -M`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`1@```````$8`"``````(`&P+ -M%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`2``````` -M`$@`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````9@!(```````` -M2``(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``9@!'````````1P`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``;`!)````````20`(``````@`;`L6"0P-X`(```$` -M``$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````!F`$D```````!)``@`````"`!L"Q8)#`W@`@```0`` -M`0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`$@```````!(``@`````"`!L -M"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`$H````` -M``!*``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X``````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````&8`2@`````` -M`$H`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&8`20```````$D`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````! -M```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`4L```````!+ -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````9@!+````````2P`(``````@`;`L6"0P-X`(```$` -M``$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@` -M;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!2@`` -M`````$H`;`!,````````3``(``````@`;`L6"0P-X`(```$```$!05)2!0&) -M3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!F`$P````` -M``!,``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!F`$L```````!+``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!L`$T```````!-``@`````"`!L"Q8)#`W@`@`` -M`0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````&8`30```````$T`"``````(`&P+%@D,#>`"```! -M```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`3````````$P`"``````( -M`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`3@`` -M`````$X`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````9@!.```` -M````3@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``9@!-````````30`(``````@`;`L6"0P-X`(```$```$!`5)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``;`!/````````3P`(``````@`;`L6"0P-X`(` -M``$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````!F`$\```````!/``@`````"`!L"Q8)#`W@`@`` -M`0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`$X```````!.``@````` -M"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`%`` -M``````!0``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X``````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````&8`4``` -M`````%``"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&8`3P```````$\`"``````(`&P+%@D,#>`"```!```!`0%24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`` -M```!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`5$````` -M``!1```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````9@!1````````40`(``````@`;`L6"0P-X`(` -M``$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8```` -M`!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P! -M4````````%``;`!2````````4@`(``````@`;`L6"0P-X`(```$```$!05)2 -M!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!F`%(` -M``````!2``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!F`%$```````!1``@`````"`!L"Q8)#`W@`@```0```0$!4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`%,```````!3``@`````"`!L"Q8)#`W@ -M`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````&8`4P```````%,`"``````(`&P+%@D,#>`" -M```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`4@```````%(`"``` -M```(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P` -M5````````%0`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````9@!4 -M````````5``(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``9@!3````````4P`(``````@`;`L6"0P-X`(```$```$!`5)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!5````````50`(``````@`;`L6"0P- -MX`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````!F`%4```````!5``@`````"`!L"Q8)#`W@ -M`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`%0```````!4``@` -M````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L -M`%8```````!6``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````&8` -M5@```````%8`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&8`50```````%4`"``````(`&P+%@D,#>`"```!```!`0%2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D, -M#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`5<` -M``````!7```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````9@!7````````5P`(``````@`;`L6"0P- -MX`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8 -M`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P`````` -M`"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!0 -M3`P!5@```````%8`;`!8````````6``(``````@`;`L6"0P-X`(```$```$! -M05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!F -M`%@```````!8``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!F`%<```````!7``@`````"`!L"Q8)#`W@`@```0```0$! -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`%D```````!9``@`````"`!L"Q8) -M#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````&8`60```````%D`"``````(`&P+%@D, -M#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`6````````%@` -M"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&P`6@```````%H`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M9@!:````````6@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``9@!9````````60`(``````@`;`L6"0P-X`(```$```$! -M`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!;````````6P`(``````@`;`L6 -M"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````!F`%L```````!;``@`````"`!L"Q8) -M#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`%H```````!: -M``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!L`%P```````!<``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308! -M`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`&8`7````````%P`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&8`6P```````%L`"``````(`&P+%@D,#>`"```!```! -M`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+ -M%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP, -M`5T```````!=```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````9@!=````````70`(``````@`;`L6 -M"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>```````` -M'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P`` -M`````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>!03`P!7````````%P`;`!>````````7@`(``````@`;`L6"0P-X`(```$` -M``$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``!F`%X```````!>``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!F`%T```````!=``@`````"`!L"Q8)#`W@`@```0`` -M`0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`%\```````!?``@`````"`!L -M"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````&8`7P```````%\`"``````(`&P+ -M%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`7@`````` -M`%X`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&P`8````````&``"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````9@!@````````8``(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``9@!?````````7P`(``````@`;`L6"0P-X`(```$` -M``$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!A````````80`(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````!F`&$```````!A``@`````"`!L -M"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`&`````` -M``!@``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!L`&(```````!B``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E. -M308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````&8`8@```````&(`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&8`80```````&$`"``````(`&P+%@D,#>`"```! -M```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L````````` -M`&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M0TP,`6,```````!C```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````9@!C````````8P`(``````@` -M;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>```` -M````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M -M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>!03`P!8@```````&(`;`!D````````9``(``````@`;`L6"0P-X`(` -M``$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````!F`&0```````!D``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!F`&,```````!C``@`````"`!L"Q8)#`W@`@`` -M`0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`&4```````!E``@````` -M"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX``````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````&8`90```````&4`"``````( -M`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`9``` -M`````&0`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&P`9@```````&8`"``````(`&P+%@D,#>`"```!```!`4%24@4! -MB4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````9@!F````````9@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``9@!E````````90`(``````@`;`L6"0P-X`(` -M``$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!G````````9P`(```` -M``@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!F`&<```````!G``@````` -M"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`&8` -M``````!F``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!L`&@```````!H``@`````"`!L"Q8)#`W@`@```0```0%!4E(% -M`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````&8`:````````&@`"``````(`&P+%@D,#>`"```!```!`0!24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&8`9P```````&<`"``````(`&P+%@D,#>`" -M```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L````` -M`````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@0TP,`6D```````!I```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````9@!I````````:0`(```` -M``@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`> -M````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!```` -M`$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>!03`P!:````````&@`;`!J````````:@`(``````@`;`L6"0P- -MX`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````!F`&H```````!J``@`````"`!L"Q8)#`W@`@```0```0$`4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`&D```````!I``@`````"`!L"Q8)#`W@ -M`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`&L```````!K``@` -M````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X``````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````&8`:P```````&L`"``` -M```(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8` -M:@```````&H`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&P`;````````&P`"``````(`&P+%@D,#>`"```!```!`4%2 -M4@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````9@!L````````;``(``````@`;`L6"0P-X`(```$```$!`%)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@!K````````:P`(``````@`;`L6"0P- -MX`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!M````````;0`( -M``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!F`&T```````!M``@` -M````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F -M`&P```````!L``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!L`&X```````!N``@`````"`!L"Q8)#`W@`@```0```0%! -M4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````&8`;@```````&X`"``````(`&P+%@D,#>`"```!```!`0!2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`;0```````&T`"``````(`&P+%@D, -M#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L` -M`````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@0TP,`6\```````!O```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````9@!O````````;P`( -M``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U! -M`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>!03`P!;@```````&X`;`!P````````<``(``````@`;`L6 -M"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````!F`'````````!P``@`````"`!L"Q8)#`W@`@```0```0$` -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`&\```````!O``@`````"`!L"Q8) -M#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`'$```````!Q -M``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X``````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&8`<0```````'$` -M"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&8`<````````'``"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&P`<@```````'(`"``````(`&P+%@D,#>`"```!```! -M`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````9@!R````````<@`(``````@`;`L6"0P-X`(```$```$! -M`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@!Q````````<0`(``````@`;`L6 -M"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!S```````` -MU!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````!F`',```````!S -M``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!F`'(```````!R``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!L`'0```````!T``@`````"`!L"Q8)#`W@`@```0`` -M`0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````&8`=````````'0`"``````(`&P+%@D,#>`"```!```! -M`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8``"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$````` -M`;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@0TP,`74```````!U```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````9@!U```````` -M=0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D -M`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>!03`P!=````````'0`;`!V````````=@`(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````!F`'8```````!V``@`````"`!L"Q8)#`W@`@```0`` -M`0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`'4```````!U``@`````"`!L -M"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`'<````` -M``!W``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X``````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````&8`=P`````` -M`'<`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&8`=@```````'8`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&P`>````````'@`"``````(`&P+%@D,#>`"```! -M```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````9@!X````````>``(``````@`;`L6"0P-X`(```$` -M``$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@!W````````=P`(``````@` -M;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!Y```` -M````>0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!F`'D````` -M``!Y``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!F`'@```````!X``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!L`'H```````!Z``@`````"`!L"Q8)#`W@`@`` -M`0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````&8`>@```````'H`"``````(`&P+%@D,#>`"```! -M```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`>0```````'D`"``````( -M`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$` -M`````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@0TP,`7L```````![```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````9@![```` -M````>P`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A -M4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>!03`P!>@```````'H`;`!\````````?``(```` -M``@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````!F`'P```````!\``@`````"`!L"Q8)#`W@`@`` -M`0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`'L```````![``@````` -M"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`'T` -M``````!]``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X``````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````&8`?0`` -M`````'T`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&8`?````````'P`"``````(`&P+%@D,#>`"```!```!`0%24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&P`?@```````'X`"``````(`&P+%@D,#>`" -M```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````9@!^````````?@`(``````@`;`L6"0P-X`(` -M``$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@!]````````?0`(```` -M``@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`!_ -M````````?P`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!F`'\` -M``````!_``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!F`'X```````!^``@`````"`!L"Q8)#`W@`@```0```0$!4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`(````````"```@`````"`!L"Q8)#`W@ -M`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````&8`@````````(``"``````(`&P+%@D,#>`" -M```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`?P```````'\`"``` -M```(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@` -MNP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@0TP,`8$```````"!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````9@"! -M````````@0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2 -M!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!@````````(``;`""````````@@`( -M``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````!F`((```````""``@`````"`!L"Q8)#`W@ -M`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`($```````"!``@` -M````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L -M`(,```````"#``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````&8` -M@P```````(,`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&8`@@```````((`"``````(`&P+%@D,#>`"```!```!`0%2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`A````````(0`"``````(`&P+%@D, -M#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````9@"$````````A``(``````@`;`L6"0P- -MX`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@"#````````@P`( -M``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M;`"%````````A0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!F -M`(4```````"%``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!F`(0```````"$``@`````"`!L"Q8)#`W@`@```0```0$! -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`(8```````"&``@`````"`!L"Q8) -M#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````&8`A@```````(8`"``````(`&P+%@D, -M#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`A0```````(4` -M"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`8<```````"'```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M9@"'````````AP`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$! -M`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!A@```````(8`;`"(```````` -MB``(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````!F`(@```````"(``@`````"`!L"Q8) -M#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`(<```````"' -M``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!L`(D```````")``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308! -M`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`&8`B0```````(D`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&8`B````````(@`"``````(`&P+%@D,#>`"```!```! -M`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`B@```````(H`"``````(`&P+ -M%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````9@"*````````B@`(``````@`;`L6 -M"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@")```````` -MB0`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``;`"+````````BP`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``!F`(L```````"+``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!F`(H```````"*``@`````"`!L"Q8)#`W@`@```0`` -M`0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`(P```````",``@`````"`!L -M"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````&8`C````````(P`"``````(`&P+ -M%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`BP`````` -M`(L`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`8T```````"-```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````9@"-````````C0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$` -M``$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!C````````(P`;`".```` -M````C@`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````!F`(X```````".``@`````"`!L -M"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`(T````` -M``"-``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!L`(\```````"/``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E. -M308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````&8`CP```````(\`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&8`C@```````(X`"``````(`&P+%@D,#>`"```! -M```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`D````````)``"``````( -M`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````9@"0````````D``(``````@` -M;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@"/```` -M````CP`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``;`"1````````D0`(``````@`;`L6"0P-X`(```$```$!05)2!0&) -M3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````!F`)$```````"1``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!F`)````````"0``@`````"`!L"Q8)#`W@`@`` -M`0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`)(```````"2``@````` -M"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX``````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````&8`D@```````)(`"``````( -M`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`D0`` -M`````)$`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4! -MF4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`9,```````"3```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````9@"3````````DP`(``````@`;`L6"0P-X`(```$```$!`%)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(` -M``$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!D@```````)(`;`"4 -M````````E``(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!F`)0```````"4``@````` -M"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`),` -M``````"3``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!L`)4```````"5``@`````"`!L"Q8)#`W@`@```0```0%!4E(% -M`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````&8`E0```````)4`"``````(`&P+%@D,#>`"```!```!`0!24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&8`E````````)0`"``````(`&P+%@D,#>`" -M```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`E@```````)8`"``` -M```(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````9@"6````````E@`(```` -M``@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@"5 -M````````E0`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``;`"7````````EP`(``````@`;`L6"0P-X`(```$```$!05)2 -M!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````!F`)<```````"7``@`````"`!L"Q8)#`W@`@```0```0$`4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`)8```````"6``@`````"`!L"Q8)#`W@ -M`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`)@```````"8``@` -M````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X``````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````&8`F````````)@`"``` -M```(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8` -MEP```````)<`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%2 -M4@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`9D```````"9```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````9@"9````````F0`(``````@`;`L6"0P-X`(```$```$!`%)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P- -MX`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!F````````)@` -M;`":````````F@`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!F`)H```````":``@` -M````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F -M`)D```````"9``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!L`)L```````";``@`````"`!L"Q8)#`W@`@```0```0%! -M4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````&8`FP```````)L`"``````(`&P+%@D,#>`"```!```!`0!2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`F@```````)H`"``````(`&P+%@D, -M#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`G````````)P` -M"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````9@"<````````G``( -M``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M9@";````````FP`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``;`"=````````G0`(``````@`;`L6"0P-X`(```$```$! -M05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````!F`)T```````"=``@`````"`!L"Q8)#`W@`@```0```0$` -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`)P```````"<``@`````"`!L"Q8) -M#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`)X```````"> -M``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X``````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&8`G@```````)X` -M"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&8`G0```````)T`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````!```! -M`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`9\```````"?```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````9@"?````````GP`(``````@`;`L6"0P-X`(```$```$! -M`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6 -M"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!G@`````` -M`)X`;`"@````````H``(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````!F`*````````"@ -M``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!F`)\```````"?``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!L`*$```````"A``@`````"`!L"Q8)#`W@`@```0`` -M`0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````&8`H0```````*$`"``````(`&P+%@D,#>`"```!```! -M`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`H````````*``"``````(`&P+ -M%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`H@`````` -M`*(`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````9@"B```````` -MH@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``9@"A````````H0`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``;`"C````````HP`(``````@`;`L6"0P-X`(```$` -M``$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````!F`*,```````"C``@`````"`!L"Q8)#`W@`@```0`` -M`0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`*(```````"B``@`````"`!L -M"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`*0````` -M``"D``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X``````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````&8`I``````` -M`*0`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&8`HP```````*,`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`````! -M```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`:4```````"E -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````9@"E````````I0`(``````@`;`L6"0P-X`(```$` -M``$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8`````!@` -M;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!I``` -M`````*0`;`"F````````I@`(``````@`;`L6"0P-X`(```$```$!05)2!0&) -M3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!F`*8````` -M``"F``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!F`*4```````"E``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!L`*<```````"G``@`````"`!L"Q8)#`W@`@`` -M`0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````&8`IP```````*<`"``````(`&P+%@D,#>`"```! -M```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`I@```````*8`"``````( -M`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`J``` -M`````*@`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````9@"H```` -M````J``(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``9@"G````````IP`(``````@`;`L6"0P-X`(```$```$!`5)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``;`"I````````J0`(``````@`;`L6"0P-X`(` -M``$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````!F`*D```````"I``@`````"`!L"Q8)#`W@`@`` -M`0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`*@```````"H``@````` -M"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`*H` -M``````"J``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X``````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````&8`J@`` -M`````*H`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&8`J0```````*D`"``````(`&P+%@D,#>`"```!```!`0%24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D,#>`` -M```!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`:L````` -M``"K```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````9@"K````````JP`(``````@`;`L6"0P-X`(` -M``$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8```` -M`!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P```````"/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P! -MJ@```````*H`;`"L````````K``(``````@`;`L6"0P-X`(```$```$!05)2 -M!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!F`*P` -M``````"L``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!F`*L```````"K``@`````"`!L"Q8)#`W@`@```0```0$!4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`*T```````"M``@`````"`!L"Q8)#`W@ -M`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````&8`K0```````*T`"``````(`&P+%@D,#>`" -M```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`K````````*P`"``` -M```(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P` -MK@```````*X`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````9@"N -M````````K@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``9@"M````````K0`(``````@`;`L6"0P-X`(```$```$!`5)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`"O````````KP`(``````@`;`L6"0P- -MX`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````!F`*\```````"O``@`````"`!L"Q8)#`W@ -M`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`*X```````"N``@` -M````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L -M`+````````"P``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````&8` -ML````````+``"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&8`KP```````*\`"``````(`&P+%@D,#>`"```!```!`0%2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+%@D, -M#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`;$` -M``````"Q```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````9@"Q````````L0`(``````@`;`L6"0P- -MX`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>````````'@`8 -M`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P`````` -M`"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!0 -M3`P!L````````+``;`"R````````L@`(``````@`;`L6"0P-X`(```$```$! -M05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!F -M`+(```````"R``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!F`+$```````"Q``@`````"`!L"Q8)#`W@`@```0```0$! -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`+,```````"S``@`````"`!L"Q8) -M#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````&8`LP```````+,`"``````(`&P+%@D, -M#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`L@```````+(` -M"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&P`M````````+0`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y-!@$` -M05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M9@"T````````M``(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``9@"S````````LP`(``````@`;`L6"0P-X`(```$```$! -M`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`"U````````M0`(``````@`;`L6 -M"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````!F`+4```````"U``@`````"`!L"Q8) -M#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`+0```````"T -M``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!L`+8```````"V``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308! -M`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`&8`M@```````+8`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&8`M0```````+4`"``````(`&P+%@D,#>`"```!```! -M`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L``````````&P+ -M%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@0TP, -M`;<```````"W```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````9@"W````````MP`(``````@`;`L6 -M"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>```````` -M'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M(P`` -M`````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>!03`P!M@```````+8`;`"X````````N``(``````@`;`L6"0P-X`(```$` -M``$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``!F`+@```````"X``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!F`+<```````"W``@`````"`!L"Q8)#`W@`@```0`` -M`0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`+D```````"Y``@`````"`!L -M"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````&8`N0```````+D`"``````(`&P+ -M%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`N``````` -M`+@`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&P`N@```````+H`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````9@"Z````````N@`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``9@"Y````````N0`(``````@`;`L6"0P-X`(```$` -M``$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`"[````````NP`(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````!F`+L```````"[``@`````"`!L -M"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`+H````` -M``"Z``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!L`+P```````"\``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E. -M308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````&8`O````````+P`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&8`NP```````+L`"``````(`&P+%@D,#>`"```! -M```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L````````` -M`&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M0TP,`;T```````"]```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````9@"]````````O0`(``````@` -M;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`>```` -M````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!`````$'M -M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>!03`P!O````````+P`;`"^````````O@`(``````@`;`L6"0P-X`(` -M``$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````!F`+X```````"^``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!F`+T```````"]``@`````"`!L"Q8)#`W@`@`` -M`0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`+\```````"_``@````` -M"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX``````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````&8`OP```````+\`"``````( -M`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`O@`` -M`````+X`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&P`P````````,``"``````(`&P+%@D,#>`"```!```!`4%24@4! -MB4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````9@#`````````P``(``````@`;`L6"0P-X`(```$```$!`%)2!0&! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``9@"_````````OP`(``````@`;`L6"0P-X`(` -M``$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#!````````P0`(```` -M``@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!F`,$```````#!``@````` -M"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`,`` -M``````#```@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!L`,(```````#"``@`````"`!L"Q8)#`W@`@```0```0%!4E(% -M`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````&8`P@```````,(`"``````(`&P+%@D,#>`"```!```!`0!24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&8`P0```````,$`"``````(`&P+%@D,#>`" -M```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L````` -M`````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@0TP,`<,```````##```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````9@##````````PP`(```` -M``@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``<@`> -M````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U!```` -M`$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>!03`P!P@```````,(`;`#$````````Q``(``````@`;`L6"0P- -MX`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````!F`,0```````#$``@`````"`!L"Q8)#`W@`@```0```0$`4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`,,```````##``@`````"`!L"Q8)#`W@ -M`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`,4```````#%``@` -M````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X``````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````&8`Q0```````,4`"``` -M```(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8` -MQ````````,0`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&P`Q@```````,8`"``````(`&P+%@D,#>`"```!```!`4%2 -M4@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````9@#&````````Q@`(``````@`;`L6"0P-X`(```$```$!`%)2 -M!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#%````````Q0`(``````@`;`L6"0P- -MX`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#'````````QP`( -M``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!F`,<```````#'``@` -M````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F -M`,8```````#&``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!L`,@```````#(``@`````"`!L"Q8)#`W@`@```0```0%! -M4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````&8`R````````,@`"``````(`&P+%@D,#>`"```!```!`0!2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`QP```````,<`"``````(`&P+%@D, -M#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$``````;L` -M`````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@0TP,`U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D`>U! -M`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>!03`P!R````````,@`;`#*````````R@`(``````@`;`L6 -M"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````!F`,H```````#*``@`````"`!L"Q8)#`W@`@```0```0$` -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`,D```````#)``@`````"`!L"Q8) -M#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`,L```````#+ -M``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X``````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&8`RP```````,L` -M"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`&8`R@```````,H`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&P`S````````,P`"``````(`&P+%@D,#>`"```!```! -M`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````9@#,````````S``(``````@`;`L6"0P-X`(```$```$! -M`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#+````````RP`(``````@`;`L6 -M"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#-```````` -MS0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````!F`,T```````#- -M``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#```` -M`````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!F`,P```````#,``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!L`,X```````#.``@`````"`!L"Q8)#`W@`@```0`` -M`0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````&8`S@```````,X`"``````(`&P+%@D,#>`"```!```! -M`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`S0```````,T`"``````(`&P+ -M%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$````` -M`;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@0TP,`<\```````#/```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````9@#/```````` -MSP`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A4%@D -M`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>!03`P!S@```````,X`;`#0````````T``(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````!F`-````````#0``@`````"`!L"Q8)#`W@`@```0`` -M`0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`,\```````#/``@`````"`!L -M"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`-$````` -M``#1``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X``````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````&8`T0`````` -M`-$`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&8`T````````-``"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&P`T@```````-(`"``````(`&P+%@D,#>`"```! -M```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````9@#2````````T@`(``````@`;`L6"0P-X`(```$` -M``$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#1````````T0`(``````@` -M;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`` -M```#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#3```` -M````TP`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U! -M`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!F`-,````` -M``#3``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!F`-(```````#2``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!L`-0```````#4``@`````"`!L"Q8)#`W@`@`` -M`0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````&8`U````````-0`"``````(`&P+%@D,#>`"```! -M```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`TP```````-,`"``````( -M`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@`NP$` -M`````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@0TP,`=4```````#5```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````9@#5```` -M````U0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2!0&A -M4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>!03`P!U````````-0`;`#6````````U@`(```` -M``@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````!F`-8```````#6``@`````"`!L"Q8)#`W@`@`` -M`0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`-4```````#5``@````` -M"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`-<` -M``````#7``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X``````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````&8`UP`` -M`````-<`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!! -M[0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L -M"Q8)#`W@`&8`U@```````-8`"``````(`&P+%@D,#>`"```!```!`0%24@4! -M@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@`&P`V````````-@`"``````(`&P+%@D,#>`" -M```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````9@#8````````V``(``````@`;`L6"0P-X`(` -M``$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#7````````UP`(```` -M``@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H -M`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#9 -M````````V0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!F`-D` -M``````#9``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$````` -M0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@ -M;`L6"0P-X`!F`-@```````#8``@`````"`!L"Q8)#`W@`@```0```0$!4E(% -M`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`-H```````#:``@`````"`!L"Q8)#`W@ -M`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````&8`V@```````-H`"``````(`&P+%@D,#>`" -M```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@````` -M`````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`V0```````-D`"``` -M```(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`'@` -MNP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$`05!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@0TP,`=L```````#;```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````9@#; -M````````VP`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U!```` -M`$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P- -MX&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$!`5)2 -M!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!V@```````-H`;`#<````````W``( -M``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M -M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+ -M%@D,#>`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````!F`-P```````#<``@`````"`!L"Q8)#`W@ -M`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```` -M``````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`-L```````#;``@` -M````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L -M`-T```````#=``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````&8` -MW0```````-T`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M00`` -M``!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D, -M#>!L"Q8)#`W@`&8`W````````-P`"``````(`&P+%@D,#>`"```!```!`0%2 -M4@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`W@```````-X`"``````(`&P+%@D, -M#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````#Z`,` -M`````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````9@#>````````W@`(``````@`;`L6"0P- -MX`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``` -M````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#=````````W0`( -M``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M;`#?````````WP`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!! -M4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!F -M`-\```````#?``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$` -M````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8) -M#`W@;`L6"0P-X`!F`-X```````#>``@`````"`!L"Q8)#`W@`@```0```0$! -M4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`.````````#@``@`````"`!L"Q8) -M#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#`````````^@# -M``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````&8`X````````.``"``````(`&P+%@D, -M#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,``````^@` -M`````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`WP```````-\` -M"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,````` -M```#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@ -M`'@`NP$``````;L``````````&P+%@D,#>`````!```!`4%24@4!F4Y-!@$` -M05!8)`'M00````!![0(````````"Z`,``````^@``````````%1&&@$.;`L6 -M"0P-X&P+%@D,#>!L"Q8)#`W@0TP,`>$```````#A```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M9@#A````````X0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D`>U! -M`````$'M`@````````+H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6 -M"0P-X&P+%@D,#>``<@`>````````'@`8`````!@`;`L6"0P-X`(```$```$! -M`5)2!0&A4%@D`>U!`````$'M(P```````"/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>!03`P!X````````.`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````!F`.(```````#B``@`````"`!L"Q8) -M#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#``````/H -M``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`!P````````< -M``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T%```` -M````!>@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P- -MX`!L`.,```````#C``@`````"`!L"Q8)#`W@`@```0```0%!4E(%`8E.308! -M`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+ -M%@D,#>!L"Q8)#`W@;`L6"0P-X``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`&8`XP```````.,`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8)`'M -M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+ -M%@D,#>!L"Q8)#`W@`&8`X@```````.(`"``````(`&P+%@D,#>`"```!```! -M`0%24@4!@5!8)`'M00````!![0,````````#Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&P`Y````````.0`"``````(`&P+ -M%@D,#>`"```!```!`4%24@4!B4Y-!@$`05!8)`'M00````!![0,````````# -MZ`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````9@#D````````Y``(``````@`;`L6 -M"0P-X`(```$```$!`%)2!0&!4%@D`>U!`````$'M`P````````/H`P`````# -MZ```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``9@#C```````` -MXP`(``````@`;`L6"0P-X`(```$```$!`5)2!0&!4%@D`>U!`````$'M`P`` -M``````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D, -M#>``;`#E````````Y0`(``````@`;`L6"0P-X`(```$```$!05)2!0&)3DT& -M`0!!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL -M"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``!F`.4```````#E``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%06"0! -M[4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L -M"Q8)#`W@;`L6"0P-X`!F`.0```````#D``@`````"`!L"Q8)#`W@`@```0`` -M`0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H``````````!4 -M1AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!L`.8```````#F``@`````"`!L -M"Q8)#`W@`@```0```0%!4E(%`8E.308!`$%06"0![4$`````0>T#```````` -M`^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X``` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````&8`Y@```````.8`"``````(`&P+ -M%@D,#>`"```!```!`0!24@4!@5!8)`'M00````!![0,````````#Z`,````` -M`^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`&8`Y0`````` -M`.4`"``````(`&P+%@D,#>`"```!```!`0%24@4!@5!8)`'M00````!![0,` -M```````#Z`,``````^@``````````%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8) -M#`W@`&P`YP```````.<`"``````(`&P+%@D,#>`"```!```!`4%24@4!B4Y- -M!@$`05!8)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$. -M;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````9@#G````````YP`(``````@`;`L6"0P-X`(```$```$!`%)2!0&!4%@D -M`>U!`````$'M`P````````/H`P`````#Z```````````5$8:`0YL"Q8)#`W@ -M;`L6"0P-X&P+%@D,#>``9@#F````````Y@`(``````@`;`L6"0P-X`(```$` -M``$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````````` -M5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>``;`#H````````Z``(``````@` -M;`L6"0P-X`(```$```$!05)2!0&)3DT&`0!!4%@D`>U!`````$'M`P`````` -M``/H`P`````#Z```````````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````!F`.@```````#H``@`````"`!L -M"Q8)#`W@`@```0```0$`4E(%`8%06"0![4$`````0>T#`````````^@#```` -M``/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`!F`.<````` -M``#G``@`````"`!L"Q8)#`W@`@```0```0$!4E(%`8%06"0![4$`````0>T# -M`````````^@#``````/H``````````!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6 -M"0P-X`!X`+L!``````&[``````````!L"Q8)#`W@`````0```0%!4E(%`9E. -M308!`$%06"0![4$`````0>T#`````````^@#``````/H``````````!41AH! -M#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X$-,#`$A````````(0`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````&8`Z0```````.D`"``````(`&P+%@D,#>`"```!```!`0!24@4!@5!8 -M)`'M00````!![0,````````#Z`,``````^@``````````%1&&@$.;`L6"0P- -MX&P+%@D,#>!L"Q8)#`W@`&8`'````````!P`"``````(`&P+%@D,#>`"```! -M```!`0%24@4!@5!8)`'M00````!![04````````%Z`,``````^@````````` -M`%1&&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@`/@`ZP```````.L`"``````( -M`&P+%@D,#>`"```!```!'T%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%24@4!B4Y-EP$!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%#11P!Z@```````.H``````````+`` -M``````"P```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````3DUR`0!!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!4%@D`>U!`````$'M`P````````/H`P`````#Z```````````5$8: -M`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````!F`.L```````#K``@`````"`!L"Q8)#`W@`@```0```0$`4E(%`8%0 -M6"0![4$`````0>T#`````````^@#``````/H``````````!41AH!#FP+%@D, -M#>!L"Q8)#`W@;`L6"0P-X`!F`.D```````#I``@`````"`!L"Q8)#`W@`@`` -M`0```0$!4E(%`8%06"0![4$`````0>T#`````````^@#``````/H```````` -M``!41AH!#FP+%@D,#>!L"Q8)#`W@;`L6"0P-X`#X`.T```````#M``@````` -M"`!L"Q8)#`W@`@```0```1]!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!4E(%`8E.39P```````#L``````````"P -M````````L``````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````$Y-<@$`04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%!04%! -M04%!04%!05!8)`'M00````!![0(````````"Z`,``````^@``````````%1& -M&@$.;`L6"0P-X&P+%@D,#>!L"Q8)#`W@```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````9@#M````````[0`(``````@`;`L6"0P-X`(```$```$!`%)2!0&! -M4%@D`>U!`````$'M`@````````+H`P`````#Z```````````5$8:`0YL"Q8) -M#`W@;`L6"0P-X&P+%@D,#>``9@#K````````ZP`(``````@`;`L6"0P-X`(` -M``$```$!`5)2!0&!4%@D`>U!`````$'M`P````````/H`P`````#Z``````` -M````5$8:`0YL"Q8)#`W@;`L6"0P-X&P+%@D,#>`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````B`.X```````#N``@````` -M"`!L"Q8)#`W@`@```0```0$`(@#N````````[@`(``````@`;`L6"0P-X`(` -M``$```$!`20`L`$``````;``"``````(`&P+%@D,#>`"```!```!`@!!`*(` -MMP$``````;<`"``````(`&P+%@D,#>`"```!```!@`!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````"(`[P```````.\`"``````(`&P+%@D,#>`"```!```!`0`B`+8! -M``````&V``@`````"`!L"Q8)#`W@`@```0```0$!)`#P````````\``(```` -M``@`;`L6"0P-X`(```$```$"`$$````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````(@#P````````\``(```` -M``@`;`L6"0P-X`(```$```$!`"(`[P```````.\`"``````(`&P+%@D,#>`" -M```!```!`0$D`/$```````#Q``@`````"`!L"Q8)#`W@`@```0```0(`00`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````B`/$```````#Q``@`````"`!L"Q8)#`W@`@```0```0$`(@#P -M````````\``(``````@`;`L6"0P-X`(```$```$!`20`\@```````/(`"``` -M```(`&P+%@D,#>`"```!```!`@!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````"(`\@```````/(`"``` -M```(`&P+%@D,#>`"```!```!`0`B`/$```````#Q``@`````"`!L"Q8)#`W@ -M`@```0```0$!)`#S````````\P`(``````@`;`L6"0P-X`(```$```$"`$$` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````(@#S````````\P`(``````@`;`L6"0P-X`(```$```$!`"(` -M\@```````/(`"``````(`&P+%@D,#>`"```!```!`0$D`/0```````#T``@` -M````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````B`/0```````#T``@` -M````"`!L"Q8)#`W@`@```0```0$`(@#S````````\P`(``````@`;`L6"0P- -MX`(```$```$!`20`]0```````/4`"``````(`&P+%@D,#>`"```!```!`@!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"(`]0```````/4`"``````(`&P+%@D,#>`"```!```!`0`B -M`/0```````#T``@`````"`!L"Q8)#`W@`@```0```0$!)`#V````````]@`( -M``````@`;`L6"0P-X`(```$```$"`$$````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````(@#V````````]@`( -M``````@`;`L6"0P-X`(```$```$!`"(`]0```````/4`"``````(`&P+%@D, -M#>`"```!```!`0$D`/<```````#W``@`````"`!L"Q8)#`W@`@```0```0(` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````B`/<```````#W``@`````"`!L"Q8)#`W@`@```0```0$` -M(@#V````````]@`(``````@`;`L6"0P-X`(```$```$!`20`^````````/@` -M"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````"(`^````````/@` -M"``````(`&P+%@D,#>`"```!```!`0`B`/<```````#W``@`````"`!L"Q8) -M#`W@`@```0```0$!)`#Y````````^0`(``````@`;`L6"0P-X`(```$```$" -M`$$````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````(@#Y````````^0`(``````@`;`L6"0P-X`(```$```$! -M`"(`^````````/@`"``````(`&P+%@D,#>`"```!```!`0$D`/H```````#Z -M``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````B`/H```````#Z -M``@`````"`!L"Q8)#`W@`@```0```0$`(@#Y````````^0`(``````@`;`L6 -M"0P-X`(```$```$!`20`^P```````/L`"``````(`&P+%@D,#>`"```!```! -M`@!!```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````"(`^P```````/L`"``````(`&P+%@D,#>`"```!```! -M`0`B`/H```````#Z``@`````"`!L"Q8)#`W@`@```0```0$!)`#\```````` -M_``(``````@`;`L6"0P-X`(```$```$"`$$````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````(@#\```````` -M_``(``````@`;`L6"0P-X`(```$```$!`"(`^P```````/L`"``````(`&P+ -M%@D,#>`"```!```!`0$D`/T```````#]``@`````"`!L"Q8)#`W@`@```0`` -M`0(`00`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````B`/T```````#]``@`````"`!L"Q8)#`W@`@```0`` -M`0$`(@#\````````_``(``````@`;`L6"0P-X`(```$```$!`20`_@`````` -M`/X`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````"(`_@`````` -M`/X`"``````(`&P+%@D,#>`"```!```!`0`B`/T```````#]``@`````"`!L -M"Q8)#`W@`@```0```0$!)`#_````````_P`(``````@`;`L6"0P-X`(```$` -M``$"`$$````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````(@#_````````_P`(``````@`;`L6"0P-X`(```$` -M``$!`"(`_@```````/X`"``````(`&P+%@D,#>`"```!```!`0$D```!```` -M``$```@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````B```!```` -M``$```@`````"`!L"Q8)#`W@`@```0```0$`(@#_````````_P`(``````@` -M;`L6"0P-X`(```$```$!`20``0$``````0$`"``````(`&P+%@D,#>`"```! -M```!`@!!```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````"(``0$``````0$`"``````(`&P+%@D,#>`"```! -M```!`0`B```!``````$```@`````"`!L"Q8)#`W@`@```0```0$!)``"`0`` -M```!`@`(``````@`;`L6"0P-X`(```$```$"`$$````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````(@`"`0`` -M```!`@`(``````@`;`L6"0P-X`(```$```$!`"(``0$``````0$`"``````( -M`&P+%@D,#>`"```!```!`0$D``,!``````$#``@`````"`!L"Q8)#`W@`@`` -M`0```0(`00`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````B``,!``````$#``@`````"`!L"Q8)#`W@`@`` -M`0```0$`(@`"`0`````!`@`(``````@`;`L6"0P-X`(```$```$!`20`!`$` -M`````00`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````"(`!`$` -M`````00`"``````(`&P+%@D,#>`"```!```!`0`B``,!``````$#``@````` -M"`!L"Q8)#`W@`@```0```0$!)``%`0`````!!0`(``````@`;`L6"0P-X`(` -M``$```$"`$$````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````(@`%`0`````!!0`(``````@`;`L6"0P-X`(` -M``$```$!`"(`!`$``````00`"``````(`&P+%@D,#>`"```!```!`0$D``8! -M``````$&``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````B``8! -M``````$&``@`````"`!L"Q8)#`W@`@```0```0$`(@`%`0`````!!0`(```` -M``@`;`L6"0P-X`(```$```$!`20`!P$``````0<`"``````(`&P+%@D,#>`" -M```!```!`@!!```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````"(`!P$``````0<`"``````(`&P+%@D,#>`" -M```!```!`0`B``8!``````$&``@`````"`!L"Q8)#`W@`@```0```0$!)``( -M`0`````!"``(``````@`;`L6"0P-X`(```$```$"`$$````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````(@`( -M`0`````!"``(``````@`;`L6"0P-X`(```$```$!`"(`!P$``````0<`"``` -M```(`&P+%@D,#>`"```!```!`0$D``D!``````$)``@`````"`!L"Q8)#`W@ -M`@```0```0(`00`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````B``D!``````$)``@`````"`!L"Q8)#`W@ -M`@```0```0$`(@`(`0`````!"``(``````@`;`L6"0P-X`(```$```$!`20` -M"@$``````0H`"``````(`&P+%@D,#>`"```!```!`@!!```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````"(` -M"@$``````0H`"``````(`&P+%@D,#>`"```!```!`0`B``D!``````$)``@` -M````"`!L"Q8)#`W@`@```0```0$!)``+`0`````!"P`(``````@`;`L6"0P- -MX`(```$```$"`$$````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````(@`+`0`````!"P`(``````@`;`L6"0P- -MX`(```$```$!`"(`"@$``````0H`"``````(`&P+%@D,#>`"```!```!`0$D -M``P!``````$,``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````B -M``P!``````$,``@`````"`!L"Q8)#`W@`@```0```0$`(@`+`0`````!"P`( -M``````@`;`L6"0P-X`(```$```$!`20`#0$``````0T`"``````(`&P+%@D, -M#>`"```!```!`@!!```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````"(`#0$``````0T`"``````(`&P+%@D, -M#>`"```!```!`0`B``P!``````$,``@`````"`!L"Q8)#`W@`@```0```0$! -M)``.`0`````!#@`(``````@`;`L6"0P-X`(```$```$"`$$````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M(@`.`0`````!#@`(``````@`;`L6"0P-X`(```$```$!`"(`#0$``````0T` -M"``````(`&P+%@D,#>`"```!```!`0$D``\!``````$/``@`````"`!L"Q8) -M#`W@`@```0```0(`00`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````B``\!``````$/``@`````"`!L"Q8) -M#`W@`@```0```0$`(@`.`0`````!#@`(``````@`;`L6"0P-X`(```$```$! -M`20`$`$``````1``"``````(`&P+%@D,#>`"```!```!`@!!```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"(`$`$``````1``"``````(`&P+%@D,#>`"```!```!`0`B``\!``````$/ -M``@`````"`!L"Q8)#`W@`@```0```0$!)``1`0`````!$0`(``````@`;`L6 -M"0P-X`(```$```$"`$$````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````(@`1`0`````!$0`(``````@`;`L6 -M"0P-X`(```$```$!`"(`$`$``````1``"``````(`&P+%@D,#>`"```!```! -M`0$D`!(!``````$2``@`````"`!L"Q8)#`W@`@```0```0(`00`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```B`!(!``````$2``@`````"`!L"Q8)#`W@`@```0```0$`(@`1`0`````! -M$0`(``````@`;`L6"0P-X`(```$```$!`20`$P$``````1,`"``````(`&P+ -M%@D,#>`"```!```!`@!!```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````"(`$P$``````1,`"``````(`&P+ -M%@D,#>`"```!```!`0`B`!(!``````$2``@`````"`!L"Q8)#`W@`@```0`` -M`0$!)``4`0`````!%``(``````@`;`L6"0P-X`(```$```$"`$$````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````(@`4`0`````!%``(``````@`;`L6"0P-X`(```$```$!`"(`$P$````` -M`1,`"``````(`&P+%@D,#>`"```!```!`0$D`!4!``````$5``@`````"`!L -M"Q8)#`W@`@```0```0(`00`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````B`!4!``````$5``@`````"`!L -M"Q8)#`W@`@```0```0$`(@`4`0`````!%``(``````@`;`L6"0P-X`(```$` -M``$!`20`%@$``````18`"``````(`&P+%@D,#>`"```!```!`@!!```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````"(`%@$``````18`"``````(`&P+%@D,#>`"```!```!`0`B`!4!```` -M``$5``@`````"`!L"Q8)#`W@`@```0```0$!)``7`0`````!%P`(``````@` -M;`L6"0P-X`(```$```$"`$$````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````(@`7`0`````!%P`(``````@` -M;`L6"0P-X`(```$```$!`"(`%@$``````18`"``````(`&P+%@D,#>`"```! -M```!`0$D`!@!``````$8``@`````"`!L"Q8)#`W@`@```0```0(`00`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````B`!@!``````$8``@`````"`!L"Q8)#`W@`@```0```0$`(@`7`0`` -M```!%P`(``````@`;`L6"0P-X`(```$```$!`20`&0$``````1D`"``````( -M`&P+%@D,#>`"```!```!`@!!```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````"(`&0$``````1D`"``````( -M`&P+%@D,#>`"```!```!`0`B`!@!``````$8``@`````"`!L"Q8)#`W@`@`` -M`0```0$!)``:`0`````!&@`(``````@`;`L6"0P-X`(```$```$"`$$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````(@`:`0`````!&@`(``````@`;`L6"0P-X`(```$```$!`"(`&0$` -M`````1D`"``````(`&P+%@D,#>`"```!```!`0$D`!L!``````$;``@````` -M"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````B`!L!``````$;``@````` -M"`!L"Q8)#`W@`@```0```0$`(@`:`0`````!&@`(``````@`;`L6"0P-X`(` -M``$```$!`20`'`$``````1P`"``````(`&P+%@D,#>`"```!```!`@!!```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````"(`'`$``````1P`"``````(`&P+%@D,#>`"```!```!`0`B`!L! -M``````$;``@`````"`!L"Q8)#`W@`@```0```0$!)``=`0`````!'0`(```` -M``@`;`L6"0P-X`(```$```$"`$$````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````(@`=`0`````!'0`(```` -M``@`;`L6"0P-X`(```$```$!`"(`'`$``````1P`"``````(`&P+%@D,#>`" -M```!```!`0$D`!X!``````$>``@`````"`!L"Q8)#`W@`@```0```0(`00`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````B`!X!``````$>``@`````"`!L"Q8)#`W@`@```0```0$`(@`= -M`0`````!'0`(``````@`;`L6"0P-X`(```$```$!`20`'P$``````1\`"``` -M```(`&P+%@D,#>`"```!```!`@!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````"(`'P$``````1\`"``` -M```(`&P+%@D,#>`"```!```!`0`B`!X!``````$>``@`````"`!L"Q8)#`W@ -M`@```0```0$!)``@`0`````!(``(``````@`;`L6"0P-X`(```$```$"`$$` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````(@`@`0`````!(``(``````@`;`L6"0P-X`(```$```$!`"(` -M'P$``````1\`"``````(`&P+%@D,#>`"```!```!`0$D`"$!``````$A``@` -M````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````B`"$!``````$A``@` -M````"`!L"Q8)#`W@`@```0```0$`(@`@`0`````!(``(``````@`;`L6"0P- -MX`(```$```$!`20`(@$``````2(`"``````(`&P+%@D,#>`"```!```!`@!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"(`(@$``````2(`"``````(`&P+%@D,#>`"```!```!`0`B -M`"$!``````$A``@`````"`!L"Q8)#`W@`@```0```0$!)``C`0`````!(P`( -M``````@`;`L6"0P-X`(```$```$"`$$````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````(@`C`0`````!(P`( -M``````@`;`L6"0P-X`(```$```$!`"(`(@$``````2(`"``````(`&P+%@D, -M#>`"```!```!`0$D`"0!``````$D``@`````"`!L"Q8)#`W@`@```0```0(` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````B`"0!``````$D``@`````"`!L"Q8)#`W@`@```0```0$` -M(@`C`0`````!(P`(``````@`;`L6"0P-X`(```$```$!`20`)0$``````24` -M"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````"(`)0$``````24` -M"``````(`&P+%@D,#>`"```!```!`0`B`"0!``````$D``@`````"`!L"Q8) -M#`W@`@```0```0$!)``F`0`````!)@`(``````@`;`L6"0P-X`(```$```$" -M`$$````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````(@`F`0`````!)@`(``````@`;`L6"0P-X`(```$```$! -M`"(`)0$``````24`"``````(`&P+%@D,#>`"```!```!`0$D`"`"```!```! -M`@!!```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````"(`*`$``````2@`"``````(`&P+%@D,#>`"```!```! -M`0`B`"`"```!```!`0$D`"H!``````$J``@`````"`!L"Q8)#`W@`@```0`` -M`0(`00`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````B`"H!``````$J``@`````"`!L"Q8)#`W@`@```0`` -M`0$`(@`I`0`````!*0`(``````@`;`L6"0P-X`(```$```$!`20`*P$````` -M`2L`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````"(`*P$````` -M`2L`"``````(`&P+%@D,#>`"```!```!`0`B`"H!``````$J``@`````"`!L -M"Q8)#`W@`@```0```0$!)``L`0`````!+``(``````@`;`L6"0P-X`(```$` -M``$"`$$````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````(@`L`0`````!+``(``````@`;`L6"0P-X`(```$` -M``$!`"(`*P$``````2L`"``````(`&P+%@D,#>`"```!```!`0$D`"T!```` -M``$M``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````B`"T!```` -M``$M``@`````"`!L"Q8)#`W@`@```0```0$`(@`L`0`````!+``(``````@` -M;`L6"0P-X`(```$```$!`20`+@$``````2X`"``````(`&P+%@D,#>`"```! -M```!`@!!```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````"(`+@$``````2X`"``````(`&P+%@D,#>`"```! -M```!`0`B`"T!``````$M``@`````"`!L"Q8)#`W@`@```0```0$!)``O`0`` -M```!+P`(``````@`;`L6"0P-X`(```$```$"`$$````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````(@`O`0`` -M```!+P`(``````@`;`L6"0P-X`(```$```$!`"(`+@$``````2X`"``````( -M`&P+%@D,#>`"```!```!`0$D`#`!``````$P``@`````"`!L"Q8)#`W@`@`` -M`0```0(`00`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````B`#`!``````$P``@`````"`!L"Q8)#`W@`@`` -M`0```0$`(@`O`0`````!+P`(``````@`;`L6"0P-X`(```$```$!`20`,0$` -M`````3$`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````"(`,0$` -M`````3$`"``````(`&P+%@D,#>`"```!```!`0`B`#`!``````$P``@````` -M"`!L"Q8)#`W@`@```0```0$!)``R`0`````!,@`(``````@`;`L6"0P-X`(` -M``$```$"`$$````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````(@`R`0`````!,@`(``````@`;`L6"0P-X`(` -M``$```$!`"(`,0$``````3$`"``````(`&P+%@D,#>`"```!```!`0$D`#,! -M``````$S``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````B`#,! -M``````$S``@`````"`!L"Q8)#`W@`@```0```0$`(@`R`0`````!,@`(```` -M``@`;`L6"0P-X`(```$```$!`20`-`$``````30`"``````(`&P+%@D,#>`" -M```!```!`@!!```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````"(`-`$``````30`"``````(`&P+%@D,#>`" -M```!```!`0`B`#,!``````$S``@`````"`!L"Q8)#`W@`@```0```0$!)``U -M`0`````!-0`(``````@`;`L6"0P-X`(```$```$"`$$````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````(@`U -M`0`````!-0`(``````@`;`L6"0P-X`(```$```$!`"(`-`$``````30`"``` -M```(`&P+%@D,#>`"```!```!`0$D`#8!``````$V``@`````"`!L"Q8)#`W@ -M`@```0```0(`00`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````B`#8!``````$V``@`````"`!L"Q8)#`W@ -M`@```0```0$`(@`U`0`````!-0`(``````@`;`L6"0P-X`(```$```$!`20` -M-P$``````3<`"``````(`&P+%@D,#>`"```!```!`@!!```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````"(` -M-P$``````3<`"``````(`&P+%@D,#>`"```!```!`0`B`#8!``````$V``@` -M````"`!L"Q8)#`W@`@```0```0$!)``X`0`````!.``(``````@`;`L6"0P- -MX`(```$```$"`$$````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````(@`X`0`````!.``(``````@`;`L6"0P- -MX`(```$```$!`"(`-P$``````3<`"``````(`&P+%@D,#>`"```!```!`0$D -M`#D!``````$Y``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````B -M`#D!``````$Y``@`````"`!L"Q8)#`W@`@```0```0$`(@`X`0`````!.``( -M``````@`;`L6"0P-X`(```$```$!`20`.@$``````3H`"``````(`&P+%@D, -M#>`"```!```!`@!!```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````"(`.@$``````3H`"``````(`&P+%@D, -M#>`"```!```!`0`B`#D!``````$Y``@`````"`!L"Q8)#`W@`@```0```0$! -M)``[`0`````!.P`(``````@`;`L6"0P-X`(```$```$"`$$````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M(@`[`0`````!.P`(``````@`;`L6"0P-X`(```$```$!`"(`.@$``````3H` -M"``````(`&P+%@D,#>`"```!```!`0$D`#P!``````$\``@`````"`!L"Q8) -M#`W@`@```0```0(`00`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````B`#P!``````$\``@`````"`!L"Q8) -M#`W@`@```0```0$`(@`[`0`````!.P`(``````@`;`L6"0P-X`(```$```$! -M`20`/0$``````3T`"``````(`&P+%@D,#>`"```!```!`@!!```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"(`/0$``````3T`"``````(`&P+%@D,#>`"```!```!`0`B`#P!``````$\ -M``@`````"`!L"Q8)#`W@`@```0```0$!)``^`0`````!/@`(``````@`;`L6 -M"0P-X`(```$```$"`$$````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````(@`^`0`````!/@`(``````@`;`L6 -M"0P-X`(```$```$!`"(`/0$``````3T`"``````(`&P+%@D,#>`"```!```! -M`0$D`#\!``````$_``@`````"`!L"Q8)#`W@`@```0```0(`00`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```B`#\!``````$_``@`````"`!L"Q8)#`W@`@```0```0$`(@`^`0`````! -M/@`(``````@`;`L6"0P-X`(```$```$!`20`0`$``````4``"``````(`&P+ -M%@D,#>`"```!```!`@!!```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````"(`0`$``````4``"``````(`&P+ -M%@D,#>`"```!```!`0`B`#\!``````$_``@`````"`!L"Q8)#`W@`@```0`` -M`0$!)`!!`0`````!00`(``````@`;`L6"0P-X`(```$```$"`$$````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````(@!!`0`````!00`(``````@`;`L6"0P-X`(```$```$!`"(`0`$````` -M`4``"``````(`&P+%@D,#>`"```!```!`0$D`$(!``````%"``@`````"`!L -M"Q8)#`W@`@```0```0(`00`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````B`$(!``````%"``@`````"`!L -M"Q8)#`W@`@```0```0$`(@!!`0`````!00`(``````@`;`L6"0P-X`(```$` -M``$!`20`0P$``````4,`"``````(`&P+%@D,#>`"```!```!`@!!```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````"(`0P$``````4,`"``````(`&P+%@D,#>`"```!```!`0`B`$(!```` -M``%"``@`````"`!L"Q8)#`W@`@```0```0$!)`!$`0`````!1``(``````@` -M;`L6"0P-X`(```$```$"`$$````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````(@!$`0`````!1``(``````@` -M;`L6"0P-X`(```$```$!`"(`0P$``````4,`"``````(`&P+%@D,#>`"```! -M```!`0$D`$4!``````%%``@`````"`!L"Q8)#`W@`@```0```0(`00`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````B`$4!``````%%``@`````"`!L"Q8)#`W@`@```0```0$`(@!$`0`` -M```!1``(``````@`;`L6"0P-X`(```$```$!`20`1@$``````48`"``````( -M`&P+%@D,#>`"```!```!`@!!```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````"(`1@$``````48`"``````( -M`&P+%@D,#>`"```!```!`0`B`$4!``````%%``@`````"`!L"Q8)#`W@`@`` -M`0```0$!)`!'`0`````!1P`(``````@`;`L6"0P-X`(```$```$"`$$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````(@!'`0`````!1P`(``````@`;`L6"0P-X`(```$```$!`"(`1@$` -M`````48`"``````(`&P+%@D,#>`"```!```!`0$D`$@!``````%(``@````` -M"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````B`$@!``````%(``@````` -M"`!L"Q8)#`W@`@```0```0$`(@!'`0`````!1P`(``````@`;`L6"0P-X`(` -M``$```$!`20`20$``````4D`"``````(`&P+%@D,#>`"```!```!`@!!```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````"(`20$``````4D`"``````(`&P+%@D,#>`"```!```!`0`B`$@! -M``````%(``@`````"`!L"Q8)#`W@`@```0```0$!)`!*`0`````!2@`(```` -M``@`;`L6"0P-X`(```$```$"`$$````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````(@!*`0`````!2@`(```` -M``@`;`L6"0P-X`(```$```$!`"(`20$``````4D`"``````(`&P+%@D,#>`" -M```!```!`0$D`$L!``````%+``@`````"`!L"Q8)#`W@`@```0```0(`00`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````B`$L!``````%+``@`````"`!L"Q8)#`W@`@```0```0$`(@!* -M`0`````!2@`(``````@`;`L6"0P-X`(```$```$!`20`3`$``````4P`"``` -M```(`&P+%@D,#>`"```!```!`@!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````"(`3`$``````4P`"``` -M```(`&P+%@D,#>`"```!```!`0`B`$L!``````%+``@`````"`!L"Q8)#`W@ -M`@```0```0$!)`!-`0`````!30`(``````@`;`L6"0P-X`(```$```$"`$$` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````(@!-`0`````!30`(``````@`;`L6"0P-X`(```$```$!`"(` -M3`$``````4P`"``````(`&P+%@D,#>`"```!```!`0$D`$X!``````%.``@` -M````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````B`$X!``````%.``@` -M````"`!L"Q8)#`W@`@```0```0$`(@!-`0`````!30`(``````@`;`L6"0P- -MX`(```$```$!`20`3P$``````4\`"``````(`&P+%@D,#>`"```!```!`@!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"(`3P$``````4\`"``````(`&P+%@D,#>`"```!```!`0`B -M`$X!``````%.``@`````"`!L"Q8)#`W@`@```0```0$!)`!0`0`````!4``( -M``````@`;`L6"0P-X`(```$```$"`$$````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````(@!0`0`````!4``( -M``````@`;`L6"0P-X`(```$```$!`"(`3P$``````4\`"``````(`&P+%@D, -M#>`"```!```!`0$D`%$!``````%1``@`````"`!L"Q8)#`W@`@```0```0(` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````B`%$!``````%1``@`````"`!L"Q8)#`W@`@```0```0$` -M(@!0`0`````!4``(``````@`;`L6"0P-X`(```$```$!`20`4@$``````5(` -M"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````"(`4@$``````5(` -M"``````(`&P+%@D,#>`"```!```!`0`B`%$!``````%1``@`````"`!L"Q8) -M#`W@`@```0```0$!)`!3`0`````!4P`(``````@`;`L6"0P-X`(```$```$" -M`$$````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````(@!3`0`````!4P`(``````@`;`L6"0P-X`(```$```$! -M`"(`4@$``````5(`"``````(`&P+%@D,#>`"```!```!`0$D`%0!``````%4 -M``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````B`%0!``````%4 -M``@`````"`!L"Q8)#`W@`@```0```0$`(@!3`0`````!4P`(``````@`;`L6 -M"0P-X`(```$```$!`20`50$``````54`"``````(`&P+%@D,#>`"```!```! -M`@!!```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````"(`50$``````54`"``````(`&P+%@D,#>`"```!```! -M`0`B`%0!``````%4``@`````"`!L"Q8)#`W@`@```0```0$!)`!6`0`````! -M5@`(``````@`;`L6"0P-X`(```$```$"`$$````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````(@!6`0`````! -M5@`(``````@`;`L6"0P-X`(```$```$!`"(`50$``````54`"``````(`&P+ -M%@D,#>`"```!```!`0$D`%`"```!```!`@!!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````"(`6`$````` -M`5@`"``````(`&P+%@D,#>`"```!```!`0`B`%`"```!```!`0$D`%H!```` -M``%:``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````B`%H!```` -M``%:``@`````"`!L"Q8)#`W@`@```0```0$`(@!9`0`````!60`(``````@` -M;`L6"0P-X`(```$```$!`20`6P$``````5L`"``````(`&P+%@D,#>`"```! -M```!`@!!```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````"(`6P$``````5L`"``````(`&P+%@D,#>`"```! -M```!`0`B`%H!``````%:``@`````"`!L"Q8)#`W@`@```0```0$!)`!<`0`` -M```!7``(``````@`;`L6"0P-X`(```$```$"`$$````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````(@!<`0`` -M```!7``(``````@`;`L6"0P-X`(```$```$!`"(`6P$``````5L`"``````( -M`&P+%@D,#>`"```!```!`0$D`%T!``````%=``@`````"`!L"Q8)#`W@`@`` -M`0```0(`00`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````B`%T!``````%=``@`````"`!L"Q8)#`W@`@`` -M`0```0$`(@!<`0`````!7``(``````@`;`L6"0P-X`(```$```$!`20`7@$` -M`````5X`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````"(`7@$` -M`````5X`"``````(`&P+%@D,#>`"```!```!`0`B`%T!``````%=``@````` -M"`!L"Q8)#`W@`@```0```0$!)`!?`0`````!7P`(``````@`;`L6"0P-X`(` -M``$```$"`$$````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````(@!?`0`````!7P`(``````@`;`L6"0P-X`(` -M``$```$!`"(`7@$``````5X`"``````(`&P+%@D,#>`"```!```!`0$D`&`! -M``````%@``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````B`&`! -M``````%@``@`````"`!L"Q8)#`W@`@```0```0$`(@!?`0`````!7P`(```` -M``@`;`L6"0P-X`(```$```$!`20`80$``````6$`"``````(`&P+%@D,#>`" -M```!```!`@!!```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````"(`80$``````6$`"``````(`&P+%@D,#>`" -M```!```!`0`B`&`!``````%@``@`````"`!L"Q8)#`W@`@```0```0$!)`!B -M`0`````!8@`(``````@`;`L6"0P-X`(```$```$"`$$````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````(@!B -M`0`````!8@`(``````@`;`L6"0P-X`(```$```$!`"(`80$``````6$`"``` -M```(`&P+%@D,#>`"```!```!`0$D`&,!``````%C``@`````"`!L"Q8)#`W@ -M`@```0```0(`00`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````B`&,!``````%C``@`````"`!L"Q8)#`W@ -M`@```0```0$`(@!B`0`````!8@`(``````@`;`L6"0P-X`(```$```$!`20` -M9`$``````60`"``````(`&P+%@D,#>`"```!```!`@!!```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````"(` -M9`$``````60`"``````(`&P+%@D,#>`"```!```!`0`B`&,!``````%C``@` -M````"`!L"Q8)#`W@`@```0```0$!)`!E`0`````!90`(``````@`;`L6"0P- -MX`(```$```$"`$$````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````(@!E`0`````!90`(``````@`;`L6"0P- -MX`(```$```$!`"(`9`$``````60`"``````(`&P+%@D,#>`"```!```!`0$D -M`&8!``````%F``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````B -M`&8!``````%F``@`````"`!L"Q8)#`W@`@```0```0$`(@!E`0`````!90`( -M``````@`;`L6"0P-X`(```$```$!`20`9P$``````6<`"``````(`&P+%@D, -M#>`"```!```!`@!!```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````"(`9P$``````6<`"``````(`&P+%@D, -M#>`"```!```!`0`B`&8!``````%F``@`````"`!L"Q8)#`W@`@```0```0$! -M)`!H`0`````!:``(``````@`;`L6"0P-X`(```$```$"`$$````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M(@!H`0`````!:``(``````@`;`L6"0P-X`(```$```$!`"(`9P$``````6<` -M"``````(`&P+%@D,#>`"```!```!`0$D`&D!``````%I``@`````"`!L"Q8) -M#`W@`@```0```0(`00`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````B`&D!``````%I``@`````"`!L"Q8) -M#`W@`@```0```0$`(@!H`0`````!:``(``````@`;`L6"0P-X`(```$```$! -M`20`:@$``````6H`"``````(`&P+%@D,#>`"```!```!`@!!```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"(`:@$``````6H`"``````(`&P+%@D,#>`"```!```!`0`B`&D!``````%I -M``@`````"`!L"Q8)#`W@`@```0```0$!)`!K`0`````!:P`(``````@`;`L6 -M"0P-X`(```$```$"`$$````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````(@!K`0`````!:P`(``````@`;`L6 -M"0P-X`(```$```$!`"(`:@$``````6H`"``````(`&P+%@D,#>`"```!```! -M`0$D`&P!``````%L``@`````"`!L"Q8)#`W@`@```0```0(`00`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```B`&P!``````%L``@`````"`!L"Q8)#`W@`@```0```0$`(@!K`0`````! -M:P`(``````@`;`L6"0P-X`(```$```$!`20`;0$``````6T`"``````(`&P+ -M%@D,#>`"```!```!`@!!```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````"(`;0$``````6T`"``````(`&P+ -M%@D,#>`"```!```!`0`B`&P!``````%L``@`````"`!L"Q8)#`W@`@```0`` -M`0$!)`!N`0`````!;@`(``````@`;`L6"0P-X`(```$```$"`$$````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````(@!N`0`````!;@`(``````@`;`L6"0P-X`(```$```$!`"(`;0$````` -M`6T`"``````(`&P+%@D,#>`"```!```!`0$D`&\!``````%O``@`````"`!L -M"Q8)#`W@`@```0```0(`00`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````B`&\!``````%O``@`````"`!L -M"Q8)#`W@`@```0```0$`(@!N`0`````!;@`(``````@`;`L6"0P-X`(```$` -M``$!`20`<`$``````7``"``````(`&P+%@D,#>`"```!```!`@!!```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````"(`<`$``````7``"``````(`&P+%@D,#>`"```!```!`0`B`&\!```` -M``%O``@`````"`!L"Q8)#`W@`@```0```0$!)`!Q`0`````!<0`(``````@` -M;`L6"0P-X`(```$```$"`$$````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````(@!Q`0`````!<0`(``````@` -M;`L6"0P-X`(```$```$!`"(`<`$``````7``"``````(`&P+%@D,#>`"```! -M```!`0$D`'(!``````%R``@`````"`!L"Q8)#`W@`@```0```0(`00`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````B`'(!``````%R``@`````"`!L"Q8)#`W@`@```0```0$`(@!Q`0`` -M```!<0`(``````@`;`L6"0P-X`(```$```$!`20``"```!```!`@!!```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````"(``"```!```!`0`B`'(!``````%R``@`````"`!L"Q8)#`W@`@`` -M`0```0$!)`!T`0`````!=``(``````@`;`L6"0P-X`(```$```$"`$$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````(@!T`0`````!=``(``````@`;`L6"0P-X`(```$```$!`"(``"```!```!`0$D`'4!``````%U``@````` -M"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````B`'4!``````%U``@````` -M"`!L"Q8)#`W@`@```0```0$`(@!T`0`````!=``(``````@`;`L6"0P-X`(` -M``$```$!`20`=@$``````78`"``````(`&P+%@D,#>`"```!```!`@!!```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````"(`=@$``````78`"``````(`&P+%@D,#>`"```!```!`0`B`'4! -M``````%U``@`````"`!L"Q8)#`W@`@```0```0$!)`!W`0`````!=P`(```` -M``@`;`L6"0P-X`(```$```$"`$$````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````(@!W`0`````!=P`(```` -M``@`;`L6"0P-X`(```$```$!`"(`=@$``````78`"``````(`&P+%@D,#>`" -M```!```!`0$D`'@!``````%X``@`````"`!L"Q8)#`W@`@```0```0(`00`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````B`'@!``````%X``@`````"`!L"Q8)#`W@`@```0```0$`(@!W -M`0`````!=P`(``````@`;`L6"0P-X`(```$```$!`20`>0$``````7D`"``` -M```(`&P+%@D,#>`"```!```!`@!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````"(`>0$``````7D`"``` -M```(`&P+%@D,#>`"```!```!`0`B`'@!``````%X``@`````"`!L"Q8)#`W@ -M`@```0```0$!)`!Z`0`````!>@`(``````@`;`L6"0P-X`(```$```$"`$$` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````(@!Z`0`````!>@`(``````@`;`L6"0P-X`(```$```$!`"(` -M>0$``````7D`"``````(`&P+%@D,#>`"```!```!`0$D`'L!``````%[``@` -M````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````B`'L!``````%[``@` -M````"`!L"Q8)#`W@`@```0```0$`(@!Z`0`````!>@`(``````@`;`L6"0P- -MX`(```$```$!`20`?`$``````7P`"``````(`&P+%@D,#>`"```!```!`@!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"(`?`$``````7P`"``````(`&P+%@D,#>`"```!```!`0`B -M`'L!``````%[``@`````"`!L"Q8)#`W@`@```0```0$!)`!]`0`````!?0`( -M``````@`;`L6"0P-X`(```$```$"`$$````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````(@!]`0`````!?0`( -M``````@`;`L6"0P-X`(```$```$!`"(`?`$``````7P`"``````(`&P+%@D, -M#>`"```!```!`0$D`'X!``````%^``@`````"`!L"Q8)#`W@`@```0```0(` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````B`'X!``````%^``@`````"`!L"Q8)#`W@`@```0```0$` -M(@!]`0`````!?0`(``````@`;`L6"0P-X`(```$```$!`20`?P$``````7\` -M"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````"(`?P$``````7\` -M"``````(`&P+%@D,#>`"```!```!`0`B`'X!``````%^``@`````"`!L"Q8) -M#`W@`@```0```0$!)`"``0`````!@``(``````@`;`L6"0P-X`(```$```$" -M`$$````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````(@"``0`````!@``(``````@`;`L6"0P-X`(```$```$! -M`"(`?P$``````7\`"``````(`&P+%@D,#>`"```!```!`0$D`($!``````&! -M``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````B`($!``````&! -M``@`````"`!L"Q8)#`W@`@```0```0$`(@"``0`````!@``(``````@`;`L6 -M"0P-X`(```$```$!`20`@@$``````8(`"``````(`&P+%@D,#>`"```!```! -M`@!!```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````"(`@@$``````8(`"``````(`&P+%@D,#>`"```!```! -M`0`B`($!``````&!``@`````"`!L"Q8)#`W@`@```0```0$!)`"#`0`````! -M@P`(``````@`;`L6"0P-X`(```$```$"`$$````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````(@"#`0`````! -M@P`(``````@`;`L6"0P-X`(```$```$!`"(`@@$``````8(`"``````(`&P+ -M%@D,#>`"```!```!`0$D`(0!``````&$``@`````"`!L"Q8)#`W@`@```0`` -M`0(`00`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````B`(0!``````&$``@`````"`!L"Q8)#`W@`@```0`` -M`0$`(@"#`0`````!@P`(``````@`;`L6"0P-X`(```$```$!`20`A0$````` -M`84`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````"(`A0$````` -M`84`"``````(`&P+%@D,#>`"```!```!`0`B`(0!``````&$``@`````"`!L -M"Q8)#`W@`@```0```0$!)`"&`0`````!A@`(``````@`;`L6"0P-X`(```$` -M``$"`$$````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````(@"&`0`````!A@`(``````@`;`L6"0P-X`(```$` -M``$!`"(`A0$``````84`"``````(`&P+%@D,#>`"```!```!`0$D`(`"```! -M```!`@!!```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````"(`B`$``````8@`"``````(`&P+%@D,#>`"```! -M```!`0`B`(`"```!```!`0$D`(H!``````&*``@`````"`!L"Q8)#`W@`@`` -M`0```0(`00`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````B`(H!``````&*``@`````"`!L"Q8)#`W@`@`` -M`0```0$`(@")`0`````!B0`(``````@`;`L6"0P-X`(```$```$!`20`BP$` -M`````8L`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````"(`BP$` -M`````8L`"``````(`&P+%@D,#>`"```!```!`0`B`(H!``````&*``@````` -M"`!L"Q8)#`W@`@```0```0$!)`",`0`````!C``(``````@`;`L6"0P-X`(` -M``$```$"`$$````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````(@",`0`````!C``(``````@`;`L6"0P-X`(` -M``$```$!`"(`BP$``````8L`"``````(`&P+%@D,#>`"```!```!`0$D`(T! -M``````&-``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````B`(T! -M``````&-``@`````"`!L"Q8)#`W@`@```0```0$`(@",`0`````!C``(```` -M``@`;`L6"0P-X`(```$```$!`20`C@$``````8X`"``````(`&P+%@D,#>`" -M```!```!`@!!```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````"(`C@$``````8X`"``````(`&P+%@D,#>`" -M```!```!`0`B`(T!``````&-``@`````"`!L"Q8)#`W@`@```0```0$!)`"/ -M`0`````!CP`(``````@`;`L6"0P-X`(```$```$"`$$````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````````(@"/ -M`0`````!CP`(``````@`;`L6"0P-X`(```$```$!`"(`C@$``````8X`"``` -M```(`&P+%@D,#>`"```!```!`0$D`)`!``````&0``@`````"`!L"Q8)#`W@ -M`@```0```0(`00`````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````B`)`!``````&0``@`````"`!L"Q8)#`W@ -M`@```0```0$`(@"/`0`````!CP`(``````@`;`L6"0P-X`(```$```$!`20` -MD0$``````9$`"``````(`&P+%@D,#>`"```!```!`@!!```````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````````"(` -MD0$``````9$`"``````(`&P+%@D,#>`"```!```!`0`B`)`!``````&0``@` -M````"`!L"Q8)#`W@`@```0```0$!)`"2`0`````!D@`(``````@`;`L6"0P- -MX`(```$```$"`$$````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````(@"2`0`````!D@`(``````@`;`L6"0P- -MX`(```$```$!`"(`D0$``````9$`"``````(`&P+%@D,#>`"```!```!`0$D -M`),!``````&3``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````B -M`),!``````&3``@`````"`!L"Q8)#`W@`@```0```0$`(@"2`0`````!D@`( -M``````@`;`L6"0P-X`(```$```$!`20`E`$``````90`"``````(`&P+%@D, -M#>`"```!```!`@!!```````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````"(`E`$``````90`"``````(`&P+%@D, -M#>`"```!```!`0`B`),!``````&3``@`````"`!L"Q8)#`W@`@```0```0$! -M)`"5`0`````!E0`(``````@`;`L6"0P-X`(```$```$"`$$````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M(@"5`0`````!E0`(``````@`;`L6"0P-X`(```$```$!`"(`E`$``````90` -M"``````(`&P+%@D,#>`"```!```!`0$D`)8!``````&6``@`````"`!L"Q8) -M#`W@`@```0```0(`00`````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````B`)8!``````&6``@`````"`!L"Q8) -M#`W@`@```0```0$`(@"5`0`````!E0`(``````@`;`L6"0P-X`(```$```$! -M`20`EP$``````9<`"``````(`&P+%@D,#>`"```!```!`@!!```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"(`EP$``````9<`"``````(`&P+%@D,#>`"```!```!`0`B`)8!``````&6 -M``@`````"`!L"Q8)#`W@`@```0```0$!)`"8`0`````!F``(``````@`;`L6 -M"0P-X`(```$```$"`$$````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````(@"8`0`````!F``(``````@`;`L6 -M"0P-X`(```$```$!`"(`EP$``````9<`"``````(`&P+%@D,#>`"```!```! -M`0$D`)D!``````&9``@`````"`!L"Q8)#`W@`@```0```0(`00`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```B`)D!``````&9``@`````"`!L"Q8)#`W@`@```0```0$`(@"8`0`````! -MF``(``````@`;`L6"0P-X`(```$```$!`20`F@$``````9H`"``````(`&P+ -M%@D,#>`"```!```!`@!!```````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````"(`F@$``````9H`"``````(`&P+ -M%@D,#>`"```!```!`0`B`)D!``````&9``@`````"`!L"Q8)#`W@`@```0`` -M`0$!)`";`0`````!FP`(``````@`;`L6"0P-X`(```$```$"`$$````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````(@";`0`````!FP`(``````@`;`L6"0P-X`(```$```$!`"(`F@$````` -M`9H`"``````(`&P+%@D,#>`"```!```!`0$D`)P!``````&<``@`````"`!L -M"Q8)#`W@`@```0```0(`00`````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````B`)P!``````&<``@`````"`!L -M"Q8)#`W@`@```0```0$`(@";`0`````!FP`(``````@`;`L6"0P-X`(```$` -M``$!`20`G0$``````9T`"``````(`&P+%@D,#>`"```!```!`@!!```````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````"(`G0$``````9T`"``````(`&P+%@D,#>`"```!```!`0`B`)P!```` -M``&<``@`````"`!L"Q8)#`W@`@```0```0$!)`">`0`````!G@`(``````@` -M;`L6"0P-X`(```$```$"`$$````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````(@">`0`````!G@`(``````@` -M;`L6"0P-X`(```$```$!`"(`G0$``````9T`"``````(`&P+%@D,#>`"```! -M```!`0$D`)\!``````&?``@`````"`!L"Q8)#`W@`@```0```0(`00`````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````B`)\!``````&?``@`````"`!L"Q8)#`W@`@```0```0$`(@">`0`` -M```!G@`(``````@`;`L6"0P-X`(```$```$!`20`H`$``````:``"``````( -M`&P+%@D,#>`"```!```!`@!!```````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````"(`H`$``````:``"``````( -M`&P+%@D,#>`"```!```!`0`B`)\!``````&?``@`````"`!L"Q8)#`W@`@`` -M`0```0$!)`"A`0`````!H0`(``````@`;`L6"0P-X`(```$```$"`$$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````(@"A`0`````!H0`(``````@`;`L6"0P-X`(```$```$!`"(`H`$` -M`````:``"``````(`&P+%@D,#>`"```!```!`0$D`*(!``````&B``@````` -M"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````B`*(!``````&B``@````` -M"`!L"Q8)#`W@`@```0```0$`(@"A`0`````!H0`(``````@`;`L6"0P-X`(` -M``$```$!`20`HP$``````:,`"``````(`&P+%@D,#>`"```!```!`@!!```` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````"(`HP$``````:,`"``````(`&P+%@D,#>`"```!```!`0`B`*(! -M``````&B``@`````"`!L"Q8)#`W@`@```0```0$!)`"D`0`````!I``(```` -M``@`;`L6"0P-X`(```$```$"`$$````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````(@"D`0`````!I``(```` -M``@`;`L6"0P-X`(```$```$!`"(`HP$``````:,`"``````(`&P+%@D,#>`" -M```!```!`0$D`*4!``````&E``@`````"`!L"Q8)#`W@`@```0```0(`00`` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````B`*4!``````&E``@`````"`!L"Q8)#`W@`@```0```0$`(@"D -M`0`````!I``(``````@`;`L6"0P-X`(```$```$!`20`I@$``````:8`"``` -M```(`&P+%@D,#>`"```!```!`@!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````"(`I@$``````:8`"``` -M```(`&P+%@D,#>`"```!```!`0`B`*4!``````&E``@`````"`!L"Q8)#`W@ -M`@```0```0$!)`"G`0`````!IP`(``````@`;`L6"0P-X`(```$```$"`$$` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````(@"G`0`````!IP`(``````@`;`L6"0P-X`(```$```$!`"(` -MI@$``````:8`"``````(`&P+%@D,#>`"```!```!`0$D`*@!``````&H``@` -M````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````B`*@!``````&H``@` -M````"`!L"Q8)#`W@`@```0```0$`(@"G`0`````!IP`(``````@`;`L6"0P- -MX`(```$```$!`20`J0$``````:D`"``````(`&P+%@D,#>`"```!```!`@!! -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````"(`J0$``````:D`"``````(`&P+%@D,#>`"```!```!`0`B -M`*@!``````&H``@`````"`!L"Q8)#`W@`@```0```0$!)`"J`0`````!J@`( -M``````@`;`L6"0P-X`(```$```$"`$$````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````(@"J`0`````!J@`( -M``````@`;`L6"0P-X`(```$```$!`"(`J0$``````:D`"``````(`&P+%@D, -M#>`"```!```!`0$D`*L!``````&K``@`````"`!L"Q8)#`W@`@```0```0(` -M00`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````B`*L!``````&K``@`````"`!L"Q8)#`W@`@```0```0$` -M(@"J`0`````!J@`(``````@`;`L6"0P-X`(```$```$!`20`K`$``````:P` -M"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````"(`K`$``````:P` -M"``````(`&P+%@D,#>`"```!```!`0`B`*L!``````&K``@`````"`!L"Q8) -M#`W@`@```0```0$!)`"M`0`````!K0`(``````@`;`L6"0P-X`(```$```$" -M`$$````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````(@"M`0`````!K0`(``````@`;`L6"0P-X`(```$```$! -M`"(`K`$``````:P`"``````(`&P+%@D,#>`"```!```!`0$D`*X!``````&N -M``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````B`*X!``````&N -M``@`````"`!L"Q8)#`W@`@```0```0$`(@"M`0`````!K0`(``````@`;`L6 -M"0P-X`(```$```$!`20`KP$``````:\`"``````(`&P+%@D,#>`"```!```! -M`@!!```````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````"(`KP$``````:\`"``````(`&P+%@D,#>`"```!```! -M`0`B`*X!``````&N``@`````"`!L"Q8)#`W@`@```0```0$!```````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````(@"P`0`````! -ML``(``````@`;`L6"0P-X`(```$```$!`"(`[@```````.X`"``````(`&P+ -M%@D,#>`"```!```!`0$D`+$!``````&Q``@`````"`!L"Q8)#`W@`@```0`` -M`0(`00`````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````B`+$!``````&Q``@`````"`!L"Q8)#`W@`@```0`` -M`0$`(@"P`0`````!L``(``````@`;`L6"0P-X`(```$```$!`20`L@$````` -M`;(`"``````(`&P+%@D,#>`"```!```!`@!!```````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````"(`L@$````` -M`;(`"``````(`&P+%@D,#>`"```!```!`0`B`+$!``````&Q``@`````"`!L -M"Q8)#`W@`@```0```0$!)`"S`0`````!LP`(``````@`;`L6"0P-X`(```$` -M``$"`$$````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````(@"S`0`````!LP`(``````@`;`L6"0P-X`(```$` -M``$!`"(`L@$``````;(`"``````(`&P+%@D,#>`"```!```!`0$D`+0!```` -M``&T``@`````"`!L"Q8)#`W@`@```0```0(`00`````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````B`+0!```` -M``&T``@`````"`!L"Q8)#`W@`@```0```0$`(@"S`0`````!LP`(``````@` -M;`L6"0P-X`(```$```$!`20`M0$``````;4`"``````(`&P+%@D,#>`"```! -M```!`@!!```````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````"(`M0$``````;4`"``````(`&P+%@D,#>`"```! -M```!`0`B`+0!``````&T``@`````"`!L"Q8)#`W@`@```0```0$!)`"V`0`` -M```!M@`(``````@`;`L6"0P-X`(```$```$"`$$````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````````````(@"V`0`` -M```!M@`(``````@`;`L6"0P-X`(```$```$!`"(`M0$``````;4`"``````( -M`&P+%@D,#>`"```!```!`0$D`.\```````#O``@`````"`!L"Q8)#`W@`@`` -M`0```0(`00`````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````B`+`"```!```!@`!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!! -M`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$`00!!`$$` -M00!!`$$`00!!`$$`00!!`$$`00!!```````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````````````"(`N`$` -M`````;@`"``````(`&P+%@D,#>`"```!```!`0`B`+`"```!```!`0$````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````!%4NT! -M"E2'`5)225!?,3DY,4%42$4@4D]#2R!2241'12!)3E1%4D-(04Y'12!04D]4 -M3T-/3"!04D]6241%4R!355!03U)4($9/4B!03U-)6"!&24Q%(%-94U1%32!3 -M14U!3E1)0U-03$5!4T4@0T].5$%#5"!$25-#(%!50DQ)4TA%4B!&3U(@4U!% -M0TE&24-!5$E/3B!33U520T4N("!3144@4%5"3$E32$52($E$14Y4249)15(@ -M24X@4%))34%262!63TQ5344@1$530U))4%1/4B!&3U(@0T].5$%#5"!)3D9/ -M4DU!5$E/3BX````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -$```````` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_link_resolver.c b/Utilities/cmlibarchive/libarchive/test/test_link_resolver.c deleted file mode 100644 index 4976fecc9..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_link_resolver.c +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_link_resolver.c,v 1.2 2008/06/15 04:31:43 kientzle Exp $"); - -static void test_linkify_tar(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_TAR_USTAR); - - /* Create an entry with only 1 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 1); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Now, try again with an entry that has 2 links. */ - archive_entry_set_pathname(entry, "test2"); - archive_entry_set_nlink(entry, 2); - archive_entry_set_ino(entry, 2); - archive_entry_linkify(resolver, &entry, &e2); - /* Shouldn't be altered, since it wasn't seen before. */ - assert(e2 == NULL); - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - assertEqualInt(10, archive_entry_size(entry)); - - /* Match again and make sure it does get altered. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualString("test2", archive_entry_hardlink(entry)); - assertEqualInt(0, archive_entry_size(entry)); - - - /* Dirs should never be matched as hardlinks, regardless. */ - archive_entry_set_pathname(entry, "test3"); - archive_entry_set_nlink(entry, 2); - archive_entry_set_filetype(entry, AE_IFDIR); - archive_entry_set_ino(entry, 3); - archive_entry_set_hardlink(entry, NULL); - archive_entry_linkify(resolver, &entry, &e2); - /* Shouldn't be altered, since it wasn't seen before. */ - assert(e2 == NULL); - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - - /* Dir, so it shouldn't get matched. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - - archive_entry_free(entry); - archive_entry_linkresolver_free(resolver); -} - -static void test_linkify_old_cpio(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_CPIO_POSIX); - - /* Create an entry with 2 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 2); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Still shouldn't be matched. */ - archive_entry_linkify(resolver, &entry, &e2); - assert(e2 == NULL); - assertEqualString("test1", archive_entry_pathname(entry)); - assertEqualString(NULL, archive_entry_hardlink(entry)); - assertEqualInt(10, archive_entry_size(entry)); - - archive_entry_free(entry); - archive_entry_linkresolver_free(resolver); -} - -static void test_linkify_new_cpio(void) -{ - struct archive_entry *entry, *e2; - struct archive_entry_linkresolver *resolver; - - /* Initialize the resolver. */ - assert(NULL != (resolver = archive_entry_linkresolver_new())); - archive_entry_linkresolver_set_strategy(resolver, - ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - - /* Create an entry with only 1 link and try to linkify it. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test1"); - archive_entry_set_ino(entry, 1); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 1); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Shouldn't have been changed. */ - assert(e2 == NULL); - assertEqualInt(10, archive_entry_size(entry)); - assertEqualString("test1", archive_entry_pathname(entry)); - - /* Now, try again with an entry that has 3 links. */ - archive_entry_set_pathname(entry, "test2"); - archive_entry_set_nlink(entry, 3); - archive_entry_set_ino(entry, 2); - archive_entry_linkify(resolver, &entry, &e2); - - /* First time, it just gets swallowed. */ - assert(entry == NULL); - assert(e2 == NULL); - - /* Match again. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test3"); - archive_entry_set_ino(entry, 2); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 2); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Should get back "test2" and nothing else. */ - assertEqualString("test2", archive_entry_pathname(entry)); - assertEqualInt(0, archive_entry_size(entry)); - archive_entry_free(entry); - assert(NULL == e2); - archive_entry_free(e2); /* This should be a no-op. */ - - /* Match a third time. */ - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_pathname(entry, "test4"); - archive_entry_set_ino(entry, 2); - archive_entry_set_dev(entry, 2); - archive_entry_set_nlink(entry, 3); - archive_entry_set_size(entry, 10); - archive_entry_linkify(resolver, &entry, &e2); - - /* Should get back "test3". */ - assertEqualString("test3", archive_entry_pathname(entry)); - assertEqualInt(0, archive_entry_size(entry)); - - /* Since "test4" was the last link, should get it back also. */ - assertEqualString("test4", archive_entry_pathname(e2)); - assertEqualInt(10, archive_entry_size(e2)); - - archive_entry_free(entry); - archive_entry_free(e2); - archive_entry_linkresolver_free(resolver); -} - -DEFINE_TEST(test_link_resolver) -{ - test_linkify_tar(); - test_linkify_old_cpio(); - test_linkify_new_cpio(); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_open_fd.c b/Utilities/cmlibarchive/libarchive/test/test_open_fd.c deleted file mode 100644 index b44756bf7..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_open_fd.c +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define open _open -#define lseek _lseek -#define close _close -#endif - -DEFINE_TEST(test_open_fd) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - int fd; - - fd = open("test.tar", O_RDWR | O_CREAT | O_BINARY, 0777); - assert(fd >= 0); - if (fd < 0) - return; - - /* Write an archive through this fd. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_fd(a, fd)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - assert(lseek(fd, 0, SEEK_SET) == 0); - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_fd(a, fd, 512)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - close(fd); - - - /* - * Verify some of the error handling. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - /* FD 100 shouldn't be open. */ - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_open_fd(a, 100, 512)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_open_file.c b/Utilities/cmlibarchive/libarchive/test/test_open_file.c deleted file mode 100644 index 47c93466e..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_open_file.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_open_file) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - FILE *f; - - f = fopen("test.tar", "wb"); - assert(f != NULL); - if (f == NULL) - return; - - /* Write an archive through this FILE *. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_FILE(a, f)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - fclose(f); - - /* - * Now, read the data back. - */ - f = fopen("test.tar", "rb"); - assert(f != NULL); - if (f == NULL) - return; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_FILE(a, f)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - fclose(f); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_open_filename.c b/Utilities/cmlibarchive/libarchive/test/test_open_filename.c deleted file mode 100644 index 1f1290d65..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_open_filename.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_open_filename) -{ - char buff[64]; - struct archive_entry *ae; - struct archive *a; - - /* Write an archive through this FILE *. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_filename(a, "test.tar")); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * Write a second file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 819200); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, "test.tar", 512)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff, 10)); - assertEqualMem(buff, "12345678", 8); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(819200, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_data_skip(a)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Verify some of the error handling. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_open_filename(a, "nonexistent.tar", 512)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.c b/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.c deleted file mode 100644 index 14d955359..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.c +++ /dev/null @@ -1,337 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_pax_filename_encoding.c,v 1.3 2008/08/11 01:19:36 kientzle Exp $"); - -#include - -/* - * Pax interchange is supposed to encode filenames into - * UTF-8. Of course, that's not always possible. This - * test is intended to verify that filenames always get - * stored and restored correctly, regardless of the encodings. - */ - -/* - * Read a manually-created archive that has filenames that are - * stored in binary instead of UTF-8 and verify that we get - * the right filename returned and that we get a warning only - * if the header isn't marked as binary. - */ -static void -test_pax_filename_encoding_1(void) -{ - static const char testname[] = "test_pax_filename_encoding.tar"; - /* - * \314\214 is a valid 2-byte UTF-8 sequence. - * \374 is invalid in UTF-8. - */ - char filename[] = "abc\314\214mno\374xyz"; - struct archive *a; - struct archive_entry *entry; - - /* - * Read an archive that has non-UTF8 pax filenames in it. - */ - extract_reference_file(testname); - a = archive_read_new(); - assertEqualInt(ARCHIVE_OK, archive_read_support_format_tar(a)); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, testname, 10240)); - /* - * First entry in this test archive has an invalid UTF-8 sequence - * in it, but the header is not marked as hdrcharset=BINARY, so that - * requires a warning. - */ - failure("Invalid UTF8 in a pax archive pathname should cause a warning"); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - /* - * Second entry is identical except that it does have - * hdrcharset=BINARY, so no warning should be generated. - */ - failure("A pathname with hdrcharset=BINARY can have invalid UTF8\n" - " characters in it without generating a warning"); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - archive_read_finish(a); -} - -/* - * Set the locale and write a pathname containing invalid characters. - * This should work; the underlying implementation should automatically - * fall back to storing the pathname in binary. - */ -static void -test_pax_filename_encoding_2(void) -{ - char filename[] = "abc\314\214mno\374xyz"; - struct archive *a; - struct archive_entry *entry; - char buff[65536]; - char longname[] = "abc\314\214mno\374xyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - "/abc\314\214mno\374xyz/abcdefghijklmnopqrstuvwxyz" - ; - size_t used; - - /* - * We need a starting locale which has invalid sequences. - * de_DE.UTF-8 seems to be commonly supported. - */ - /* If it doesn't exist, just warn and return. */ - if (NULL == setlocale(LC_ALL, LOCALE_DE)) { - skipping("invalid encoding tests require a suitable locale;" - " %s not available on this system", LOCALE_DE); - return; - } - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_pax(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); - assertEqualInt(0, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname, gname, uname, hardlink to nonconvertible values. */ - archive_entry_copy_pathname(entry, filename); - archive_entry_copy_gname(entry, filename); - archive_entry_copy_uname(entry, filename); - archive_entry_copy_hardlink(entry, filename); - archive_entry_set_filetype(entry, AE_IFREG); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - /* Set path, gname, uname, and symlink to nonconvertible values. */ - archive_entry_copy_pathname(entry, filename); - archive_entry_copy_gname(entry, filename); - archive_entry_copy_uname(entry, filename); - archive_entry_copy_symlink(entry, filename); - archive_entry_set_filetype(entry, AE_IFLNK); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname to a very long nonconvertible value. */ - archive_entry_copy_pathname(entry, longname); - archive_entry_set_filetype(entry, AE_IFREG); - failure("This should generate a warning for nonconvertible names."); - assertEqualInt(ARCHIVE_WARN, archive_write_header(a, entry)); - archive_entry_free(entry); - - assertEqualInt(0, archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now read the entries back. - */ - - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_format_tar(a)); - assertEqualInt(0, archive_read_open_memory(a, buff, used)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - assertEqualString(filename, archive_entry_gname(entry)); - assertEqualString(filename, archive_entry_uname(entry)); - assertEqualString(filename, archive_entry_hardlink(entry)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(filename, archive_entry_pathname(entry)); - assertEqualString(filename, archive_entry_gname(entry)); - assertEqualString(filename, archive_entry_uname(entry)); - assertEqualString(filename, archive_entry_symlink(entry)); - - assertEqualInt(0, archive_read_next_header(a, &entry)); - assertEqualString(longname, archive_entry_pathname(entry)); - - assertEqualInt(0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -/* - * Create an entry starting from a wide-character Unicode pathname, - * read it back into "C" locale, which doesn't support the name. - * TODO: Figure out the "right" behavior here. - */ -static void -test_pax_filename_encoding_3(void) -{ - wchar_t badname[] = L"xxxAyyyBzzz"; - const char badname_utf8[] = "xxx\xE1\x88\xB4yyy\xE5\x99\xB8zzz"; - struct archive *a; - struct archive_entry *entry; - char buff[65536]; - size_t used; - - badname[3] = 0x1234; - badname[7] = 0x5678; - - /* If it doesn't exist, just warn and return. */ - if (NULL == setlocale(LC_ALL, "C")) { - skipping("Can't set \"C\" locale, so can't exercise " - "certain character-conversion failures"); - return; - } - - /* If wctomb is broken, warn and return. */ - if (wctomb(buff, 0x1234) > 0) { - skipping("Cannot test conversion failures because \"C\" " - "locale on this system has no invalid characters."); - return; - } - - /* If wctomb is broken, warn and return. */ - if (wctomb(buff, 0x1234) > 0) { - skipping("Cannot test conversion failures because \"C\" " - "locale on this system has no invalid characters."); - return; - } - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_pax(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_set_bytes_per_block(a, 0)); - assertEqualInt(0, - archive_write_open_memory(a, buff, sizeof(buff), &used)); - - assert((entry = archive_entry_new()) != NULL); - /* Set pathname to non-convertible wide value. */ - archive_entry_copy_pathname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set gname to non-convertible wide value. */ - archive_entry_copy_gname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set uname to non-convertible wide value. */ - archive_entry_copy_uname_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set hardlink to non-convertible wide value. */ - archive_entry_copy_hardlink_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFREG); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assert((entry = archive_entry_new()) != NULL); - archive_entry_copy_pathname_w(entry, L"abc"); - /* Set symlink to non-convertible wide value. */ - archive_entry_copy_symlink_w(entry, badname); - archive_entry_set_filetype(entry, AE_IFLNK); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, entry)); - archive_entry_free(entry); - - assertEqualInt(0, archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now read the entries back. - */ - - assert((a = archive_read_new()) != NULL); - assertEqualInt(0, archive_read_support_format_tar(a)); - assertEqualInt(0, archive_read_open_memory(a, buff, used)); - - failure("A non-convertible pathname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_pathname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_pathname(entry)); - - failure("A non-convertible gname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_gname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_gname(entry)); - - failure("A non-convertible uname should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_uname_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_uname(entry)); - - failure("A non-convertible hardlink should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_hardlink_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_hardlink(entry)); - - failure("A non-convertible symlink should cause a warning."); - assertEqualInt(ARCHIVE_WARN, archive_read_next_header(a, &entry)); - assertEqualWString(badname, archive_entry_symlink_w(entry)); - assertEqualWString(NULL, archive_entry_hardlink_w(entry)); - failure("If native locale can't convert, we should get UTF-8 back."); - assertEqualString(badname_utf8, archive_entry_symlink(entry)); - - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &entry)); - - assertEqualInt(0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_pax_filename_encoding) -{ - test_pax_filename_encoding_1(); - test_pax_filename_encoding_2(); - test_pax_filename_encoding_3(); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.tar.uu b/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.tar.uu deleted file mode 100644 index 1c221fd6b..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_pax_filename_encoding.tar.uu +++ /dev/null @@ -1,117 +0,0 @@ -begin 644 test_pax_filename_encoding.tar -M4&%X2&5A9&5R+V%B8\R,;6YO6'AY>@`````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@`#`P,#`P,#`P,38V -M(#$P-S8V-C`W,#,V(#`Q-3,P-@`@>``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U@HR,"!C=&EM -M93TQ,C`U-3,X-C@U"C(P(&%T:6UE/3$R,#4U,S@V,C8*,3<@4T-(24Q9+F1E -M=CTX.`HR,B!30TA)3%DN:6YO/30S,34T-#D*,3@@4T-(24Q9+FYL:6YK/3$* -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````````````````````&%B8\R,;6YO6'AY -M>@`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````P -M,#`V-#0@`#`P,3'EZ -M```````````````````````````````````````````````````````````` -M````````````````````````````````````````````,#`P-C0T(``P,#$W -M-3`@`#`P,3'EZ"C(P(&-T:6UE -M/3$R,#4U-#$W,S4*,C`@871I;64],3(P-34S.#8R-@HQ-R!30TA)3%DN9&5V -M/3@X"C(R(%-#2$E,62YI;F\]-#,Q-3$R-@HQ."!30TA)3%DN;FQI;FL],0H` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M````````````````86)CS(QM;F_\>'EZ```````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````````````#`P,#8T-"``,#`Q-S4P(``P,#$W-3`@ -M`#`P,#`P,#`P,#`U(#$P-S8V-C`W,#,V(#`Q,S4W,0`@,``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -M= 1009000 -/* - * This "archive" is created by "GNU ar". Here we try to verify - * our GNU format handling functionality. - */ -static unsigned char archive[] = { -'!','<','a','r','c','h','>',10,'/','/',' ',' ',' ',' ',' ',' ',' ', -' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -' ',' ',' ',' ',' ','4','0',' ',' ',' ',' ',' ',' ',' ',' ','`',10, -'y','y','y','t','t','t','s','s','s','a','a','a','f','f','f','.','o', -'/',10,'h','h','h','h','j','j','j','j','k','k','k','k','l','l','l', -'l','.','o','/',10,10,'/','0',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -' ',' ',' ',' ','1','1','7','5','4','6','5','6','5','2',' ',' ','1', -'0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4', -' ',' ','8',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'5','5','6', -'6','7','7','8','8','g','g','h','h','.','o','/',' ',' ',' ',' ',' ', -' ',' ',' ',' ','1','1','7','5','4','6','5','6','6','8',' ',' ','1', -'0','0','1',' ',' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4', -' ',' ','4',' ',' ',' ',' ',' ',' ',' ',' ',' ','`',10,'3','3','3', -'3','/','1','9',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -'1','1','7','5','4','6','5','7','1','3',' ',' ','1','0','0','1',' ', -' ','0',' ',' ',' ',' ',' ','1','0','0','6','4','4',' ',' ','9',' ', -' ',' ',' ',' ',' ',' ',' ',' ','`',10,'9','8','7','6','5','4','3', -'2','1',10}; - -char buff[64]; -#endif - -DEFINE_TEST(test_read_format_ar) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("test_read_support_format_ar()"); -#else - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archive, sizeof(archive))); - - /* Filename table. */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("//", archive_entry_pathname(ae)); - assertEqualInt(0, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_uid(ae)); - assertEqualInt(0, archive_entry_gid(ae)); - assertEqualInt(0, archive_entry_size(ae)); - - /* First Entry */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("yyytttsssaaafff.o", archive_entry_pathname(ae)); - assertEqualInt(1175465652, archive_entry_mtime(ae)); - assertEqualInt(1001, archive_entry_uid(ae)); - assertEqualInt(0, archive_entry_gid(ae)); - assert(8 == archive_entry_size(ae)); - assertA(8 == archive_read_data(a, buff, 10)); - assert(0 == memcmp(buff, "55667788", 8)); - - /* Second Entry */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("gghh.o", archive_entry_pathname(ae)); - assertEqualInt(1175465668, archive_entry_mtime(ae)); - assertEqualInt(1001, archive_entry_uid(ae)); - assertEqualInt(0, archive_entry_gid(ae)); - assert(4 == archive_entry_size(ae)); - assertA(4 == archive_read_data(a, buff, 10)); - assert(0 == memcmp(buff, "3333", 4)); - - /* Third Entry */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("hhhhjjjjkkkkllll.o", archive_entry_pathname(ae)); - assertEqualInt(1175465713, archive_entry_mtime(ae)); - assertEqualInt(1001, archive_entry_uid(ae)); - assertEqualInt(0, archive_entry_gid(ae)); - assert(9 == archive_entry_size(ae)); - assertA(9 == archive_read_data(a, buff, 9)); - assert(0 == memcmp(buff, "987654321", 9)); - - /* Test EOF */ - assertA(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin.c deleted file mode 100644 index 21e26ae7c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_bin.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -199,'q',21,4,177,'y',237,'A',232,3,232,3,2,0,0,0,'p','C',244,'M',2,0,0,0, -0,0,'.',0,199,'q',0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,11,0,0,0,0,0,'T','R', -'A','I','L','E','R','!','!','!',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - -DEFINE_TEST(test_read_format_cpio_bin) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archive, sizeof(archive))); - assertA(0 == archive_read_next_header(a, &ae)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_Z.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_Z.c deleted file mode 100644 index 515e45c34..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_Z.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_bin_Z.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,157,144,199,226,'T',' ',16,'+','O',187,' ',232,6,'$',20,0,160,'!',156, -'!',244,154,'0','l',216,208,5,128,128,20,'3','R',12,160,177,225,2,141,'T', -164,4,'I',194,164,136,148,16,'(',';',170,'\\',201,178,165,203,151,'0','c', -202,156,'I',179,166,205,155,'8','s',234,220,201,179,167,207,159,'@',127,2}; - -DEFINE_TEST(test_read_format_cpio_bin_Z) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - assertEqualString(archive_compression_name(a), "compress (.Z)"); - failure("archive_format_name(a)=\"%s\"", - archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.c deleted file mode 100644 index 9f14eb98c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.c +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_read_format_cpio_bin_be) -{ - struct archive_entry *ae; - struct archive *a; - const char *reference = "test_read_format_cpio_bin_be.cpio"; - - extract_reference_file(reference); - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, reference, 10)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "file1111222233334444"); - assertEqualInt(archive_entry_size(ae), 5); - assertEqualInt(archive_entry_mtime(ae), 1240664175); - assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 0); - - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_BE); - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.cpio.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.cpio.uu deleted file mode 100644 index 999f1e0d9..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_be.cpio.uu +++ /dev/null @@ -1,8 +0,0 @@ -$FreeBSD$ -begin 644 test_read_format_cpio_bin_be.cpio -M<<<`"#P\@:0#Z`````$``$GS"&\`%0````5F:6QE,3$Q,3(R,C(S,S,S-#0T -M-```86)C9&4`<<<```````````````$`````````"P````!44D%)3$52(2$A -M```````````````````````````````````````````````````````````` -3```````````````````````````` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_bz2.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_bz2.c deleted file mode 100644 index aa7dfe877..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_bz2.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_bin_bz2.c,v 1.3 2008/12/06 06:00:52 kientzle Exp $"); - -static unsigned char archive[] = { -'B','Z','h','9','1','A','Y','&','S','Y',134,'J',208,'4',0,0,30,246,141,253, -8,2,0,' ',1,'*','&',20,0,'`',' ',' ',2,0,128,0,'B',4,8,' ',0,'T','P',0,'4', -0,13,6,137,168,245,27,'Q',160,'a',25,169,5,'I',187,'(',10,'d','E',177,177, -142,218,232,'r',130,'4','D',247,'<','Z',190,'U',237,236,'d',227,31,' ','z', -192,'E','_',23,'r','E','8','P',144,134,'J',208,'4'}; - -DEFINE_TEST(test_read_format_cpio_bin_bz2) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r != ARCHIVE_OK) { - skipping("bzip2 support unavailable"); - archive_read_close(a); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assert(archive_compression(a) == ARCHIVE_COMPRESSION_BZIP2); - assert(archive_format(a) == ARCHIVE_FORMAT_CPIO_BIN_LE); - assert(0 == archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_gz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_gz.c deleted file mode 100644 index bb49d9422..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_gz.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_bin_gz.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,139,8,0,244,'M','p','C',0,3,';','^','(',202,178,177,242,173,227,11,230, -23,204,'L',12,12,12,5,206,'_','|','A','4',3,131,30,195,241,'B',6,'8','`', -132,210,220,'`','2','$',200,209,211,199,'5','H','Q','Q',145,'a',20,12,'i', -0,0,170,199,228,195,0,2,0,0}; - -DEFINE_TEST(test_read_format_cpio_bin_gz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - failure("archive_read_support_compression_gzip"); - assertEqualInt(ARCHIVE_OK, r); - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_xz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_xz.c deleted file mode 100644 index 99d44c15e..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_bin_xz.c +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { - 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00, 0x00, 0x04, - 0xe6, 0xd6, 0xb4, 0x46, 0x02, 0x00, 0x21, 0x01, - 0x16, 0x00, 0x00, 0x00, 0x74, 0x2f, 0xe5, 0xa3, - 0xe0, 0x01, 0xff, 0x00, 0x33, 0x5d, 0x00, 0x63, - 0x9c, 0x3e, 0xa0, 0x43, 0x7c, 0xe6, 0x5d, 0xdc, - 0xeb, 0x76, 0x1d, 0x4b, 0x1b, 0xe2, 0x9e, 0x43, - 0x95, 0x97, 0x60, 0x16, 0x36, 0xc6, 0xd1, 0x3f, - 0x68, 0xd1, 0x94, 0xf9, 0xee, 0x47, 0xbb, 0xc9, - 0xf3, 0xa2, 0x01, 0x2a, 0x2f, 0x2b, 0xb2, 0x23, - 0x5a, 0x06, 0x9c, 0xd0, 0x4a, 0x6b, 0x5b, 0x14, - 0xb4, 0x00, 0x00, 0x00, 0x91, 0x62, 0x1e, 0x15, - 0x04, 0x46, 0x6b, 0x4d, 0x00, 0x01, 0x4f, 0x80, - 0x04, 0x00, 0x00, 0x00, 0xa1, 0x4b, 0xdf, 0x03, - 0xb1, 0xc4, 0x67, 0xfb, 0x02, 0x00, 0x00, 0x00, - 0x00, 0x04, 0x59, 0x5a -}; - -DEFINE_TEST(test_read_format_cpio_bin_xz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_BIN_LE); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_odc.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_odc.c deleted file mode 100644 index 349309140..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_odc.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_odc.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -'0','7','0','7','0','7','0','0','2','0','2','5','0','7','4','6','6','1','0', -'4','0','7','5','5','0','0','1','7','5','0','0','0','1','7','5','0','0','0', -'0','0','0','2','0','0','0','0','0','0','1','0','3','3','4','0','5','0','0', -'5','3','0','0','0','0','0','2','0','0','0','0','0','0','0','0','0','0','0', -'.',0,'0','7','0','7','0','7','0','0','0','0','0','0','0','0','0','0','0', -'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', -'0','0','0','0','0','1','0','0','0','0','0','0','0','0','0','0','0','0','0', -'0','0','0','0','0','0','0','0','1','3','0','0','0','0','0','0','0','0','0', -'0','0','T','R','A','I','L','E','R','!','!','!',0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0}; - -DEFINE_TEST(test_read_format_cpio_odc) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_CPIO_POSIX); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4_gzip.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4_gzip.c deleted file mode 100644 index bc8fefdc0..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4_gzip.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_svr4_gzip.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,139,8,0,236,'c',217,'D',0,3,'3','0','7','0','7','0','4','0','0',181,'0', -183,'L',2,210,6,6,'&',134,169,')',' ',218,192,'8',213,2,133,'6','0','0','2', -'1','6','7','0','5','0','N','6','@',5,'&',16,202,208,212,0,';','0',130,'1', -244,24,12,160,246,17,5,136,'U',135,14,146,'`',140,144,' ','G','O',31,215, -' ','E','E','E',134,'Q',128,21,0,0,'%',215,202,221,0,2,0,0}; - -DEFINE_TEST(test_read_format_cpio_svr4_gzip) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), - ARCHIVE_FORMAT_CPIO_SVR4_NOCRC); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4c_Z.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4c_Z.c deleted file mode 100644 index c77fb85c1..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_cpio_svr4c_Z.c +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_cpio_svr4c_Z.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,157,144,'0','n',4,132,'!',3,6,140,26,'8','n',228,16,19,195,160,'A',26, -'1',202,144,'q','h','p','F',25,28,20,'a','X',196,152,145,' ',141,25,2,'k', -192,160,'A',163,163,201,135,29,'c',136,'<',201,'2','c','A',147,'.',0,12,20, -248,178,165,205,155,20,27,226,220,201,243,166,152,147,'T',164,4,'I',194,164, -136,148,16,'H',1,'(',']',202,180,169,211,167,'P',163,'J',157,'J',181,170, -213,171,'X',179,'j',221,202,181,171,215,175,'L',1}; - -DEFINE_TEST(test_read_format_cpio_svr4c_Z) -{ - struct archive_entry *ae; - struct archive *a; -/* printf("Archive address: start=%X, end=%X\n", archive, archive+sizeof(archive)); */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_CPIO_SVR4_CRC); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_empty.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_empty.c deleted file mode 100644 index 2b5480488..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_empty.c +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_empty.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { 0 }; - -DEFINE_TEST(test_read_format_empty) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archive, 0)); - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_EMPTY); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_gz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_gz.c deleted file mode 100644 index e504be9b0..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_gz.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_gtar_gz.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,139,8,0,'+','e',217,'D',0,3,211,211,'g',160,'9','0',0,2,'s','S','S',16, -'m','h','n','j',128,'L',195,0,131,161,129,177,177,137,129,137,185,185,161, -'!',131,129,161,129,153,161,'9',131,130,')',237,157,198,192,'P','Z','\\', -146,'X',164,160,192,'P',146,153,139,'W',29,'!','y',152,'G','`',244,'(',24, -5,163,'`',20,12,'r',0,0,226,234,'6',162,0,6,0,0}; - -DEFINE_TEST(test_read_format_gtar_gz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_lzma.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_lzma.c deleted file mode 100644 index 53de903a2..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_lzma.c +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 2008 Miklos Vajna - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -0x5d, 0x0, 0x0, 0x80, 0x0, 0x0, 0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, -0x17, 0xb, 0xbc, 0x1c, 0x7d, 0x1, 0x95, 0xc0, 0x1d, 0x4a, 0x46, 0x9c, -0x1c, 0xc5, 0x8, 0x82, 0x10, 0xed, 0x84, 0xf6, 0xea, 0x7a, 0xfe, 0x63, -0x5a, 0x34, 0x5e, 0xf7, 0xc, 0x60, 0xd6, 0x8b, 0xc1, 0x47, 0xaf, 0x11, -0x6f, 0x18, 0x94, 0x81, 0x74, 0x8a, 0xf8, 0x47, 0xcc, 0xdd, 0xc0, 0xd9, -0x40, 0xa, 0xc3, 0xac, 0x43, 0x47, 0xb5, 0xac, 0x2b, 0x31, 0xd3, 0x6, -0xa4, 0x2c, 0x44, 0x80, 0x24, 0x4b, 0xfe, 0x43, 0x22, 0x4e, 0x14, 0x30, -0x7a, 0xef, 0x99, 0x6e, 0xf, 0x8b, 0xc1, 0x79, 0x93, 0x88, 0x54, 0x73, -0x59, 0x3f, 0xc, 0xfb, 0xee, 0x9c, 0x83, 0x49, 0x93, 0x33, 0xad, 0x44, -0xbe, 0x0}; - -DEFINE_TEST(test_read_format_gtar_lzma) -{ - int r; - - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - - assertEqualIntA(a, ARCHIVE_OK, r); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - r = archive_read_open_memory2(a, archive, sizeof(archive), 3); - if (r != ARCHIVE_OK) { - skipping("Skipping LZMA compression check: %s", - archive_error_string(a)); - goto finish; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_LZMA); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_GNUTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse.c deleted file mode 100644 index c3f086a29..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse.c +++ /dev/null @@ -1,318 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_gtar_sparse.c,v 1.11 2008/12/06 05:58:24 kientzle Exp $"); - - -struct contents { - off_t o; - size_t s; - const char *d; -}; - -struct contents archive_contents_sparse[] = { - { 1000000, 1, "a" }, - { 2000000, 1, "a" }, - { 3145728, 0, NULL } -}; - -struct contents archive_contents_sparse2[] = { - { 1000000, 1, "a" }, - { 2000000, 1, "a" }, - { 3000000, 1, "a" }, - { 4000000, 1, "a" }, - { 5000000, 1, "a" }, - { 6000000, 1, "a" }, - { 7000000, 1, "a" }, - { 8000000, 1, "a" }, - { 9000000, 1, "a" }, - { 10000000, 1, "a" }, - { 11000000, 1, "a" }, - { 12000000, 1, "a" }, - { 13000000, 1, "a" }, - { 14000000, 1, "a" }, - { 15000000, 1, "a" }, - { 16000000, 1, "a" }, - { 17000000, 1, "a" }, - { 18000000, 1, "a" }, - { 19000000, 1, "a" }, - { 20000000, 1, "a" }, - { 21000000, 1, "a" }, - { 22000000, 1, "a" }, - { 23000000, 1, "a" }, - { 24000000, 1, "a" }, - { 25000000, 1, "a" }, - { 26000000, 1, "a" }, - { 27000000, 1, "a" }, - { 28000000, 1, "a" }, - { 29000000, 1, "a" }, - { 30000000, 1, "a" }, - { 31000000, 1, "a" }, - { 32000000, 1, "a" }, - { 33000000, 1, "a" }, - { 34000000, 1, "a" }, - { 35000000, 1, "a" }, - { 36000000, 1, "a" }, - { 37000000, 1, "a" }, - { 38000000, 1, "a" }, - { 39000000, 1, "a" }, - { 40000000, 1, "a" }, - { 41000000, 1, "a" }, - { 42000000, 1, "a" }, - { 43000000, 1, "a" }, - { 44000000, 1, "a" }, - { 45000000, 1, "a" }, - { 46000000, 1, "a" }, - { 47000000, 1, "a" }, - { 48000000, 1, "a" }, - { 49000000, 1, "a" }, - { 50000000, 1, "a" }, - { 51000000, 1, "a" }, - { 52000000, 1, "a" }, - { 53000000, 1, "a" }, - { 54000000, 1, "a" }, - { 55000000, 1, "a" }, - { 56000000, 1, "a" }, - { 57000000, 1, "a" }, - { 58000000, 1, "a" }, - { 59000000, 1, "a" }, - { 60000000, 1, "a" }, - { 61000000, 1, "a" }, - { 62000000, 1, "a" }, - { 63000000, 1, "a" }, - { 64000000, 1, "a" }, - { 65000000, 1, "a" }, - { 66000000, 1, "a" }, - { 67000000, 1, "a" }, - { 68000000, 1, "a" }, - { 69000000, 1, "a" }, - { 70000000, 1, "a" }, - { 71000000, 1, "a" }, - { 72000000, 1, "a" }, - { 73000000, 1, "a" }, - { 74000000, 1, "a" }, - { 75000000, 1, "a" }, - { 76000000, 1, "a" }, - { 77000000, 1, "a" }, - { 78000000, 1, "a" }, - { 79000000, 1, "a" }, - { 80000000, 1, "a" }, - { 81000000, 1, "a" }, - { 82000000, 1, "a" }, - { 83000000, 1, "a" }, - { 84000000, 1, "a" }, - { 85000000, 1, "a" }, - { 86000000, 1, "a" }, - { 87000000, 1, "a" }, - { 88000000, 1, "a" }, - { 89000000, 1, "a" }, - { 90000000, 1, "a" }, - { 91000000, 1, "a" }, - { 92000000, 1, "a" }, - { 93000000, 1, "a" }, - { 94000000, 1, "a" }, - { 95000000, 1, "a" }, - { 96000000, 1, "a" }, - { 97000000, 1, "a" }, - { 98000000, 1, "a" }, - { 99000000, 1, "a" }, - { 99000001, 0, NULL } -}; - -struct contents archive_contents_nonsparse[] = { - { 0, 1, "a" }, - { 1, 0, NULL } -}; - -/* - * Describe an archive with three entries: - * - * File 1: named "sparse" - * * a length of 3145728 bytes (3MiB) - * * a single 'a' byte at offset 1000000 - * * a single 'a' byte at offset 2000000 - * File 2: named "sparse2" - * * a single 'a' byte at offset 1,000,000, 2,000,000, ..., 99,000,000 - * * length of 99,000,001 - * File 3: named 'non-sparse' - * * length of 1 byte - * * contains a single byte 'a' - */ - -struct archive_contents { - const char *filename; - struct contents *contents; -} files[] = { - { "sparse", archive_contents_sparse }, - { "sparse2", archive_contents_sparse2 }, - { "non-sparse", archive_contents_nonsparse }, - { NULL, NULL } -}; - -static void -verify_archive_file(const char *name, struct archive_contents *ac) -{ - struct archive_entry *ae; - int err; - /* data, size, offset of next expected block. */ - struct contents expect; - /* data, size, offset of block read from archive. */ - struct contents actual; - const void *p; - struct archive *a; - - extract_reference_file(name); - - assert((a = archive_read_new()) != NULL); - assert(0 == archive_read_support_compression_all(a)); - assert(0 == archive_read_support_format_tar(a)); - failure("Can't open %s", name); - assert(0 == archive_read_open_filename(a, name, 3)); - - while (ac->filename != NULL) { - struct contents *cts = ac->contents; - - if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { - assert(0 == archive_read_finish(a)); - return; - } - failure("Name mismatch in archive %s", name); - assertEqualString(ac->filename, archive_entry_pathname(ae)); - - expect = *cts++; - while (0 == (err = archive_read_data_block(a, - &p, &actual.s, &actual.o))) { - actual.d = p; - while (actual.s > 0) { - char c = *actual.d; - if(actual.o < expect.o) { - /* - * Any byte before the expected - * data must be NULL. - */ - failure("%s: pad at offset %d " - "should be zero", name, actual.o); - assertEqualInt(c, 0); - } else if (actual.o == expect.o) { - /* - * Data at matching offsets must match. - */ - assertEqualInt(c, *expect.d); - expect.d++; - expect.o++; - expect.s--; - /* End of expected? step to next expected. */ - if (expect.s <= 0) - expect = *cts++; - } else { - /* - * We found data beyond that expected. - */ - failure("%s: Unexpected trailing data", - name); - assert(actual.o <= expect.o); - archive_read_finish(a); - return; - } - actual.d++; - actual.o++; - actual.s--; - } - } - failure("%s: should be end of entry", name); - assertEqualIntA(a, err, ARCHIVE_EOF); - failure("%s: Size returned at EOF must be zero", name); - assertEqualInt((int)actual.s, 0); -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* libarchive < 1.9 doesn't get this right */ - skipping("offset of final sparse chunk"); -#else - failure("%s: Offset of final empty chunk must be same as file size", name); - assertEqualInt(actual.o, expect.o); -#endif - /* Step to next file description. */ - ++ac; - } - - err = archive_read_next_header(a, &ae); - assertEqualIntA(a, ARCHIVE_EOF, err); - - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - -DEFINE_TEST(test_read_format_gtar_sparse) -{ - /* Two archives that use the "GNU tar sparse format". */ - verify_archive_file("test_read_format_gtar_sparse_1_13.tar", files); - verify_archive_file("test_read_format_gtar_sparse_1_17.tar", files); - - /* - * libarchive < 1.9 doesn't support the newer --posix sparse formats - * from GNU tar 1.15 and later. - */ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("read support for GNUtar --posix sparse formats"); -#else - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix00.tar", - files); - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=0.1 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix01.tar", - files); - /* - * An archive created by GNU tar 1.17 using --posix --sparse-format=1.0 - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix10.tar", - files); - /* - * The last test archive here is a little odd. First, it's - * uncompressed, because that exercises some of the block - * reassembly code a little harder. Second, it includes some - * leading comments prior to the sparse block description. - * GNU tar doesn't do this, but I think it should, so I want - * to ensure that libarchive correctly ignores such comments. - * Dump the file, looking for "#!gnu-sparse-format" starting - * at byte 0x600. - */ - verify_archive_file( - "test_read_format_gtar_sparse_1_17_posix10_modified.tar", - files); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu deleted file mode 100644 index 5ab519036..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_gtar_sparse_1_13.tar.uu +++ /dev/null @@ -1,1369 +0,0 @@ -begin 644 test_read_format_gtar_sparse_1_13.tar -M``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!UF4],S$T-371E71E71E71E$AE861E``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!UF4],S$T-3$AE861E``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -MF4].3DP,#`P,#$*,C`@ -M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"XO1TY54W!A``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!U``````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````!U``````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````````````!U -MF4].3DP,#`P,#$*,C`@ -M871I;64],3$Y.#(Y,S8P,PHR,"!C=&EM93TQ,3DX,CDS-C`Q"@`````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`"XO1TY54W!A``````````````````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````!UDDV&5W;&L+J>O%OV0WW+;;E'I7+4>6RJO+\5_.+9?(J -MJEX>5:/R,BM'Q\^>5E^^.W^R.O^&`?$7C-X/\DD_#T4:NAL;<7VW..@/AFE^ -MF.^GH[!],!@F:19>+Y^?M#?)DJ*PEM63CT4A2[?V)UEXTWL;&MUN*Z2UP\G! -M>"?9&J:KRD[8JWU(M[)\,J[OU?+>[F`X'(QW'FJZS3AN-QIQI]EJKK<[<7Q^ -MI2+^0W2E1REZJ-'S;[B/US;+^=$B-&MQK176YN%LMCA;.YU-/W\ZFI^>3,]J17N8/O0<`("[ -M*5VLL8O_`0``X#&[B/RK%@````#@,;O]'[M;>U@[```````````````````` -M`````````````````````````````````````````````.#.?@")(\.V`(`! -!```` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.c deleted file mode 100644 index e73de8f91..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.c +++ /dev/null @@ -1,139 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * All rights reserved. - * - * Based on libarchive/test/test_read_format_isorr_bz2.c with - * bugs introduced by Andreas Henriksson for - * testing ISO9660 image with Joliet extension. - * - * 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 "test.h" - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_bz2.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/long-joliet-file-name.textfile -ln /tmp/iso/long-joliet-file-name.textfile /tmp/iso/hardlink -(cd /tmp/iso; ln -s long-joliet-file-name.textfile symlink) -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir -TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/long-joliet-file-name.textfile /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -fi -mkhybrid -J -uid 1 -gid 2 /tmp/iso | bzip2 > test_read_format_isojoliet_bz2.iso.bz2 -F=test_read_format_isojoliet_bz2.iso.bz2 -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_bz2) -{ - const char *refname = "test_read_format_isojoliet_bz2.iso.bz2"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_set_options(a, "iso9660:!rock-ridge")); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(86401, archive_entry_ctime(ae)); - assertEqualInt(0, archive_entry_stat(ae)->st_nlink); - assertEqualInt(0, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - - /* A regular file with two names ("hardlink" gets returned - * first, so it's not marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - - /* A symlink to the regular file. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("symlink", archive_entry_pathname(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.iso.bz2.uu deleted file mode 100644 index 46601a845..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_bz2.iso.bz2.uu +++ /dev/null @@ -1,29 +0,0 @@ -begin 644 test_read_format_isojoliet_bz2.iso.bz2 -M0EIH.3%!62936??^FX(``/9_^__?1_?^8__L/__?8:?_W&8@Z@$`9``008"` -M``+)"-`$/@=NN!W8[`8#23*GY-3U$](,0:`:`&"`9``9``T-'J::>B/4``#0 -MIM$9&IA-!-0'I`>HT`&1Z@``T`!H`:#0'H(,E-(-3-$-&AB-`8C0`R9#1A`# -M1A/1`&@,@!H'``#0`-`&@``-&(`!H`````&@`D1)H0B-1O)&4V2:9#"9/4/2 -M`/4>H'J-#(83U/$R@WZJ#>J&CREP**.W2R[".$_:J#$"N5P7:?.#4-4/..?K -M!KG\G]P="PX^ADTP4^Y%[1+0V,;$*HTA&\V'@+*$<.M-0L@CLZ\Z(B=]`3`4%B"00B`FF@!-]HK<2. -M)?&IAD^/KKM>TRY#@+H5W781AM)P\\-4$&88^S$WX"2$=(X7(?,=$?H.A')A -M`%2T4:GEQRL:WS4Q=4SU(F>*JM1UEK\V`5P$L[9[D*;FBNEC^GPMAH8T>K&> -MQ)_.TSB;5G`P>)20L5V6':NL^M38\&.')5))BO/*5`\P%H!`D7B2](0T)?Y0"`M3A6)'=($UL$@I$0$RBA0F4.!DAM`/@ -M!V,L#/`+FC!;C.K58BA"1P\H1LVXG\@^"8IJ@0*0>TP@8F#0R^(M($"`"#I" -M`.FD45RN3EH2^8X6C/LKMKA;@K,T&ZZ%&PIJW%:>FG[.F=KGJ_O.(K`+0#!@ -MQK&-G6!">H`4_/.<\CK)K+S/I/"?`9JG,TS^C1FI[O3NN(`Q^:*`Z1WEO()6 -MZ*!0@MSD*1?AE*V5[='!>>O%XL8LXIOQB\@CIBM%\0JD'+MAR$"@T'8M;JFM -MLHN7HG1S:F]+B'BZ)SJ(=0,6*Z791QW+3RNI(7!E!)'@.B$(934!)D0=U#%# -MV21)DA=@4;RM?@RLG1[`,A:"YQF2!`P`2B)#APE)`^\F8V -M5_U]0O,4AE6?->8U4$<2N%TC-HD%($@9'E1DCQZ&B:X4\IUV83HQ7)A'8I511-P`;=!!).^8X*0NHMB+.&!W"009 -M,<;0G^>BA6F[;A;X2B!%?BP&(G7&@(,*O-QP;;1*`*6"F:X8D"Y$/T,(1JM' -M$>\,IQ&V6;/)!\)0C$,[;`O,`9A-HRHQ8@^PLT.?=7RL[2789J_J86!HF0T" -M3%@,A$VPC(:A@3(\&9-TZP2>KA*D>D;<^L4(H=EUT419R5`$A(R(Y-^O -+_B[DBG"A(>_]-P0` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.c deleted file mode 100644 index 8f8fbc079..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.c +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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 "test.h" - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_long.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -num=0 -file=""; -while [ $num -lt 100 ] -do - num=$((num+10)) - file="${file}1234567890" -done -dir="${file}dir" -mkdir /tmp/iso/${dir} -file="${file}123" -echo "hello" > /tmp/iso/${file} -ln /tmp/iso/${file} /tmp/iso/hardlink -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/${file} /tmp/iso/${dir} -fi -F=test_read_format_isojoliet_long.iso.bz2 -mkhybrid -J -joliet-long -uid 1 -gid 2 /tmp/iso | bzip2 > $F -uuencode $F $F > $F.uu -rm -rf /tmp/iso -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_long) -{ - const char *refname = "test_read_format_isojoliet_long.iso.bz2"; - char pathname[104]; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i, r; - - for (i = 0; i < 100; i++) - pathname[i] = '0' + ((i+1) % 10); - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_set_options(a, "iso9660:!rock-ridge")); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(86401, archive_entry_ctime(ae)); - assertEqualInt(0, archive_entry_stat(ae)->st_nlink); - assertEqualInt(0, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - pathname[100] = 'd'; - pathname[101] = 'i'; - pathname[102] = 'r'; - pathname[103] = '\0'; - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(pathname, archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - - /* A regular file with two names ("hardlink" gets returned - * first, so it's not marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - pathname[100] = '1'; - pathname[101] = '2'; - pathname[102] = '3'; - pathname[103] = '\0'; - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(pathname, archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.iso.bz2.uu deleted file mode 100644 index 78d53f9a7..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_long.iso.bz2.uu +++ /dev/null @@ -1,29 +0,0 @@ -begin 644 test_read_format_isojoliet_long.iso.bz2 -M0EIH.3%!629364L46LD``/?__?__1_?W;__X/__?8*[_GH8DJ$``!`04<8`! -M0`+@"-`$?@"[!;`NTZC4\H-&@>H#1H-# -MTADT'J9-#)H`>0GJ&3`&DG?T]7>3N%RX*8W*%^PO*-D.6'C'C^0/M/$?WQX^ -M9AAMU].DB%':^%!/8,F5!/B`3XP$RY=\!*`)TP$W0$PYV=.W -M4*S4WUZH%9:./' -M;*0L:1?4X)8&.1+$=[@7\#KWE$NQG&47.#HA>@U$91B$(I" -M#QQ;VK0-I>D%"H?M1'8B,A\JE%,=PCU.%3HV+E)N&]CJ!J[W8M3L4K.4NC0( -MP@3GM'`A4A"!!@1>A`%"$D@`*,P(!B-NM%A83\SU)LPW%OO/WVI.*Z"N/]&& -MW2@K.:A"\YR6"D*@^Q[H]$;-`U$L):67R)\]DA(\>*`40_B'^5'B;@AY90&! -M2C))&)VK\)#2*&HLKK0VYR<]-LVMO5YFV8M;^M/0R9D$J!UH0MG -M"]0E!S#GHMLB"4:RHV'BNU.?_-3$H:`];(4R;!=>(EWJ2AG-:F"#$$^[3R3@-1$Q;^'``V`2E@'S"H"3-,X,!)5!)>NH"4'$7S&VGB*:I. -M(&I@^%`>\Z[`T%NRFD -MGJ\C8QU.1*2;!V$34J`PX5O3IB6*KD"*I@F`EA`BI"77Z2(('XU0$"1#0*>3 -M\'*$+89IZ!DQY2_M@4PQ!3Q_PR0=#7`(791X],EP--!EHB!4KP\TWBV2QT#* -MB`A?(/:[Y/L!D`%LFN@E"@GQ$(DR)L$5#5I4H.V@*X!':PG4F-*!X))YRW@H -M.$'T-*"6#M)*5%3B8"V1X42(/I!!\H8F2\@1JICQ*EG for - * testing ISO9660 image with Joliet extension. - * - * 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 "test.h" - -/* -Execute the following to rebuild the data for this program: - tail -n +35 test_read_format_isojoliet_rr.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -file="long-joliet-file-name.textfile" -echo "hello" >/tmp/iso/$file -ln /tmp/iso/$file /tmp/iso/hardlink -(cd /tmp/iso; ln -s $file symlink) -if [ "$(uname -s)" = "Linux" ]; then # gnu coreutils touch doesn't have -h -TZ=utc touch -afm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir -TZ=utc touch -afm -t 197001030000.02 /tmp/iso/symlink -TZ=utc touch -afm -t 197001020000.01 /tmp/iso -else -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso/hardlink /tmp/iso/$file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso -fi -F=test_read_format_isojoliet_rr.iso.bz2 -mkhybrid -J -uid 1 -gid 2 /tmp/iso | bzip2 > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isojoliet_rr) -{ - const char *refname = "test_read_format_isojoliet_rr.iso.bz2"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* First entry is '.' root directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString(".", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - - /* A directory. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* A regular file with two names ("hardlink" gets returned - * first, so it's not marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualInt(0, archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(6, (int)size); - assertEqualInt(0, offset); - assertEqualInt(0, memcmp(p, "hello\n", 6)); - assertEqualInt(86401, archive_entry_mtime(ae)); - /* mkisofs records their access time. */ - /*assertEqualInt(86401, archive_entry_atime(ae));*/ - /* TODO: Actually, libarchive should be able to - * compute nlinks correctly even without RR - * extensions. See comments in libarchive source. */ - assertEqualInt(2, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* Second name for the same regular file (this happens to be - * returned second, so does get marked as a hardlink). */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("hardlink", archive_entry_hardlink(ae)); - assert(!archive_entry_size_is_set(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - /* TODO: See above. */ - assertEqualInt(2, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* A symlink to the regular file. */ - assertEqualInt(0, archive_read_next_header(a, &ae)); - assertEqualString("symlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("long-joliet-file-name.textfile", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_nlink(ae)); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_rr.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_rr.iso.bz2.uu deleted file mode 100644 index 3eebaac72..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isojoliet_rr.iso.bz2.uu +++ /dev/null @@ -1,31 +0,0 @@ -begin 644 test_read_format_isojoliet_rr.iso.bz2 -M0EIH.3%!62936>6EH6P``/1_____Q_?_9__\/__?8:__GF8DJD`!)$`00>`` -M`(```LD(T`1^`B!(VM*0#1$T&HQ3R2:'J-I-/0&TDT`9-&-)DQ&:`]1DTTC3 -MU&C]$&@C"&&B:$,J>TI@1J>GJGI`R#0R:!B:,F"!B:&C3)@)D:&)@3)D'``` -M``````````````````#@`````````````````````D2$($&5/9%/34;*>GJA -MIDVIFH](-&TGI#T@:`TT;:2-/4/4V4/2;1-'I+`43=>#%["-XX:D%L%8K`LT -M-%+E!I!YQY_+%Q'C\AJ4-.YA!/G -M(`!+PL$D@#5JA+%AM"PXLM`E6T-@)"2-$$TH&P0T"38FT(;S(<`0-"0)(LL@ -M*VD&J"3L8D*!B4Z4BDH&1*8*HTX;Y_%O%)D;^G*H*01KZDLL2798ECD0A(0V -M(-MB1GOZ:I[$X^LBZN'P;/J8^L" -MA7A9[.K!&_*:=4M&.]L^3@[[D4 -M]$ED_&Q)A=TY6LXW(#$A-,AL9,J`O@KP6@2D"3(328TAC`\37E4HK3A44(Z(#R`Y,F -M'@@%A&"V6=L%0$M(YO0!=BVM0M$"+8)]W:Z=Z[O`HF\DXIDY8$@FF,'LPH&, -M8,3!H9;B+"$`@!C/!@4GK;!*)1%D^=!%-$JS%RQY/):".-=."&LZ\E$;_/I, -ML&1J3;_:NA56-&T=P^RTM4<;1%X0+P`&-\Q_Y5,3P1E$(!,(A5D*&Q,S<=EN -MD07S"!(.:"GH:I&0VR,5>=+&:N/1,9?KMG*Z^*]GL."Z9\90N.\EF7)2%QI69%$&YD0?*"89$@0VDZ2>B+ -M&"0=="KJ7!SJ.RZB)$1:@O($D*-`46,N*!/1.OPX[Z`R$&E?`'0`EJQ"!CM4 -M#<-MZDN2,<0:05&^J\0M6-=B(]1R5P=<1BS7S+$:0`XL(S)0%VUGL&-T`M&4 -MC6NZ%DBZR,WQ6LPPSH&OUJKNCG3KITT$S(A4(VA!,`L+=+?)"]FA0%L$%*0Z -M=@ZYPBFV0NM&XGDJ<*-E*T;R8+(R,,F1!R_TP@1;I`*+ZRJ>!.R0,J-*])LA -MXBO-KCS8Y[*2P-7&;_._;R!*BOBN`8,Y-,MWHE6C/"9)&K8P.[(-O=4$E=(; -MV$50*9358;*&"/D4+);CFM`KR/4QC3MQ6!PX,P?-1BVH-!B@=66:""ET8H&R -MU5'YE@&"K!9?9)4Z$&AOG!=F'Z#TVE^I]AB@G74;16:A!%LE!MXX`^3L7#O@ -MSZ.E5:&6QBNAVBK-S;57A9[(+XCORVN2`RBZ7C]YES@&0B=O6E)A_V6=?=-<)+2A0/@PYT^F4)RZYM^5TF$^3G=)%$5/RPJQL20A(RT?*OS8 --NHO_%W)%.%"0Y:6A;``` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.c deleted file mode 100644 index a23fb03c4..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.c +++ /dev/null @@ -1,210 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_isorr_bz2.c,v 1.5 2008/09/01 05:38:33 kientzle Exp $"); - -/* -PLEASE use old cdrtools; mkisofs verion is 2.01. -This version mkisofs made wrong "SL" System Use Entry of RRIP. - -Execute the following command to rebuild the data for this program: - tail -n +32 test_read_format_isorr_bz2.c | /bin/sh - -rm -rf /tmp/iso -mkdir /tmp/iso -mkdir /tmp/iso/dir -echo "hello" >/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -(cd /tmp/iso; ln -s .///file symlink5) -(cd /tmp/iso; ln -s /tmp//../ symlink6) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink /tmp/iso/symlink5 -F=test_read_format_isorr_bz2.iso.bz2 -mkhybrid -R -uid 1 -gid 2 /tmp/iso | bzip2 > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isorr_bz2) -{ - const char *refname = "test_read_format_isorr_bz2.iso.bz2"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 10; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/.. (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file with "/" components. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".///file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp//.. - * (with "/" and ".." components) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp//..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.iso.bz2.uu deleted file mode 100644 index 35bd49911..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_bz2.iso.bz2.uu +++ /dev/null @@ -1,26 +0,0 @@ -begin 644 test_read_format_isorr_bz2.iso.bz2 -M0EIH.3%!629361^[8GT``-I_W?__Z_Q5X__Z/__?8*?OWB8A_R2```4@`(`" -M@0C0`[X.@;"X4N!H13U3:3U,TTF30-`T:9!IH:`:`!H&@`T-,@T&AD`TU`@: -MFFDT](]$T3"&1@`",0`#3`$8`@TPFFF!HU%,IFHTV4TTT:`!HT`#0```#0`# -MU#0``!QH:`-``T````&@````&0``#$`12(F2:1Z:GHU&$,$#1IHTR:#0```T -M```-&F1B5C+"&F]A9Z?`U1J4+Y`J<.R%DQ,4_M&L-&]P!VH0THE"001`PKEQ -ME0`&9.7LA`.V0`"_Z$%$0`=]@R77`LU0AC! -M%@7\Q3`%DJ%=(0D"('\[&MK[J*15!$`=K+&R-YNQ!N+%&C)7.T-#E1>IVJ[L -M[Z9N]_H#7;&H;!)'O@,VY`YJ-R0)C14:^@C;.7"EG9(L(S&HOPA4)@D"R1@H -M8DS22Y,"9B-XEZJ9"4Q@P/HBL$Q0GJHO'K.]Z9#V)6%C-*$=%1F\SI*/1TK= -MN.<,!."80/-@)&42M3D9",BA1GJ5.?`:ESRT%@I33,AKD0*,&I02?X[HH)67 -M?]KD&>W9J3OH4Z3%F1O%/UTEWU%*2RH[CL6)ZPT:1!,462+PJ20)T"!&A"&% -M+,$`D@@*B@D()X4/A92B1'-B)DEJF7R\W/V!V6_2O$!Q8R+C1PP!@B*!@)"4 -MD,2&P3N:C7$0P+4%#64U!CJ>BNO5*-8JS@"8'&/E4>D`.HTHL96`+%?`$^AF -M()HE49JS"KT92H!#R%5R33$E7](2I&CAZW+#`AJ:J!&58)9S)AO3=?["VH1^ -M3#)/();9KC%[E1J,5<&N(1,S],$*[)-H$^"6Q`(((8@2$4OD0,1]$2P\U-F. -M85F>3TM?8G8YMVM*;8!.`"X+$H#`R-ZGR2HE<-"5*MDB@R.>4'[#((D`-A%T -MZM;_9X1L"$-E4B=@[24#0MD=22LJK0R`,8&T$A1G#I6(B>`/]A,S@1,:WV$RA5P'4C0:D\"`G6`HAA7 -ML/K"'V(4B'7)&-/-%:31TQU=%BQ6)LBX\S(XB*C"82F+M5LTR"!.@$(9&R/< -M#`M+J68NWY?P4YF=3=H)+D]8-YC6AN6+'O,\)E&/^)4,4$2&,<9CSR@V!F-P ->@G!B;(\/.2E,^!VZA%!$`/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -(cd /tmp/iso; ln -s .///file symlink5) -(cd /tmp/iso; ln -s /tmp//../ symlink6) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -F=test_read_format_isorr_new_bz2.iso.bz2 -mkhybrid -R -uid 1 -gid 2 /tmp/iso | bzip2 > $F -uuencode $F $F > $F.uu -exit 1 - */ - -DEFINE_TEST(test_read_format_isorr_new_bz2) -{ - const char *refname = "test_read_format_isorr_new_bz2.iso.bz2"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 10; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/ (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/../ (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/../", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp/", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink5", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file with "/" components. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".///file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink6", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp//../ - * (with "/" and ".." components) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp//../", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_new_bz2.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_new_bz2.iso.bz2.uu deleted file mode 100644 index 8f71b2133..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isorr_new_bz2.iso.bz2.uu +++ /dev/null @@ -1,27 +0,0 @@ -begin 644 test_read_format_isorr_bz2.iso.bz2 -M0EIH.3%!629366".K#H``-A__?__>_QUY_^Z/__?X*?OWF8DJU4`)```A2`` -M@`_!"-`#[PZUHUSNPID``R`-#0```-``:`!ZAH`!B43U!!H````:``! -MH`````````!H<````````````````````R!%(D":GJ/4R:/4-/4/4T&FC1D! -MIDR9`!H:`R#0```>IDPZ"IJ"51(^XL`L)`>(`<*0^$EX#Q>,#L:MV;5JVQV= -M*'5(F$`SB``7_P@HB`#N;1`C(A33(41$0!K0@8()6IU:$%H"`*U$@ASD4\7@4H:M -M/;H$!]NVG>'?XLX(6*(:("IE4D=H`(;^!@D$0)=;MV[0(H(@#JX(V7;!>#$8 -MK(42:.-CC&QVZCLE;ZQ+F9`,,8%P%@40:8`*S)0.,C>R!,"*A_,='-,F%*QI -ME-&I>C%@(`28!"8HE!$((`2`R"09F"02"9Q3%\ADPX2<#B(VB6E3DAM8'S14 -M!+83_"+C9]4\\#VJ:XJC1BE)&05\OI8\]C"0RD2#IJ,.1,D008)*16AD7$9! -M0HST*KC0&A9T:"F4DRH3",`/4\1=/][@1O?OOM'D;EQ$6KD>_-5C2%&UQ&JK -M4RHJJDN*QQYO3Y/U52T@[C0-ZT:,2E,,*8P2DW"02E(D$,$I(/X`I)=,""-U -M*EVEF0UF2MZMQ>/R>7TDF*_;G8$%BB\&X3@T@*&GL$<13YU4-BQ*4BL9XO*#`22@]T)]S(Q0&1410C#$P`+O;PR(PG>R,J)2/S -MEKA(_@KQY]83UZ6(JM-P`[<40P*1;U8*97D')9[4=23%Y;HRGO66:_,45O@L -M>R+2=:M&U28';7DOGQ7W0 -M?D:EQ\A?`6`TH!PZU.R>:A$PCQ*KV-2Q9H3JA\!TD4!<2-N7L'XT!'R(H^AB -M)^3]JJ#QKK54V!EZQT@YP^Q5&+?#(K%)AH&H8Z%]!@T.OE`]>32]-%Q\QB#+ -M\',@44"HRUPP9+MYL8.>\Q[@6&<,5!MNU%9L(KK&9C[8\DR^CY9=]ED*HU+J -M,P9Q=RA4U'R+M#7B\,S_$=MBFS*`KD%*UQRE+"S-9!=DZ2419IV`S`/tmp/iso/file -dd if=/dev/zero count=1 bs=12345678 >>/tmp/iso/file -ln /tmp/iso/file /tmp/iso/hardlink -(cd /tmp/iso; ln -s file symlink) -(cd /tmp/iso; ln -s /tmp/ symlink2) -(cd /tmp/iso; ln -s /tmp/../ symlink3) -(cd /tmp/iso; ln -s .././../tmp/ symlink4) -TZ=utc touch -afhm -t 197001020000.01 /tmp/iso /tmp/iso/file /tmp/iso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/iso/symlink -mkzftree /tmp/iso /tmp/ziso -TZ=utc touch -afhm -t 197001020000.01 /tmp/ziso /tmp/ziso/file /tmp/ziso/dir -TZ=utc touch -afhm -t 197001030000.02 /tmp/ziso/symlink -mkhybrid -R -uid 1 -gid 2 -z /tmp/ziso | bzip2 > test_read_format_isozisofs_bz2.iso.bz2 -F=test_read_format_isozisofs_bz2.iso.bz2 -uuencode $F $F > $F.uu -exit 1 - - */ - -DEFINE_TEST(test_read_format_isozisofs_bz2) -{ - const char *refname = "test_read_format_isozisofs_bz2.iso.bz2"; - struct archive_entry *ae; - struct archive *a; - const void *p; - size_t size; - off_t offset; - int i; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r == ARCHIVE_WARN) { - skipping("bzip2 reading not fully supported on this platform"); - assertEqualInt(0, archive_read_finish(a)); - return; - } - assertEqualInt(0, r); - assertEqualInt(0, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_filename(a, refname, 10240)); - - /* Retrieve each of the 8 files on the ISO image and - * verify that each one is what we expect. */ - for (i = 0; i < 8; ++i) { - assertEqualInt(0, archive_read_next_header(a, &ae)); - - if (strcmp(".", archive_entry_pathname(ae)) == 0) { - /* '.' root directory. */ - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - /* Now, we read timestamp recorded by RRIP "TF". */ - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - /* Now, we read links recorded by RRIP "PX". */ - assertEqualInt(3, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt((int)size, 0); - } else if (strcmp("dir", archive_entry_pathname(ae)) == 0) { - /* A directory. */ - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - assertEqualInt(2048, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("file", archive_entry_pathname(ae)) == 0) { - /* A regular file. */ - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(12345684, archive_entry_size(ae)); - assertEqualInt(0, - archive_read_data_block(a, &p, &size, &offset)); - assertEqualInt(0, offset); - assertEqualMem(p, "hello\n", 6); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(86401, archive_entry_atime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("hardlink", archive_entry_pathname(ae)) == 0) { - /* A hardlink to the regular file. */ - /* Note: If "hardlink" gets returned before "file", - * then "hardlink" will get returned as a regular file - * and "file" will get returned as the hardlink. - * This test should tolerate that, since it's a - * perfectly permissible thing for libarchive to do. */ - assertEqualString("hardlink", archive_entry_pathname(ae)); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_hardlink(ae)); - assertEqualInt(0, archive_entry_size_is_set(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(86401, archive_entry_mtime(ae)); - assertEqualInt(2, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink", archive_entry_pathname(ae)) == 0) { - /* A symlink to the regular file. */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("file", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(172802, archive_entry_mtime(ae)); - assertEqualInt(172802, archive_entry_atime(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink2", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp (an absolute path) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink3", archive_entry_pathname(ae)) == 0) { - /* A symlink to /tmp/.. (with a ".." component) */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString("/tmp/..", archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else if (strcmp("symlink4", archive_entry_pathname(ae)) == 0) { - /* A symlink to a path with ".." and "." components */ - assertEqualInt(AE_IFLNK, archive_entry_filetype(ae)); - assertEqualString(".././../tmp", - archive_entry_symlink(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualInt(1, archive_entry_stat(ae)->st_nlink); - assertEqualInt(1, archive_entry_uid(ae)); - assertEqualInt(2, archive_entry_gid(ae)); - } else { - failure("Saw a file that shouldn't have been there"); - assertEqualString(archive_entry_pathname(ae), ""); - } - } - - /* End of archive. */ - assertEqualInt(ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify archive format. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660_ROCKRIDGE); - - /* Close the archive. */ - assertEqualInt(0, archive_read_close(a)); - assertEqualInt(0, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_isozisofs_bz2.iso.bz2.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_isozisofs_bz2.iso.bz2.uu deleted file mode 100644 index dd56f6025..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_isozisofs_bz2.iso.bz2.uu +++ /dev/null @@ -1,27 +0,0 @@ -begin 644 test_read_format_isozisofs_bz2.iso.bz2 -M0EIH.3%!62936>PH7^L``--_____R_S78__XO__?\*?OWG8E_@$`)``H!V`@ -M`1@$`L%(T`/>"@4;0TV>#1$$1Z0T#$`:!ZAZ(`:#1H`!H-!Z@'J-`]30T!H` -M`::D](!/1&J>$RFTC(9'J`>ID!IH,@,`@!ID8@:#0`P0(-,3```````````` -M``!&$8````(5!&3)IA&1HP$&`1IH8`$PFFA@`1II@`AID8!,:")1!$8J>R)@ -M4]1M-3:CU!Z@](T&C0#0``TV4!B`/4T:#0Q&BXP#6W-XB=$X@M5PJW.GJ!JF -MMKFP'4Z]`NMVI5#T&N_:21$1$04?`C@G]1D+G4&7TH%$I$`!3 -M_?Y"P-0Q2$P76;]$?#W]_0LZU^.N&IEV=H,&,+QN**>N"5?`@;RFA00W)>?I -ME-Q>Q`RGC1#/ZTF!2HX<@1`,M@A`&@OXPL4C>S#5N:CMSJD7M;REW.452Q\O -MAP]FP#8@\$P"&T5_)!O/:X:!ZM+?*@4L4W6FTF6ZN;.PTNCOQ*/D8S/"PNWFD8ZG1HZ%S]U"EUJ5V84V(H6'6U4N(Q9P-WM!R`(B(*([H/^PVN1%$QI(XU0E]((1!"=:.L0;R& -ME-`0ZA-H8K(:336Z&8=F'C%V%@@TO>@(6]]-.@_=,)J.QEBA'N,,E60.KM?, -M779&PQ60;(A$ZZZB'@=0T!.\+`(0_$1(@C$V40+KK4;P<:/!'4%A>3CMEO:Z -MOMP'DF;`*X0OAX.`4+'*R61R#>AH%.B^(M&1^4I\`L$2(;U'IJ*WZZ8#8$(: -MYB#]C:)1H>6.G)691>+`%4-O"2DXQ=DNI._A9JZ$'"XVC0("Y$*18""8BA3K'G:%.$"G -ML4>@G)GU8^RB-X6J7/;U[@^(2F^5_28]$C;,FJ0@/-8F3;ZX>ZX4Z!;AUH;Y -MV+N\Y6E4P!R>"5\ZPNZ9C"KMG!Q:=K[]*775J'=<06AY@%01,]4B4A -K$N);0`$@!;IGD:NLCA.,W8@9$#WT00=$`$1$!!(,95L%W)%.%"0["A?ZP``` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_mtree.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_mtree.c deleted file mode 100644 index f42f73aab..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_mtree.c +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_mtree.c,v 1.4 2008/09/18 04:13:36 kientzle Exp $"); - -/* Single entry with a hardlink. */ -static unsigned char archive[] = { - "#mtree\n" - "file type=file uid=18 mode=0123 size=3\n" - "dir type=dir\n" - " file\\040with\\040space type=file uid=18\n" - " ..\n" - "file\\040with\\040space type=file\n" - "dir2 type=dir\n" - " dir3a type=dir\n" - " indir3a type=file\n" - "dir2/fullindir2 type=file mode=0777\n" - " ..\n" - " indir2 type=file\n" - " dir3b type=dir\n" - " indir3b type=file\n" - " ..\n" - " ..\n" - "notindir type=file\n" - "dir2/fullindir2 mode=0644\n" -}; - -DEFINE_TEST(test_read_format_mtree) -{ - char buff[16]; - struct archive_entry *ae; - struct archive *a; - FILE *f; - - /* - * An access error occurred on some platform when mtree - * format handling open a directory. It is for through - * the routine which open a directory that we create - * "dir" and "dir2" directories. - */ - assertMakeDir("dir", 0775); - assertMakeDir("dir2", 0775); - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - - /* - * Read "file", whose data is available on disk. - */ - f = fopen("file", "wb"); - assert(f != NULL); - assertEqualInt(3, fwrite("hi\n", 1, 3, f)); - fclose(f); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_MTREE); - assertEqualString(archive_entry_pathname(ae), "file"); - assertEqualInt(archive_entry_uid(ae), 18); - assertEqualInt(AE_IFREG, archive_entry_filetype(ae)); - assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0123); - assertEqualInt(archive_entry_size(ae), 3); - assertEqualInt(3, archive_read_data(a, buff, 3)); - assertEqualMem(buff, "hi\n", 3); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir"); - assertEqualInt(AE_IFDIR, archive_entry_filetype(ae)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir/file with space"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "file with space"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3a"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3a/indir3a"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/fullindir2"); - assertEqualInt(archive_entry_mode(ae), AE_IFREG | 0644); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/indir2"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3b"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "dir2/dir3b/indir3b"); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString(archive_entry_pathname(ae), "notindir"); - - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_pax_bz2.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_pax_bz2.c deleted file mode 100644 index 2f49b9881..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_pax_bz2.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_pax_bz2.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -'B','Z','h','9','1','A','Y','&','S','Y',152,180,30,185,0,0,140,127,176,212, -144,0,' ','@',1,255,226,8,'d','H',' ',238,'/',159,'@',0,16,4,'@',0,8,'0', -0,216,'A',164,167,147,'Q',147,'!',180,'#',0,'L',153,162,'i',181,'?','P',192, -26,'h','h',209,136,200,6,128,13,12,18,132,202,'5','O',209,'5','=',26,'2', -154,7,168,12,2,'d',252,13,254,29,'4',247,181,'l','T','i',130,5,195,1,'2', -'@',146,18,251,245,'c','J',130,224,172,'$','l','4',235,170,186,'c','1',255, -179,'K',188,136,18,208,152,192,149,153,10,'{','|','0','8',166,3,6,9,128,172, -'(',164,220,244,149,6,' ',243,212,'B',25,17,'6',237,13,'I',152,'L',129,209, -'G','J','<',137,'Y',16,'b',21,18,'a','Y','l','t','r',160,128,147,'l','f', -'~',219,206,'=','?','S',233,'3',251,'L','~',17,176,169,'%',23,'_',225,'M', -'C','u','k',218,8,'q',216,'(',22,235,'K',131,136,146,136,147,202,0,158,134, -'F',23,160,184,'s','0','a',246,'*','P',7,2,238,'H',167,10,18,19,22,131,215, -' '}; - -DEFINE_TEST(test_read_format_pax_bz2) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r != ARCHIVE_OK) { - archive_read_close(a); - skipping("Bzip2 unavailable"); - return; - } - assertEqualIntA(a,ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a,ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a,ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE); - assertEqualIntA(a,ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.c deleted file mode 100644 index fbaf98d41..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.c +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * Copyright (c) 2007 Kai Wang - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_read_format_raw) -{ - char buff[512]; - struct archive_entry *ae; - struct archive *a; - const char *reffile1 = "test_read_format_raw.data"; - const char *reffile2 = "test_read_format_raw.data.Z"; - - /* First, try pulling data out of an uninterpretable file. */ - extract_reference_file(reffile1); - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, reffile1, 512)); - - /* First (and only!) Entry */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("data", archive_entry_pathname(ae)); - /* Most fields should be unset (unknown) */ - assert(!archive_entry_size_is_set(ae)); - assert(!archive_entry_atime_is_set(ae)); - assert(!archive_entry_ctime_is_set(ae)); - assert(!archive_entry_mtime_is_set(ae)); - assertEqualInt(4, archive_read_data(a, buff, 32)); - assertEqualMem(buff, "foo\n", 4); - - /* Test EOF */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - - /* Second, try the same with a compressed file. */ - extract_reference_file(reffile2); - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_filename(a, reffile2, 1)); - - /* First (and only!) Entry */ - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("data", archive_entry_pathname(ae)); - /* Most fields should be unset (unknown) */ - assert(!archive_entry_size_is_set(ae)); - assert(!archive_entry_atime_is_set(ae)); - assert(!archive_entry_ctime_is_set(ae)); - assert(!archive_entry_mtime_is_set(ae)); - assertEqualInt(4, archive_read_data(a, buff, 32)); - assertEqualMem(buff, "foo\n", 4); - - /* Test EOF */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.Z.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.Z.uu deleted file mode 100644 index 3fe4deaba..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.Z.uu +++ /dev/null @@ -1,4 +0,0 @@ -begin 644 test_read_format_raw.data.Z -('YV09MZ\40`` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.uu deleted file mode 100644 index 7c68a2caa..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_raw.data.uu +++ /dev/null @@ -1,4 +0,0 @@ -begin 644 test_read_format_raw.data -$9F]O"@`` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_tar.c deleted file mode 100644 index 00eb76e5a..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar.c +++ /dev/null @@ -1,480 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_tar.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Each of these archives is a short archive with a single entry. The - * corresponding verify function verifies the entry structure returned - * from libarchive is what it should be. The support functions pad with - * lots of zeros, so we can trim trailing zero bytes from each hardcoded - * archive to save space. - * - * The naming here follows the tar file type flags. E.g. '1' is a hardlink, - * '2' is a symlink, '5' is a dir, etc. - */ - -/* Empty archive. */ -static unsigned char archiveEmpty[] = { - /* 512 zero bytes */ - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 -}; - -static void verifyEmpty(void) -{ - struct archive_entry *ae; - struct archive *a; - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, archiveEmpty, 512)); - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualString(archive_compression_name(a), "none"); - failure("512 zero bytes should be recognized as a tar archive."); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); - - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - -/* Single entry with a hardlink. */ -static unsigned char archive1[] = { -'h','a','r','d','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', -'0','6','4','4',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0', -' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4','6', -'0','5','2','6','6','2',' ','0','1','3','0','5','7',0,' ','1','f','i','l', -'e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0,'0', -'0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0', -'0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '}; - -static void verify1(struct archive_entry *ae) -{ - /* A hardlink is not a symlink. */ - assert(archive_entry_filetype(ae) != AE_IFLNK); - /* Nor is it a directory. */ - assert(archive_entry_filetype(ae) != AE_IFDIR); - assertEqualInt(archive_entry_mode(ae) & 0777, 0644); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "hardlink"); - assertEqualString(archive_entry_hardlink(ae), "file"); - assert(archive_entry_symlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184388530); -} - -/* Verify that symlinks are read correctly. */ -static unsigned char archive2[] = { -'s','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', -'0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', -'5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', -'6','0','5','4','1','0','1',' ','0','0','1','3','3','2','3',' ','2','f','i', -'l','e',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; - -static void verify2(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "symlink"); - assertEqualString(archive_entry_symlink(ae), "file"); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184389185); -} - -/* Character device node. */ -static unsigned char archive3[] = { -'d','e','v','c','h','a','r',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', -'0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', -'5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', -'6','0','5','4','1','0','1',' ','0','0','1','2','4','1','2',' ','3',0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; - -static void verify3(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFCHR); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "devchar"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184389185); -} - -/* Block device node. */ -static unsigned char archive4[] = { -'d','e','v','b','l','o','c','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', -'0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', -'5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', -'6','0','5','4','1','0','1',' ','0','0','1','2','5','7','0',' ','4',0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; - -static void verify4(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFBLK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "devblock"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184389185); -} - -/* Directory. */ -static unsigned char archive5[] = { -'.',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0', -'7','5','5',' ',0,'0','0','1','7','5','0',' ',0,'0','0','1','7','5','0', -' ',0,'0','0','0','0','0','0','0','0','0','0','0',' ','1','0','3','3', -'4','0','4','1','7','3','6',' ','0','1','0','5','6','1',0,' ','5',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'0','0','0','0','0','0',' ',0,'0','0','0','0','0','0',' '}; - -static void verify5(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFDIR); - assertEqualInt(archive_entry_mtime(ae), 1131430878); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); -} - -/* fifo */ -static unsigned char archive6[] = { -'f','i','f','o',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0', -'0','0','7','5','5',' ','0','0','0','1','7','5','0',' ','0','0','0','1','7', -'5','0',' ','0','0','0','0','0','0','0','0','0','0','0',' ','1','0','6','4', -'6','0','5','4','1','0','1',' ','0','0','1','1','7','2','4',' ','6',0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',0, -'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'0','0','0','0','0','0','0',' ','0','0','0','0','0','0','0',' '}; - -static void verify6(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFIFO); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "fifo"); - assert(archive_entry_symlink(ae) == NULL); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184389185); -} - -/* GNU long link name */ -static unsigned char archiveK[] = { -'.','/','.','/','@','L','o','n','g','L','i','n','k',0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0',0,'0','0','0', -'0','0','0','0',0,'0','0','0','0','0','0','0','0','6','6','6',0,'0','0','0', -'0','0','0','0','0','0','0','0',0,'0','1','1','7','1','5',0,' ','K',0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u','s','t','a','r',' ',' ', -0,'r','o','o','t',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'w','h','e','e','l',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'t', -'h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o','n','g','_', -'s','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c','d','e','f', -'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', -'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', -'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i', -'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a', -'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', -'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l', -'m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', -'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', -'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', -'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g', -'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', -'_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', -'s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j', -'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', -'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', -'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m', -'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e', -'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x', -'y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p', -'q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h', -'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -'s','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','1', -'2','0','7','5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5', -'0',0,'0','0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0', -'5','6','7','7','0',0,'0','3','5','4','4','7',0,' ','2','t','h','i','s','_', -'i','s','_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l', -'i','n','k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j', -'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', -'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', -'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l',0, -'u','s','t','a','r',' ',' ',0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,'t','i','m'}; - -static void verifyK(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "symlink"); - assertEqualString(archive_entry_symlink(ae), - "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz"); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184390648); -} - -/* TODO: GNU long name */ - -/* TODO: Solaris ACL */ - -/* Pax extended long link name */ -static unsigned char archivexL[] = { -'.','/','P','a','x','H','e','a','d','e','r','s','.','8','6','9','7','5','/', -'s','y','m','l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0','0','6','4','4',0,'0','0','0','1', -'7','5','0',0,'0','0','0','1','7','5','0',0,'0','0','0','0','0','0','0','0', -'7','5','3',0,'1','0','6','4','6','0','5','7','6','1','1',0,'0','1','3','7', -'1','4',0,' ','x',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'u', -'s','t','a','r',0,'0','0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0',0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'4','5','1',' ','l','i','n','k','p','a','t', -'h','=','t','h','i','s','_','i','s','_','a','_','v','e','r','y','_','l','o', -'n','g','_','s','y','m','l','i','n','k','_','b','o','d','y','_','a','b','c', -'d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', -'w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n', -'o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f', -'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y', -'z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', -'r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i', -'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a', -'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t', -'u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l', -'m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', -'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', -'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', -'p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g', -'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', -'_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r', -'s','t','u','v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j', -'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b', -'c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u', -'v','w','x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m', -'n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d','e', -'f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x', -'y','z',10,'2','0',' ','a','t','i','m','e','=','1','1','8','4','3','9','1', -'0','2','5',10,'2','0',' ','c','t','i','m','e','=','1','1','8','4','3','9', -'0','6','4','8',10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'s','y','m', -'l','i','n','k',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0','0','0','0','7', -'5','5',0,'0','0','0','1','7','5','0',0,'0','0','0','1','7','5','0',0,'0', -'0','0','0','0','0','0','0','0','0','0',0,'1','0','6','4','6','0','5','6', -'7','7','0',0,'0','3','7','1','2','1',0,' ','2','t','h','i','s','_','i','s', -'_','a','_','v','e','r','y','_','l','o','n','g','_','s','y','m','l','i','n', -'k','_','b','o','d','y','_','a','b','c','d','e','f','g','h','i','j','k','l', -'m','n','o','p','q','r','s','t','u','v','w','x','y','z','_','a','b','c','d', -'e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', -'x','y','z','_','a','b','c','d','e','f','g','h','i','j','k','l','m','u','s', -'t','a','r',0,'0','0','t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,'t','i','m',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,'0','0','0','0','0','0','0',0,'0','0','0','0','0','0','0'}; - -static void verifyxL(struct archive_entry *ae) -{ - assertEqualInt(archive_entry_filetype(ae), AE_IFLNK); - assertEqualInt(archive_entry_mode(ae) & 0777, 0755); - assertEqualInt(archive_entry_uid(ae), 1000); - assertEqualInt(archive_entry_gid(ae), 1000); - assertEqualString(archive_entry_uname(ae), "tim"); - assertEqualString(archive_entry_gname(ae), "tim"); - assertEqualString(archive_entry_pathname(ae), "symlink"); - assertEqualString(archive_entry_symlink(ae), - "this_is_a_very_long_symlink_body_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_" - "abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz"); - assert(archive_entry_hardlink(ae) == NULL); - assertEqualInt(archive_entry_mtime(ae), 1184390648); -} - - -/* TODO: Any other types of headers? */ - -static void verify(unsigned char *d, size_t s, - void (*f)(struct archive_entry *), - int compression, int format) -{ - struct archive_entry *ae; - struct archive *a; - unsigned char *buff = malloc(100000); - - memcpy(buff, d, s); - memset(buff + s, 0, 2048); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_memory(a, buff, s + 1024)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), compression); - assertEqualInt(archive_format(a), format); - - /* Verify the only entry. */ - f(ae); - - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - free(buff); -} - -DEFINE_TEST(test_read_format_tar) -{ - verifyEmpty(); - verify(archive1, sizeof(archive1), verify1, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archive2, sizeof(archive2), verify2, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archive3, sizeof(archive3), verify3, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archive4, sizeof(archive4), verify4, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archive5, sizeof(archive5), verify5, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archive6, sizeof(archive6), verify6, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_USTAR); - verify(archiveK, sizeof(archiveK), verifyK, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_GNUTAR); - verify(archivexL, sizeof(archivexL), verifyxL, - ARCHIVE_COMPRESSION_NONE, ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.c deleted file mode 100644 index eddab4194..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_tar_empty_filename.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Tar entries with empty filenames are unusual, but shouldn't crash us. - */ -DEFINE_TEST(test_read_format_tar_empty_filename) -{ - char name[] = "test_read_format_tar_empty_filename.tar"; - struct archive_entry *ae; - struct archive *a; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - extract_reference_file(name); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); - - /* Read first entry. */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("", archive_entry_pathname(ae)); - assertEqualInt(1208628157, archive_entry_mtime(ae)); - assertEqualInt(1000, archive_entry_uid(ae)); - assertEqualString("tim", archive_entry_uname(ae)); - assertEqualInt(0, archive_entry_gid(ae)); - assertEqualString("wheel", archive_entry_gname(ae)); - assertEqualInt(040775, archive_entry_mode(ae)); - - /* Verify the end-of-archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Verify that the format detection worked. */ - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_NONE); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.tar.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.tar.uu deleted file mode 100644 index f8a4f4f2f..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_tar_empty_filename.tar.uu +++ /dev/null @@ -1,39 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_read_format_tar_empty_filename.tar.uu,v 1.2 2008/07/03 03:26:30 peter Exp $ -begin 644 test_compat_tar_1.tar -M```````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````#`P,#',205,'f',29,170,227,'[',179,139, -'\'','L','o',211,':',178,'0',162,134,'*','>','8',24,153,230,147,'R','?',23, -'r','E','8','P',144,237,7,140,'W'}; - -DEFINE_TEST(test_read_format_tbz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - r = archive_read_support_compression_bzip2(a); - if (r != ARCHIVE_OK) { - skipping("Bzip2 support"); - archive_read_finish(a); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_BZIP2); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_tgz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_tgz.c deleted file mode 100644 index 17a86f182..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_tgz.c +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_tgz.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,139,8,0,222,'C','p','C',0,3,211,'c',160,'=','0','0','0','0','7','5','U', -0,210,134,230,166,6,200,'4',28,'(',24,26,24,27,155,24,152,24,154,27,155,')', -24,24,26,152,154,25,'2','(',152,210,193,'m',12,165,197,'%',137,'E','@',167, -148,'d',230,226,'U','G','H',30,234,15,'8','=',10,'F',193,'(',24,5,131,28, -0,0,29,172,5,240,0,6,0,0}; - -DEFINE_TEST(test_read_format_tgz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualInt(ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualInt(ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), - ARCHIVE_COMPRESSION_GZIP); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK,archive_read_finish(a)); -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_txz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_txz.c deleted file mode 100644 index 1f3a159ef..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_txz.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned char archive[] = { -253, 55,122, 88, 90, 0, 0, 4,230,214,180, 70, 2, 0, 33, 1, - 22, 0, 0, 0,116, 47,229,163,224, 5,255, 0, 73, 93, 0, 23, - 0, 51, 80, 24,164,204,238, 45, 77, 28,191, 13,144, 8, 10, 70, - 5,173,215, 47,132,237,145,162, 96, 6,131,168,152, 8,135,161, -189, 73,110,132, 27,195, 52,109,203, 22, 17,168,211, 18,181, 76, - 93,120, 88,154,155,244,141,193,206,170,224, 80,137,134, 67, 1, - 9,123,121,188,247, 28,139, 0, 0, 0, 0, 0,112,184, 17, 5, -103, 16, 8, 73, 0, 1,101,128, 12, 0, 0, 0, 30, 69, 92, 96, -177,196,103,251, 2, 0, 0, 0, 0, 4, 89, 90 -}; - -DEFINE_TEST(test_read_format_txz) -{ - struct archive_entry *ae; - struct archive *a; - int r; - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_XZ); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_tz.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_tz.c deleted file mode 100644 index 3f7075c9d..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_tz.c +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_tz.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char archive[] = { -31,157,144,'.',0,8,28,'H',176,160,193,131,8,19,'*','\\',200,176,'!','B',24, -16,'o',212,168,1,2,0,196,24,18,'a','T',188,152,'q','#',196,143,' ','5',198, -128,'1','c',6,13,24,'4','0',206,176,1,2,198,200,26,'6','b',0,0,'Q',195,161, -205,155,'8','s',234,4,'P','g',14,157,'0','r',',',194,160,147,166,205,206, -132,'D',141,30,'=',24,'R',163,'P',144,21,151,'J',157,'J',181,170,213,171, -'X',179,'j',221,202,181,171,215,175,'`',195,138,29,'K',182,172,217,179,'h', -211,170,']',203,182,173,219,183,'g',1}; - -DEFINE_TEST(test_read_format_tz) -{ - struct archive_entry *ae; - struct archive *a; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, archive, sizeof(archive))); - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - failure("archive_compression_name(a)=\"%s\"", - archive_compression_name(a)); - assertEqualInt(archive_compression(a), ARCHIVE_COMPRESSION_COMPRESS); - failure("archive_format_name(a)=\"%s\"", archive_format_name(a)); - assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.c b/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.c deleted file mode 100644 index 8d4509d5b..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.c +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_format_zip.c,v 1.8 2008/10/21 05:08:35 kientzle Exp $"); - -/* - * The reference file for this has been manually tweaked so that: - * * file2 has length-at-end but file1 does not - * * file2 has an invalid CRC - */ - -DEFINE_TEST(test_read_format_zip) -{ - const char *refname = "test_read_format_zip.zip"; - struct archive_entry *ae; - struct archive *a; - char *buff[128]; - const void *pv; - size_t s; - off_t o; - int r; - - extract_reference_file(refname); - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_open_filename(a, refname, 10240)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("dir/", archive_entry_pathname(ae)); - assertEqualInt(1179604249, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_data_block(a, &pv, &s, &o)); - assertEqualInt((int)s, 0); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("file1", archive_entry_pathname(ae)); - assertEqualInt(1179604289, archive_entry_mtime(ae)); - assertEqualInt(18, archive_entry_size(ae)); - failure("archive_read_data() returns number of bytes read"); - r = archive_read_data(a, buff, 19); - if (r < ARCHIVE_OK) { - if (strcmp(archive_error_string(a), - "libarchive compiled without deflate support (no libz)") == 0) { - skipping("Skipping ZIP compression check: %s", - archive_error_string(a)); - goto finish; - } - } - assertEqualInt(18, r); - assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); - assertA(0 == archive_read_next_header(a, &ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assertEqualInt(1179605932, archive_entry_mtime(ae)); - failure("file2 has length-at-end, so we shouldn't see a valid size"); - assertEqualInt(0, archive_entry_size_is_set(ae)); - failure("file2 has a bad CRC, so reading to end should fail"); - assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19)); - assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); - assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); - assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP); - assert(0 == archive_read_close(a)); -finish: -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - - diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.zip.uu b/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.zip.uu deleted file mode 100644 index b1f04c4fe..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_format_zip.zip.uu +++ /dev/null @@ -1,14 +0,0 @@ -$FreeBSD: src/lib/libarchive/test/test_read_format_zip.zip.uu,v 1.3 2008/10/21 05:08:35 kientzle Exp $ -begin 644 test_read_format_zip.zip -M4$L#!`H`"````%EFLS8````````````````$`!4`9&ER+U54"0`#&55/1M19 -M_4A5>`0`Z`/H`U!+!P@```````````````!02P,$%`````@`;V:S-CHW9CT* -M````$@````4`%0!F:6QE,554"0`#055/1L!9_4A5>`0`Z`/H`\M(S`0`Z`/H`\M(S```4$L!`A<#%``(``@`;V:S-CHW9CT*````$@````4`#0`` -M`````0```.V!1P```&9I;&4Q550%``-!54]&57@``%!+`0(7`Q0`"``(`%IJ -MLS8Z-V8]"@```!(````%``T```````$```#M@8D```!F:6QE,E54!0`#K%M/ -;1E5X``!02P4&``````,``P"_````VP`````` -` -end diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_large.c b/Utilities/cmlibarchive/libarchive/test/test_read_large.c deleted file mode 100644 index f9573951f..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_large.c +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_large.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char testdata[10 * 1024 * 1024]; -static unsigned char testdatacopy[10 * 1024 * 1024]; -static unsigned char buff[11 * 1024 * 1024]; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define open _open -#define close _close -#endif - -/* Check correct behavior on large reads. */ -DEFINE_TEST(test_read_large) -{ - unsigned int i; - int tmpfilefd; - char tmpfilename[] = "test-read_large.XXXXXX"; - size_t used; - struct archive *a; - struct archive_entry *entry; - FILE *f; - - for (i = 0; i < sizeof(testdata); i++) - testdata[i] = (unsigned char)(rand()); - - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assert(NULL != (entry = archive_entry_new())); - archive_entry_set_size(entry, sizeof(testdata)); - archive_entry_set_mode(entry, S_IFREG | 0777); - archive_entry_set_pathname(entry, "test"); - assertA(0 == archive_write_header(a, entry)); - archive_entry_free(entry); - assertA(sizeof(testdata) == archive_write_data(a, testdata, sizeof(testdata))); - assertA(0 == archive_write_finish(a)); - - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); - assertA(0 == archive_read_next_header(a, &entry)); - assertA(0 == archive_read_data_into_buffer(a, testdatacopy, sizeof(testdatacopy))); - assertA(0 == archive_read_finish(a)); - assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); - - - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, sizeof(buff))); - assertA(0 == archive_read_next_header(a, &entry)); - // TODO: Provide a Windows-friendly version of this? - assert(0 < (tmpfilefd = open(tmpfilename, - O_WRONLY | O_CREAT | O_BINARY, 0755))); - assertA(0 == archive_read_data_into_fd(a, tmpfilefd)); - close(tmpfilefd); - assertA(0 == archive_read_finish(a)); - - f = fopen(tmpfilename, "rb"); - fread(testdatacopy, 1, sizeof(testdatacopy), f); - fclose(f); - assert(0 == memcmp(testdata, testdatacopy, sizeof(testdata))); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_pax_truncated.c b/Utilities/cmlibarchive/libarchive/test/test_read_pax_truncated.c deleted file mode 100644 index ed1570981..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_pax_truncated.c +++ /dev/null @@ -1,288 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_pax_truncated.c,v 1.4 2008/12/06 05:59:46 kientzle Exp $"); - -DEFINE_TEST(test_read_pax_truncated) -{ - struct archive_entry *ae; - struct archive *a; - size_t used, i, buff_size = 1000000; - size_t filedata_size = 100000; - char *buff = malloc(buff_size); - char *buff2 = malloc(buff_size); - char *filedata = malloc(filedata_size); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buff_size, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - for (i = 0; i < filedata_size; i++) - filedata[i] = (unsigned char)rand(); - archive_entry_set_atime(ae, 1, 2); - archive_entry_set_ctime(ae, 3, 4); - archive_entry_set_mtime(ae, 5, 6); - archive_entry_set_size(ae, filedata_size); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA((ssize_t)filedata_size - == archive_write_data(a, filedata, filedata_size)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Now, read back a truncated version of the archive and - * verify that we get an appropriate error. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory2(a, buff, i, 13)); - - if (i < 1536) { - assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); - goto wrap_up; - } else { - failure("Archive truncated to %d bytes", i); - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - } - - if (i < 1536 + filedata_size) { - assertA(ARCHIVE_FATAL == archive_read_data(a, filedata, filedata_size)); - goto wrap_up; - } else { - failure("Archive truncated to %d bytes", i); - assertEqualIntA(a, filedata_size, - archive_read_data(a, filedata, filedata_size)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - failure("i=%d minsize=%d", i, - 1536 + 512*((filedata_size + 511)/512) + 512); - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_next_header(a, &ae)); - } else { - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - } - wrap_up: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - - - /* Same as above, except skip the body instead of reading it. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == read_open_memory(a, buff, i, 7)); - - if (i < 1536) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up2; - } else { - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - } - - if (i < 1536 + 512*((filedata_size+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); - goto wrap_up2; - } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 1536 + 512*((filedata_size + 511)/512) + 512) { - assertEqualIntA(a, ARCHIVE_FATAL, - archive_read_next_header(a, &ae)); - } else { - assertEqualIntA(a, ARCHIVE_EOF, - archive_read_next_header(a, &ae)); - } - wrap_up2: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - /* Now, damage the archive in various ways and test the responses. */ - - /* Damage the first size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '9'; - buff2[513] = '9'; - buff2[514] = 'A'; /* Non-digit in size. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = 'A'; /* First character not a digit. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - for (i = 512; i < 520; i++) /* Size over 999999. */ - buff2[i] = '9'; - buff2[i] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '9'; /* Valid format, but larger than attribute area. */ - buff2[513] = '9'; - buff2[514] = '9'; - buff2[515] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = '1'; /* Too small. */ - buff2[513] = ' '; - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the size field in the pax attributes. */ - memcpy(buff2, buff, buff_size); - buff2[512] = ' '; /* No size given. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_WARN, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* Damage the ustar header. */ - memcpy(buff2, buff, buff_size); - buff2[1024]++; /* Break the checksum. */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff2, used)); - assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - /* - * TODO: Damage the ustar header in various ways and fixup the - * checksum in order to test boundary cases in the innermost - * ustar header parsing. - */ - - free(buff); - free(buff2); - free(filedata); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_position.c b/Utilities/cmlibarchive/libarchive/test/test_read_position.c deleted file mode 100644 index 3ee896fad..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_position.c +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_position.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -static unsigned char nulls[10000]; -static unsigned char buff[10000000]; - -/* Check that header_position tracks correctly on read. */ -DEFINE_TEST(test_read_position) -{ - struct archive *a; - struct archive_entry *ae; - size_t write_pos; - intmax_t read_position; - size_t i, j; - size_t data_sizes[] = {0, 5, 511, 512, 513}; - - /* Sanity test */ - assert(sizeof(nulls) + 512 + 1024 <= sizeof(buff)); - - /* Create an archive. */ - assert(NULL != (a = archive_write_new())); - assertA(0 == archive_write_set_format_pax_restricted(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &write_pos)); - - for (i = 0; i < sizeof(data_sizes)/sizeof(data_sizes[0]); ++i) { - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, "testfile"); - archive_entry_set_mode(ae, S_IFREG); - archive_entry_set_size(ae, data_sizes[i]); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(data_sizes[i] - == (size_t)archive_write_data(a, nulls, sizeof(nulls))); - } - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Read the archive back. */ - assert(NULL != (a = archive_read_new())); - assertA(0 == archive_read_support_format_tar(a)); - assertA(0 == archive_read_open_memory2(a, buff, sizeof(buff), 512)); - - read_position = 0; - /* Initial header position is zero. */ - assert(read_position == (intmax_t)archive_read_header_position(a)); - for (j = 0; j < i; ++j) { - assertA(0 == archive_read_next_header(a, &ae)); - assert(read_position - == (intmax_t)archive_read_header_position(a)); - /* Every other entry: read, then skip */ - if (j & 1) - assertEqualInt(ARCHIVE_OK, - archive_read_data_into_buffer(a, buff, 1)); - assertA(0 == archive_read_data_skip(a)); - /* read_data_skip() doesn't change header_position */ - assert(read_position - == (intmax_t)archive_read_header_position(a)); - - read_position += 512; /* Size of header. */ - read_position += (data_sizes[j] + 511) & ~511; - } - - assertA(1 == archive_read_next_header(a, &ae)); - assert(read_position == (intmax_t)archive_read_header_position(a)); - assertA(0 == archive_read_close(a)); - assert(read_position == (intmax_t)archive_read_header_position(a)); - archive_read_finish(a); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_read_truncated.c b/Utilities/cmlibarchive/libarchive/test/test_read_truncated.c deleted file mode 100644 index 60ef983ae..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_read_truncated.c +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_read_truncated.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -char buff[1000000]; -char buff2[100000]; - -DEFINE_TEST(test_read_truncated) -{ - struct archive_entry *ae; - struct archive *a; - unsigned int i; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - for (i = 0; i < sizeof(buff2); i++) - buff2[i] = (unsigned char)rand(); - archive_entry_set_size(ae, sizeof(buff2)); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2))); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* Now, read back a truncated version of the archive and - * verify that we get an appropriate error. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - - if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up; - } else { - assertA(0 == archive_read_next_header(a, &ae)); - } - - if (i < 512 + sizeof(buff2)) { - assertA(ARCHIVE_FATAL == archive_read_data(a, buff2, sizeof(buff2))); - goto wrap_up; - } else { - assertA(sizeof(buff2) == archive_read_data(a, buff2, sizeof(buff2))); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - } - wrap_up: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } - - - - /* Same as above, except skip the body instead of reading it. */ - for (i = 1; i < used + 100; i += 100) { - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, i)); - - if (i < 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - goto wrap_up2; - } else { - assertA(0 == archive_read_next_header(a, &ae)); - } - - if (i < 512 + 512*((sizeof(buff2)+511)/512)) { - assertA(ARCHIVE_FATAL == archive_read_data_skip(a)); - goto wrap_up2; - } else { - assertA(ARCHIVE_OK == archive_read_data_skip(a)); - } - - /* Verify the end of the archive. */ - /* Archive must be long enough to capture a 512-byte - * block of zeroes after the entry. (POSIX requires a - * second block of zeros to be written but libarchive - * does not return an error if it can't consume - * it.) */ - if (i < 512 + 512*((sizeof(buff2) + 511)/512) + 512) { - assertA(ARCHIVE_FATAL == archive_read_next_header(a, &ae)); - } else { - assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - } - wrap_up2: - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_tar_filenames.c b/Utilities/cmlibarchive/libarchive/test/test_tar_filenames.c deleted file mode 100644 index 923995fc5..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_tar_filenames.c +++ /dev/null @@ -1,186 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_tar_filenames.c,v 1.10 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Exercise various lengths of filenames in tar archives, - * especially around the magic sizes where ustar breaks - * filenames into prefix/suffix. - */ - -static void -test_filename(const char *prefix, int dlen, int flen) -{ - char buff[8192]; - char filename[400]; - char dirname[400]; - struct archive_entry *ae; - struct archive *a; - size_t used; - char *p; - int i; - - p = filename; - if (prefix) { - strcpy(filename, prefix); - p += strlen(p); - } - if (dlen > 0) { - for (i = 0; i < dlen; i++) - *p++ = 'a'; - *p++ = '/'; - } - for (i = 0; i < flen; i++) - *p++ = 'b'; - *p = '\0'; - - strcpy(dirname, filename); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax_restricted(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a,0)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, filename); - archive_entry_set_mode(ae, S_IFREG | 0755); - failure("Pathname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* - * Write a dir to it (without trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("Dirname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Tar adds a '/' to directory names. */ - strcat(dirname, "/"); - - /* - * Write a dir to it (with trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("Dirname %d/%d", dlen, flen); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - /* Read the file and check the filename. */ - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Leading '/' preserved on long filenames"); -#else - assertEqualString(filename, archive_entry_pathname(ae)); -#endif - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - - /* - * Read the two dirs and check the names. - * - * Both dirs should read back with the same name, since - * tar should add a trailing '/' to any dir that doesn't - * already have one. We only report the first such failure - * here. - */ - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Trailing '/' preserved on dirnames"); -#else - assertEqualString(dirname, archive_entry_pathname(ae)); -#endif - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - - assertA(0 == archive_read_next_header(a, &ae)); -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("Trailing '/' added to dir names"); -#else - assertEqualString(dirname, archive_entry_pathname(ae)); -#endif - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - - /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_tar_filenames) -{ - int dlen, flen; - - /* Repeat the following for a variety of dir/file lengths. */ - for (dlen = 45; dlen < 55; dlen++) { - for (flen = 45; flen < 55; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - for (dlen = 0; dlen < 140; dlen += 10) { - for (flen = 98; flen < 102; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - for (dlen = 140; dlen < 160; dlen++) { - for (flen = 95; flen < 105; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_tar_large.c b/Utilities/cmlibarchive/libarchive/test/test_tar_large.c deleted file mode 100644 index cca5f8d96..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_tar_large.c +++ /dev/null @@ -1,312 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_tar_large.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -#include -#include -#include - -/* - * This is a somewhat tricky test that verifies the ability to - * write and read very large entries to tar archives. It - * writes entries from 2GB up to 1TB to an archive in memory. - * The memory storage here carefully avoids actually storing - * any part of the file bodies, so it runs very quickly and requires - * very little memory. If you're willing to wait a few minutes, - * you should be able to exercise petabyte entries with this code. - */ - -/* - * Each file is built up by duplicating the following block. - */ -static size_t filedatasize; -static void *filedata; - -/* - * We store the archive as blocks of data generated by libarchive, - * each possibly followed by bytes of file data. - */ -struct memblock { - struct memblock *next; - size_t size; - void *buff; - int64_t filebytes; -}; - -/* - * The total memory store is just a list of memblocks plus - * some accounting overhead. - */ -struct memdata { - int64_t filebytes; - void *buff; - struct memblock *first; - struct memblock *last; -}; - -/* The following size definitions simplify things below. */ -#define KB ((int64_t)1024) -#define MB ((int64_t)1024 * KB) -#define GB ((int64_t)1024 * MB) -#define TB ((int64_t)1024 * GB) - -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t memory_read_skip(struct archive *, void *, size_t request); -#else -static off_t memory_read_skip(struct archive *, void *, off_t request); -#endif -static ssize_t memory_read(struct archive *, void *, const void **buff); -static ssize_t memory_write(struct archive *, void *, const void *, size_t); - - -static ssize_t -memory_write(struct archive *a, void *_private, const void *buff, size_t size) -{ - struct memdata *private = _private; - struct memblock *block; - - (void)a; - - /* - * Since libarchive tries to behave in a zero-copy manner, if - * you give a pointer to filedata to the library, a pointer - * into that data will (usually) pop out here. This way, we - * can tell the difference between filedata and library header - * and metadata. - */ - if ((const char *)filedata <= (const char *)buff - && (const char *)buff < (const char *)filedata + filedatasize) { - /* We don't need to store a block of file data. */ - private->last->filebytes += (int64_t)size; - } else { - /* Yes, we're assuming the very first write is metadata. */ - /* It's header or metadata, copy and save it. */ - block = (struct memblock *)malloc(sizeof(*block)); - memset(block, 0, sizeof(*block)); - block->size = size; - block->buff = malloc(size); - memcpy(block->buff, buff, size); - if (private->last == NULL) { - private->first = private->last = block; - } else { - private->last->next = block; - private->last = block; - } - block->next = NULL; - } - return ((long)size); -} - -static ssize_t -memory_read(struct archive *a, void *_private, const void **buff) -{ - struct memdata *private = _private; - struct memblock *block; - ssize_t size; - - (void)a; - - free(private->buff); - private->buff = NULL; - if (private->first == NULL) { - private->last = NULL; - return (ARCHIVE_EOF); - } - if (private->filebytes > 0) { - /* - * We're returning file bytes, simulate it by - * passing blocks from the template data. - */ - if (private->filebytes > (int64_t)filedatasize) - size = (ssize_t)filedatasize; - else - size = (ssize_t)private->filebytes; - private->filebytes -= size; - *buff = filedata; - } else { - /* - * We need to get some real data to return. - */ - block = private->first; - private->first = block->next; - size = (ssize_t)block->size; - if (block->buff != NULL) { - private->buff = block->buff; - *buff = block->buff; - } else { - private->buff = NULL; - *buff = filedata; - } - private->filebytes = block->filebytes; - free(block); - } - return (size); -} - - -#if ARCHIVE_VERSION_NUMBER < 2000000 -static ssize_t -memory_read_skip(struct archive *a, void *private, size_t skip) -{ - (void)a; /* UNUSED */ - (void)private; /* UNUSED */ - (void)skip; /* UNUSED */ - return (0); -} -#else -static off_t -memory_read_skip(struct archive *a, void *_private, off_t skip) -{ - struct memdata *private = _private; - - (void)a; - - if (private->first == NULL) { - private->last = NULL; - return (0); - } - if (private->filebytes > 0) { - if (private->filebytes < skip) - skip = (off_t)private->filebytes; - private->filebytes -= skip; - } else { - skip = 0; - } - return (skip); -} -#endif - -DEFINE_TEST(test_tar_large) -{ - /* The sizes of the entries we're going to generate. */ - static int64_t tests[] = { - /* Test for 32-bit signed overflow. */ - 2 * GB - 1, 2 * GB, 2 * GB + 1, - /* Test for 32-bit unsigned overflow. */ - 4 * GB - 1, 4 * GB, 4 * GB + 1, - /* 8GB is the "official" max for ustar. */ - 8 * GB - 1, 8 * GB, 8 * GB + 1, - /* Bend ustar a tad and you can get 64GB (12 octal digits). */ - 64 * GB - 1, 64 * GB, - /* And larger entries that require non-ustar extensions. */ - 256 * GB, 1 * TB, 0 }; - int i; - char namebuff[64]; - struct memdata memdata; - struct archive_entry *ae; - struct archive *a; - int64_t filesize; - size_t writesize; - - filedatasize = (size_t)(1 * MB); - filedata = malloc(filedatasize); - memset(filedata, 0xAA, filedatasize); - memset(&memdata, 0, sizeof(memdata)); - - /* - * Open an archive for writing. - */ - a = archive_write_new(); - archive_write_set_format_pax_restricted(a); - archive_write_set_bytes_per_block(a, 0); /* No buffering. */ - archive_write_open(a, &memdata, NULL, memory_write, NULL); - - /* - * Write a series of large files to it. - */ - for (i = 0; tests[i] != 0; i++) { - assert((ae = archive_entry_new()) != NULL); - sprintf(namebuff, "file_%d", i); - archive_entry_copy_pathname(ae, namebuff); - archive_entry_set_mode(ae, S_IFREG | 0755); - filesize = tests[i]; - - archive_entry_set_size(ae, filesize); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - /* - * Write the actual data to the archive. - */ - while (filesize > 0) { - writesize = filedatasize; - if ((int64_t)writesize > filesize) - writesize = (size_t)filesize; - assertA((int)writesize - == archive_write_data(a, filedata, writesize)); - filesize -= writesize; - } - } - - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "lastfile"); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Open the same archive for reading. - */ - a = archive_read_new(); - archive_read_support_format_tar(a); - archive_read_open2(a, &memdata, NULL, - memory_read, memory_read_skip, NULL); - - /* - * Read entries back. - */ - for (i = 0; tests[i] > 0; i++) { - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - sprintf(namebuff, "file_%d", i); - assertEqualString(namebuff, archive_entry_pathname(ae)); - assert(tests[i] == archive_entry_size(ae)); - } - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("lastfile", archive_entry_pathname(ae)); - - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - - /* Close out the archive. */ - assertA(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertA(0 == archive_read_finish(a)); -#endif - - free(memdata.buff); - free(filedata); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_ustar_filenames.c b/Utilities/cmlibarchive/libarchive/test/test_ustar_filenames.c deleted file mode 100644 index 9cbe58c16..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_ustar_filenames.c +++ /dev/null @@ -1,191 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_ustar_filenames.c,v 1.2 2008/08/11 01:19:36 kientzle Exp $"); - -/* - * Exercise various lengths of filenames in ustar archives. - */ - -static void -test_filename(const char *prefix, int dlen, int flen) -{ - char buff[8192]; - char filename[400]; - char dirname[400]; - struct archive_entry *ae; - struct archive *a; - size_t used; - int separator = 0; - int i = 0; - - if (prefix != NULL) { - strcpy(filename, prefix); - i = (int)strlen(prefix); - } - if (dlen > 0) { - for (; i < dlen; i++) - filename[i] = 'a'; - filename[i++] = '/'; - separator = 1; - } - for (; i < dlen + flen + separator; i++) - filename[i] = 'b'; - filename[i++] = '\0'; - - strcpy(dirname, filename); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a,0)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, filename); - archive_entry_set_mode(ae, S_IFREG | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen > 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* - * Write a dir to it (without trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen >= 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* Tar adds a '/' to directory names. */ - strcat(dirname, "/"); - - /* - * Write a dir to it (with trailing '/'). - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, dirname); - archive_entry_set_mode(ae, S_IFDIR | 0755); - failure("dlen=%d, flen=%d", dlen, flen); - if (flen >= 100) { - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - } else { - assertEqualIntA(a, 0, archive_write_header(a, ae)); - } - archive_entry_free(ae); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - if (flen <= 100) { - /* Read the file and check the filename. */ - assertA(0 == archive_read_next_header(a, &ae)); - failure("dlen=%d, flen=%d", dlen, flen); - assertEqualString(filename, archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - } - - /* - * Read the two dirs and check the names. - * - * Both dirs should read back with the same name, since - * tar should add a trailing '/' to any dir that doesn't - * already have one. - */ - if (flen <= 99) { - assertA(0 == archive_read_next_header(a, &ae)); - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - failure("dlen=%d, flen=%d", dlen, flen); - assertEqualString(dirname, archive_entry_pathname(ae)); - } - - if (flen <= 99) { - assertA(0 == archive_read_next_header(a, &ae)); - assert((S_IFDIR | 0755) == archive_entry_mode(ae)); - assertEqualString(dirname, archive_entry_pathname(ae)); - } - - /* Verify the end of the archive. */ - failure("This fails if entries were written that should not have been written. dlen=%d, flen=%d", dlen, flen); - assertEqualInt(1, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_ustar_filenames) -{ - int dlen, flen; - - /* Try a bunch of different file/dir lengths that add up - * to just a little less or a little more than 100 bytes. - * This exercises the code that splits paths between ustar - * filename and prefix fields. - */ - for (dlen = 5; dlen < 70; dlen += 5) { - for (flen = 100 - dlen - 5; flen < 100 - dlen + 5; flen++) { - test_filename(NULL, dlen, flen); - test_filename("/", dlen, flen); - } - } - - /* Probe the 100-char limit for paths with no '/'. */ - for (flen = 90; flen < 110; flen++) { - test_filename(NULL, 0, flen); - test_filename("/", dlen, flen); - } - - /* XXXX TODO Probe the 100-char limit with a dir prefix. */ - /* XXXX TODO Probe the 255-char total limit. */ -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress.c deleted file mode 100644 index ca2406eb9..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress.c +++ /dev/null @@ -1,102 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_compress.c,v 1.4 2008/12/17 19:05:25 kientzle Exp $"); - -/* - * A basic exercise of compress reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used; - int i; - - buffsize = 1000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_compress(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - - - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - free(data); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress_bzip2.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress_bzip2.c deleted file mode 100644 index ad5f492d6..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress_bzip2.c +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of bzip2 reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_bzip2) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_bzip2(a); - if (r == ARCHIVE_FATAL) { - skipping("bzip2 writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_BZIP2, archive_compression(a)); - assertEqualString("bzip2", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_bzip2(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=1")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(0, archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assert(0 == archive_read_close(a)); - assert(0 == archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_bzip2(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress_gzip.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress_gzip.c deleted file mode 100644 index 9a2ddcc87..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress_gzip.c +++ /dev/null @@ -1,252 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of gzip reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_gzip) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_gzip(a); - if (r == ARCHIVE_FATAL) { - skipping("gzip writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_GZIP, archive_compression(a)); - assertEqualString("gzip", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify gzip writing by reading back;" - " gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_gzip(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - if (r == ARCHIVE_WARN) { - skipping("gzip reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_gzip(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress_lzma.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress_lzma.c deleted file mode 100644 index 9f6b4f5f9..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress_lzma.c +++ /dev/null @@ -1,245 +0,0 @@ -/*- - * Copyright (c) 2007-2009 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of lzma reading and writing. - * - */ - -DEFINE_TEST(test_write_compress_lzma) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_lzma(a); - if (r == ARCHIVE_FATAL) { - skipping("lzma writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_LZMA, archive_compression(a)); - assertEqualString("lzma", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify lzma writing by reading back;" - " lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_lzma(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_lzma(a); - if (r == ARCHIVE_WARN) { - skipping("lzma reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_lzma(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress_program.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress_program.c deleted file mode 100644 index a99300282..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress_program.c +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_compress_program.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -char buff[1000000]; -char buff2[64]; - -DEFINE_TEST(test_write_compress_program) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_set_compress_program()"); -#else - struct archive_entry *ae; - struct archive *a; - size_t used; - int blocksize = 1024; - int r; - - if (!canGzip()) { - skipping("Cannot run 'gzip'"); - return; - } - - /* Create a new archive in memory. */ - /* Write it through an external "gzip" program. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_program(a, "gzip"); - if (r == ARCHIVE_FATAL) { - skipping("Write compression via external " - "program unsupported on this platform"); - archive_write_finish(a); - return; - } - assertA(0 == archive_write_set_bytes_per_block(a, blocksize)); - assertA(0 == archive_write_set_bytes_in_last_block(a, blocksize)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assertA(blocksize == archive_write_get_bytes_in_last_block(a)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* - * Now, read the data back through the built-in gzip support. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - r = archive_read_support_compression_gzip(a); - /* The compression_gzip() handler will fall back to gunzip - * automatically, but if we know gunzip isn't available, then - * skip the rest. */ - if (r != ARCHIVE_OK && !canGunzip()) { - skipping("No libz and no gunzip program, " - "unable to verify gzip compression"); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) { - archive_read_finish(a); - return; - } - - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_compress_xz.c b/Utilities/cmlibarchive/libarchive/test/test_write_compress_xz.c deleted file mode 100644 index abfc5e65b..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_compress_xz.c +++ /dev/null @@ -1,253 +0,0 @@ -/*- - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * A basic exercise of xz reading and writing. - * - * TODO: Add a reference file and make sure we can decompress that. - */ - -DEFINE_TEST(test_write_compress_xz) -{ - struct archive_entry *ae; - struct archive* a; - char *buff, *data; - size_t buffsize, datasize; - char path[16]; - size_t used1, used2; - int i, r; - - buffsize = 2000000; - assert(NULL != (buff = (char *)malloc(buffsize))); - - datasize = 10000; - assert(NULL != (data = (char *)malloc(datasize))); - memset(data, 0, datasize); - - /* - * Write a 100 files and read them all back. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - r = archive_write_set_compression_xz(a); - if (r == ARCHIVE_FATAL) { - skipping("xz writing not supported on this platform"); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - return; - } - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used1)); - assertEqualInt(ARCHIVE_COMPRESSION_XZ, archive_compression(a)); - assertEqualString("xz", archive_compression_name(a)); - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, datasize); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - archive_entry_copy_pathname(ae, path); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize - == (size_t)archive_write_data(a, data, datasize)); - } - archive_entry_free(ae); - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("Can't verify xz writing by reading back;" - " xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used1)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat the cycle again, this time setting some compression - * options. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "nonexistent-option=0")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=abc")); - assertEqualIntA(a, ARCHIVE_WARN, - archive_write_set_compressor_options(a, "compression-level=99")); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=9")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - assertA(datasize == (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Curiously, this test fails; the test data above compresses - * better at default compression than at level 9. */ - /* - failure("compression-level=9 wrote %d bytes, default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 < used1); - */ - - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - failure("Trying to read %s", path); - if (!assertEqualIntA(a, ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Repeat again, with much lower compression. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_bytes_per_block(a, 10)); - assertA(0 == archive_write_set_compression_xz(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_compressor_options(a, "compression-level=0")); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, path); - archive_entry_set_size(ae, datasize); - archive_entry_set_filetype(ae, AE_IFREG); - assertA(0 == archive_write_header(a, ae)); - failure("Writing file %s", path); - assertEqualIntA(a, datasize, - (size_t)archive_write_data(a, data, datasize)); - archive_entry_free(ae); - } - archive_write_close(a); - assert(0 == archive_write_finish(a)); - - /* Level 0 really does result in larger data. */ - failure("Compression-level=0 wrote %d bytes; default wrote %d bytes", - (int)used2, (int)used1); - assert(used2 > used1); - - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - r = archive_read_support_compression_xz(a); - if (r == ARCHIVE_WARN) { - skipping("xz reading not fully supported on this platform"); - } else { - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used2)); - for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); - if (!assertEqualInt(ARCHIVE_OK, - archive_read_next_header(a, &ae))) - break; - assertEqualString(path, archive_entry_pathname(ae)); - assertEqualInt((int)datasize, archive_entry_size(ae)); - } - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - } - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - - /* - * Test various premature shutdown scenarios to make sure we - * don't crash or leak memory. - */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ustar(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_xz(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used2)); - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Clean up. - */ - free(data); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk.c deleted file mode 100644 index f14811d9a..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk.c +++ /dev/null @@ -1,323 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_disk.c,v 1.15 2008/09/30 04:02:36 kientzle Exp $"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - -#define UMASK 022 - -static void create(struct archive_entry *ae, const char *msg) -{ - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); - /* When verifying a dir, ignore the S_ISGID bit, as some systems set - * that automatically. */ -#if !defined(_WIN32) || defined(__CYGWIN__) - if (archive_entry_filetype(ae) == AE_IFDIR) - st.st_mode &= ~S_ISGID; - assertEqualInt(st.st_mode, archive_entry_mode(ae) & ~UMASK); -#endif -} - -static void create_reg_file(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); - failure("%s", msg); - /* - * A touchy API design issue: archive_write_data() does (as of - * 2.4.12) enforce the entry size as a limit on the data - * written to the file. This was not enforced prior to - * 2.4.12. The change was prompted by the refined - * hardlink-restore semantics introduced at that time. In - * short, libarchive needs to know whether a "hardlink entry" - * is going to overwrite the contents so that it can know - * whether or not to open the file for writing. This implies - * that there is a fundamental semantic difference between an - * entry with a zero size and one with a non-zero size in the - * case of hardlinks and treating the hardlink case - * differently from the regular file case is just asking for - * trouble. So, a zero size must always mean that no data - * will be accepted, which is consistent with the file size in - * the entry being a maximum size. - */ - archive_entry_set_size(ae, sizeof(data)); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); - assertFileSize(archive_entry_pathname(ae), sizeof(data)); - /* test_write_disk_times has more detailed tests of this area. */ - assertFileMtime(archive_entry_pathname(ae), 123456789, 0); - failure("No atime given, so atime should get set to current time"); - assertFileAtimeRecent(archive_entry_pathname(ae)); -} - -static void create_reg_file2(struct archive_entry *ae, const char *msg) -{ - const int datasize = 100000; - char *data; - struct archive *ad; - int i; - - data = malloc(datasize); - for (i = 0; i < datasize; i++) - data[i] = (char)(i % 256); - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - /* - * See above for an explanation why this next call - * is necessary. - */ - archive_entry_set_size(ae, datasize); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - for (i = 0; i < datasize - 999; i += 1000) { - assertEqualIntA(ad, ARCHIVE_OK, - archive_write_data_block(ad, data + i, 1000, i)); - } - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - assertEqualInt(0, archive_write_finish(ad)); - - /* Test the entries on disk. */ - assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777); - assertFileSize(archive_entry_pathname(ae), i); - assertFileContents(data, datasize, archive_entry_pathname(ae)); - free(data); -} - -static void create_reg_file3(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - failure("%s", msg); - /* Set the size smaller than the data and verify the truncation. */ - archive_entry_set_size(ae, 5); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(5, archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); -#endif - assertEqualInt(st.st_size, 5); -} - - -static void create_reg_file4(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - /* Leave the size unset. The data should not be truncated. */ - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(ad, data, sizeof(data), 0)); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); -#endif - failure(msg); - assertEqualInt(st.st_size, sizeof(data)); -} - -#if defined(_WIN32) && !defined(__CYGWIN__) -static void create_reg_file_win(struct archive_entry *ae, const char *msg) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct stat st; - char *p, *fname; - size_t l; - - /* Write the entry to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); - failure("%s", msg); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - /* Test the entries on disk. */ - l = strlen(archive_entry_pathname(ae)); - fname = malloc(l + 1); - assert(NULL != fname); - strcpy(fname, archive_entry_pathname(ae)); - /* Replace unusable characters in Windows to '_' */ - for (p = fname; *p != '\0'; p++) - if (*p == ':' || *p == '*' || *p == '?' || - *p == '"' || *p == '<' || *p == '>' || *p == '|') - *p = '_'; - assert(0 == stat(fname, &st)); - failure("st.st_mode=%o archive_entry_mode(ae)=%o", - st.st_mode, archive_entry_mode(ae)); - assertEqualInt(st.st_size, sizeof(data)); -} -#endif /* _WIN32 && !__CYGWIN__ */ -#endif - -DEFINE_TEST(test_write_disk) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_disk interface"); -#else - struct archive_entry *ae; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* A regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file(ae, "Test creating a regular file"); - archive_entry_free(ae); - - /* Another regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file2(ae, "Test creating another regular file"); - archive_entry_free(ae); - - /* A regular file with a size restriction */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file3(ae, "Regular file with size restriction"); - archive_entry_free(ae); - - /* A regular file with an unspecified size */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file4(ae, "Regular file with unspecified size"); - archive_entry_free(ae); - - /* A regular file over an existing file */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0724); - create(ae, "Test creating a file over an existing file."); - archive_entry_free(ae); - - /* A directory. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0555); - create(ae, "Test creating a regular dir."); - archive_entry_free(ae); - - /* A directory over an existing file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFDIR | 0742); - create(ae, "Test creating a dir over an existing file."); - archive_entry_free(ae); - - /* A file over an existing dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0744); - create(ae, "Test creating a file over an existing dir."); - archive_entry_free(ae); - -#if defined(_WIN32) && !defined(__CYGWIN__) - /* A file with unusable characters in its file name. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "f:i*l?e\"fl|e"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file_win(ae, "Test creating a regular file" - " with unusable characters in its file name"); - archive_entry_free(ae); - - /* A file with unusable characters in its directory name. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "d:i*r?e\"co|ry/file1"); - archive_entry_set_mode(ae, S_IFREG | 0755); - create_reg_file_win(ae, "Test creating a regular file" - " with unusable characters in its file name"); - archive_entry_free(ae); -#endif /* _WIN32 && !__CYGWIN__ */ -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_failures.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_failures.c deleted file mode 100644 index 0092737bb..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_failures.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_disk.c,v 1.15 2008/09/30 04:02:36 kientzle Exp $"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 - -#define UMASK 022 - - -#endif - -DEFINE_TEST(test_write_disk_failures) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) - skipping("archive_write_disk interface"); -#else - struct archive_entry *ae; - struct archive *a; - int fd; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* A directory that we can't write to. */ - assertMakeDir("dir", 0555); - - /* Can we? */ - fd = open("dir/testfile", O_WRONLY | O_CREAT | O_BINARY, 0777); - if (fd >= 0) { - /* Apparently, we can, so the test below won't work. */ - close(fd); - skipping("Can't test writing to non-writable directory"); - return; - } - - /* Try to extract a regular file into the directory above. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir/file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assert((a = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME); - archive_entry_set_mtime(ae, 123456789, 0); - assertEqualIntA(a, ARCHIVE_FAILED, archive_write_header(a, ae)); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - assertEqualInt(0, archive_write_finish(a)); - archive_entry_free(ae); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_hardlink.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_hardlink.c deleted file mode 100644 index 560a7299c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_hardlink.c +++ /dev/null @@ -1,223 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_disk_hardlink.c,v 1.5 2008/09/05 06:13:11 kientzle Exp $"); - -#if defined(_WIN32) && !defined(__CYGWIN__) -/* Execution bits, Group members bits and others bits do not work. */ -#define UMASK 0177 -#define E_MASK (~0177) -#else -#define UMASK 022 -#define E_MASK (~0) -#endif - -/* - * Exercise hardlink recreation. - * - * File permissions are chosen so that the authoritive entry - * has the correct permission and the non-authoritive versions - * are just writeable files. - */ -DEFINE_TEST(test_write_disk_hardlink) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_disk_hardlink tests"); -#else - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct archive_entry *ae; - int r; - - /* Force the umask to something predictable. */ - assertUmask(UMASK); - - /* Write entries to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - - /* - * First, use a tar-like approach; a regular file, then - * a separate "hardlink" entry. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1a"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. Size of zero means this doesn't carry data. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1b"); - archive_entry_set_mode(ae, S_IFREG | 0642); - archive_entry_set_size(ae, 0); - archive_entry_copy_hardlink(ae, "link1a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Repeat tar approach test, but use unset to mark the - * hardlink as having no data. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2a"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. Unset size means this doesn't carry data. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2b"); - archive_entry_set_mode(ae, S_IFREG | 0642); - archive_entry_unset_size(ae); - archive_entry_copy_hardlink(ae, "link2a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Second, try an old-cpio-like approach; a regular file, then - * another identical one (which has been marked hardlink). - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link3a"); - archive_entry_set_mode(ae, S_IFREG | 0600); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link3b"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_copy_hardlink(ae, "link3a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r > ARCHIVE_WARN) { - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* - * Finally, try a new-cpio-like approach, where the initial - * regular file is empty and the hardlink has the data. - */ - - /* Regular file. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link4a"); - archive_entry_set_mode(ae, S_IFREG | 0600); - archive_entry_set_size(ae, 0); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); -#if ARCHIVE_VERSION_NUMBER < 3000000 - assertEqualInt(ARCHIVE_WARN, archive_write_data(ad, data, 1)); -#else - assertEqualInt(-1, archive_write_data(ad, data, 1)); -#endif - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link4b"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - archive_entry_copy_hardlink(ae, "link4a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r > ARCHIVE_FAILED) { - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(ad); -#else - assertEqualInt(0, archive_write_finish(ad)); -#endif - - /* Test the entries on disk. */ - - /* Test #1 */ - /* If the hardlink was successfully created and the archive - * doesn't carry data for it, we consider it to be - * non-authoritive for meta data as well. This is consistent - * with GNU tar and BSD pax. */ - assertIsReg("link1a", 0755 & ~UMASK); - assertFileSize("link1a", sizeof(data)); - assertFileNLinks("link1a", 2); - assertIsHardlink("link1a", "link1b"); - - /* Test #2: Should produce identical results to test #1 */ - /* Note that marking a hardlink with size = 0 is treated the - * same as having an unset size. This is partly for backwards - * compatibility (we used to not have unset tracking, so - * relied on size == 0) and partly to match the model used by - * common file formats that store a size of zero for - * hardlinks. */ - assertIsReg("link2a", 0755 & ~UMASK); - assertFileSize("link2a", sizeof(data)); - assertFileNLinks("link2a", 2); - assertIsHardlink("link2a", "link2b"); - - /* Test #3 */ - assertIsReg("link3a", 0755 & ~UMASK); - assertFileSize("link3a", sizeof(data)); - assertFileNLinks("link3a", 2); - assertIsHardlink("link3a", "link3b"); - - /* Test #4 */ - assertIsReg("link4a", 0755 & ~UMASK); - assertFileNLinks("link4a", 2); - assertFileSize("link4a", sizeof(data)); - assertIsHardlink("link4a", "link4b"); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_perms.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_perms.c deleted file mode 100644 index 0693997ff..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_perms.c +++ /dev/null @@ -1,457 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_disk_perms.c,v 1.11 2008/12/06 06:01:50 kientzle Exp $"); - -#if ARCHIVE_VERSION_NUMBER >= 1009000 && (!defined(_WIN32) || defined(__CYGWIN__)) - -#define UMASK 022 - -static long _default_gid = -1; -static long _invalid_gid = -1; -static long _alt_gid = -1; - -/* - * To fully test SGID restores, we need three distinct GIDs to work - * with: - * * the GID that files are created with by default (for the - * current user in the current directory) - * * An "alt gid" that this user can create files with - * * An "invalid gid" that this user is not permitted to create - * files with. - * The second fails if this user doesn't belong to at least two groups; - * the third fails if the current user is root. - */ -static void -searchgid(void) -{ - static int _searched = 0; - uid_t uid = getuid(); - gid_t gid = 0; - unsigned int n; - struct stat st; - int fd; - - /* If we've already looked this up, we're done. */ - if (_searched) - return; - _searched = 1; - - /* Create a file on disk in the current default dir. */ - fd = open("test_gid", O_CREAT | O_BINARY, 0664); - failure("Couldn't create a file for gid testing."); - assert(fd > 0); - - /* See what GID it ended up with. This is our "valid" GID. */ - assert(fstat(fd, &st) == 0); - _default_gid = st.st_gid; - - /* Find a GID for which fchown() fails. This is our "invalid" GID. */ - _invalid_gid = -1; - /* This loop stops when we wrap the gid or examine 10,000 gids. */ - for (gid = 1, n = 1; gid == n && n < 10000 ; n++, gid++) { - if (fchown(fd, uid, gid) != 0) { - _invalid_gid = gid; - break; - } - } - - /* - * Find a GID for which fchown() succeeds, but which isn't the - * default. This is the "alternate" gid. - */ - _alt_gid = -1; - for (gid = 0, n = 0; gid == n && n < 10000 ; n++, gid++) { - /* _alt_gid must be different than _default_gid */ - if (gid == (gid_t)_default_gid) - continue; - if (fchown(fd, uid, gid) == 0) { - _alt_gid = gid; - break; - } - } - close(fd); -} - -static int -altgid(void) -{ - searchgid(); - return (_alt_gid); -} - -static int -invalidgid(void) -{ - searchgid(); - return (_invalid_gid); -} - -static int -defaultgid(void) -{ - searchgid(); - return (_default_gid); -} -#endif - -/* - * Exercise permission and ownership restores. - * In particular, try to exercise a bunch of border cases related - * to files/dirs that already exist, SUID/SGID bits, etc. - */ - -DEFINE_TEST(test_write_disk_perms) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 || (defined(_WIN32) && !defined(__CYGWIN__)) - skipping("archive_write_disk interface"); -#else - struct archive *a; - struct archive_entry *ae; - struct stat st; - - assertUmask(UMASK); - - /* - * Set ownership of the current directory to the group of this - * process. Otherwise, the SGID tests below fail if the - * /tmp directory is owned by a group to which we don't belong - * and we're on a system where group ownership is inherited. - * (Because we're not allowed to SGID files with defaultgid().) - */ - assertEqualInt(0, chown(".", getuid(), getgid())); - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - - /* Write a regular file to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_0755"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - archive_entry_free(ae); - - /* Write a regular file, then write over it. */ - /* For files, the perms should get updated. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_overwrite_0144"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - /* Check that file was created with different perms. */ - assert(0 == stat("file_overwrite_0144", &st)); - failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) != 0144); - /* Overwrite, this should change the perms. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_overwrite_0144"); - archive_entry_set_mode(ae, S_IFREG | 0144); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir_0514"); - archive_entry_set_mode(ae, S_IFDIR | 0514); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Overwrite an existing dir. */ - /* For dir, the first perms should get left. */ - assertMakeDir("dir_overwrite_0744", 0744); - /* Check original perms. */ - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - /* Overwrite shouldn't edit perms. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir_overwrite_0744"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - /* Make sure they're unchanged. */ - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - - /* Write a regular file with SUID bit, but don't use _EXTRACT_PERM. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file_no_suid"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0777); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular file with ARCHIVE_EXTRACT_PERM. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_0777"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_4742"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SUID bit, - * but wrong uid. POSIX says you shouldn't restore SUID bit - * unless the UID could be restored. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_suid"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assertA(0 == archive_write_header(a, ae)); - /* - * Because we didn't ask for owner, the failure to - * restore SUID shouldn't return a failure. - * We check below to make sure SUID really wasn't set. - * See more detailed comments below. - */ - failure("Opportunistic SUID failure shouldn't return error."); - assertEqualInt(0, archive_write_finish_entry(a)); - - if (getuid() != 0) { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_suid2"); - archive_entry_set_mode(ae, S_IFREG | S_ISUID | 0742); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - /* Owner change should fail here. */ - failure("Non-opportunistic SUID failure should return error."); - assertEqualInt(ARCHIVE_WARN, archive_write_finish_entry(a)); - } - - /* Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_perm_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, defaultgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should succeed here."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - if (altgid() == -1) { - /* - * Current user must belong to at least two groups or - * else we can't test setting the GID to another group. - */ - skipping("Current user can't test gid restore: must belong to more than one group."); - } else { - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit - * but without ARCHIVE_EXTRACT_OWNER. - */ - /* - * This is a weird case: The user has asked for permissions to - * be restored but not asked for ownership to be restored. As - * a result, the default file creation will create a file with - * the wrong group. There are several possible behaviors for - * libarchive in this scenario: - * = Set the SGID bit. It is wrong and a security hole to - * set SGID with the wrong group. Even POSIX thinks so. - * = Implicitly set the group. I don't like this. - * = drop the SGID bit and warn (the old libarchive behavior) - * = drop the SGID bit and don't warn (the current libarchive - * behavior). - * The current behavior sees SGID/SUID restore when you - * don't ask for owner restore as an "opportunistic" - * action. That is, libarchive should do it if it can, - * but if it can't, it's not an error. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_alt_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_entry_set_gid(ae, altgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should fail because of group mismatch but the failure should be silent because we didn't ask for the group to be set."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* - * As above, but add _EXTRACT_OWNER to verify that it - * does succeed. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_alt_sgid_owner"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_uid(ae, getuid()); - archive_entry_set_gid(ae, altgid()); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assert(0 == archive_write_header(a, ae)); - failure("Setting SGID bit should succeed here."); - assertEqualIntA(a, ARCHIVE_OK, archive_write_finish_entry(a)); - } - - /* - * Write a regular file with ARCHIVE_EXTRACT_PERM & SGID bit, - * but wrong GID. POSIX says you shouldn't restore SGID bit - * unless the GID could be restored. - */ - if (invalidgid() == -1) { - /* This test always fails for root. */ - printf("Running as root: Can't test SGID failures.\n"); - } else { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_sgid"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, invalidgid()); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_PERM); - assertA(0 == archive_write_header(a, ae)); - failure("This SGID restore should fail without an error."); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_sgid2"); - archive_entry_set_mode(ae, S_IFREG | S_ISGID | 0742); - archive_entry_set_gid(ae, invalidgid()); - archive_write_disk_set_options(a, - ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - failure("This SGID restore should fail with an error."); - assertEqualIntA(a, ARCHIVE_WARN, archive_write_finish_entry(a)); - } - - /* Set ownership should fail if we're not root. */ - if (getuid() == 0) { - printf("Running as root: Can't test setuid failures.\n"); - } else { - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "file_bad_owner"); - archive_entry_set_mode(ae, S_IFREG | 0744); - archive_entry_set_uid(ae, getuid() + 1); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_OWNER); - assertA(0 == archive_write_header(a, ae)); - assertEqualIntA(a,ARCHIVE_WARN,archive_write_finish_entry(a)); - } - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - archive_entry_free(ae); - - /* Test the entries on disk. */ - assert(0 == stat("file_0755", &st)); - failure("file_0755: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - assert(0 == stat("file_overwrite_0144", &st)); - failure("file_overwrite_0144: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0144); - - assert(0 == stat("dir_0514", &st)); - failure("dir_0514: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0514); - - assert(0 == stat("dir_overwrite_0744", &st)); - failure("dir_overwrite_0744: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0744); - - assert(0 == stat("file_no_suid", &st)); - failure("file_0755: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - assert(0 == stat("file_0777", &st)); - failure("file_0777: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0777); - - /* SUID bit should get set here. */ - assert(0 == stat("file_4742", &st)); - failure("file_4742: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISUID | 0742)); - - /* SUID bit should NOT have been set here. */ - assert(0 == stat("file_bad_suid", &st)); - failure("file_bad_suid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - - /* Some things don't fail if you're root, so suppress this. */ - if (getuid() != 0) { - /* SUID bit should NOT have been set here. */ - assert(0 == stat("file_bad_suid2", &st)); - failure("file_bad_suid2: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - } - - /* SGID should be set here. */ - assert(0 == stat("file_perm_sgid", &st)); - failure("file_perm_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISGID | 0742)); - - if (altgid() != -1) { - /* SGID should not be set here. */ - assert(0 == stat("file_alt_sgid", &st)); - failure("file_alt_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - - /* SGID should be set here. */ - assert(0 == stat("file_alt_sgid_owner", &st)); - failure("file_alt_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (S_ISGID | 0742)); - } - - if (invalidgid() != -1) { - /* SGID should NOT be set here. */ - assert(0 == stat("file_bad_sgid", &st)); - failure("file_bad_sgid: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - /* SGID should NOT be set here. */ - assert(0 == stat("file_bad_sgid2", &st)); - failure("file_bad_sgid2: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0742)); - } - - if (getuid() != 0) { - assert(0 == stat("file_bad_owner", &st)); - failure("file_bad_owner: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == (0744)); - failure("file_bad_owner: st.st_uid=%d getuid()=%d", - st.st_uid, getuid()); - /* The entry had getuid()+1, but because we're - * not root, we should not have been able to set that. */ - assert(st.st_uid == getuid()); - } -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_secure.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_secure.c deleted file mode 100644 index 08c9ef125..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_secure.c +++ /dev/null @@ -1,215 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_disk_secure.c,v 1.8 2008/09/07 23:59:27 kientzle Exp $"); - -#define UMASK 022 - -/* - * Exercise security checks that should prevent certain - * writes. - */ - -DEFINE_TEST(test_write_disk_secure) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("archive_write_disk interface"); -#elif !defined(_WIN32) || defined(__CYGWIN__) - struct archive *a; - struct archive_entry *ae; - struct stat st; - - /* Start with a known umask. */ - assertUmask(UMASK); - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - - /* Write a regular dir to it. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Write a symlink to the dir above. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * Without security checks, we should be able to - * extract a file through the link. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir/filea"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* But with security checks enabled, this should fail. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir/fileb"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS); - failure("Extracting a file through a symlink should fail here."); - assertEqualInt(ARCHIVE_FAILED, archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* Create another link. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir2"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - - /* - * With symlink check and unlink option, it should remove - * the link and create the dir. - */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir2/filec"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_UNLINK); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assert(0 == archive_write_finish_entry(a)); - - /* - * Without security checks, extracting a dir over a link to a - * dir should follow the link. - */ - /* Create a symlink to a dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir3"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir3"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was followed. */ - assertEqualInt(0, lstat("link_to_dir3", &st)); - assert(S_ISLNK(st.st_mode)); - archive_entry_free(ae); - - /* - * As above, but a broken link, so the link should get replaced. - */ - /* Create a symlink to a dir. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir4"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "nonexistent_dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir4"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was replaced. */ - assertEqualInt(0, lstat("link_to_dir4", &st)); - assert(S_ISDIR(st.st_mode)); - archive_entry_free(ae); - - /* - * As above, but a link to a non-dir, so the link should get replaced. - */ - /* Create a regular file and a symlink to it */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "non_dir"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Create symlink to the file. */ - archive_entry_copy_pathname(ae, "link_to_dir5"); - archive_entry_set_mode(ae, S_IFLNK | 0777); - archive_entry_set_symlink(ae, "non_dir"); - archive_write_disk_set_options(a, 0); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Extract a dir whose name matches the symlink. */ - assert(archive_entry_clear(ae) != NULL); - archive_entry_copy_pathname(ae, "link_to_dir5"); - archive_entry_set_mode(ae, S_IFDIR | 0777); - assert(0 == archive_write_header(a, ae)); - assert(0 == archive_write_finish_entry(a)); - /* Verify link was replaced. */ - assertEqualInt(0, lstat("link_to_dir5", &st)); - assert(S_ISDIR(st.st_mode)); - archive_entry_free(ae); - - assert(0 == archive_write_finish(a)); - - /* Test the entries on disk. */ - assert(0 == lstat("dir", &st)); - failure("dir: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0755); - - assert(0 == lstat("link_to_dir", &st)); - failure("link_to_dir: st.st_mode=%o", st.st_mode); - assert(S_ISLNK(st.st_mode)); -#if HAVE_LCHMOD - /* Systems that lack lchmod() can't set symlink perms, so skip this. */ - failure("link_to_dir: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); -#endif - - assert(0 == lstat("dir/filea", &st)); - failure("dir/filea: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); - - failure("dir/fileb: This file should not have been created"); - assert(0 != lstat("dir/fileb", &st)); - - assert(0 == lstat("link_to_dir2", &st)); - failure("link_to_dir2 should have been re-created as a true dir"); - assert(S_ISDIR(st.st_mode)); - failure("link_to_dir2: Implicit dir creation should obey umask, but st.st_mode=%o", st.st_mode); - assert((st.st_mode & 0777) == 0755); - - assert(0 == lstat("link_to_dir2/filec", &st)); - assert(S_ISREG(st.st_mode)); - failure("link_to_dir2/filec: st.st_mode=%o", st.st_mode); - assert((st.st_mode & 07777) == 0755); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_sparse.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_sparse.c deleted file mode 100644 index 5f4235a6c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_sparse.c +++ /dev/null @@ -1,280 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Write a file using archive_write_data call, read the file - * back and verify the contents. The data written includes large - * blocks of nulls, so it should exercise the sparsification logic - * if ARCHIVE_EXTRACT_SPARSE is enabled. - */ -static void -verify_write_data(struct archive *a, int sparse) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct stat st; - struct archive_entry *ae; - size_t buff_size = 64 * 1024; - char *buff, *p; - const char *msg = sparse ? "sparse" : "non-sparse"; - FILE *f; - - buff = malloc(buff_size); - assert(buff != NULL); - - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_size(ae, 8 * buff_size); - archive_entry_set_pathname(ae, "test_write_data"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - assertEqualIntA(a, 0, archive_write_header(a, ae)); - - /* Use archive_write_data() to write three relatively sparse blocks. */ - - /* First has non-null data at beginning. */ - memset(buff, 0, buff_size); - memcpy(buff, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - /* Second has non-null data in the middle. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - /* Third has non-null data at the end. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); - failure("%s", msg); - assertEqualInt(buff_size, archive_write_data(a, buff, buff_size)); - - failure("%s", msg); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - assertEqualInt(st.st_size, 8 * buff_size); - f = fopen(archive_entry_pathname(ae), "rb"); - if (!assert(f != NULL)) - return; - - /* Check first block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - assertEqualMem(buff, data, sizeof(data)); - for (p = buff + sizeof(data); p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check second block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (p == buff + buff_size / 2 - 3) { - assertEqualMem(p, data, sizeof(data)); - p += sizeof(data); - } else if (!assertEqualInt(0, *p)) - break; - } - - /* Check third block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size - sizeof(data); ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - failure("%s", msg); - assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); - - /* XXX more XXX */ - - assertEqualInt(0, fclose(f)); - archive_entry_free(ae); - free(buff); -} - -/* - * As above, but using the archive_write_data_block() call. - */ -static void -verify_write_data_block(struct archive *a, int sparse) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct stat st; - struct archive_entry *ae; - size_t buff_size = 64 * 1024; - char *buff, *p; - const char *msg = sparse ? "sparse" : "non-sparse"; - FILE *f; - - buff = malloc(buff_size); - assert(buff != NULL); - - ae = archive_entry_new(); - assert(ae != NULL); - archive_entry_set_size(ae, 8 * buff_size); - archive_entry_set_pathname(ae, "test_write_data_block"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - assertEqualIntA(a, 0, archive_write_header(a, ae)); - - /* Use archive_write_data_block() to write three - relatively sparse blocks. */ - - /* First has non-null data at beginning. */ - memset(buff, 0, buff_size); - memcpy(buff, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, 100)); - - /* Second has non-null data in the middle. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size / 2 - 3, data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, buff_size + 200)); - - /* Third has non-null data at the end. */ - memset(buff, 0, buff_size); - memcpy(buff + buff_size - sizeof(data), data, sizeof(data)); - failure("%s", msg); - assertEqualInt(ARCHIVE_OK, - archive_write_data_block(a, buff, buff_size, buff_size * 2 + 300)); - - failure("%s", msg); - assertEqualIntA(a, 0, archive_write_finish_entry(a)); - - /* Test the entry on disk. */ - assert(0 == stat(archive_entry_pathname(ae), &st)); - assertEqualInt(st.st_size, 8 * buff_size); - f = fopen(archive_entry_pathname(ae), "rb"); - if (!assert(f != NULL)) - return; - - /* Check 100-byte gap at beginning */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check first block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - assertEqualMem(buff, data, sizeof(data)); - for (p = buff + sizeof(data); p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check 100-byte gap */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check second block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (p == buff + buff_size / 2 - 3) { - assertEqualMem(p, data, sizeof(data)); - p += sizeof(data); - } else if (!assertEqualInt(0, *p)) - break; - } - - /* Check 100-byte gap */ - assertEqualInt(100, fread(buff, 1, 100, f)); - failure("%s", msg); - for (p = buff; p < buff + 100; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - /* Check third block. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - for (p = buff; p < buff + buff_size - sizeof(data); ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - failure("%s", msg); - assertEqualMem(buff + buff_size - sizeof(data), data, sizeof(data)); - - /* Check another block size beyond last we wrote. */ - assertEqualInt(buff_size, fread(buff, 1, buff_size, f)); - failure("%s", msg); - for (p = buff; p < buff + buff_size; ++p) { - failure("offset: %d, %s", (int)(p - buff), msg); - if (!assertEqualInt(0, *p)) - break; - } - - - /* XXX more XXX */ - - assertEqualInt(0, fclose(f)); - free(buff); - archive_entry_free(ae); -} - -DEFINE_TEST(test_write_disk_sparse) -{ - struct archive *ad; - - - /* - * The return values, etc, of the write data functions - * shouldn't change regardless of whether we've requested - * sparsification. (The performance and pattern of actual - * write calls to the disk should vary, of course, but the - * client program shouldn't see any difference.) - */ - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, 0); - verify_write_data(ad, 0); - verify_write_data_block(ad, 0); - assertEqualInt(0, archive_write_finish(ad)); - - assert((ad = archive_write_disk_new()) != NULL); - archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_SPARSE); - verify_write_data(ad, 1); - verify_write_data_block(ad, 1); - assertEqualInt(0, archive_write_finish(ad)); - -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_symlink.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_symlink.c deleted file mode 100644 index 7da2cf5ae..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_symlink.c +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise symlink recreation. - */ -DEFINE_TEST(test_write_disk_symlink) -{ - static const char data[]="abcdefghijklmnopqrstuvwxyz"; - struct archive *ad; - struct archive_entry *ae; - int r; - - if (!canSymlink()) { - skipping("Symlinks not supported"); - return; - } - - /* Write entries to disk. */ - assert((ad = archive_write_disk_new()) != NULL); - - /* - * First, create a regular file then a symlink to that file. - */ - - /* Regular file: link1a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1a"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* Symbolic Link: link1b -> link1a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link1b"); - archive_entry_set_mode(ae, AE_IFLNK | 0642); - archive_entry_set_size(ae, 0); - archive_entry_copy_symlink(ae, "link1a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - /* - * We should be able to do this in the other order as well, - * of course. - */ - - /* Symbolic link: link2b -> link2a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2b"); - archive_entry_set_mode(ae, AE_IFLNK | 0642); - archive_entry_unset_size(ae); - archive_entry_copy_symlink(ae, "link2a"); - assertEqualIntA(ad, 0, r = archive_write_header(ad, ae)); - if (r >= ARCHIVE_WARN) { - assertEqualInt(ARCHIVE_WARN, - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - } - archive_entry_free(ae); - - /* File: link2a */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "link2a"); - archive_entry_set_mode(ae, AE_IFREG | 0755); - archive_entry_set_size(ae, sizeof(data)); - assertEqualIntA(ad, 0, archive_write_header(ad, ae)); - assertEqualInt(sizeof(data), - archive_write_data(ad, data, sizeof(data))); - assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); - archive_entry_free(ae); - - assertEqualInt(ARCHIVE_OK, archive_write_finish(ad)); - - /* Test the entries on disk. */ - - /* Test #1 */ - assertIsReg("link1a", -1); - assertFileSize("link1a", sizeof(data)); - assertFileNLinks("link1a", 1); - assertIsSymlink("link1b", "link1a"); - - /* Test #2: Should produce identical results to test #1 */ - assertIsReg("link2a", -1); - assertFileSize("link2a", sizeof(data)); - assertFileNLinks("link2a", 1); - assertIsSymlink("link2b", "link2a"); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_disk_times.c b/Utilities/cmlibarchive/libarchive/test/test_write_disk_times.c deleted file mode 100644 index 27c3786f1..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_disk_times.c +++ /dev/null @@ -1,167 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Exercise time restores in archive_write_disk(), including - * correct handling of omitted time values. - * On FreeBSD, we also test birthtime and high-res time restores. - */ - -DEFINE_TEST(test_write_disk_times) -{ - struct archive *a; - struct archive_entry *ae; - - /* Create an archive_write_disk object. */ - assert((a = archive_write_disk_new()) != NULL); - assertEqualInt(ARCHIVE_OK, - archive_write_disk_set_options(a, ARCHIVE_EXTRACT_TIME)); - - /* - * Easy case: mtime and atime both specified. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file1"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 123456, 0); - archive_entry_set_mtime(ae, 234567, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtime("file1", 123456, 0); - assertFileMtime("file1", 234567, 0); - - /* - * mtime specified, but not atime - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_mtime(ae, 234567, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - assertFileMtime("file2", 234567, 0); - assertFileAtimeRecent("file2"); - - /* - * atime specified, but not mtime - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file3"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 345678, 0); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify: Current mtime and atime as specified. */ - assertFileAtime("file3", 345678, 0); - assertFileMtimeRecent("file3"); - - /* - * Neither atime nor mtime specified. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file4"); - archive_entry_set_mode(ae, S_IFREG | 0777); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify: Current mtime and atime. */ - assertFileAtimeRecent("file4"); - assertFileMtimeRecent("file4"); - -#if defined(__FreeBSD__) - /* - * High-res mtime and atime on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file10"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 1234567, 23456); - archive_entry_set_mtime(ae, 2345678, 4567); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileMtime("file10", 2345678, 4567); - assertFileAtime("file10", 1234567, 23456); - - /* - * Birthtime, mtime and atime on FreeBSD - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file11"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_atime(ae, 1234567, 23456); - archive_entry_set_birthtime(ae, 3456789, 12345); - /* mtime must be later than birthtime! */ - archive_entry_set_mtime(ae, 12345678, 4567); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtime("file11", 1234567, 23456); - assertFileBirthtime("file11", 3456789, 12345); - assertFileMtime("file11", 12345678, 4567); - - /* - * Birthtime only on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file12"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_birthtime(ae, 3456789, 12345); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtimeRecent("file12"); - assertFileBirthtime("file12", 3456789, 12345); - assertFileMtimeRecent("file12"); - - /* - * mtime only on FreeBSD. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "file13"); - archive_entry_set_mode(ae, S_IFREG | 0777); - archive_entry_set_mtime(ae, 4567890, 23456); - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(ARCHIVE_OK, archive_write_finish_entry(a)); - archive_entry_free(ae); - /* Verify */ - assertFileAtimeRecent("file13"); - assertFileBirthtime("file13", 4567890, 23456); - assertFileMtime("file13", 4567890, 23456); -#else - skipping("Platform-specific time restore tests"); -#endif - - archive_write_finish(a); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_ar.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_ar.c deleted file mode 100644 index d06952206..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_ar.c +++ /dev/null @@ -1,209 +0,0 @@ -/*- - * Copyright (c) 2007 Kai Wang - * Copyright (c) 2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_ar.c,v 1.9 2008/12/17 19:03:44 kientzle Exp $"); - -char buff[4096]; -char buff2[64]; -static char strtab[] = "abcdefghijklmn.o/\nggghhhjjjrrrttt.o/\niiijjjdddsssppp.o/\n"; - -DEFINE_TEST(test_write_format_ar) -{ -#if ARCHIVE_VERSION_NUMBER < 1009000 - skipping("ar write support"); -#else - struct archive_entry *ae; - struct archive* a; - size_t used; - - /* - * First we try to create a SVR4/GNU format archive. - */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ar_svr4(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* write the filename table */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "//"); - archive_entry_set_size(ae, strlen(strtab)); - assertA(0 == archive_write_header(a, ae)); - assertA(strlen(strtab) == (size_t)archive_write_data(a, strtab, strlen(strtab))); - archive_entry_free(ae); - - /* write entries */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 0); - assert(1 == archive_entry_mtime(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_copy_pathname(ae, "abcdefghijklmn.o"); - archive_entry_set_size(ae, 8); - assertA(0 == archive_write_header(a, ae)); - assertA(8 == archive_write_data(a, "87654321", 15)); - archive_entry_free(ae); - - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ggghhhjjjrrrttt.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 7); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 7, archive_write_data(a, "7777777", 7)); - archive_entry_free(ae); - - /* test full pathname */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjjdddsssppp.o"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 8, archive_write_data(a, "88877766", 8)); - archive_entry_free(ae); - - /* trailing "/" should be rejected */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "/usr/home/xx/iiijjj/"); - archive_entry_set_size(ae, 8); - assertA(0 != archive_write_header(a, ae)); - archive_entry_free(ae); - - /* Non regular file should be rejected */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "gfgh.o"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 6); - assertA(0 != archive_write_header(a, ae)); - archive_entry_free(ae); - - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(0, archive_entry_mtime(ae)); - assertEqualString("//", archive_entry_pathname(ae)); - assertEqualInt(0, archive_entry_size(ae)); - - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualString("abcdefghijklmn.o", archive_entry_pathname(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "87654321", 8); - - assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualString("ggghhhjjjrrrttt.o", archive_entry_pathname(ae)); - assertEqualInt(7, archive_entry_size(ae)); - assertEqualIntA(a, 7, archive_read_data(a, buff2, 11)); - assertEqualMem(buff2, "7777777", 7); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("iiijjjdddsssppp.o", archive_entry_pathname(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 17)); - assertEqualMem(buff2, "88877766", 8); - - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif - - /* - * Then, we try to create a BSD format archive. - */ - memset(buff, 0, sizeof(buff)); - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_ar_bsd(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* write a entry need long name extension */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ttttyyyyuuuuiiii.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 5); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualInt(5, archive_entry_size(ae)); - assertEqualIntA(a, 5, archive_write_data(a, "12345", 7)); - archive_entry_free(ae); - - /* write a entry with a short name */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_copy_pathname(ae, "ttyy.o"); - archive_entry_set_filetype(ae, AE_IFREG); - archive_entry_set_size(ae, 6); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - assertEqualIntA(a, 6, archive_write_data(a, "555555", 7)); - archive_entry_free(ae); - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - - /* Now, Read the data back */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("ttttyyyyuuuuiiii.o", archive_entry_pathname(ae)); - assertEqualInt(5, archive_entry_size(ae)); - assertEqualIntA(a, 5, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345", 5); - - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualString("ttyy.o", archive_entry_pathname(ae)); - assertEqualInt(6, archive_entry_size(ae)); - assertEqualIntA(a, 6, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "555555", 6); - - /* Test EOF */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio.c deleted file mode 100644 index 4405ee3cd..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio.c +++ /dev/null @@ -1,206 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_cpio.c,v 1.6 2008/12/06 06:02:26 kientzle Exp $"); - -/* The version stamp macro was introduced after cpio write support. */ -#if ARCHIVE_VERSION_NUMBER >= 1009000 -static void -test_format(int (*set_format)(struct archive *)) -{ - char filedata[64]; - struct archive_entry *ae; - struct archive *a; - char *p; - size_t used; - size_t buffsize = 1000000; - char *buff; - int damaged = 0; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == (*set_format)(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); - assert(10 == archive_entry_mtime_nsec(ae)); - p = strdup("file"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* - * Write another file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); - assert(10 == archive_entry_mtime_nsec(ae)); - p = strdup("file2"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file2", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 4); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(4 == archive_write_data(a, "1234", 5)); - - /* - * Write a directory to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 11, 110); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 512); - - assertA(0 == archive_write_header(a, ae)); - assertEqualInt(0, archive_entry_size(ae)); - archive_entry_free(ae); - assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); - - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - /* - * Damage the second entry to test the search-ahead recovery. - */ - { - int i; - for (i = 80; i < 150; i++) { - if (memcmp(buff + i, "07070", 5) == 0) { - damaged = 1; - buff[i] = 'X'; - break; - } - } - } - failure("Unable to locate the second header for damage-recovery test."); - assert(damaged = 1); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) { - archive_read_finish(a); - return; - } - - assertEqualInt(1, archive_entry_mtime(ae)); - /* Not the same as above: cpio doesn't store hi-res times. */ - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertA(8 == archive_read_data(a, filedata, 10)); - assert(0 == memcmp(filedata, "12345678", 8)); - - /* - * Read the second file back. - */ - if (!damaged) { - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - /* Not the same as above: cpio doesn't store hi-res times. */ - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(4, archive_entry_size(ae)); - assertEqualIntA(a, 4, archive_read_data(a, filedata, 10)); - assert(0 == memcmp(filedata, "1234", 4)); - } - - /* - * Read the dir entry back. - */ - assertEqualIntA(a, - damaged ? ARCHIVE_WARN : ARCHIVE_OK, - archive_read_next_header(a, &ae)); - assertEqualInt(11, archive_entry_mtime(ae)); - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("dir", archive_entry_pathname(ae)); - assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, 1, archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - - free(buff); -} -#endif - -DEFINE_TEST(test_write_format_cpio) -{ -#if ARCHIVE_VERSION_NUMBER >= 1009000 - test_format(archive_write_set_format_cpio); - test_format(archive_write_set_format_cpio_newc); -#else - skipping("cpio write support"); -#endif -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_empty.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_empty.c deleted file mode 100644 index c5f94b543..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_empty.c +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_cpio_empty.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Check that an "empty" cpio archive is correctly created. - */ - -/* Here's what an empty cpio archive should look like. */ -static char ref[] = -"070707" /* Magic number */ -"000000" /* Dev = 0 */ -"000000" /* ino = 0 */ -"000000" /* mode = 0 */ -"000000" /* uid = 0 */ -"000000" /* gid = 0 */ -"000001" /* nlink = 1 */ -"000000" /* rdev = 0 */ -"00000000000" /* mtime = 0 */ -"000013" /* Namesize = 11 */ -"00000000000" /* filesize = 0 */ -"TRAILER!!!\0"; /* Name */ - -DEFINE_TEST(test_write_format_cpio_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_cpio(a)); - assertA(0 == archive_write_set_compression_none(a)); - /* 1-byte block size ensures we see only the required bytes. */ - /* We're not testing the padding here. */ - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - failure("Empty cpio archive should be exactly 87 bytes, was %d.", used); - assert(used == 87); - failure("Empty cpio archive is incorrectly formatted."); - assert(memcmp(buff, ref, 87) == 0); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_newc.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_newc.c deleted file mode 100644 index 22029b387..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_newc.c +++ /dev/null @@ -1,212 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_cpio_newc.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - - -static int -is_hex(const char *p, size_t l) -{ - while (l > 0) { - if (*p >= 0 && *p <= '9') { - /* Ascii digit */ - } else if (*p >= 'a' && *p <= 'f') { - /* lowercase letter a-f */ - } else { - /* Not hex. */ - return (0); - } - --l; - ++p; - } - return (1); -} - -/* - * Detailed verification that cpio 'newc' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_cpio_newc) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e; - size_t buffsize = 100000; - size_t used; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_cpio_newc(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* Regular file */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Directory */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* Symlink */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "lnk"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 83); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 13); - archive_entry_set_ino(entry, 88); - archive_entry_set_nlink(entry, 1); - archive_entry_set_symlink(entry,"a"); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - */ - e = buff; - - /* First entry is "file" */ - assert(is_hex(e, 110)); /* Entire header is hex digits. */ - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000059", 8); /* ino */ - assertEqualMem(e + 14, "000081b4", 8); /* Mode */ - assertEqualMem(e + 22, "00000050", 8); /* uid */ - assertEqualMem(e + 30, "0000005a", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000001", 8); /* mtime */ - assertEqualMem(e + 54, "0000000a", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "0000000c", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000005", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "file\0\0", 6); /* Name contents */ - assertEqualMem(e + 116, "1234567890", 10); /* File body */ - assertEqualMem(e + 126, "\0\0", 2); /* Pad to multiple of 4 */ - e += 128; /* Must be multiple of four here! */ - - /* Second entry is "dir" */ - assert(is_hex(e, 110)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000000", 8); /* ino */ - assertEqualMem(e + 14, "000041fd", 8); /* Mode */ - assertEqualMem(e + 22, "00000000", 8); /* uid */ - assertEqualMem(e + 30, "00000000", 8); /* gid */ - assertEqualMem(e + 38, "00000002", 8); /* nlink */ - assertEqualMem(e + 46, "00000002", 8); /* mtime */ - assertEqualMem(e + 54, "00000000", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "00000000", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000004", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "dir\0", 4); /* name */ - assertEqualMem(e + 114, "\0\0", 2); /* Pad to multiple of 4 */ - e += 116; /* Must be multiple of four here! */ - - /* Third entry is "lnk" */ - assert(is_hex(e, 110)); /* Entire header is hex digits. */ - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000058", 8); /* ino */ - assertEqualMem(e + 14, "0000a1b4", 8); /* Mode */ - assertEqualMem(e + 22, "00000053", 8); /* uid */ - assertEqualMem(e + 30, "0000005d", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000003", 8); /* mtime */ - assertEqualMem(e + 54, "00000001", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "0000000d", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "00000004", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "lnk\0\0\0", 6); /* Name contents */ - assertEqualMem(e + 116, "a\0\0\0", 4); /* File body + pad */ - e += 120; /* Must be multiple of four here! */ - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_hex(e, 76)); - assertEqualMem(e + 0, "070701", 6); /* Magic */ - assertEqualMem(e + 6, "00000000", 8); /* ino */ - assertEqualMem(e + 14, "00000000", 8); /* Mode */ - assertEqualMem(e + 22, "00000000", 8); /* uid */ - assertEqualMem(e + 30, "00000000", 8); /* gid */ - assertEqualMem(e + 38, "00000001", 8); /* nlink */ - assertEqualMem(e + 46, "00000000", 8); /* mtime */ - assertEqualMem(e + 54, "00000000", 8); /* File size */ - assertEqualMem(e + 62, "00000000", 8); /* devmajor */ - assertEqualMem(e + 70, "00000000", 8); /* devminor */ - assertEqualMem(e + 78, "00000000", 8); /* rdevmajor */ - assertEqualMem(e + 86, "00000000", 8); /* rdevminor */ - assertEqualMem(e + 94, "0000000b", 8); /* Name size */ - assertEqualMem(e + 102, "00000000", 8); /* CRC */ - assertEqualMem(e + 110, "TRAILER!!!\0", 11); /* Name */ - assertEqualMem(e + 121, "\0\0\0", 3); /* Pad to multiple of 4 bytes */ - e += 124; /* Must be multiple of four here! */ - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_odc.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_odc.c deleted file mode 100644 index 46a930398..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_cpio_odc.c +++ /dev/null @@ -1,225 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_cpio_odc.c,v 1.2 2008/09/01 05:38:33 kientzle Exp $"); - - -static int -is_octal(const char *p, size_t l) -{ - while (l > 0) { - if (*p < '0' || *p > '7') - return (0); - --l; - ++p; - } - return (1); -} - -/* - * Detailed verification that cpio 'odc' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_cpio_odc) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e; - size_t buffsize = 100000; - size_t used; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_cpio(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Hardlink to "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "linkfile"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* "dir" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "symlink" pointing to "file" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "symlink"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_symlink(entry,"file"); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 88); - archive_entry_set_gid(entry, 98); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 90); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to symlink should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - */ - e = buff; - - /* "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assertEqualMem(e + 12, "000131", 6); /* ino */ - assertEqualMem(e + 18, "100664", 6); /* Mode */ - assertEqualMem(e + 24, "000120", 6); /* uid */ - assertEqualMem(e + 30, "000132", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000001", 11); /* mtime */ - assertEqualMem(e + 59, "000005", 6); /* Name size */ - assertEqualMem(e + 65, "00000000012", 11); /* File size */ - assertEqualMem(e + 76, "file\0", 5); /* Name contents */ - assertEqualMem(e + 81, "1234567890", 10); /* File contents */ - e += 91; - - /* hardlink to "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assertEqualMem(e + 12, "000131", 6); /* ino */ - assertEqualMem(e + 18, "100664", 6); /* Mode */ - assertEqualMem(e + 24, "000120", 6); /* uid */ - assertEqualMem(e + 30, "000132", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000001", 11); /* mtime */ - assertEqualMem(e + 59, "000011", 6); /* Name size */ - assertEqualMem(e + 65, "00000000012", 11); /* File size */ - assertEqualMem(e + 76, "linkfile\0", 9); /* Name contents */ - assertEqualMem(e + 85, "1234567890", 10); /* File contents */ - e += 95; - - /* "dir" */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000000", 6); /* dev */ - assertEqualMem(e + 12, "000000", 6); /* ino */ - assertEqualMem(e + 18, "040775", 6); /* Mode */ - assertEqualMem(e + 24, "000000", 6); /* uid */ - assertEqualMem(e + 30, "000000", 6); /* gid */ - assertEqualMem(e + 36, "000002", 6); /* Nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000002", 11); /* mtime */ - assertEqualMem(e + 59, "000004", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "dir\0", 4); /* name */ - e += 80; - - /* "symlink" pointing to "file" */ - assert(is_octal(e, 76)); /* Entire header is octal digits. */ - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000014", 6); /* dev */ - assertEqualMem(e + 12, "000132", 6); /* ino */ - assertEqualMem(e + 18, "120664", 6); /* Mode */ - assertEqualMem(e + 24, "000130", 6); /* uid */ - assertEqualMem(e + 30, "000142", 6); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000003", 11); /* mtime */ - assertEqualMem(e + 59, "000010", 6); /* Name size */ - assertEqualMem(e + 65, "00000000004", 11); /* File size */ - assertEqualMem(e + 76, "symlink\0", 8); /* Name contents */ - assertEqualMem(e + 84, "file", 4); /* File contents == link target */ - e += 88; - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_octal(e, 76)); - assertEqualMem(e + 0, "070707", 6); /* Magic */ - assertEqualMem(e + 6, "000000", 6); /* dev */ - assertEqualMem(e + 12, "000000", 6); /* ino */ - assertEqualMem(e + 18, "000000", 6); /* Mode */ - assertEqualMem(e + 24, "000000", 6); /* uid */ - assertEqualMem(e + 30, "000000", 6); /* gid */ - assertEqualMem(e + 36, "000001", 6); /* Nlink */ - assertEqualMem(e + 42, "000000", 6); /* rdev */ - assertEqualMem(e + 48, "00000000000", 11); /* mtime */ - assertEqualMem(e + 59, "000013", 6); /* Name size */ - assertEqualMem(e + 65, "00000000000", 11); /* File size */ - assertEqualMem(e + 76, "TRAILER!!!\0", 11); /* Name */ - e += 87; - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_mtree.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_mtree.c deleted file mode 100644 index 483a5f216..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_mtree.c +++ /dev/null @@ -1,154 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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 - * in this position and unchanged. - * 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 "test.h" - -static char buff[4096]; -static struct { - const char *path; - mode_t mode; - time_t mtime; - uid_t uid; - gid_t gid; -} entries[] = { - { "./Makefile", S_IFREG | 0644, 1233041050, 1001, 1001 }, - { "./NEWS", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./PROJECTS", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./README", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./COPYING", S_IFREG | 0644, 1231975636, 1001, 1001 }, - { "./subdir", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir/README", S_IFREG | 0664, 1231975636, 1002, 1001 }, - { "./subdir/config", S_IFREG | 0664, 1232266273, 1003, 1003 }, - { "./subdir2", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir3", S_IFDIR | 0755, 1233504586, 1001, 1001 }, - { "./subdir3/mtree", S_IFREG | 0664, 1232266273, 1003, 1003 }, - { NULL, 0, 0, 0, 0 } -}; - -static void -test_write_format_mtree_sub(int use_set, int dironly) -{ - struct archive_entry *ae; - struct archive* a; - size_t used; - int i; - - /* Create a mtree format archive. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_mtree(a)); - if (use_set) - assertA(0 == archive_write_set_options(a, "use-set")); - if (dironly) - assertA(0 == archive_write_set_options(a, "dironly")); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff)-1, &used)); - - /* Write entries */ - for (i = 0; entries[i].path != NULL; i++) { - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, entries[i].mtime, 0); - assert(entries[i].mtime == archive_entry_mtime(ae)); - archive_entry_set_mode(ae, entries[i].mode); - assert(entries[i].mode == archive_entry_mode(ae)); - archive_entry_set_uid(ae, entries[i].uid); - assert(entries[i].uid == archive_entry_uid(ae)); - archive_entry_set_gid(ae, entries[i].gid); - assert(entries[i].gid == archive_entry_gid(ae)); - archive_entry_copy_pathname(ae, entries[i].path); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - archive_entry_set_size(ae, 8); - assertA(0 == archive_write_header(a, ae)); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - assertA(8 == archive_write_data(a, "Hello012", 15)); - archive_entry_free(ae); - } - archive_write_close(a); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertEqualInt(0, archive_write_finish(a)); -#endif - if (use_set) { - const char *p; - - buff[used] = '\0'; - assert(NULL != (p = strstr(buff, "\n/set "))); - if (p != NULL) { - char *r; - const char *o; - p++; - r = strchr(p, '\n'); - if (r != NULL) - *r = '\0'; - if (dironly) - o = "/set type=dir uid=1001 gid=1001 mode=755"; - else - o = "/set type=file uid=1001 gid=1001 mode=644"; - assertEqualString(o, p); - if (r != NULL) - *r = '\n'; - } - } - - /* - * Read the data and check it. - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used)); - - /* Read entries */ - for (i = 0; entries[i].path != NULL; i++) { - if (dironly && (entries[i].mode & AE_IFMT) != S_IFDIR) - continue; - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(entries[i].mtime, archive_entry_mtime(ae)); - assertEqualInt(entries[i].mode, archive_entry_mode(ae)); - assertEqualInt(entries[i].uid, archive_entry_uid(ae)); - assertEqualInt(entries[i].gid, archive_entry_gid(ae)); - assertEqualString(entries[i].path, archive_entry_pathname(ae)); - if ((entries[i].mode & AE_IFMT) != S_IFDIR) - assertEqualInt(8, archive_entry_size(ae)); - } - assertEqualIntA(a, 0, archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assertEqualInt(0, archive_read_finish(a)); -#endif -} - -DEFINE_TEST(test_write_format_mtree) -{ - /* Default setting */ - test_write_format_mtree_sub(0, 0); - /* Directory only */ - test_write_format_mtree_sub(0, 1); - /* Use /set keyword */ - test_write_format_mtree_sub(1, 0); - /* Use /set keyword with directory only */ - test_write_format_mtree_sub(1, 1); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_pax.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_pax.c deleted file mode 100644 index c12bc944c..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_pax.c +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -char buff2[64]; - -DEFINE_TEST(test_write_format_pax) -{ - size_t buffsize = 1000000; - char *buff; - struct archive_entry *ae; - struct archive *a; - size_t used; - - buff = malloc(buffsize); /* million bytes of work area */ - assert(buff != NULL); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * "file" has a bunch of attributes and 8 bytes of data. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_atime(ae, 2, 20); - archive_entry_set_birthtime(ae, 3, 30); - archive_entry_set_ctime(ae, 4, 40); - archive_entry_set_mtime(ae, 5, 50); - archive_entry_copy_pathname(ae, "file"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * "file2" is similar but has birthtime later than mtime. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_atime(ae, 2, 20); - archive_entry_set_birthtime(ae, 8, 80); - archive_entry_set_ctime(ae, 4, 40); - archive_entry_set_mtime(ae, 5, 50); - archive_entry_copy_pathname(ae, "file2"); - archive_entry_set_mode(ae, S_IFREG | 0755); - archive_entry_set_size(ae, 8); - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9)); - - /* - * XXX TODO XXX Archive directory, other file types. - * Archive extended attributes, ACLs, other metadata. - * Verify they get read back correctly. - */ - - /* Close out the archive. */ - assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_finish(a)); - - /* - * - * Now, read the data back. - * - */ - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, 0, archive_read_support_format_all(a)); - assertEqualIntA(a, 0, archive_read_support_compression_all(a)); - assertEqualIntA(a, 0, archive_read_open_memory(a, buff, used)); - - /* - * Read "file" - */ - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assertEqualInt(2, archive_entry_atime(ae)); - assertEqualInt(20, archive_entry_atime_nsec(ae)); - assertEqualInt(3, archive_entry_birthtime(ae)); - assertEqualInt(30, archive_entry_birthtime_nsec(ae)); - assertEqualInt(4, archive_entry_ctime(ae)); - assertEqualInt(40, archive_entry_ctime_nsec(ae)); - assertEqualInt(5, archive_entry_mtime(ae)); - assertEqualInt(50, archive_entry_mtime_nsec(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* - * Read "file2" - */ - assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - assert(archive_entry_atime_is_set(ae)); - assertEqualInt(2, archive_entry_atime(ae)); - assertEqualInt(20, archive_entry_atime_nsec(ae)); - /* Birthtime > mtime above, so it doesn't get stored at all. */ - assert(!archive_entry_birthtime_is_set(ae)); - assertEqualInt(0, archive_entry_birthtime(ae)); - assertEqualInt(0, archive_entry_birthtime_nsec(ae)); - assert(archive_entry_ctime_is_set(ae)); - assertEqualInt(4, archive_entry_ctime(ae)); - assertEqualInt(40, archive_entry_ctime_nsec(ae)); - assert(archive_entry_mtime_is_set(ae)); - assertEqualInt(5, archive_entry_mtime(ae)); - assertEqualInt(50, archive_entry_mtime_nsec(ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(8, archive_entry_size(ae)); - assertEqualIntA(a, 8, archive_read_data(a, buff2, 10)); - assertEqualMem(buff2, "12345678", 8); - - /* - * Verify the end of the archive. - */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); - assertEqualIntA(a, ARCHIVE_OK, archive_read_finish(a)); - - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_shar_empty.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_shar_empty.c deleted file mode 100644 index a7996d5cf..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_shar_empty.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_shar_empty.c,v 1.3 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Check that an "empty" shar archive is correctly created as an empty file. - */ - -DEFINE_TEST(test_write_format_shar_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_shar(a)); - assertA(0 == archive_write_set_compression_none(a)); - /* 1-byte block size ensures we see only the required bytes. */ - /* We're not testing the padding here. */ - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - - failure("Empty shar archive should be exactly 0 bytes, was %d.", used); - assert(used == 0); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_tar.c deleted file mode 100644 index 60870dc3d..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar.c +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_tar.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -char buff[1000000]; -char buff2[64]; - -DEFINE_TEST(test_write_format_tar) -{ - struct archive_entry *ae; - struct archive *a; - char *p; - size_t used; - size_t blocksize; - - /* Repeat the following for a variety of odd blocksizes. */ - for (blocksize = 1; blocksize < 100000; blocksize += blocksize + 3) { - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); - assertA(0 == archive_write_set_bytes_in_last_block(a, (int)blocksize)); - assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - assertA(blocksize == (size_t)archive_write_get_bytes_in_last_block(a)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assert(1 == archive_entry_mtime(ae)); -#if !defined(__INTERIX) - assert(10 == archive_entry_mtime_nsec(ae)); -#endif - p = strdup("file"); - archive_entry_copy_pathname(ae, p); - strcpy(p, "XXXX"); - free(p); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertA(0 == archive_write_header(a, ae)); - archive_entry_free(ae); - assertA(8 == archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - /* This calculation gives "the smallest multiple of - * the block size that is at least 2048 bytes". */ - assert(((2048 - 1)/blocksize+1)*blocksize == used); - - /* - * Now, read the data back. - */ - assert((a = archive_read_new()) != NULL); - assertA(0 == archive_read_support_format_all(a)); - assertA(0 == archive_read_support_compression_all(a)); - assertA(0 == archive_read_open_memory(a, buff, used)); - - assertA(0 == archive_read_next_header(a, &ae)); - - assert(1 == archive_entry_mtime(ae)); - /* Not the same as above: ustar doesn't store hi-res times. */ - assert(0 == archive_entry_mtime_nsec(ae)); - assert(0 == archive_entry_atime(ae)); - assert(0 == archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assert(8 == archive_entry_size(ae)); - assertA(8 == archive_read_data(a, buff2, 10)); - assert(0 == memcmp(buff2, "12345678", 8)); - - /* Verify the end of the archive. */ - assert(1 == archive_read_next_header(a, &ae)); - assert(0 == archive_read_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_read_finish(a); -#else - assert(0 == archive_read_finish(a)); -#endif - } -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_empty.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_empty.c deleted file mode 100644 index 3d5d09ddb..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_empty.c +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_tar_empty.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -/* - * Check that an "empty" tar archive is correctly created. - */ - -DEFINE_TEST(test_write_format_tar_empty) -{ - struct archive *a; - char buff[2048]; - size_t used; - unsigned int i; - - /* USTAR format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Earlier versions wrote 0-length files for empty tar archives. */ - skipping("empty tar archive size"); -#else - assert(used == 1024); -#endif - for (i = 0; i < used; i++) { - failure("Empty tar archive should be all nulls."); - assert(buff[i] == 0); - } - - /* PAX format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_pax(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 512)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 512)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive. */ - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assertA(0 == archive_write_finish(a)); -#endif - -#if ARCHIVE_VERSION_NUMBER < 1009000 - /* Earlier versions wrote 0-length files for empty tar archives. */ - skipping("empty tar archive size"); -#else - assertEqualInt((int)used, 1024); -#endif - for (i = 0; i < used; i++) { - failure("Empty tar archive should be all nulls."); - assert(buff[i] == 0); - } -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_ustar.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_ustar.c deleted file mode 100644 index b8ca998ba..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_tar_ustar.c +++ /dev/null @@ -1,347 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_format_tar_ustar.c,v 1.2 2008/08/11 01:19:36 kientzle Exp $"); - -static int -is_null(const char *p, size_t l) -{ - while (l > 0) { - if (*p != '\0') - return (0); - --l; - ++p; - } - return (1); -} - -/* Verify the contents, then erase them to NUL bytes. */ -/* Tar requires all "unused" bytes be set to NUL; this allows us - * to easily verify that by invoking is_null() over the entire header - * after verifying each field. */ -#define myAssertEqualMem(a,b,s) assertEqualMem(a, b, s); memset(a, 0, s) - -/* - * Detailed verification that 'ustar' archives are written with - * the correct format. - */ -DEFINE_TEST(test_write_format_tar_ustar) -{ - struct archive *a; - struct archive_entry *entry; - char *buff, *e; - size_t buffsize = 100000; - size_t used; - int i; - char f99[100]; - char f100[101]; - char f256[257]; - - for (i = 0; i < 99; ++i) - f99[i] = 'a' + i % 26; - f99[99] = '\0'; - - for (i = 0; i < 100; ++i) - f100[i] = 'A' + i % 26; - f100[100] = '\0'; - - for (i = 0; i < 256; ++i) - f256[i] = 'A' + i % 26; - f256[155] = '/'; - f256[256] = '\0'; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, 0, archive_write_set_format_ustar(a)); - assertEqualIntA(a, 0, archive_write_set_compression_none(a)); - assertEqualIntA(a, 0, archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Add various files to it. - * TODO: Extend this to cover more filetypes. - */ - - /* "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "file"); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 10); - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - assertEqualIntA(a, 10, archive_write_data(a, "1234567890", 10)); - - /* Hardlink to "file" with 10 bytes of content */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, "linkfile"); - archive_entry_set_mode(entry, S_IFREG | 0664); - /* TODO: Put this back and fix the bug. */ - /* archive_entry_set_size(entry, 10); */ - archive_entry_set_uid(entry, 80); - archive_entry_set_gid(entry, 90); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 89); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "dir" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 2, 20); - archive_entry_set_pathname(entry, "dir"); - archive_entry_set_mode(entry, S_IFDIR | 0775); - archive_entry_set_size(entry, 10); - archive_entry_set_nlink(entry, 2); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to dir should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* "symlink" pointing to "file" */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 3, 30); - archive_entry_set_pathname(entry, "symlink"); - archive_entry_set_mode(entry, 0664); - archive_entry_set_filetype(entry, AE_IFLNK); - archive_entry_set_symlink(entry,"file"); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 88); - archive_entry_set_gid(entry, 98); - archive_entry_set_dev(entry, 12); - archive_entry_set_ino(entry, 90); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - /* Write of data to symlink should fail == zero bytes get written. */ - assertEqualIntA(a, 0, archive_write_data(a, "1234567890", 10)); - - /* file with 99-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f99); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* file with 100-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f100); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* file with 256-char filename. */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_mtime(entry, 1, 10); - archive_entry_set_pathname(entry, f256); - archive_entry_set_mode(entry, S_IFREG | 0664); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, 82); - archive_entry_set_gid(entry, 93); - archive_entry_set_dev(entry, 102); - archive_entry_set_ino(entry, 7); - archive_entry_set_nlink(entry, 1); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - - /* - * Verify the archive format. - */ - e = buff; - - /* "file" */ - myAssertEqualMem(e + 0, "file", 5); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000012 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "010034\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - myAssertEqualMem(e + 512, "1234567890", 10); - assert(is_null(e + 512, 512)); - e += 1024; - - /* hardlink to "file" */ - myAssertEqualMem(e + 0, "linkfile", 9); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000120 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000132 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "010707\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* "dir" */ - myAssertEqualMem(e + 0, "dir/", 4); /* Filename */ - myAssertEqualMem(e + 100, "000775 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000000 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000000 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000002 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "007747\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "5", 1); /* typeflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* "symlink" pointing to "file" */ - myAssertEqualMem(e + 0, "symlink", 8); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000130 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000142 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000003 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "011446\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "2", 1); /* linkflag */ - myAssertEqualMem(e + 157, "file", 5); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 99-char filename */ - myAssertEqualMem(e + 0, f99, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "034242\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 100-char filename */ - myAssertEqualMem(e + 0, f100, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "026230\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, "", 1); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* File with 256-char filename */ - myAssertEqualMem(e + 0, f256 + 156, 100); /* Filename */ - myAssertEqualMem(e + 100, "000664 ", 8); /* mode */ - myAssertEqualMem(e + 108, "000122 ", 8); /* uid */ - myAssertEqualMem(e + 116, "000135 ", 8); /* gid */ - myAssertEqualMem(e + 124, "00000000000 ", 12); /* size */ - myAssertEqualMem(e + 136, "00000000001 ", 12); /* mtime */ - myAssertEqualMem(e + 148, "055570\0 ", 8); /* checksum */ - myAssertEqualMem(e + 156, "0", 1); /* linkflag */ - myAssertEqualMem(e + 157, "", 1); /* linkname */ - myAssertEqualMem(e + 257, "ustar\000000", 8); /* signature/version */ - myAssertEqualMem(e + 265, "", 1); /* uname */ - myAssertEqualMem(e + 297, "", 1); /* gname */ - myAssertEqualMem(e + 329, "000000 ", 8); /* devmajor */ - myAssertEqualMem(e + 337, "000000 ", 8); /* devminor */ - myAssertEqualMem(e + 345, f256, 155); /* prefix */ - assert(is_null(e + 0, 512)); - e += 512; - - /* TODO: Verify other types of entries. */ - - /* Last entry is end-of-archive marker. */ - assert(is_null(e, 1024)); - e += 1024; - - assertEqualInt((int)used, e - buff); - - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_zip.c deleted file mode 100644 index 0ab665978..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip.c +++ /dev/null @@ -1,180 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * Copyright (c) 2008 Anselm Strauss - * 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. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -/* TODO: reader does not yet restore permissions. */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_write_format_zip) -{ - char filedata[64]; - struct archive_entry *ae; - struct archive *a; - size_t used; - size_t buffsize = 1000000; - char *buff; - const char *compression_type; - - buff = malloc(buffsize); - - /* Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_format_zip(a)); -#ifdef HAVE_ZLIB_H - compression_type = "zip:compression=deflate"; -#else - compression_type = "zip:compression=store"; -#endif - assertEqualIntA(a, ARCHIVE_OK, - archive_write_set_format_options(a, compression_type)); - assertEqualIntA(a, ARCHIVE_OK, archive_write_set_compression_none(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_write_open_memory(a, buff, buffsize, &used)); - - /* - * Write a file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(10, archive_entry_mtime_nsec(ae)); - archive_entry_copy_pathname(ae, "file"); - assertEqualString("file", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - archive_entry_set_size(ae, 8); - - assertEqualInt(0, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualInt(8, archive_write_data(a, "12345678", 9)); - assertEqualInt(0, archive_write_data(a, "1", 1)); - - /* - * Write another file to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 1, 10); - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(10, archive_entry_mtime_nsec(ae)); - archive_entry_copy_pathname(ae, "file2"); - assertEqualString("file2", archive_entry_pathname(ae)); - archive_entry_set_mode(ae, S_IFREG | 0755); - assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - archive_entry_set_size(ae, 4); - - assertEqualInt(ARCHIVE_OK, archive_write_header(a, ae)); - archive_entry_free(ae); - assertEqualInt(4, archive_write_data(a, "1234", 5)); - - /* - * Write a directory to it. - */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_mtime(ae, 11, 110); - archive_entry_copy_pathname(ae, "dir"); - archive_entry_set_mode(ae, S_IFDIR | 0755); - archive_entry_set_size(ae, 512); - - assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); - failure("size should be zero so that applications know not to write"); - assertEqualInt(0, archive_entry_size(ae)); - archive_entry_free(ae); - assertEqualIntA(a, 0, archive_write_data(a, "12345678", 9)); - - /* Close out the archive. */ - assertEqualInt(ARCHIVE_OK, archive_write_close(a)); - assertEqualInt(ARCHIVE_OK, archive_write_finish(a)); - - /* - * Now, read the data back. - */ - ae = NULL; - assert((a = archive_read_new()) != NULL); - assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_support_compression_all(a)); - assertEqualIntA(a, ARCHIVE_OK, - archive_read_open_memory(a, buff, used)); - - /* - * Read and verify first file. - */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(1, archive_entry_mtime(ae)); - /* Zip doesn't store high-resolution mtime. */ - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file", archive_entry_pathname(ae)); - //assertEqualInt((S_IFREG | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 8, - archive_read_data(a, filedata, sizeof(filedata))); - assertEqualMem(filedata, "12345678", 8); - - - /* - * Read the second file back. - */ - if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))){ - free(buff); - return; - } - assertEqualInt(1, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("file2", archive_entry_pathname(ae)); - //assert((S_IFREG | 0755) == archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 4, - archive_read_data(a, filedata, sizeof(filedata))); - assertEqualMem(filedata, "1234", 4); - - /* - * Read the dir entry back. - */ - assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - assertEqualInt(11, archive_entry_mtime(ae)); - assertEqualInt(0, archive_entry_mtime_nsec(ae)); - assertEqualInt(0, archive_entry_atime(ae)); - assertEqualInt(0, archive_entry_ctime(ae)); - assertEqualString("dir/", archive_entry_pathname(ae)); - //assertEqualInt((S_IFDIR | 0755), archive_entry_mode(ae)); - assertEqualInt(0, archive_entry_size(ae)); - assertEqualIntA(a, 0, archive_read_data(a, filedata, 10)); - - /* Verify the end of the archive. */ - assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); - assertEqualInt(ARCHIVE_OK, archive_read_close(a)); - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); - free(buff); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_empty.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_empty.c deleted file mode 100644 index 218725c08..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_empty.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2008 Anselm Strauss - * 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. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -DEFINE_TEST(test_write_format_zip_empty) -{ - struct archive *a; - char buff[256]; - size_t used; - - /* Zip format: Create a new archive in memory. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_zip(a)); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Close out the archive without writing anything. */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Verify the correct format for an empy Zip archive. */ - assertEqualInt(used, 22); - assertEqualMem(buff, - "PK\005\006\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", - 22); -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_no_compression.c b/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_no_compression.c deleted file mode 100644 index f3da66d0d..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_format_zip_no_compression.c +++ /dev/null @@ -1,304 +0,0 @@ -/*- - * Copyright (c) 2008 Anselm Strauss - * 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. - */ - -/* - * Development supported by Google Summer of Code 2008. - */ - -#include "test.h" -__FBSDID("$FreeBSD$"); - -static unsigned long -bitcrc32(unsigned long c, void *_p, size_t s) -{ - /* This is a drop-in replacement for crc32() from zlib. - * Libarchive should be able to correctly generate - * uncompressed zip archives (including correct CRCs) even - * when zlib is unavailable, and this function helps us verify - * that. Yes, this is very, very slow and unsuitable for - * production use, but it's correct, compact, and works well - * enough for this particular usage. Libarchive internally - * uses a much more efficient implementation. */ - const unsigned char *p = _p; - int bitctr; - - if (p == NULL) - return (0); - - for (; s > 0; --s) { - c ^= *p++; - for (bitctr = 8; bitctr > 0; --bitctr) { - if (c & 1) c = (c >> 1); - else c = (c >> 1) ^ 0xedb88320; - c ^= 0x80000000; - } - } - return (c); -} - -/* Quick and dirty: Read 2-byte and 4-byte integers from Zip file. */ -static int i2(const char *p) { return ((p[0] & 0xff) | ((p[1] & 0xff) << 8)); } -static int i4(const char *p) { return (i2(p) | (i2(p + 2) << 16)); } - -DEFINE_TEST(test_write_format_zip_no_compression) -{ - /* Buffer data */ - struct archive *a; - struct archive_entry *entry; - char buff[100000]; - const char *buffend; - /* p is the pointer to walk over the central directory, - * q walks over the local headers, the data and the data descriptors. */ - const char *p, *q; - size_t used; - - /* File data */ - char file_name[] = "file"; - char file_data1[] = {'1', '2', '3', '4', '5'}; - char file_data2[] = {'6', '7', '8', '9', '0'}; - int file_perm = 00644; - short file_uid = 10; - short file_gid = 20; - - /* Folder data */ - char folder_name[] = "folder/"; - int folder_perm = 00755; - short folder_uid = 30; - short folder_gid = 40; - - /* Time data */ - time_t t = time(NULL); - struct tm *tm = localtime(&t); - - /* Misc variables */ - unsigned long crc; - - /* Create new ZIP archive in memory without padding. */ - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_zip(a)); - assertA(0 == archive_write_set_format_options(a, "zip:compression=store")); - assertA(0 == archive_write_set_compression_none(a)); - assertA(0 == archive_write_set_bytes_per_block(a, 1)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &used)); - - /* Write entries. */ - - /* Regular file */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, file_name); - archive_entry_set_mode(entry, S_IFREG | 0644); - archive_entry_set_size(entry, sizeof(file_data1) + sizeof(file_data2)); - archive_entry_set_uid(entry, file_uid); - archive_entry_set_gid(entry, file_gid); - archive_entry_set_mtime(entry, t, 0); - archive_entry_set_atime(entry, t, 0); - archive_entry_set_ctime(entry, t, 0); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - assertEqualIntA(a, sizeof(file_data1), archive_write_data(a, file_data1, sizeof(file_data1))); - assertEqualIntA(a, sizeof(file_data2), archive_write_data(a, file_data2, sizeof(file_data2))); - archive_entry_free(entry); - - /* Folder */ - assert((entry = archive_entry_new()) != NULL); - archive_entry_set_pathname(entry, folder_name); - archive_entry_set_mode(entry, S_IFDIR | folder_perm); - archive_entry_set_size(entry, 0); - archive_entry_set_uid(entry, folder_uid); - archive_entry_set_gid(entry, folder_gid); - archive_entry_set_mtime(entry, t, 0); - archive_entry_set_atime(entry, t, 0); - archive_entry_set_ctime(entry, t, 0); - assertEqualIntA(a, 0, archive_write_header(a, entry)); - archive_entry_free(entry); - - /* Close the archive . */ - assertA(0 == archive_write_close(a)); - assertA(0 == archive_write_finish(a)); - - /* Remember the end of the archive in memory. */ - buffend = buff + used; - - /* Verify "End of Central Directory" record. */ - /* Get address of end-of-central-directory record. */ - p = buffend - 22; /* Assumes there is no zip comment field. */ - failure("End-of-central-directory begins with PK\\005\\006 signature"); - assertEqualMem(p, "PK\005\006", 4); - failure("This must be disk 0"); - assertEqualInt(i2(p + 4), 0); - failure("Central dir must start on disk 0"); - assertEqualInt(i2(p + 6), 0); - failure("All central dir entries are on this disk"); - assertEqualInt(i2(p + 8), i2(p + 10)); - failure("CD start (%d) + CD length (%d) should == archive size - 22", - i4(p + 12), i4(p + 16)); - assertEqualInt(i4(p + 12) + i4(p + 16), used - 22); - failure("no zip comment"); - assertEqualInt(i2(p + 20), 0); - - /* Get address of first entry in central directory. */ - p = buff + i4(buffend - 6); - failure("Central file record at offset %d should begin with" - " PK\\001\\002 signature", - i4(buffend - 10)); - - /* Verify file entry in central directory. */ - assertEqualMem(p, "PK\001\002", 4); /* Signature */ - assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ - assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ - assertEqualInt(i2(p + 8), 8); /* Flags */ - assertEqualInt(i2(p + 10), 0); /* Compression method */ - assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - crc = bitcrc32(0, file_data1, sizeof(file_data1)); - crc = bitcrc32(crc, file_data2, sizeof(file_data2)); - assertEqualInt(i4(p + 16), crc); /* CRC-32 */ - assertEqualInt(i4(p + 20), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(p + 24), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - assertEqualInt(i2(p + 28), strlen(file_name)); /* Pathname length */ - assertEqualInt(i2(p + 30), 13); /* Extra field length */ - assertEqualInt(i2(p + 32), 0); /* File comment length */ - assertEqualInt(i2(p + 34), 0); /* Disk number start */ - assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ - assertEqualInt(i4(p + 38) >> 16 & 01777, file_perm); /* External file attrs */ - assertEqualInt(i4(p + 42), 0); /* Offset of local header */ - assertEqualMem(p + 46, file_name, strlen(file_name)); /* Pathname */ - p = p + 46 + strlen(file_name); - assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(p + 2), 5); /* 'UT' size */ - assertEqualInt(p[4], 7); /* 'UT' flags */ - assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ - p = p + 9; - assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ - p = p + 4; - - /* Verify local header of file entry. */ - q = buff; - assertEqualMem(q, "PK\003\004", 4); /* Signature */ - assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ - assertEqualInt(i2(q + 6), 8); /* Flags */ - assertEqualInt(i2(q + 8), 0); /* Compression method */ - assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - assertEqualInt(i4(q + 14), 0); /* CRC-32 */ - assertEqualInt(i4(q + 18), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(q + 22), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - assertEqualInt(i2(q + 26), strlen(file_name)); /* Pathname length */ - assertEqualInt(i2(q + 28), 25); /* Extra field length */ - assertEqualMem(q + 30, file_name, strlen(file_name)); /* Pathname */ - q = q + 30 + strlen(file_name); - assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(q + 2), 13); /* 'UT' size */ - assertEqualInt(q[4], 7); /* 'UT' flags */ - assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ - assertEqualInt(i4(q + 9), t); /* 'UT' atime */ - assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ - q = q + 17; - assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ - assertEqualInt(i2(q + 4), file_uid); /* 'Ux' UID */ - assertEqualInt(i2(q + 6), file_gid); /* 'Ux' GID */ - q = q + 8; - - /* Verify data of file entry. */ - assertEqualMem(q, file_data1, sizeof(file_data1)); - assertEqualMem(q + sizeof(file_data1), file_data2, sizeof(file_data2)); - q = q + sizeof(file_data1) + sizeof(file_data2); - - /* Verify data descriptor of file entry. */ - assertEqualMem(q, "PK\007\010", 4); /* Signature */ - assertEqualInt(i4(q + 4), crc); /* CRC-32 */ - assertEqualInt(i4(q + 8), sizeof(file_data1) + sizeof(file_data2)); /* Compressed size */ - assertEqualInt(i4(q + 12), sizeof(file_data1) + sizeof(file_data2)); /* Uncompressed size */ - q = q + 16; - - /* Verify folder entry in central directory. */ - assertEqualMem(p, "PK\001\002", 4); /* Signature */ - assertEqualInt(i2(p + 4), 3 * 256 + 20); /* Version made by */ - assertEqualInt(i2(p + 6), 20); /* Version needed to extract */ - assertEqualInt(i2(p + 8), 8); /* Flags */ - assertEqualInt(i2(p + 10), 0); /* Compression method */ - assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - crc = 0; - assertEqualInt(i4(p + 16), crc); /* CRC-32 */ - assertEqualInt(i4(p + 20), 0); /* Compressed size */ - assertEqualInt(i4(p + 24), 0); /* Uncompressed size */ - assertEqualInt(i2(p + 28), strlen(folder_name)); /* Pathname length */ - assertEqualInt(i2(p + 30), 13); /* Extra field length */ - assertEqualInt(i2(p + 32), 0); /* File comment length */ - assertEqualInt(i2(p + 34), 0); /* Disk number start */ - assertEqualInt(i2(p + 36), 0); /* Internal file attrs */ - assertEqualInt(i4(p + 38) >> 16 & 01777, folder_perm); /* External file attrs */ - assertEqualInt(i4(p + 42), q - buff); /* Offset of local header */ - assertEqualMem(p + 46, folder_name, strlen(folder_name)); /* Pathname */ - p = p + 46 + strlen(folder_name); - assertEqualInt(i2(p), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(p + 2), 5); /* 'UT' size */ - assertEqualInt(p[4], 7); /* 'UT' flags */ - assertEqualInt(i4(p + 5), t); /* 'UT' mtime */ - p = p + 9; - assertEqualInt(i2(p), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(p + 2), 0); /* 'Ux' size */ - p = p + 4; - - /* Verify local header of folder entry. */ - assertEqualMem(q, "PK\003\004", 4); /* Signature */ - assertEqualInt(i2(q + 4), 20); /* Version needed to extract */ - assertEqualInt(i2(q + 6), 8); /* Flags */ - assertEqualInt(i2(q + 8), 0); /* Compression method */ - assertEqualInt(i2(q + 10), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ - assertEqualInt(i2(q + 12), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ - assertEqualInt(i4(q + 14), 0); /* CRC-32 */ - assertEqualInt(i4(q + 18), 0); /* Compressed size */ - assertEqualInt(i4(q + 22), 0); /* Uncompressed size */ - assertEqualInt(i2(q + 26), strlen(folder_name)); /* Pathname length */ - assertEqualInt(i2(q + 28), 25); /* Extra field length */ - assertEqualMem(q + 30, folder_name, strlen(folder_name)); /* Pathname */ - q = q + 30 + strlen(folder_name); - assertEqualInt(i2(q), 0x5455); /* 'UT' extension header */ - assertEqualInt(i2(q + 2), 13); /* 'UT' size */ - assertEqualInt(q[4], 7); /* 'UT' flags */ - assertEqualInt(i4(q + 5), t); /* 'UT' mtime */ - assertEqualInt(i4(q + 9), t); /* 'UT' atime */ - assertEqualInt(i4(q + 13), t); /* 'UT' ctime */ - q = q + 17; - assertEqualInt(i2(q), 0x7855); /* 'Ux' extension header */ - assertEqualInt(i2(q + 2), 4); /* 'Ux' size */ - assertEqualInt(i2(q + 4), folder_uid); /* 'Ux' UID */ - assertEqualInt(i2(q + 6), folder_gid); /* 'Ux' GID */ - q = q + 8; - - /* There should not be any data in the folder entry, - * meaning next is the data descriptor header. */ - - /* Verify data descriptor of folder entry. */ - assertEqualMem(q, "PK\007\010", 4); /* Signature */ - assertEqualInt(i4(q + 4), crc); /* CRC-32 */ - assertEqualInt(i4(q + 8), 0); /* Compressed size */ - assertEqualInt(i4(q + 12), 0); /* Uncompressed size */ - q = q + 16; -} diff --git a/Utilities/cmlibarchive/libarchive/test/test_write_open_memory.c b/Utilities/cmlibarchive/libarchive/test/test_write_open_memory.c deleted file mode 100644 index 5a419fcb4..000000000 --- a/Utilities/cmlibarchive/libarchive/test/test_write_open_memory.c +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/lib/libarchive/test/test_write_open_memory.c,v 1.4 2008/09/01 05:38:33 kientzle Exp $"); - -/* Try to force archive_write_open_memory.c to write past the end of an array. */ -static unsigned char buff[16384]; - -DEFINE_TEST(test_write_open_memory) -{ - unsigned int i; - struct archive *a; - struct archive_entry *ae; - const char *name="/tmp/test"; - - /* Create a simple archive_entry. */ - assert((ae = archive_entry_new()) != NULL); - archive_entry_set_pathname(ae, name); - archive_entry_set_mode(ae, S_IFREG); - assertEqualString(archive_entry_pathname(ae), name); - - /* Try writing with different buffer sizes. */ - /* Make sure that we get failure on too-small buffers, success on - * large enough ones. */ - for (i = 100; i < 1600; i++) { - size_t s; - size_t blocksize = 94; - assert((a = archive_write_new()) != NULL); - assertA(0 == archive_write_set_format_ustar(a)); - assertA(0 == archive_write_set_bytes_in_last_block(a, 1)); - assertA(0 == archive_write_set_bytes_per_block(a, (int)blocksize)); - buff[i] = 0xAE; - assertA(0 == archive_write_open_memory(a, buff, i, &s)); - /* If buffer is smaller than a tar header, this should fail. */ - if (i < (511/blocksize)*blocksize) - assertA(ARCHIVE_FATAL == archive_write_header(a,ae)); - else - assertA(0 == archive_write_header(a, ae)); - /* If buffer is smaller than a tar header plus 1024 byte - * end-of-archive marker, then this should fail. */ - if (i < 1536) - assertA(ARCHIVE_FATAL == archive_write_close(a)); - else - assertA(0 == archive_write_close(a)); -#if ARCHIVE_VERSION_NUMBER < 2000000 - archive_write_finish(a); -#else - assert(0 == archive_write_finish(a)); -#endif - assert(buff[i] == 0xAE); - assert(s <= i); - } - archive_entry_free(ae); -} diff --git a/Utilities/cmlibarchive/libarchive_fe/err.c b/Utilities/cmlibarchive/libarchive_fe/err.c deleted file mode 100644 index b0bc70a93..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/err.c +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_STDARG_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "err.h" - -const char *lafe_progname; - -static void -lafe_vwarnc(int code, const char *fmt, va_list ap) -{ - fprintf(stderr, "%s: ", lafe_progname); - vfprintf(stderr, fmt, ap); - if (code != 0) - fprintf(stderr, ": %s", strerror(code)); - fprintf(stderr, "\n"); -} - -void -lafe_warnc(int code, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - lafe_vwarnc(code, fmt, ap); - va_end(ap); -} - -void -lafe_errc(int eval, int code, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - lafe_vwarnc(code, fmt, ap); - va_end(ap); - exit(eval); -} diff --git a/Utilities/cmlibarchive/libarchive_fe/err.h b/Utilities/cmlibarchive/libarchive_fe/err.h deleted file mode 100644 index c507be1ee..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/err.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * 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. - */ - -#ifndef LAFE_ERR_H -#define LAFE_ERR_H - -extern const char *lafe_progname; - -void lafe_warnc(int code, const char *fmt, ...); -void lafe_errc(int eval, int code, const char *fmt, ...); - -#endif diff --git a/Utilities/cmlibarchive/libarchive_fe/lafe_platform.h b/Utilities/cmlibarchive/libarchive_fe/lafe_platform.h deleted file mode 100644 index 79fa2b44f..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/lafe_platform.h +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/cpio/cpio_platform.h,v 1.2 2008/12/06 07:15:42 kientzle Exp $ - */ - -/* - * This header is the first thing included in any of the libarchive_fe - * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. - */ - -#ifndef LAFE_PLATFORM_H_INCLUDED -#define LAFE_PLATFORM_H_INCLUDED - -#if defined(PLATFORM_CONFIG_H) -/* Use hand-built config.h in environments that need it. */ -#include PLATFORM_CONFIG_H -#else -/* Read config.h or die trying. */ -#include "config.h" -#endif - -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#elif !defined(__FBSDID) -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ -#define __FBSDID(a) struct _undefined_hack -#endif - -#endif diff --git a/Utilities/cmlibarchive/libarchive_fe/line_reader.c b/Utilities/cmlibarchive/libarchive_fe/line_reader.c deleted file mode 100644 index f7d265647..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/line_reader.c +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2008 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include "err.h" -#include "line_reader.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define strdup _strdup -#endif - -/* - * Read lines from file and do something with each one. If option_null - * is set, lines are terminated with zero bytes; otherwise, they're - * terminated with newlines. - * - * This uses a self-sizing buffer to handle arbitrarily-long lines. - */ -struct lafe_line_reader { - FILE *f; - char *buff, *buff_end, *line_start, *line_end, *p; - char *pathname; - size_t buff_length; - int nullSeparator; /* Lines separated by null, not CR/CRLF/etc. */ - int ret; -}; - -struct lafe_line_reader * -lafe_line_reader(const char *pathname, int nullSeparator) -{ - struct lafe_line_reader *lr; - - lr = calloc(1, sizeof(*lr)); - if (lr == NULL) - lafe_errc(1, ENOMEM, "Can't open %s", pathname); - - lr->nullSeparator = nullSeparator; - lr->pathname = strdup(pathname); - - if (strcmp(pathname, "-") == 0) - lr->f = stdin; - else - lr->f = fopen(pathname, "r"); - if (lr->f == NULL) - lafe_errc(1, errno, "Couldn't open %s", pathname); - lr->buff_length = 8192; - lr->buff = malloc(lr->buff_length); - if (lr->buff == NULL) - lafe_errc(1, ENOMEM, "Can't read %s", pathname); - lr->line_start = lr->line_end = lr->buff_end = lr->buff; - - return (lr); -} - -const char * -lafe_line_reader_next(struct lafe_line_reader *lr) -{ - size_t bytes_wanted, bytes_read, new_buff_size; - char *line_start, *p; - - for (;;) { - /* If there's a line in the buffer, return it immediately. */ - while (lr->line_end < lr->buff_end) { - if (lr->nullSeparator) { - if (*lr->line_end == '\0') { - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - return (line_start); - } - } else if (*lr->line_end == '\x0a' || *lr->line_end == '\x0d') { - *lr->line_end = '\0'; - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - if (line_start[0] != '\0') - return (line_start); - } - lr->line_end++; - } - - /* If we're at end-of-file, process the final data. */ - if (lr->f == NULL) { - /* If there's more text, return one last line. */ - if (lr->line_end > lr->line_start) { - *lr->line_end = '\0'; - line_start = lr->line_start; - lr->line_start = lr->line_end + 1; - lr->line_end = lr->line_start; - return (line_start); - } - /* Otherwise, we're done. */ - return (NULL); - } - - /* Buffer only has part of a line. */ - if (lr->line_start > lr->buff) { - /* Move a leftover fractional line to the beginning. */ - memmove(lr->buff, lr->line_start, - lr->buff_end - lr->line_start); - lr->buff_end -= lr->line_start - lr->buff; - lr->line_end -= lr->line_start - lr->buff; - lr->line_start = lr->buff; - } else { - /* Line is too big; enlarge the buffer. */ - new_buff_size = lr->buff_length * 2; - if (new_buff_size <= lr->buff_length) - lafe_errc(1, ENOMEM, - "Line too long in %s", lr->pathname); - lr->buff_length = new_buff_size; - p = realloc(lr->buff, new_buff_size); - if (p == NULL) - lafe_errc(1, ENOMEM, - "Line too long in %s", lr->pathname); - lr->buff_end = p + (lr->buff_end - lr->buff); - lr->line_end = p + (lr->line_end - lr->buff); - lr->line_start = lr->buff = p; - } - - /* Get some more data into the buffer. */ - bytes_wanted = lr->buff + lr->buff_length - lr->buff_end; - bytes_read = fread(lr->buff_end, 1, bytes_wanted, lr->f); - lr->buff_end += bytes_read; - - if (ferror(lr->f)) - lafe_errc(1, errno, "Can't read %s", lr->pathname); - if (feof(lr->f)) { - if (lr->f != stdin) - fclose(lr->f); - lr->f = NULL; - } - } -} - -void -lafe_line_reader_free(struct lafe_line_reader *lr) -{ - free(lr->buff); - free(lr->pathname); - free(lr); -} diff --git a/Utilities/cmlibarchive/libarchive_fe/line_reader.h b/Utilities/cmlibarchive/libarchive_fe/line_reader.h deleted file mode 100644 index 7b6f42984..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/line_reader.h +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * Copyright (c) 2009 Joerg Sonnenberger - * 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. - */ - -#ifndef LAFE_LINE_READER_H -#define LAFE_LINE_READER_H - -struct lafe_line_reader; - -struct lafe_line_reader *lafe_line_reader(const char *, int nullSeparator); -const char *lafe_line_reader_next(struct lafe_line_reader *); -void lafe_line_reader_free(struct lafe_line_reader *); - -#endif diff --git a/Utilities/cmlibarchive/libarchive_fe/matching.c b/Utilities/cmlibarchive/libarchive_fe/matching.c deleted file mode 100644 index 0a05bd363..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/matching.c +++ /dev/null @@ -1,284 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "lafe_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/cpio/matching.c,v 1.2 2008/06/21 02:20:20 kientzle Exp $"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "err.h" -#include "line_reader.h" -#include "matching.h" -#include "pathmatch.h" - -struct match { - struct match *next; - int matches; - char pattern[1]; -}; - -struct lafe_matching { - struct match *exclusions; - int exclusions_count; - struct match *inclusions; - int inclusions_count; - int inclusions_unmatched_count; -}; - -static void add_pattern(struct match **list, const char *pattern); -static void initialize_matching(struct lafe_matching **); -static int match_exclusion(struct match *, const char *pathname); -static int match_inclusion(struct match *, const char *pathname); - -/* - * The matching logic here needs to be re-thought. I started out to - * try to mimic gtar's matching logic, but it's not entirely - * consistent. In particular 'tar -t' and 'tar -x' interpret patterns - * on the command line as anchored, but --exclude doesn't. - */ - -/* - * Utility functions to manage exclusion/inclusion patterns - */ - -int -lafe_exclude(struct lafe_matching **matching, const char *pattern) -{ - - if (*matching == NULL) - initialize_matching(matching); - add_pattern(&((*matching)->exclusions), pattern); - (*matching)->exclusions_count++; - return (0); -} - -int -lafe_exclude_from_file(struct lafe_matching **matching, const char *pathname) -{ - struct lafe_line_reader *lr; - const char *p; - int ret = 0; - - lr = lafe_line_reader(pathname, '\n'); - while ((p = lafe_line_reader_next(lr)) != NULL) { - if (lafe_exclude(matching, p) != 0) - ret = -1; - } - lafe_line_reader_free(lr); - return (ret); -} - -int -lafe_include(struct lafe_matching **matching, const char *pattern) -{ - - if (*matching == NULL) - initialize_matching(matching); - add_pattern(&((*matching)->inclusions), pattern); - (*matching)->inclusions_count++; - (*matching)->inclusions_unmatched_count++; - return (0); -} - -int -lafe_include_from_file(struct lafe_matching **matching, const char *pathname, - int nullSeparator) -{ - struct lafe_line_reader *lr; - const char *p; - int ret = 0; - - lr = lafe_line_reader(pathname, nullSeparator); - while ((p = lafe_line_reader_next(lr)) != NULL) { - if (lafe_include(matching, p) != 0) - ret = -1; - } - lafe_line_reader_free(lr); - return (ret); -} - -static void -add_pattern(struct match **list, const char *pattern) -{ - struct match *match; - size_t len; - - len = strlen(pattern); - match = malloc(sizeof(*match) + len + 1); - if (match == NULL) - lafe_errc(1, errno, "Out of memory"); - strcpy(match->pattern, pattern); - /* Both "foo/" and "foo" should match "foo/bar". */ - if (len && match->pattern[len - 1] == '/') - match->pattern[strlen(match->pattern)-1] = '\0'; - match->next = *list; - *list = match; - match->matches = 0; -} - - -int -lafe_excluded(struct lafe_matching *matching, const char *pathname) -{ - struct match *match; - struct match *matched; - - if (matching == NULL) - return (0); - - /* Exclusions take priority */ - for (match = matching->exclusions; match != NULL; match = match->next){ - if (match_exclusion(match, pathname)) - return (1); - } - - /* Then check for inclusions */ - matched = NULL; - for (match = matching->inclusions; match != NULL; match = match->next){ - if (match_inclusion(match, pathname)) { - /* - * If this pattern has never been matched, - * then we're done. - */ - if (match->matches == 0) { - match->matches++; - matching->inclusions_unmatched_count--; - return (0); - } - /* - * Otherwise, remember the match but keep checking - * in case we can tick off an unmatched pattern. - */ - matched = match; - } - } - /* - * We didn't find a pattern that had never been matched, but - * we did find a match, so count it and exit. - */ - if (matched != NULL) { - matched->matches++; - return (0); - } - - /* If there were inclusions, default is to exclude. */ - if (matching->inclusions != NULL) - return (1); - - /* No explicit inclusions, default is to match. */ - return (0); -} - -/* - * This is a little odd, but it matches the default behavior of - * gtar. In particular, 'a*b' will match 'foo/a1111/222b/bar' - * - */ -static int -match_exclusion(struct match *match, const char *pathname) -{ - return (lafe_pathmatch(match->pattern, - pathname, - PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); -} - -/* - * Again, mimic gtar: inclusions are always anchored (have to match - * the beginning of the path) even though exclusions are not anchored. - */ -static int -match_inclusion(struct match *match, const char *pathname) -{ -#if 0 - return (lafe_pathmatch(match->pattern, pathname, 0)); -#else - return (lafe_pathmatch(match->pattern, pathname, PATHMATCH_NO_ANCHOR_END)); -#endif -} - -void -lafe_cleanup_exclusions(struct lafe_matching **matching) -{ - struct match *p, *q; - - if (*matching == NULL) - return; - - for (p = (*matching)->inclusions; p != NULL; ) { - q = p; - p = p->next; - free(q); - } - - for (p = (*matching)->exclusions; p != NULL; ) { - q = p; - p = p->next; - free(q); - } - - free(*matching); - *matching = NULL; -} - -static void -initialize_matching(struct lafe_matching **matching) -{ - *matching = calloc(sizeof(**matching), 1); - if (*matching == NULL) - lafe_errc(1, errno, "No memory"); -} - -int -lafe_unmatched_inclusions(struct lafe_matching *matching) -{ - - if (matching == NULL) - return (0); - return (matching->inclusions_unmatched_count); -} - -int -lafe_unmatched_inclusions_warn(struct lafe_matching *matching, const char *msg) -{ - struct match *p; - - if (matching == NULL) - return (0); - - for (p = matching->inclusions; p != NULL; p = p->next) { - if (p->matches == 0) - lafe_warnc(0, "%s: %s", p->pattern, msg); - } - - return (matching->inclusions_unmatched_count); -} diff --git a/Utilities/cmlibarchive/libarchive_fe/matching.h b/Utilities/cmlibarchive/libarchive_fe/matching.h deleted file mode 100644 index af9e57551..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/matching.h +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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. - * - * $FreeBSD$ - */ - -#ifndef MATCHING_H -#define MATCHING_H - -struct lafe_matching; - -int lafe_exclude(struct lafe_matching **matching, const char *pattern); -int lafe_exclude_from_file(struct lafe_matching **matching, - const char *pathname); -int lafe_include(struct lafe_matching **matching, const char *pattern); -int lafe_include_from_file(struct lafe_matching **matching, - const char *pathname, int nullSeparator); - -int lafe_excluded(struct lafe_matching *, const char *pathname); -void lafe_cleanup_exclusions(struct lafe_matching **); -int lafe_unmatched_inclusions(struct lafe_matching *); -int lafe_unmatched_inclusions_warn(struct lafe_matching *, const char *msg); - -#endif diff --git a/Utilities/cmlibarchive/libarchive_fe/pathmatch.c b/Utilities/cmlibarchive/libarchive_fe/pathmatch.c deleted file mode 100644 index 8ea9161e3..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/pathmatch.c +++ /dev/null @@ -1,257 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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 "lafe_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_STRING_H -#include -#endif - -#include "pathmatch.h" - -/* - * Check whether a character 'c' is matched by a list specification [...]: - * * Leading '!' negates the class. - * * - is a range of characters - * * \ removes any special meaning for - * - * Some interesting boundary cases: - * a-d-e is one range (a-d) followed by two single characters - and e. - * \a-\d is same as a-d - * a\-d is three single characters: a, d, - - * Trailing - is not special (so [a-] is two characters a and -). - * Initial - is not special ([a-] is same as [-a] is same as [\\-a]) - * This function never sees a trailing \. - * [] always fails - * [!] always succeeds - */ -static int -pm_list(const char *start, const char *end, const char c, int flags) -{ - const char *p = start; - char rangeStart = '\0', nextRangeStart; - int match = 1, nomatch = 0; - - /* This will be used soon... */ - (void)flags; /* UNUSED */ - - /* If this is a negated class, return success for nomatch. */ - if (*p == '!' && p < end) { - match = 0; - nomatch = 1; - ++p; - } - - while (p < end) { - nextRangeStart = '\0'; - switch (*p) { - case '-': - /* Trailing or initial '-' is not special. */ - if ((rangeStart == '\0') || (p == end - 1)) { - if (*p == c) - return (match); - } else { - char rangeEnd = *++p; - if (rangeEnd == '\\') - rangeEnd = *++p; - if ((rangeStart <= c) && (c <= rangeEnd)) - return (match); - } - break; - case '\\': - ++p; - /* Fall through */ - default: - if (*p == c) - return (match); - nextRangeStart = *p; /* Possible start of range. */ - } - rangeStart = nextRangeStart; - ++p; - } - return (nomatch); -} - -/* - * If s is pointing to "./", ".//", "./././" or the like, skip it. - */ -static const char * -pm_slashskip(const char *s) { - while ((*s == '/') - || (s[0] == '.' && s[1] == '/') - || (s[0] == '.' && s[1] == '\0')) - ++s; - return (s); -} - -static int -pm(const char *p, const char *s, int flags) -{ - const char *end; - - /* - * Ignore leading './', './/', '././', etc. - */ - if (s[0] == '.' && s[1] == '/') - s = pm_slashskip(s + 1); - if (p[0] == '.' && p[1] == '/') - p = pm_slashskip(p + 1); - - for (;;) { - switch (*p) { - case '\0': - if (s[0] == '/') { - if (flags & PATHMATCH_NO_ANCHOR_END) - return (1); - /* "dir" == "dir/" == "dir/." */ - s = pm_slashskip(s); - } - return (*s == '\0'); - break; - case '?': - /* ? always succeds, unless we hit end of 's' */ - if (*s == '\0') - return (0); - break; - case '*': - /* "*" == "**" == "***" ... */ - while (*p == '*') - ++p; - /* Trailing '*' always succeeds. */ - if (*p == '\0') - return (1); - while (*s) { - if (lafe_pathmatch(p, s, flags)) - return (1); - ++s; - } - return (0); - break; - case '[': - /* - * Find the end of the [...] character class, - * ignoring \] that might occur within the class. - */ - end = p + 1; - while (*end != '\0' && *end != ']') { - if (*end == '\\' && end[1] != '\0') - ++end; - ++end; - } - if (*end == ']') { - /* We found [...], try to match it. */ - if (!pm_list(p + 1, end, *s, flags)) - return (0); - p = end; /* Jump to trailing ']' char. */ - break; - } else - /* No final ']', so just match '['. */ - if (*p != *s) - return (0); - break; - case '\\': - /* Trailing '\\' matches itself. */ - if (p[1] == '\0') { - if (*s != '\\') - return (0); - } else { - ++p; - if (*p != *s) - return (0); - } - break; - case '/': - if (*s != '/' && *s != '\0') - return (0); - /* Note: pattern "/\./" won't match "/"; - * pm_slashskip() correctly stops at backslash. */ - p = pm_slashskip(p); - s = pm_slashskip(s); - if (*p == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)) - return (1); - --p; /* Counteract the increment below. */ - --s; - break; - case '$': - /* '$' is special only at end of pattern and only - * if PATHMATCH_NO_ANCHOR_END is specified. */ - if (p[1] == '\0' && (flags & PATHMATCH_NO_ANCHOR_END)){ - /* "dir" == "dir/" == "dir/." */ - return (*pm_slashskip(s) == '\0'); - } - /* Otherwise, '$' is not special. */ - /* FALL THROUGH */ - default: - if (*p != *s) - return (0); - break; - } - ++p; - ++s; - } -} - -/* Main entry point. */ -int -lafe_pathmatch(const char *p, const char *s, int flags) -{ - /* Empty pattern only matches the empty string. */ - if (p == NULL || *p == '\0') - return (s == NULL || *s == '\0'); - - /* Leading '^' anchors the start of the pattern. */ - if (*p == '^') { - ++p; - flags &= ~PATHMATCH_NO_ANCHOR_START; - } - - if (*p == '/' && *s != '/') - return (0); - - /* Certain patterns and file names anchor implicitly. */ - if (*p == '*' || *p == '/' || *p == '/') { - while (*p == '/') - ++p; - while (*s == '/') - ++s; - return (pm(p, s, flags)); - } - - /* If start is unanchored, try to match start of each path element. */ - if (flags & PATHMATCH_NO_ANCHOR_START) { - for ( ; s != NULL; s = strchr(s, '/')) { - if (*s == '/') - s++; - if (pm(p, s, flags)) - return (1); - } - return (0); - } - - /* Default: Match from beginning. */ - return (pm(p, s, flags)); -} diff --git a/Utilities/cmlibarchive/libarchive_fe/pathmatch.h b/Utilities/cmlibarchive/libarchive_fe/pathmatch.h deleted file mode 100644 index ee8eecc38..000000000 --- a/Utilities/cmlibarchive/libarchive_fe/pathmatch.h +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 - * in this position and unchanged. - * 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. - * - * $FreeBSD$ - */ - -#ifndef LAFE_PATHMATCH_H -#define LAFE_PATHMATCH_H - -/* Don't anchor at beginning unless the pattern starts with "^" */ -#define PATHMATCH_NO_ANCHOR_START 1 -/* Don't anchor at end unless the pattern ends with "$" */ -#define PATHMATCH_NO_ANCHOR_END 2 - -/* Note that "^" and "$" are not special unless you set the corresponding - * flag above. */ - -int lafe_pathmatch(const char *p, const char *s, int flags); - -#endif diff --git a/Utilities/cmlibarchive/tar/CMakeLists.txt b/Utilities/cmlibarchive/tar/CMakeLists.txt deleted file mode 100644 index f6a0d0ec7..000000000 --- a/Utilities/cmlibarchive/tar/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -############################################ -# -# How to build bsdtar -# -############################################ -IF (ENABLE_TAR) - - SET(bsdtar_SOURCES - bsdtar.c - bsdtar.h - bsdtar_platform.h - cmdline.c - getdate.c - read.c - subst.c - tree.c - tree.h - util.c - write.c - ../libarchive_fe/err.c - ../libarchive_fe/err.h - ../libarchive_fe/lafe_platform.h - ../libarchive_fe/line_reader.c - ../libarchive_fe/line_reader.h - ../libarchive_fe/matching.c - ../libarchive_fe/matching.h - ../libarchive_fe/pathmatch.c - ../libarchive_fe/pathmatch.h - ) - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libarchive_fe) - IF(WIN32 AND NOT CYGWIN) - LIST(APPEND bsdtar_SOURCES bsdtar_windows.c) - LIST(APPEND bsdtar_SOURCES bsdtar_windows.h) - ENDIF(WIN32 AND NOT CYGWIN) - - # bsdtar documentation - SET(bsdtar_MANS bsdtar.1) - - # How to build bsdtar - ADD_EXECUTABLE(bsdtar ${bsdtar_SOURCES}) - IF(ENABLE_TAR_SHARED) - TARGET_LINK_LIBRARIES(bsdtar archive ${ADDITIONAL_LIBS}) - ELSE(ENABLE_TAR_SHARED) - TARGET_LINK_LIBRARIES(bsdtar archive_static ${ADDITIONAL_LIBS}) - ENDIF(ENABLE_TAR_SHARED) - # On Windows, DLL must end up in same dir with EXEs - IF(WIN32 AND NOT CYGWIN) - SET_TARGET_PROPERTIES(bsdtar PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) - ENDIF(WIN32 AND NOT CYGWIN) - GET_TARGET_PROPERTY(BSDTAR bsdtar LOCATION) - - # Installation rules - INSTALL(TARGETS bsdtar RUNTIME DESTINATION bin) - INSTALL_MAN(${bsdtar_MANS}) -ENDIF(ENABLE_TAR) - -add_subdirectory(test) diff --git a/Utilities/cmlibarchive/tar/bsdtar.1 b/Utilities/cmlibarchive/tar/bsdtar.1 deleted file mode 100644 index 28d5106e2..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar.1 +++ /dev/null @@ -1,921 +0,0 @@ -.\" Copyright (c) 2003-2007 Tim Kientzle -.\" 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 AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD: src/usr.bin/tar/bsdtar.1,v 1.46 2008/12/06 07:37:55 kientzle Exp $ -.\" -.Dd May 26, 2009 -.Dt BSDTAR 1 -.Os -.Sh NAME -.Nm tar -.Nd manipulate tape archives -.Sh SYNOPSIS -.Nm -.Op Ar bundled-flags Ao args Ac -.Op Ao Ar file Ac | Ao Ar pattern Ac ... -.Nm -.Brq Fl c -.Op Ar options -.Op Ar files | Ar directories -.Nm -.Brq Fl r | Fl u -.Fl f Ar archive-file -.Op Ar options -.Op Ar files | Ar directories -.Nm -.Brq Fl t | Fl x -.Op Ar options -.Op Ar patterns -.Sh DESCRIPTION -.Nm -creates and manipulates streaming archive files. -This implementation can extract from tar, pax, cpio, zip, jar, ar, -and ISO 9660 cdrom images and can create tar, pax, cpio, ar, -and shar archives. -.Pp -The first synopsis form shows a -.Dq bundled -option word. -This usage is provided for compatibility with historical implementations. -See COMPATIBILITY below for details. -.Pp -The other synopsis forms show the preferred usage. -The first option to -.Nm -is a mode indicator from the following list: -.Bl -tag -compact -width indent -.It Fl c -Create a new archive containing the specified items. -.It Fl r -Like -.Fl c , -but new entries are appended to the archive. -Note that this only works on uncompressed archives stored in regular files. -The -.Fl f -option is required. -.It Fl t -List archive contents to stdout. -.It Fl u -Like -.Fl r , -but new entries are added only if they have a modification date -newer than the corresponding entry in the archive. -Note that this only works on uncompressed archives stored in regular files. -The -.Fl f -option is required. -.It Fl x -Extract to disk from the archive. -If a file with the same name appears more than once in the archive, -each copy will be extracted, with later copies overwriting (replacing) -earlier copies. -.El -.Pp -In -.Fl c , -.Fl r , -or -.Fl u -mode, each specified file or directory is added to the -archive in the order specified on the command line. -By default, the contents of each directory are also archived. -.Pp -In extract or list mode, the entire command line -is read and parsed before the archive is opened. -The pathnames or patterns on the command line indicate -which items in the archive should be processed. -Patterns are shell-style globbing patterns as -documented in -.Xr tcsh 1 . -.Sh OPTIONS -Unless specifically stated otherwise, options are applicable in -all operating modes. -.Bl -tag -width indent -.It Cm @ Ns Pa archive -(c and r mode only) -The specified archive is opened and the entries -in it will be appended to the current archive. -As a simple example, -.Dl Nm Fl c Fl f Pa - Pa newfile Cm @ Ns Pa original.tar -writes a new archive to standard output containing a file -.Pa newfile -and all of the entries from -.Pa original.tar . -In contrast, -.Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar -creates a new archive with only two entries. -Similarly, -.Dl Nm Fl czf Pa - Fl -format Cm pax Cm @ Ns Pa - -reads an archive from standard input (whose format will be determined -automatically) and converts it into a gzip-compressed -pax-format archive on stdout. -In this way, -.Nm -can be used to convert archives from one format to another. -.It Fl b Ar blocksize -Specify the block size, in 512-byte records, for tape drive I/O. -As a rule, this argument is only needed when reading from or writing -to tape drives, and usually not even then as the default block size of -20 records (10240 bytes) is very common. -.It Fl C Ar directory -In c and r mode, this changes the directory before adding -the following files. -In x mode, change directories after opening the archive -but before extracting entries from the archive. -.It Fl -check-links -(c and r modes only) -Issue a warning message unless all links to each file are archived. -.It Fl -chroot -(x mode only) -.Fn chroot -to the current directory after processing any -.Fl C -options and before extracting any files. -.It Fl -exclude Ar pattern -Do not process files or directories that match the -specified pattern. -Note that exclusions take precedence over patterns or filenames -specified on the command line. -.It Fl -format Ar format -(c, r, u mode only) -Use the specified format for the created archive. -Supported formats include -.Dq cpio , -.Dq pax , -.Dq shar , -and -.Dq ustar . -Other formats may also be supported; see -.Xr libarchive-formats 5 -for more information about currently-supported formats. -In r and u modes, when extending an existing archive, the format specified -here must be compatible with the format of the existing archive on disk. -.It Fl f Ar file -Read the archive from or write the archive to the specified file. -The filename can be -.Pa - -for standard input or standard output. -If not specified, the default tape device will be used. -(On -.Fx , -the default tape device is -.Pa /dev/sa0 . ) -.It Fl H -(c and r mode only) -Symbolic links named on the command line will be followed; the -target of the link will be archived, not the link itself. -.It Fl h -(c and r mode only) -Synonym for -.Fl L . -.It Fl I -Synonym for -.Fl T . -.It Fl -include Ar pattern -Process only files or directories that match the specified pattern. -Note that exclusions specified with -.Fl -exclude -take precedence over inclusions. -If no inclusions are explicitly specified, all entries are processed by -default. -The -.Fl -include -option is especially useful when filtering archives. -For example, the command -.Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz -creates a new archive -.Pa new.tar -containing only the entries from -.Pa old.tgz -containing the string -.Sq foo . -.It Fl j -(c mode only) -Compress the resulting archive with -.Xr bzip2 1 . -In extract or list modes, this option is ignored. -Note that, unlike other -.Nm tar -implementations, this implementation recognizes bzip2 compression -automatically when reading archives. -.It Fl k -(x mode only) -Do not overwrite existing files. -In particular, if a file appears more than once in an archive, -later copies will not overwrite earlier copies. -.It Fl -keep-newer-files -(x mode only) -Do not overwrite existing files that are newer than the -versions appearing in the archive being extracted. -.It Fl L -(c and r mode only) -All symbolic links will be followed. -Normally, symbolic links are archived as such. -With this option, the target of the link will be archived instead. -.It Fl l -This is a synonym for the -.Fl -check-links -option. -.It Fl m -(x mode only) -Do not extract modification time. -By default, the modification time is set to the time stored in the archive. -.It Fl n -(c, r, u modes only) -Do not recursively archive the contents of directories. -.It Fl -newer Ar date -(c, r, u modes only) -Only include files and directories newer than the specified date. -This compares ctime entries. -.It Fl -newer-mtime Ar date -(c, r, u modes only) -Like -.Fl -newer , -except it compares mtime entries instead of ctime entries. -.It Fl -newer-than Pa file -(c, r, u modes only) -Only include files and directories newer than the specified file. -This compares ctime entries. -.It Fl -newer-mtime-than Pa file -(c, r, u modes only) -Like -.Fl -newer-than , -except it compares mtime entries instead of ctime entries. -.It Fl -nodump -(c and r modes only) -Honor the nodump file flag by skipping this file. -.It Fl -null -(use with -.Fl I , -.Fl T , -or -.Fl X ) -Filenames or patterns are separated by null characters, -not by newlines. -This is often used to read filenames output by the -.Fl print0 -option to -.Xr find 1 . -.It Fl -numeric-owner -(x mode only) -Ignore symbolic user and group names when restoring archives to disk, -only numeric uid and gid values will be obeyed. -.It Fl O -(x, t modes only) -In extract (-x) mode, files will be written to standard out rather than -being extracted to disk. -In list (-t) mode, the file listing will be written to stderr rather than -the usual stdout. -.It Fl o -(x mode) -Use the user and group of the user running the program rather -than those specified in the archive. -Note that this has no significance unless -.Fl p -is specified, and the program is being run by the root user. -In this case, the file modes and flags from -the archive will be restored, but ACLs or owner information in -the archive will be discarded. -.It Fl o -(c, r, u mode) -A synonym for -.Fl -format Ar ustar -.It Fl -one-file-system -(c, r, and u modes) -Do not cross mount points. -.It Fl -options Ar options -Select optional behaviors for particular modules. -The argument is a text string containing comma-separated -keywords and values. -These are passed to the modules that handle particular -formats to control how those formats will behave. -Each option has one of the following forms: -.Bl -tag -compact -width indent -.It Ar key=value -The key will be set to the specified value in every module that supports it. -Modules that do not support this key will ignore it. -.It Ar key -The key will be enabled in every module that supports it. -This is equivalent to -.Ar key Ns Cm =1 . -.It Ar !key -The key will be disabled in every module that supports it. -.It Ar module:key=value , Ar module:key , Ar module:!key -As above, but the corresponding key and value will be provided -only to modules whose name matches -.Ar module . -.El -The currently supported modules and keys are: -.Bl -tag -compact -width indent -.It Cm iso9660:joliet -Support Joliet extensions. -This is enabled by default, use -.Cm !joliet -or -.Cm iso9660:!joliet -to disable. -.It Cm iso9660:rock-ridge -Support Rock Ridge extensions. -This is enabled by default, use -.Cm !rock-ridge -or -.Cm iso9660:!rock-ridge -to disable. -.It Cm gzip:compression-level -A decimal integer from 0 to 9 specifying the gzip compression level. -.It Cm xz:compression-level -A decimal integer from 0 to 9 specifying the xz compression level. -.It Cm mtree: Ns Ar keyword -The mtree writer module allows you to specify which mtree keywords -will be included in the output. -Supported keywords include: -.Cm cksum , Cm device , Cm flags , Cm gid , Cm gname , Cm indent , -.Cm link , Cm md5 , Cm mode , Cm nlink , Cm rmd160 , Cm sha1 , Cm sha256 , -.Cm sha384 , Cm sha512 , Cm size , Cm time , Cm uid , Cm uname . -The default is equivalent to: -.Dq device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname . -.It Cm mtree:all -Enables all of the above keywords. -You can also use -.Cm mtree:!all -to disable all keywords. -.It Cm mtree:use-set -Enable generation of -.Cm /set -lines in the output. -.It Cm mtree:indent -Produce human-readable output by indenting options and splitting lines -to fit into 80 columns. -.It Cm zip:compression Ns = Ns Ar type -Use -.Ar type -as compression method. -Supported values are store (uncompressed) and deflate (gzip algorithm). -.El -If a provided option is not supported by any module, that -is a fatal error. -.It Fl P -Preserve pathnames. -By default, absolute pathnames (those that begin with a / -character) have the leading slash removed both when creating archives -and extracting from them. -Also, -.Nm -will refuse to extract archive entries whose pathnames contain -.Pa .. -or whose target directory would be altered by a symlink. -This option suppresses these behaviors. -.It Fl p -(x mode only) -Preserve file permissions. -Attempt to restore the full permissions, including owner, file modes, file -flags and ACLs, if available, for each item extracted from the archive. -By default, newly-created files are owned by the user running -.Nm , -the file mode is restored for newly-created regular files, and -all other types of entries receive default permissions. -If -.Nm -is being run by root, the default is to restore the owner unless the -.Fl o -option is also specified. -.It Fl q ( Fl -fast-read ) -(x and t mode only) -Extract or list only the first archive entry that matches each pattern -or filename operand. -Exit as soon as each specified pattern or filename has been matched. -By default, the archive is always read to the very end, since -there can be multiple entries with the same name and, by convention, -later entries overwrite earlier entries. -This option is provided as a performance optimization. -.It Fl S -(x mode only) -Extract files as sparse files. -For every block on disk, check first if it contains only NULL bytes and seek -over it otherwise. -This works similiar to the conv=sparse option of dd. -.It Fl -strip-components Ar count -(x mode only) -Remove the specified number of leading path elements. -Pathnames with fewer elements will be silently skipped. -Note that the pathname is edited after checking inclusion/exclusion patterns -but before security checks. -.It Fl s Ar pattern -Modify file or archive member names according to -.Pa pattern . -The pattern has the format -.Ar /old/new/ Ns Op gps -where -.Ar old -is a basic regular expression, -.Ar new -is the replacement string of the matched part, -and the optional trailing letters modify -how the replacement is handled. -If -.Ar old -is not matched, the pattern is skipped. -Within -.Ar new , -~ is substituted with the match, \1 to \9 with the content of -the corresponding captured group. -The optional trailing g specifies that matching should continue -after the matched part and stopped on the first unmatched pattern. -The optional trailing s specifies that the pattern applies to the value -of symbolic links. -The optional trailing p specifies that after a successful substitution -the original path name and the new path name should be printed to -standard error. -.It Fl T Ar filename -In x or t mode, -.Nm -will read the list of names to be extracted from -.Pa filename . -In c mode, -.Nm -will read names to be archived from -.Pa filename . -The special name -.Dq -C -on a line by itself will cause the current directory to be changed to -the directory specified on the following line. -Names are terminated by newlines unless -.Fl -null -is specified. -Note that -.Fl -null -also disables the special handling of lines containing -.Dq -C . -.It Fl U -(x mode only) -Unlink files before creating them. -Without this option, -.Nm -overwrites existing files, which preserves existing hardlinks. -With this option, existing hardlinks will be broken, as will any -symlink that would affect the location of an extracted file. -.It Fl -use-compress-program Ar program -Pipe the input (in x or t mode) or the output (in c mode) through -.Pa program -instead of using the builtin compression support. -.It Fl v -Produce verbose output. -In create and extract modes, -.Nm -will list each file name as it is read from or written to -the archive. -In list mode, -.Nm -will produce output similar to that of -.Xr ls 1 . -Additional -.Fl v -options will provide additional detail. -.It Fl -version -Print version of -.Nm -and -.Nm libarchive , -and exit. -.It Fl w -Ask for confirmation for every action. -.It Fl X Ar filename -Read a list of exclusion patterns from the specified file. -See -.Fl -exclude -for more information about the handling of exclusions. -.It Fl y -(c mode only) -Compress the resulting archive with -.Xr bzip2 1 . -In extract or list modes, this option is ignored. -Note that, unlike other -.Nm tar -implementations, this implementation recognizes bzip2 compression -automatically when reading archives. -.It Fl z -(c mode only) -Compress the resulting archive with -.Xr gzip 1 . -In extract or list modes, this option is ignored. -Note that, unlike other -.Nm tar -implementations, this implementation recognizes gzip compression -automatically when reading archives. -.It Fl Z -(c mode only) -Compress the resulting archive with -.Xr compress 1 . -In extract or list modes, this option is ignored. -Note that, unlike other -.Nm tar -implementations, this implementation recognizes compress compression -automatically when reading archives. -.El -.Sh ENVIRONMENT -The following environment variables affect the execution of -.Nm : -.Bl -tag -width ".Ev BLOCKSIZE" -.It Ev LANG -The locale to use. -See -.Xr environ 7 -for more information. -.It Ev TAPE -The default tape device. -The -.Fl f -option overrides this. -.It Ev TZ -The timezone to use when displaying dates. -See -.Xr environ 7 -for more information. -.El -.Sh FILES -.Bl -tag -width ".Ev BLOCKSIZE" -.It Pa /dev/sa0 -The default tape device, if not overridden by the -.Ev TAPE -environment variable or the -.Fl f -option. -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -The following creates a new archive -called -.Ar file.tar.gz -that contains two files -.Ar source.c -and -.Ar source.h : -.Dl Nm Fl czf Pa file.tar.gz Pa source.c Pa source.h -.Pp -To view a detailed table of contents for this -archive: -.Dl Nm Fl tvf Pa file.tar.gz -.Pp -To extract all entries from the archive on -the default tape drive: -.Dl Nm Fl x -.Pp -To examine the contents of an ISO 9660 cdrom image: -.Dl Nm Fl tf Pa image.iso -.Pp -To move file hierarchies, invoke -.Nm -as -.Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpf Pa - Fl C Pa destdir -or more traditionally -.Dl cd srcdir \&; Nm Fl cf Pa -\ . | ( cd destdir \&; Nm Fl xpf Pa - ) -.Pp -In create mode, the list of files and directories to be archived -can also include directory change instructions of the form -.Cm -C Ns Pa foo/baz -and archive inclusions of the form -.Cm @ Ns Pa archive-file . -For example, the command line -.Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2 -will create a new archive -.Pa new.tar . -.Nm -will read the file -.Pa foo1 -from the current directory and add it to the output archive. -It will then read each entry from -.Pa old.tgz -and add those entries to the output archive. -Finally, it will switch to the -.Pa /tmp -directory and add -.Pa foo2 -to the output archive. -.Pp -An input file in -.Xr mtree 5 -format can be used to create an output archive with arbitrary ownership, -permissions, or names that differ from existing data on disk: -.Pp -.Dl $ cat input.mtree -.Dl #mtree -.Dl usr/bin uid=0 gid=0 mode=0755 type=dir -.Dl usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls -.Dl $ tar -cvf output.tar @input.mtree -.Pp -The -.Fl -newer -and -.Fl -newer-mtime -switches accept a variety of common date and time specifications, including -.Dq 12 Mar 2005 7:14:29pm , -.Dq 2005-03-12 19:14 , -.Dq 5 minutes ago , -and -.Dq 19:14 PST May 1 . -.Pp -The -.Fl -options -argument can be used to control various details of archive generation -or reading. -For example, you can generate mtree output which only contains -.Cm type , Cm time , -and -.Cm uid -keywords: -.Dl Nm Fl cf Pa file.tar Fl -format=mtree Fl -options='!all,type,time,uid' Pa dir -or you can set the compression level used by gzip or xz compression: -.Dl Nm Fl czf Pa file.tar Fl -options='compression-level=9' . -For more details, see the explanation of the -.Fn archive_read_set_options -and -.Fn archive_write_set_options -API calls that are described in -.Xr archive_read 3 -and -.Xr archive_write 3 . -.Sh COMPATIBILITY -The bundled-arguments format is supported for compatibility -with historic implementations. -It consists of an initial word (with no leading - character) in which -each character indicates an option. -Arguments follow as separate words. -The order of the arguments must match the order -of the corresponding characters in the bundled command word. -For example, -.Dl Nm Cm tbf 32 Pa file.tar -specifies three flags -.Cm t , -.Cm b , -and -.Cm f . -The -.Cm b -and -.Cm f -flags both require arguments, -so there must be two additional items -on the command line. -The -.Ar 32 -is the argument to the -.Cm b -flag, and -.Ar file.tar -is the argument to the -.Cm f -flag. -.Pp -The mode options c, r, t, u, and x and the options -b, f, l, m, o, v, and w comply with SUSv2. -.Pp -For maximum portability, scripts that invoke -.Nm tar -should use the bundled-argument format above, should limit -themselves to the -.Cm c , -.Cm t , -and -.Cm x -modes, and the -.Cm b , -.Cm f , -.Cm m , -.Cm v , -and -.Cm w -options. -.Pp -Additional long options are provided to improve compatibility with other -tar implementations. -.Sh SECURITY -Certain security issues are common to many archiving programs, including -.Nm . -In particular, carefully-crafted archives can request that -.Nm -extract files to locations outside of the target directory. -This can potentially be used to cause unwitting users to overwrite -files they did not intend to overwrite. -If the archive is being extracted by the superuser, any file -on the system can potentially be overwritten. -There are three ways this can happen. -Although -.Nm -has mechanisms to protect against each one, -savvy users should be aware of the implications: -.Bl -bullet -width indent -.It -Archive entries can have absolute pathnames. -By default, -.Nm -removes the leading -.Pa / -character from filenames before restoring them to guard against this problem. -.It -Archive entries can have pathnames that include -.Pa .. -components. -By default, -.Nm -will not extract files containing -.Pa .. -components in their pathname. -.It -Archive entries can exploit symbolic links to restore -files to other directories. -An archive can restore a symbolic link to another directory, -then use that link to restore a file into that directory. -To guard against this, -.Nm -checks each extracted path for symlinks. -If the final path element is a symlink, it will be removed -and replaced with the archive entry. -If -.Fl U -is specified, any intermediate symlink will also be unconditionally removed. -If neither -.Fl U -nor -.Fl P -is specified, -.Nm -will refuse to extract the entry. -.El -To protect yourself, you should be wary of any archives that -come from untrusted sources. -You should examine the contents of an archive with -.Dl Nm Fl tf Pa filename -before extraction. -You should use the -.Fl k -option to ensure that -.Nm -will not overwrite any existing files or the -.Fl U -option to remove any pre-existing files. -You should generally not extract archives while running with super-user -privileges. -Note that the -.Fl P -option to -.Nm -disables the security checks above and allows you to extract -an archive while preserving any absolute pathnames, -.Pa .. -components, or symlinks to other directories. -.Sh SEE ALSO -.Xr bzip2 1 , -.Xr compress 1 , -.Xr cpio 1 , -.Xr gzip 1 , -.Xr mt 1 , -.Xr pax 1 , -.Xr shar 1 , -.Xr libarchive 3 , -.Xr libarchive-formats 5 , -.Xr tar 5 -.Sh STANDARDS -There is no current POSIX standard for the tar command; it appeared -in -.St -p1003.1-96 -but was dropped from -.St -p1003.1-2001 . -The options used by this implementation were developed by surveying a -number of existing tar implementations as well as the old POSIX specification -for tar and the current POSIX specification for pax. -.Pp -The ustar and pax interchange file formats are defined by -.St -p1003.1-2001 -for the pax command. -.Sh HISTORY -A -.Nm tar -command appeared in Seventh Edition Unix, which was released in January, 1979. -There have been numerous other implementations, -many of which extended the file format. -John Gilmore's -.Nm pdtar -public-domain implementation (circa November, 1987) -was quite influential, and formed the basis of GNU tar. -GNU tar was included as the standard system tar -in -.Fx -beginning with -.Fx 1.0 . -.Pp -This is a complete re-implementation based on the -.Xr libarchive 3 -library. -.Sh BUGS -This program follows -.St -p1003.1-96 -for the definition of the -.Fl l -option. -Note that GNU tar prior to version 1.15 treated -.Fl l -as a synonym for the -.Fl -one-file-system -option. -.Pp -The -.Fl C Pa dir -option may differ from historic implementations. -.Pp -All archive output is written in correctly-sized blocks, even -if the output is being compressed. -Whether or not the last output block is padded to a full -block size varies depending on the format and the -output device. -For tar and cpio formats, the last block of output is padded -to a full block size if the output is being -written to standard output or to a character or block device such as -a tape drive. -If the output is being written to a regular file, the last block -will not be padded. -Many compressors, including -.Xr gzip 1 -and -.Xr bzip2 1 , -complain about the null padding when decompressing an archive created by -.Nm , -although they still extract it correctly. -.Pp -The compression and decompression is implemented internally, so -there may be insignificant differences between the compressed output -generated by -.Dl Nm Fl czf Pa - file -and that generated by -.Dl Nm Fl cf Pa - file | Nm gzip -.Pp -The default should be to read and write archives to the standard I/O paths, -but tradition (and POSIX) dictates otherwise. -.Pp -The -.Cm r -and -.Cm u -modes require that the archive be uncompressed -and located in a regular file on disk. -Other archives can be modified using -.Cm c -mode with the -.Pa @archive-file -extension. -.Pp -To archive a file called -.Pa @foo -or -.Pa -foo -you must specify it as -.Pa ./@foo -or -.Pa ./-foo , -respectively. -.Pp -In create mode, a leading -.Pa ./ -is always removed. -A leading -.Pa / -is stripped unless the -.Fl P -option is specified. -.Pp -There needs to be better support for file selection on both create -and extract. -.Pp -There is not yet any support for multi-volume archives or for archiving -sparse files. -.Pp -Converting between dissimilar archive formats (such as tar and cpio) using the -.Cm @ Ns Pa - -convention can cause hard link information to be lost. -(This is a consequence of the incompatible ways that different archive -formats store hardlink information.) -.Pp -There are alternative long options for many of the short options that -are deliberately not documented. diff --git a/Utilities/cmlibarchive/tar/bsdtar.c b/Utilities/cmlibarchive/tar/bsdtar.c deleted file mode 100644 index 35f6bc67d..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar.c +++ /dev/null @@ -1,730 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/bsdtar.c,v 1.93 2008/11/08 04:43:24 kientzle Exp $"); - -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_LANGINFO_H -#include -#endif -#ifdef HAVE_LOCALE_H -#include -#endif -#ifdef HAVE_PATHS_H -#include -#endif -#ifdef HAVE_SIGNAL_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_TIME_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#if HAVE_ZLIB_H -#include -#endif - -#include "bsdtar.h" -#include "err.h" - -/* - * Per POSIX.1-1988, tar defaults to reading/writing archives to/from - * the default tape device for the system. Pick something reasonable here. - */ -#ifdef __linux -#define _PATH_DEFTAPE "/dev/st0" -#endif -#if defined(_WIN32) && !defined(__CYGWIN__) -#define _PATH_DEFTAPE "\\\\.\\tape0" -#endif - -#ifndef _PATH_DEFTAPE -#define _PATH_DEFTAPE "/dev/tape" -#endif - -static struct bsdtar *_bsdtar; - -#if defined(SIGINFO) || defined(SIGUSR1) -static volatile int siginfo_occurred; - -static void -siginfo_handler(int sig) -{ - (void)sig; /* UNUSED */ - siginfo_occurred = 1; -} - -int -need_report(void) -{ - int r = siginfo_occurred; - siginfo_occurred = 0; - return (r); -} -#else -int -need_report(void) -{ - return (0); -} -#endif - -/* External function to parse a date/time string */ -time_t get_date(time_t, const char *); - -static void long_help(void); -static void only_mode(struct bsdtar *, const char *opt, - const char *valid); -static void set_mode(struct bsdtar *, char opt); -static void version(void); - -/* A basic set of security flags to request from libarchive. */ -#define SECURITY \ - (ARCHIVE_EXTRACT_SECURE_SYMLINKS \ - | ARCHIVE_EXTRACT_SECURE_NODOTDOT) - -int -main(int argc, char **argv) -{ - struct bsdtar *bsdtar, bsdtar_storage; - int opt, t; - char option_o; - char possible_help_request; - char buff[16]; - time_t now; - - /* - * Use a pointer for consistency, but stack-allocated storage - * for ease of cleanup. - */ - _bsdtar = bsdtar = &bsdtar_storage; - memset(bsdtar, 0, sizeof(*bsdtar)); - bsdtar->fd = -1; /* Mark as "unused" */ - option_o = 0; - -#if defined(SIGINFO) || defined(SIGUSR1) - { /* Catch SIGINFO and SIGUSR1, if they exist. */ - struct sigaction sa; - sa.sa_handler = siginfo_handler; - sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; -#ifdef SIGINFO - if (sigaction(SIGINFO, &sa, NULL)) - lafe_errc(1, errno, "sigaction(SIGINFO) failed"); -#endif -#ifdef SIGUSR1 - /* ... and treat SIGUSR1 the same way as SIGINFO. */ - if (sigaction(SIGUSR1, &sa, NULL)) - lafe_errc(1, errno, "sigaction(SIGUSR1) failed"); -#endif - } -#endif - - - /* Need lafe_progname before calling lafe_warnc. */ - if (*argv == NULL) - lafe_progname = "bsdtar"; - else { -#if defined(_WIN32) && !defined(__CYGWIN__) - lafe_progname = strrchr(*argv, '\\'); -#else - lafe_progname = strrchr(*argv, '/'); -#endif - if (lafe_progname != NULL) - lafe_progname++; - else - lafe_progname = *argv; - } - - time(&now); - -#if HAVE_SETLOCALE - if (setlocale(LC_ALL, "") == NULL) - lafe_warnc(0, "Failed to set default locale"); -#endif -#if defined(HAVE_NL_LANGINFO) && defined(HAVE_D_MD_ORDER) - bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd'); -#endif - possible_help_request = 0; - - /* Look up uid of current user for future reference */ - bsdtar->user_uid = geteuid(); - - /* Default: open tape drive. */ - bsdtar->filename = getenv("TAPE"); - if (bsdtar->filename == NULL) - bsdtar->filename = _PATH_DEFTAPE; - - /* Default: preserve mod time on extract */ - bsdtar->extract_flags = ARCHIVE_EXTRACT_TIME; - - /* Default: Perform basic security checks. */ - bsdtar->extract_flags |= SECURITY; - -#ifndef _WIN32 - /* On POSIX systems, assume --same-owner and -p when run by - * the root user. This doesn't make any sense on Windows. */ - if (bsdtar->user_uid == 0) { - /* --same-owner */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; - /* -p */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; - } -#endif - - bsdtar->argv = argv; - bsdtar->argc = argc; - - /* - * Comments following each option indicate where that option - * originated: SUSv2, POSIX, GNU tar, star, etc. If there's - * no such comment, then I don't know of anyone else who - * implements that option. - */ - while ((opt = bsdtar_getopt(bsdtar)) != -1) { - switch (opt) { - case 'B': /* GNU tar */ - /* libarchive doesn't need this; just ignore it. */ - break; - case 'b': /* SUSv2 */ - t = atoi(bsdtar->optarg); - if (t <= 0 || t > 1024) - lafe_errc(1, 0, - "Argument to -b is out of range (1..1024)"); - bsdtar->bytes_per_block = 512 * t; - break; - case 'C': /* GNU tar */ - set_chdir(bsdtar, bsdtar->optarg); - break; - case 'c': /* SUSv2 */ - set_mode(bsdtar, opt); - break; - case OPTION_CHECK_LINKS: /* GNU tar */ - bsdtar->option_warn_links = 1; - break; - case OPTION_CHROOT: /* NetBSD */ - bsdtar->option_chroot = 1; - break; - case OPTION_EXCLUDE: /* GNU tar */ - if (lafe_exclude(&bsdtar->matching, bsdtar->optarg)) - lafe_errc(1, 0, - "Couldn't exclude %s\n", bsdtar->optarg); - break; - case OPTION_FORMAT: /* GNU tar, others */ - bsdtar->create_format = bsdtar->optarg; - break; - case OPTION_OPTIONS: - bsdtar->option_options = bsdtar->optarg; - break; - case 'f': /* SUSv2 */ - bsdtar->filename = bsdtar->optarg; - if (strcmp(bsdtar->filename, "-") == 0) - bsdtar->filename = NULL; - break; - case 'H': /* BSD convention */ - bsdtar->symlink_mode = 'H'; - break; - case 'h': /* Linux Standards Base, gtar; synonym for -L */ - bsdtar->symlink_mode = 'L'; - /* Hack: -h by itself is the "help" command. */ - possible_help_request = 1; - break; - case OPTION_HELP: /* GNU tar, others */ - long_help(); - exit(0); - break; - case 'I': /* GNU tar */ - /* - * TODO: Allow 'names' to come from an archive, - * not just a text file. Design a good UI for - * allowing names and mode/owner to be read - * from an archive, with contents coming from - * disk. This can be used to "refresh" an - * archive or to design archives with special - * permissions without having to create those - * permissions on disk. - */ - bsdtar->names_from_file = bsdtar->optarg; - break; - case OPTION_INCLUDE: - /* - * Noone else has the @archive extension, so - * noone else needs this to filter entries - * when transforming archives. - */ - if (lafe_include(&bsdtar->matching, bsdtar->optarg)) - lafe_errc(1, 0, - "Failed to add %s to inclusion list", - bsdtar->optarg); - break; - case 'j': /* GNU tar */ - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case 'J': /* GNU tar 1.21 and later */ - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case 'k': /* GNU tar */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE; - break; - case OPTION_KEEP_NEWER_FILES: /* GNU tar */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER; - break; - case 'L': /* BSD convention */ - bsdtar->symlink_mode = 'L'; - break; - case 'l': /* SUSv2 and GNU tar beginning with 1.16 */ - /* GNU tar 1.13 used -l for --one-file-system */ - bsdtar->option_warn_links = 1; - break; - case OPTION_LZMA: - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case 'm': /* SUSv2 */ - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_TIME; - break; - case 'n': /* GNU tar */ - bsdtar->option_no_subdirs = 1; - break; - /* - * Selecting files by time: - * --newer-?time='date' Only files newer than 'date' - * --newer-?time-than='file' Only files newer than time - * on specified file (useful for incremental backups) - * TODO: Add corresponding "older" options to reverse these. - */ - case OPTION_NEWER_CTIME: /* GNU tar */ - bsdtar->newer_ctime_sec = get_date(now, bsdtar->optarg); - break; - case OPTION_NEWER_CTIME_THAN: - { - struct stat st; - if (stat(bsdtar->optarg, &st) != 0) - lafe_errc(1, 0, - "Can't open file %s", bsdtar->optarg); - bsdtar->newer_ctime_sec = st.st_ctime; - bsdtar->newer_ctime_nsec = - ARCHIVE_STAT_CTIME_NANOS(&st); - } - break; - case OPTION_NEWER_MTIME: /* GNU tar */ - bsdtar->newer_mtime_sec = get_date(now, bsdtar->optarg); - break; - case OPTION_NEWER_MTIME_THAN: - { - struct stat st; - if (stat(bsdtar->optarg, &st) != 0) - lafe_errc(1, 0, - "Can't open file %s", bsdtar->optarg); - bsdtar->newer_mtime_sec = st.st_mtime; - bsdtar->newer_mtime_nsec = - ARCHIVE_STAT_MTIME_NANOS(&st); - } - break; - case OPTION_NODUMP: /* star */ - bsdtar->option_honor_nodump = 1; - break; - case OPTION_NO_SAME_OWNER: /* GNU tar */ - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; - break; - case OPTION_NO_SAME_PERMISSIONS: /* GNU tar */ - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_PERM; - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_ACL; - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_XATTR; - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_FFLAGS; - break; - case OPTION_NULL: /* GNU tar */ - bsdtar->option_null++; - break; - case OPTION_NUMERIC_OWNER: /* GNU tar */ - bsdtar->option_numeric_owner++; - break; - case 'O': /* GNU tar */ - bsdtar->option_stdout = 1; - break; - case 'o': /* SUSv2 and GNU conflict here, but not fatally */ - option_o = 1; /* Record it and resolve it later. */ - break; - case OPTION_ONE_FILE_SYSTEM: /* GNU tar */ - bsdtar->option_dont_traverse_mounts = 1; - break; -#if 0 - /* - * The common BSD -P option is not necessary, since - * our default is to archive symlinks, not follow - * them. This is convenient, as -P conflicts with GNU - * tar anyway. - */ - case 'P': /* BSD convention */ - /* Default behavior, no option necessary. */ - break; -#endif - case 'P': /* GNU tar */ - bsdtar->extract_flags &= ~SECURITY; - bsdtar->option_absolute_paths = 1; - break; - case 'p': /* GNU tar, star */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_PERM; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_ACL; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_XATTR; - bsdtar->extract_flags |= ARCHIVE_EXTRACT_FFLAGS; - break; - case OPTION_POSIX: /* GNU tar */ - bsdtar->create_format = "pax"; - break; - case 'q': /* FreeBSD GNU tar --fast-read, NetBSD -q */ - bsdtar->option_fast_read = 1; - break; - case 'r': /* SUSv2 */ - set_mode(bsdtar, opt); - break; - case 'S': /* NetBSD pax-as-tar */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_SPARSE; - break; - case 's': /* NetBSD pax-as-tar */ -#if HAVE_REGEX_H - add_substitution(bsdtar, bsdtar->optarg); -#else - lafe_warnc(0, - "-s is not supported by this version of bsdtar"); - usage(); -#endif - break; - case OPTION_SAME_OWNER: /* GNU tar */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_OWNER; - break; - case OPTION_STRIP_COMPONENTS: /* GNU tar 1.15 */ - bsdtar->strip_components = atoi(bsdtar->optarg); - break; - case 'T': /* GNU tar */ - bsdtar->names_from_file = bsdtar->optarg; - break; - case 't': /* SUSv2 */ - set_mode(bsdtar, opt); - bsdtar->verbose++; - break; - case OPTION_TOTALS: /* GNU tar */ - bsdtar->option_totals++; - break; - case 'U': /* GNU tar */ - bsdtar->extract_flags |= ARCHIVE_EXTRACT_UNLINK; - bsdtar->option_unlink_first = 1; - break; - case 'u': /* SUSv2 */ - set_mode(bsdtar, opt); - break; - case 'v': /* SUSv2 */ - bsdtar->verbose++; - break; - case OPTION_VERSION: /* GNU convention */ - version(); - break; -#if 0 - /* - * The -W longopt feature is handled inside of - * bsdtar_getopt(), so -W is not available here. - */ - case 'W': /* Obscure GNU convention. */ - break; -#endif - case 'w': /* SUSv2 */ - bsdtar->option_interactive = 1; - break; - case 'X': /* GNU tar */ - if (lafe_exclude_from_file(&bsdtar->matching, bsdtar->optarg)) - lafe_errc(1, 0, - "failed to process exclusions from file %s", - bsdtar->optarg); - break; - case 'x': /* SUSv2 */ - set_mode(bsdtar, opt); - break; - case 'y': /* FreeBSD version of GNU tar */ - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case 'Z': /* GNU tar */ - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case 'z': /* GNU tar, star, many others */ - if (bsdtar->create_compression != '\0') - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, - bsdtar->create_compression); - bsdtar->create_compression = opt; - break; - case OPTION_USE_COMPRESS_PROGRAM: - bsdtar->compress_program = bsdtar->optarg; - break; - default: - usage(); - } - } - - /* - * Sanity-check options. - */ - - /* If no "real" mode was specified, treat -h as --help. */ - if ((bsdtar->mode == '\0') && possible_help_request) { - long_help(); - exit(0); - } - - /* Otherwise, a mode is required. */ - if (bsdtar->mode == '\0') - lafe_errc(1, 0, - "Must specify one of -c, -r, -t, -u, -x"); - - /* Check boolean options only permitted in certain modes. */ - if (bsdtar->option_dont_traverse_mounts) - only_mode(bsdtar, "--one-file-system", "cru"); - if (bsdtar->option_fast_read) - only_mode(bsdtar, "--fast-read", "xt"); - if (bsdtar->option_honor_nodump) - only_mode(bsdtar, "--nodump", "cru"); - if (option_o > 0) { - switch (bsdtar->mode) { - case 'c': - /* - * In GNU tar, -o means "old format." The - * "ustar" format is the closest thing - * supported by libarchive. - */ - bsdtar->create_format = "ustar"; - /* TODO: bsdtar->create_format = "v7"; */ - break; - case 'x': - /* POSIX-compatible behavior. */ - bsdtar->option_no_owner = 1; - bsdtar->extract_flags &= ~ARCHIVE_EXTRACT_OWNER; - break; - default: - only_mode(bsdtar, "-o", "xc"); - break; - } - } - if (bsdtar->option_no_subdirs) - only_mode(bsdtar, "-n", "cru"); - if (bsdtar->option_stdout) - only_mode(bsdtar, "-O", "xt"); - if (bsdtar->option_unlink_first) - only_mode(bsdtar, "-U", "x"); - if (bsdtar->option_warn_links) - only_mode(bsdtar, "--check-links", "cr"); - - /* Check other parameters only permitted in certain modes. */ - if (bsdtar->create_compression != '\0') { - strcpy(buff, "-?"); - buff[1] = bsdtar->create_compression; - only_mode(bsdtar, buff, "cxt"); - } - if (bsdtar->create_format != NULL) - only_mode(bsdtar, "--format", "cru"); - if (bsdtar->symlink_mode != '\0') { - strcpy(buff, "-?"); - buff[1] = bsdtar->symlink_mode; - only_mode(bsdtar, buff, "cru"); - } - if (bsdtar->strip_components != 0) - only_mode(bsdtar, "--strip-components", "xt"); - - switch(bsdtar->mode) { - case 'c': - tar_mode_c(bsdtar); - break; - case 'r': - tar_mode_r(bsdtar); - break; - case 't': - tar_mode_t(bsdtar); - break; - case 'u': - tar_mode_u(bsdtar); - break; - case 'x': - tar_mode_x(bsdtar); - break; - } - - lafe_cleanup_exclusions(&bsdtar->matching); -#if HAVE_REGEX_H - cleanup_substitution(bsdtar); -#endif - - if (bsdtar->return_value != 0) - lafe_warnc(0, - "Error exit delayed from previous errors."); - return (bsdtar->return_value); -} - -static void -set_mode(struct bsdtar *bsdtar, char opt) -{ - if (bsdtar->mode != '\0' && bsdtar->mode != opt) - lafe_errc(1, 0, - "Can't specify both -%c and -%c", opt, bsdtar->mode); - bsdtar->mode = opt; -} - -/* - * Verify that the mode is correct. - */ -static void -only_mode(struct bsdtar *bsdtar, const char *opt, const char *valid_modes) -{ - if (strchr(valid_modes, bsdtar->mode) == NULL) - lafe_errc(1, 0, - "Option %s is not permitted in mode -%c", - opt, bsdtar->mode); -} - - -void -usage(void) -{ - const char *p; - - p = lafe_progname; - - fprintf(stderr, "Usage:\n"); - fprintf(stderr, " List: %s -tf \n", p); - fprintf(stderr, " Extract: %s -xf \n", p); - fprintf(stderr, " Create: %s -cf [filenames...]\n", p); - fprintf(stderr, " Help: %s --help\n", p); - exit(1); -} - -static void -version(void) -{ - printf("bsdtar %s - %s\n", - BSDTAR_VERSION_STRING, - archive_version()); - exit(0); -} - -static const char *long_help_msg = - "First option must be a mode specifier:\n" - " -c Create -r Add/Replace -t List -u Update -x Extract\n" - "Common Options:\n" - " -b # Use # 512-byte records per I/O block\n" - " -f Location of archive (default " _PATH_DEFTAPE ")\n" - " -v Verbose\n" - " -w Interactive\n" - "Create: %p -c [options] [ | | @ | -C ]\n" - " , add these items to archive\n" - " -z, -j, -J, --lzma Compress archive with gzip/bzip2/xz/lzma\n" - " --format {ustar|pax|cpio|shar} Select archive format\n" - " --exclude Skip files that match pattern\n" - " -C Change to before processing remaining files\n" - " @ Add entries from to output\n" - "List: %p -t [options] []\n" - " If specified, list only entries that match\n" - "Extract: %p -x [options] []\n" - " If specified, extract only entries that match\n" - " -k Keep (don't overwrite) existing files\n" - " -m Don't restore modification times\n" - " -O Write entries to stdout, don't restore to disk\n" - " -p Restore permissions (including ACLs, owner, file flags)\n"; - - -/* - * Note that the word 'bsdtar' will always appear in the first line - * of output. - * - * In particular, /bin/sh scripts that need to test for the presence - * of bsdtar can use the following template: - * - * if (tar --help 2>&1 | grep bsdtar >/dev/null 2>&1 ) then \ - * echo bsdtar; else echo not bsdtar; fi - */ -static void -long_help(void) -{ - const char *prog; - const char *p; - - prog = lafe_progname; - - fflush(stderr); - - p = (strcmp(prog,"bsdtar") != 0) ? "(bsdtar)" : ""; - printf("%s%s: manipulate archive files\n", prog, p); - - for (p = long_help_msg; *p != '\0'; p++) { - if (*p == '%') { - if (p[1] == 'p') { - fputs(prog, stdout); - p++; - } else - putchar('%'); - } else - putchar(*p); - } - version(); -} diff --git a/Utilities/cmlibarchive/tar/bsdtar.h b/Utilities/cmlibarchive/tar/bsdtar.h deleted file mode 100644 index 9dfe843d6..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar.h +++ /dev/null @@ -1,157 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $ - */ - -#include "bsdtar_platform.h" -#include - -#include "matching.h" - -#define DEFAULT_BYTES_PER_BLOCK (20*512) - -/* - * The internal state for the "bsdtar" program. - * - * Keeping all of the state in a structure like this simplifies memory - * leak testing (at exit, anything left on the heap is suspect). A - * pointer to this structure is passed to most bsdtar internal - * functions. - */ -struct bsdtar { - /* Options */ - const char *filename; /* -f filename */ - const char *create_format; /* -F format */ - char *pending_chdir; /* -C dir */ - const char *names_from_file; /* -T file */ - time_t newer_ctime_sec; /* --newer/--newer-than */ - long newer_ctime_nsec; /* --newer/--newer-than */ - time_t newer_mtime_sec; /* --newer-mtime */ - long newer_mtime_nsec; /* --newer-mtime-than */ - int bytes_per_block; /* -b block_size */ - int verbose; /* -v */ - int extract_flags; /* Flags for extract operation */ - int strip_components; /* Remove this many leading dirs */ - char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ - char symlink_mode; /* H or L, per BSD conventions */ - char create_compression; /* j, y, or z */ - const char *compress_program; - char option_absolute_paths; /* -P */ - char option_chroot; /* --chroot */ - char option_dont_traverse_mounts; /* --one-file-system */ - char option_fast_read; /* --fast-read */ - const char *option_options; /* --options */ - char option_honor_nodump; /* --nodump */ - char option_interactive; /* -w */ - char option_no_owner; /* -o */ - char option_no_subdirs; /* -n */ - char option_null; /* --null */ - char option_numeric_owner; /* --numeric-owner */ - char option_stdout; /* -O */ - char option_totals; /* --totals */ - char option_unlink_first; /* -U */ - char option_warn_links; /* --check-links */ - char day_first; /* show day before month in -tv output */ - - /* If >= 0, then close this when done. */ - int fd; - - /* Miscellaneous state information */ - int argc; - char **argv; - const char *optarg; - size_t gs_width; /* For 'list_item' in read.c */ - size_t u_width; /* for 'list_item' in read.c */ - uid_t user_uid; /* UID running this program */ - int return_value; /* Value returned by main() */ - char warned_lead_slash; /* Already displayed warning */ - char next_line_is_dir; /* Used for -C parsing in -cT */ - - /* - * Data for various subsystems. Full definitions are located in - * the file where they are used. - */ - struct archive *diskreader; /* for write.c */ - struct archive_entry_linkresolver *resolver; /* for write.c */ - struct archive_dir *archive_dir; /* for write.c */ - struct name_cache *gname_cache; /* for write.c */ - char *buff; /* for write.c */ - struct lafe_matching *matching; /* for matching.c */ - struct security *security; /* for read.c */ - struct name_cache *uname_cache; /* for write.c */ - struct siginfo_data *siginfo; /* for siginfo.c */ - struct substitution *substitution; /* for subst.c */ -}; - -/* Fake short equivalents for long options that otherwise lack them. */ -enum { - OPTION_CHECK_LINKS = 1, - OPTION_CHROOT, - OPTION_EXCLUDE, - OPTION_FORMAT, - OPTION_OPTIONS, - OPTION_HELP, - OPTION_INCLUDE, - OPTION_KEEP_NEWER_FILES, - OPTION_LZMA, - OPTION_NEWER_CTIME, - OPTION_NEWER_CTIME_THAN, - OPTION_NEWER_MTIME, - OPTION_NEWER_MTIME_THAN, - OPTION_NODUMP, - OPTION_NO_SAME_OWNER, - OPTION_NO_SAME_PERMISSIONS, - OPTION_NULL, - OPTION_NUMERIC_OWNER, - OPTION_ONE_FILE_SYSTEM, - OPTION_POSIX, - OPTION_SAME_OWNER, - OPTION_STRIP_COMPONENTS, - OPTION_TOTALS, - OPTION_USE_COMPRESS_PROGRAM, - OPTION_VERSION -}; - - -int bsdtar_getopt(struct bsdtar *); -void do_chdir(struct bsdtar *); -int edit_pathname(struct bsdtar *, struct archive_entry *); -int need_report(void); -int pathcmp(const char *a, const char *b); -void safe_fprintf(FILE *, const char *fmt, ...); -void set_chdir(struct bsdtar *, const char *newdir); -void tar_mode_c(struct bsdtar *bsdtar); -void tar_mode_r(struct bsdtar *bsdtar); -void tar_mode_t(struct bsdtar *bsdtar); -void tar_mode_u(struct bsdtar *bsdtar); -void tar_mode_x(struct bsdtar *bsdtar); -void usage(void); -int yes(const char *fmt, ...); - -#if HAVE_REGEX_H -void add_substitution(struct bsdtar *, const char *); -int apply_substitution(struct bsdtar *, const char *, char **, int); -void cleanup_substitution(struct bsdtar *); -#endif diff --git a/Utilities/cmlibarchive/tar/bsdtar_platform.h b/Utilities/cmlibarchive/tar/bsdtar_platform.h deleted file mode 100644 index b532f04ed..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar_platform.h +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/tar/bsdtar_platform.h,v 1.26 2008/12/06 07:37:14 kientzle Exp $ - */ - -/* - * This header is the first thing included in any of the bsdtar - * source files. As far as possible, platform-specific issues should - * be dealt with here and not within individual source files. - */ - -#ifndef BSDTAR_PLATFORM_H_INCLUDED -#define BSDTAR_PLATFORM_H_INCLUDED - -#if defined(PLATFORM_CONFIG_H) -/* Use hand-built config.h in environments that need it. */ -#include PLATFORM_CONFIG_H -#else -/* Not having a config.h of some sort is a serious problem. */ -#include "config.h" -#endif - -/* No non-FreeBSD platform will have __FBSDID, so just define it here. */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Just leaving this macro replacement empty leads to a dangling semicolon. */ -#define __FBSDID(a) struct _undefined_hack -#endif - -#ifdef HAVE_LIBARCHIVE -/* If we're using the platform libarchive, include system headers. */ -#include -#include -#else -/* Otherwise, include user headers. */ -#include "archive.h" -#include "archive_entry.h" -#endif - -#ifdef HAVE_LIBACL -#include -#endif - -/* - * Include "dirent.h" (or it's equivalent on several different platforms). - * - * This is slightly modified from the GNU autoconf recipe. - * In particular, FreeBSD includes d_namlen in it's dirent structure, - * so my configure script includes an explicit test for the d_namlen - * field. - */ -#if HAVE_DIRENT_H -# include -# if HAVE_DIRENT_D_NAMLEN -# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen -# else -# define DIRENT_NAMLEN(dirent) strlen((dirent)->d_name) -# endif -#else -# define dirent direct -# define DIRENT_NAMLEN(dirent) (dirent)->d_namlen -# if HAVE_SYS_NDIR_H -# include -# endif -# if HAVE_SYS_DIR_H -# include -# endif -# if HAVE_NDIR_H -# include -# endif -#endif - - -/* - * We need to be able to display a filesize using printf(). The type - * and format string here must be compatible with one another and - * large enough for any file. - */ -#if HAVE_UINTMAX_T -#define BSDTAR_FILESIZE_TYPE uintmax_t -#define BSDTAR_FILESIZE_PRINTF "%ju" -#else -#if HAVE_UNSIGNED_LONG_LONG -#define BSDTAR_FILESIZE_TYPE unsigned long long -#define BSDTAR_FILESIZE_PRINTF "%llu" -#else -#define BSDTAR_FILESIZE_TYPE unsigned long -#define BSDTAR_FILESIZE_PRINTF "%lu" -#endif -#endif - -#if HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC -#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctimespec.tv_nsec -#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec -#elif HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC -#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctim.tv_nsec -#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtim.tv_nsec -#elif HAVE_STRUCT_STAT_ST_MTIME_N -#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_n -#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_n -#elif HAVE_STRUCT_STAT_ST_UMTIME -#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_uctime * 1000 -#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_umtime * 1000 -#elif HAVE_STRUCT_STAT_ST_MTIME_USEC -#define ARCHIVE_STAT_CTIME_NANOS(st) (st)->st_ctime_usec * 1000 -#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtime_usec * 1000 -#else -#define ARCHIVE_STAT_CTIME_NANOS(st) (0) -#define ARCHIVE_STAT_MTIME_NANOS(st) (0) -#endif - -/* How to mark functions that don't return. */ -/* This facilitates use of some newer static code analysis tools. */ -#undef __LA_DEAD -#if defined(__GNUC__) && (__GNUC__ > 2 || \ - (__GNUC__ == 2 && __GNUC_MINOR__ >= 5)) -#define __LA_DEAD __attribute__((__noreturn__)) -#else -#define __LA_DEAD -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -#include "bsdtar_windows.h" -#endif - -#endif /* !BSDTAR_PLATFORM_H_INCLUDED */ diff --git a/Utilities/cmlibarchive/tar/bsdtar_windows.c b/Utilities/cmlibarchive/tar/bsdtar_windows.c deleted file mode 100644 index 1c8008e7e..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar_windows.c +++ /dev/null @@ -1,296 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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. - * - * $FreeBSD$ - */ - -#if defined(_WIN32) && !defined(__CYGWIN__) - -#include "bsdtar_platform.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bsdtar.h" -#include "err.h" - -/* This may actually not be needed anymore. - * TODO: Review the error handling for chdir() failures and - * simply dump this if it's not really needed. */ -static void __tar_dosmaperr(unsigned long); - -/* - * Prepend "\\?\" to the path name and convert it to unicode to permit - * an extended-length path for a maximum total path length of 32767 - * characters. - * see also http://msdn.microsoft.com/en-us/library/aa365247.aspx - */ -static wchar_t * -permissive_name(const char *name) -{ - wchar_t *wn, *wnp; - wchar_t *ws, *wsp; - size_t l, len, slen, alloclen; - int unc; - - len = strlen(name); - wn = malloc((len + 1) * sizeof(wchar_t)); - if (wn == NULL) - return (NULL); - l = MultiByteToWideChar(CP_ACP, 0, name, len, wn, len); - if (l == 0) { - free(wn); - return (NULL); - } - wn[l] = L'\0'; - - /* Get a full path names */ - l = GetFullPathNameW(wn, 0, NULL, NULL); - if (l == 0) { - free(wn); - return (NULL); - } - wnp = malloc(l * sizeof(wchar_t)); - if (wnp == NULL) { - free(wn); - return (NULL); - } - len = GetFullPathNameW(wn, l, wnp, NULL); - free(wn); - wn = wnp; - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'?' && wnp[3] == L'\\') - /* We have already permissive names. */ - return (wn); - - if (wnp[0] == L'\\' && wnp[1] == L'\\' && - wnp[2] == L'.' && wnp[3] == L'\\') { - /* Device names */ - if (((wnp[4] >= L'a' && wnp[4] <= L'z') || - (wnp[4] >= L'A' && wnp[4] <= L'Z')) && - wnp[5] == L':' && wnp[6] == L'\\') - wnp[2] = L'?';/* Not device names. */ - return (wn); - } - - unc = 0; - if (wnp[0] == L'\\' && wnp[1] == L'\\' && wnp[2] != L'\\') { - wchar_t *p = &wnp[2]; - - /* Skip server-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\') { - wchar_t *rp = ++p; - /* Skip share-name letters. */ - while (*p != L'\\' && *p != L'\0') - ++p; - if (*p == L'\\' && p != rp) { - /* Now, match patterns such as - * "\\server-name\share-name\" */ - wnp += 2; - len -= 2; - unc = 1; - } - } - } - - alloclen = slen = 4 + (unc * 4) + len + 1; - ws = wsp = malloc(slen * sizeof(wchar_t)); - if (ws == NULL) { - free(wn); - return (NULL); - } - /* prepend "\\?\" */ - wcsncpy(wsp, L"\\\\?\\", 4); - wsp += 4; - slen -= 4; - if (unc) { - /* append "UNC\" ---> "\\?\UNC\" */ - wcsncpy(wsp, L"UNC\\", 4); - wsp += 4; - slen -= 4; - } - wcsncpy(wsp, wnp, slen); - free(wn); - ws[alloclen - 1] = L'\0'; - return (ws); -} - -int -__tar_chdir(const char *path) -{ - wchar_t *ws; - int r; - - r = SetCurrentDirectoryA(path); - if (r == 0) { - if (GetLastError() != ERROR_FILE_NOT_FOUND) { - __tar_dosmaperr(GetLastError()); - return (-1); - } - } else - return (0); - ws = permissive_name(path); - if (ws == NULL) { - errno = EINVAL; - return (-1); - } - r = SetCurrentDirectoryW(ws); - free(ws); - if (r == 0) { - __tar_dosmaperr(GetLastError()); - return (-1); - } - return (0); -} - -/* - * The following function was modified from PostgreSQL sources and is - * subject to the copyright below. - */ -/*------------------------------------------------------------------------- - * - * win32error.c - * Map win32 error codes to errno values - * - * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group - * - * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/win32error.c,v 1.4 2008/01/01 19:46:00 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -/* -PostgreSQL Database Management System -(formerly known as Postgres, then as Postgres95) - -Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group - -Portions Copyright (c) 1994, The Regents of the University of California - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose, without fee, and without a written agreement -is hereby granted, provided that the above copyright notice and this -paragraph and the following two paragraphs appear in all copies. - -IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR -DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING -LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS -DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS -ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO -PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -*/ - -static const struct { - DWORD winerr; - int doserr; -} doserrors[] = -{ - { ERROR_INVALID_FUNCTION, EINVAL }, - { ERROR_FILE_NOT_FOUND, ENOENT }, - { ERROR_PATH_NOT_FOUND, ENOENT }, - { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, - { ERROR_ACCESS_DENIED, EACCES }, - { ERROR_INVALID_HANDLE, EBADF }, - { ERROR_ARENA_TRASHED, ENOMEM }, - { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, - { ERROR_INVALID_BLOCK, ENOMEM }, - { ERROR_BAD_ENVIRONMENT, E2BIG }, - { ERROR_BAD_FORMAT, ENOEXEC }, - { ERROR_INVALID_ACCESS, EINVAL }, - { ERROR_INVALID_DATA, EINVAL }, - { ERROR_INVALID_DRIVE, ENOENT }, - { ERROR_CURRENT_DIRECTORY, EACCES }, - { ERROR_NOT_SAME_DEVICE, EXDEV }, - { ERROR_NO_MORE_FILES, ENOENT }, - { ERROR_LOCK_VIOLATION, EACCES }, - { ERROR_SHARING_VIOLATION, EACCES }, - { ERROR_BAD_NETPATH, ENOENT }, - { ERROR_NETWORK_ACCESS_DENIED, EACCES }, - { ERROR_BAD_NET_NAME, ENOENT }, - { ERROR_FILE_EXISTS, EEXIST }, - { ERROR_CANNOT_MAKE, EACCES }, - { ERROR_FAIL_I24, EACCES }, - { ERROR_INVALID_PARAMETER, EINVAL }, - { ERROR_NO_PROC_SLOTS, EAGAIN }, - { ERROR_DRIVE_LOCKED, EACCES }, - { ERROR_BROKEN_PIPE, EPIPE }, - { ERROR_DISK_FULL, ENOSPC }, - { ERROR_INVALID_TARGET_HANDLE, EBADF }, - { ERROR_INVALID_HANDLE, EINVAL }, - { ERROR_WAIT_NO_CHILDREN, ECHILD }, - { ERROR_CHILD_NOT_COMPLETE, ECHILD }, - { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, - { ERROR_NEGATIVE_SEEK, EINVAL }, - { ERROR_SEEK_ON_DEVICE, EACCES }, - { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, - { ERROR_NOT_LOCKED, EACCES }, - { ERROR_BAD_PATHNAME, ENOENT }, - { ERROR_MAX_THRDS_REACHED, EAGAIN }, - { ERROR_LOCK_FAILED, EACCES }, - { ERROR_ALREADY_EXISTS, EEXIST }, - { ERROR_FILENAME_EXCED_RANGE, ENOENT }, - { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, - { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } -}; - -static void -__tar_dosmaperr(unsigned long e) -{ - int i; - - if (e == 0) { - errno = 0; - return; - } - - for (i = 0; i < sizeof(doserrors); i++) { - if (doserrors[i].winerr == e) { - errno = doserrors[i].doserr; - return; - } - } - - /* fprintf(stderr, "unrecognized win32 error code: %lu", e); */ - errno = EINVAL; - return; -} - -#endif diff --git a/Utilities/cmlibarchive/tar/bsdtar_windows.h b/Utilities/cmlibarchive/tar/bsdtar_windows.h deleted file mode 100644 index 9761d4872..000000000 --- a/Utilities/cmlibarchive/tar/bsdtar_windows.h +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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. - * - * $FreeBSD$ - */ - -#ifndef BSDTAR_WINDOWS_H -#define BSDTAR_WINDOWS_H 1 -#include -#include - -#ifndef PRId64 -#define PRId64 "I64" -#endif -#define geteuid() 0 - -#ifndef S_IFIFO -#define S_IFIFO 0010000 /* pipe */ -#endif - -#include /* Must include before redefining 'strdup' */ -#define strdup _strdup -#define read _read -#define getcwd _getcwd - -#define chdir __tar_chdir -int __tar_chdir(const char *); - -#ifndef S_ISREG -#define S_ISREG(a) (a & _S_IFREG) -#endif -#ifndef S_ISBLK -#define S_ISBLK(a) (0) -#endif - -#endif /* BSDTAR_WINDOWS_H */ diff --git a/Utilities/cmlibarchive/tar/cmdline.c b/Utilities/cmlibarchive/tar/cmdline.c deleted file mode 100644 index 3a7ce372c..000000000 --- a/Utilities/cmlibarchive/tar/cmdline.c +++ /dev/null @@ -1,381 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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. - */ - -/* - * Command line parser for tar. - */ - -#include "bsdtar_platform.h" -__FBSDID("$FreeBSD$"); - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif - -#include "bsdtar.h" -#include "err.h" - -/* - * Short options for tar. Please keep this sorted. - */ -static const char *short_options - = "Bb:C:cf:HhI:JjkLlmnOoPpqrSs:T:tUuvW:wX:xyZz"; - -/* - * Long options for tar. Please keep this list sorted. - * - * The symbolic names for options that lack a short equivalent are - * defined in bsdtar.h. Also note that so far I've found no need - * to support optional arguments to long options. That would be - * a small change to the code below. - */ - -static struct option { - const char *name; - int required; /* 1 if this option requires an argument. */ - int equivalent; /* Equivalent short option. */ -} tar_longopts[] = { - { "absolute-paths", 0, 'P' }, - { "append", 0, 'r' }, - { "block-size", 1, 'b' }, - { "bunzip2", 0, 'j' }, - { "bzip", 0, 'j' }, - { "bzip2", 0, 'j' }, - { "cd", 1, 'C' }, - { "check-links", 0, OPTION_CHECK_LINKS }, - { "chroot", 0, OPTION_CHROOT }, - { "compress", 0, 'Z' }, - { "confirmation", 0, 'w' }, - { "create", 0, 'c' }, - { "dereference", 0, 'L' }, - { "directory", 1, 'C' }, - { "exclude", 1, OPTION_EXCLUDE }, - { "exclude-from", 1, 'X' }, - { "extract", 0, 'x' }, - { "fast-read", 0, 'q' }, - { "file", 1, 'f' }, - { "files-from", 1, 'T' }, - { "format", 1, OPTION_FORMAT }, - { "options", 1, OPTION_OPTIONS }, - { "gunzip", 0, 'z' }, - { "gzip", 0, 'z' }, - { "help", 0, OPTION_HELP }, - { "include", 1, OPTION_INCLUDE }, - { "interactive", 0, 'w' }, - { "insecure", 0, 'P' }, - { "keep-newer-files", 0, OPTION_KEEP_NEWER_FILES }, - { "keep-old-files", 0, 'k' }, - { "list", 0, 't' }, - { "lzma", 0, OPTION_LZMA }, - { "modification-time", 0, 'm' }, - { "newer", 1, OPTION_NEWER_CTIME }, - { "newer-ctime", 1, OPTION_NEWER_CTIME }, - { "newer-ctime-than", 1, OPTION_NEWER_CTIME_THAN }, - { "newer-mtime", 1, OPTION_NEWER_MTIME }, - { "newer-mtime-than", 1, OPTION_NEWER_MTIME_THAN }, - { "newer-than", 1, OPTION_NEWER_CTIME_THAN }, - { "nodump", 0, OPTION_NODUMP }, - { "norecurse", 0, 'n' }, - { "no-recursion", 0, 'n' }, - { "no-same-owner", 0, OPTION_NO_SAME_OWNER }, - { "no-same-permissions", 0, OPTION_NO_SAME_PERMISSIONS }, - { "null", 0, OPTION_NULL }, - { "numeric-owner", 0, OPTION_NUMERIC_OWNER }, - { "one-file-system", 0, OPTION_ONE_FILE_SYSTEM }, - { "posix", 0, OPTION_POSIX }, - { "preserve-permissions", 0, 'p' }, - { "read-full-blocks", 0, 'B' }, - { "same-owner", 0, OPTION_SAME_OWNER }, - { "same-permissions", 0, 'p' }, - { "strip-components", 1, OPTION_STRIP_COMPONENTS }, - { "to-stdout", 0, 'O' }, - { "totals", 0, OPTION_TOTALS }, - { "uncompress", 0, 'Z' }, - { "unlink", 0, 'U' }, - { "unlink-first", 0, 'U' }, - { "update", 0, 'u' }, - { "use-compress-program", 1, OPTION_USE_COMPRESS_PROGRAM }, - { "verbose", 0, 'v' }, - { "version", 0, OPTION_VERSION }, - { "xz", 0, 'J' }, - { NULL, 0, 0 } -}; - -/* - * This getopt implementation has two key features that common - * getopt_long() implementations lack. Apart from those, it's a - * straightforward option parser, considerably simplified by not - * needing to support the wealth of exotic getopt_long() features. It - * has, of course, been shamelessly tailored for bsdtar. (If you're - * looking for a generic getopt_long() implementation for your - * project, I recommend Gregory Pietsch's public domain getopt_long() - * implementation.) The two additional features are: - * - * Old-style tar arguments: The original tar implementation treated - * the first argument word as a list of single-character option - * letters. All arguments follow as separate words. For example, - * tar xbf 32 /dev/tape - * Here, the "xbf" is three option letters, "32" is the argument for - * "b" and "/dev/tape" is the argument for "f". We support this usage - * if the first command-line argument does not begin with '-'. We - * also allow regular short and long options to follow, e.g., - * tar xbf 32 /dev/tape -P --format=pax - * - * -W long options: There's an obscure GNU convention (only rarely - * supported even there) that allows "-W option=argument" as an - * alternative way to support long options. This was supported in - * early bsdtar as a way to access long options on platforms that did - * not support getopt_long() and is preserved here for backwards - * compatibility. (Of course, if I'd started with a custom - * command-line parser from the beginning, I would have had normal - * long option support on every platform so that hack wouldn't have - * been necessary. Oh, well. Some mistakes you just have to live - * with.) - * - * TODO: We should be able to use this to pull files and intermingled - * options (such as -C) from the command line in write mode. That - * will require a little rethinking of the argument handling in - * bsdtar.c. - * - * TODO: If we want to support arbitrary command-line options from -T - * input (as GNU tar does), we may need to extend this to handle option - * words from sources other than argv/arc. I'm not really sure if I - * like that feature of GNU tar, so it's certainly not a priority. - */ - -int -bsdtar_getopt(struct bsdtar *bsdtar) -{ - enum { state_start = 0, state_old_tar, state_next_word, - state_short, state_long }; - static int state = state_start; - static char *opt_word; - - const struct option *popt, *match = NULL, *match2 = NULL; - const char *p, *long_prefix = "--"; - size_t optlength; - int opt = '?'; - int required = 0; - - bsdtar->optarg = NULL; - - /* First time through, initialize everything. */ - if (state == state_start) { - /* Skip program name. */ - ++bsdtar->argv; - --bsdtar->argc; - if (*bsdtar->argv == NULL) - return (-1); - /* Decide between "new style" and "old style" arguments. */ - if (bsdtar->argv[0][0] == '-') { - state = state_next_word; - } else { - state = state_old_tar; - opt_word = *bsdtar->argv++; - --bsdtar->argc; - } - } - - /* - * We're parsing old-style tar arguments - */ - if (state == state_old_tar) { - /* Get the next option character. */ - opt = *opt_word++; - if (opt == '\0') { - /* New-style args can follow old-style. */ - state = state_next_word; - } else { - /* See if it takes an argument. */ - p = strchr(short_options, opt); - if (p == NULL) - return ('?'); - if (p[1] == ':') { - bsdtar->optarg = *bsdtar->argv; - if (bsdtar->optarg == NULL) { - lafe_warnc(0, - "Option %c requires an argument", - opt); - return ('?'); - } - ++bsdtar->argv; - --bsdtar->argc; - } - } - } - - /* - * We're ready to look at the next word in argv. - */ - if (state == state_next_word) { - /* No more arguments, so no more options. */ - if (bsdtar->argv[0] == NULL) - return (-1); - /* Doesn't start with '-', so no more options. */ - if (bsdtar->argv[0][0] != '-') - return (-1); - /* "--" marks end of options; consume it and return. */ - if (strcmp(bsdtar->argv[0], "--") == 0) { - ++bsdtar->argv; - --bsdtar->argc; - return (-1); - } - /* Get next word for parsing. */ - opt_word = *bsdtar->argv++; - --bsdtar->argc; - if (opt_word[1] == '-') { - /* Set up long option parser. */ - state = state_long; - opt_word += 2; /* Skip leading '--' */ - } else { - /* Set up short option parser. */ - state = state_short; - ++opt_word; /* Skip leading '-' */ - } - } - - /* - * We're parsing a group of POSIX-style single-character options. - */ - if (state == state_short) { - /* Peel next option off of a group of short options. */ - opt = *opt_word++; - if (opt == '\0') { - /* End of this group; recurse to get next option. */ - state = state_next_word; - return bsdtar_getopt(bsdtar); - } - - /* Does this option take an argument? */ - p = strchr(short_options, opt); - if (p == NULL) - return ('?'); - if (p[1] == ':') - required = 1; - - /* If it takes an argument, parse that. */ - if (required) { - /* If arg is run-in, opt_word already points to it. */ - if (opt_word[0] == '\0') { - /* Otherwise, pick up the next word. */ - opt_word = *bsdtar->argv; - if (opt_word == NULL) { - lafe_warnc(0, - "Option -%c requires an argument", - opt); - return ('?'); - } - ++bsdtar->argv; - --bsdtar->argc; - } - if (opt == 'W') { - state = state_long; - long_prefix = "-W "; /* For clearer errors. */ - } else { - state = state_next_word; - bsdtar->optarg = opt_word; - } - } - } - - /* We're reading a long option, including -W long=arg convention. */ - if (state == state_long) { - /* After this long option, we'll be starting a new word. */ - state = state_next_word; - - /* Option name ends at '=' if there is one. */ - p = strchr(opt_word, '='); - if (p != NULL) { - optlength = (size_t)(p - opt_word); - bsdtar->optarg = (char *)(uintptr_t)(p + 1); - } else { - optlength = strlen(opt_word); - } - - /* Search the table for an unambiguous match. */ - for (popt = tar_longopts; popt->name != NULL; popt++) { - /* Short-circuit if first chars don't match. */ - if (popt->name[0] != opt_word[0]) - continue; - /* If option is a prefix of name in table, record it.*/ - if (strncmp(opt_word, popt->name, optlength) == 0) { - match2 = match; /* Record up to two matches. */ - match = popt; - /* If it's an exact match, we're done. */ - if (strlen(popt->name) == optlength) { - match2 = NULL; /* Forget the others. */ - break; - } - } - } - - /* Fail if there wasn't a unique match. */ - if (match == NULL) { - lafe_warnc(0, - "Option %s%s is not supported", - long_prefix, opt_word); - return ('?'); - } - if (match2 != NULL) { - lafe_warnc(0, - "Ambiguous option %s%s (matches --%s and --%s)", - long_prefix, opt_word, match->name, match2->name); - return ('?'); - } - - /* We've found a unique match; does it need an argument? */ - if (match->required) { - /* Argument required: get next word if necessary. */ - if (bsdtar->optarg == NULL) { - bsdtar->optarg = *bsdtar->argv; - if (bsdtar->optarg == NULL) { - lafe_warnc(0, - "Option %s%s requires an argument", - long_prefix, match->name); - return ('?'); - } - ++bsdtar->argv; - --bsdtar->argc; - } - } else { - /* Argument forbidden: fail if there is one. */ - if (bsdtar->optarg != NULL) { - lafe_warnc(0, - "Option %s%s does not allow an argument", - long_prefix, match->name); - return ('?'); - } - } - return (match->equivalent); - } - - return (opt); -} diff --git a/Utilities/cmlibarchive/tar/config_freebsd.h b/Utilities/cmlibarchive/tar/config_freebsd.h deleted file mode 100644 index c94c539f7..000000000 --- a/Utilities/cmlibarchive/tar/config_freebsd.h +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/tar/config_freebsd.h,v 1.8 2008/11/29 20:06:53 kientzle Exp $ - */ - -/* A default configuration for FreeBSD, used if there is no config.h. */ - -#include /* __FreeBSD_version */ - -#undef HAVE_ATTR_XATTR_H -#define HAVE_CHROOT 1 -#define HAVE_DIRENT_D_NAMLEN 1 -#define HAVE_DIRENT_H 1 -#define HAVE_D_MD_ORDER 1 -#define HAVE_ERRNO_H 1 -#undef HAVE_EXT2FS_EXT2_FS_H -#define HAVE_FCHDIR 1 -#define HAVE_FCNTL_H 1 -#define HAVE_GRP_H 1 -#define HAVE_LANGINFO_H 1 -#undef HAVE_LIBACL -#define HAVE_LIBARCHIVE 1 -#define HAVE_LIMITS_H 1 -#define HAVE_LINK 1 -#undef HAVE_LINUX_EXT2_FS_H -#undef HAVE_LINUX_FS_H -#define HAVE_LOCALE_H 1 -#define HAVE_MBTOWC 1 -#undef HAVE_NDIR_H -#if __FreeBSD_version >= 450002 /* nl_langinfo introduced */ -#define HAVE_NL_LANGINFO 1 -#endif -#define HAVE_PATHS_H 1 -#define HAVE_PWD_H 1 -#define HAVE_READLINK 1 -#define HAVE_REGEX_H 1 -#define HAVE_SETLOCALE 1 -#define HAVE_SIGNAL_H 1 -#define HAVE_STDARG_H 1 -#define HAVE_STDLIB_H 1 -#define HAVE_STRING_H 1 -#define HAVE_STRUCT_STAT_ST_FLAGS 1 -#undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC -#undef HAVE_STRUCT_STAT_ST_MTIME_N -#undef HAVE_STRUCT_STAT_ST_MTIME_USEC -#define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 -#undef HAVE_STRUCT_STAT_ST_UMTIME -#define HAVE_SYMLINK 1 -#undef HAVE_SYS_DIR_H -#define HAVE_SYS_IOCTL_H 1 -#undef HAVE_SYS_NDIR_H -#define HAVE_SYS_PARAM_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_TIME_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_UINTMAX_T 1 -#define HAVE_UNISTD_H 1 -#define HAVE_UNSIGNED_LONG_LONG -#define HAVE_WCTYPE_H 1 -#define HAVE_ZLIB_H 1 -#undef MAJOR_IN_MKDEV diff --git a/Utilities/cmlibarchive/tar/getdate.c b/Utilities/cmlibarchive/tar/getdate.c deleted file mode 100644 index aa4ccbb95..000000000 --- a/Utilities/cmlibarchive/tar/getdate.c +++ /dev/null @@ -1,1037 +0,0 @@ -/* - * This code is in the public domain and has no copyright. - * - * This is a plain C recursive-descent translation of an old - * public-domain YACC grammar that has been used for parsing dates in - * very many open-source projects. - * - * Since the original authors were generous enough to donate their - * work to the public domain, I feel compelled to match their - * generosity. - * - * Tim Kientzle, February 2009. - */ - -/* - * Header comment from original getdate.y: - */ - -/* -** Originally written by Steven M. Bellovin while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** and Jim Berets in August, 1990; -** -** This grammar has 10 shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -*/ - -#ifdef __FreeBSD__ -#include -__FBSDID("$FreeBSD$"); -#endif - -#include -#include -#include -#include -#include - -/* This file defines a single public function. */ -time_t get_date(time_t now, char *); - -/* Basic time units. */ -#define EPOCH 1970 -#define MINUTE (60L) -#define HOUR (60L * MINUTE) -#define DAY (24L * HOUR) - -/* Daylight-savings mode: on, off, or not yet known. */ -enum DSTMODE { DSTon, DSToff, DSTmaybe }; -/* Meridian: am or pm. */ -enum { tAM, tPM }; -/* Token types returned by nexttoken() */ -enum { tAGO = 260, tDAY, tDAYZONE, tAMPM, tMONTH, tMONTH_UNIT, tSEC_UNIT, - tUNUMBER, tZONE, tDST }; -struct token { int token; time_t value; }; - -/* - * Parser state. - */ -struct gdstate { - struct token *tokenp; /* Pointer to next token. */ - /* HaveXxxx counts how many of this kind of phrase we've seen; - * it's a fatal error to have more than one time, zone, day, - * or date phrase. */ - int HaveYear; - int HaveMonth; - int HaveDay; - int HaveWeekDay; /* Day of week */ - int HaveTime; /* Hour/minute/second */ - int HaveZone; /* timezone and/or DST info */ - int HaveRel; /* time offset; we can have more than one */ - /* Absolute time values. */ - time_t Timezone; /* Seconds offset from GMT */ - time_t Day; - time_t Hour; - time_t Minutes; - time_t Month; - time_t Seconds; - time_t Year; - /* DST selection */ - enum DSTMODE DSTmode; - /* Day of week accounting, e.g., "3rd Tuesday" */ - time_t DayOrdinal; /* "3" in "3rd Tuesday" */ - time_t DayNumber; /* "Tuesday" in "3rd Tuesday" */ - /* Relative time values: hour/day/week offsets are measured in - * seconds, month/year are counted in months. */ - time_t RelMonth; - time_t RelSeconds; -}; - -/* - * A series of functions that recognize certain common time phrases. - * Each function returns 1 if it managed to make sense of some of the - * tokens, zero otherwise. - */ - -/* - * hour:minute or hour:minute:second with optional AM, PM, or numeric - * timezone offset - */ -static int -timephrase(struct gdstate *gds) -{ - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == ':' - && gds->tokenp[2].token == tUNUMBER - && gds->tokenp[3].token == ':' - && gds->tokenp[4].token == tUNUMBER) { - /* "12:14:18" or "22:08:07" */ - ++gds->HaveTime; - gds->Hour = gds->tokenp[0].value; - gds->Minutes = gds->tokenp[2].value; - gds->Seconds = gds->tokenp[4].value; - gds->tokenp += 5; - } - else if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == ':' - && gds->tokenp[2].token == tUNUMBER) { - /* "12:14" or "22:08" */ - ++gds->HaveTime; - gds->Hour = gds->tokenp[0].value; - gds->Minutes = gds->tokenp[2].value; - gds->Seconds = 0; - gds->tokenp += 3; - } - else if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tAMPM) { - /* "7" is a time if it's followed by "am" or "pm" */ - ++gds->HaveTime; - gds->Hour = gds->tokenp[0].value; - gds->Minutes = gds->Seconds = 0; - /* We'll handle the AM/PM below. */ - gds->tokenp += 1; - } else { - /* We can't handle this. */ - return 0; - } - - if (gds->tokenp[0].token == tAMPM) { - /* "7:12pm", "12:20:13am" */ - if (gds->Hour == 12) - gds->Hour = 0; - if (gds->tokenp[0].value == tPM) - gds->Hour += 12; - gds->tokenp += 1; - } - if (gds->tokenp[0].token == '+' - && gds->tokenp[1].token == tUNUMBER) { - /* "7:14+0700" */ - gds->HaveZone++; - gds->DSTmode = DSToff; - gds->Timezone = - ((gds->tokenp[1].value / 100) * HOUR - + (gds->tokenp[1].value % 100) * MINUTE); - gds->tokenp += 2; - } - if (gds->tokenp[0].token == '-' - && gds->tokenp[1].token == tUNUMBER) { - /* "19:14:12-0530" */ - gds->HaveZone++; - gds->DSTmode = DSToff; - gds->Timezone = + ((gds->tokenp[1].value / 100) * HOUR - + (gds->tokenp[1].value % 100) * MINUTE); - gds->tokenp += 2; - } - return 1; -} - -/* - * Timezone name, possibly including DST. - */ -static int -zonephrase(struct gdstate *gds) -{ - if (gds->tokenp[0].token == tZONE - && gds->tokenp[1].token == tDST) { - gds->HaveZone++; - gds->Timezone = gds->tokenp[0].value; - gds->DSTmode = DSTon; - gds->tokenp += 1; - return 1; - } - - if (gds->tokenp[0].token == tZONE) { - gds->HaveZone++; - gds->Timezone = gds->tokenp[0].value; - gds->DSTmode = DSToff; - gds->tokenp += 1; - return 1; - } - - if (gds->tokenp[0].token == tDAYZONE) { - gds->HaveZone++; - gds->Timezone = gds->tokenp[0].value; - gds->DSTmode = DSTon; - gds->tokenp += 1; - return 1; - } - return 0; -} - -/* - * Year/month/day in various combinations. - */ -static int -datephrase(struct gdstate *gds) -{ - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == '/' - && gds->tokenp[2].token == tUNUMBER - && gds->tokenp[3].token == '/' - && gds->tokenp[4].token == tUNUMBER) { - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - if (gds->tokenp[0].value >= 13) { - /* First number is big: 2004/01/29, 99/02/17 */ - gds->Year = gds->tokenp[0].value; - gds->Month = gds->tokenp[2].value; - gds->Day = gds->tokenp[4].value; - } else if ((gds->tokenp[4].value >= 13) - || (gds->tokenp[2].value >= 13)) { - /* Last number is big: 01/07/98 */ - /* Middle number is big: 01/29/04 */ - gds->Month = gds->tokenp[0].value; - gds->Day = gds->tokenp[2].value; - gds->Year = gds->tokenp[4].value; - } else { - /* No significant clues: 02/03/04 */ - gds->Month = gds->tokenp[0].value; - gds->Day = gds->tokenp[2].value; - gds->Year = gds->tokenp[4].value; - } - gds->tokenp += 5; - return 1; - } - - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == '/' - && gds->tokenp[2].token == tUNUMBER) { - /* "1/15" */ - gds->HaveMonth++; - gds->HaveDay++; - gds->Month = gds->tokenp[0].value; - gds->Day = gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == '-' - && gds->tokenp[2].token == tUNUMBER - && gds->tokenp[3].token == '-' - && gds->tokenp[4].token == tUNUMBER) { - /* ISO 8601 format. yyyy-mm-dd. */ - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - gds->Year = gds->tokenp[0].value; - gds->Month = gds->tokenp[2].value; - gds->Day = gds->tokenp[4].value; - gds->tokenp += 5; - return 1; - } - - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == '-' - && gds->tokenp[2].token == tMONTH - && gds->tokenp[3].token == '-' - && gds->tokenp[4].token == tUNUMBER) { - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - if (gds->tokenp[0].value > 31) { - /* e.g. 1992-Jun-17 */ - gds->Year = gds->tokenp[0].value; - gds->Month = gds->tokenp[2].value; - gds->Day = gds->tokenp[4].value; - } else { - /* e.g. 17-JUN-1992. */ - gds->Day = gds->tokenp[0].value; - gds->Month = gds->tokenp[2].value; - gds->Year = gds->tokenp[4].value; - } - gds->tokenp += 5; - return 1; - } - - if (gds->tokenp[0].token == tMONTH - && gds->tokenp[1].token == tUNUMBER - && gds->tokenp[2].token == ',' - && gds->tokenp[3].token == tUNUMBER) { - /* "June 17, 2001" */ - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - gds->Month = gds->tokenp[0].value; - gds->Day = gds->tokenp[1].value; - gds->Year = gds->tokenp[3].value; - gds->tokenp += 4; - return 1; - } - - if (gds->tokenp[0].token == tMONTH - && gds->tokenp[1].token == tUNUMBER) { - /* "May 3" */ - gds->HaveMonth++; - gds->HaveDay++; - gds->Month = gds->tokenp[0].value; - gds->Day = gds->tokenp[1].value; - gds->tokenp += 2; - return 1; - } - - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tMONTH - && gds->tokenp[2].token == tUNUMBER) { - /* "12 Sept 1997" */ - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - gds->Day = gds->tokenp[0].value; - gds->Month = gds->tokenp[1].value; - gds->Year = gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tMONTH) { - /* "12 Sept" */ - gds->HaveMonth++; - gds->HaveDay++; - gds->Day = gds->tokenp[0].value; - gds->Month = gds->tokenp[1].value; - gds->tokenp += 2; - return 1; - } - - return 0; -} - -/* - * Relative time phrase: "tomorrow", "yesterday", "+1 hour", etc. - */ -static int -relunitphrase(struct gdstate *gds) -{ - if (gds->tokenp[0].token == '-' - && gds->tokenp[1].token == tUNUMBER - && gds->tokenp[2].token == tSEC_UNIT) { - /* "-3 hours" */ - gds->HaveRel++; - gds->RelSeconds -= gds->tokenp[1].value * gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - if (gds->tokenp[0].token == '+' - && gds->tokenp[1].token == tUNUMBER - && gds->tokenp[2].token == tSEC_UNIT) { - /* "+1 minute" */ - gds->HaveRel++; - gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tSEC_UNIT) { - /* "1 day" */ - gds->HaveRel++; - gds->RelSeconds += gds->tokenp[1].value * gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - if (gds->tokenp[0].token == '-' - && gds->tokenp[1].token == tUNUMBER - && gds->tokenp[2].token == tMONTH_UNIT) { - /* "-3 months" */ - gds->HaveRel++; - gds->RelMonth -= gds->tokenp[1].value * gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - if (gds->tokenp[0].token == '+' - && gds->tokenp[1].token == tUNUMBER - && gds->tokenp[2].token == tMONTH_UNIT) { - /* "+5 years" */ - gds->HaveRel++; - gds->RelMonth += gds->tokenp[1].value * gds->tokenp[2].value; - gds->tokenp += 3; - return 1; - } - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tMONTH_UNIT) { - /* "2 years" */ - gds->HaveRel++; - gds->RelMonth += gds->tokenp[0].value * gds->tokenp[1].value; - gds->tokenp += 2; - return 1; - } - if (gds->tokenp[0].token == tSEC_UNIT) { - /* "now", "tomorrow" */ - gds->HaveRel++; - gds->RelSeconds += gds->tokenp[0].value; - ++gds->tokenp; - return 1; - } - if (gds->tokenp[0].token == tMONTH_UNIT) { - /* "month" */ - gds->HaveRel++; - gds->RelMonth += gds->tokenp[0].value; - gds->tokenp += 1; - return 1; - } - return 0; -} - -/* - * Day of the week specification. - */ -static int -dayphrase(struct gdstate *gds) -{ - if (gds->tokenp[0].token == tDAY) { - /* "tues", "wednesday," */ - gds->HaveWeekDay++; - gds->DayOrdinal = 1; - gds->DayNumber = gds->tokenp[0].value; - gds->tokenp += 1; - if (gds->tokenp[0].token == ',') - gds->tokenp += 1; - return 1; - } - if (gds->tokenp[0].token == tUNUMBER - && gds->tokenp[1].token == tDAY) { - /* "second tues" "3 wed" */ - gds->HaveWeekDay++; - gds->DayOrdinal = gds->tokenp[0].value; - gds->DayNumber = gds->tokenp[1].value; - gds->tokenp += 2; - return 1; - } - return 0; -} - -/* - * Try to match a phrase using one of the above functions. - * This layer also deals with a couple of generic issues. - */ -static int -phrase(struct gdstate *gds) -{ - if (timephrase(gds)) - return 1; - if (zonephrase(gds)) - return 1; - if (datephrase(gds)) - return 1; - if (dayphrase(gds)) - return 1; - if (relunitphrase(gds)) { - if (gds->tokenp[0].token == tAGO) { - gds->RelSeconds = -gds->RelSeconds; - gds->RelMonth = -gds->RelMonth; - gds->tokenp += 1; - } - return 1; - } - - /* Bare numbers sometimes have meaning. */ - if (gds->tokenp[0].token == tUNUMBER) { - if (gds->HaveTime && !gds->HaveYear && !gds->HaveRel) { - gds->HaveYear++; - gds->Year = gds->tokenp[0].value; - gds->tokenp += 1; - return 1; - } - - if(gds->tokenp[0].value > 10000) { - /* "20040301" */ - gds->HaveYear++; - gds->HaveMonth++; - gds->HaveDay++; - gds->Day= (gds->tokenp[0].value)%100; - gds->Month= (gds->tokenp[0].value/100)%100; - gds->Year = gds->tokenp[0].value/10000; - gds->tokenp += 1; - return 1; - } - - if (gds->tokenp[0].value < 24) { - gds->HaveTime++; - gds->Hour = gds->tokenp[0].value; - gds->Minutes = 0; - gds->Seconds = 0; - gds->tokenp += 1; - return 1; - } - - if ((gds->tokenp[0].value / 100 < 24) - && (gds->tokenp[0].value % 100 < 60)) { - /* "513" is same as "5:13" */ - gds->Hour = gds->tokenp[0].value / 100; - gds->Minutes = gds->tokenp[0].value % 100; - gds->Seconds = 0; - gds->tokenp += 1; - return 1; - } - } - - return 0; -} - -/* - * A dictionary of time words. - */ -static struct LEXICON { - size_t abbrev; - const char *name; - int type; - time_t value; -} const TimeWords[] = { - /* am/pm */ - { 0, "am", tAMPM, tAM }, - { 0, "pm", tAMPM, tPM }, - - /* Month names. */ - { 3, "january", tMONTH, 1 }, - { 3, "february", tMONTH, 2 }, - { 3, "march", tMONTH, 3 }, - { 3, "april", tMONTH, 4 }, - { 3, "may", tMONTH, 5 }, - { 3, "june", tMONTH, 6 }, - { 3, "july", tMONTH, 7 }, - { 3, "august", tMONTH, 8 }, - { 3, "september", tMONTH, 9 }, - { 3, "october", tMONTH, 10 }, - { 3, "november", tMONTH, 11 }, - { 3, "december", tMONTH, 12 }, - - /* Days of the week. */ - { 2, "sunday", tDAY, 0 }, - { 3, "monday", tDAY, 1 }, - { 2, "tuesday", tDAY, 2 }, - { 3, "wednesday", tDAY, 3 }, - { 2, "thursday", tDAY, 4 }, - { 2, "friday", tDAY, 5 }, - { 2, "saturday", tDAY, 6 }, - - /* Timezones: Offsets are in seconds. */ - { 0, "gmt", tZONE, 0*HOUR }, /* Greenwich Mean */ - { 0, "ut", tZONE, 0*HOUR }, /* Universal (Coordinated) */ - { 0, "utc", tZONE, 0*HOUR }, - { 0, "wet", tZONE, 0*HOUR }, /* Western European */ - { 0, "bst", tDAYZONE, 0*HOUR }, /* British Summer */ - { 0, "wat", tZONE, 1*HOUR }, /* West Africa */ - { 0, "at", tZONE, 2*HOUR }, /* Azores */ - /* { 0, "bst", tZONE, 3*HOUR }, */ /* Brazil Standard: Conflict */ - /* { 0, "gst", tZONE, 3*HOUR }, */ /* Greenland Standard: Conflict*/ - { 0, "nft", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland */ - { 0, "nst", tZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Standard */ - { 0, "ndt", tDAYZONE, 3*HOUR+30*MINUTE }, /* Newfoundland Daylight */ - { 0, "ast", tZONE, 4*HOUR }, /* Atlantic Standard */ - { 0, "adt", tDAYZONE, 4*HOUR }, /* Atlantic Daylight */ - { 0, "est", tZONE, 5*HOUR }, /* Eastern Standard */ - { 0, "edt", tDAYZONE, 5*HOUR }, /* Eastern Daylight */ - { 0, "cst", tZONE, 6*HOUR }, /* Central Standard */ - { 0, "cdt", tDAYZONE, 6*HOUR }, /* Central Daylight */ - { 0, "mst", tZONE, 7*HOUR }, /* Mountain Standard */ - { 0, "mdt", tDAYZONE, 7*HOUR }, /* Mountain Daylight */ - { 0, "pst", tZONE, 8*HOUR }, /* Pacific Standard */ - { 0, "pdt", tDAYZONE, 8*HOUR }, /* Pacific Daylight */ - { 0, "yst", tZONE, 9*HOUR }, /* Yukon Standard */ - { 0, "ydt", tDAYZONE, 9*HOUR }, /* Yukon Daylight */ - { 0, "hst", tZONE, 10*HOUR }, /* Hawaii Standard */ - { 0, "hdt", tDAYZONE, 10*HOUR }, /* Hawaii Daylight */ - { 0, "cat", tZONE, 10*HOUR }, /* Central Alaska */ - { 0, "ahst", tZONE, 10*HOUR }, /* Alaska-Hawaii Standard */ - { 0, "nt", tZONE, 11*HOUR }, /* Nome */ - { 0, "idlw", tZONE, 12*HOUR }, /* Intl Date Line West */ - { 0, "cet", tZONE, -1*HOUR }, /* Central European */ - { 0, "met", tZONE, -1*HOUR }, /* Middle European */ - { 0, "mewt", tZONE, -1*HOUR }, /* Middle European Winter */ - { 0, "mest", tDAYZONE, -1*HOUR }, /* Middle European Summer */ - { 0, "swt", tZONE, -1*HOUR }, /* Swedish Winter */ - { 0, "sst", tDAYZONE, -1*HOUR }, /* Swedish Summer */ - { 0, "fwt", tZONE, -1*HOUR }, /* French Winter */ - { 0, "fst", tDAYZONE, -1*HOUR }, /* French Summer */ - { 0, "eet", tZONE, -2*HOUR }, /* Eastern Eur, USSR Zone 1 */ - { 0, "bt", tZONE, -3*HOUR }, /* Baghdad, USSR Zone 2 */ - { 0, "it", tZONE, -3*HOUR-30*MINUTE },/* Iran */ - { 0, "zp4", tZONE, -4*HOUR }, /* USSR Zone 3 */ - { 0, "zp5", tZONE, -5*HOUR }, /* USSR Zone 4 */ - { 0, "ist", tZONE, -5*HOUR-30*MINUTE },/* Indian Standard */ - { 0, "zp6", tZONE, -6*HOUR }, /* USSR Zone 5 */ - /* { 0, "nst", tZONE, -6.5*HOUR }, */ /* North Sumatra: Conflict */ - /* { 0, "sst", tZONE, -7*HOUR }, */ /* So Sumatra, USSR 6: Conflict */ - { 0, "wast", tZONE, -7*HOUR }, /* West Australian Standard */ - { 0, "wadt", tDAYZONE, -7*HOUR }, /* West Australian Daylight */ - { 0, "jt", tZONE, -7*HOUR-30*MINUTE },/* Java (3pm in Cronusland!)*/ - { 0, "cct", tZONE, -8*HOUR }, /* China Coast, USSR Zone 7 */ - { 0, "jst", tZONE, -9*HOUR }, /* Japan Std, USSR Zone 8 */ - { 0, "cast", tZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Std */ - { 0, "cadt", tDAYZONE, -9*HOUR-30*MINUTE },/* Ctrl Australian Daylt */ - { 0, "east", tZONE, -10*HOUR }, /* Eastern Australian Std */ - { 0, "eadt", tDAYZONE, -10*HOUR }, /* Eastern Australian Daylt */ - { 0, "gst", tZONE, -10*HOUR }, /* Guam Std, USSR Zone 9 */ - { 0, "nzt", tZONE, -12*HOUR }, /* New Zealand */ - { 0, "nzst", tZONE, -12*HOUR }, /* New Zealand Standard */ - { 0, "nzdt", tDAYZONE, -12*HOUR }, /* New Zealand Daylight */ - { 0, "idle", tZONE, -12*HOUR }, /* Intl Date Line East */ - - { 0, "dst", tDST, 0 }, - - /* Time units. */ - { 4, "years", tMONTH_UNIT, 12 }, - { 5, "months", tMONTH_UNIT, 1 }, - { 9, "fortnights", tSEC_UNIT, 14 * DAY }, - { 4, "weeks", tSEC_UNIT, 7 * DAY }, - { 3, "days", tSEC_UNIT, DAY }, - { 4, "hours", tSEC_UNIT, HOUR }, - { 3, "minutes", tSEC_UNIT, MINUTE }, - { 3, "seconds", tSEC_UNIT, 1 }, - - /* Relative-time words. */ - { 0, "tomorrow", tSEC_UNIT, DAY }, - { 0, "yesterday", tSEC_UNIT, -DAY }, - { 0, "today", tSEC_UNIT, 0 }, - { 0, "now", tSEC_UNIT, 0 }, - { 0, "last", tUNUMBER, -1 }, - { 0, "this", tSEC_UNIT, 0 }, - { 0, "next", tUNUMBER, 2 }, - { 0, "first", tUNUMBER, 1 }, - { 0, "1st", tUNUMBER, 1 }, -/* { 0, "second", tUNUMBER, 2 }, */ - { 0, "2nd", tUNUMBER, 2 }, - { 0, "third", tUNUMBER, 3 }, - { 0, "3rd", tUNUMBER, 3 }, - { 0, "fourth", tUNUMBER, 4 }, - { 0, "4th", tUNUMBER, 4 }, - { 0, "fifth", tUNUMBER, 5 }, - { 0, "5th", tUNUMBER, 5 }, - { 0, "sixth", tUNUMBER, 6 }, - { 0, "seventh", tUNUMBER, 7 }, - { 0, "eighth", tUNUMBER, 8 }, - { 0, "ninth", tUNUMBER, 9 }, - { 0, "tenth", tUNUMBER, 10 }, - { 0, "eleventh", tUNUMBER, 11 }, - { 0, "twelfth", tUNUMBER, 12 }, - { 0, "ago", tAGO, 1 }, - - /* Military timezones. */ - { 0, "a", tZONE, 1*HOUR }, - { 0, "b", tZONE, 2*HOUR }, - { 0, "c", tZONE, 3*HOUR }, - { 0, "d", tZONE, 4*HOUR }, - { 0, "e", tZONE, 5*HOUR }, - { 0, "f", tZONE, 6*HOUR }, - { 0, "g", tZONE, 7*HOUR }, - { 0, "h", tZONE, 8*HOUR }, - { 0, "i", tZONE, 9*HOUR }, - { 0, "k", tZONE, 10*HOUR }, - { 0, "l", tZONE, 11*HOUR }, - { 0, "m", tZONE, 12*HOUR }, - { 0, "n", tZONE, -1*HOUR }, - { 0, "o", tZONE, -2*HOUR }, - { 0, "p", tZONE, -3*HOUR }, - { 0, "q", tZONE, -4*HOUR }, - { 0, "r", tZONE, -5*HOUR }, - { 0, "s", tZONE, -6*HOUR }, - { 0, "t", tZONE, -7*HOUR }, - { 0, "u", tZONE, -8*HOUR }, - { 0, "v", tZONE, -9*HOUR }, - { 0, "w", tZONE, -10*HOUR }, - { 0, "x", tZONE, -11*HOUR }, - { 0, "y", tZONE, -12*HOUR }, - { 0, "z", tZONE, 0*HOUR }, - - /* End of table. */ - { 0, NULL, 0, 0 } -}; - -/* - * Year is either: - * = A number from 0 to 99, which means a year from 1970 to 2069, or - * = The actual year (>=100). - */ -static time_t -Convert(time_t Month, time_t Day, time_t Year, - time_t Hours, time_t Minutes, time_t Seconds, - time_t Timezone, enum DSTMODE DSTmode) -{ - static int DaysInMonth[12] = { - 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - time_t Julian; - int i; - - if (Year < 69) - Year += 2000; - else if (Year < 100) - Year += 1900; - DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) - ? 29 : 28; - /* Checking for 2038 bogusly assumes that time_t is 32 bits. But - I'm too lazy to try to check for time_t overflow in another way. */ - if (Year < EPOCH || Year > 2038 - || Month < 1 || Month > 12 - /* Lint fluff: "conversion from long may lose accuracy" */ - || Day < 1 || Day > DaysInMonth[(int)--Month] - || Hours < 0 || Hours > 23 - || Minutes < 0 || Minutes > 59 - || Seconds < 0 || Seconds > 59) - return -1; - - Julian = Day - 1; - for (i = 0; i < Month; i++) - Julian += DaysInMonth[i]; - for (i = EPOCH; i < Year; i++) - Julian += 365 + (i % 4 == 0); - Julian *= DAY; - Julian += Timezone; - Julian += Hours * HOUR + Minutes * MINUTE + Seconds; - if (DSTmode == DSTon - || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) - Julian -= HOUR; - return Julian; -} - - -static time_t -DSTcorrect(time_t Start, time_t Future) -{ - time_t StartDay; - time_t FutureDay; - - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * HOUR; -} - - -static time_t -RelativeDate(time_t Start, time_t zone, int dstmode, - time_t DayOrdinal, time_t DayNumber) -{ - struct tm *tm; - time_t t, now; - - t = Start - zone; - tm = gmtime(&t); - now = Start; - now += DAY * ((DayNumber - tm->tm_wday + 7) % 7); - now += 7 * DAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); - if (dstmode == DSTmaybe) - return DSTcorrect(Start, now); - return now - Start; -} - - -static time_t -RelativeMonth(time_t Start, time_t Timezone, time_t RelMonth) -{ - struct tm *tm; - time_t Month; - time_t Year; - - if (RelMonth == 0) - return 0; - tm = localtime(&Start); - Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; - Year = Month / 12; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - Timezone, DSTmaybe)); -} - -/* - * Tokenizer. - */ -static int -nexttoken(char **in, time_t *value) -{ - char c; - char buff[64]; - - for ( ; ; ) { - while (isspace((unsigned char)**in)) - ++*in; - - /* Skip parenthesized comments. */ - if (**in == '(') { - int Count = 0; - do { - c = *(*in)++; - if (c == '\0') - return c; - if (c == '(') - Count++; - else if (c == ')') - Count--; - } while (Count > 0); - continue; - } - - /* Try the next token in the word table first. */ - /* This allows us to match "2nd", for example. */ - { - char *src = *in; - const struct LEXICON *tp; - unsigned i = 0; - - /* Force to lowercase and strip '.' characters. */ - while (*src != '\0' - && (isalnum((unsigned char)*src) || *src == '.') - && i < sizeof(buff)-1) { - if (*src != '.') { - if (isupper((unsigned char)*src)) - buff[i++] = tolower((unsigned char)*src); - else - buff[i++] = *src; - } - src++; - } - buff[i++] = '\0'; - - /* - * Find the first match. If the word can be - * abbreviated, make sure we match at least - * the minimum abbreviation. - */ - for (tp = TimeWords; tp->name; tp++) { - size_t abbrev = tp->abbrev; - if (abbrev == 0) - abbrev = strlen(tp->name); - if (strlen(buff) >= abbrev - && strncmp(tp->name, buff, strlen(buff)) - == 0) { - /* Skip over token. */ - *in = src; - /* Return the match. */ - *value = tp->value; - return tp->type; - } - } - } - - /* - * Not in the word table, maybe it's a number. Note: - * Because '-' and '+' have other special meanings, I - * don't deal with signed numbers here. - */ - if (isdigit((unsigned char)(c = **in))) { - for (*value = 0; isdigit((unsigned char)(c = *(*in)++)); ) - *value = 10 * *value + c - '0'; - (*in)--; - return (tUNUMBER); - } - - return *(*in)++; - } -} - -#define TM_YEAR_ORIGIN 1900 - -/* Yield A - B, measured in seconds. */ -static long -difftm (struct tm *a, struct tm *b) -{ - int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); - int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - int days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay/100 - by/100) - + ((ay/100 >> 2) - (by/100 >> 2)) - /* + difference in years * 365 */ - + (long)(ay-by) * 365 - ); - return (days * DAY + (a->tm_hour - b->tm_hour) * HOUR - + (a->tm_min - b->tm_min) * MINUTE - + (a->tm_sec - b->tm_sec)); -} - -/* - * - * The public function. - * - * TODO: tokens[] array should be dynamically sized. - */ -time_t -get_date(time_t now, char *p) -{ - struct token tokens[256]; - struct gdstate _gds; - struct token *lasttoken; - struct gdstate *gds; - struct tm local, *tm; - struct tm gmt, *gmt_ptr; - time_t Start; - time_t tod; - long tzone; - - /* Clear out the parsed token array. */ - memset(tokens, 0, sizeof(tokens)); - /* Initialize the parser state. */ - memset(&_gds, 0, sizeof(_gds)); - gds = &_gds; - - /* Look up the current time. */ - memset(&local, 0, sizeof(local)); - tm = localtime (&now); - if (tm == NULL) - return -1; - local = *tm; - - /* Look up UTC if we can and use that to determine the current - * timezone offset. */ - memset(&gmt, 0, sizeof(gmt)); - gmt_ptr = gmtime (&now); - if (gmt_ptr != NULL) { - /* Copy, in case localtime and gmtime use the same buffer. */ - gmt = *gmt_ptr; - } - if (gmt_ptr != NULL) - tzone = difftm (&gmt, &local); - else - /* This system doesn't understand timezones; fake it. */ - tzone = 0; - if(local.tm_isdst) - tzone += HOUR; - - /* Tokenize the input string. */ - lasttoken = tokens; - while ((lasttoken->token = nexttoken(&p, &lasttoken->value)) != 0) { - ++lasttoken; - if (lasttoken > tokens + 255) - return -1; - } - gds->tokenp = tokens; - - /* Match phrases until we run out of input tokens. */ - while (gds->tokenp < lasttoken) { - if (!phrase(gds)) - return -1; - } - - /* Use current local timezone if none was specified. */ - if (!gds->HaveZone) { - gds->Timezone = tzone; - gds->DSTmode = DSTmaybe; - } - - /* If a timezone was specified, use that for generating the default - * time components instead of the local timezone. */ - if (gds->HaveZone && gmt_ptr != NULL) { - now -= gds->Timezone; - gmt_ptr = gmtime (&now); - if (gmt_ptr != NULL) - local = *gmt_ptr; - now += gds->Timezone; - } - - if (!gds->HaveYear) - gds->Year = local.tm_year + 1900; - if (!gds->HaveMonth) - gds->Month = local.tm_mon + 1; - if (!gds->HaveDay) - gds->Day = local.tm_mday; - /* Note: No default for hour/min/sec; a specifier that just - * gives date always refers to 00:00 on that date. */ - - /* If we saw more than one time, timezone, weekday, year, month, - * or day, then give up. */ - if (gds->HaveTime > 1 || gds->HaveZone > 1 || gds->HaveWeekDay > 1 - || gds->HaveYear > 1 || gds->HaveMonth > 1 || gds->HaveDay > 1) - return -1; - - /* Compute an absolute time based on whatever absolute information - * we collected. */ - if (gds->HaveYear || gds->HaveMonth || gds->HaveDay - || gds->HaveTime || gds->HaveWeekDay) { - Start = Convert(gds->Month, gds->Day, gds->Year, - gds->Hour, gds->Minutes, gds->Seconds, - gds->Timezone, gds->DSTmode); - if (Start < 0) - return -1; - } else { - Start = now; - if (!gds->HaveRel) - Start -= local.tm_hour * HOUR + local.tm_min * MINUTE - + local.tm_sec; - } - - /* Add the relative offset. */ - Start += gds->RelSeconds; - Start += RelativeMonth(Start, gds->Timezone, gds->RelMonth); - - /* Adjust for day-of-week offsets. */ - if (gds->HaveWeekDay - && !(gds->HaveYear || gds->HaveMonth || gds->HaveDay)) { - tod = RelativeDate(Start, gds->Timezone, - gds->DSTmode, gds->DayOrdinal, gds->DayNumber); - Start += tod; - } - - /* -1 is an error indicator, so return 0 instead of -1 if - * that's the actual time. */ - return Start == -1 ? 0 : Start; -} - - -#if defined(TEST) - -/* ARGSUSED */ -int -main(int argc, char **argv) -{ - time_t d; - - while (*++argv != NULL) { - (void)printf("Input: %s\n", *argv); - d = get_date(*argv); - if (d == -1) - (void)printf("Bad format - couldn't convert.\n"); - else - (void)printf("Output: %s\n", ctime(&d)); - } - exit(0); - /* NOTREACHED */ -} -#endif /* defined(TEST) */ diff --git a/Utilities/cmlibarchive/tar/read.c b/Utilities/cmlibarchive/tar/read.c deleted file mode 100644 index 3aff1d5f8..000000000 --- a/Utilities/cmlibarchive/tar/read.c +++ /dev/null @@ -1,440 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/read.c,v 1.40 2008/08/21 06:41:14 kientzle Exp $"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_PARAM_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif - -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_TIME_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#include "bsdtar.h" -#include "err.h" - -struct progress_data { - struct bsdtar *bsdtar; - struct archive *archive; - struct archive_entry *entry; -}; - -static void list_item_verbose(struct bsdtar *, FILE *, - struct archive_entry *); -static void read_archive(struct bsdtar *bsdtar, char mode); - -void -tar_mode_t(struct bsdtar *bsdtar) -{ - read_archive(bsdtar, 't'); - if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0) - bsdtar->return_value = 1; -} - -void -tar_mode_x(struct bsdtar *bsdtar) -{ - read_archive(bsdtar, 'x'); - - if (lafe_unmatched_inclusions_warn(bsdtar->matching, "Not found in archive") != 0) - bsdtar->return_value = 1; -} - -static void -progress_func(void *cookie) -{ - struct progress_data *progress_data = cookie; - struct bsdtar *bsdtar = progress_data->bsdtar; - struct archive *a = progress_data->archive; - struct archive_entry *entry = progress_data->entry; - uintmax_t comp, uncomp; - - if (!need_report()) - return; - - if (bsdtar->verbose) - fprintf(stderr, "\n"); - if (a != NULL) { - comp = archive_position_compressed(a); - uncomp = archive_position_uncompressed(a); - fprintf(stderr, - "In: %ju bytes, compression %d%%;", - comp, (int)((uncomp - comp) * 100 / uncomp)); - fprintf(stderr, " Out: %d files, %ju bytes\n", - archive_file_count(a), uncomp); - } - if (entry != NULL) { - safe_fprintf(stderr, "Current: %s (%ju bytes)", - archive_entry_pathname(entry), - (uintmax_t)archive_entry_size(entry)); - fprintf(stderr, "\n"); - } -} - -/* - * Handle 'x' and 't' modes. - */ -static void -read_archive(struct bsdtar *bsdtar, char mode) -{ - struct progress_data progress_data; - FILE *out; - struct archive *a; - struct archive_entry *entry; - const struct stat *st; - int r; - - while (*bsdtar->argv) { - lafe_include(&bsdtar->matching, *bsdtar->argv); - bsdtar->argv++; - } - - if (bsdtar->names_from_file != NULL) - lafe_include_from_file(&bsdtar->matching, - bsdtar->names_from_file, bsdtar->option_null); - - a = archive_read_new(); - if (bsdtar->compress_program != NULL) - archive_read_support_compression_program(a, bsdtar->compress_program); - else - archive_read_support_compression_all(a); - archive_read_support_format_all(a); - if (ARCHIVE_OK != archive_read_set_options(a, bsdtar->option_options)) - lafe_errc(1, 0, archive_error_string(a)); - if (archive_read_open_file(a, bsdtar->filename, - bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : - DEFAULT_BYTES_PER_BLOCK)) - lafe_errc(1, 0, "Error opening archive: %s", - archive_error_string(a)); - - do_chdir(bsdtar); - - if (mode == 'x') { - /* Set an extract callback so that we can handle SIGINFO. */ - progress_data.bsdtar = bsdtar; - progress_data.archive = a; - archive_read_extract_set_progress_callback(a, progress_func, - &progress_data); - } - - if (mode == 'x' && bsdtar->option_chroot) { -#if HAVE_CHROOT - if (chroot(".") != 0) - lafe_errc(1, errno, "Can't chroot to \".\""); -#else - lafe_errc(1, 0, - "chroot isn't supported on this platform"); -#endif - } - - for (;;) { - /* Support --fast-read option */ - if (bsdtar->option_fast_read && - lafe_unmatched_inclusions(bsdtar->matching) == 0) - break; - - r = archive_read_next_header(a, &entry); - progress_data.entry = entry; - if (r == ARCHIVE_EOF) - break; - if (r < ARCHIVE_OK) - lafe_warnc(0, "%s", archive_error_string(a)); - if (r <= ARCHIVE_WARN) - bsdtar->return_value = 1; - if (r == ARCHIVE_RETRY) { - /* Retryable error: try again */ - lafe_warnc(0, "Retrying..."); - continue; - } - if (r == ARCHIVE_FATAL) - break; - - if (bsdtar->option_numeric_owner) { - archive_entry_set_uname(entry, NULL); - archive_entry_set_gname(entry, NULL); - } - - /* - * Exclude entries that are too old. - */ - st = archive_entry_stat(entry); - if (bsdtar->newer_ctime_sec > 0) { - if (st->st_ctime < bsdtar->newer_ctime_sec) - continue; /* Too old, skip it. */ - if (st->st_ctime == bsdtar->newer_ctime_sec - && ARCHIVE_STAT_CTIME_NANOS(st) - <= bsdtar->newer_ctime_nsec) - continue; /* Too old, skip it. */ - } - if (bsdtar->newer_mtime_sec > 0) { - if (st->st_mtime < bsdtar->newer_mtime_sec) - continue; /* Too old, skip it. */ - if (st->st_mtime == bsdtar->newer_mtime_sec - && ARCHIVE_STAT_MTIME_NANOS(st) - <= bsdtar->newer_mtime_nsec) - continue; /* Too old, skip it. */ - } - - /* - * Note that pattern exclusions are checked before - * pathname rewrites are handled. This gives more - * control over exclusions, since rewrites always lose - * information. (For example, consider a rewrite - * s/foo[0-9]/foo/. If we check exclusions after the - * rewrite, there would be no way to exclude foo1/bar - * while allowing foo2/bar.) - */ - if (lafe_excluded(bsdtar->matching, archive_entry_pathname(entry))) - continue; /* Excluded by a pattern test. */ - - if (mode == 't') { - /* Perversely, gtar uses -O to mean "send to stderr" - * when used with -t. */ - out = bsdtar->option_stdout ? stderr : stdout; - - /* - * TODO: Provide some reasonable way to - * preview rewrites. gtar always displays - * the unedited path in -t output, which means - * you cannot easily preview rewrites. - */ - if (bsdtar->verbose < 2) - safe_fprintf(out, "%s", - archive_entry_pathname(entry)); - else - list_item_verbose(bsdtar, out, entry); - fflush(out); - r = archive_read_data_skip(a); - if (r == ARCHIVE_WARN) { - fprintf(out, "\n"); - lafe_warnc(0, "%s", - archive_error_string(a)); - } - if (r == ARCHIVE_RETRY) { - fprintf(out, "\n"); - lafe_warnc(0, "%s", - archive_error_string(a)); - } - if (r == ARCHIVE_FATAL) { - fprintf(out, "\n"); - lafe_warnc(0, "%s", - archive_error_string(a)); - bsdtar->return_value = 1; - break; - } - fprintf(out, "\n"); - } else { - /* Note: some rewrite failures prevent extraction. */ - if (edit_pathname(bsdtar, entry)) - continue; /* Excluded by a rewrite failure. */ - - if (bsdtar->option_interactive && - !yes("extract '%s'", archive_entry_pathname(entry))) - continue; - - /* - * Format here is from SUSv2, including the - * deferred '\n'. - */ - if (bsdtar->verbose) { - safe_fprintf(stderr, "x %s", - archive_entry_pathname(entry)); - fflush(stderr); - } - - // TODO siginfo_printinfo(bsdtar, 0); - - if (bsdtar->option_stdout) - r = archive_read_data_into_fd(a, 1); - else - r = archive_read_extract(a, entry, - bsdtar->extract_flags); - if (r != ARCHIVE_OK) { - if (!bsdtar->verbose) - safe_fprintf(stderr, "%s", - archive_entry_pathname(entry)); - safe_fprintf(stderr, ": %s", - archive_error_string(a)); - if (!bsdtar->verbose) - fprintf(stderr, "\n"); - bsdtar->return_value = 1; - } - if (bsdtar->verbose) - fprintf(stderr, "\n"); - if (r == ARCHIVE_FATAL) - break; - } - } - - - r = archive_read_close(a); - if (r != ARCHIVE_OK) - lafe_warnc(0, "%s", archive_error_string(a)); - if (r <= ARCHIVE_WARN) - bsdtar->return_value = 1; - - if (bsdtar->verbose > 2) - fprintf(stdout, "Archive Format: %s, Compression: %s\n", - archive_format_name(a), archive_compression_name(a)); - - archive_read_finish(a); -} - - -/* - * Display information about the current file. - * - * The format here roughly duplicates the output of 'ls -l'. - * This is based on SUSv2, where 'tar tv' is documented as - * listing additional information in an "unspecified format," - * and 'pax -l' is documented as using the same format as 'ls -l'. - */ -static void -list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry) -{ - char tmp[100]; - size_t w; - const char *p; - const char *fmt; - time_t tim; - static time_t now; - - /* - * We avoid collecting the entire list in memory at once by - * listing things as we see them. However, that also means we can't - * just pre-compute the field widths. Instead, we start with guesses - * and just widen them as necessary. These numbers are completely - * arbitrary. - */ - if (!bsdtar->u_width) { - bsdtar->u_width = 6; - bsdtar->gs_width = 13; - } - if (!now) - time(&now); - fprintf(out, "%s %d ", - archive_entry_strmode(entry), - archive_entry_nlink(entry)); - - /* Use uname if it's present, else uid. */ - p = archive_entry_uname(entry); - if ((p == NULL) || (*p == '\0')) { - sprintf(tmp, "%lu ", - (unsigned long)archive_entry_uid(entry)); - p = tmp; - } - w = strlen(p); - if (w > bsdtar->u_width) - bsdtar->u_width = w; - fprintf(out, "%-*s ", (int)bsdtar->u_width, p); - - /* Use gname if it's present, else gid. */ - p = archive_entry_gname(entry); - if (p != NULL && p[0] != '\0') { - fprintf(out, "%s", p); - w = strlen(p); - } else { - sprintf(tmp, "%lu", - (unsigned long)archive_entry_gid(entry)); - w = strlen(tmp); - fprintf(out, "%s", tmp); - } - - /* - * Print device number or file size, right-aligned so as to make - * total width of group and devnum/filesize fields be gs_width. - * If gs_width is too small, grow it. - */ - if (archive_entry_filetype(entry) == AE_IFCHR - || archive_entry_filetype(entry) == AE_IFBLK) { - sprintf(tmp, "%lu,%lu", - (unsigned long)archive_entry_rdevmajor(entry), - (unsigned long)archive_entry_rdevminor(entry)); - } else { - /* - * Note the use of platform-dependent macros to format - * the filesize here. We need the format string and the - * corresponding type for the cast. - */ - sprintf(tmp, BSDTAR_FILESIZE_PRINTF, - (BSDTAR_FILESIZE_TYPE)archive_entry_size(entry)); - } - if (w + strlen(tmp) >= bsdtar->gs_width) - bsdtar->gs_width = w+strlen(tmp)+1; - fprintf(out, "%*s", (int)(bsdtar->gs_width - w), tmp); - - /* Format the time using 'ls -l' conventions. */ - tim = archive_entry_mtime(entry); -#define HALF_YEAR (time_t)365 * 86400 / 2 -#if defined(_WIN32) && !defined(__CYGWIN__) -#define DAY_FMT "%d" /* Windows' strftime function does not support %e format. */ -#else -#define DAY_FMT "%e" /* Day number without leading zeros */ -#endif - if (tim < now - HALF_YEAR || tim > now + HALF_YEAR) - fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y"; - else - fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M"; - strftime(tmp, sizeof(tmp), fmt, localtime(&tim)); - fprintf(out, " %s ", tmp); - safe_fprintf(out, "%s", archive_entry_pathname(entry)); - - /* Extra information for links. */ - if (archive_entry_hardlink(entry)) /* Hard link */ - safe_fprintf(out, " link to %s", - archive_entry_hardlink(entry)); - else if (archive_entry_symlink(entry)) /* Symbolic link */ - safe_fprintf(out, " -> %s", archive_entry_symlink(entry)); -} diff --git a/Utilities/cmlibarchive/tar/subst.c b/Utilities/cmlibarchive/tar/subst.c deleted file mode 100644 index 34295ef38..000000000 --- a/Utilities/cmlibarchive/tar/subst.c +++ /dev/null @@ -1,289 +0,0 @@ -/*- - * Copyright (c) 2008 Joerg Sonnenberger - * 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 "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/subst.c,v 1.4 2008/06/15 10:08:16 kientzle Exp $"); - -#if HAVE_REGEX_H -#include "bsdtar.h" - -#include -#include -#include -#include - -#ifndef REG_BASIC -#define REG_BASIC 0 -#endif - -#include "err.h" - -struct subst_rule { - struct subst_rule *next; - regex_t re; - char *result; - unsigned int global:1, print:1, symlink:1; -}; - -struct substitution { - struct subst_rule *first_rule, *last_rule; -}; - -static void -init_substitution(struct bsdtar *bsdtar) -{ - struct substitution *subst; - - bsdtar->substitution = subst = malloc(sizeof(*subst)); - if (subst == NULL) - lafe_errc(1, errno, "Out of memory"); - subst->first_rule = subst->last_rule = NULL; -} - -void -add_substitution(struct bsdtar *bsdtar, const char *rule_text) -{ - struct subst_rule *rule; - struct substitution *subst; - const char *end_pattern, *start_subst; - char *pattern; - int r; - - if ((subst = bsdtar->substitution) == NULL) { - init_substitution(bsdtar); - subst = bsdtar->substitution; - } - - rule = malloc(sizeof(*rule)); - if (rule == NULL) - lafe_errc(1, errno, "Out of memory"); - rule->next = NULL; - - if (subst->last_rule == NULL) - subst->first_rule = rule; - else - subst->last_rule->next = rule; - subst->last_rule = rule; - - if (*rule_text == '\0') - lafe_errc(1, 0, "Empty replacement string"); - end_pattern = strchr(rule_text + 1, *rule_text); - if (end_pattern == NULL) - lafe_errc(1, 0, "Invalid replacement string"); - - pattern = malloc(end_pattern - rule_text); - if (pattern == NULL) - lafe_errc(1, errno, "Out of memory"); - memcpy(pattern, rule_text + 1, end_pattern - rule_text - 1); - pattern[end_pattern - rule_text - 1] = '\0'; - - if ((r = regcomp(&rule->re, pattern, REG_BASIC)) != 0) { - char buf[80]; - regerror(r, &rule->re, buf, sizeof(buf)); - lafe_errc(1, 0, "Invalid regular expression: %s", buf); - } - free(pattern); - - start_subst = end_pattern + 1; - end_pattern = strchr(start_subst, *rule_text); - if (end_pattern == NULL) - lafe_errc(1, 0, "Invalid replacement string"); - - rule->result = malloc(end_pattern - start_subst + 1); - if (rule->result == NULL) - lafe_errc(1, errno, "Out of memory"); - memcpy(rule->result, start_subst, end_pattern - start_subst); - rule->result[end_pattern - start_subst] = '\0'; - - rule->global = 0; - rule->print = 0; - rule->symlink = 0; - - while (*++end_pattern) { - switch (*end_pattern) { - case 'g': - case 'G': - rule->global = 1; - break; - case 'p': - case 'P': - rule->print = 1; - break; - case 's': - case 'S': - rule->symlink = 1; - break; - default: - lafe_errc(1, 0, "Invalid replacement flag %c", *end_pattern); - } - } -} - -static void -realloc_strncat(char **str, const char *append, size_t len) -{ - char *new_str; - size_t old_len; - - if (*str == NULL) - old_len = 0; - else - old_len = strlen(*str); - - new_str = malloc(old_len + len + 1); - if (new_str == NULL) - lafe_errc(1, errno, "Out of memory"); - memcpy(new_str, *str, old_len); - memcpy(new_str + old_len, append, len); - new_str[old_len + len] = '\0'; - free(*str); - *str = new_str; -} - -static void -realloc_strcat(char **str, const char *append) -{ - char *new_str; - size_t old_len; - - if (*str == NULL) - old_len = 0; - else - old_len = strlen(*str); - - new_str = malloc(old_len + strlen(append) + 1); - if (new_str == NULL) - lafe_errc(1, errno, "Out of memory"); - memcpy(new_str, *str, old_len); - strcpy(new_str + old_len, append); - free(*str); - *str = new_str; -} - -int -apply_substitution(struct bsdtar *bsdtar, const char *name, char **result, int symlink_only) -{ - const char *path = name; - regmatch_t matches[10]; - size_t i, j; - struct subst_rule *rule; - struct substitution *subst; - int c, got_match, print_match; - - *result = NULL; - - if ((subst = bsdtar->substitution) == NULL) - return 0; - - got_match = 0; - print_match = 0; - - for (rule = subst->first_rule; rule != NULL; rule = rule->next) { - if (symlink_only && !rule->symlink) - continue; - if (regexec(&rule->re, name, 10, matches, 0)) - continue; - - got_match = 1; - print_match |= rule->print; - realloc_strncat(result, name, matches[0].rm_so); - - for (i = 0, j = 0; rule->result[i] != '\0'; ++i) { - if (rule->result[i] == '~') { - realloc_strncat(result, rule->result + j, i - j); - realloc_strncat(result, name, matches[0].rm_eo); - j = i + 1; - continue; - } - if (rule->result[i] != '\\') - continue; - - ++i; - c = rule->result[i]; - switch (c) { - case '~': - case '\\': - realloc_strncat(result, rule->result + j, i - j - 1); - j = i; - break; - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - realloc_strncat(result, rule->result + j, i - j - 1); - if ((size_t)(c - '0') > (size_t)(rule->re.re_nsub)) { - free(*result); - *result = NULL; - return -1; - } - realloc_strncat(result, name + matches[c - '0'].rm_so, matches[c - '0'].rm_eo - matches[c - '0'].rm_so); - j = i + 1; - break; - default: - /* Just continue; */ - break; - } - - } - - realloc_strcat(result, rule->result + j); - - name += matches[0].rm_eo; - - if (!rule->global) - break; - } - - if (got_match) - realloc_strcat(result, name); - - if (print_match) - fprintf(stderr, "%s >> %s\n", path, *result); - - return got_match; -} - -void -cleanup_substitution(struct bsdtar *bsdtar) -{ - struct subst_rule *rule; - struct substitution *subst; - - if ((subst = bsdtar->substitution) == NULL) - return; - - while ((rule = subst->first_rule) != NULL) { - subst->first_rule = rule->next; - free(rule->result); - free(rule); - } - free(subst); -} -#endif /* HAVE_REGEX_H */ diff --git a/Utilities/cmlibarchive/tar/test/CMakeLists.txt b/Utilities/cmlibarchive/tar/test/CMakeLists.txt deleted file mode 100644 index 81870c482..000000000 --- a/Utilities/cmlibarchive/tar/test/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -############################################ -# -# How to build bsdtar_test -# -############################################ -IF(ENABLE_TAR AND ENABLE_TEST) - SET(bsdtar_test_SOURCES - ../getdate.c - main.c - test.h - test_0.c - test_basic.c - test_copy.c - test_getdate.c - test_help.c - test_option_T_upper.c - test_option_q.c - test_option_r.c - test_option_s.c - test_patterns.c - test_stdio.c - test_strip_components.c - test_symlink_dir.c - test_version.c - test_windows.c - ) - IF(WIN32 AND NOT CYGWIN) - LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.c) - LIST(APPEND bsdtar_test_SOURCES ../bsdtar_windows.h) - ENDIF(WIN32 AND NOT CYGWIN) - - # - # Generate the list.h - # - GENERATE_LIST_H(${CMAKE_CURRENT_BINARY_DIR}/list.h - ${CMAKE_CURRENT_LIST_FILE} ${bsdtar_test_SOURCES}) - SET_PROPERTY(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_BINARY_DIR}) - # - # Register target - # - ADD_EXECUTABLE(bsdtar_test ${bsdtar_test_SOURCES}) - SET_PROPERTY(TARGET bsdtar_test PROPERTY COMPILE_DEFINITIONS LIST_H) - - # ADD_TEST() for each separate test - SET(num 0) - FOREACH(test ${bsdtar_test_SOURCES}) - IF(test MATCHES "^test_[^/]+[.]c$") - STRING(REGEX REPLACE "^(test_[^/]+)[.]c$" "\\1" testname ${test}) - ADD_TEST("bsdtar_${testname}" bsdtar_test - -q -v -p ${BSDTAR} -r ${CMAKE_CURRENT_SOURCE_DIR} ${num}) - MATH(EXPR num "${num} + 1") - ENDIF(test MATCHES "^test_[^/]+[.]c$") - ENDFOREACH(test) - - # Experimental new test handling - ADD_CUSTOM_TARGET(run_bsdtar_test - COMMAND bsdtar_test -p ${BSDTAR} -r ${CMAKE_CURRENT_SOURCE_DIR}) - ADD_DEPENDENCIES(run_bsdtar_test bsdtar) - ADD_DEPENDENCIES(run_all_tests run_bsdtar_test) - -ENDIF (ENABLE_TAR AND ENABLE_TEST) diff --git a/Utilities/cmlibarchive/tar/test/main.c b/Utilities/cmlibarchive/tar/test/main.c deleted file mode 100644 index 9815a8543..000000000 --- a/Utilities/cmlibarchive/tar/test/main.c +++ /dev/null @@ -1,2057 +0,0 @@ -/* - * Copyright (c) 2003-2009 Tim Kientzle - * 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 -#include -#include -#include -#include "test.h" - -/* - * This same file is used pretty much verbatim for all test harnesses. - * - * The next few lines are the only differences. - * TODO: Move this into a separate configuration header, have all test - * suites share one copy of this file. - */ -__FBSDID("$FreeBSD: src/usr.bin/tar/test/main.c,v 1.6 2008/11/05 06:40:53 kientzle Exp $"); -#define KNOWNREF "test_patterns_2.tar.uu" -#define ENVBASE "BSDTAR" /* Prefix for environment variables. */ -#define PROGRAM "bsdtar" /* Name of program being tested. */ -#undef LIBRARY /* Not testing a library. */ -#undef EXTRA_DUMP /* How to dump extra data */ -/* How to generate extra version info. */ -#define EXTRA_VERSION (systemf("%s --version", testprog) ? "" : "") - -/* - * - * Windows support routines - * - * Note: Configuration is a tricky issue. Using HAVE_* feature macros - * in the test harness is dangerous because they cover up - * configuration errors. The classic example of this is omitting a - * configure check. If libarchive and libarchive_test both look for - * the same feature macro, such errors are hard to detect. Platform - * macros (e.g., _WIN32 or __GNUC__) are a little better, but can - * easily lead to very messy code. It's best to limit yourself - * to only the most generic programming techniques in the test harness - * and thus avoid conditionals altogether. Where that's not possible, - * try to minimize conditionals by grouping platform-specific tests in - * one place (e.g., test_acl_freebsd) or by adding new assert() - * functions (e.g., assertMakeHardlink()) to cover up platform - * differences. Platform-specific coding in libarchive_test is often - * a symptom that some capability is missing from libarchive itself. - */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#if !defined(__GNUC__) -#include -#endif -#include -#include -#ifndef F_OK -#define F_OK (0) -#endif -#ifndef S_ISDIR -#define S_ISDIR(m) ((m) & _S_IFDIR) -#endif -#ifndef S_ISREG -#define S_ISREG(m) ((m) & _S_IFREG) -#endif -#define access _access -#ifndef fileno -#define fileno _fileno -#endif -/*#define fstat _fstat64*/ -#define getcwd _getcwd -#define lstat stat -/*#define lstat _stat64*/ -/*#define stat _stat64*/ -#define rmdir _rmdir -#define strdup _strdup -#define umask _umask -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -void *GetFunctionKernel32(const char *name) -{ - static HINSTANCE lib; - static int set; - if (!set) { - set = 1; - lib = LoadLibrary("kernel32.dll"); - } - if (lib == NULL) { - fprintf(stderr, "Can't load kernel32.dll?!\n"); - exit(1); - } - return (void *)GetProcAddress(lib, name); -} - -static int -my_CreateSymbolicLinkA(const char *linkname, const char *target, int flags) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, DWORD); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateSymbolicLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, flags); -} - -static int -my_CreateHardLinkA(const char *linkname, const char *target) -{ - static BOOLEAN (WINAPI *f)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); - static int set; - if (!set) { - set = 1; - f = GetFunctionKernel32("CreateHardLinkA"); - } - return f == NULL ? 0 : (*f)(linkname, target, NULL); -} - -int -my_GetFileInformationByName(const char *path, BY_HANDLE_FILE_INFORMATION *bhfi) -{ - HANDLE h; - int r; - - h = CreateFile(path, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) - return (0); - r = GetFileInformationByHandle(h, bhfi); - CloseHandle(h); - return (r); -} -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) -static void -invalid_parameter_handler(const wchar_t * expression, - const wchar_t * function, const wchar_t * file, - unsigned int line, uintptr_t pReserved) -{ - /* nop */ -} -#endif - -/* - * - * OPTIONS FLAGS - * - */ - -/* Enable core dump on failure. */ -static int dump_on_failure = 0; -/* Default is to remove temp dirs and log data for successful tests. */ -static int keep_temp_files = 0; -/* Default is to just report pass/fail for each test. */ -static int verbosity = 0; -#define VERBOSITY_SUMMARY_ONLY -1 /* -q */ -#define VERBOSITY_PASSFAIL 0 /* Default */ -#define VERBOSITY_LIGHT_REPORT 1 /* -v */ -#define VERBOSITY_FULL 2 /* -vv */ -/* A few places generate even more output for verbosity > VERBOSITY_FULL, - * mostly for debugging the test harness itself. */ -/* Cumulative count of assertion failures. */ -static int failures = 0; -/* Cumulative count of reported skips. */ -static int skips = 0; -/* Cumulative count of assertions checked. */ -static int assertions = 0; - -/* Directory where uuencoded reference files can be found. */ -static const char *refdir; - -/* - * Report log information selectively to console and/or disk log. - */ -static int log_console = 0; -static FILE *logfile; -static void -vlogprintf(const char *fmt, va_list ap) -{ - if (log_console) - vfprintf(stdout, fmt, ap); - if (logfile != NULL) - vfprintf(logfile, fmt, ap); -} - -static void -logprintf(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vlogprintf(fmt, ap); - va_end(ap); -} - -/* Set up a message to display only if next assertion fails. */ -static char msgbuff[4096]; -static const char *msg, *nextmsg; -void -failure(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); - va_end(ap); - nextmsg = msgbuff; -} - -/* - * Copy arguments into file-local variables. - * This was added to permit vararg assert() functions without needing - * variadic wrapper macros. Turns out that the vararg capability is almost - * never used, so almost all of the vararg assertions can be simplified - * by removing the vararg capability and reworking the wrapper macro to - * pass __FILE__, __LINE__ directly into the function instead of using - * this hook. I suspect this machinery is used so rarely that we - * would be better off just removing it entirely. That would simplify - * the code here noticably. - */ -static const char *test_filename; -static int test_line; -static void *test_extra; -void assertion_setup(const char *filename, int line) -{ - test_filename = filename; - test_line = line; -} - -/* Called at the beginning of each assert() function. */ -static void -assertion_count(const char *file, int line) -{ - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - ++assertions; - /* Proper handling of "failure()" message. */ - msg = nextmsg; - nextmsg = NULL; - /* Uncomment to print file:line after every assertion. - * Verbose, but occasionally useful in tracking down crashes. */ - /* printf("Checked %s:%d\n", file, line); */ -} - -/* - * For each test source file, we remember how many times each - * assertion was reported. Cleared before each new test, - * used by test_summarize(). - */ -static struct line { - int count; - int skip; -} failed_lines[10000]; - -/* Count this failure, setup up log destination and handle initial report. */ -static void -failure_start(const char *filename, int line, const char *fmt, ...) -{ - va_list ap; - - /* Record another failure for this line. */ - ++failures; - /* test_filename = filename; */ - failed_lines[line].count++; - - /* Determine whether to log header to console. */ - switch (verbosity) { - case VERBOSITY_FULL: - log_console = 1; - break; - case VERBOSITY_LIGHT_REPORT: - log_console = (failed_lines[line].count < 2); - break; - default: - log_console = 0; - } - - /* Log file:line header for this failure */ - va_start(ap, fmt); -#if _MSC_VER - logprintf("%s(%d): ", filename, line); -#else - logprintf("%s:%d: ", filename, line); -#endif - vlogprintf(fmt, ap); - va_end(ap); - logprintf("\n"); - - if (msg != NULL && msg[0] != '\0') { - logprintf(" Description: %s\n", msg); - msg = NULL; - } - - /* Determine whether to log details to console. */ - if (verbosity == VERBOSITY_LIGHT_REPORT) - log_console = 0; -} - -/* Complete reporting of failed tests. */ -/* - * The 'extra' hook here is used by libarchive to include libarchive - * error messages with assertion failures. It could also be used - * to add strerror() output, for example. Just define the EXTRA_DUMP() - * macro appropriately. - */ -static void -failure_finish(void *extra) -{ - (void)extra; /* UNUSED (maybe) */ -#ifdef EXTRA_DUMP - if (extra != NULL) - logprintf(" detail: %s\n", EXTRA_DUMP(extra)); -#endif - - if (dump_on_failure) { - fprintf(stderr, - " *** forcing core dump so failure can be debugged ***\n"); - *(char *)(NULL) = 0; - exit(1); - } -} - -/* Inform user that we're skipping some checks. */ -void -test_skipping(const char *fmt, ...) -{ - char buff[1024]; - va_list ap; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - va_end(ap); - /* failure_start() isn't quite right, but is awfully convenient. */ - failure_start(test_filename, test_line, "SKIPPING: %s", buff); - --failures; /* Undo failures++ in failure_start() */ - /* Don't failure_finish() here. */ - /* Mark as skip, so doesn't count as failed test. */ - failed_lines[test_line].skip = 1; - ++skips; -} - -/* - * - * ASSERTIONS - * - */ - -/* Generic assert() just displays the failed condition. */ -int -assertion_assert(const char *file, int line, int value, - const char *condition, void *extra) -{ - assertion_count(file, line); - if (!value) { - failure_start(file, line, "Assertion failed: %s", condition); - failure_finish(extra); - } - return (value); -} - -/* chdir() and report any errors */ -int -assertion_chdir(const char *file, int line, const char *pathname) -{ - assertion_count(file, line); - if (chdir(pathname) == 0) - return (1); - failure_start(file, line, "chdir(\"%s\")", pathname); - failure_finish(NULL); - return (0); - -} - -/* Verify two integers are equal. */ -int -assertion_equal_int(const char *file, int line, - long long v1, const char *e1, long long v2, const char *e2, void *extra) -{ - assertion_count(file, line); - if (v1 == v2) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e1, v1, v1, v1); - logprintf(" %s=%lld (0x%llx, 0%llo)\n", e2, v2, v2, v2); - failure_finish(extra); - return (0); -} - -static void strdump(const char *e, const char *p) -{ - const char *q = p; - - logprintf(" %s = ", e); - if (p == NULL) { - logprintf("NULL"); - return; - } - logprintf("\""); - while (*p != '\0') { - unsigned int c = 0xff & *p++; - switch (c) { - case '\a': printf("\a"); break; - case '\b': printf("\b"); break; - case '\n': printf("\n"); break; - case '\r': printf("\r"); break; - default: - if (c >= 32 && c < 127) - logprintf("%c", c); - else - logprintf("\\x%02X", c); - } - } - logprintf("\""); - logprintf(" (length %d)\n", q == NULL ? -1 : (int)strlen(q)); -} - -/* Verify two strings are equal, dump them if not. */ -int -assertion_equal_string(const char *file, int line, - const char *v1, const char *e1, - const char *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || strcmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - strdump(e1, v1); - strdump(e2, v2); - failure_finish(extra); - return (0); -} - -static void -wcsdump(const char *e, const wchar_t *w) -{ - logprintf(" %s = ", e); - if (w == NULL) { - logprintf("(null)"); - return; - } - logprintf("\""); - while (*w != L'\0') { - unsigned int c = *w++; - if (c >= 32 && c < 127) - logprintf("%c", c); - else if (c < 256) - logprintf("\\x%02X", c); - else if (c < 0x10000) - logprintf("\\u%04X", c); - else - logprintf("\\U%08X", c); - } - logprintf("\"\n"); -} - -/* Verify that two wide strings are equal, dump them if not. */ -int -assertion_equal_wstring(const char *file, int line, - const wchar_t *v1, const char *e1, - const wchar_t *v2, const char *e2, - void *extra) -{ - assertion_count(file, line); - if (v1 == v2 || wcscmp(v1, v2) == 0) - return (1); - failure_start(file, line, "%s != %s", e1, e2); - wcsdump(e1, v1); - wcsdump(e2, v2); - failure_finish(extra); - return (0); -} - -/* - * Pretty standard hexdump routine. As a bonus, if ref != NULL, then - * any bytes in p that differ from ref will be highlighted with '_' - * before and after the hex value. - */ -static void -hexdump(const char *p, const char *ref, size_t l, size_t offset) -{ - size_t i, j; - char sep; - - for(i=0; i < l; i+=16) { - logprintf("%04x", (unsigned)(i + offset)); - sep = ' '; - for (j = 0; j < 16 && i + j < l; j++) { - if (ref != NULL && p[i + j] != ref[i + j]) - sep = '_'; - logprintf("%c%02x", sep, 0xff & (int)p[i+j]); - if (ref != NULL && p[i + j] == ref[i + j]) - sep = ' '; - } - for (; j < 16; j++) { - logprintf("%c ", sep); - sep = ' '; - } - logprintf("%c", sep); - for (j=0; j < 16 && i + j < l; j++) { - int c = p[i + j]; - if (c >= ' ' && c <= 126) - logprintf("%c", c); - else - logprintf("."); - } - logprintf("\n"); - } -} - -/* Verify that two blocks of memory are the same, display the first - * block of differences if they're not. */ -int -assertion_equal_mem(const char *file, int line, - const void *_v1, const char *e1, - const void *_v2, const char *e2, - size_t l, const char *ld, void *extra) -{ - const char *v1 = (const char *)_v1; - const char *v2 = (const char *)_v2; - size_t offset; - - assertion_count(file, line); - if (v1 == v2 || memcmp(v1, v2, l) == 0) - return (1); - - failure_start(file, line, "%s != %s", e1, e2); - logprintf(" size %s = %d\n", ld, (int)l); - /* Dump 48 bytes (3 lines) so that the first difference is - * in the second line. */ - offset = 0; - while (l > 64 && memcmp(v1, v2, 32) == 0) { - /* Two lines agree, so step forward one line. */ - v1 += 16; - v2 += 16; - l -= 16; - offset += 16; - } - logprintf(" Dump of %s\n", e1); - hexdump(v1, v2, l < 64 ? l : 64, offset); - logprintf(" Dump of %s\n", e2); - hexdump(v2, v1, l < 64 ? l : 64, offset); - logprintf("\n"); - failure_finish(extra); - return (0); -} - -/* Verify that the named file exists and is empty. */ -int -assertion_empty_file(const char *f1fmt, ...) -{ - char buff[1024]; - char f1[1024]; - struct stat st; - va_list ap; - ssize_t s; - FILE *f; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) - return (1); - - failure_start(test_filename, test_line, "File should be empty: %s", f1); - logprintf(" File size: %d\n", (int)st.st_size); - logprintf(" Contents:\n"); - f = fopen(f1, "rb"); - if (f == NULL) { - logprintf(" Unable to open %s\n", f1); - } else { - s = ((off_t)sizeof(buff) < st.st_size) ? - (ssize_t)sizeof(buff) : (ssize_t)st.st_size; - s = fread(buff, 1, s, f); - hexdump(buff, NULL, s, 0); - fclose(f); - } - failure_finish(NULL); - return (0); -} - -/* Verify that the named file exists and is not empty. */ -int -assertion_non_empty_file(const char *f1fmt, ...) -{ - char f1[1024]; - struct stat st; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, f1fmt); - vsprintf(f1, f1fmt, ap); - va_end(ap); - - if (stat(f1, &st) != 0) { - failure_start(test_filename, test_line, "Stat failed: %s", f1); - failure_finish(NULL); - return (0); - } - if (st.st_size == 0) { - failure_start(test_filename, test_line, "File empty: %s", f1); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify that two files have the same contents. */ -/* TODO: hexdump the first bytes that actually differ. */ -int -assertion_equal_file(const char *fn1, const char *f2pattern, ...) -{ - char fn2[1024]; - va_list ap; - char buff1[1024]; - char buff2[1024]; - FILE *f1, *f2; - int n1, n2; - - assertion_count(test_filename, test_line); - va_start(ap, f2pattern); - vsprintf(fn2, f2pattern, ap); - va_end(ap); - - f1 = fopen(fn1, "rb"); - f2 = fopen(fn2, "rb"); - for (;;) { - n1 = fread(buff1, 1, sizeof(buff1), f1); - n2 = fread(buff2, 1, sizeof(buff2), f2); - if (n1 != n2) - break; - if (n1 == 0 && n2 == 0) { - fclose(f1); - fclose(f2); - return (1); - } - if (memcmp(buff1, buff2, n1) != 0) - break; - } - fclose(f1); - fclose(f2); - failure_start(test_filename, test_line, "Files not identical"); - logprintf(" file1=\"%s\"\n", fn1); - logprintf(" file2=\"%s\"\n", fn2); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file does exist. */ -int -assertion_file_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (!_access(f, 0)) - return (1); -#else - if (!access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Verify that the named file doesn't exist. */ -int -assertion_file_not_exists(const char *fpattern, ...) -{ - char f[1024]; - va_list ap; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(f, fpattern, ap); - va_end(ap); - -#if defined(_WIN32) && !defined(__CYGWIN__) - if (_access(f, 0)) - return (1); -#else - if (access(f, F_OK)) - return (1); -#endif - failure_start(test_filename, test_line, "File should not exist: %s", f); - failure_finish(test_extra); - return (0); -} - -/* Compare the contents of a file to a block of memory. */ -int -assertion_file_contents(const void *buff, int s, const char *fpattern, ...) -{ - char fn[1024]; - va_list ap; - char *contents; - FILE *f; - int n; - - assertion_count(test_filename, test_line); - va_start(ap, fpattern); - vsprintf(fn, fpattern, ap); - va_end(ap); - - f = fopen(fn, "rb"); - if (f == NULL) { - failure_start(test_filename, test_line, - "File should exist: %s", fn); - failure_finish(test_extra); - return (0); - } - contents = malloc(s * 2); - n = fread(contents, 1, s * 2, f); - fclose(f); - if (n == s && memcmp(buff, contents, s) == 0) { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "File contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n > 512 ? 512 : n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s > 512 ? 512 : n, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Check the contents of a text file, being tolerant of line endings. */ -int -assertion_text_file_contents(const char *buff, const char *fn) -{ - char *contents; - const char *btxt, *ftxt; - FILE *f; - int n, s; - - assertion_count(test_filename, test_line); - f = fopen(fn, "r"); - s = strlen(buff); - contents = malloc(s * 2 + 128); - n = fread(contents, 1, s * 2 + 128 - 1, f); - if (n >= 0) - contents[n] = '\0'; - fclose(f); - /* Compare texts. */ - btxt = buff; - ftxt = (const char *)contents; - while (*btxt != '\0' && *ftxt != '\0') { - if (*btxt == *ftxt) { - ++btxt; - ++ftxt; - continue; - } - if (btxt[0] == '\n' && ftxt[0] == '\r' && ftxt[1] == '\n') { - /* Pass over different new line characters. */ - ++btxt; - ftxt += 2; - continue; - } - break; - } - if (*btxt == '\0' && *ftxt == '\0') { - free(contents); - return (1); - } - failure_start(test_filename, test_line, "Contents don't match"); - logprintf(" file=\"%s\"\n", fn); - if (n > 0) - hexdump(contents, buff, n, 0); - else { - logprintf(" File empty, contents should be:\n"); - hexdump(buff, NULL, s, 0); - } - failure_finish(test_extra); - free(contents); - return (0); -} - -/* Test that two paths point to the same file. */ -/* As a side-effect, asserts that both files exist. */ -static int -is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi1, bhfi2; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(path1, &bhfi1); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path1); - failure_finish(NULL); - return (0); - } - r = my_GetFileInformationByName(path2, &bhfi2); - if (r == 0) { - failure_start(file, line, "File %s can't be inspected?", path2); - failure_finish(NULL); - return (0); - } - return (bhfi1.nFileIndexHigh == bhfi2.nFileIndexHigh - && bhfi1.nFileIndexLow == bhfi2.nFileIndexLow); -#else - struct stat st1, st2; - int r; - - assertion_count(file, line); - r = lstat(path1, &st1); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path1); - failure_finish(NULL); - return (0); - } - r = lstat(path2, &st2); - if (r != 0) { - failure_start(file, line, "File should exist: %s", path2); - failure_finish(NULL); - return (0); - } - return (st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev); -#endif -} - -int -assertion_is_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s are not hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -int -assertion_is_not_hardlink(const char *file, int line, - const char *path1, const char *path2) -{ - if (!is_hardlink(file, line, path1, path2)) - return (1); - failure_start(file, line, - "Files %s and %s should not be hardlinked", path1, path2); - failure_finish(NULL); - return (0); -} - -/* Verify a/b/mtime of 'pathname'. */ -/* If 'recent', verify that it's within last 10 seconds. */ -static int -assertion_file_time(const char *file, int line, - const char *pathname, long t, long nsec, char type, int recent) -{ - long long filet, filet_nsec; - int r; - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define EPOC_TIME (116444736000000000ULL) - FILETIME ftime, fbirthtime, fatime, fmtime; - ULARGE_INTEGER wintm; - HANDLE h; - ftime.dwLowDateTime = 0; - ftime.dwHighDateTime = 0; - - assertion_count(file, line); - h = CreateFile(pathname, FILE_READ_ATTRIBUTES, 0, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (h == INVALID_HANDLE_VALUE) { - failure_start(file, line, "Can't access %s\n", pathname); - failure_finish(NULL); - return (0); - } - r = GetFileTime(h, &fbirthtime, &fatime, &fmtime); - switch (type) { - case 'a': ftime = fatime; break; - case 'b': ftime = fbirthtime; break; - case 'm': ftime = fmtime; break; - } - CloseHandle(h); - if (r == 0) { - failure_start(file, line, "Can't GetFileTime %s\n", pathname); - failure_finish(NULL); - return (0); - } - wintm.LowPart = ftime.dwLowDateTime; - wintm.HighPart = ftime.dwHighDateTime; - filet = (wintm.QuadPart - EPOC_TIME) / 10000000; - filet_nsec = ((wintm.QuadPart - EPOC_TIME) % 10000000) * 100; - nsec = (nsec / 100) * 100; /* Round the request */ -#else - struct stat st; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Can't stat %s\n", pathname); - failure_finish(NULL); - return (0); - } - switch (type) { - case 'a': filet = st.st_atime; break; - case 'm': filet = st.st_mtime; break; - case 'b': filet = 0; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } -#if defined(__FreeBSD__) - switch (type) { - case 'a': filet_nsec = st.st_atimespec.tv_nsec; break; - case 'b': filet = st.st_birthtime; - filet_nsec = st.st_birthtimespec.tv_nsec; break; - case 'm': filet_nsec = st.st_mtimespec.tv_nsec; break; - default: fprintf(stderr, "INTERNAL: Bad type %c for file time", type); - exit(1); - } - /* FreeBSD generally only stores to microsecond res, so round. */ - filet_nsec = (filet_nsec / 1000) * 1000; - nsec = (nsec / 1000) * 1000; -#else - filet_nsec = nsec = 0; /* Generic POSIX only has whole seconds. */ - if (type == 'b') return (1); /* Generic POSIX doesn't have birthtime */ -#endif -#endif - if (recent) { - /* Check that requested time is up-to-date. */ - time_t now = time(NULL); - if (filet < now - 10 || filet > now + 1) { - failure_start(file, line, - "File %s has %ctime %ld, %ld seconds ago\n", - pathname, type, filet, now - filet); - failure_finish(NULL); - return (0); - } - } else if (filet != t || filet_nsec != nsec) { - failure_start(file, line, - "File %s has %ctime %ld.%09ld, expected %ld.%09ld", - pathname, type, filet, filet_nsec, t, nsec); - failure_finish(NULL); - return (0); - } - return (1); -} - -/* Verify atime of 'pathname'. */ -int -assertion_file_atime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'a', 0); -} - -/* Verify atime of 'pathname' is up-to-date. */ -int -assertion_file_atime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'a', 1); -} - -/* Verify birthtime of 'pathname'. */ -int -assertion_file_birthtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'b', 0); -} - -/* Verify birthtime of 'pathname' is up-to-date. */ -int -assertion_file_birthtime_recent(const char *file, int line, - const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'b', 1); -} - -/* Verify mtime of 'pathname'. */ -int -assertion_file_mtime(const char *file, int line, - const char *pathname, long t, long nsec) -{ - return assertion_file_time(file, line, pathname, t, nsec, 'm', 0); -} - -/* Verify mtime of 'pathname' is up-to-date. */ -int -assertion_file_mtime_recent(const char *file, int line, const char *pathname) -{ - return assertion_file_time(file, line, pathname, 0, 0, 'm', 1); -} - -/* Verify number of links to 'pathname'. */ -int -assertion_file_nlinks(const char *file, int line, - const char *pathname, int nlinks) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - BY_HANDLE_FILE_INFORMATION bhfi; - int r; - - assertion_count(file, line); - r = my_GetFileInformationByName(pathname, &bhfi); - if (r != 0 && bhfi.nNumberOfLinks == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, bhfi.nNumberOfLinks, nlinks); - failure_finish(NULL); - return (0); -#else - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_nlink == nlinks) - return (1); - failure_start(file, line, "File %s has %d links, expected %d", - pathname, st.st_nlink, nlinks); - failure_finish(NULL); - return (0); -#endif -} - -/* Verify size of 'pathname'. */ -int -assertion_file_size(const char *file, int line, const char *pathname, long size) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r == 0 && st.st_size == size) - return (1); - failure_start(file, line, "File %s has size %ld, expected %ld", - pathname, (long)st.st_size, (long)size); - failure_finish(NULL); - return (0); -} - -/* Assert that 'pathname' is a dir. If mode >= 0, verify that too. */ -int -assertion_is_dir(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, "Dir should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISDIR(st.st_mode)) { - failure_start(file, line, "%s is not a dir", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "Dir %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Verify that 'pathname' is a regular file. If 'mode' is >= 0, - * verify that too. */ -int -assertion_is_reg(const char *file, int line, const char *pathname, int mode) -{ - struct stat st; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0 || !S_ISREG(st.st_mode)) { - failure_start(file, line, "File should exist: %s", pathname); - failure_finish(NULL); - return (0); - } -#if !defined(_WIN32) || defined(__CYGWIN__) - /* Windows doesn't handle permissions the same way as POSIX, - * so just ignore the mode tests. */ - /* TODO: Can we do better here? */ - if (mode >= 0 && mode != (st.st_mode & 07777)) { - failure_start(file, line, "File %s has wrong mode", pathname); - logprintf(" Expected: 0%3o\n", mode); - logprintf(" Found: 0%3o\n", st.st_mode & 07777); - failure_finish(NULL); - return (0); - } -#endif - return (1); -} - -/* Check whether 'pathname' is a symbolic link. If 'contents' is - * non-NULL, verify that the symlink has those contents. */ -static int -is_symlink(const char *file, int line, - const char *pathname, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - assertion_count(file, line); - /* Windows sort-of has real symlinks, but they're only usable - * by privileged users and are crippled even then, so there's - * really not much point in bothering with this. */ - return (0); -#else - char buff[300]; - struct stat st; - ssize_t linklen; - int r; - - assertion_count(file, line); - r = lstat(pathname, &st); - if (r != 0) { - failure_start(file, line, - "Symlink should exist: %s", pathname); - failure_finish(NULL); - return (0); - } - if (!S_ISLNK(st.st_mode)) - return (0); - if (contents == NULL) - return (1); - linklen = readlink(pathname, buff, sizeof(buff)); - if (linklen < 0) { - failure_start(file, line, "Can't read symlink %s", pathname); - failure_finish(NULL); - return (0); - } - buff[linklen] = '\0'; - if (strcmp(buff, contents) != 0) - return (0); - return (1); -#endif -} - -/* Assert that path is a symlink that (optionally) contains contents. */ -int -assertion_is_symlink(const char *file, int line, - const char *path, const char *contents) -{ - if (is_symlink(file, line, path, contents)) - return (1); - if (contents) - failure_start(file, line, "File %s is not a symlink to %s", - path, contents); - else - failure_start(file, line, "File %s is not a symlink", path); - failure_finish(NULL); - return (0); -} - - -/* Create a directory and report any errors. */ -int -assertion_make_dir(const char *file, int line, const char *dirname, int mode) -{ - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - if (0 == _mkdir(dirname)) - return (1); -#else - if (0 == mkdir(dirname, mode)) - return (1); -#endif - failure_start(file, line, "Could not create directory %s", dirname); - failure_finish(NULL); - return(0); -} - -/* Create a file with the specified contents and report any failures. */ -int -assertion_make_file(const char *file, int line, - const char *path, int mode, const char *contents) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: Rework this to set file mode as well. */ - FILE *f; - assertion_count(file, line); - f = fopen(path, "wb"); - if (f == NULL) { - failure_start(file, line, "Could not create file %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if (strlen(contents) - != fwrite(contents, 1, strlen(contents), f)) { - fclose(f); - failure_start(file, line, - "Could not write file %s", path); - failure_finish(NULL); - return (0); - } - } - fclose(f); - return (1); -#else - int fd; - assertion_count(file, line); - fd = open(path, O_CREAT | O_WRONLY, mode >= 0 ? mode : 0644); - if (fd < 0) { - failure_start(file, line, "Could not create %s", path); - failure_finish(NULL); - return (0); - } - if (contents != NULL) { - if ((ssize_t)strlen(contents) - != write(fd, contents, strlen(contents))) { - close(fd); - failure_start(file, line, "Could not write to %s", path); - failure_finish(NULL); - return (0); - } - } - close(fd); - return (1); -#endif -} - -/* Create a hardlink and report any failures. */ -int -assertion_make_hardlink(const char *file, int line, - const char *newpath, const char *linkto) -{ - int succeeded; - - assertion_count(file, line); -#if defined(_WIN32) && !defined(__CYGWIN__) - succeeded = my_CreateHardLinkA(newpath, linkto); -#elif HAVE_LINK - succeeded = !link(linkto, newpath); -#else - succeeded = 0; -#endif - if (succeeded) - return (1); - failure_start(file, line, "Could not create hardlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Create a symlink and report any failures. */ -int -assertion_make_symlink(const char *file, int line, - const char *newpath, const char *linkto) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - int targetIsDir = 0; /* TODO: Fix this */ - assertion_count(file, line); - if (my_CreateSymbolicLinkA(newpath, linkto, targetIsDir)) - return (1); -#elif HAVE_SYMLINK - assertion_count(file, line); - if (0 == symlink(linkto, newpath)) - return (1); -#endif - failure_start(file, line, "Could not create symlink"); - logprintf(" New link: %s\n", newpath); - logprintf(" Old name: %s\n", linkto); - failure_finish(NULL); - return(0); -} - -/* Set umask, report failures. */ -int -assertion_umask(const char *file, int line, int mask) -{ - assertion_count(file, line); - (void)file; /* UNUSED */ - (void)line; /* UNUSED */ - umask(mask); - return (1); -} - -/* - * - * UTILITIES for use by tests. - * - */ - -/* - * Check whether platform supports symlinks. This is intended - * for tests to use in deciding whether to bother testing symlink - * support; if the platform doesn't support symlinks, there's no point - * in checking whether the program being tested can create them. - * - * Note that the first time this test is called, we actually go out to - * disk to create and verify a symlink. This is necessary because - * symlink support is actually a property of a particular filesystem - * and can thus vary between directories on a single system. After - * the first call, this returns the cached result from memory, so it's - * safe to call it as often as you wish. - */ -int -canSymlink(void) -{ - /* Remember the test result */ - static int value = 0, tested = 0; - if (tested) - return (value); - - ++tested; - assertion_make_file(__FILE__, __LINE__, "canSymlink.0", 0644, "a"); - /* Note: Cygwin has its own symlink() emulation that does not - * use the Win32 CreateSymbolicLink() function. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - value = my_CreateSymbolicLinkA("canSymlink.1", "canSymlink.0", 0) - && is_symlink(__FILE__, __LINE__, "canSymlink.1", "canSymlink.0"); -#elif HAVE_SYMLINK - value = (0 == symlink("canSymlink.0", "canSymlink.1")) - && is_symlink(__FILE__, __LINE__, "canSymlink.1","canSymlink.0"); -#endif - return (value); -} - -/* - * Can this platform run the gzip program? - */ -/* Platform-dependent options for hiding the output of a subcommand. */ -#if defined(_WIN32) && !defined(__CYGWIN__) -static const char *redirectArgs = ">NUL 2>NUL"; /* Win32 cmd.exe */ -#else -static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */ -#endif -int -canGzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Can this platform run the gunzip program? - */ -int -canGunzip(void) -{ - static int tested = 0, value = 0; - if (!tested) { - tested = 1; - if (systemf("gunzip -V %s", redirectArgs) == 0) - value = 1; - } - return (value); -} - -/* - * Sleep as needed; useful for verifying disk timestamp changes by - * ensuring that the wall-clock time has actually changed before we - * go back to re-read something from disk. - */ -void -sleepUntilAfter(time_t t) -{ - while (t >= time(NULL)) -#if defined(_WIN32) && !defined(__CYGWIN__) - Sleep(500); -#else - sleep(1); -#endif -} - -/* - * Call standard system() call, but build up the command line using - * sprintf() conventions. - */ -int -systemf(const char *fmt, ...) -{ - char buff[8192]; - va_list ap; - int r; - - va_start(ap, fmt); - vsprintf(buff, fmt, ap); - if (verbosity > VERBOSITY_FULL) - logprintf("Cmd: %s\n", buff); - r = system(buff); - va_end(ap); - return (r); -} - -/* - * Slurp a file into memory for ease of comparison and testing. - * Returns size of file in 'sizep' if non-NULL, null-terminates - * data in memory for ease of use. - */ -char * -slurpfile(size_t * sizep, const char *fmt, ...) -{ - char filename[8192]; - struct stat st; - va_list ap; - char *p; - ssize_t bytes_read; - FILE *f; - int r; - - va_start(ap, fmt); - vsprintf(filename, fmt, ap); - va_end(ap); - - f = fopen(filename, "rb"); - if (f == NULL) { - /* Note: No error; non-existent file is okay here. */ - return (NULL); - } - r = fstat(fileno(f), &st); - if (r != 0) { - logprintf("Can't stat file %s\n", filename); - fclose(f); - return (NULL); - } - p = malloc((size_t)st.st_size + 1); - if (p == NULL) { - logprintf("Can't allocate %ld bytes of memory to read file %s\n", - (long int)st.st_size, filename); - fclose(f); - return (NULL); - } - bytes_read = fread(p, 1, (size_t)st.st_size, f); - if (bytes_read < st.st_size) { - logprintf("Can't read file %s\n", filename); - fclose(f); - free(p); - return (NULL); - } - p[st.st_size] = '\0'; - if (sizep != NULL) - *sizep = (size_t)st.st_size; - fclose(f); - return (p); -} - -/* Read a uuencoded file from the reference directory, decode, and - * write the result into the current directory. */ -#define UUDECODE(c) (((c) - 0x20) & 0x3f) -void -extract_reference_file(const char *name) -{ - char buff[1024]; - FILE *in, *out; - - sprintf(buff, "%s/%s.uu", refdir, name); - in = fopen(buff, "r"); - failure("Couldn't open reference file %s", buff); - assert(in != NULL); - if (in == NULL) - return; - /* Read up to and including the 'begin' line. */ - for (;;) { - if (fgets(buff, sizeof(buff), in) == NULL) { - /* TODO: This is a failure. */ - return; - } - if (memcmp(buff, "begin ", 6) == 0) - break; - } - /* Now, decode the rest and write it. */ - /* Not a lot of error checking here; the input better be right. */ - out = fopen(name, "wb"); - while (fgets(buff, sizeof(buff), in) != NULL) { - char *p = buff; - int bytes; - - if (memcmp(buff, "end", 3) == 0) - break; - - bytes = UUDECODE(*p++); - while (bytes > 0) { - int n = 0; - /* Write out 1-3 bytes from that. */ - if (bytes > 0) { - n = UUDECODE(*p++) << 18; - n |= UUDECODE(*p++) << 12; - fputc(n >> 16, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++) << 6; - fputc((n >> 8) & 0xFF, out); - --bytes; - } - if (bytes > 0) { - n |= UUDECODE(*p++); - fputc(n & 0xFF, out); - --bytes; - } - } - } - fclose(out); - fclose(in); -} - -/* - * - * TEST management - * - */ - -/* - * "list.h" is simply created by "grep DEFINE_TEST test_*.c"; it has - * a line like - * DEFINE_TEST(test_function) - * for each test. - */ - -/* Use "list.h" to declare all of the test functions. */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); -#include "list.h" - -/* Use "list.h" to create a list of all tests (functions and names). */ -#undef DEFINE_TEST -#define DEFINE_TEST(n) { n, #n, 0 }, -struct { void (*func)(void); const char *name; int failures; } tests[] = { - #include "list.h" -}; - -/* - * Summarize repeated failures in the just-completed test. - */ -static void -test_summarize(const char *filename, int failed) -{ - unsigned int i; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: - printf(failed ? "E" : "."); - fflush(stdout); - break; - case VERBOSITY_PASSFAIL: - printf(failed ? "FAIL\n" : "ok\n"); - break; - } - - log_console = (verbosity == VERBOSITY_LIGHT_REPORT); - - for (i = 0; i < sizeof(failed_lines)/sizeof(failed_lines[0]); i++) { - if (failed_lines[i].count > 1 && !failed_lines[i].skip) - logprintf("%s:%d: Summary: Failed %d times\n", - filename, i, failed_lines[i].count); - } - /* Clear the failure history for the next file. */ - memset(failed_lines, 0, sizeof(failed_lines)); -} - -/* - * Actually run a single test, with appropriate setup and cleanup. - */ -static int -test_run(int i, const char *tmpdir) -{ - char logfilename[64]; - int failures_before = failures; - int oldumask; - - switch (verbosity) { - case VERBOSITY_SUMMARY_ONLY: /* No per-test reports at all */ - break; - case VERBOSITY_PASSFAIL: /* rest of line will include ok/FAIL marker */ - printf("%3d: %-50s", i, tests[i].name); - fflush(stdout); - break; - default: /* Title of test, details will follow */ - printf("%3d: %s\n", i, tests[i].name); - } - - /* Chdir to the top-level work directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, - "ERROR: Can't chdir to top work dir %s\n", tmpdir); - exit(1); - } - /* Create a log file for this test. */ - sprintf(logfilename, "%s.log", tests[i].name); - logfile = fopen(logfilename, "w"); - fprintf(logfile, "%s\n\n", tests[i].name); - /* Chdir() to a work dir for this specific test. */ - if (!assertMakeDir(tests[i].name, 0755) - || !assertChdir(tests[i].name)) { - fprintf(stderr, - "ERROR: Can't chdir to work dir %s/%s\n", - tmpdir, tests[i].name); - exit(1); - } - /* Explicitly reset the locale before each test. */ - setlocale(LC_ALL, "C"); - /* Record the umask before we run the test. */ - umask(oldumask = umask(0)); - /* - * Run the actual test. - */ - (*tests[i].func)(); - /* - * Clean up and report afterwards. - */ - /* Restore umask */ - umask(oldumask); - /* Reset locale. */ - setlocale(LC_ALL, "C"); - /* Reset directory. */ - if (!assertChdir(tmpdir)) { - fprintf(stderr, "ERROR: Couldn't chdir to temp dir %s\n", - tmpdir); - exit(1); - } - /* Report per-test summaries. */ - tests[i].failures = failures - failures_before; - test_summarize(test_filename, tests[i].failures); - /* Close the per-test log file. */ - fclose(logfile); - logfile = NULL; - /* If there were no failures, we can remove the work dir and logfile. */ - if (tests[i].failures == 0) { - if (!keep_temp_files && assertChdir(tmpdir)) { -#if defined(_WIN32) && !defined(__CYGWIN__) - systemf("rmdir /S /Q %s", tests[i].name); - systemf("del %s", logfilename); -#else - systemf("rm -rf %s", tests[i].name); - systemf("rm %s", logfilename); -#endif - } - } - /* Return appropriate status. */ - return (tests[i].failures); -} - -/* - * - * - * MAIN and support routines. - * - * - */ - -static void -usage(const char *program) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i; - - printf("Usage: %s [options] ...\n", program); - printf("Default is to run all tests.\n"); - printf("Otherwise, specify the numbers of the tests you wish to run.\n"); - printf("Options:\n"); - printf(" -d Dump core after any failure, for debugging.\n"); - printf(" -k Keep all temp files.\n"); - printf(" Default: temp files for successful tests deleted.\n"); -#ifdef PROGRAM - printf(" -p Path to executable to be tested.\n"); - printf(" Default: path taken from " ENVBASE " environment variable.\n"); -#endif - printf(" -q Quiet.\n"); - printf(" -r Path to dir containing reference files.\n"); - printf(" Default: Current directory.\n"); - printf(" -v Verbose.\n"); - printf("Available tests:\n"); - for (i = 0; i < limit; i++) - printf(" %d: %s\n", i, tests[i].name); - exit(1); -} - -static char * -get_refdir(const char *d) -{ - char tried[512] = { '\0' }; - char buff[128]; - char *pwd, *p; - - /* If a dir was specified, try that */ - if (d != NULL) { - pwd = NULL; - snprintf(buff, sizeof(buff), "%s", d); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - goto failure; - } - - /* Get the current dir. */ - pwd = getcwd(NULL, 0); - while (pwd[strlen(pwd) - 1] == '\n') - pwd[strlen(pwd) - 1] = '\0'; - - /* Look for a known file. */ - snprintf(buff, sizeof(buff), "%s", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - -#if defined(LIBRARY) - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY); -#else - snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM); -#endif - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - if (memcmp(pwd, "/usr/obj", 8) == 0) { - snprintf(buff, sizeof(buff), "%s", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - - snprintf(buff, sizeof(buff), "%s/test", pwd + 8); - p = slurpfile(NULL, "%s/%s", buff, KNOWNREF); - if (p != NULL) goto success; - strncat(tried, buff, sizeof(tried) - strlen(tried) - 1); - strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1); - } - -failure: - printf("Unable to locate known reference file %s\n", KNOWNREF); - printf(" Checked following directories:\n%s\n", tried); -#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG) - DebugBreak(); -#endif - exit(1); - -success: - free(p); - free(pwd); - return strdup(buff); -} - -int -main(int argc, char **argv) -{ - static const int limit = sizeof(tests) / sizeof(tests[0]); - int i, tests_run = 0, tests_failed = 0, option; - time_t now; - char *refdir_alloc = NULL; - const char *progname; - const char *tmp, *option_arg, *p; - char tmpdir[256]; - char tmpdir_timestamp[256]; - - (void)argc; /* UNUSED */ - -#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__) - /* To stop to run the default invalid parameter handler. */ - _set_invalid_parameter_handler(invalid_parameter_handler); - /* Disable annoying assertion message box. */ - _CrtSetReportMode(_CRT_ASSERT, 0); -#endif - - /* - * Name of this program, used to build root of our temp directory - * tree. - */ - progname = p = argv[0]; - while (*p != '\0') { - /* Support \ or / dir separators for Windows compat. */ - if (*p == '/' || *p == '\\') - progname = p + 1; - ++p; - } - -#ifdef PROGRAM - /* Get the target program from environment, if available. */ - testprogfile = getenv(ENVBASE); -#endif - - if (getenv("TMPDIR") != NULL) - tmp = getenv("TMPDIR"); - else if (getenv("TMP") != NULL) - tmp = getenv("TMP"); - else if (getenv("TEMP") != NULL) - tmp = getenv("TEMP"); - else if (getenv("TEMPDIR") != NULL) - tmp = getenv("TEMPDIR"); - else - tmp = "/tmp"; - - /* Allow -d to be controlled through the environment. */ - if (getenv(ENVBASE "_DEBUG") != NULL) - dump_on_failure = 1; - - /* Get the directory holding test files from environment. */ - refdir = getenv(ENVBASE "_TEST_FILES"); - - /* - * Parse options, without using getopt(), which isn't available - * on all platforms. - */ - ++argv; /* Skip program name */ - while (*argv != NULL) { - if (**argv != '-') - break; - p = *argv++; - ++p; /* Skip '-' */ - while (*p != '\0') { - option = *p++; - option_arg = NULL; - /* If 'opt' takes an argument, parse that. */ - if (option == 'p' || option == 'r') { - if (*p != '\0') - option_arg = p; - else if (*argv == NULL) { - fprintf(stderr, - "Option -%c requires argument.\n", - option); - usage(progname); - } else - option_arg = *argv++; - p = ""; /* End of this option word. */ - } - - /* Now, handle the option. */ - switch (option) { - case 'd': - dump_on_failure = 1; - break; - case 'k': - keep_temp_files = 1; - break; - case 'p': -#ifdef PROGRAM - testprogfile = option_arg; -#else - usage(progname); -#endif - break; - case 'q': - verbosity--; - break; - case 'r': - refdir = option_arg; - break; - case 'v': - verbosity++; - break; - default: - usage(progname); - } - } - } - - /* - * Sanity-check that our options make sense. - */ -#ifdef PROGRAM - if (testprogfile == NULL) - usage(progname); - { - char *testprg; -#if defined(_WIN32) && !defined(__CYGWIN__) - /* Command.com sometimes rejects '/' separators. */ - testprg = strdup(testprogfile); - for (i = 0; testprg[i] != '\0'; i++) { - if (testprg[i] == '/') - testprg[i] = '\\'; - } - testprogfile = testprg; -#endif - /* Quote the name that gets put into shell command lines. */ - testprg = malloc(strlen(testprogfile) + 3); - strcpy(testprg, "\""); - strcat(testprg, testprogfile); - strcat(testprg, "\""); - testprog = testprg; - } -#endif - - /* - * Create a temp directory for the following tests. - * Include the time the tests started as part of the name, - * to make it easier to track the results of multiple tests. - */ - now = time(NULL); - for (i = 0; ; i++) { - strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), - "%Y-%m-%dT%H.%M.%S", - localtime(&now)); - sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname, - tmpdir_timestamp, i); - if (assertMakeDir(tmpdir,0755)) - break; - if (i >= 999) { - fprintf(stderr, - "ERROR: Unable to create temp directory %s\n", - tmpdir); - exit(1); - } - } - - /* - * If the user didn't specify a directory for locating - * reference files, try to find the reference files in - * the "usual places." - */ - refdir = refdir_alloc = get_refdir(refdir); - - /* - * Banner with basic information. - */ - printf("\n"); - printf("If tests fail or crash, details will be in:\n"); - printf(" %s\n", tmpdir); - printf("\n"); - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("Reference files will be read from: %s\n", refdir); -#ifdef PROGRAM - printf("Running tests on: %s\n", testprog); -#endif - printf("Exercising: "); - fflush(stdout); - printf("%s\n", EXTRA_VERSION); - } else { - printf("Running "); - fflush(stdout); - } - - /* - * Run some or all of the individual tests. - */ - if (*argv == NULL) { - /* Default: Run all tests. */ - for (i = 0; i < limit; i++) { - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - } - } else { - while (*(argv) != NULL) { - if (**argv >= '0' && **argv <= '9') { - i = atoi(*argv); - if (i < 0 || i >= limit) { - printf("*** INVALID Test %s\n", *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } else { - for (i = 0; i < limit; ++i) { - if (strcmp(*argv, tests[i].name) == 0) - break; - } - if (i >= limit) { - printf("*** INVALID Test ``%s''\n", - *argv); - free(refdir_alloc); - usage(progname); - /* usage() never returns */ - } - } - if (test_run(i, tmpdir)) - tests_failed++; - tests_run++; - argv++; - } - } - - /* - * Report summary statistics. - */ - if (verbosity > VERBOSITY_SUMMARY_ONLY) { - printf("\n"); - printf("Totals:\n"); - printf(" Tests run: %8d\n", tests_run); - printf(" Tests failed: %8d\n", tests_failed); - printf(" Assertions checked:%8d\n", assertions); - printf(" Assertions failed: %8d\n", failures); - printf(" Skips reported: %8d\n", skips); - } - if (failures) { - printf("\n"); - printf("Failing tests:\n"); - for (i = 0; i < limit; ++i) { - if (tests[i].failures) - printf(" %d: %s (%d failures)\n", i, - tests[i].name, tests[i].failures); - } - printf("\n"); - printf("Details for failing tests: %s\n", tmpdir); - printf("\n"); - } else { - if (verbosity == VERBOSITY_SUMMARY_ONLY) - printf("\n"); - printf("%d tests passed, no failures\n", tests_run); - } - - free(refdir_alloc); - - /* If the final tmpdir is empty, we can remove it. */ - /* This should be the usual case when all tests succeed. */ - assertChdir(".."); - rmdir(tmpdir); - - return (tests_failed ? 1 : 0); -} diff --git a/Utilities/cmlibarchive/tar/test/test.h b/Utilities/cmlibarchive/tar/test/test.h deleted file mode 100644 index 814da13fb..000000000 --- a/Utilities/cmlibarchive/tar/test/test.h +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (c) 2003-2006 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/tar/test/test.h,v 1.4 2008/08/21 07:04:57 kientzle Exp $ - */ - -/* Every test program should #include "test.h" as the first thing. */ - -/* - * The goal of this file (and the matching test.c) is to - * simplify the very repetitive test-*.c test programs. - */ -#if defined(HAVE_CONFIG_H) -/* Most POSIX platforms use the 'configure' script to build config.h */ -#include "config.h" -#elif defined(__FreeBSD__) -/* Building as part of FreeBSD system requires a pre-built config.h. */ -#include "config_freebsd.h" -#elif defined(_WIN32) && !defined(__CYGWIN__) -/* Win32 can't run the 'configure' script. */ -#include "config_windows.h" -#else -/* Warn if the library hasn't been (automatically or manually) configured. */ -#error Oops: No config.h and no pre-built configuration in test.h. -#endif - -#include /* Windows requires this before sys/stat.h */ -#include - -#ifdef USE_DMALLOC -#include -#endif -#if HAVE_DIRENT_H -#include -#else -#include -#define dirent direct -#endif -#include -#include -#ifdef HAVE_IO_H -#include -#endif -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_WINDOWS_H -#include -#endif - -/* - * System-specific tweaks. We really want to minimize these - * as much as possible, since they make it harder to understand - * the mainline code. - */ - -/* Windows (including Visual Studio and MinGW but not Cygwin) */ -#if defined(_WIN32) && !defined(__CYGWIN__) -#include "../bsdtar_windows.h" -#define strdup _strdup -#define LOCALE_DE "deu" -#else -#define LOCALE_DE "de_DE.UTF-8" -#endif - -/* Visual Studio */ -#ifdef _MSC_VER -#define snprintf sprintf_s -#endif - -/* Cygwin */ -#if defined(__CYGWIN__) -/* Cygwin-1.7.x is lazy about populating nlinks, so don't - * expect it to be accurate. */ -# define NLINKS_INACCURATE_FOR_DIRS -#endif - -/* FreeBSD */ -#ifdef __FreeBSD__ -#include /* For __FBSDID */ -#else -/* Surprisingly, some non-FreeBSD platforms define __FBSDID. */ -#ifndef __FBSDID -#define __FBSDID(a) struct _undefined_hack -#endif -#endif - -#ifndef O_BINARY -#define O_BINARY 0 -#endif - -/* - * Redefine DEFINE_TEST for use in defining the test functions. - */ -#undef DEFINE_TEST -#define DEFINE_TEST(name) void name(void); void name(void) - -/* An implementation of the standard assert() macro */ -#define assert(e) assertion_assert(__FILE__, __LINE__, (e), #e, NULL) -/* chdir() and error if it fails */ -#define assertChdir(path) \ - assertion_chdir(__FILE__, __LINE__, path) -/* Assert two integers are the same. Reports value of each one if not. */ -#define assertEqualInt(v1,v2) \ - assertion_equal_int(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* Assert two strings are the same. Reports value of each one if not. */ -#define assertEqualString(v1,v2) \ - assertion_equal_string(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but v1 and v2 are wchar_t * */ -#define assertEqualWString(v1,v2) \ - assertion_equal_wstring(__FILE__, __LINE__, (v1), #v1, (v2), #v2, NULL) -/* As above, but raw blocks of bytes. */ -#define assertEqualMem(v1, v2, l) \ - assertion_equal_mem(__FILE__, __LINE__, (v1), #v1, (v2), #v2, (l), #l, NULL) -/* Assert two files are the same; allow printf-style expansion of second name. - * See below for comments about variable arguments here... - */ -#define assertEqualFile \ - assertion_setup(__FILE__, __LINE__);assertion_equal_file -/* Assert that a file is empty; supports printf-style arguments. */ -#define assertEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_empty_file -/* Assert that a file is not empty; supports printf-style arguments. */ -#define assertNonEmptyFile \ - assertion_setup(__FILE__, __LINE__);assertion_non_empty_file -#define assertFileAtime(pathname, sec, nsec) \ - assertion_file_atime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileAtimeRecent(pathname) \ - assertion_file_atime_recent(__FILE__, __LINE__, pathname) -#define assertFileBirthtime(pathname, sec, nsec) \ - assertion_file_birthtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileBirthtimeRecent(pathname) \ - assertion_file_birthtime_recent(__FILE__, __LINE__, pathname) -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_exists -/* Assert that a file exists; supports printf-style arguments. */ -#define assertFileNotExists \ - assertion_setup(__FILE__, __LINE__);assertion_file_not_exists -/* Assert that file contents match a string; supports printf-style arguments. */ -#define assertFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_file_contents -#define assertFileMtime(pathname, sec, nsec) \ - assertion_file_mtime(__FILE__, __LINE__, pathname, sec, nsec) -#define assertFileMtimeRecent(pathname) \ - assertion_file_mtime_recent(__FILE__, __LINE__, pathname) -#define assertFileNLinks(pathname, nlinks) \ - assertion_file_nlinks(__FILE__, __LINE__, pathname, nlinks) -#define assertFileSize(pathname, size) \ - assertion_file_size(__FILE__, __LINE__, pathname, size) -#define assertTextFileContents \ - assertion_setup(__FILE__, __LINE__);assertion_text_file_contents -#define assertIsDir(pathname, mode) \ - assertion_is_dir(__FILE__, __LINE__, pathname, mode) -#define assertIsHardlink(path1, path2) \ - assertion_is_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsNotHardlink(path1, path2) \ - assertion_is_not_hardlink(__FILE__, __LINE__, path1, path2) -#define assertIsReg(pathname, mode) \ - assertion_is_reg(__FILE__, __LINE__, pathname, mode) -#define assertIsSymlink(pathname, contents) \ - assertion_is_symlink(__FILE__, __LINE__, pathname, contents) -/* Create a directory, report error if it fails. */ -#define assertMakeDir(dirname, mode) \ - assertion_make_dir(__FILE__, __LINE__, dirname, mode) -#define assertMakeFile(path, mode, contents) \ - assertion_make_file(__FILE__, __LINE__, path, mode, contents) -#define assertMakeHardlink(newfile, oldfile) \ - assertion_make_hardlink(__FILE__, __LINE__, newfile, oldfile) -#define assertMakeSymlink(newfile, linkto) \ - assertion_make_symlink(__FILE__, __LINE__, newfile, linkto) -#define assertUmask(mask) \ - assertion_umask(__FILE__, __LINE__, mask) - -/* - * This would be simple with C99 variadic macros, but I don't want to - * require that. Instead, I insert a function call before each - * skipping() call to pass the file and line information down. Crude, - * but effective. - */ -#define skipping \ - assertion_setup(__FILE__, __LINE__);test_skipping - -/* Function declarations. These are defined in test_utility.c. */ -void failure(const char *fmt, ...); -int assertion_assert(const char *, int, int, const char *, void *); -int assertion_chdir(const char *, int, const char *); -int assertion_empty_file(const char *, ...); -int assertion_equal_file(const char *, const char *, ...); -int assertion_equal_int(const char *, int, long long, const char *, long long, const char *, void *); -int assertion_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *); -int assertion_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *); -int assertion_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *); -int assertion_file_atime(const char *, int, const char *, long, long); -int assertion_file_atime_recent(const char *, int, const char *); -int assertion_file_birthtime(const char *, int, const char *, long, long); -int assertion_file_birthtime_recent(const char *, int, const char *); -int assertion_file_contents(const void *, int, const char *, ...); -int assertion_file_exists(const char *, ...); -int assertion_file_mtime(const char *, int, const char *, long, long); -int assertion_file_mtime_recent(const char *, int, const char *); -int assertion_file_nlinks(const char *, int, const char *, int); -int assertion_file_not_exists(const char *, ...); -int assertion_file_size(const char *, int, const char *, long); -int assertion_is_dir(const char *, int, const char *, int); -int assertion_is_hardlink(const char *, int, const char *, const char *); -int assertion_is_not_hardlink(const char *, int, const char *, const char *); -int assertion_is_reg(const char *, int, const char *, int); -int assertion_is_symlink(const char *, int, const char *, const char *); -int assertion_make_dir(const char *, int, const char *, int); -int assertion_make_file(const char *, int, const char *, int, const char *); -int assertion_make_hardlink(const char *, int, const char *newpath, const char *); -int assertion_make_symlink(const char *, int, const char *newpath, const char *); -int assertion_non_empty_file(const char *, ...); -int assertion_text_file_contents(const char *buff, const char *f); -int assertion_umask(const char *, int, int); -void assertion_setup(const char *, int); - -void test_skipping(const char *fmt, ...); - -/* Like sprintf, then system() */ -int systemf(const char * fmt, ...); - -/* Delay until time() returns a value after this. */ -void sleepUntilAfter(time_t); - -/* Return true if this platform can create symlinks. */ -int canSymlink(void); - -/* Return true if this platform can run the "gzip" program. */ -int canGzip(void); - -/* Return true if this platform can run the "gunzip" program. */ -int canGunzip(void); - -/* Suck file into string allocated via malloc(). Call free() when done. */ -/* Supports printf-style args: slurpfile(NULL, "%s/myfile", refdir); */ -char *slurpfile(size_t *, const char *fmt, ...); - -/* Extracts named reference file to the current directory. */ -void extract_reference_file(const char *); - -/* - * Special interfaces for program test harness. - */ - -/* Pathname of exe to be tested. */ -const char *testprogfile; -/* Name of exe to use in printf-formatted command strings. */ -/* On Windows, this includes leading/trailing quotes. */ -const char *testprog; diff --git a/Utilities/cmlibarchive/tar/test/test_0.c b/Utilities/cmlibarchive/tar/test/test_0.c deleted file mode 100644 index 34a225aa7..000000000 --- a/Utilities/cmlibarchive/tar/test/test_0.c +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - -/* - * This first test does basic sanity checks on the environment. For - * most of these, we just exit on failure. - */ -#if !defined(_WIN32) || defined(__CYGWIN__) -#define DEV_NULL "/dev/null" -#else -#define DEV_NULL "NUL" -#endif - -DEFINE_TEST(test_0) -{ - struct stat st; - - failure("File %s does not exist?!", testprog); - if (!assertEqualInt(0, stat(testprogfile, &st))) - exit(1); - - failure("%s is not executable?!", testprog); - if (!assert((st.st_mode & 0111) != 0)) - exit(1); - - /* - * Try to succesfully run the program; this requires that - * we know some option that will succeed. - */ - if (0 == systemf("%s --version >" DEV_NULL, testprog)) { - /* This worked. */ - } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { - /* This worked. */ - } else { - failure("Unable to successfully run any of the following:\n" - " * %s --version\n" - " * %s -W version\n", - testprog, testprog); - assert(0); - } - - /* TODO: Ensure that our reference files are available. */ -} diff --git a/Utilities/cmlibarchive/tar/test/test_basic.c b/Utilities/cmlibarchive/tar/test/test_basic.c deleted file mode 100644 index ac392d6dc..000000000 --- a/Utilities/cmlibarchive/tar/test/test_basic.c +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_basic.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - - -static void -basic_tar(const char *target, const char *pack_options, - const char *unpack_options, const char *flist) -{ - int r; - - assertMakeDir(target, 0775); - - /* Use the tar program to create an archive. */ - r = systemf("%s cf - %s %s >%s/archive 2>%s/pack.err", testprog, pack_options, flist, target, target); - failure("Error invoking %s cf -", testprog, pack_options); - assertEqualInt(r, 0); - - assertChdir(target); - - /* Verify that nothing went to stderr. */ - assertEmptyFile("pack.err"); - - /* - * Use tar to unpack the archive into another directory. - */ - r = systemf("%s xf archive %s >unpack.out 2>unpack.err", testprog, unpack_options); - failure("Error invoking %s xf archive %s", testprog, unpack_options); - assertEqualInt(r, 0); - - /* Verify that nothing went to stderr. */ - assertEmptyFile("unpack.err"); - - /* - * Verify unpacked files. - */ - - /* Regular file with 2 links. */ - assertIsReg("file", -1); - assertFileSize("file", 10); - failure("%s", target); - assertFileNLinks("file", 2); - - /* Another name for the same file. */ - assertIsReg("linkfile", -1); - assertFileSize("linkfile", 10); - assertFileNLinks("linkfile", 2); - assertIsHardlink("file", "linkfile"); - - /* Symlink */ - if (canSymlink()) - assertIsSymlink("symlink", "file"); - - /* dir */ - assertIsDir("dir", 0775); - assertChdir(".."); -} - -DEFINE_TEST(test_basic) -{ - FILE *f; - const char *flist; - - assertUmask(0); - - /* File with 10 bytes content. */ - f = fopen("file", "wb"); - assert(f != NULL); - assertEqualInt(10, fwrite("123456789", 1, 10, f)); - fclose(f); - - /* hardlink to above file. */ - assertMakeHardlink("linkfile", "file"); - assertIsHardlink("file", "linkfile"); - - /* Symlink to above file. */ - if (canSymlink()) - assertMakeSymlink("symlink", "file"); - - /* Directory. */ - assertMakeDir("dir", 0775); - - if (canSymlink()) - flist = "file linkfile symlink dir"; - else - flist = "file linkfile dir"; - /* Archive/dearchive with a variety of options. */ - basic_tar("copy", "", "", flist); - /* tar doesn't handle cpio symlinks correctly */ - /* basic_tar("copy_odc", "--format=odc", ""); */ - basic_tar("copy_ustar", "--format=ustar", "", flist); -} diff --git a/Utilities/cmlibarchive/tar/test/test_copy.c b/Utilities/cmlibarchive/tar/test/test_copy.c deleted file mode 100644 index b5e4a0bcd..000000000 --- a/Utilities/cmlibarchive/tar/test/test_copy.c +++ /dev/null @@ -1,373 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_copy.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); - -#if defined(__CYGWIN__) -# include -# include -#endif - -/* - * Try to figure out how deep we can go in our tests. Assumes that - * the first call to this function has the longest starting cwd (which - * is currently "/original"). This is mostly to work around - * limits in our Win32 support. - * - * Background: On Posix systems, PATH_MAX is merely a limit on the - * length of the string passed into a system call. By repeatedly - * calling chdir(), you can work with arbitrarily long paths on such - * systems. In contrast, Win32 APIs apply PATH_MAX limits to the full - * absolute path, so the permissible length of a system call argument - * varies with the cwd. Some APIs actually enforce limits - * significantly less than PATH_MAX to ensure that you can create - * files within the current working directory. The Win32 limits also - * apply to Cygwin before 1.7. - * - * Someday, I want to convert the Win32 support to use newer - * wide-character paths with '\\?\' prefix, which has a 32k PATH_MAX - * instead of the rather anemic 260 character limit of the older - * system calls. Then we can drop this mess (unless we want to - * continue to special-case Cygwin 1.5 and earlier). - */ -static int -compute_loop_max(void) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - static int LOOP_MAX = 0; - char buf[MAX_PATH]; - size_t cwdlen; - - if (LOOP_MAX == 0) { - assert(_getcwd(buf, MAX_PATH) != NULL); - cwdlen = strlen(buf); - /* 12 characters = length of 8.3 filename */ - /* 4 characters = length of "/../" used in symlink tests */ - /* 1 character = length of extra "/" separator */ - LOOP_MAX = MAX_PATH - (int)cwdlen - 12 - 4 - 1; - } - return LOOP_MAX; -#elif defined(__CYGWIN__) && !defined(HAVE_CYGWIN_CONV_PATH) - static int LOOP_MAX = 0; - if (LOOP_MAX == 0) { - char wbuf[PATH_MAX]; - char pbuf[PATH_MAX]; - size_t wcwdlen; - size_t pcwdlen; - size_t cwdlen; - assert(getcwd(pbuf, PATH_MAX) != NULL); - pcwdlen = strlen(pbuf); - cygwin_conv_to_full_win32_path(pbuf, wbuf); - wcwdlen = strlen(wbuf); - cwdlen = ((wcwdlen > pcwdlen) ? wcwdlen : pcwdlen); - /* Cygwin helper needs an extra few characters. */ - LOOP_MAX = PATH_MAX - (int)cwdlen - 12 - 4 - 4; - } - return LOOP_MAX; -#else - /* cygwin-1.7 ends up here, along with "normal" unix */ - return 200; /* restore pre-r278 depth */ -#endif -} - -/* filenames[i] is a distinctive filename of length i. */ -/* To simplify interpreting failures, each filename ends with a - * decimal integer which is the length of the filename. E.g., A - * filename ending in "_92" is 92 characters long. To detect errors - * which drop or misplace characters, the filenames use a repeating - * "abcdefghijklmnopqrstuvwxyz..." pattern. */ -static char *filenames[201]; - -static void -compute_filenames(void) -{ - char buff[250]; - size_t i,j; - - filenames[0] = strdup(""); - filenames[1] = strdup("1"); - filenames[2] = strdup("a2"); - for (i = 3; i < sizeof(filenames)/sizeof(filenames[0]); ++i) { - /* Fill with "abcdefghij..." */ - for (j = 0; j < i; ++j) - buff[j] = 'a' + (j % 26); - buff[j--] = '\0'; - /* Work from the end to fill in the number portion. */ - buff[j--] = '0' + (i % 10); - if (i > 9) { - buff[j--] = '0' + ((i / 10) % 10); - if (i > 99) - buff[j--] = '0' + (i / 100); - } - buff[j] = '_'; - /* Guard against obvious screwups in the above code. */ - assertEqualInt(strlen(buff), i); - filenames[i] = strdup(buff); - } -} - -static void -create_tree(void) -{ - char buff[260]; - char buff2[260]; - int i; - int LOOP_MAX; - - compute_filenames(); - - /* Log that we'll be omitting some checks. */ - if (!canSymlink()) { - skipping("Symlink checks"); - } - - assertMakeDir("original", 0775); - chdir("original"); - LOOP_MAX = compute_loop_max(); - - assertMakeDir("f", 0775); - assertMakeDir("l", 0775); - assertMakeDir("m", 0775); - assertMakeDir("s", 0775); - assertMakeDir("d", 0775); - - for (i = 1; i < LOOP_MAX; i++) { - failure("Internal sanity check failed: i = %d", i); - assert(filenames[i] != NULL); - - sprintf(buff, "f/%s", filenames[i]); - assertMakeFile(buff, 0777, buff); - - /* Create a link named "l/abcdef..." to the above. */ - sprintf(buff2, "l/%s", filenames[i]); - assertMakeHardlink(buff2, buff); - - /* Create a link named "m/abcdef..." to the above. */ - sprintf(buff2, "m/%s", filenames[i]); - assertMakeHardlink(buff2, buff); - - if (canSymlink()) { - /* Create a symlink named "s/abcdef..." to the above. */ - sprintf(buff, "s/%s", filenames[i]); - sprintf(buff2, "../f/%s", filenames[i]); - failure("buff=\"%s\" buff2=\"%s\"", buff, buff2); - assertMakeSymlink(buff, buff2); - } - /* Create a dir named "d/abcdef...". */ - buff[0] = 'd'; - failure("buff=\"%s\"", buff); - assertMakeDir(buff, 0775); - } - - chdir(".."); -} - -#define LIMIT_NONE 200 -#define LIMIT_USTAR 100 - -static void -verify_tree(size_t limit) -{ - char name1[260]; - char name2[260]; - size_t i, LOOP_MAX; - - LOOP_MAX = compute_loop_max(); - - /* Generate the names we know should be there and verify them. */ - for (i = 1; i < LOOP_MAX; i++) { - /* Verify a file named "f/abcdef..." */ - sprintf(name1, "f/%s", filenames[i]); - if (i <= limit) { - assertFileExists(name1); - assertFileContents(name1, strlen(name1), name1); - } - - sprintf(name2, "l/%s", filenames[i]); - if (i + 2 <= limit) { - /* Verify hardlink "l/abcdef..." */ - assertIsHardlink(name1, name2); - /* Verify hardlink "m/abcdef..." */ - name2[0] = 'm'; - assertIsHardlink(name1, name2); - } - - if (canSymlink()) { - /* Verify symlink "s/abcdef..." */ - sprintf(name1, "s/%s", filenames[i]); - sprintf(name2, "../f/%s", filenames[i]); - if (strlen(name2) <= limit) - assertIsSymlink(name1, name2); - } - - /* Verify dir "d/abcdef...". */ - sprintf(name1, "d/%s", filenames[i]); - if (i + 1 <= limit) { /* +1 for trailing slash */ - if (assertIsDir(name1, -1)) { - /* TODO: opendir/readdir this - * directory and make sure - * it's empty. - */ - } - } - } - -#if !defined(_WIN32) || defined(__CYGWIN__) - { - const char *dp; - /* Now make sure nothing is there that shouldn't be. */ - for (dp = "dflms"; *dp != '\0'; ++dp) { - DIR *d; - struct dirent *de; - char dir[2]; - dir[0] = *dp; dir[1] = '\0'; - d = opendir(dir); - failure("Unable to open dir '%s'", dir); - if (!assert(d != NULL)) - continue; - while ((de = readdir(d)) != NULL) { - char *p = de->d_name; - if (p[0] == '.') - continue; - switch(dp[0]) { - case 'l': case 'm': case 'd': - failure("strlen(p)=%d", strlen(p)); - assert(strlen(p) < limit); - assertEqualString(p, - filenames[strlen(p)]); - break; - case 'f': case 's': - failure("strlen(p)=%d", strlen(p)); - assert(strlen(p) < limit + 1); - assertEqualString(p, - filenames[strlen(p)]); - break; - default: - failure("File %s shouldn't be here", p); - assert(0); - } - } - closedir(d); - } - } -#endif -} - -static void -copy_basic(void) -{ - int r; - - /* NOTE: for proper operation on cygwin-1.5 and windows, the - * length of the name of the directory below, "plain", must be - * less than or equal to the lengthe of the name of the original - * directory, "original" This restriction derives from the - * extremely limited pathname lengths on those platforms. - */ - assertMakeDir("plain", 0775); - assertEqualInt(0, chdir("plain")); - - /* - * Use the tar program to create an archive. - */ - r = systemf("%s cf archive -C ../original f d l m s >pack.out 2>pack.err", - testprog); - failure("Error invoking \"%s cf\"", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ - assertEmptyFile("pack.err"); - assertEmptyFile("pack.out"); - - /* - * Use tar to unpack the archive into another directory. - */ - r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); - failure("Error invoking %s xf archive", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ - assertEmptyFile("unpack.err"); - assertEmptyFile("unpack.out"); - - verify_tree(LIMIT_NONE); - assertEqualInt(0, chdir("..")); -} - -static void -copy_ustar(void) -{ - const char *target = "ustar"; - int r; - - /* NOTE: for proper operation on cygwin-1.5 and windows, the - * length of the name of the directory below, "ustar", must be - * less than or equal to the lengthe of the name of the original - * directory, "original" This restriction derives from the - * extremely limited pathname lengths on those platforms. - */ - assertMakeDir(target, 0775); - assertEqualInt(0, chdir(target)); - - /* - * Use the tar program to create an archive. - */ - r = systemf("%s cf archive --format=ustar -C ../original f d l m s >pack.out 2>pack.err", - testprog); - failure("Error invoking \"%s cf archive --format=ustar\"", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout. */ - assertEmptyFile("pack.out"); - /* Stderr is non-empty, since there are a bunch of files - * with filenames too long to archive. */ - - /* - * Use tar to unpack the archive into another directory. - */ - r = systemf("%s xf archive >unpack.out 2>unpack.err", testprog); - failure("Error invoking %s xf archive", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ - assertEmptyFile("unpack.err"); - assertEmptyFile("unpack.out"); - - chdir("original"); - verify_tree(LIMIT_USTAR); - chdir("../.."); -} - -DEFINE_TEST(test_copy) -{ - assertUmask(0); - create_tree(); /* Create sample files in "original" dir. */ - - /* Test simple "tar -c | tar -x" pipeline copy. */ - copy_basic(); - - /* Same, but constrain to ustar format. */ - copy_ustar(); -} diff --git a/Utilities/cmlibarchive/tar/test/test_getdate.c b/Utilities/cmlibarchive/tar/test/test_getdate.c deleted file mode 100644 index bd5afd006..000000000 --- a/Utilities/cmlibarchive/tar/test/test_getdate.c +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_getdate.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - -#include - -/* - * Verify that the getdate() function works. - */ - -time_t get_date(time_t, const char *); - -DEFINE_TEST(test_getdate) -{ - time_t now = time(NULL); - - assertEqualInt(get_date(now, "Jan 1, 1970 UTC"), 0); - assertEqualInt(get_date(now, "7:12:18-0530 4 May 1983"), 420900138); - assertEqualInt(get_date(now, "2004/01/29 513 mest"), 1075345980); - assertEqualInt(get_date(now, "99/02/17 7pm utc"), 919278000); - assertEqualInt(get_date(now, "02/17/99 7:11am est"), 919253460); - /* It's important that we handle ctime() format. */ - assertEqualInt(get_date(now, "Sun Feb 22 17:38:26 PST 2009"), - 1235353106); - /* Basic relative offsets. */ - /* If we use the actual current time as the reference, then - * these tests break around DST changes, so it's actually - * important to use a specific reference time here. */ - assertEqualInt(get_date(0, "tomorrow"), 24 * 60 * 60); - assertEqualInt(get_date(0, "yesterday"), - 24 * 60 * 60); - assertEqualInt(get_date(0, "now + 1 hour"), 60 * 60); - assertEqualInt(get_date(0, "now + 1 hour + 1 minute"), 60 * 60 + 60); - /* Repeat the above for a different start time. */ - now = 1231113600; /* Jan 5, 2009 00:00 UTC */ - assertEqualInt(get_date(0, "Jan 5, 2009 00:00 UTC"), now); - assertEqualInt(get_date(now, "tomorrow"), now + 24 * 60 * 60); - assertEqualInt(get_date(now, "yesterday"), now - 24 * 60 * 60); - assertEqualInt(get_date(now, "now + 1 hour"), now + 60 * 60); - assertEqualInt(get_date(now, "now + 1 hour + 1 minute"), - now + 60 * 60 + 60); - assertEqualInt(get_date(now, "tomorrow 5:16am UTC"), - now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60); - assertEqualInt(get_date(now, "UTC 5:16am tomorrow"), - now + 24 * 60 * 60 + 5 * 60 * 60 + 16 * 60); - - /* Jan 5, 2009 was a Monday. */ - assertEqualInt(get_date(now, "monday UTC"), now); - assertEqualInt(get_date(now, "sunday UTC"), now + 6 * 24 * 60 * 60); - assertEqualInt(get_date(now, "tuesday UTC"), now + 24 * 60 * 60); - /* "next tuesday" is one week after "tuesday" */ - assertEqualInt(get_date(now, "UTC next tuesday"), - now + 8 * 24 * 60 * 60); - /* "last tuesday" is one week before "tuesday" */ - assertEqualInt(get_date(now, "last tuesday UTC"), - now - 6 * 24 * 60 * 60); - /* TODO: Lots more tests here. */ -} diff --git a/Utilities/cmlibarchive/tar/test/test_help.c b/Utilities/cmlibarchive/tar/test/test_help.c deleted file mode 100644 index 6dcff4490..000000000 --- a/Utilities/cmlibarchive/tar/test/test_help.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_help.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - -/* - * Test that "--help", "-h", and "-W help" options all work and - * generate reasonable output. - */ - -static int -in_first_line(const char *p, const char *substring) -{ - size_t l = strlen(substring); - - while (*p != '\0' && *p != '\n') { - if (memcmp(p, substring, l) == 0) - return (1); - ++p; - } - return (0); -} - -DEFINE_TEST(test_help) -{ - int r; - char *p; - size_t plen; - - /* Exercise --help option. */ - r = systemf("%s --help >help.stdout 2>help.stderr", testprog); - failure("--help should generate nothing to stderr."); - assertEmptyFile("help.stderr"); - /* Help message should start with name of program. */ - p = slurpfile(&plen, "help.stdout"); - failure("Help output should be long enough."); - assert(plen >= 6); - failure("First line of help output should contain 'bsdtar': %s", p); - assert(in_first_line(p, "bsdtar")); - /* - * TODO: Extend this check to further verify that --help output - * looks approximately right. - */ - free(p); - - /* -h option should generate the same output. */ - r = systemf("%s -h >h.stdout 2>h.stderr", testprog); - failure("-h should generate nothing to stderr."); - assertEmptyFile("h.stderr"); - failure("stdout should be same for -h and --help"); - assertEqualFile("h.stdout", "help.stdout"); - - /* -W help should be another synonym. */ - r = systemf("%s -W help >Whelp.stdout 2>Whelp.stderr", testprog); - failure("-W help should generate nothing to stderr."); - assertEmptyFile("Whelp.stderr"); - failure("stdout should be same for -W help and --help"); - assertEqualFile("Whelp.stdout", "help.stdout"); -} diff --git a/Utilities/cmlibarchive/tar/test/test_option_T_upper.c b/Utilities/cmlibarchive/tar/test/test_option_T_upper.c deleted file mode 100644 index 97f895d11..000000000 --- a/Utilities/cmlibarchive/tar/test/test_option_T_upper.c +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); - -static int -touch(const char *fn, int fail) -{ - FILE *f = fopen(fn, "w"); - if (fail) { - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (0); /* Failure. */ - } else { - if (f == NULL) - return (0); /* Soft failure. */ - } - fclose(f); - return (1); /* Success */ -} - -DEFINE_TEST(test_option_T_upper) -{ - FILE *f; - int r; - struct stat st; - int gnarlyFilesSupported; - - /* Create a simple dir heirarchy; bail if anything fails. */ - if (!assertMakeDir("d1", 0755)) return; - if (!assertMakeDir("d1/d2", 0755)) return; - if (!touch("f", 1)) return; - if (!touch("d1/f1", 1)) return; - if (!touch("d1/f2", 1)) return; - if (!touch("d1/d2/f3", 1)) return; - if (!touch("d1/d2/f4", 1)) return; - if (!touch("d1/d2/f5", 1)) return; - if (!touch("d1/d2/f6", 1)) return; - /* Some platforms don't permit such things; just skip it. */ - gnarlyFilesSupported = touch("d1/d2/f\x0a", 0); - - /* Populate a file list */ - f = fopen("filelist", "w+"); - if (!assert(f != NULL)) - return; - /* Use a variety of text line endings. */ - fprintf(f, "f\x0d"); /* CR */ - fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */ - fprintf(f, "d1/d2/f4\x0a"); /* NL */ - fprintf(f, "d1/d2/f6"); /* EOF */ - fclose(f); - - /* Populate a second file list */ - f = fopen("filelist2", "w+"); - if (!assert(f != NULL)) - return; - /* Use null-terminated names. */ - fprintf(f, "d1/d2/f3"); - fwrite("\0", 1, 1, f); - fprintf(f, "d1/d2/f5"); - fwrite("\0", 1, 1, f); - if (gnarlyFilesSupported) { - fprintf(f, "d1/d2/f\x0a"); - fwrite("\0", 1, 1, f); - } - fclose(f); - - /* Use -c -T to archive up the files. */ - r = systemf("%s -c -f test1.tar -T filelist > test1.out 2> test1.err", - testprog); - assert(r == 0); - assertEmptyFile("test1.out"); - assertEmptyFile("test1.err"); - - /* Use -x -T to dearchive the files */ - if (!assertMakeDir("test1", 0755)) return; - systemf("%s -x -f test1.tar -T filelist -C test1" - " > test1b.out 2> test1b.err", testprog); - assertEmptyFile("test1b.out"); - assertEmptyFile("test1b.err"); - - /* Verify the files were extracted. */ - assertFileExists("test1/f"); - assertFileExists("test1/d1/f1"); - assertFileNotExists("test1/d1/f2"); - assertFileNotExists("test1/d1/d2/f3"); - assertFileExists("test1/d1/d2/f4"); - assertFileNotExists("test1/d1/d2/f5"); - assertFileExists("test1/d1/d2/f6"); - if (gnarlyFilesSupported) { - assertFileNotExists("test1/d1/d2/f\x0a"); - } - - /* Use -r -T to add more files to the archive. */ - systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err", - testprog); - assertEmptyFile("test2.out"); - assertEmptyFile("test2.err"); - - /* Use -x without -T to dearchive the files (ensure -r worked) */ - if (!assertMakeDir("test3", 0755)) return; - systemf("%s -x -f test1.tar -C test3" - " > test3.out 2> test3.err", testprog); - assertEmptyFile("test3.out"); - assertEmptyFile("test3.err"); - /* Verify the files were extracted.*/ - assertFileExists("test3/f"); - assertFileExists("test3/d1/f1"); - assertFileNotExists("test3/d1/f2"); - assertFileExists("test3/d1/d2/f3"); - assertFileExists("test3/d1/d2/f4"); - assertFileExists("test3/d1/d2/f5"); - assertFileExists("test3/d1/d2/f6"); - if (gnarlyFilesSupported) { - assertFileExists("test3/d1/d2/f\x0a"); - } - - /* Use -x -T to dearchive the files (verify -x -T together) */ - if (!assertMakeDir("test2", 0755)) return; - systemf("%s -x -f test1.tar -T filelist -C test2" - " > test2b.out 2> test2b.err", testprog); - assertEmptyFile("test2b.out"); - assertEmptyFile("test2b.err"); - /* Verify the files were extracted.*/ - assertFileExists("test2/f"); - assertFileExists("test2/d1/f1"); - assertFileNotExists("test2/d1/f2"); - assertFileNotExists("test2/d1/d2/f3"); - assertFileExists("test2/d1/d2/f4"); - assertFileNotExists("test2/d1/d2/f5"); - assertFileExists("test2/d1/d2/f6"); - if (gnarlyFilesSupported) { - assertFileNotExists("test2/d1/d2/f\x0a"); - } - - assertMakeDir("test4", 0755); - assertMakeDir("test4_out", 0755); - assertMakeDir("test4_out2", 0755); - assertMakeDir("test4/d1", 0755); - assertEqualInt(1, touch("test4/d1/foo", 0)); - - /* Does bsdtar support -s option ? */ - systemf("%s -cf - -s /foo/bar/ test4/d1/foo > check.out 2> check.err", - testprog); - assertEqualInt(0, stat("check.err", &st)); - if (st.st_size == 0) { - systemf("%s -cf - -s /foo/bar/ test4/d1/foo | %s -xf - -C test4_out", - testprog, testprog); - assertEmptyFile("test4_out/test4/d1/bar"); - systemf("%s -cf - -s /d1/d2/ test4/d1/foo | %s -xf - -C test4_out", - testprog, testprog); - assertEmptyFile("test4_out/test4/d2/foo"); - systemf("%s -cf - -s ,test4/d1/foo,, test4/d1/foo | %s -tvf - > test4.lst", - testprog, testprog); - assertEmptyFile("test4.lst"); - systemf("%s -cf - test4/d1/foo | %s -xf - -s /foo/bar/ -C test4_out2", - testprog, testprog); - assertEmptyFile("test4_out2/test4/d1/bar"); - } else { - skipping("bsdtar does not support -s option on this platform"); - } - - /* TODO: Include some use of -C directory-changing within the filelist. */ - /* I'm pretty sure -C within the filelist is broken on extract. */ -} diff --git a/Utilities/cmlibarchive/tar/test/test_option_q.c b/Utilities/cmlibarchive/tar/test/test_option_q.c deleted file mode 100644 index 0b9944276..000000000 --- a/Utilities/cmlibarchive/tar/test/test_option_q.c +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_q.c,v 1.3 2008/08/22 01:35:08 kientzle Exp $"); - -DEFINE_TEST(test_option_q) -{ - FILE *f; - int r; - - /* - * Create an archive with several different versions of the - * same files. By default, the last version will overwrite - * any earlier versions. The -q/--fast-read option will - * stop early, so we can verify -q/--fast-read by seeing - * which version of each file actually ended up being - * extracted. This also exercises -r mode, since that's - * what we use to build up the test archive. - */ - - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo1"); - fclose(f); - - assertEqualInt(0, systemf("%s -cf archive.tar foo", testprog)); - - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo2"); - fclose(f); - - assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); - - f = fopen("bar", "w"); - assert(f != NULL); - fprintf(f, "bar1"); - fclose(f); - - assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); - - f = fopen("foo", "w"); - assert(f != NULL); - fprintf(f, "foo3"); - fclose(f); - - assertEqualInt(0, systemf("%s -rf archive.tar foo", testprog)); - - f = fopen("bar", "w"); - assert(f != NULL); - fprintf(f, "bar2"); - fclose(f); - - assertEqualInt(0, systemf("%s -rf archive.tar bar", testprog)); - - /* - * Now, try extracting from the test archive with various - * combinations of -q. - */ - - /* Test 1: -q foo should only extract the first foo. */ - assertMakeDir("test1", 0755); - assertChdir("test1"); - r = systemf("%s -xf ../archive.tar -q foo >test.out 2>test.err", - testprog); - failure("Fatal error trying to use -q option"); - if (!assertEqualInt(0, r)) - return; - - assertFileContents("foo1", 4, "foo"); - assertEmptyFile("test.out"); - assertEmptyFile("test.err"); - assertChdir(".."); - - /* Test 2: -q foo bar should extract up to the first bar. */ - assertMakeDir("test2", 0755); - assertChdir("test2"); - assertEqualInt(0, - systemf("%s -xf ../archive.tar -q foo bar >test.out 2>test.err", testprog)); - assertFileContents("foo2", 4, "foo"); - assertFileContents("bar1", 4, "bar"); - assertEmptyFile("test.out"); - assertEmptyFile("test.err"); - assertChdir(".."); - - /* Test 3: Same as test 2, but use --fast-read spelling. */ - assertMakeDir("test3", 0755); - assertChdir("test3"); - assertEqualInt(0, - systemf("%s -xf ../archive.tar --fast-read foo bar >test.out 2>test.err", testprog)); - assertFileContents("foo2", 4, "foo"); - assertFileContents("bar1", 4, "bar"); - assertEmptyFile("test.out"); - assertEmptyFile("test.err"); - assertChdir(".."); - - /* Test 4: Without -q, should extract everything. */ - assertMakeDir("test4", 0755); - assertChdir("test4"); - assertEqualInt(0, - systemf("%s -xf ../archive.tar foo bar >test.out 2>test.err", testprog)); - assertFileContents("foo3", 4, "foo"); - assertFileContents("bar2", 4, "bar"); - assertEmptyFile("test.out"); - assertEmptyFile("test.err"); - assertChdir(".."); -} diff --git a/Utilities/cmlibarchive/tar/test/test_option_r.c b/Utilities/cmlibarchive/tar/test/test_option_r.c deleted file mode 100644 index b6d310add..000000000 --- a/Utilities/cmlibarchive/tar/test/test_option_r.c +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD$"); - -/* - * Also see test_option_q for additional validation of -r support. - */ -DEFINE_TEST(test_option_r) -{ - char buff[15]; - char *p0, *p1; - size_t s; - FILE *f; - int r; - - /* Create a file */ - f = fopen("f1", "w"); - if (!assert(f != NULL)) - return; - assertEqualInt(3, fwrite("abc", 1, 3, f)); - fclose(f); - - /* Archive that one file. */ - r = systemf("%s cf archive.tar f1 >step1.out 2>step1.err", testprog); - failure("Error invoking %s cf archive.tar f1", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ - assertEmptyFile("step1.out"); - assertEmptyFile("step1.err"); - - - /* Do some basic validation of the constructed archive. */ - p0 = slurpfile(&s, "archive.tar"); - if (!assert(p0 != NULL)) - return; - if (!assert(s >= 2048)) { - free(p0); - return; - } - assertEqualMem(p0 + 0, "f1", 3); - assertEqualMem(p0 + 512, "abc", 3); - assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8); - assertEqualMem(p0 + 1536, "\0\0\0\0\0\0\0\0", 8); - - /* Edit that file */ - f = fopen("f1", "w"); - if (!assert(f != NULL)) - return; - assertEqualInt(3, fwrite("123", 1, 3, f)); - fclose(f); - - /* Update the archive. */ - r = systemf("%s rf archive.tar f1 >step2.out 2>step2.err", testprog); - failure("Error invoking %s rf archive.tar f1", testprog); - assertEqualInt(r, 0); - - /* Verify that nothing went to stdout or stderr. */ - assertEmptyFile("step2.out"); - assertEmptyFile("step2.err"); - - /* Do some basic validation of the constructed archive. */ - p1 = slurpfile(&s, "archive.tar"); - if (!assert(p1 != NULL)) { - free(p0); - return; - } - assert(s >= 3072); - /* Verify first entry is unchanged. */ - assertEqualMem(p0, p1, 1024); - /* Verify that second entry is correct. */ - assertEqualMem(p1 + 1024, "f1", 3); - assertEqualMem(p1 + 1536, "123", 3); - /* Verify end-of-archive marker. */ - assertEqualMem(p1 + 2048, "\0\0\0\0\0\0\0\0", 8); - assertEqualMem(p1 + 2560, "\0\0\0\0\0\0\0\0", 8); - free(p0); - free(p1); - - /* Unpack both items */ - assertMakeDir("step3", 0775); - assertChdir("step3"); - r = systemf("%s xf ../archive.tar", testprog); - failure("Error invoking %s xf archive.tar", testprog); - assertEqualInt(r, 0); - - /* Verify that the second one overwrote the first. */ - f = fopen("f1", "r"); - if (assert(f != NULL)) { - assertEqualInt(3, fread(buff, 1, 3, f)); - assertEqualMem(buff, "123", 3); - fclose(f); - } -} diff --git a/Utilities/cmlibarchive/tar/test/test_option_s.c b/Utilities/cmlibarchive/tar/test/test_option_s.c deleted file mode 100644 index 3bddbcf75..000000000 --- a/Utilities/cmlibarchive/tar/test/test_option_s.c +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * Copyright (c) 2003-2008 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_option_T.c,v 1.3 2008/08/15 06:12:02 kientzle Exp $"); - -static int -mkfile(const char *fn, const char *contents) -{ - FILE *f = fopen(fn, "w"); - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (1); /* Failure. */ - if (contents != NULL) - assertEqualInt(strlen(contents), - fwrite(contents, 1, strlen(contents), f)); - assertEqualInt(0, fclose(f)); - return (0); /* Success */ -} - -DEFINE_TEST(test_option_s) -{ - struct stat st; - - /* Create a sample file heirarchy. */ - assertMakeDir("in", 0755); - assertMakeDir("in/d1", 0755); - assertEqualInt(0, mkfile("in/d1/foo", "foo")); - assertEqualInt(0, mkfile("in/d1/bar", "bar")); - - /* Does bsdtar support -s option ? */ - systemf("%s -cf - -s /foo/bar/ in/d1/foo > NUL 2> check.err", - testprog); - assertEqualInt(0, stat("check.err", &st)); - if (st.st_size != 0) { - skipping("%s does not support -s option on this platform", - testprog); - return; - } - - /* - * Test 1: Filename substitution when creating archives. - */ - assertMakeDir("test1", 0755); - systemf("%s -cf - -s /foo/bar/ in/d1/foo | %s -xf - -C test1", - testprog, testprog); - assertFileContents("foo", 3, "test1/in/d1/bar"); - systemf("%s -cf - -s /d1/d2/ in/d1/foo | %s -xf - -C test1", - testprog, testprog); - assertFileContents("foo", 3, "test1/in/d2/foo"); - - - /* - * Test 2: Basic substitution when extracting archive. - */ - assertMakeDir("test2", 0755); - systemf("%s -cf - in/d1/foo | %s -xf - -s /foo/bar/ -C test2", - testprog, testprog); - assertFileContents("foo", 3, "test2/in/d1/bar"); - - /* - * Test 3: Files with empty names shouldn't be archived. - */ - systemf("%s -cf - -s ,in/d1/foo,, in/d1/foo | %s -tvf - > in.lst", - testprog, testprog); - assertEmptyFile("in.lst"); - - /* - * Test 4: Multiple substitutions when extracting archive. - */ - assertMakeDir("test4", 0755); - systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}baz} -C test4", - testprog, testprog); - assertFileContents("foo", 3, "test4/in/d1/bar"); - assertFileContents("bar", 3, "test4/in/d1/baz"); - - /* - * Test 5: Name-switching substitutions when extracting archive. - */ - assertMakeDir("test5", 0755); - systemf("%s -cf - in/d1/foo in/d1/bar | %s -xf - -s /foo/bar/ -s }bar}foo} -C test5", - testprog, testprog); - assertFileContents("foo", 3, "test5/in/d1/bar"); - assertFileContents("bar", 3, "test5/in/d1/foo"); -} diff --git a/Utilities/cmlibarchive/tar/test/test_patterns.c b/Utilities/cmlibarchive/tar/test/test_patterns.c deleted file mode 100644 index fb84f7a91..000000000 --- a/Utilities/cmlibarchive/tar/test/test_patterns.c +++ /dev/null @@ -1,184 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_patterns.c,v 1.6 2008/08/21 22:28:00 kientzle Exp $"); - -DEFINE_TEST(test_patterns) -{ - FILE *f; - int r; - const char *reffile2 = "test_patterns_2.tar"; - const char *reffile3 = "test_patterns_3.tar"; - const char *reffile4 = "test_patterns_4.tar"; - const char *p; - - /* - * Test basic command-line pattern handling. - */ - - /* - * Test 1: Files on the command line that don't get matched - * didn't produce an error. - * - * John Baldwin reported this problem in PR bin/121598 - */ - f = fopen("foo", "w"); - assert(f != NULL); - fclose(f); - r = systemf("%s cfv tar1.tgz foo > tar1a.out 2> tar1a.err", testprog); - assertEqualInt(r, 0); - r = systemf("%s xv --no-same-owner -f tar1.tgz foo bar > tar1b.out 2> tar1b.err", testprog); - failure("tar should return non-zero because a file was given on the command line that's not in the archive"); - assert(r != 0); - - /* - * Test 2: Check basic matching of full paths that start with / - */ - extract_reference_file(reffile2); - - r = systemf("%s tf %s /tmp/foo/bar > tar2a.out 2> tar2a.err", - testprog, reffile2); - assertEqualInt(r, 0); -#if !defined(_WIN32) || defined(__CYGWIN__) - p = "/tmp/foo/bar/\n/tmp/foo/bar/baz\n"; -#else - p = "/tmp/foo/bar/\r\n/tmp/foo/bar/baz\r\n"; -#endif - assertFileContents(p, strlen(p), "tar2a.out"); - assertEmptyFile("tar2a.err"); - - /* - * Test 3 archive has some entries starting with '/' and some not. - */ - extract_reference_file(reffile3); - - /* Test 3a: Pattern tmp/foo/bar should not match /tmp/foo/bar */ - r = systemf("%s x --no-same-owner -f %s tmp/foo/bar > tar3a.out 2> tar3a.err", - testprog, reffile3); - assert(r != 0); - assertEmptyFile("tar3a.out"); - - /* Test 3b: Pattern /tmp/foo/baz should not match tmp/foo/baz */ - assertNonEmptyFile("tar3a.err"); - /* Again, with the '/' */ - r = systemf("%s x --no-same-owner -f %s /tmp/foo/baz > tar3b.out 2> tar3b.err", - testprog, reffile3); - assert(r != 0); - assertEmptyFile("tar3b.out"); - assertNonEmptyFile("tar3b.err"); - - /* Test 3c: ./tmp/foo/bar should not match /tmp/foo/bar */ - r = systemf("%s x --no-same-owner -f %s ./tmp/foo/bar > tar3c.out 2> tar3c.err", - testprog, reffile3); - assert(r != 0); - assertEmptyFile("tar3c.out"); - assertNonEmptyFile("tar3c.err"); - - /* Test 3d: ./tmp/foo/baz should match tmp/foo/baz */ - r = systemf("%s x --no-same-owner -f %s ./tmp/foo/baz > tar3d.out 2> tar3d.err", - testprog, reffile3); - assertEqualInt(r, 0); - assertEmptyFile("tar3d.out"); - assertEmptyFile("tar3d.err"); - assertFileExists("tmp/foo/baz/bar"); - - /* - * Test 4 archive has some entries starting with windows drive letters - * such as 'c:\', '//./c:/' or '//?/c:/'. - */ - extract_reference_file(reffile4); - - r = systemf("%s x --no-same-owner -f %s -C tmp > tar4.out 2> tar4.err", - testprog, reffile4); - assert(r != 0); - assertEmptyFile("tar4.out"); - assertNonEmptyFile("tar4.err"); - - for (r = 1; r <= 54; r++) { - char file_a[] = "tmp/fileXX"; - char file_b1[] = "tmp/server/share/fileXX"; - char file_b2[] = "tmp/server\\share\\fileXX"; - char file_c[] = "tmp/../fileXX"; - char *filex; - int xsize; - - switch (r) { - case 15: case 18: - /* - * Including server and share names. - * //?/UNC/server/share/file15 - * //?/unc/server/share/file18 - */ - filex = file_b1; - xsize = sizeof(file_b1); - break; - case 35: case 38: case 52: - /* - * Including server and share names. - * \\?\UNC\server\share\file35 - * \\?\unc\server\share\file38 - * \/?/uNc/server\share\file52 - */ - filex = file_b2; - xsize = sizeof(file_b2); - break; - default: - filex = file_a; - xsize = sizeof(file_a); - break; - } - filex[xsize-3] = '0' + r / 10; - filex[xsize-2] = '0' + r % 10; - switch (r) { - case 5: case 6: case 17: case 20: case 25: - case 26: case 37: case 40: case 43: case 54: - /* - * Not extracted patterns. - * D:../file05 - * c:../../file06 - * //?/UNC/../file17 - * //?/unc/../file20 - * z:..\file25 - * c:..\..\file26 - * \\?\UNC\..\file37 - * \\?\unc\..\file40 - * c:../..\file43 - * \/?\UnC\../file54 - */ - assertFileNotExists(filex); - filex = file_c; - xsize = sizeof(file_c); - filex[xsize-3] = '0' + r / 10; - filex[xsize-2] = '0' + r % 10; - assertFileNotExists(filex); - break; - default: - /* Extracted patterns. */ - assertFileExists(filex); - break; - } - } -} diff --git a/Utilities/cmlibarchive/tar/test/test_patterns_2.tar.uu b/Utilities/cmlibarchive/tar/test/test_patterns_2.tar.uu deleted file mode 100644 index eba2daece..000000000 --- a/Utilities/cmlibarchive/tar/test/test_patterns_2.tar.uu +++ /dev/null @@ -1,231 +0,0 @@ -begin 644 test_patterns_2.tar -M+W1M<"]F;V\O```````````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````#`P,#@`````````````````````````````````````````````````````````` -M```````````````````````````````````````````````````````````P -M,#`V-#0@`#`P,3@`````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````````#`P,#8T-"``,#`Q-S4P(``P,#`P,#`@`#`P,#`P -M,#`P,#`P(#$Q,#4Q,C$R-C4S(#`Q,S8V-P`@,``````````````````````` -M```````````````````````````````````````````````````````````` -M``````````````````````````````````````````````````!UCHN+EQF:6QE,C4````````````````````````````````````````` -M```````````````````````````````````````````````````````````` -M`````````````````#`P,#8T-"``,#`Q-S4Q(``P,#$W-3$@`#`P,#`P,#`P -M,#`P(#$Q,34P-Ccf.out 2>cf.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("cf.out"); - assertEmptyFile("cf.err"); - - /* 'cvf' should generate file list on stderr, empty stdout. */ - r = systemf("%s cvf archive f l >cvf.out 2>cvf.err", testprog); - assertEqualInt(r, 0); - failure("'cv' writes filenames to stderr, nothing to stdout (SUSv2)\n" - "Note that GNU tar writes the file list to stdout by default."); - assertEmptyFile("cvf.out"); - /* TODO: Verify cvf.err has file list in SUSv2-prescribed format. */ - - /* 'cvf -' should generate file list on stderr, archive on stdout. */ - r = systemf("%s cvf - f l >cvf-.out 2>cvf-.err", testprog); - assertEqualInt(r, 0); - failure("cvf - should write archive to stdout"); - /* TODO: Verify cvf-.out has archive. */ - failure("cvf - should write file list to stderr (SUSv2)"); - /* TODO: Verify cvf-.err has verbose file list. */ - - /* 'tf' should generate file list on stdout, empty stderr. */ - r = systemf("%s tf archive >tf.out 2>tf.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("tf.err"); - failure("'t' mode should write results to stdout"); - /* TODO: Verify tf.out has file list. */ - - /* 'tvf' should generate file list on stdout, empty stderr. */ - r = systemf("%s tvf archive >tvf.out 2>tvf.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("tvf.err"); - failure("'tv' mode should write results to stdout"); - /* TODO: Verify tvf.out has file list. */ - - /* 'tvf -' uses stdin, file list on stdout, empty stderr. */ - r = systemf("%s tvf - < archive >tvf-.out 2>tvf-.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("tvf-.err"); - /* TODO: Verify tvf-.out has file list. */ - - /* Basic 'xf' should generate no output on stdout or stderr. */ - r = systemf("%s xf archive >xf.out 2>xf.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("xf.err"); - assertEmptyFile("xf.out"); - - /* 'xvf' should generate list on stderr, empty stdout. */ - r = systemf("%s xvf archive >xvf.out 2>xvf.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("xvf.out"); - /* TODO: Verify xvf.err */ - - /* 'xvOf' should generate list on stderr, file contents on stdout. */ - r = systemf("%s xvOf archive >xvOf.out 2>xvOf.err", testprog); - assertEqualInt(r, 0); - /* Verify xvOf.out is the file contents */ - p = slurpfile(&s, "xvOf.out"); - assert(p != NULL); - assert(s = 2); - assertEqualMem(p, "f\n", 2); - /* TODO: Verify xvf.err */ - - /* 'xvf -' should generate list on stderr, empty stdout. */ - r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog); - assertEqualInt(r, 0); - assertEmptyFile("xvf-.out"); - /* TODO: Verify xvf-.err */ -} diff --git a/Utilities/cmlibarchive/tar/test/test_strip_components.c b/Utilities/cmlibarchive/tar/test/test_strip_components.c deleted file mode 100644 index 6d258e49d..000000000 --- a/Utilities/cmlibarchive/tar/test/test_strip_components.c +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_strip_components.c,v 1.2 2008/11/10 05:24:13 kientzle Exp $"); - -static int -touch(const char *fn) -{ - FILE *f = fopen(fn, "w"); - failure("Couldn't create file '%s', errno=%d (%s)\n", - fn, errno, strerror(errno)); - if (!assert(f != NULL)) - return (0); /* Failure. */ - fclose(f); - return (1); /* Success */ -} - -DEFINE_TEST(test_strip_components) -{ - assertMakeDir("d0", 0755); - assertChdir("d0"); - assertMakeDir("d1", 0755); - assertMakeDir("d1/d2", 0755); - assertMakeDir("d1/d2/d3", 0755); - assertEqualInt(1, touch("d1/d2/f1")); - assertMakeHardlink("l1", "d1/d2/f1"); - assertMakeHardlink("d1/l2", "d1/d2/f1"); - if (canSymlink()) { - assertMakeSymlink("s1", "d1/d2/f1"); - assertMakeSymlink("d1/s2", "d2/f1"); - } - assertChdir(".."); - - assertEqualInt(0, systemf("%s -cf test.tar d0", testprog)); - - assertMakeDir("target", 0755); - assertEqualInt(0, systemf("%s -x -C target --strip-components 2 " - "-f test.tar", testprog)); - - failure("d0/ is too short and should not get restored"); - assertFileNotExists("target/d0"); - failure("d0/d1/ is too short and should not get restored"); - assertFileNotExists("target/d1"); - failure("d0/d1/s2 is a symlink to something that won't be extracted"); - /* If platform supports symlinks, target/s2 is a broken symlink. */ - /* If platform does not support symlink, target/s2 doesn't exist. */ - assertFileNotExists("target/s2"); - if (canSymlink()) - assertIsSymlink("target/s2", "d2/f1"); - failure("d0/d1/d2 should be extracted"); - assertIsDir("target/d2", -1); - - /* - * This next is a complicated case. d0/l1, d0/d1/l2, and - * d0/d1/d2/f1 are all hardlinks to the same file; d0/l1 can't - * be extracted with --strip-components=2 and the other two - * can. Remember that tar normally stores the first file with - * a body and the other as hardlink entries to the first - * appearance. So the final result depends on the order in - * which these three names get archived. If d0/l1 is first, - * none of the three can be restored. If either of the longer - * names are first, then the two longer ones can both be - * restored. - * - * The tree-walking code used by bsdtar always visits files - * before subdirectories, so bsdtar's behavior is fortunately - * deterministic: d0/l1 will always get stored first and the - * other two will be stored as hardlinks to d0/l1. Since - * d0/l1 can't be extracted, none of these three will be - * extracted. - * - * It may be worth extending this test to force a particular - * archiving order so as to exercise both of the cases described - * above. - * - * Of course, this is all totally different for cpio and newc - * formats because the hardlink management is different. - * TODO: Rename this to test_strip_components_tar and create - * parallel tests for cpio and newc formats. - */ - failure("d0/l1 is too short and should not get restored"); - assertFileNotExists("target/l1"); - failure("d0/d1/l2 is a hardlink to file whose name was too short"); - assertFileNotExists("target/l2"); - failure("d0/d1/d2/f1 is a hardlink to file whose name was too short"); - assertFileNotExists("target/d2/f1"); -} diff --git a/Utilities/cmlibarchive/tar/test/test_symlink_dir.c b/Utilities/cmlibarchive/tar/test/test_symlink_dir.c deleted file mode 100644 index 04e0a4baa..000000000 --- a/Utilities/cmlibarchive/tar/test/test_symlink_dir.c +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_symlink_dir.c,v 1.1 2008/09/14 02:16:04 kientzle Exp $"); - -/* - * tar -x -P should follow existing symlinks for dirs, but not other - * content. Plain tar -x should remove symlinks when they're in the - * way of a dir extraction. - */ - -static int -mkfile(const char *name, int mode, const char *contents, size_t size) -{ - FILE *f = fopen(name, "wb"); - size_t written; - - (void)mode; /* UNUSED */ - if (f == NULL) - return (-1); - written = fwrite(contents, 1, size, f); - fclose(f); - if (size != written) - return (-1); - return (0); -} - -DEFINE_TEST(test_symlink_dir) -{ - assertUmask(0); - - assertMakeDir("source", 0755); - assertEqualInt(0, mkfile("source/file", 0755, "a", 1)); - assertEqualInt(0, mkfile("source/file2", 0755, "ab", 2)); - assertMakeDir("source/dir", 0755); - assertMakeDir("source/dir/d", 0755); - assertEqualInt(0, mkfile("source/dir/f", 0755, "abc", 3)); - assertMakeDir("source/dir2", 0755); - assertMakeDir("source/dir2/d2", 0755); - assertEqualInt(0, mkfile("source/dir2/f2", 0755, "abcd", 4)); - assertMakeDir("source/dir3", 0755); - assertMakeDir("source/dir3/d3", 0755); - assertEqualInt(0, mkfile("source/dir3/f3", 0755, "abcde", 5)); - - assertEqualInt(0, - systemf("%s -cf test.tar -C source dir dir2 dir3 file file2", - testprog)); - - /* - * Extract with -x and without -P. - */ - assertMakeDir("dest1", 0755); - /* "dir" is a symlink to an existing "dest1/real_dir" */ - assertMakeDir("dest1/real_dir", 0755); - if (canSymlink()) { - assertMakeSymlink("dest1/dir", "real_dir"); - /* "dir2" is a symlink to a non-existing "real_dir2" */ - assertMakeSymlink("dest1/dir2", "real_dir2"); - } else { - skipping("some symlink checks"); - } - /* "dir3" is a symlink to an existing "non_dir3" */ - assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6)); - if (canSymlink()) - assertMakeSymlink("dest1/dir3", "non_dir3"); - /* "file" is a symlink to existing "real_file" */ - assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7)); - if (canSymlink()) { - assertMakeSymlink("dest1/file", "real_file"); - /* "file2" is a symlink to non-existing "real_file2" */ - assertMakeSymlink("dest1/file2", "real_file2"); - } - assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog)); - - /* dest1/dir symlink should be replaced */ - failure("symlink to dir was followed when it shouldn't be"); - assertIsDir("dest1/dir", -1); - /* dest1/dir2 symlink should be replaced */ - failure("Broken symlink wasn't replaced with dir"); - assertIsDir("dest1/dir2", -1); - /* dest1/dir3 symlink should be replaced */ - failure("Symlink to non-dir wasn't replaced with dir"); - assertIsDir("dest1/dir3", -1); - /* dest1/file symlink should be replaced */ - failure("Symlink to existing file should be replaced"); - assertIsReg("dest1/file", -1); - /* dest1/file2 symlink should be replaced */ - failure("Symlink to non-existing file should be replaced"); - assertIsReg("dest1/file2", -1); - - /* - * Extract with both -x and -P - */ - assertMakeDir("dest2", 0755); - /* "dir" is a symlink to existing "real_dir" */ - assertMakeDir("dest2/real_dir", 0755); - if (canSymlink()) - assertMakeSymlink("dest2/dir", "real_dir"); - /* "dir2" is a symlink to a non-existing "real_dir2" */ - if (canSymlink()) - assertMakeSymlink("dest2/dir2", "real_dir2"); - /* "dir3" is a symlink to an existing "non_dir3" */ - assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8)); - if (canSymlink()) - assertMakeSymlink("dest2/dir3", "non_dir3"); - /* "file" is a symlink to existing "real_file" */ - assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9)); - if (canSymlink()) - assertMakeSymlink("dest2/file", "real_file"); - /* "file2" is a symlink to non-existing "real_file2" */ - if (canSymlink()) - assertMakeSymlink("dest2/file2", "real_file2"); - assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog)); - - /* dest2/dir symlink should be followed */ - if (canSymlink()) { - assertIsSymlink("dest2/dir", "real_dir"); - assertIsDir("dest2/real_dir", -1); - } - - /* Contents of 'dir' should be restored */ - assertIsDir("dest2/dir/d", -1); - assertIsReg("dest2/dir/f", -1); - assertFileSize("dest2/dir/f", 3); - /* dest2/dir2 symlink should be removed */ - failure("Broken symlink wasn't replaced with dir"); - assertIsDir("dest2/dir2", -1); - /* dest2/dir3 symlink should be removed */ - failure("Symlink to non-dir wasn't replaced with dir"); - assertIsDir("dest2/dir3", -1); - /* dest2/file symlink should be removed; - * even -P shouldn't follow symlinks for files */ - failure("Symlink to existing file should be removed"); - assertIsReg("dest2/file", -1); - /* dest2/file2 symlink should be removed */ - failure("Symlink to non-existing file should be removed"); - assertIsReg("dest2/file2", -1); -} diff --git a/Utilities/cmlibarchive/tar/test/test_version.c b/Utilities/cmlibarchive/tar/test/test_version.c deleted file mode 100644 index 518dd413e..000000000 --- a/Utilities/cmlibarchive/tar/test/test_version.c +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "test.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_version.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); - -/* - * Test that --version option works and generates reasonable output. - */ - -DEFINE_TEST(test_version) -{ - int r; - char *p, *q; - size_t s; - - - r = systemf("%s --version >version.stdout 2>version.stderr", testprog); - if (r != 0) - r = systemf("%s -W version >version.stdout 2>version.stderr", - testprog); - failure("Unable to run either %s --version or %s -W version", - testprog, testprog); - if (!assert(r == 0)) - return; - - /* --version should generate nothing to stdout. */ - assertEmptyFile("version.stderr"); - /* Verify format of version message. */ - q = p = slurpfile(&s, "version.stdout"); - /* Version message should start with name of program, then space. */ - assert(s > 6); - failure("Version must start with 'bsdtar': ``%s''", p); - if (!assertEqualMem(q, "bsdtar ", 7)) - return; - q += 7; s -= 7; - /* Version number is a series of digits and periods. */ - while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { - ++q; - --s; - } - /* Version number terminated by space. */ - failure("No space after bsdtar version: ``%s''", p); - assert(s > 1); - /* Skip a single trailing a,b,c, or d. */ - if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') - ++q; - failure("No space after bsdtar version: ``%s''", p); - assert(*q == ' '); - ++q; --s; - /* Separator. */ - failure("No `-' between bsdtar and libarchive versions: ``%s''", p); - assertEqualMem(q, "- ", 2); - q += 2; s -= 2; - /* libarchive name and version number */ - failure("Not long enough for libarchive version: ``%s''", p); - assert(s > 11); - failure("Libarchive version must start with `libarchive': ``%s''", p); - assertEqualMem(q, "libarchive ", 11); - q += 11; s -= 11; - /* Version number is a series of digits and periods. */ - while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) { - ++q; - --s; - } - /* Skip a single trailing a,b,c, or d. */ - if (*q == 'a' || *q == 'b' || *q == 'c' || *q == 'd') - ++q; - /* All terminated by end-of-line. */ - assert(s >= 1); - /* Skip an optional CR character (e.g., Windows) */ - failure("Version output must end with \\n or \\r\\n"); - if (*q == '\r') { ++q; --s; } - assertEqualMem(q, "\n", 1); - free(p); -} diff --git a/Utilities/cmlibarchive/tar/test/test_windows.c b/Utilities/cmlibarchive/tar/test/test_windows.c deleted file mode 100644 index b0eefff45..000000000 --- a/Utilities/cmlibarchive/tar/test/test_windows.c +++ /dev/null @@ -1,324 +0,0 @@ -/*- - * Copyright (c) 2009 Michihiro NAKAJIMA - * 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 "test.h" - -#if defined(_WIN32) && !defined(__CYGWIN__) -#include - -static void -mkfile(const char *name) -{ - FILE *f; - - f = fopen(name, "wb"); - assert(f != NULL); - assertEqualInt(5, fwrite("01234", 1, 5, f)); - fclose(f); -} - -static void -mkfullpath(char **path1, char **path2, const char *tpath, int type) -{ - char *fp1 = NULL, *fp2 = NULL, *p1 = NULL, *p2 = NULL; - size_t l; - - /* - * Get full path name of "tpath" - */ - l = GetFullPathNameA(tpath, 0, NULL, NULL); - assert(0 != l); - fp1 = malloc(l); - assert(NULL != fp1); - fp2 = malloc(l*2); - assert(NULL != fp2); - l = GetFullPathNameA(tpath, l, fp1, NULL); - if ((type & 0x01) == 0) { - for (p1 = fp1; *p1 != '\0'; p1++) - if (*p1 == '\\') - *p1 = '/'; - } - - switch(type) { - case 0: /* start with "/" */ - case 1: /* start with "\" */ - /* strip "c:" */ - memmove(fp1, fp1 + 2, l - 2); - fp1[l -2] = '\0'; - p1 = fp1 + 1; - break; - case 2: /* start with "c:/" */ - case 3: /* start with "c:\" */ - p1 = fp1 + 3; - break; - case 4: /* start with "//./c:/" */ - case 5: /* start with "\\.\c:\" */ - case 6: /* start with "//?/c:/" */ - case 7: /* start with "\\?\c:\" */ - p1 = malloc(l + 4 + 1); - assert(NULL != p1); - if (type & 0x1) - memcpy(p1, "\\\\.\\", 4); - else - memcpy(p1, "//./", 4); - if (type == 6 || type == 7) - p1[2] = '?'; - memcpy(p1 + 4, fp1, l); - p1[l + 4] = '\0'; - free(fp1); - fp1 = p1; - p1 = fp1 + 7; - break; - } - - /* - * Strip leading drive names and converting "\" to "\\" - */ - p2 = fp2; - while (*p1 != '\0') { - if (*p1 == '\\') - *p2++ = *p1; - *p2++ = *p1++; - } - *p2++ = '\r'; - *p2++ = '\n'; - *p2 = '\0'; - - *path1 = fp1; - *path2 = fp2; -} - -static const char list1[] = - "aaa/\r\naaa/file1\r\naaa/xxa/\r\naaa/xxb/\r\naaa/zzc/\r\n" - "aaa/zzc/file1\r\naaa/xxb/file1\r\naaa/xxa/file1\r\naab/\r\n" - "aac/\r\nabb/\r\nabc/\r\nabd/\r\n"; -static const char list2[] = - "bbb/\r\nbbb/file1\r\nbbb/xxa/\r\nbbb/xxb/\r\nbbb/zzc/\r\n" - "bbb/zzc/file1\r\nbbb/xxb/file1\r\nbbb/xxa/file1\r\nbbc/\r\n" - "bbd/\r\nbcc/\r\nbcd/\r\nbce/\r\n"; -static const char list3[] = - "aac/\r\nabc/\r\nbbc/\r\nbcc/\r\nccc/\r\n"; -static const char list4[] = - "fff/abca\r\nfff/acca\r\n"; -static const char list5[] = - "aaa/file1\r\naaa/xxa/\r\naaa/xxa/file1\r\naaa/xxb/\r\n" - "aaa/xxb/file1\r\naaa/zzc/\r\naaa/zzc/file1\r\n"; -static const char list6[] = - "fff/abca\r\nfff/acca\r\naaa/xxa/\r\naaa/xxa/file1\r\n" - "aaa/xxb/\r\naaa/xxb/file1\r\n"; -#endif /* _WIN32 && !__CYGWIN__ */ - -DEFINE_TEST(test_windows) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - char *fp1, *fp2; - - /* - * Preparre tests. - * Create directories and files. - */ - assertMakeDir("tmp", 0775); - assertChdir("tmp"); - - assertMakeDir("aaa", 0775); - assertMakeDir("aaa/xxa", 0775); - assertMakeDir("aaa/xxb", 0775); - assertMakeDir("aaa/zzc", 0775); - mkfile("aaa/file1"); - mkfile("aaa/xxa/file1"); - mkfile("aaa/xxb/file1"); - mkfile("aaa/zzc/file1"); - assertMakeDir("aab", 0775); - assertMakeDir("aac", 0775); - assertMakeDir("abb", 0775); - assertMakeDir("abc", 0775); - assertMakeDir("abd", 0775); - assertMakeDir("bbb", 0775); - assertMakeDir("bbb/xxa", 0775); - assertMakeDir("bbb/xxb", 0775); - assertMakeDir("bbb/zzc", 0775); - mkfile("bbb/file1"); - mkfile("bbb/xxa/file1"); - mkfile("bbb/xxb/file1"); - mkfile("bbb/zzc/file1"); - assertMakeDir("bbc", 0775); - assertMakeDir("bbd", 0775); - assertMakeDir("bcc", 0775); - assertMakeDir("bcd", 0775); - assertEqualInt(0, _mkdir("bce")); - assertEqualInt(0, _mkdir("ccc")); - assertEqualInt(0, _mkdir("fff")); - mkfile("fff/aaaa"); - mkfile("fff/abba"); - mkfile("fff/abca"); - mkfile("fff/acba"); - mkfile("fff/acca"); - - /* - * Test1: Command line pattern matching. - */ - assertEqualInt(0, - systemf("%s -cf ../archive1.tar a*", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive1.tar > ../list1", testprog)); - assertFileContents(list1, strlen(list1), "../list1"); - - assertEqualInt(0, - systemf("%s -cf ../archive2.tar b*", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive2.tar > ../list2", testprog)); - assertFileContents(list2, strlen(list2), "../list2"); - - assertEqualInt(0, - systemf("%s -cf ../archive3.tar ??c", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive3.tar > ../list3", testprog)); - assertFileContents(list3, strlen(list3), "../list3"); - - assertEqualInt(0, - systemf("%s -cf ../archive3b.tar *c", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive3b.tar > ../list3b", testprog)); - assertFileContents(list3, strlen(list3), "../list3b"); - - assertEqualInt(0, - systemf("%s -cf ../archive4.tar fff/a?ca", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive4.tar > ../list4", testprog)); - assertFileContents(list4, strlen(list4), "../list4"); - - assertEqualInt(0, - systemf("%s -cf ../archive5.tar aaa\\*", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive5.tar > ../list5", testprog)); - assertFileContents(list5, strlen(list5), "../list5"); - - assertEqualInt(0, - systemf("%s -cf ../archive6.tar fff\\a?ca aaa\\xx*", testprog)); - assertEqualInt(0, - systemf("%s -tf ../archive6.tar > ../list6", testprog)); - assertFileContents(list6, strlen(list6), "../list6"); - - /* - * Test2: Archive the file start with drive letters. - */ - /* Test2a: start with "/" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 0); - assertEqualInt(0, - systemf("%s -cf ../archive10.tar %s > ../out10 2> ../err10", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive10.tar > ../list10", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list10"); - free(fp1); - free(fp2); - - /* Test2b: start with "\" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 1); - assertEqualInt(0, - systemf("%s -cf ../archive11.tar %s > ../out11 2> ../err11", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive11.tar > ../list11", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list11"); - free(fp1); - free(fp2); - - /* Test2c: start with "c:/" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 2); - assertEqualInt(0, - systemf("%s -cf ../archive12.tar %s > ../out12 2> ../err12", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive12.tar > ../list12", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list12"); - free(fp1); - free(fp2); - - /* Test2d: start with "c:\" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 3); - assertEqualInt(0, - systemf("%s -cf ../archive13.tar %s > ../out13 2> ../err13", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive13.tar > ../list13", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list13"); - free(fp1); - free(fp2); - - /* Test2e: start with "//./c:/" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 4); - assertEqualInt(0, - systemf("%s -cf ../archive14.tar %s > ../out14 2> ../err14", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive14.tar > ../list14", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list14"); - free(fp1); - free(fp2); - - /* Test2f: start with "\\.\c:\" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 5); - assertEqualInt(0, - systemf("%s -cf ../archive15.tar %s > ../out15 2> ../err15", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive15.tar > ../list15", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list15"); - free(fp1); - free(fp2); - - /* Test2g: start with "//?/c:/" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 6); - assertEqualInt(0, - systemf("%s -cf ../archive16.tar %s > ../out16 2> ../err16", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive16.tar > ../list16", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list16"); - free(fp1); - free(fp2); - - /* Test2h: start with "\\?\c:\" */ - mkfullpath(&fp1, &fp2, "aaa/file1", 7); - assertEqualInt(0, - systemf("%s -cf ../archive17.tar %s > ../out17 2> ../err17", - testprog, fp1)); - assertEqualInt(0, - systemf("%s -tf ../archive17.tar > ../list17", testprog)); - /* Check drive letters have been stripped. */ - assertFileContents(fp2, strlen(fp2), "../list17"); - free(fp1); - free(fp2); -#else - skipping("Windows specific test"); -#endif /* _WIN32 && !__CYGWIN__ */ -} diff --git a/Utilities/cmlibarchive/tar/tree.c b/Utilities/cmlibarchive/tar/tree.c deleted file mode 100644 index 360b2a037..000000000 --- a/Utilities/cmlibarchive/tar/tree.c +++ /dev/null @@ -1,795 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - */ - -/*- - * This is a new directory-walking system that addresses a number - * of problems I've had with fts(3). In particular, it has no - * pathname-length limits (other than the size of 'int'), handles - * deep logical traversals, uses considerably less memory, and has - * an opaque interface (easier to modify in the future). - * - * Internally, it keeps a single list of "tree_entry" items that - * represent filesystem objects that require further attention. - * Non-directories are not kept in memory: they are pulled from - * readdir(), returned to the client, then freed as soon as possible. - * Any directory entry to be traversed gets pushed onto the stack. - * - * There is surprisingly little information that needs to be kept for - * each item on the stack. Just the name, depth (represented here as the - * string length of the parent directory's pathname), and some markers - * indicating how to get back to the parent (via chdir("..") for a - * regular dir or via fchdir(2) for a symlink). - */ -#include "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/tree.c,v 1.9 2008/11/27 05:49:52 kientzle Exp $"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_DIRECT_H -#include -#endif -#ifdef HAVE_DIRENT_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) -#include -#endif - -#include "tree.h" - -/* - * TODO: - * 1) Loop checking. - * 3) Arbitrary logical traversals by closing/reopening intermediate fds. - */ - -struct tree_entry { - int depth; - struct tree_entry *next; - struct tree_entry *parent; - char *name; - size_t dirname_length; - dev_t dev; - ino_t ino; - int flags; - /* How to return back to the parent of a symlink. */ -#ifdef HAVE_FCHDIR - int symlink_parent_fd; -#elif defined(_WIN32) && !defined(__CYGWIN__) - char *symlink_parent_path; -#else -#error fchdir function required. -#endif -}; - -/* Definitions for tree_entry.flags bitmap. */ -#define isDir 1 /* This entry is a regular directory. */ -#define isDirLink 2 /* This entry is a symbolic link to a directory. */ -#define needsFirstVisit 4 /* This is an initial entry. */ -#define needsDescent 8 /* This entry needs to be previsited. */ -#define needsOpen 16 /* This is a directory that needs to be opened. */ -#define needsAscent 32 /* This entry needs to be postvisited. */ - -/* - * On Windows, "first visit" is handled as a pattern to be handed to - * _findfirst(). This is consistent with Windows conventions that - * file patterns are handled within the application. On Posix, - * "first visit" is just returned to the client. - */ - -/* - * Local data for this package. - */ -struct tree { - struct tree_entry *stack; - struct tree_entry *current; -#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) - HANDLE d; - BY_HANDLE_FILE_INFORMATION fileInfo; -#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE - WIN32_FIND_DATA _findData; - WIN32_FIND_DATA *findData; -#else - DIR *d; -#define INVALID_DIR_HANDLE NULL - struct dirent *de; -#endif - int flags; - int visit_type; - int tree_errno; /* Error code from last failed operation. */ - - /* Dynamically-sized buffer for holding path */ - char *buff; - size_t buff_length; - - const char *basename; /* Last path element */ - size_t dirname_length; /* Leading dir length */ - size_t path_length; /* Total path length */ - - int depth; - int openCount; - int maxOpenCount; - - struct stat lst; - struct stat st; -}; - -/* Definitions for tree.flags bitmap. */ -#define hasStat 16 /* The st entry is valid. */ -#define hasLstat 32 /* The lst entry is valid. */ -#define hasFileInfo 64 /* The Windows fileInfo entry is valid. */ - -#if defined(_WIN32) && !defined(__CYGWIN__) -static int -tree_dir_next_windows(struct tree *t, const char *pattern); -#else -static int -tree_dir_next_posix(struct tree *t); -#endif - -#ifdef HAVE_DIRENT_D_NAMLEN -/* BSD extension; avoids need for a strlen() call. */ -#define D_NAMELEN(dp) (dp)->d_namlen -#else -#define D_NAMELEN(dp) (strlen((dp)->d_name)) -#endif - -#include -void -tree_dump(struct tree *t, FILE *out) -{ - char buff[300]; - struct tree_entry *te; - - fprintf(out, "\tdepth: %d\n", t->depth); - fprintf(out, "\tbuff: %s\n", t->buff); - fprintf(out, "\tpwd: %s\n", getcwd(buff, sizeof(buff))); - fprintf(out, "\tbasename: %s\n", t->basename); - fprintf(out, "\tstack:\n"); - for (te = t->stack; te != NULL; te = te->next) { - fprintf(out, "\t\t%s%d:\"%s\" %s%s%s%s%s\n", - t->current == te ? "*" : " ", - te->depth, - te->name, - te->flags & needsFirstVisit ? "V" : "", - te->flags & needsDescent ? "D" : "", - te->flags & needsOpen ? "O" : "", - te->flags & needsAscent ? "A" : "", - (t->current == te && t->d) ? "+" : "" - ); - } -} - -/* - * Add a directory path to the current stack. - */ -static void -tree_push(struct tree *t, const char *path) -{ - struct tree_entry *te; - - te = malloc(sizeof(*te)); - memset(te, 0, sizeof(*te)); - te->next = t->stack; - te->parent = t->current; - if (te->parent) - te->depth = te->parent->depth + 1; - t->stack = te; -#ifdef HAVE_FCHDIR - te->symlink_parent_fd = -1; - te->name = strdup(path); -#elif defined(_WIN32) && !defined(__CYGWIN__) - te->symlink_parent_path = NULL; - te->name = _strdup(path); -#endif - te->flags = needsDescent | needsOpen | needsAscent; - te->dirname_length = t->dirname_length; -} - -/* - * Append a name to the current dir path. - */ -static void -tree_append(struct tree *t, const char *name, size_t name_length) -{ - char *p; - - if (t->buff != NULL) - t->buff[t->dirname_length] = '\0'; - /* Strip trailing '/' from name, unless entire name is "/". */ - while (name_length > 1 && - (name[name_length - 1] == '/' || name[name_length - 1] == '/')) - name_length--; - - /* Resize pathname buffer as needed. */ - while (name_length + 1 + t->dirname_length >= t->buff_length) { - t->buff_length *= 2; - if (t->buff_length < 1024) - t->buff_length = 1024; - t->buff = realloc(t->buff, t->buff_length); - if (t->buff == NULL) - abort(); - } - p = t->buff + t->dirname_length; - t->path_length = t->dirname_length + name_length; - /* Add a separating '/' if it's needed. */ - if (t->dirname_length > 0 && p[-1] != '/') { - *p++ = '/'; - t->path_length ++; - } -#if HAVE_STRNCPY_S - strncpy_s(p, t->buff_length - (p - t->buff), name, name_length); -#else - strncpy(p, name, name_length); -#endif - p[name_length] = '\0'; - t->basename = p; -} - -/* - * Open a directory tree for traversal. - */ -struct tree * -tree_open(const char *path) -{ - struct tree *t; - - t = malloc(sizeof(*t)); - memset(t, 0, sizeof(*t)); -// tree_append(t, path, strlen(path)); - /* First item is set up a lot like a symlink traversal. */ - tree_push(t, path); - t->stack->flags = needsFirstVisit | isDirLink; -#ifdef HAVE_FCHDIR - t->stack->symlink_parent_fd = open(".", O_RDONLY); - t->openCount++; -#elif defined(_WIN32) && !defined(__CYGWIN__) - t->stack->symlink_parent_path = _getcwd(NULL, 0); -#endif - t->d = INVALID_DIR_HANDLE; - return (t); -} - -/* - * We've finished a directory; ascend back to the parent. - */ -static int -tree_ascend(struct tree *t) -{ - struct tree_entry *te; - int r = 0; - - te = t->stack; - t->depth--; - if (te->flags & isDirLink) { -#ifdef HAVE_FCHDIR - if (fchdir(te->symlink_parent_fd) != 0) { - t->tree_errno = errno; - r = TREE_ERROR_FATAL; - } - close(te->symlink_parent_fd); -#elif defined(_WIN32) && !defined(__CYGWIN__) - if (SetCurrentDirectory(te->symlink_parent_path) == 0) { - t->tree_errno = errno; - r = TREE_ERROR_FATAL; - } - free(te->symlink_parent_path); - te->symlink_parent_path = NULL; -#endif - t->openCount--; - } else { -#if defined(_WIN32) && !defined(__CYGWIN__) - if (SetCurrentDirectory("..") == 0) { -#else - if (chdir("..") != 0) { -#endif - t->tree_errno = errno; - r = TREE_ERROR_FATAL; - } - } - return (r); -} - -/* - * Pop the working stack. - */ -static void -tree_pop(struct tree *t) -{ - struct tree_entry *te; - - if (t->buff) - t->buff[t->dirname_length] = '\0'; - if (t->stack == t->current && t->current != NULL) - t->current = t->current->parent; - te = t->stack; - t->stack = te->next; - t->dirname_length = te->dirname_length; - if (t->buff) { - t->basename = t->buff + t->dirname_length; - while (t->basename[0] == '/') - t->basename++; - } - free(te->name); - free(te); -} - -/* - * Get the next item in the tree traversal. - */ -int -tree_next(struct tree *t) -{ - int r; - - /* If we're called again after a fatal error, that's an API - * violation. Just crash now. */ - if (t->visit_type == TREE_ERROR_FATAL) { - fprintf(stderr, "Unable to continue traversing" - " directory heirarchy after a fatal error."); - abort(); - } - - while (t->stack != NULL) { - /* If there's an open dir, get the next entry from there. */ - if (t->d != INVALID_DIR_HANDLE) { -#if defined(_WIN32) && !defined(__CYGWIN__) - r = tree_dir_next_windows(t, NULL); -#else - r = tree_dir_next_posix(t); -#endif - if (r == 0) - continue; - return (r); - } - - if (t->stack->flags & needsFirstVisit) { -#if defined(_WIN32) && !defined(__CYGWIN__) - char *d = strdup(t->stack->name); - char *p, *pattern; - //tree_pop(t); - t->stack->flags &= ~needsFirstVisit; - if (strchr(d, '*') || strchr(d, '?')) { - // It has a wildcard in it... - if ((p = strrchr(d, '\\')) != NULL) { - pattern = strdup(p + 1); - p[1] = '\0'; - chdir(d); - tree_append(t, d, strlen(d)); - free(d); - } else { - pattern = d; - } - r = tree_dir_next_windows(t, pattern); - free(pattern); - if (r == 0) - continue; - return (r); - } - // Not a pattern, handle it as-is... -#endif - /* Top stack item needs a regular visit. */ - t->current = t->stack; - tree_append(t, t->stack->name, strlen(t->stack->name)); - //t->dirname_length = t->path_length; - //tree_pop(t); - t->stack->flags &= ~needsFirstVisit; - return (t->visit_type = TREE_REGULAR); - } else if (t->stack->flags & needsDescent) { - /* Top stack item is dir to descend into. */ - t->current = t->stack; - tree_append(t, t->stack->name, strlen(t->stack->name)); - t->stack->flags &= ~needsDescent; - /* If it is a link, set up fd for the ascent. */ - if (t->stack->flags & isDirLink) { -#ifdef HAVE_FCHDIR - t->stack->symlink_parent_fd = open(".", O_RDONLY); - t->openCount++; - if (t->openCount > t->maxOpenCount) - t->maxOpenCount = t->openCount; -#elif defined(_WIN32) && !defined(__CYGWIN__) - t->stack->symlink_parent_path = _getcwd(NULL, 0); -#endif - } - t->dirname_length = t->path_length; -#if defined(_WIN32) && !defined(__CYGWIN__) - if (t->path_length == 259 || !SetCurrentDirectory(t->stack->name) != 0) -#else - if (chdir(t->stack->name) != 0) -#endif - { - /* chdir() failed; return error */ - tree_pop(t); - t->tree_errno = errno; - return (t->visit_type = TREE_ERROR_DIR); - } - t->depth++; - return (t->visit_type = TREE_POSTDESCENT); - } else if (t->stack->flags & needsOpen) { - t->stack->flags &= ~needsOpen; -#if defined(_WIN32) && !defined(__CYGWIN__) - r = tree_dir_next_windows(t, "*"); -#else - r = tree_dir_next_posix(t); -#endif - if (r == 0) - continue; - return (r); - } else if (t->stack->flags & needsAscent) { - /* Top stack item is dir and we're done with it. */ - r = tree_ascend(t); - tree_pop(t); - t->visit_type = r != 0 ? r : TREE_POSTASCENT; - return (t->visit_type); - } else { - /* Top item on stack is dead. */ - tree_pop(t); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - } - } - return (t->visit_type = 0); -} - -#if defined(_WIN32) && !defined(__CYGWIN__) -static int -tree_dir_next_windows(struct tree *t, const char *pattern) -{ - const char *name; - size_t namelen; - int r; - - for (;;) { - if (pattern != NULL) { - t->d = FindFirstFile(pattern, &t->_findData); - if (t->d == INVALID_DIR_HANDLE) { - r = tree_ascend(t); /* Undo "chdir" */ - tree_pop(t); - t->tree_errno = errno; - t->visit_type = r != 0 ? r : TREE_ERROR_DIR; - return (t->visit_type); - } - t->findData = &t->_findData; - pattern = NULL; - } else if (!FindNextFile(t->d, &t->_findData)) { - FindClose(t->d); - t->d = INVALID_DIR_HANDLE; - t->findData = NULL; - return (0); - } - name = t->findData->cFileName; - namelen = strlen(name); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - if (name[0] == '.' && name[1] == '\0') - continue; - if (name[0] == '.' && name[1] == '.' && name[2] == '\0') - continue; - tree_append(t, name, namelen); - return (t->visit_type = TREE_REGULAR); - } -} -#else -static int -tree_dir_next_posix(struct tree *t) -{ - int r; - const char *name; - size_t namelen; - - if (t->d == NULL) { - if ((t->d = opendir(".")) == NULL) { - r = tree_ascend(t); /* Undo "chdir" */ - tree_pop(t); - t->tree_errno = errno; - t->visit_type = r != 0 ? r : TREE_ERROR_DIR; - return (t->visit_type); - } - } - for (;;) { - t->de = readdir(t->d); - if (t->de == NULL) { - closedir(t->d); - t->d = INVALID_DIR_HANDLE; - return (0); - } - name = t->de->d_name; - namelen = D_NAMELEN(t->de); - t->flags &= ~hasLstat; - t->flags &= ~hasStat; - if (name[0] == '.' && name[1] == '\0') - continue; - if (name[0] == '.' && name[1] == '.' && name[2] == '\0') - continue; - tree_append(t, name, namelen); - return (t->visit_type = TREE_REGULAR); - } -} -#endif - -/* - * Return error code. - */ -int -tree_errno(struct tree *t) -{ - return (t->tree_errno); -} - -/* - * Called by the client to mark the directory just returned from - * tree_next() as needing to be visited. - */ -void -tree_descend(struct tree *t) -{ - if (t->visit_type != TREE_REGULAR) - return; - - if (tree_current_is_physical_dir(t)) { - tree_push(t, t->basename); - t->stack->flags |= isDir; - } else if (tree_current_is_dir(t)) { - tree_push(t, t->basename); - t->stack->flags |= isDirLink; - } -} - -/* - * Get the stat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_stat(struct tree *t) -{ - if (!(t->flags & hasStat)) { - if (stat(tree_current_access_path(t), &t->st) != 0) - return NULL; - t->flags |= hasStat; - } - return (&t->st); -} - -#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) -const BY_HANDLE_FILE_INFORMATION * -tree_current_file_information(struct tree *t) -{ - if (!(t->flags & hasFileInfo)) { - HANDLE h = CreateFile(tree_current_access_path(t), - 0, 0, NULL, - OPEN_EXISTING, - FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, - NULL); - if (h == INVALID_HANDLE_VALUE) - return NULL; - if (!GetFileInformationByHandle(h, &t->fileInfo)) { - CloseHandle(h); - return NULL; - } - CloseHandle(h); - t->flags |= hasFileInfo; - } - return (&t->fileInfo); -} -#endif -/* - * Get the lstat() data for the entry just returned from tree_next(). - */ -const struct stat * -tree_current_lstat(struct tree *t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - return (tree_current_stat(t)); -#else - if (!(t->flags & hasLstat)) { - if (lstat(tree_current_access_path(t), &t->lst) != 0) - return NULL; - t->flags |= hasLstat; - } - return (&t->lst); -#endif -} - -/* - * Test whether current entry is a dir or link to a dir. - */ -int -tree_current_is_dir(struct tree *t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - if (t->findData) - return (t->findData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - if (tree_current_file_information(t)) - return (t->fileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - return (0); -#else - const struct stat *st; - /* - * If we already have lstat() info, then try some - * cheap tests to determine if this is a dir. - */ - if (t->flags & hasLstat) { - /* If lstat() says it's a dir, it must be a dir. */ - if (S_ISDIR(tree_current_lstat(t)->st_mode)) - return 1; - /* Not a dir; might be a link to a dir. */ - /* If it's not a link, then it's not a link to a dir. */ - if (!S_ISLNK(tree_current_lstat(t)->st_mode)) - return 0; - /* - * It's a link, but we don't know what it's a link to, - * so we'll have to use stat(). - */ - } - - st = tree_current_stat(t); - /* If we can't stat it, it's not a dir. */ - if (st == NULL) - return 0; - /* Use the definitive test. Hopefully this is cached. */ - return (S_ISDIR(st->st_mode)); -#endif -} - -/* - * Test whether current entry is a physical directory. Usually, we - * already have at least one of stat() or lstat() in memory, so we - * use tricks to try to avoid an extra trip to the disk. - */ -int -tree_current_is_physical_dir(struct tree *t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - if (tree_current_is_physical_link(t)) - return (0); - return (tree_current_is_dir(t)); -#else - const struct stat *st; - - /* - * If stat() says it isn't a dir, then it's not a dir. - * If stat() data is cached, this check is free, so do it first. - */ - if ((t->flags & hasStat) - && (!S_ISDIR(tree_current_stat(t)->st_mode))) - return 0; - - /* - * Either stat() said it was a dir (in which case, we have - * to determine whether it's really a link to a dir) or - * stat() info wasn't available. So we use lstat(), which - * hopefully is already cached. - */ - - st = tree_current_lstat(t); - /* If we can't stat it, it's not a dir. */ - if (st == NULL) - return 0; - /* Use the definitive test. Hopefully this is cached. */ - return (S_ISDIR(st->st_mode)); -#endif -} - -/* - * Test whether current entry is a symbolic link. - */ -int -tree_current_is_physical_link(struct tree *t) -{ -#if defined(_WIN32) && !defined(__CYGWIN__) - if (t->findData) - return ((t->findData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - && (t->findData->dwReserved0 == IO_REPARSE_TAG_SYMLINK)); - return (0); -#else - const struct stat *st = tree_current_lstat(t); - if (st == NULL) - return 0; - return (S_ISLNK(st->st_mode)); -#endif -} - -/* - * Return the access path for the entry just returned from tree_next(). - */ -const char * -tree_current_access_path(struct tree *t) -{ - return (t->basename); -} - -/* - * Return the full path for the entry just returned from tree_next(). - */ -const char * -tree_current_path(struct tree *t) -{ - return (t->buff); -} - -/* - * Return the length of the path for the entry just returned from tree_next(). - */ -size_t -tree_current_pathlen(struct tree *t) -{ - return (t->path_length); -} - -/* - * Return the nesting depth of the entry just returned from tree_next(). - */ -int -tree_current_depth(struct tree *t) -{ - return (t->depth); -} - -/* - * Terminate the traversal and release any resources. - */ -void -tree_close(struct tree *t) -{ - /* Release anything remaining in the stack. */ - while (t->stack != NULL) - tree_pop(t); - if (t->buff) - free(t->buff); - /* TODO: Ensure that premature close() resets cwd */ -#if 0 -#ifdef HAVE_FCHDIR - if (t->initialDirFd >= 0) { - int s = fchdir(t->initialDirFd); - (void)s; /* UNUSED */ - close(t->initialDirFd); - t->initialDirFd = -1; - } -#elif defined(_WIN32) && !defined(__CYGWIN__) - if (t->initialDir != NULL) { - SetCurrentDir(t->initialDir); - free(t->initialDir); - t->initialDir = NULL; - } -#endif -#endif - free(t); -} diff --git a/Utilities/cmlibarchive/tar/tree.h b/Utilities/cmlibarchive/tar/tree.h deleted file mode 100644 index a99edf27c..000000000 --- a/Utilities/cmlibarchive/tar/tree.h +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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. - * - * $FreeBSD: src/usr.bin/tar/tree.h,v 1.4 2008/11/27 05:49:52 kientzle Exp $ - */ - -/*- - * A set of routines for traversing directory trees. - * Similar in concept to the fts library, but with a few - * important differences: - * * Uses less memory. In particular, fts stores an entire directory - * in memory at a time. This package only keeps enough subdirectory - * information in memory to track the traversal. Information - * about non-directories is discarded as soon as possible. - * * Supports very deep logical traversals. The fts package - * uses "non-chdir" approach for logical traversals. This - * package does use a chdir approach for logical traversals - * and can therefore handle pathnames much longer than PATH_MAX. - * * Supports deep physical traversals "out of the box." - * Due to the memory optimizations above, there's no need to - * limit dir names to 32k. - */ - -#include -#include - -struct tree; - -/* Initiate/terminate a tree traversal. */ -struct tree *tree_open(const char * /* pathname */); -void tree_close(struct tree *); - -/* - * tree_next() returns Zero if there is no next entry, non-zero if - * there is. Note that directories are visited three times. - * Directories are always visited first as part of enumerating their - * parent; that is a "regular" visit. If tree_descend() is invoked at - * that time, the directory is added to a work list and will - * subsequently be visited two more times: once just after descending - * into the directory ("postdescent") and again just after ascending - * back to the parent ("postascent"). - * - * TREE_ERROR_DIR is returned if the descent failed (because the - * directory couldn't be opened, for instance). This is returned - * instead of TREE_POSTDESCENT/TREE_POSTASCENT. TREE_ERROR_DIR is not a - * fatal error, but it does imply that the relevant subtree won't be - * visited. TREE_ERROR_FATAL is returned for an error that left the - * traversal completely hosed. Right now, this is only returned for - * chdir() failures during ascent. - */ -#define TREE_REGULAR 1 -#define TREE_POSTDESCENT 2 -#define TREE_POSTASCENT 3 -#define TREE_ERROR_DIR -1 -#define TREE_ERROR_FATAL -2 - -int tree_next(struct tree *); - -/* Errno value associated with the last traversal error. */ -int tree_errno(struct tree *); - -/* - * Request that current entry be visited. If you invoke it on every - * directory, you'll get a physical traversal. This is ignored if the - * current entry isn't a directory or a link to a directory. So, if - * you invoke this on every returned path, you'll get a full logical - * traversal. - */ -void tree_descend(struct tree *); - -/* - * Return information about the current entry. - */ - -/* Current depth in the traversal. */ -int tree_current_depth(struct tree *); - -/* - * The current full pathname, length of the full pathname, and a name - * that can be used to access the file. Because tree does use chdir - * extensively, the access path is almost never the same as the full - * current path. - * - * TODO: Flesh out this interface to provide other information. In - * particular, Windows can provide file size, mode, and some permission - * information without invoking stat() at all. - * - * TODO: On platforms that support it, use openat()-style operations - * to eliminate the chdir() operations entirely while still supporting - * arbitrarily deep traversals. This makes access_path troublesome to - * support, of course, which means we'll need a rich enough interface - * that clients can function without it. (In particular, we'll need - * tree_current_open() that returns an open file descriptor.) - * - * TODO: Provide tree_current_archive_entry(). - */ -const char *tree_current_path(struct tree *); -size_t tree_current_pathlen(struct tree *); -const char *tree_current_access_path(struct tree *); - -/* - * Request the lstat() or stat() data for the current path. Since the - * tree package needs to do some of this anyway, and caches the - * results, you should take advantage of it here if you need it rather - * than make a redundant stat() or lstat() call of your own. - */ -const struct stat *tree_current_stat(struct tree *); -const struct stat *tree_current_lstat(struct tree *); - -/* The following functions use tricks to avoid a certain number of - * stat()/lstat() calls. */ -/* "is_physical_dir" is equivalent to S_ISDIR(tree_current_lstat()->st_mode) */ -int tree_current_is_physical_dir(struct tree *); -/* "is_physical_link" is equivalent to S_ISLNK(tree_current_lstat()->st_mode) */ -int tree_current_is_physical_link(struct tree *); -/* "is_dir" is equivalent to S_ISDIR(tree_current_stat()->st_mode) */ -int tree_current_is_dir(struct tree *); - -/* For testing/debugging: Dump the internal status to the given filehandle. */ -void tree_dump(struct tree *, FILE *); diff --git a/Utilities/cmlibarchive/tar/util.c b/Utilities/cmlibarchive/tar/util.c deleted file mode 100644 index 82b938e25..000000000 --- a/Utilities/cmlibarchive/tar/util.c +++ /dev/null @@ -1,530 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.23 2008/12/15 06:00:25 kientzle Exp $"); - -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_SYS_TYPES_H -#include /* Linux doesn't define mode_t, etc. in sys/stat.h. */ -#endif -#include -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_STDARG_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_WCTYPE_H -#include -#else -/* If we don't have wctype, we need to hack up some version of iswprint(). */ -#define iswprint isprint -#endif - -#include "bsdtar.h" -#include "err.h" - -static size_t bsdtar_expand_char(char *, size_t, char); -static const char *strip_components(const char *path, int elements); - -/* TODO: Hack up a version of mbtowc for platforms with no wide - * character support at all. I think the following might suffice, - * but it needs careful testing. - * #if !HAVE_MBTOWC - * #define mbtowc(wcp, p, n) ((*wcp = *p), 1) - * #endif - */ - -/* - * Print a string, taking care with any non-printable characters. - * - * Note that we use a stack-allocated buffer to receive the formatted - * string if we can. This is partly performance (avoiding a call to - * malloc()), partly out of expedience (we have to call vsnprintf() - * before malloc() anyway to find out how big a buffer we need; we may - * as well point that first call at a small local buffer in case it - * works), but mostly for safety (so we can use this to print messages - * about out-of-memory conditions). - */ - -void -safe_fprintf(FILE *f, const char *fmt, ...) -{ - char fmtbuff_stack[256]; /* Place to format the printf() string. */ - char outbuff[256]; /* Buffer for outgoing characters. */ - char *fmtbuff_heap; /* If fmtbuff_stack is too small, we use malloc */ - char *fmtbuff; /* Pointer to fmtbuff_stack or fmtbuff_heap. */ - int fmtbuff_length; - int length, n; - va_list ap; - const char *p; - unsigned i; - wchar_t wc; - char try_wc; - - /* Use a stack-allocated buffer if we can, for speed and safety. */ - fmtbuff_heap = NULL; - fmtbuff_length = sizeof(fmtbuff_stack); - fmtbuff = fmtbuff_stack; - - /* Try formatting into the stack buffer. */ - va_start(ap, fmt); - length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap); - va_end(ap); - - /* If the result was too large, allocate a buffer on the heap. */ - if (length >= fmtbuff_length) { - fmtbuff_length = length+1; - fmtbuff_heap = malloc(fmtbuff_length); - - /* Reformat the result into the heap buffer if we can. */ - if (fmtbuff_heap != NULL) { - fmtbuff = fmtbuff_heap; - va_start(ap, fmt); - length = vsnprintf(fmtbuff, fmtbuff_length, fmt, ap); - va_end(ap); - } else { - /* Leave fmtbuff pointing to the truncated - * string in fmtbuff_stack. */ - length = sizeof(fmtbuff_stack) - 1; - } - } - - /* Note: mbrtowc() has a cleaner API, but mbtowc() seems a bit - * more portable, so we use that here instead. */ - n = mbtowc(NULL, NULL, 1); /* Reset the shift state. */ - - /* Write data, expanding unprintable characters. */ - p = fmtbuff; - i = 0; - try_wc = 1; - while (*p != '\0') { - - /* Convert to wide char, test if the wide - * char is printable in the current locale. */ - if (try_wc && (n = mbtowc(&wc, p, length)) != -1) { - length -= n; - if (iswprint(wc) && wc != L'\\') { - /* Printable, copy the bytes through. */ - while (n-- > 0) - outbuff[i++] = *p++; - } else { - /* Not printable, format the bytes. */ - while (n-- > 0) - i += bsdtar_expand_char( - outbuff, i, *p++); - } - } else { - /* After any conversion failure, don't bother - * trying to convert the rest. */ - i += bsdtar_expand_char(outbuff, i, *p++); - try_wc = 0; - } - - /* If our output buffer is full, dump it and keep going. */ - if (i > (sizeof(outbuff) - 20)) { - outbuff[i++] = '\0'; - fprintf(f, "%s", outbuff); - i = 0; - } - } - outbuff[i++] = '\0'; - fprintf(f, "%s", outbuff); - - /* If we allocated a heap-based formatting buffer, free it now. */ - if (fmtbuff_heap != NULL) - free(fmtbuff_heap); -} - -/* - * Render an arbitrary sequence of bytes into printable ASCII characters. - */ -static size_t -bsdtar_expand_char(char *buff, size_t offset, char c) -{ - size_t i = offset; - - if (isprint((unsigned char)c) && c != '\\') - buff[i++] = c; - else { - buff[i++] = '\\'; - switch (c) { - case '\a': buff[i++] = 'a'; break; - case '\b': buff[i++] = 'b'; break; - case '\f': buff[i++] = 'f'; break; - case '\n': buff[i++] = 'n'; break; -#if '\r' != '\n' - /* On some platforms, \n and \r are the same. */ - case '\r': buff[i++] = 'r'; break; -#endif - case '\t': buff[i++] = 't'; break; - case '\v': buff[i++] = 'v'; break; - case '\\': buff[i++] = '\\'; break; - default: - sprintf(buff + i, "%03o", 0xFF & (int)c); - i += 3; - } - } - - return (i - offset); -} - -int -yes(const char *fmt, ...) -{ - char buff[32]; - char *p; - ssize_t l; - - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, " (y/N)? "); - fflush(stderr); - - l = read(2, buff, sizeof(buff) - 1); - if (l <= 0) - return (0); - buff[l] = 0; - - for (p = buff; *p != '\0'; p++) { - if (isspace((unsigned char)*p)) - continue; - switch(*p) { - case 'y': case 'Y': - return (1); - case 'n': case 'N': - return (0); - default: - return (0); - } - } - - return (0); -} - -/*- - * The logic here for -C attempts to avoid - * chdir() as long as possible. For example: - * "-C /foo -C /bar file" needs chdir("/bar") but not chdir("/foo") - * "-C /foo -C bar file" needs chdir("/foo/bar") - * "-C /foo -C bar /file1" does not need chdir() - * "-C /foo -C bar /file1 file2" needs chdir("/foo/bar") before file2 - * - * The only correct way to handle this is to record a "pending" chdir - * request and combine multiple requests intelligently until we - * need to process a non-absolute file. set_chdir() adds the new dir - * to the pending list; do_chdir() actually executes any pending chdir. - * - * This way, programs that build tar command lines don't have to worry - * about -C with non-existent directories; such requests will only - * fail if the directory must be accessed. - * - * TODO: Make this handle Windows paths correctly. - */ -void -set_chdir(struct bsdtar *bsdtar, const char *newdir) -{ - if (newdir[0] == '/') { - /* The -C /foo -C /bar case; dump first one. */ - free(bsdtar->pending_chdir); - bsdtar->pending_chdir = NULL; - } - if (bsdtar->pending_chdir == NULL) - /* Easy case: no previously-saved dir. */ - bsdtar->pending_chdir = strdup(newdir); - else { - /* The -C /foo -C bar case; concatenate */ - char *old_pending = bsdtar->pending_chdir; - size_t old_len = strlen(old_pending); - bsdtar->pending_chdir = malloc(old_len + strlen(newdir) + 2); - if (old_pending[old_len - 1] == '/') - old_pending[old_len - 1] = '\0'; - if (bsdtar->pending_chdir != NULL) - sprintf(bsdtar->pending_chdir, "%s/%s", - old_pending, newdir); - free(old_pending); - } - if (bsdtar->pending_chdir == NULL) - lafe_errc(1, errno, "No memory"); -} - -void -do_chdir(struct bsdtar *bsdtar) -{ - if (bsdtar->pending_chdir == NULL) - return; - - if (chdir(bsdtar->pending_chdir) != 0) { - lafe_errc(1, 0, "could not chdir to '%s'\n", - bsdtar->pending_chdir); - } - free(bsdtar->pending_chdir); - bsdtar->pending_chdir = NULL; -} - -const char * -strip_components(const char *p, int elements) -{ - /* Skip as many elements as necessary. */ - while (elements > 0) { - switch (*p++) { - case '/': -#if defined(_WIN32) && !defined(__CYGWIN__) - case '\\': /* Support \ path sep on Windows ONLY. */ -#endif - elements--; - break; - case '\0': - /* Path is too short, skip it. */ - return (NULL); - } - } - - /* Skip any / characters. This handles short paths that have - * additional / termination. This also handles the case where - * the logic above stops in the middle of a duplicate // - * sequence (which would otherwise get converted to an - * absolute path). */ - for (;;) { - switch (*p) { - case '/': -#if defined(_WIN32) && !defined(__CYGWIN__) - case '\\': /* Support \ path sep on Windows ONLY. */ -#endif - ++p; - break; - case '\0': - return (NULL); - default: - return (p); - } - } -} - -/* - * Handle --strip-components and any future path-rewriting options. - * Returns non-zero if the pathname should not be extracted. - * - * TODO: Support pax-style regex path rewrites. - */ -int -edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry) -{ - const char *name = archive_entry_pathname(entry); -#if HAVE_REGEX_H - char *subst_name; - int r; -#endif - -#if HAVE_REGEX_H - r = apply_substitution(bsdtar, name, &subst_name, 0); - if (r == -1) { - lafe_warnc(0, "Invalid substitution, skipping entry"); - return 1; - } - if (r == 1) { - archive_entry_copy_pathname(entry, subst_name); - if (*subst_name == '\0') { - free(subst_name); - return -1; - } else - free(subst_name); - name = archive_entry_pathname(entry); - } - - if (archive_entry_hardlink(entry)) { - r = apply_substitution(bsdtar, archive_entry_hardlink(entry), &subst_name, 1); - if (r == -1) { - lafe_warnc(0, "Invalid substitution, skipping entry"); - return 1; - } - if (r == 1) { - archive_entry_copy_hardlink(entry, subst_name); - free(subst_name); - } - } - if (archive_entry_symlink(entry) != NULL) { - r = apply_substitution(bsdtar, archive_entry_symlink(entry), &subst_name, 1); - if (r == -1) { - lafe_warnc(0, "Invalid substitution, skipping entry"); - return 1; - } - if (r == 1) { - archive_entry_copy_symlink(entry, subst_name); - free(subst_name); - } - } -#endif - - /* Strip leading dir names as per --strip-components option. */ - if (bsdtar->strip_components > 0) { - const char *linkname = archive_entry_hardlink(entry); - - name = strip_components(name, bsdtar->strip_components); - if (name == NULL) - return (1); - - if (linkname != NULL) { - linkname = strip_components(linkname, - bsdtar->strip_components); - if (linkname == NULL) - return (1); - archive_entry_copy_hardlink(entry, linkname); - } - } - - /* By default, don't write or restore absolute pathnames. */ - if (!bsdtar->option_absolute_paths) { - const char *rp, *p = name; - int slashonly = 1; - - /* Remove leading "//./" or "//?/" or "//?/UNC/" - * (absolute path prefixes used by Windows API) */ - if ((p[0] == '/' || p[0] == '\\') && - (p[1] == '/' || p[1] == '\\') && - (p[2] == '.' || p[2] == '?') && - (p[3] == '/' || p[3] == '\\')) - { - if (p[2] == '?' && - (p[4] == 'U' || p[4] == 'u') && - (p[5] == 'N' || p[5] == 'n') && - (p[6] == 'C' || p[6] == 'c') && - (p[7] == '/' || p[7] == '\\')) - p += 8; - else - p += 4; - slashonly = 0; - } - do { - rp = p; - /* Remove leading drive letter from archives created - * on Windows. */ - if (((p[0] >= 'a' && p[0] <= 'z') || - (p[0] >= 'A' && p[0] <= 'Z')) && - p[1] == ':') { - p += 2; - slashonly = 0; - } - /* Remove leading "/../", "//", etc. */ - while (p[0] == '/' || p[0] == '\\') { - if (p[1] == '.' && p[2] == '.' && - (p[3] == '/' || p[3] == '\\')) { - p += 3; /* Remove "/..", leave "/" - * for next pass. */ - slashonly = 0; - } else - p += 1; /* Remove "/". */ - } - } while (rp != p); - - if (p != name && !bsdtar->warned_lead_slash) { - /* Generate a warning the first time this happens. */ - if (slashonly) - lafe_warnc(0, - "Removing leading '%c' from member names", - name[0]); - else - lafe_warnc(0, - "Removing leading drive letter from " - "member names"); - bsdtar->warned_lead_slash = 1; - } - - /* Special case: Stripping everything yields ".". */ - if (*p == '\0') - name = "."; - else - name = p; - } else { - /* Strip redundant leading '/' characters. */ - while (name[0] == '/' && name[1] == '/') - name++; - } - - /* Safely replace name in archive_entry. */ - if (name != archive_entry_pathname(entry)) { - char *q = strdup(name); - archive_entry_copy_pathname(entry, q); - free(q); - } - return (0); -} - -/* - * Like strcmp(), but try to be a little more aware of the fact that - * we're comparing two paths. Right now, it just handles leading - * "./" and trailing '/' specially, so that "a/b/" == "./a/b" - * - * TODO: Make this better, so that "./a//b/./c/" == "a/b/c" - * TODO: After this works, push it down into libarchive. - * TODO: Publish the path normalization routines in libarchive so - * that bsdtar can normalize paths and use fast strcmp() instead - * of this. - * - * Note: This is currently only used within write.c, so should - * not handle \ path separators. - */ - -int -pathcmp(const char *a, const char *b) -{ - /* Skip leading './' */ - if (a[0] == '.' && a[1] == '/' && a[2] != '\0') - a += 2; - if (b[0] == '.' && b[1] == '/' && b[2] != '\0') - b += 2; - /* Find the first difference, or return (0) if none. */ - while (*a == *b) { - if (*a == '\0') - return (0); - a++; - b++; - } - /* - * If one ends in '/' and the other one doesn't, - * they're the same. - */ - if (a[0] == '/' && a[1] == '\0' && b[0] == '\0') - return (0); - if (a[0] == '\0' && b[0] == '/' && b[1] == '\0') - return (0); - /* They're really different, return the correct sign. */ - return (*(const unsigned char *)a - *(const unsigned char *)b); -} diff --git a/Utilities/cmlibarchive/tar/write.c b/Utilities/cmlibarchive/tar/write.c deleted file mode 100644 index 43c5dfe52..000000000 --- a/Utilities/cmlibarchive/tar/write.c +++ /dev/null @@ -1,1129 +0,0 @@ -/*- - * Copyright (c) 2003-2007 Tim Kientzle - * 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 "bsdtar_platform.h" -__FBSDID("$FreeBSD: src/usr.bin/tar/write.c,v 1.79 2008/11/27 05:49:52 kientzle Exp $"); - -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_ATTR_XATTR_H -#include -#endif -#ifdef HAVE_ERRNO_H -#include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#ifdef HAVE_GRP_H -#include -#endif -#ifdef HAVE_IO_H -#include -#endif -#ifdef HAVE_LIMITS_H -#include -#endif -#ifdef HAVE_LINUX_FS_H -#include /* for Linux file flags */ -#endif -/* - * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. - * As the include guards don't agree, the order of include is important. - */ -#ifdef HAVE_LINUX_EXT2_FS_H -#include /* for Linux file flags */ -#endif -#if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__) -/* This header exists but is broken on Cygwin. */ -#include -#endif -#ifdef HAVE_PWD_H -#include -#endif -#include -#ifdef HAVE_STDLIB_H -#include -#endif -#ifdef HAVE_STRING_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_WINDOWS_H -#include -#endif - -#include "bsdtar.h" -#include "err.h" -#include "line_reader.h" -#include "tree.h" - -/* Size of buffer for holding file data prior to writing. */ -#define FILEDATABUFLEN 65536 - -/* Fixed size of uname/gname caches. */ -#define name_cache_size 101 - -static const char * const NO_NAME = "(noname)"; - -struct archive_dir_entry { - struct archive_dir_entry *next; - time_t mtime_sec; - int mtime_nsec; - char *name; -}; - -struct archive_dir { - struct archive_dir_entry *head, *tail; -}; - -struct name_cache { - int probes; - int hits; - size_t size; - struct { - id_t id; - const char *name; - } cache[name_cache_size]; -}; - -static void add_dir_list(struct bsdtar *bsdtar, const char *path, - time_t mtime_sec, int mtime_nsec); -static int append_archive(struct bsdtar *, struct archive *, - struct archive *ina); -static int append_archive_filename(struct bsdtar *, - struct archive *, const char *fname); -static void archive_names_from_file(struct bsdtar *bsdtar, - struct archive *a); -static int copy_file_data(struct bsdtar *, struct archive *a, - struct archive *ina, struct archive_entry *); -static int new_enough(struct bsdtar *, const char *path, - const struct stat *); -static void report_write(struct bsdtar *, struct archive *, - struct archive_entry *, int64_t progress); -static void test_for_append(struct bsdtar *); -static void write_archive(struct archive *, struct bsdtar *); -static void write_entry_backend(struct bsdtar *, struct archive *, - struct archive_entry *); -static int write_file_data(struct bsdtar *, struct archive *, - struct archive_entry *, int fd); -static void write_hierarchy(struct bsdtar *, struct archive *, - const char *); - -#if defined(_WIN32) && !defined(__CYGWIN__) -/* Not a full lseek() emulation, but enough for our needs here. */ -static int -seek_file(int fd, int64_t offset, int whence) -{ - LARGE_INTEGER distance; - (void)whence; /* UNUSED */ - distance.QuadPart = offset; - return (SetFilePointerEx((HANDLE)_get_osfhandle(fd), - distance, NULL, FILE_BEGIN) ? 1 : -1); -} -#define open _open -#define close _close -#define read _read -#define lseek seek_file -#endif - -void -tar_mode_c(struct bsdtar *bsdtar) -{ - struct archive *a; - int r; - - if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) - lafe_errc(1, 0, "no files or directories specified"); - - a = archive_write_new(); - - /* Support any format that the library supports. */ - if (bsdtar->create_format == NULL) { - r = archive_write_set_format_pax_restricted(a); - bsdtar->create_format = "pax restricted"; - } else { - r = archive_write_set_format_by_name(a, bsdtar->create_format); - } - if (r != ARCHIVE_OK) { - fprintf(stderr, "Can't use format %s: %s\n", - bsdtar->create_format, - archive_error_string(a)); - usage(); - } - - /* - * If user explicitly set the block size, then assume they - * want the last block padded as well. Otherwise, use the - * default block size and accept archive_write_open_file()'s - * default padding decisions. - */ - if (bsdtar->bytes_per_block != 0) { - archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); - archive_write_set_bytes_in_last_block(a, - bsdtar->bytes_per_block); - } else - archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); - - if (bsdtar->compress_program) { - archive_write_set_compression_program(a, bsdtar->compress_program); - } else { - switch (bsdtar->create_compression) { - case 0: - r = archive_write_set_compression_none(a); - break; - case 'j': case 'y': - r = archive_write_set_compression_bzip2(a); - break; - case 'J': - r = archive_write_set_compression_xz(a); - break; - case OPTION_LZMA: - archive_write_set_compression_lzma(a); - break; - case 'z': - r = archive_write_set_compression_gzip(a); - break; - case 'Z': - r = archive_write_set_compression_compress(a); - break; - default: - lafe_errc(1, 0, - "Unrecognized compression option -%c", - bsdtar->create_compression); - } - if (r != ARCHIVE_OK) { - lafe_errc(1, 0, - "Unsupported compression option -%c", - bsdtar->create_compression); - } - } - - if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - lafe_errc(1, 0, archive_error_string(a)); - if (ARCHIVE_OK != archive_write_open_file(a, bsdtar->filename)) - lafe_errc(1, 0, archive_error_string(a)); - write_archive(a, bsdtar); -} - -/* - * Same as 'c', except we only support tar or empty formats in - * uncompressed files on disk. - */ -void -tar_mode_r(struct bsdtar *bsdtar) -{ - int64_t end_offset; - int format; - struct archive *a; - struct archive_entry *entry; - int r; - - /* Sanity-test some arguments and the file. */ - test_for_append(bsdtar); - - format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; - - bsdtar->fd = open(bsdtar->filename, O_RDWR | O_CREAT, 0666); - if (bsdtar->fd < 0) - lafe_errc(1, errno, - "Cannot open %s", bsdtar->filename); - - a = archive_read_new(); - archive_read_support_compression_all(a); - archive_read_support_format_tar(a); - archive_read_support_format_gnutar(a); - r = archive_read_open_fd(a, bsdtar->fd, 10240); - if (r != ARCHIVE_OK) - lafe_errc(1, archive_errno(a), - "Can't read archive %s: %s", bsdtar->filename, - archive_error_string(a)); - while (0 == archive_read_next_header(a, &entry)) { - if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) { - archive_read_finish(a); - close(bsdtar->fd); - lafe_errc(1, 0, - "Cannot append to compressed archive."); - } - /* Keep going until we hit end-of-archive */ - format = archive_format(a); - } - - end_offset = archive_read_header_position(a); - archive_read_finish(a); - - /* Re-open archive for writing */ - a = archive_write_new(); - archive_write_set_compression_none(a); - /* - * Set the format to be used for writing. To allow people to - * extend empty files, we need to allow them to specify the format, - * which opens the possibility that they will specify a format that - * doesn't match the existing format. Hence, the following bit - * of arcane ugliness. - */ - - if (bsdtar->create_format != NULL) { - /* If the user requested a format, use that, but ... */ - archive_write_set_format_by_name(a, - bsdtar->create_format); - /* ... complain if it's not compatible. */ - format &= ARCHIVE_FORMAT_BASE_MASK; - if (format != (int)(archive_format(a) & ARCHIVE_FORMAT_BASE_MASK) - && format != ARCHIVE_FORMAT_EMPTY) { - lafe_errc(1, 0, - "Format %s is incompatible with the archive %s.", - bsdtar->create_format, bsdtar->filename); - } - } else { - /* - * Just preserve the current format, with a little care - * for formats that libarchive can't write. - */ - if (format == ARCHIVE_FORMAT_TAR_GNUTAR) - /* TODO: When gtar supports pax, use pax restricted. */ - format = ARCHIVE_FORMAT_TAR_USTAR; - if (format == ARCHIVE_FORMAT_EMPTY) - format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; - archive_write_set_format(a, format); - } - if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) - lafe_errc(1, errno, "Could not seek to archive end"); - if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - lafe_errc(1, 0, archive_error_string(a)); - if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) - lafe_errc(1, 0, archive_error_string(a)); - - write_archive(a, bsdtar); /* XXX check return val XXX */ - - close(bsdtar->fd); - bsdtar->fd = -1; -} - -void -tar_mode_u(struct bsdtar *bsdtar) -{ - int64_t end_offset; - struct archive *a; - struct archive_entry *entry; - int format; - struct archive_dir_entry *p; - struct archive_dir archive_dir; - - bsdtar->archive_dir = &archive_dir; - memset(&archive_dir, 0, sizeof(archive_dir)); - - format = ARCHIVE_FORMAT_TAR_PAX_RESTRICTED; - - /* Sanity-test some arguments and the file. */ - test_for_append(bsdtar); - - bsdtar->fd = open(bsdtar->filename, O_RDWR); - if (bsdtar->fd < 0) - lafe_errc(1, errno, - "Cannot open %s", bsdtar->filename); - - a = archive_read_new(); - archive_read_support_compression_all(a); - archive_read_support_format_tar(a); - archive_read_support_format_gnutar(a); - if (archive_read_open_fd(a, bsdtar->fd, - bsdtar->bytes_per_block != 0 ? bsdtar->bytes_per_block : - DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { - lafe_errc(1, 0, - "Can't open %s: %s", bsdtar->filename, - archive_error_string(a)); - } - - /* Build a list of all entries and their recorded mod times. */ - while (0 == archive_read_next_header(a, &entry)) { - if (archive_compression(a) != ARCHIVE_COMPRESSION_NONE) { - archive_read_finish(a); - close(bsdtar->fd); - lafe_errc(1, 0, - "Cannot append to compressed archive."); - } - add_dir_list(bsdtar, archive_entry_pathname(entry), - archive_entry_mtime(entry), - archive_entry_mtime_nsec(entry)); - /* Record the last format determination we see */ - format = archive_format(a); - /* Keep going until we hit end-of-archive */ - } - - end_offset = archive_read_header_position(a); - archive_read_finish(a); - - /* Re-open archive for writing. */ - a = archive_write_new(); - archive_write_set_compression_none(a); - /* - * Set format to same one auto-detected above, except that - * we don't write GNU tar format, so use ustar instead. - */ - if (format == ARCHIVE_FORMAT_TAR_GNUTAR) - format = ARCHIVE_FORMAT_TAR_USTAR; - archive_write_set_format(a, format); - if (bsdtar->bytes_per_block != 0) { - archive_write_set_bytes_per_block(a, bsdtar->bytes_per_block); - archive_write_set_bytes_in_last_block(a, - bsdtar->bytes_per_block); - } else - archive_write_set_bytes_per_block(a, DEFAULT_BYTES_PER_BLOCK); - if (lseek(bsdtar->fd, end_offset, SEEK_SET) < 0) - lafe_errc(1, errno, "Could not seek to archive end"); - if (ARCHIVE_OK != archive_write_set_options(a, bsdtar->option_options)) - lafe_errc(1, 0, archive_error_string(a)); - if (ARCHIVE_OK != archive_write_open_fd(a, bsdtar->fd)) - lafe_errc(1, 0, archive_error_string(a)); - - write_archive(a, bsdtar); - - close(bsdtar->fd); - bsdtar->fd = -1; - - while (bsdtar->archive_dir->head != NULL) { - p = bsdtar->archive_dir->head->next; - free(bsdtar->archive_dir->head->name); - free(bsdtar->archive_dir->head); - bsdtar->archive_dir->head = p; - } - bsdtar->archive_dir->tail = NULL; -} - - -/* - * Write user-specified files/dirs to opened archive. - */ -static void -write_archive(struct archive *a, struct bsdtar *bsdtar) -{ - const char *arg; - struct archive_entry *entry, *sparse_entry; - - /* Allocate a buffer for file data. */ - if ((bsdtar->buff = malloc(FILEDATABUFLEN)) == NULL) - lafe_errc(1, 0, "cannot allocate memory"); - - if ((bsdtar->resolver = archive_entry_linkresolver_new()) == NULL) - lafe_errc(1, 0, "cannot create link resolver"); - archive_entry_linkresolver_set_strategy(bsdtar->resolver, - archive_format(a)); - if ((bsdtar->diskreader = archive_read_disk_new()) == NULL) - lafe_errc(1, 0, "Cannot create read_disk object"); - archive_read_disk_set_standard_lookup(bsdtar->diskreader); - - if (bsdtar->names_from_file != NULL) - archive_names_from_file(bsdtar, a); - - while (*bsdtar->argv) { - arg = *bsdtar->argv; - if (arg[0] == '-' && arg[1] == 'C') { - arg += 2; - if (*arg == '\0') { - bsdtar->argv++; - arg = *bsdtar->argv; - if (arg == NULL) { - lafe_warnc(1, 0, - "Missing argument for -C"); - bsdtar->return_value = 1; - goto cleanup; - } - } - set_chdir(bsdtar, arg); - } else { - if (*arg != '/' && (arg[0] != '@' || arg[1] != '/')) - do_chdir(bsdtar); /* Handle a deferred -C */ - if (*arg == '@') { - if (append_archive_filename(bsdtar, a, - arg + 1) != 0) - break; - } else - write_hierarchy(bsdtar, a, arg); - } - bsdtar->argv++; - } - - entry = NULL; - archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); - while (entry != NULL) { - write_entry_backend(bsdtar, a, entry); - archive_entry_free(entry); - entry = NULL; - archive_entry_linkify(bsdtar->resolver, &entry, &sparse_entry); - } - - if (archive_write_close(a)) { - lafe_warnc(0, "%s", archive_error_string(a)); - bsdtar->return_value = 1; - } - -cleanup: - /* Free file data buffer. */ - free(bsdtar->buff); - archive_entry_linkresolver_free(bsdtar->resolver); - bsdtar->resolver = NULL; - archive_read_finish(bsdtar->diskreader); - bsdtar->diskreader = NULL; - - if (bsdtar->option_totals) { - fprintf(stderr, "Total bytes written: " BSDTAR_FILESIZE_PRINTF "\n", - (BSDTAR_FILESIZE_TYPE)archive_position_compressed(a)); - } - - archive_write_finish(a); -} - -/* - * Archive names specified in file. - * - * Unless --null was specified, a line containing exactly "-C" will - * cause the next line to be a directory to pass to chdir(). If - * --null is specified, then a line "-C" is just another filename. - */ -void -archive_names_from_file(struct bsdtar *bsdtar, struct archive *a) -{ - struct lafe_line_reader *lr; - const char *line; - - bsdtar->next_line_is_dir = 0; - - lr = lafe_line_reader(bsdtar->names_from_file, bsdtar->option_null); - while ((line = lafe_line_reader_next(lr)) != NULL) { - if (bsdtar->next_line_is_dir) { - set_chdir(bsdtar, line); - bsdtar->next_line_is_dir = 0; - } else if (!bsdtar->option_null && strcmp(line, "-C") == 0) - bsdtar->next_line_is_dir = 1; - else { - if (*line != '/') - do_chdir(bsdtar); /* Handle a deferred -C */ - write_hierarchy(bsdtar, a, line); - } - } - lafe_line_reader_free(lr); - if (bsdtar->next_line_is_dir) - lafe_errc(1, errno, - "Unexpected end of filename list; " - "directory expected after -C"); -} - -/* - * Copy from specified archive to current archive. Returns non-zero - * for write errors (which force us to terminate the entire archiving - * operation). If there are errors reading the input archive, we set - * bsdtar->return_value but return zero, so the overall archiving - * operation will complete and return non-zero. - */ -static int -append_archive_filename(struct bsdtar *bsdtar, struct archive *a, - const char *filename) -{ - struct archive *ina; - int rc; - - if (strcmp(filename, "-") == 0) - filename = NULL; /* Library uses NULL for stdio. */ - - ina = archive_read_new(); - archive_read_support_format_all(ina); - archive_read_support_compression_all(ina); - if (archive_read_open_file(ina, filename, 10240)) { - lafe_warnc(0, "%s", archive_error_string(ina)); - bsdtar->return_value = 1; - return (0); - } - - rc = append_archive(bsdtar, a, ina); - - if (archive_errno(ina)) { - lafe_warnc(0, "Error reading archive %s: %s", - filename, archive_error_string(ina)); - bsdtar->return_value = 1; - } - archive_read_finish(ina); - - return (rc); -} - -static int -append_archive(struct bsdtar *bsdtar, struct archive *a, struct archive *ina) -{ - struct archive_entry *in_entry; - int e; - - while (0 == archive_read_next_header(ina, &in_entry)) { - if (!new_enough(bsdtar, archive_entry_pathname(in_entry), - archive_entry_stat(in_entry))) - continue; - if (lafe_excluded(bsdtar->matching, archive_entry_pathname(in_entry))) - continue; - if (bsdtar->option_interactive && - !yes("copy '%s'", archive_entry_pathname(in_entry))) - continue; - if (bsdtar->verbose) - safe_fprintf(stderr, "a %s", - archive_entry_pathname(in_entry)); - if (need_report()) - report_write(bsdtar, a, in_entry, 0); - - e = archive_write_header(a, in_entry); - if (e != ARCHIVE_OK) { - if (!bsdtar->verbose) - lafe_warnc(0, "%s: %s", - archive_entry_pathname(in_entry), - archive_error_string(a)); - else - fprintf(stderr, ": %s", archive_error_string(a)); - } - if (e == ARCHIVE_FATAL) - exit(1); - - if (e >= ARCHIVE_WARN) { - if (archive_entry_size(in_entry) == 0) - archive_read_data_skip(ina); - else if (copy_file_data(bsdtar, a, ina, in_entry)) - exit(1); - } - - if (bsdtar->verbose) - fprintf(stderr, "\n"); - } - - /* Note: If we got here, we saw no write errors, so return success. */ - return (0); -} - -/* Helper function to copy data between archives. */ -static int -copy_file_data(struct bsdtar *bsdtar, struct archive *a, - struct archive *ina, struct archive_entry *entry) -{ - ssize_t bytes_read; - ssize_t bytes_written; - int64_t progress = 0; - - bytes_read = archive_read_data(ina, bsdtar->buff, FILEDATABUFLEN); - while (bytes_read > 0) { - if (need_report()) - report_write(bsdtar, a, entry, progress); - - bytes_written = archive_write_data(a, bsdtar->buff, - bytes_read); - if (bytes_written < bytes_read) { - lafe_warnc(0, "%s", archive_error_string(a)); - return (-1); - } - progress += bytes_written; - bytes_read = archive_read_data(ina, bsdtar->buff, - FILEDATABUFLEN); - } - - return (0); -} - -/* - * Add the file or dir hierarchy named by 'path' to the archive - */ -static void -write_hierarchy(struct bsdtar *bsdtar, struct archive *a, const char *path) -{ - struct archive_entry *entry = NULL, *spare_entry = NULL; - struct tree *tree; - char symlink_mode = bsdtar->symlink_mode; - dev_t first_dev = 0; - int dev_recorded = 0; - int tree_ret; - - tree = tree_open(path); - - if (!tree) { - lafe_warnc(errno, "%s: Cannot open", path); - bsdtar->return_value = 1; - return; - } - - while ((tree_ret = tree_next(tree))) { - int r; - const char *name = tree_current_path(tree); - const struct stat *st = NULL; /* info to use for this entry */ - const struct stat *lst = NULL; /* lstat() information */ - int descend; - - if (tree_ret == TREE_ERROR_FATAL) - lafe_errc(1, tree_errno(tree), - "%s: Unable to continue traversing directory tree", - name); - if (tree_ret == TREE_ERROR_DIR) { - lafe_warnc(errno, - "%s: Couldn't visit directory", name); - bsdtar->return_value = 1; - } - if (tree_ret != TREE_REGULAR) - continue; - - /* - * If this file/dir is excluded by a filename - * pattern, skip it. - */ - if (lafe_excluded(bsdtar->matching, name)) - continue; - - /* - * Get lstat() info from the tree library. - */ - lst = tree_current_lstat(tree); - if (lst == NULL) { - /* Couldn't lstat(); must not exist. */ - lafe_warnc(errno, "%s: Cannot stat", name); - /* Return error if files disappear during traverse. */ - bsdtar->return_value = 1; - continue; - } - - /* - * Distinguish 'L'/'P'/'H' symlink following. - */ - switch(symlink_mode) { - case 'H': - /* 'H': After the first item, rest like 'P'. */ - symlink_mode = 'P'; - /* 'H': First item (from command line) like 'L'. */ - /* FALLTHROUGH */ - case 'L': - /* 'L': Do descend through a symlink to dir. */ - descend = tree_current_is_dir(tree); - /* 'L': Follow symlinks to files. */ - archive_read_disk_set_symlink_logical(bsdtar->diskreader); - /* 'L': Archive symlinks as targets, if we can. */ - st = tree_current_stat(tree); - if (st != NULL) - break; - /* If stat fails, we have a broken symlink; - * in that case, don't follow the link. */ - /* FALLTHROUGH */ - default: - /* 'P': Don't descend through a symlink to dir. */ - descend = tree_current_is_physical_dir(tree); - /* 'P': Don't follow symlinks to files. */ - archive_read_disk_set_symlink_physical(bsdtar->diskreader); - /* 'P': Archive symlinks as symlinks. */ - st = lst; - break; - } - - /* - * Are we about to cross to a new filesystem? - */ - if (!dev_recorded) { - /* This is the initial file system. */ - first_dev = lst->st_dev; - dev_recorded = 1; - } else if (lst->st_dev == first_dev) { - /* The starting file system is always acceptable. */ - } else if (descend == 0) { - /* We're not descending, so no need to check. */ - } else if (bsdtar->option_dont_traverse_mounts) { - /* User has asked us not to cross mount points. */ - descend = 0; - } else { - /* We're prepared to cross a mount point. */ - - /* XXX TODO: check whether this filesystem is - * synthetic and/or local. Add a new - * --local-only option to skip non-local - * filesystems. Skip synthetic filesystems - * regardless. - * - * The results should be cached, since - * tree.c doesn't usually visit a directory - * and the directory contents together. A simple - * move-to-front list should perform quite well. - * - * This is going to be heavily OS dependent: - * FreeBSD's statfs() in conjunction with getvfsbyname() - * provides all of this; NetBSD's statvfs() does - * most of it; other systems will vary. - */ - } - - /* - * In -u mode, check that the file is newer than what's - * already in the archive; in all modes, obey --newerXXX flags. - */ - if (!new_enough(bsdtar, name, st)) - continue; - - archive_entry_free(entry); - entry = archive_entry_new(); - - archive_entry_set_pathname(entry, name); - archive_entry_copy_sourcepath(entry, - tree_current_access_path(tree)); - - /* Populate the archive_entry with metadata from the disk. */ - /* XXX TODO: Arrange to open a regular file before - * calling this so we can pass in an fd and shorten - * the race to query metadata. The linkify dance - * makes this more complex than it might sound. */ -#if defined(_WIN32) && !defined(__CYGWIN__) - /* TODO: tree.c uses stat(), which is badly broken - * on Windows. To fix this, we should - * deprecate tree_current_stat() and provide a new - * call tree_populate_entry(t, entry). This call - * would use stat() internally on POSIX and - * GetInfoByFileHandle() internally on Windows. - * This would be another step towards a tree-walker - * that can be integrated deep into libarchive. - * For now, just set st to NULL on Windows; - * archive_read_disk_entry_from_file() should - * be smart enough to use platform-appropriate - * ways to probe file information. - */ - st = NULL; -#endif - r = archive_read_disk_entry_from_file(bsdtar->diskreader, - entry, -1, st); - if (r != ARCHIVE_OK) - lafe_warnc(archive_errno(bsdtar->diskreader), - archive_error_string(bsdtar->diskreader)); - if (r < ARCHIVE_WARN) - continue; - - /* XXX TODO: Just use flag data from entry; avoid the - * duplicate check here. */ - - /* - * If this file/dir is flagged "nodump" and we're - * honoring such flags, skip this file/dir. - */ -#ifdef HAVE_STRUCT_STAT_ST_FLAGS - /* BSD systems store flags in struct stat */ - if (bsdtar->option_honor_nodump && - (lst->st_flags & UF_NODUMP)) - continue; -#endif - -#if defined(EXT2_IOC_GETFLAGS) && defined(EXT2_NODUMP_FL) - /* Linux uses ioctl to read flags. */ - if (bsdtar->option_honor_nodump) { - int fd = open(name, O_RDONLY | O_NONBLOCK); - if (fd >= 0) { - unsigned long fflags; - int r = ioctl(fd, EXT2_IOC_GETFLAGS, &fflags); - close(fd); - if (r >= 0 && (fflags & EXT2_NODUMP_FL)) - continue; - } - } -#endif - - /* - * If the user vetoes this file/directory, skip it. - * We want this to be fairly late; if some other - * check would veto this file, we shouldn't bother - * the user with it. - */ - if (bsdtar->option_interactive && - !yes("add '%s'", name)) - continue; - - /* Note: if user vetoes, we won't descend. */ - if (descend && !bsdtar->option_no_subdirs) - tree_descend(tree); - - /* - * Rewrite the pathname to be archived. If rewrite - * fails, skip the entry. - */ - if (edit_pathname(bsdtar, entry)) - continue; - - /* Display entry as we process it. - * This format is required by SUSv2. */ - if (bsdtar->verbose) - safe_fprintf(stderr, "a %s", - archive_entry_pathname(entry)); - - /* Non-regular files get archived with zero size. */ - if (archive_entry_filetype(entry) != AE_IFREG) - archive_entry_set_size(entry, 0); - - archive_entry_linkify(bsdtar->resolver, &entry, &spare_entry); - - while (entry != NULL) { - write_entry_backend(bsdtar, a, entry); - archive_entry_free(entry); - entry = spare_entry; - spare_entry = NULL; - } - - if (bsdtar->verbose) - fprintf(stderr, "\n"); - } - archive_entry_free(entry); - tree_close(tree); -} - -/* - * Backend for write_entry. - */ -static void -write_entry_backend(struct bsdtar *bsdtar, struct archive *a, - struct archive_entry *entry) -{ - int fd = -1; - int e; - - if (archive_entry_size(entry) > 0) { - const char *pathname = archive_entry_sourcepath(entry); - fd = open(pathname, O_RDONLY); - if (fd == -1) { - if (!bsdtar->verbose) - lafe_warnc(errno, - "%s: could not open file", pathname); - else - fprintf(stderr, ": %s", strerror(errno)); - return; - } - } - - e = archive_write_header(a, entry); - if (e != ARCHIVE_OK) { - if (!bsdtar->verbose) - lafe_warnc(0, "%s: %s", - archive_entry_pathname(entry), - archive_error_string(a)); - else - fprintf(stderr, ": %s", archive_error_string(a)); - } - - if (e == ARCHIVE_FATAL) - exit(1); - - /* - * If we opened a file earlier, write it out now. Note that - * the format handler might have reset the size field to zero - * to inform us that the archive body won't get stored. In - * that case, just skip the write. - */ - if (e >= ARCHIVE_WARN && fd >= 0 && archive_entry_size(entry) > 0) { - if (write_file_data(bsdtar, a, entry, fd)) - exit(1); - } - - /* - * If we opened a file, close it now even if there was an error - * which made us decide not to write the archive body. - */ - if (fd >= 0) - close(fd); -} - -static void -report_write(struct bsdtar *bsdtar, struct archive *a, - struct archive_entry *entry, int64_t progress) -{ - uintmax_t comp, uncomp; - if (bsdtar->verbose) - fprintf(stderr, "\n"); - comp = archive_position_compressed(a); - uncomp = archive_position_uncompressed(a); - fprintf(stderr, "In: %d files, %ju bytes;", - archive_file_count(a), uncomp); - fprintf(stderr, - " Out: %ju bytes, compression %d%%\n", - comp, (int)((uncomp - comp) * 100 / uncomp)); - safe_fprintf(stderr, "Current: %s (%ju/%ju bytes)", - archive_entry_pathname(entry), - (uintmax_t)progress, - (uintmax_t)archive_entry_size(entry)); - fprintf(stderr, "\n"); -} - - -/* Helper function to copy file to archive. */ -static int -write_file_data(struct bsdtar *bsdtar, struct archive *a, - struct archive_entry *entry, int fd) -{ - ssize_t bytes_read; - ssize_t bytes_written; - int64_t progress = 0; - - bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN); - while (bytes_read > 0) { - if (need_report()) - report_write(bsdtar, a, entry, progress); - - bytes_written = archive_write_data(a, bsdtar->buff, - bytes_read); - if (bytes_written < 0) { - /* Write failed; this is bad */ - lafe_warnc(0, "%s", archive_error_string(a)); - return (-1); - } - if (bytes_written < bytes_read) { - /* Write was truncated; warn but continue. */ - lafe_warnc(0, - "%s: Truncated write; file may have grown while being archived.", - archive_entry_pathname(entry)); - return (0); - } - progress += bytes_written; - bytes_read = read(fd, bsdtar->buff, FILEDATABUFLEN); - } - return 0; -} - -/* - * Test if the specified file is new enough to include in the archive. - */ -int -new_enough(struct bsdtar *bsdtar, const char *path, const struct stat *st) -{ - struct archive_dir_entry *p; - - /* - * If this file/dir is excluded by a time comparison, skip it. - */ - if (bsdtar->newer_ctime_sec > 0) { - if (st->st_ctime < bsdtar->newer_ctime_sec) - return (0); /* Too old, skip it. */ - if (st->st_ctime == bsdtar->newer_ctime_sec - && ARCHIVE_STAT_CTIME_NANOS(st) - <= bsdtar->newer_ctime_nsec) - return (0); /* Too old, skip it. */ - } - if (bsdtar->newer_mtime_sec > 0) { - if (st->st_mtime < bsdtar->newer_mtime_sec) - return (0); /* Too old, skip it. */ - if (st->st_mtime == bsdtar->newer_mtime_sec - && ARCHIVE_STAT_MTIME_NANOS(st) - <= bsdtar->newer_mtime_nsec) - return (0); /* Too old, skip it. */ - } - - /* - * In -u mode, we only write an entry if it's newer than - * what was already in the archive. - */ - if (bsdtar->archive_dir != NULL && - bsdtar->archive_dir->head != NULL) { - for (p = bsdtar->archive_dir->head; p != NULL; p = p->next) { - if (pathcmp(path, p->name)==0) - return (p->mtime_sec < st->st_mtime || - (p->mtime_sec == st->st_mtime && - p->mtime_nsec - < ARCHIVE_STAT_MTIME_NANOS(st))); - } - } - - /* If the file wasn't rejected, include it. */ - return (1); -} - -/* - * Add an entry to the dir list for 'u' mode. - * - * XXX TODO: Make this fast. - */ -static void -add_dir_list(struct bsdtar *bsdtar, const char *path, - time_t mtime_sec, int mtime_nsec) -{ - struct archive_dir_entry *p; - - /* - * Search entire list to see if this file has appeared before. - * If it has, override the timestamp data. - */ - p = bsdtar->archive_dir->head; - while (p != NULL) { - if (strcmp(path, p->name)==0) { - p->mtime_sec = mtime_sec; - p->mtime_nsec = mtime_nsec; - return; - } - p = p->next; - } - - p = malloc(sizeof(*p)); - if (p == NULL) - lafe_errc(1, ENOMEM, "Can't read archive directory"); - - p->name = strdup(path); - if (p->name == NULL) - lafe_errc(1, ENOMEM, "Can't read archive directory"); - p->mtime_sec = mtime_sec; - p->mtime_nsec = mtime_nsec; - p->next = NULL; - if (bsdtar->archive_dir->tail == NULL) { - bsdtar->archive_dir->head = bsdtar->archive_dir->tail = p; - } else { - bsdtar->archive_dir->tail->next = p; - bsdtar->archive_dir->tail = p; - } -} - -void -test_for_append(struct bsdtar *bsdtar) -{ - struct stat s; - - if (*bsdtar->argv == NULL && bsdtar->names_from_file == NULL) - lafe_errc(1, 0, "no files or directories specified"); - if (bsdtar->filename == NULL) - lafe_errc(1, 0, "Cannot append to stdout."); - - if (bsdtar->create_compression != 0) - lafe_errc(1, 0, - "Cannot append to %s with compression", bsdtar->filename); - - if (stat(bsdtar->filename, &s) != 0) - return; - - if (!S_ISREG(s.st_mode) && !S_ISBLK(s.st_mode)) - lafe_errc(1, 0, - "Cannot append to %s: not a regular file.", - bsdtar->filename); - -/* Is this an appropriate check here on Windows? */ -/* - if (GetFileType(handle) != FILE_TYPE_DISK) - lafe_errc(1, 0, "Cannot append"); -*/ - -} diff --git a/bootstrap b/bootstrap index 3daac2a37..3be3d1f68 100755 --- a/bootstrap +++ b/bootstrap @@ -1,7 +1,7 @@ #!/bin/sh #============================================================================= # CMake - Cross Platform Makefile Generator -# Copyright 2000-2009 Kitware, Inc., Insight Software Consortium +# Copyright 2000-2011 Kitware, Inc., Insight Software Consortium # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -11,6 +11,10 @@ # See the License for more information. #============================================================================= +die() { + echo "$@" 1>&2 ; exit 1 +} + # Version number extraction function. cmake_version_component() { @@ -123,10 +127,20 @@ fi cmake_bootstrap_dir="${cmake_binary_dir}/Bootstrap${_cmk}" # Helper function to fix windows paths. -cmake_fix_slashes () -{ - echo "$1" | sed 's/\\/\//g' -} +case "${cmake_system}" in +*MINGW*) + cmake_fix_slashes() + { + cmd //c echo "$(echo "$1" | sed 's/\\/\//g')" | sed 's/^"//;s/" *$//' + } + ;; +*) + cmake_fix_slashes() + { + echo "$1" | sed 's/\\/\//g' + } + ;; +esac # Choose the default install prefix. if ${cmake_system_mingw}; then @@ -194,6 +208,7 @@ CMAKE_CXX_SOURCES="\ cmExportInstallFileGenerator \ cmInstallDirectoryGenerator \ cmGeneratedFileStream \ + cmGeneratorTarget \ cmGeneratorExpression \ cmGlobalGenerator \ cmLocalGenerator \ @@ -292,7 +307,7 @@ KWSYS_IOS_FILES=" cmake_usage() { echo ' -Usage: '"$0"' [options] +Usage: '"$0"' [...] [-- ...] Options: [defaults in brackets after descriptions] Configuration: --help print this message @@ -337,7 +352,7 @@ Directory and file names: # Display CMake bootstrap usage cmake_version_display() { - echo "CMake ${cmake_version}, Copyright 2000-2009 Kitware, Inc." + echo "CMake ${cmake_version}, Copyright 2000-2011 Kitware, Inc." } # Display CMake bootstrap error, display the log file and exit @@ -527,63 +542,31 @@ cmake_verbose= cmake_parallel_make= cmake_ccache_enabled= cmake_prefix_dir="${cmake_default_prefix}" -for a in "$@"; do - if echo $a | grep "^--prefix=" > /dev/null 2> /dev/null; then - cmake_prefix_dir=`echo $a | sed "s/^--prefix=//"` - cmake_prefix_dir=`cmake_fix_slashes "${cmake_prefix_dir}"` - fi - if echo $a | grep "^--parallel=" > /dev/null 2> /dev/null; then - cmake_parallel_make=`echo $a | sed "s/^--parallel=//" | grep "[0-9][0-9]*"` - fi - if echo $a | grep "^--datadir=" > /dev/null 2> /dev/null; then - cmake_data_dir=`echo $a | sed "s/^--datadir=//"` - fi - if echo $a | grep "^--docdir=" > /dev/null 2> /dev/null; then - cmake_doc_dir=`echo $a | sed "s/^--docdir=//"` - fi - if echo $a | grep "^--mandir=" > /dev/null 2> /dev/null; then - cmake_man_dir=`echo $a | sed "s/^--mandir=//"` - fi - if echo $a | grep "^--init=" > /dev/null 2> /dev/null; then - cmake_init_file=`echo $a | sed "s/^--init=//"` - fi - for lib in bzip2 curl expat libarchive zlib; do - if echo $a | grep "^--system-${lib}" > /dev/null 2> /dev/null; then - cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper ${lib}`=1" - break - elif echo $a | grep "^--no-system-${lib}" > /dev/null 2> /dev/null; then - cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper ${lib}`=0" - break - fi - done - if echo $a | grep "^--system-libs" > /dev/null 2> /dev/null; then - cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" - fi - if echo $a | grep "^--no-system-libs" > /dev/null 2> /dev/null; then - cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" - fi - if echo $a | grep "^--qt-gui" > /dev/null 2> /dev/null; then - cmake_bootstrap_qt_gui="1" - fi - if echo $a | grep "^--no-qt-gui" > /dev/null 2> /dev/null; then - cmake_bootstrap_qt_gui="0" - fi - if echo $a | grep "^--qt-qmake=" > /dev/null 2> /dev/null; then - cmake_bootstrap_qt_qmake=`echo $a | sed "s/^--qt-qmake=//"` - fi - if echo $a | grep "^--help" > /dev/null 2> /dev/null; then - cmake_usage - fi - if echo $a | grep "^--version" > /dev/null 2> /dev/null; then - cmake_version_display - exit 2 - fi - if echo $a | grep "^--verbose" > /dev/null 2> /dev/null; then - cmake_verbose=TRUE - fi - if echo $a | grep "^--enable-ccache" > /dev/null 2> /dev/null; then - cmake_ccache_enabled=TRUE - fi +while test $# != 0; do + case "$1" in + --prefix=*) cmake_prefix_dir=`cmake_fix_slashes "${1#*=}"` ;; + --parallel=*) cmake_parallel_make="${1#*=}" ;; + --datadir=*) cmake_data_dir="${1#*=}" ;; + --docdir=*) cmake_doc_dir="${1#*=}" ;; + --mandir=*) cmake_man_dir="${1#*=}" ;; + --init=*) cmake_init_file="${1#*=}" ;; + --system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=1" ;; + --no-system-libs) cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARIES=0" ;; + --system-bzip2|--system-curl|--system-expat|--system-libarchive|--system-zlib) + cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper ${1#--system-}`=1" ;; + --no-system-bzip2|--no-system-curl|--no-system-expat|--no-system-libarchive|--no-system-zlib) + cmake_bootstrap_system_libs="${cmake_bootstrap_system_libs} -DCMAKE_USE_SYSTEM_LIBRARY_`cmake_toupper ${1#--no-system-}`=0" ;; + --qt-gui) cmake_bootstrap_qt_gui="1" ;; + --no-qt-gui) cmake_bootstrap_qt_gui="0" ;; + --qt-qmake=*) cmake_bootstrap_qt_qmake="${1#*=}" ;; + --help) cmake_usage ;; + --version) cmake_version_display ; exit 2 ;; + --verbose) cmake_verbose=TRUE ;; + --enable-ccache) cmake_ccache_enabled=TRUE ;; + --) shift; break ;; + *) die "Unknown option: $1" ;; + esac + shift done # If verbose, display some information about bootstrap @@ -1533,7 +1516,7 @@ cmake_options="-DCMAKE_BOOTSTRAP=1" if [ -n "${cmake_verbose}" ]; then cmake_options="${cmake_options} -DCMAKE_VERBOSE_MAKEFILE=1" fi -"${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake" "-G${cmake_bootstrap_generator}" ${cmake_options} ${cmake_bootstrap_system_libs} +"${cmake_bootstrap_dir}/cmake" "${cmake_source_dir}" "-C${cmake_bootstrap_dir}/InitialCacheFlags.cmake" "-G${cmake_bootstrap_generator}" ${cmake_options} ${cmake_bootstrap_system_libs} "$@" RES=$? if [ "${RES}" -ne "0" ]; then cmake_error 11 "Problem while running initial CMake" diff --git a/cmake.1 b/cmake.1 deleted file mode 100644 index c7695b498..000000000 --- a/cmake.1 +++ /dev/null @@ -1,112 +0,0 @@ -.\" Hey, EMACS: -*- nroff -*- -.\" First parameter, NAME, should be all caps -.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection -.\" other parameters are allowed: see man(7), man(1) -.TH CMAKE 1 "August 8, 2002" -.\" Please adjust this date whenever revising the manpage. -.\" -.\" Some roff macros, for reference: -.\" .nh disable hyphenation -.\" .hy enable hyphenation -.\" .ad l left justify -.\" .ad b justify to both left and right margins -.\" .nf disable filling -.\" .fi enable filling -.\" .br insert line break -.\" .sp insert n+1 empty lines -.\" for manpage-specific macros, see man(7) -.SH NAME -cmake \- Cross-platform Makefile generator. -.SH SYNOPSIS -.B cmake -.RI < path-to-source > " " [ options ] -.br -.B ccmake -.RI < path-to-source > -.br -.B ctest -.RI [ -R " " < regex > ] -.br -.B cmaketest -.RI < test-src-dir > " " < test-bin-dir > " " < test-executable > -.SH DESCRIPTION - -This manual page documents briefly the \fBcmake\fP, \fBccmake\fP, -\fBctest\fP and \fBcmaketest\fP commands. It is not intended to aid -authors of CMakeLists.txt files or to describe all advanced options -available. For full documentation, please visit -\fBhttp://www.cmake.org\fP. - -.PP -.\" TeX users may be more comfortable with the \fB\fP and -.\" \fI\fP escape sequences to invode bold face and italics, -.\" respectively. - -CMake provides developers with a means of building their project on -multiple platforms while writing only one build system configuration. -The developer writes a set of CMakeLists.txt files that are read by -CMake and used to generate a native build system for the current -environment. On unix platforms, Makefiles are generated. - -.PP - -\fBcmake\fP is used to generate the makefiles for a project from its -source. The first argument should specify a path to the source tree. -The current directory will be used as the build tree for the project. -Both in-source and out-of-source builds are supported, but -out-of-source builds are preferred. CMake provides functionality for -tailoring the build to user preferences through settings in the cmake -cache. Options may be set interactively using the -i option (or -\fBccmake\fP). Once CMake has generated the makefiles in the build -tree, one may use the standard \fBmake\fP tool to build the project. - -.PP - -\fBccmake\fP provides a curses interface front-end for \fBcmake\fP. -The interface allows users to interactively configure the build -options stored in the cmake cache. This is the preferred interface -for interactive builds. Build scripts should use \fBcmake\fP -directly. - -.PP - -\fBctest\fP runs tests found in the project's build tree after it has -been compiled and displays a summary of test results. Use the -R -option to specify a regular expression of test names to match. - -\fBcmaketest\fP is provided to simplify project testing scripts. It -allows a CMake project to be compiled and tested from a single command -line. - -.SH OPTIONS - -.TP -.B \-\-help -Available for \fBcmake\fP , \fBccmake\fP and \fBcmaketest\fP. -.br -Show version number and summary of options. - -.TP -.B -R regex -Available for \fBctest\fP. -.br -Run only tests matching the given regular expression. - -.TP -.B -i -Available for \fBcmake\fP. -.br -Run cmake in an interactive wizard mode to configure the build. - -.SH SEE ALSO -.BR Dart (1), -.BR VTK (1). - -.SH MAILING LIST -For help using cmake, a mailing list is provided at -\fBcmake@www.cmake.org\fP. Please first read the full documentation -at \fBhttp://www.cmake.org\fP before posting questions to the list. - -.SH AUTHOR -This manual page was written by CMake authors at Kitware -.