zstd-native-ruby 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CLAUDE.md +101 -0
- data/LICENSE +19 -0
- data/README.md +47 -0
- data/ext/zstd_ruby/extconf.rb +35 -0
- data/ext/zstd_ruby/zstd_ruby.c +221 -0
- data/lib/zstd_ruby.rb +68 -0
- data/vendor/zstd/CHANGELOG +863 -0
- data/vendor/zstd/CMakeLists.txt +11 -0
- data/vendor/zstd/CODE_OF_CONDUCT.md +5 -0
- data/vendor/zstd/CONTRIBUTING.md +494 -0
- data/vendor/zstd/COPYING +339 -0
- data/vendor/zstd/LICENSE +30 -0
- data/vendor/zstd/Makefile +470 -0
- data/vendor/zstd/Package.swift +36 -0
- data/vendor/zstd/README.md +244 -0
- data/vendor/zstd/SECURITY.md +15 -0
- data/vendor/zstd/TESTING.md +43 -0
- data/vendor/zstd/build/LICENSE +0 -0
- data/vendor/zstd/build/README.md +56 -0
- data/vendor/zstd/build/VS2008/fullbench/fullbench.vcproj +549 -0
- data/vendor/zstd/build/VS2008/fuzzer/fuzzer.vcproj +585 -0
- data/vendor/zstd/build/VS2008/zstd/zstd.vcproj +677 -0
- data/vendor/zstd/build/VS2008/zstd.sln +56 -0
- data/vendor/zstd/build/VS2008/zstdlib/zstdlib.vcproj +635 -0
- data/vendor/zstd/build/VS2010/CompileAsCpp.props +8 -0
- data/vendor/zstd/build/VS2010/datagen/datagen.vcxproj +170 -0
- data/vendor/zstd/build/VS2010/fullbench/fullbench.vcxproj +220 -0
- data/vendor/zstd/build/VS2010/fuzzer/fuzzer.vcxproj +224 -0
- data/vendor/zstd/build/VS2010/libzstd/libzstd.vcxproj +243 -0
- data/vendor/zstd/build/VS2010/libzstd-dll/libzstd-dll.rc +51 -0
- data/vendor/zstd/build/VS2010/libzstd-dll/libzstd-dll.vcxproj +250 -0
- data/vendor/zstd/build/VS2010/zstd/zstd.rc +51 -0
- data/vendor/zstd/build/VS2010/zstd/zstd.vcxproj +266 -0
- data/vendor/zstd/build/VS2010/zstd.sln +84 -0
- data/vendor/zstd/build/VS_scripts/README.md +64 -0
- data/vendor/zstd/build/VS_scripts/build.VS2010.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2012.cmd +6 -0
- data/vendor/zstd/build/VS_scripts/build.VS2013.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2015.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2017.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2017Community.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2017Enterprise.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VS2017Professional.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.VSPreview.cmd +7 -0
- data/vendor/zstd/build/VS_scripts/build.generic.cmd +67 -0
- data/vendor/zstd/build/cmake/CMakeLists.txt +81 -0
- data/vendor/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake +138 -0
- data/vendor/zstd/build/cmake/CMakeModules/FindLibLZ4.cmake +49 -0
- data/vendor/zstd/build/cmake/CMakeModules/GetZstdLibraryVersion.cmake +10 -0
- data/vendor/zstd/build/cmake/CMakeModules/JoinPaths.cmake +23 -0
- data/vendor/zstd/build/cmake/CMakeModules/ZstdBuild.cmake +42 -0
- data/vendor/zstd/build/cmake/CMakeModules/ZstdDependencies.cmake +30 -0
- data/vendor/zstd/build/cmake/CMakeModules/ZstdOptions.cmake +68 -0
- data/vendor/zstd/build/cmake/CMakeModules/ZstdPackage.cmake +42 -0
- data/vendor/zstd/build/cmake/CMakeModules/ZstdVersion.cmake +31 -0
- data/vendor/zstd/build/cmake/README.md +155 -0
- data/vendor/zstd/build/cmake/contrib/CMakeLists.txt +13 -0
- data/vendor/zstd/build/cmake/contrib/gen_html/CMakeLists.txt +30 -0
- data/vendor/zstd/build/cmake/contrib/pzstd/CMakeLists.txt +39 -0
- data/vendor/zstd/build/cmake/lib/CMakeLists.txt +298 -0
- data/vendor/zstd/build/cmake/lib/cmake_uninstall.cmake.in +22 -0
- data/vendor/zstd/build/cmake/programs/CMakeLists.txt +144 -0
- data/vendor/zstd/build/cmake/tests/CMakeLists.txt +118 -0
- data/vendor/zstd/build/cmake/zstdConfig.cmake.in +10 -0
- data/vendor/zstd/build/meson/GetZstdLibraryVersion.py +39 -0
- data/vendor/zstd/build/meson/InstallSymlink.py +55 -0
- data/vendor/zstd/build/meson/README.md +38 -0
- data/vendor/zstd/build/meson/contrib/gen_html/meson.build +30 -0
- data/vendor/zstd/build/meson/contrib/meson.build +12 -0
- data/vendor/zstd/build/meson/contrib/pzstd/meson.build +25 -0
- data/vendor/zstd/build/meson/lib/meson.build +175 -0
- data/vendor/zstd/build/meson/meson.build +155 -0
- data/vendor/zstd/build/meson/meson_options.txt +36 -0
- data/vendor/zstd/build/meson/programs/meson.build +124 -0
- data/vendor/zstd/build/meson/tests/meson.build +217 -0
- data/vendor/zstd/build/meson/tests/valgrindTest.py +90 -0
- data/vendor/zstd/build/single_file_libs/README.md +33 -0
- data/vendor/zstd/build/single_file_libs/build_decoder_test.sh +91 -0
- data/vendor/zstd/build/single_file_libs/build_library_test.sh +98 -0
- data/vendor/zstd/build/single_file_libs/combine.py +234 -0
- data/vendor/zstd/build/single_file_libs/combine.sh +249 -0
- data/vendor/zstd/build/single_file_libs/create_single_file_decoder.sh +19 -0
- data/vendor/zstd/build/single_file_libs/create_single_file_library.sh +19 -0
- data/vendor/zstd/build/single_file_libs/examples/README.md +11 -0
- data/vendor/zstd/build/single_file_libs/examples/emscripten.c +340 -0
- data/vendor/zstd/build/single_file_libs/examples/roundtrip.c +83 -0
- data/vendor/zstd/build/single_file_libs/examples/shell.html +31 -0
- data/vendor/zstd/build/single_file_libs/examples/simple.c +75 -0
- data/vendor/zstd/build/single_file_libs/examples/testcard-dxt1.inl +2731 -0
- data/vendor/zstd/build/single_file_libs/examples/testcard-zstd.inl +261 -0
- data/vendor/zstd/build/single_file_libs/examples/testcard.png +0 -0
- data/vendor/zstd/build/single_file_libs/zstd-in.c +91 -0
- data/vendor/zstd/build/single_file_libs/zstddeclib-in.c +62 -0
- data/vendor/zstd/contrib/VS2005/README.md +3 -0
- data/vendor/zstd/contrib/VS2005/fullbench/fullbench.vcproj +440 -0
- data/vendor/zstd/contrib/VS2005/fuzzer/fuzzer.vcproj +488 -0
- data/vendor/zstd/contrib/VS2005/zstd/zstd.vcproj +552 -0
- data/vendor/zstd/contrib/VS2005/zstd.sln +55 -0
- data/vendor/zstd/contrib/VS2005/zstdlib/zstdlib.vcproj +546 -0
- data/vendor/zstd/contrib/cleanTabs +2 -0
- data/vendor/zstd/contrib/diagnose_corruption/Makefile +35 -0
- data/vendor/zstd/contrib/diagnose_corruption/check_flipped_bits.c +400 -0
- data/vendor/zstd/contrib/docker/Dockerfile +20 -0
- data/vendor/zstd/contrib/docker/README.md +20 -0
- data/vendor/zstd/contrib/externalSequenceProducer/Makefile +40 -0
- data/vendor/zstd/contrib/externalSequenceProducer/README.md +14 -0
- data/vendor/zstd/contrib/externalSequenceProducer/main.c +108 -0
- data/vendor/zstd/contrib/externalSequenceProducer/sequence_producer.c +80 -0
- data/vendor/zstd/contrib/externalSequenceProducer/sequence_producer.h +26 -0
- data/vendor/zstd/contrib/freestanding_lib/freestanding.py +774 -0
- data/vendor/zstd/contrib/gen_html/Makefile +51 -0
- data/vendor/zstd/contrib/gen_html/README.md +31 -0
- data/vendor/zstd/contrib/gen_html/gen-zstd-manual.sh +9 -0
- data/vendor/zstd/contrib/gen_html/gen_html.cpp +225 -0
- data/vendor/zstd/contrib/largeNbDicts/Makefile +58 -0
- data/vendor/zstd/contrib/largeNbDicts/README.md +33 -0
- data/vendor/zstd/contrib/largeNbDicts/largeNbDicts.c +1087 -0
- data/vendor/zstd/contrib/linux-kernel/Makefile +108 -0
- data/vendor/zstd/contrib/linux-kernel/README.md +14 -0
- data/vendor/zstd/contrib/linux-kernel/btrfs-benchmark.sh +104 -0
- data/vendor/zstd/contrib/linux-kernel/btrfs-extract-benchmark.sh +99 -0
- data/vendor/zstd/contrib/linux-kernel/decompress_sources.h +34 -0
- data/vendor/zstd/contrib/linux-kernel/linux.mk +44 -0
- data/vendor/zstd/contrib/linux-kernel/linux_zstd.h +691 -0
- data/vendor/zstd/contrib/linux-kernel/mem.h +262 -0
- data/vendor/zstd/contrib/linux-kernel/squashfs-benchmark.sh +39 -0
- data/vendor/zstd/contrib/linux-kernel/test/Makefile +49 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/compiler.h +23 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/errno.h +15 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/kernel.h +19 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/limits.h +15 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/math64.h +15 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/module.h +20 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/printk.h +15 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/stddef.h +15 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/swab.h +16 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/types.h +16 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/unaligned.h +187 -0
- data/vendor/zstd/contrib/linux-kernel/test/include/linux/xxhash.h +745 -0
- data/vendor/zstd/contrib/linux-kernel/test/macro-test.sh +44 -0
- data/vendor/zstd/contrib/linux-kernel/test/static_test.c +52 -0
- data/vendor/zstd/contrib/linux-kernel/test/test.c +229 -0
- data/vendor/zstd/contrib/linux-kernel/zstd_common_module.c +29 -0
- data/vendor/zstd/contrib/linux-kernel/zstd_compress_module.c +286 -0
- data/vendor/zstd/contrib/linux-kernel/zstd_decompress_module.c +141 -0
- data/vendor/zstd/contrib/linux-kernel/zstd_deps.h +121 -0
- data/vendor/zstd/contrib/match_finders/README.md +42 -0
- data/vendor/zstd/contrib/match_finders/zstd_edist.c +558 -0
- data/vendor/zstd/contrib/match_finders/zstd_edist.h +70 -0
- data/vendor/zstd/contrib/premake/premake4.lua +6 -0
- data/vendor/zstd/contrib/premake/zstd.lua +81 -0
- data/vendor/zstd/contrib/pzstd/BUCK +72 -0
- data/vendor/zstd/contrib/pzstd/ErrorHolder.h +54 -0
- data/vendor/zstd/contrib/pzstd/Logging.h +73 -0
- data/vendor/zstd/contrib/pzstd/Makefile +265 -0
- data/vendor/zstd/contrib/pzstd/Options.cpp +424 -0
- data/vendor/zstd/contrib/pzstd/Options.h +71 -0
- data/vendor/zstd/contrib/pzstd/Pzstd.cpp +626 -0
- data/vendor/zstd/contrib/pzstd/Pzstd.h +153 -0
- data/vendor/zstd/contrib/pzstd/README.md +56 -0
- data/vendor/zstd/contrib/pzstd/SkippableFrame.cpp +30 -0
- data/vendor/zstd/contrib/pzstd/SkippableFrame.h +64 -0
- data/vendor/zstd/contrib/pzstd/images/Cspeed.png +0 -0
- data/vendor/zstd/contrib/pzstd/images/Dspeed.png +0 -0
- data/vendor/zstd/contrib/pzstd/main.cpp +27 -0
- data/vendor/zstd/contrib/pzstd/test/BUCK +37 -0
- data/vendor/zstd/contrib/pzstd/test/OptionsTest.cpp +536 -0
- data/vendor/zstd/contrib/pzstd/test/PzstdTest.cpp +147 -0
- data/vendor/zstd/contrib/pzstd/test/RoundTrip.h +86 -0
- data/vendor/zstd/contrib/pzstd/test/RoundTripTest.cpp +84 -0
- data/vendor/zstd/contrib/pzstd/utils/BUCK +75 -0
- data/vendor/zstd/contrib/pzstd/utils/Buffer.h +99 -0
- data/vendor/zstd/contrib/pzstd/utils/FileSystem.h +96 -0
- data/vendor/zstd/contrib/pzstd/utils/Likely.h +28 -0
- data/vendor/zstd/contrib/pzstd/utils/Portability.h +16 -0
- data/vendor/zstd/contrib/pzstd/utils/Range.h +133 -0
- data/vendor/zstd/contrib/pzstd/utils/ResourcePool.h +96 -0
- data/vendor/zstd/contrib/pzstd/utils/ScopeGuard.h +50 -0
- data/vendor/zstd/contrib/pzstd/utils/ThreadPool.h +58 -0
- data/vendor/zstd/contrib/pzstd/utils/WorkQueue.h +182 -0
- data/vendor/zstd/contrib/pzstd/utils/test/BUCK +35 -0
- data/vendor/zstd/contrib/pzstd/utils/test/BufferTest.cpp +89 -0
- data/vendor/zstd/contrib/pzstd/utils/test/RangeTest.cpp +82 -0
- data/vendor/zstd/contrib/pzstd/utils/test/ResourcePoolTest.cpp +72 -0
- data/vendor/zstd/contrib/pzstd/utils/test/ScopeGuardTest.cpp +28 -0
- data/vendor/zstd/contrib/pzstd/utils/test/ThreadPoolTest.cpp +71 -0
- data/vendor/zstd/contrib/pzstd/utils/test/WorkQueueTest.cpp +282 -0
- data/vendor/zstd/contrib/recovery/Makefile +35 -0
- data/vendor/zstd/contrib/recovery/recover_directory.c +152 -0
- data/vendor/zstd/contrib/seekable_format/README.md +42 -0
- data/vendor/zstd/contrib/seekable_format/examples/Makefile +55 -0
- data/vendor/zstd/contrib/seekable_format/examples/parallel_compression.c +254 -0
- data/vendor/zstd/contrib/seekable_format/examples/parallel_processing.c +191 -0
- data/vendor/zstd/contrib/seekable_format/examples/seekable_compression.c +136 -0
- data/vendor/zstd/contrib/seekable_format/examples/seekable_decompression.c +141 -0
- data/vendor/zstd/contrib/seekable_format/examples/seekable_decompression_mem.c +147 -0
- data/vendor/zstd/contrib/seekable_format/tests/Makefile +58 -0
- data/vendor/zstd/contrib/seekable_format/tests/seekable_tests.c +375 -0
- data/vendor/zstd/contrib/seekable_format/zstd_seekable.h +226 -0
- data/vendor/zstd/contrib/seekable_format/zstd_seekable_compression_format.md +116 -0
- data/vendor/zstd/contrib/seekable_format/zstdseek_compress.c +365 -0
- data/vendor/zstd/contrib/seekable_format/zstdseek_decompress.c +600 -0
- data/vendor/zstd/contrib/seqBench/Makefile +58 -0
- data/vendor/zstd/contrib/seqBench/seqBench.c +53 -0
- data/vendor/zstd/contrib/snap/snapcraft.yaml +28 -0
- data/vendor/zstd/doc/README.md +26 -0
- data/vendor/zstd/doc/decompressor_errata.md +148 -0
- data/vendor/zstd/doc/decompressor_permissive.md +80 -0
- data/vendor/zstd/doc/educational_decoder/Makefile +62 -0
- data/vendor/zstd/doc/educational_decoder/README.md +36 -0
- data/vendor/zstd/doc/educational_decoder/harness.c +119 -0
- data/vendor/zstd/doc/educational_decoder/zstd_decompress.c +2323 -0
- data/vendor/zstd/doc/educational_decoder/zstd_decompress.h +61 -0
- data/vendor/zstd/doc/images/CSpeed2.png +0 -0
- data/vendor/zstd/doc/images/DCspeed5.png +0 -0
- data/vendor/zstd/doc/images/DSpeed3.png +0 -0
- data/vendor/zstd/doc/images/cdict_v136.png +0 -0
- data/vendor/zstd/doc/images/dict-cr.png +0 -0
- data/vendor/zstd/doc/images/dict-cs.png +0 -0
- data/vendor/zstd/doc/images/dict-ds.png +0 -0
- data/vendor/zstd/doc/images/zstd_cdict_v1_3_5.png +0 -0
- data/vendor/zstd/doc/images/zstd_logo86.png +0 -0
- data/vendor/zstd/doc/zstd_compression_format.md +1772 -0
- data/vendor/zstd/doc/zstd_manual.html +2244 -0
- data/vendor/zstd/examples/Makefile +93 -0
- data/vendor/zstd/examples/README.md +46 -0
- data/vendor/zstd/examples/common.h +246 -0
- data/vendor/zstd/examples/dictionary_compression.c +107 -0
- data/vendor/zstd/examples/dictionary_decompression.c +99 -0
- data/vendor/zstd/examples/multiple_simple_compression.c +116 -0
- data/vendor/zstd/examples/multiple_streaming_compression.c +133 -0
- data/vendor/zstd/examples/simple_compression.c +68 -0
- data/vendor/zstd/examples/simple_decompression.c +65 -0
- data/vendor/zstd/examples/streaming_compression.c +146 -0
- data/vendor/zstd/examples/streaming_compression_thread_pool.c +180 -0
- data/vendor/zstd/examples/streaming_decompression.c +100 -0
- data/vendor/zstd/examples/streaming_memory_usage.c +137 -0
- data/vendor/zstd/lib/BUCK +232 -0
- data/vendor/zstd/lib/Makefile +389 -0
- data/vendor/zstd/lib/README.md +267 -0
- data/vendor/zstd/lib/common/allocations.h +55 -0
- data/vendor/zstd/lib/common/bits.h +205 -0
- data/vendor/zstd/lib/common/bitstream.h +454 -0
- data/vendor/zstd/lib/common/compiler.h +482 -0
- data/vendor/zstd/lib/common/cpu.h +249 -0
- data/vendor/zstd/lib/common/debug.c +30 -0
- data/vendor/zstd/lib/common/debug.h +107 -0
- data/vendor/zstd/lib/common/debug.o +0 -0
- data/vendor/zstd/lib/common/entropy_common.c +340 -0
- data/vendor/zstd/lib/common/entropy_common.o +0 -0
- data/vendor/zstd/lib/common/error_private.c +64 -0
- data/vendor/zstd/lib/common/error_private.h +158 -0
- data/vendor/zstd/lib/common/error_private.o +0 -0
- data/vendor/zstd/lib/common/fse.h +625 -0
- data/vendor/zstd/lib/common/fse_decompress.c +315 -0
- data/vendor/zstd/lib/common/fse_decompress.o +0 -0
- data/vendor/zstd/lib/common/huf.h +277 -0
- data/vendor/zstd/lib/common/mem.h +422 -0
- data/vendor/zstd/lib/common/pool.c +371 -0
- data/vendor/zstd/lib/common/pool.h +81 -0
- data/vendor/zstd/lib/common/pool.o +0 -0
- data/vendor/zstd/lib/common/portability_macros.h +190 -0
- data/vendor/zstd/lib/common/threading.c +196 -0
- data/vendor/zstd/lib/common/threading.h +142 -0
- data/vendor/zstd/lib/common/threading.o +0 -0
- data/vendor/zstd/lib/common/xxhash.c +18 -0
- data/vendor/zstd/lib/common/xxhash.h +7094 -0
- data/vendor/zstd/lib/common/xxhash.o +0 -0
- data/vendor/zstd/lib/common/zstd_common.c +57 -0
- data/vendor/zstd/lib/common/zstd_common.o +0 -0
- data/vendor/zstd/lib/common/zstd_deps.h +123 -0
- data/vendor/zstd/lib/common/zstd_internal.h +326 -0
- data/vendor/zstd/lib/common/zstd_trace.h +156 -0
- data/vendor/zstd/lib/compress/clevels.h +134 -0
- data/vendor/zstd/lib/compress/fse_compress.c +625 -0
- data/vendor/zstd/lib/compress/fse_compress.o +0 -0
- data/vendor/zstd/lib/compress/hist.c +446 -0
- data/vendor/zstd/lib/compress/hist.h +86 -0
- data/vendor/zstd/lib/compress/hist.o +0 -0
- data/vendor/zstd/lib/compress/huf_compress.c +1465 -0
- data/vendor/zstd/lib/compress/huf_compress.o +0 -0
- data/vendor/zstd/lib/compress/zstd_compress.c +8362 -0
- data/vendor/zstd/lib/compress/zstd_compress.o +0 -0
- data/vendor/zstd/lib/compress/zstd_compress_internal.h +1636 -0
- data/vendor/zstd/lib/compress/zstd_compress_literals.c +235 -0
- data/vendor/zstd/lib/compress/zstd_compress_literals.h +39 -0
- data/vendor/zstd/lib/compress/zstd_compress_literals.o +0 -0
- data/vendor/zstd/lib/compress/zstd_compress_sequences.c +442 -0
- data/vendor/zstd/lib/compress/zstd_compress_sequences.h +55 -0
- data/vendor/zstd/lib/compress/zstd_compress_sequences.o +0 -0
- data/vendor/zstd/lib/compress/zstd_compress_superblock.c +688 -0
- data/vendor/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/vendor/zstd/lib/compress/zstd_compress_superblock.o +0 -0
- data/vendor/zstd/lib/compress/zstd_cwksp.h +765 -0
- data/vendor/zstd/lib/compress/zstd_double_fast.c +778 -0
- data/vendor/zstd/lib/compress/zstd_double_fast.h +42 -0
- data/vendor/zstd/lib/compress/zstd_double_fast.o +0 -0
- data/vendor/zstd/lib/compress/zstd_fast.c +985 -0
- data/vendor/zstd/lib/compress/zstd_fast.h +30 -0
- data/vendor/zstd/lib/compress/zstd_fast.o +0 -0
- data/vendor/zstd/lib/compress/zstd_lazy.c +2243 -0
- data/vendor/zstd/lib/compress/zstd_lazy.h +193 -0
- data/vendor/zstd/lib/compress/zstd_lazy.o +0 -0
- data/vendor/zstd/lib/compress/zstd_ldm.c +745 -0
- data/vendor/zstd/lib/compress/zstd_ldm.h +109 -0
- data/vendor/zstd/lib/compress/zstd_ldm.o +0 -0
- data/vendor/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/vendor/zstd/lib/compress/zstd_opt.c +1572 -0
- data/vendor/zstd/lib/compress/zstd_opt.h +72 -0
- data/vendor/zstd/lib/compress/zstd_opt.o +0 -0
- data/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
- data/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
- data/vendor/zstd/lib/compress/zstd_preSplit.o +0 -0
- data/vendor/zstd/lib/compress/zstdmt_compress.c +1924 -0
- data/vendor/zstd/lib/compress/zstdmt_compress.h +102 -0
- data/vendor/zstd/lib/compress/zstdmt_compress.o +0 -0
- data/vendor/zstd/lib/decompress/huf_decompress.c +1953 -0
- data/vendor/zstd/lib/decompress/huf_decompress.o +0 -0
- data/vendor/zstd/lib/decompress/huf_decompress_amd64.S +766 -0
- data/vendor/zstd/lib/decompress/zstd_ddict.c +244 -0
- data/vendor/zstd/lib/decompress/zstd_ddict.h +44 -0
- data/vendor/zstd/lib/decompress/zstd_ddict.o +0 -0
- data/vendor/zstd/lib/decompress/zstd_decompress.c +2410 -0
- data/vendor/zstd/lib/decompress/zstd_decompress.o +0 -0
- data/vendor/zstd/lib/decompress/zstd_decompress_block.c +2311 -0
- data/vendor/zstd/lib/decompress/zstd_decompress_block.h +73 -0
- data/vendor/zstd/lib/decompress/zstd_decompress_block.o +0 -0
- data/vendor/zstd/lib/decompress/zstd_decompress_internal.h +240 -0
- data/vendor/zstd/lib/deprecated/zbuff.h +214 -0
- data/vendor/zstd/lib/deprecated/zbuff_common.c +26 -0
- data/vendor/zstd/lib/deprecated/zbuff_compress.c +167 -0
- data/vendor/zstd/lib/deprecated/zbuff_decompress.c +77 -0
- data/vendor/zstd/lib/dictBuilder/cover.c +1333 -0
- data/vendor/zstd/lib/dictBuilder/cover.h +152 -0
- data/vendor/zstd/lib/dictBuilder/divsufsort.c +1913 -0
- data/vendor/zstd/lib/dictBuilder/divsufsort.h +57 -0
- data/vendor/zstd/lib/dictBuilder/fastcover.c +765 -0
- data/vendor/zstd/lib/dictBuilder/zdict.c +1137 -0
- data/vendor/zstd/lib/dll/example/Makefile +48 -0
- data/vendor/zstd/lib/dll/example/README.md +63 -0
- data/vendor/zstd/lib/dll/example/build_package.bat +55 -0
- data/vendor/zstd/lib/dll/example/fullbench-dll.sln +25 -0
- data/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +181 -0
- data/vendor/zstd/lib/install_oses.mk +17 -0
- data/vendor/zstd/lib/legacy/zstd_legacy.h +452 -0
- data/vendor/zstd/lib/legacy/zstd_v01.c +2128 -0
- data/vendor/zstd/lib/legacy/zstd_v01.h +94 -0
- data/vendor/zstd/lib/legacy/zstd_v02.c +3465 -0
- data/vendor/zstd/lib/legacy/zstd_v02.h +93 -0
- data/vendor/zstd/lib/legacy/zstd_v03.c +3105 -0
- data/vendor/zstd/lib/legacy/zstd_v03.h +93 -0
- data/vendor/zstd/lib/legacy/zstd_v04.c +3598 -0
- data/vendor/zstd/lib/legacy/zstd_v04.h +142 -0
- data/vendor/zstd/lib/legacy/zstd_v05.c +4005 -0
- data/vendor/zstd/lib/legacy/zstd_v05.h +162 -0
- data/vendor/zstd/lib/legacy/zstd_v06.c +4110 -0
- data/vendor/zstd/lib/legacy/zstd_v06.h +172 -0
- data/vendor/zstd/lib/legacy/zstd_v07.c +4490 -0
- data/vendor/zstd/lib/legacy/zstd_v07.h +187 -0
- data/vendor/zstd/lib/libzstd.mk +238 -0
- data/vendor/zstd/lib/libzstd.pc.in +17 -0
- data/vendor/zstd/lib/module.modulemap +35 -0
- data/vendor/zstd/lib/zdict.h +481 -0
- data/vendor/zstd/lib/zstd.h +3209 -0
- data/vendor/zstd/lib/zstd_errors.h +107 -0
- data/vendor/zstd/programs/BUCK +44 -0
- data/vendor/zstd/programs/Makefile +445 -0
- data/vendor/zstd/programs/README.md +344 -0
- data/vendor/zstd/programs/benchfn.c +256 -0
- data/vendor/zstd/programs/benchfn.h +173 -0
- data/vendor/zstd/programs/benchzstd.c +1270 -0
- data/vendor/zstd/programs/benchzstd.h +191 -0
- data/vendor/zstd/programs/datagen.c +186 -0
- data/vendor/zstd/programs/datagen.h +38 -0
- data/vendor/zstd/programs/dibio.c +447 -0
- data/vendor/zstd/programs/dibio.h +39 -0
- data/vendor/zstd/programs/fileio.c +3717 -0
- data/vendor/zstd/programs/fileio.h +171 -0
- data/vendor/zstd/programs/fileio_asyncio.c +663 -0
- data/vendor/zstd/programs/fileio_asyncio.h +195 -0
- data/vendor/zstd/programs/fileio_common.h +121 -0
- data/vendor/zstd/programs/fileio_types.h +86 -0
- data/vendor/zstd/programs/lorem.c +285 -0
- data/vendor/zstd/programs/lorem.h +32 -0
- data/vendor/zstd/programs/platform.h +217 -0
- data/vendor/zstd/programs/timefn.c +170 -0
- data/vendor/zstd/programs/timefn.h +59 -0
- data/vendor/zstd/programs/util.c +1731 -0
- data/vendor/zstd/programs/util.h +364 -0
- data/vendor/zstd/programs/windres/verrsrc.h +17 -0
- data/vendor/zstd/programs/windres/zstd.rc +51 -0
- data/vendor/zstd/programs/windres/zstd32.res +0 -0
- data/vendor/zstd/programs/windres/zstd64.res +0 -0
- data/vendor/zstd/programs/zstd.1 +580 -0
- data/vendor/zstd/programs/zstd.1.md +714 -0
- data/vendor/zstd/programs/zstdcli.c +1675 -0
- data/vendor/zstd/programs/zstdcli_trace.c +173 -0
- data/vendor/zstd/programs/zstdcli_trace.h +24 -0
- data/vendor/zstd/programs/zstdgrep +134 -0
- data/vendor/zstd/programs/zstdgrep.1 +26 -0
- data/vendor/zstd/programs/zstdgrep.1.md +30 -0
- data/vendor/zstd/programs/zstdless +8 -0
- data/vendor/zstd/programs/zstdless.1 +14 -0
- data/vendor/zstd/programs/zstdless.1.md +16 -0
- data/vendor/zstd/tests/DEPRECATED-test-zstd-speed.py +378 -0
- data/vendor/zstd/tests/Makefile +485 -0
- data/vendor/zstd/tests/README.md +184 -0
- data/vendor/zstd/tests/automated_benchmarking.py +326 -0
- data/vendor/zstd/tests/checkTag.c +65 -0
- data/vendor/zstd/tests/check_size.py +31 -0
- data/vendor/zstd/tests/cli-tests/README.md +258 -0
- data/vendor/zstd/tests/cli-tests/basic/args.sh +10 -0
- data/vendor/zstd/tests/cli-tests/basic/args.sh.exit +1 -0
- data/vendor/zstd/tests/cli-tests/basic/args.sh.stderr.glob +28 -0
- data/vendor/zstd/tests/cli-tests/basic/help.sh +10 -0
- data/vendor/zstd/tests/cli-tests/basic/help.sh.stdout.glob +34 -0
- data/vendor/zstd/tests/cli-tests/basic/memlimit.sh +40 -0
- data/vendor/zstd/tests/cli-tests/basic/memlimit.sh.stderr.exact +13 -0
- data/vendor/zstd/tests/cli-tests/basic/memlimit.sh.stdout.exact +13 -0
- data/vendor/zstd/tests/cli-tests/basic/output_dir.sh +7 -0
- data/vendor/zstd/tests/cli-tests/basic/output_dir.sh.stderr.exact +2 -0
- data/vendor/zstd/tests/cli-tests/basic/output_dir.sh.stdout.exact +2 -0
- data/vendor/zstd/tests/cli-tests/basic/version.sh +6 -0
- data/vendor/zstd/tests/cli-tests/basic/version.sh.stdout.glob +2 -0
- data/vendor/zstd/tests/cli-tests/bin/cmp_size +44 -0
- data/vendor/zstd/tests/cli-tests/bin/datagen +3 -0
- data/vendor/zstd/tests/cli-tests/bin/die +4 -0
- data/vendor/zstd/tests/cli-tests/bin/println +2 -0
- data/vendor/zstd/tests/cli-tests/bin/unzstd +1 -0
- data/vendor/zstd/tests/cli-tests/bin/zstd +9 -0
- data/vendor/zstd/tests/cli-tests/bin/zstdcat +1 -0
- data/vendor/zstd/tests/cli-tests/bin/zstdgrep +2 -0
- data/vendor/zstd/tests/cli-tests/bin/zstdless +2 -0
- data/vendor/zstd/tests/cli-tests/cltools/setup +6 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdgrep.sh +8 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdgrep.sh.exit +1 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdgrep.sh.stderr.exact +1 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdgrep.sh.stdout.glob +4 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdless.sh +10 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdless.sh.stderr.exact +2 -0
- data/vendor/zstd/tests/cli-tests/cltools/zstdless.sh.stdout.glob +5 -0
- data/vendor/zstd/tests/cli-tests/common/format.sh +19 -0
- data/vendor/zstd/tests/cli-tests/common/mtime.sh +13 -0
- data/vendor/zstd/tests/cli-tests/common/permissions.sh +18 -0
- data/vendor/zstd/tests/cli-tests/common/platform.sh +47 -0
- data/vendor/zstd/tests/cli-tests/compression/adapt.sh +14 -0
- data/vendor/zstd/tests/cli-tests/compression/basic.sh +36 -0
- data/vendor/zstd/tests/cli-tests/compression/compress-literals.sh +10 -0
- data/vendor/zstd/tests/cli-tests/compression/format.sh +16 -0
- data/vendor/zstd/tests/cli-tests/compression/golden.sh +16 -0
- data/vendor/zstd/tests/cli-tests/compression/gzip-compat.sh +17 -0
- data/vendor/zstd/tests/cli-tests/compression/levels.sh +75 -0
- data/vendor/zstd/tests/cli-tests/compression/levels.sh.stderr.exact +80 -0
- data/vendor/zstd/tests/cli-tests/compression/long-distance-matcher.sh +7 -0
- data/vendor/zstd/tests/cli-tests/compression/multi-threaded.sh +22 -0
- data/vendor/zstd/tests/cli-tests/compression/multi-threaded.sh.stderr.exact +21 -0
- data/vendor/zstd/tests/cli-tests/compression/multiple-files.sh +21 -0
- data/vendor/zstd/tests/cli-tests/compression/multiple-files.sh.stdout.exact +12 -0
- data/vendor/zstd/tests/cli-tests/compression/row-match-finder.sh +7 -0
- data/vendor/zstd/tests/cli-tests/compression/setup +7 -0
- data/vendor/zstd/tests/cli-tests/compression/stream-size.sh +7 -0
- data/vendor/zstd/tests/cli-tests/compression/verbose-wlog.sh +11 -0
- data/vendor/zstd/tests/cli-tests/compression/verbose-wlog.sh.stderr.glob +5 -0
- data/vendor/zstd/tests/cli-tests/compression/verbose-wlog.sh.stdout.glob +5 -0
- data/vendor/zstd/tests/cli-tests/compression/window-resize.sh +9 -0
- data/vendor/zstd/tests/cli-tests/compression/window-resize.sh.stderr.ignore +0 -0
- data/vendor/zstd/tests/cli-tests/compression/window-resize.sh.stdout.glob +3 -0
- data/vendor/zstd/tests/cli-tests/decompression/detectErrors.sh +11 -0
- data/vendor/zstd/tests/cli-tests/decompression/golden.sh +7 -0
- data/vendor/zstd/tests/cli-tests/decompression/pass-through.sh +57 -0
- data/vendor/zstd/tests/cli-tests/decompression/pass-through.sh.stderr.exact +11 -0
- data/vendor/zstd/tests/cli-tests/decompression/pass-through.sh.stdout.exact +25 -0
- data/vendor/zstd/tests/cli-tests/determinism/basic.sh +36 -0
- data/vendor/zstd/tests/cli-tests/determinism/basic.sh.stderr.exact +0 -0
- data/vendor/zstd/tests/cli-tests/determinism/basic.sh.stdout.exact +880 -0
- data/vendor/zstd/tests/cli-tests/determinism/multithread.sh +45 -0
- data/vendor/zstd/tests/cli-tests/determinism/multithread.sh.stderr.exact +0 -0
- data/vendor/zstd/tests/cli-tests/determinism/multithread.sh.stdout.exact +260 -0
- data/vendor/zstd/tests/cli-tests/determinism/reuse.sh +44 -0
- data/vendor/zstd/tests/cli-tests/determinism/reuse.sh.stderr.exact +0 -0
- data/vendor/zstd/tests/cli-tests/determinism/reuse.sh.stdout.exact +19 -0
- data/vendor/zstd/tests/cli-tests/determinism/setup +5 -0
- data/vendor/zstd/tests/cli-tests/determinism/setup_once +30 -0
- data/vendor/zstd/tests/cli-tests/dict-builder/empty-input.sh +9 -0
- data/vendor/zstd/tests/cli-tests/dict-builder/empty-input.sh.stderr.exact +1 -0
- data/vendor/zstd/tests/cli-tests/dict-builder/no-inputs.sh +3 -0
- data/vendor/zstd/tests/cli-tests/dict-builder/no-inputs.sh.exit +1 -0
- data/vendor/zstd/tests/cli-tests/dict-builder/no-inputs.sh.stderr.exact +5 -0
- data/vendor/zstd/tests/cli-tests/dictionaries/dictionary-mismatch.sh +29 -0
- data/vendor/zstd/tests/cli-tests/dictionaries/dictionary-mismatch.sh.stderr.exact +7 -0
- data/vendor/zstd/tests/cli-tests/dictionaries/golden.sh +9 -0
- data/vendor/zstd/tests/cli-tests/dictionaries/setup +6 -0
- data/vendor/zstd/tests/cli-tests/dictionaries/setup_once +24 -0
- data/vendor/zstd/tests/cli-tests/file-handling/directory-mirror.sh +49 -0
- data/vendor/zstd/tests/cli-tests/file-handling/directory-mirror.sh.stderr.exact +0 -0
- data/vendor/zstd/tests/cli-tests/file-handling/directory-mirror.sh.stdout.exact +0 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-dir-without-write-perm.sh +12 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-dir-without-write-perm.sh.stderr.exact +30 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-file.sh +9 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-file.sh.stderr.glob +46 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-stdout.sh +8 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-file-to-stdout.sh.stderr.exact +24 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-stdin-to-file.sh +8 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-stdin-to-file.sh.stderr.glob +28 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-stdin-to-stdout.sh +8 -0
- data/vendor/zstd/tests/cli-tests/file-stat/compress-stdin-to-stdout.sh.stderr.exact +18 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-file-to-file.sh +8 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-file-to-file.sh.stderr.glob +42 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-file-to-stdout.sh +7 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-file-to-stdout.sh.stderr.exact +18 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-stdin-to-file.sh +7 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-stdin-to-file.sh.stderr.glob +24 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-stdin-to-stdout.sh +7 -0
- data/vendor/zstd/tests/cli-tests/file-stat/decompress-stdin-to-stdout.sh.stderr.exact +14 -0
- data/vendor/zstd/tests/cli-tests/progress/no-progress.sh +46 -0
- data/vendor/zstd/tests/cli-tests/progress/no-progress.sh.stderr.glob +96 -0
- data/vendor/zstd/tests/cli-tests/progress/progress.sh +41 -0
- data/vendor/zstd/tests/cli-tests/progress/progress.sh.stderr.glob +62 -0
- data/vendor/zstd/tests/cli-tests/run.py +732 -0
- data/vendor/zstd/tests/cli-tests/zstd-symlinks/setup +6 -0
- data/vendor/zstd/tests/cli-tests/zstd-symlinks/zstdcat.sh +12 -0
- data/vendor/zstd/tests/cli-tests/zstd-symlinks/zstdcat.sh.stdout.exact +8 -0
- data/vendor/zstd/tests/datagencli.c +149 -0
- data/vendor/zstd/tests/decodecorpus.c +1998 -0
- data/vendor/zstd/tests/dict-files/zero-weight-dict +0 -0
- data/vendor/zstd/tests/external_matchfinder.c +140 -0
- data/vendor/zstd/tests/external_matchfinder.h +39 -0
- data/vendor/zstd/tests/fullbench.c +1210 -0
- data/vendor/zstd/tests/fuzz/Makefile +278 -0
- data/vendor/zstd/tests/fuzz/README.md +161 -0
- data/vendor/zstd/tests/fuzz/block_decompress.c +53 -0
- data/vendor/zstd/tests/fuzz/block_round_trip.c +103 -0
- data/vendor/zstd/tests/fuzz/decompress_cross_format.c +130 -0
- data/vendor/zstd/tests/fuzz/decompress_dstSize_tooSmall.c +74 -0
- data/vendor/zstd/tests/fuzz/dictionary_decompress.c +77 -0
- data/vendor/zstd/tests/fuzz/dictionary_loader.c +106 -0
- data/vendor/zstd/tests/fuzz/dictionary_round_trip.c +155 -0
- data/vendor/zstd/tests/fuzz/dictionary_stream_round_trip.c +209 -0
- data/vendor/zstd/tests/fuzz/fse_read_ncount.c +100 -0
- data/vendor/zstd/tests/fuzz/fuzz.h +57 -0
- data/vendor/zstd/tests/fuzz/fuzz.py +910 -0
- data/vendor/zstd/tests/fuzz/fuzz_data_producer.c +95 -0
- data/vendor/zstd/tests/fuzz/fuzz_data_producer.h +66 -0
- data/vendor/zstd/tests/fuzz/fuzz_helpers.c +47 -0
- data/vendor/zstd/tests/fuzz/fuzz_helpers.h +82 -0
- data/vendor/zstd/tests/fuzz/fuzz_third_party_seq_prod.h +116 -0
- data/vendor/zstd/tests/fuzz/generate_sequences.c +88 -0
- data/vendor/zstd/tests/fuzz/huf_decompress.c +68 -0
- data/vendor/zstd/tests/fuzz/huf_round_trip.c +137 -0
- data/vendor/zstd/tests/fuzz/raw_dictionary_round_trip.c +119 -0
- data/vendor/zstd/tests/fuzz/regression_driver.c +90 -0
- data/vendor/zstd/tests/fuzz/seekable_roundtrip.c +88 -0
- data/vendor/zstd/tests/fuzz/seq_prod_fuzz_example/Makefile +16 -0
- data/vendor/zstd/tests/fuzz/seq_prod_fuzz_example/README.md +12 -0
- data/vendor/zstd/tests/fuzz/seq_prod_fuzz_example/example_seq_prod.c +52 -0
- data/vendor/zstd/tests/fuzz/sequence_compression_api.c +452 -0
- data/vendor/zstd/tests/fuzz/simple_compress.c +60 -0
- data/vendor/zstd/tests/fuzz/simple_decompress.c +59 -0
- data/vendor/zstd/tests/fuzz/simple_round_trip.c +182 -0
- data/vendor/zstd/tests/fuzz/stream_decompress.c +119 -0
- data/vendor/zstd/tests/fuzz/stream_round_trip.c +218 -0
- data/vendor/zstd/tests/fuzz/zstd_frame_info.c +43 -0
- data/vendor/zstd/tests/fuzz/zstd_helpers.c +208 -0
- data/vendor/zstd/tests/fuzz/zstd_helpers.h +56 -0
- data/vendor/zstd/tests/fuzzer.c +5482 -0
- data/vendor/zstd/tests/golden-compression/PR-3517-block-splitter-corruption-test +1 -0
- data/vendor/zstd/tests/golden-compression/http +1 -0
- data/vendor/zstd/tests/golden-compression/huffman-compressed-larger +0 -0
- data/vendor/zstd/tests/golden-compression/large-literal-and-match-lengths +0 -0
- data/vendor/zstd/tests/golden-decompression/block-128k.zst +0 -0
- data/vendor/zstd/tests/golden-decompression/empty-block.zst +0 -0
- data/vendor/zstd/tests/golden-decompression/rle-first-block.zst +0 -0
- data/vendor/zstd/tests/golden-decompression/zeroSeq_2B.zst +0 -0
- data/vendor/zstd/tests/golden-decompression-errors/off0.bin.zst +0 -0
- data/vendor/zstd/tests/golden-decompression-errors/truncated_huff_state.zst +0 -0
- data/vendor/zstd/tests/golden-decompression-errors/zeroSeq_extraneous.zst +0 -0
- data/vendor/zstd/tests/golden-dictionaries/http-dict-missing-symbols +0 -0
- data/vendor/zstd/tests/gzip/Makefile +45 -0
- data/vendor/zstd/tests/gzip/gzip-env.sh +46 -0
- data/vendor/zstd/tests/gzip/helin-segv.sh +31 -0
- data/vendor/zstd/tests/gzip/help-version.sh +270 -0
- data/vendor/zstd/tests/gzip/hufts-segv.gz +0 -0
- data/vendor/zstd/tests/gzip/hufts.sh +34 -0
- data/vendor/zstd/tests/gzip/init.cfg +5 -0
- data/vendor/zstd/tests/gzip/init.sh +616 -0
- data/vendor/zstd/tests/gzip/keep.sh +51 -0
- data/vendor/zstd/tests/gzip/list.sh +31 -0
- data/vendor/zstd/tests/gzip/memcpy-abuse.sh +34 -0
- data/vendor/zstd/tests/gzip/mixed.sh +68 -0
- data/vendor/zstd/tests/gzip/null-suffix-clobber.sh +35 -0
- data/vendor/zstd/tests/gzip/stdin.sh +31 -0
- data/vendor/zstd/tests/gzip/test-driver.sh +150 -0
- data/vendor/zstd/tests/gzip/trailing-nul.sh +37 -0
- data/vendor/zstd/tests/gzip/unpack-invalid.sh +36 -0
- data/vendor/zstd/tests/gzip/z-suffix.sh +30 -0
- data/vendor/zstd/tests/gzip/zdiff.sh +48 -0
- data/vendor/zstd/tests/gzip/zgrep-context.sh +47 -0
- data/vendor/zstd/tests/gzip/zgrep-f.sh +43 -0
- data/vendor/zstd/tests/gzip/zgrep-signal.sh +64 -0
- data/vendor/zstd/tests/gzip/znew-k.sh +40 -0
- data/vendor/zstd/tests/invalidDictionaries.c +61 -0
- data/vendor/zstd/tests/largeDictionary.c +131 -0
- data/vendor/zstd/tests/legacy.c +262 -0
- data/vendor/zstd/tests/libzstd_builds.sh +104 -0
- data/vendor/zstd/tests/longmatch.c +123 -0
- data/vendor/zstd/tests/loremOut.c +50 -0
- data/vendor/zstd/tests/loremOut.h +15 -0
- data/vendor/zstd/tests/paramgrill.c +2965 -0
- data/vendor/zstd/tests/playTests.sh +1926 -0
- data/vendor/zstd/tests/poolTests.c +271 -0
- data/vendor/zstd/tests/rateLimiter.py +41 -0
- data/vendor/zstd/tests/regression/Makefile +60 -0
- data/vendor/zstd/tests/regression/README.md +28 -0
- data/vendor/zstd/tests/regression/config.c +404 -0
- data/vendor/zstd/tests/regression/config.h +91 -0
- data/vendor/zstd/tests/regression/data.c +631 -0
- data/vendor/zstd/tests/regression/data.h +121 -0
- data/vendor/zstd/tests/regression/levels.h +59 -0
- data/vendor/zstd/tests/regression/method.c +701 -0
- data/vendor/zstd/tests/regression/method.h +65 -0
- data/vendor/zstd/tests/regression/result.c +30 -0
- data/vendor/zstd/tests/regression/result.h +103 -0
- data/vendor/zstd/tests/regression/results.csv +1480 -0
- data/vendor/zstd/tests/regression/test.c +362 -0
- data/vendor/zstd/tests/roundTripCrash.c +241 -0
- data/vendor/zstd/tests/seqgen.c +260 -0
- data/vendor/zstd/tests/seqgen.h +58 -0
- data/vendor/zstd/tests/test-license.py +156 -0
- data/vendor/zstd/tests/test-variants.sh +115 -0
- data/vendor/zstd/tests/test-zstd-versions.py +308 -0
- data/vendor/zstd/tests/test_process_substitution.bash +92 -0
- data/vendor/zstd/tests/zstreamtest.c +3467 -0
- data/vendor/zstd/zlibWrapper/BUCK +22 -0
- data/vendor/zstd/zlibWrapper/Makefile +120 -0
- data/vendor/zstd/zlibWrapper/README.md +163 -0
- data/vendor/zstd/zlibWrapper/examples/example.c +598 -0
- data/vendor/zstd/zlibWrapper/examples/example_original.c +599 -0
- data/vendor/zstd/zlibWrapper/examples/fitblk.c +254 -0
- data/vendor/zstd/zlibWrapper/examples/fitblk_original.c +233 -0
- data/vendor/zstd/zlibWrapper/examples/minigzip.c +605 -0
- data/vendor/zstd/zlibWrapper/examples/zwrapbench.c +1018 -0
- data/vendor/zstd/zlibWrapper/gzclose.c +26 -0
- data/vendor/zstd/zlibWrapper/gzcompatibility.h +68 -0
- data/vendor/zstd/zlibWrapper/gzguts.h +229 -0
- data/vendor/zstd/zlibWrapper/gzlib.c +587 -0
- data/vendor/zstd/zlibWrapper/gzread.c +637 -0
- data/vendor/zstd/zlibWrapper/gzwrite.c +632 -0
- data/vendor/zstd/zlibWrapper/zstd_zlibwrapper.c +1200 -0
- data/vendor/zstd/zlibWrapper/zstd_zlibwrapper.h +91 -0
- metadata +738 -0
|
@@ -0,0 +1,1731 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
7
|
+
* in the COPYING file in the root directory of this source tree).
|
|
8
|
+
* You may select, at your option, one of the above-listed licenses.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/*-****************************************
|
|
12
|
+
* Dependencies
|
|
13
|
+
******************************************/
|
|
14
|
+
#include "util.h" /* note : ensure that platform.h is included first ! */
|
|
15
|
+
#include <stdlib.h> /* malloc, realloc, free */
|
|
16
|
+
#include <stdio.h> /* fprintf */
|
|
17
|
+
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
|
|
18
|
+
#include <errno.h>
|
|
19
|
+
#include <assert.h>
|
|
20
|
+
|
|
21
|
+
#if defined(__FreeBSD__)
|
|
22
|
+
#include <sys/param.h> /* __FreeBSD_version */
|
|
23
|
+
#endif /* #ifdef __FreeBSD__ */
|
|
24
|
+
|
|
25
|
+
#if defined(_WIN32)
|
|
26
|
+
# include <sys/utime.h> /* utime */
|
|
27
|
+
# include <io.h> /* _chmod */
|
|
28
|
+
# define ZSTD_USE_UTIMENSAT 0
|
|
29
|
+
#else
|
|
30
|
+
# include <unistd.h> /* chown, stat */
|
|
31
|
+
# include <sys/stat.h> /* utimensat, st_mtime */
|
|
32
|
+
# if (PLATFORM_POSIX_VERSION >= 200809L && defined(st_mtime)) \
|
|
33
|
+
|| (defined(__FreeBSD__) && __FreeBSD_version >= 1100056)
|
|
34
|
+
# define ZSTD_USE_UTIMENSAT 1
|
|
35
|
+
# else
|
|
36
|
+
# define ZSTD_USE_UTIMENSAT 0
|
|
37
|
+
# endif
|
|
38
|
+
# if ZSTD_USE_UTIMENSAT
|
|
39
|
+
# include <fcntl.h> /* AT_FDCWD */
|
|
40
|
+
# else
|
|
41
|
+
# include <utime.h> /* utime */
|
|
42
|
+
# endif
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined (__MSVCRT__)
|
|
46
|
+
#include <direct.h> /* needed for _mkdir in windows */
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
#if defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
|
|
50
|
+
# include <dirent.h> /* opendir, readdir */
|
|
51
|
+
# include <string.h> /* strerror, memcpy */
|
|
52
|
+
#endif /* #ifdef _WIN32 */
|
|
53
|
+
|
|
54
|
+
/*-****************************************
|
|
55
|
+
* Internal Macros
|
|
56
|
+
******************************************/
|
|
57
|
+
|
|
58
|
+
/* CONTROL is almost like an assert(), but is never disabled.
|
|
59
|
+
* It's designed for failures that may happen rarely,
|
|
60
|
+
* but we don't want to maintain a specific error code path for them,
|
|
61
|
+
* such as a malloc() returning NULL for example.
|
|
62
|
+
* Since it's always active, this macro can trigger side effects.
|
|
63
|
+
*/
|
|
64
|
+
#define CONTROL(c) { \
|
|
65
|
+
if (!(c)) { \
|
|
66
|
+
UTIL_DISPLAYLEVEL(1, "Error : %s, %i : %s", \
|
|
67
|
+
__FILE__, __LINE__, #c); \
|
|
68
|
+
exit(1); \
|
|
69
|
+
} }
|
|
70
|
+
|
|
71
|
+
/* console log */
|
|
72
|
+
#define UTIL_DISPLAY(...) fprintf(stderr, __VA_ARGS__)
|
|
73
|
+
#define UTIL_DISPLAYLEVEL(l, ...) { if (g_utilDisplayLevel>=l) { UTIL_DISPLAY(__VA_ARGS__); } }
|
|
74
|
+
|
|
75
|
+
static int g_traceDepth = 0;
|
|
76
|
+
int g_traceFileStat = 0;
|
|
77
|
+
|
|
78
|
+
#define UTIL_TRACE_CALL(...) \
|
|
79
|
+
{ \
|
|
80
|
+
if (g_traceFileStat) { \
|
|
81
|
+
UTIL_DISPLAY("Trace:FileStat: %*s> ", g_traceDepth, ""); \
|
|
82
|
+
UTIL_DISPLAY(__VA_ARGS__); \
|
|
83
|
+
UTIL_DISPLAY("\n"); \
|
|
84
|
+
++g_traceDepth; \
|
|
85
|
+
} \
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#define UTIL_TRACE_RET(ret) \
|
|
89
|
+
{ \
|
|
90
|
+
if (g_traceFileStat) { \
|
|
91
|
+
--g_traceDepth; \
|
|
92
|
+
UTIL_DISPLAY("Trace:FileStat: %*s< %d\n", g_traceDepth, "", (ret)); \
|
|
93
|
+
} \
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* A modified version of realloc().
|
|
97
|
+
* If UTIL_realloc() fails the original block is freed.
|
|
98
|
+
*/
|
|
99
|
+
UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size)
|
|
100
|
+
{
|
|
101
|
+
void *newptr = realloc(ptr, size);
|
|
102
|
+
if (newptr) return newptr;
|
|
103
|
+
free(ptr);
|
|
104
|
+
return NULL;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#if defined(_MSC_VER)
|
|
108
|
+
#define chmod _chmod
|
|
109
|
+
#endif
|
|
110
|
+
|
|
111
|
+
#ifndef ZSTD_HAVE_FCHMOD
|
|
112
|
+
#if PLATFORM_POSIX_VERSION >= 199309L
|
|
113
|
+
#define ZSTD_HAVE_FCHMOD
|
|
114
|
+
#endif
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
#ifndef ZSTD_HAVE_FCHOWN
|
|
118
|
+
#if PLATFORM_POSIX_VERSION >= 200809L
|
|
119
|
+
#define ZSTD_HAVE_FCHOWN
|
|
120
|
+
#endif
|
|
121
|
+
#endif
|
|
122
|
+
|
|
123
|
+
/*-****************************************
|
|
124
|
+
* Console log
|
|
125
|
+
******************************************/
|
|
126
|
+
int g_utilDisplayLevel;
|
|
127
|
+
|
|
128
|
+
int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg,
|
|
129
|
+
const char* acceptableLetters, int hasStdinInput) {
|
|
130
|
+
int ch, result;
|
|
131
|
+
|
|
132
|
+
if (hasStdinInput) {
|
|
133
|
+
UTIL_DISPLAY("stdin is an input - not proceeding.\n");
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
UTIL_DISPLAY("%s", prompt);
|
|
138
|
+
ch = getchar();
|
|
139
|
+
result = 0;
|
|
140
|
+
if (strchr(acceptableLetters, ch) == NULL) {
|
|
141
|
+
UTIL_DISPLAY("%s \n", abortMsg);
|
|
142
|
+
result = 1;
|
|
143
|
+
}
|
|
144
|
+
/* flush the rest */
|
|
145
|
+
while ((ch!=EOF) && (ch!='\n'))
|
|
146
|
+
ch = getchar();
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
/*-*************************************
|
|
152
|
+
* Constants
|
|
153
|
+
***************************************/
|
|
154
|
+
#define KB * (1 << 10)
|
|
155
|
+
#define LIST_SIZE_INCREASE (8 KB)
|
|
156
|
+
#define MAX_FILE_OF_FILE_NAMES_SIZE (1<<20)*50
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/*-*************************************
|
|
160
|
+
* Functions
|
|
161
|
+
***************************************/
|
|
162
|
+
|
|
163
|
+
void UTIL_traceFileStat(void)
|
|
164
|
+
{
|
|
165
|
+
g_traceFileStat = 1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
int UTIL_fstat(const int fd, const char* filename, stat_t* statbuf)
|
|
169
|
+
{
|
|
170
|
+
int ret;
|
|
171
|
+
UTIL_TRACE_CALL("UTIL_stat(%d, %s)", fd, filename);
|
|
172
|
+
#if defined(_MSC_VER)
|
|
173
|
+
if (fd >= 0) {
|
|
174
|
+
ret = !_fstat64(fd, statbuf);
|
|
175
|
+
} else {
|
|
176
|
+
ret = !_stat64(filename, statbuf);
|
|
177
|
+
}
|
|
178
|
+
#elif defined(__MINGW32__) && defined (__MSVCRT__)
|
|
179
|
+
if (fd >= 0) {
|
|
180
|
+
ret = !_fstati64(fd, statbuf);
|
|
181
|
+
} else {
|
|
182
|
+
ret = !_stati64(filename, statbuf);
|
|
183
|
+
}
|
|
184
|
+
#else
|
|
185
|
+
if (fd >= 0) {
|
|
186
|
+
ret = !fstat(fd, statbuf);
|
|
187
|
+
} else {
|
|
188
|
+
ret = !stat(filename, statbuf);
|
|
189
|
+
}
|
|
190
|
+
#endif
|
|
191
|
+
UTIL_TRACE_RET(ret);
|
|
192
|
+
return ret;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
int UTIL_stat(const char* filename, stat_t* statbuf)
|
|
196
|
+
{
|
|
197
|
+
return UTIL_fstat(-1, filename, statbuf);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
int UTIL_isFdRegularFile(int fd)
|
|
201
|
+
{
|
|
202
|
+
stat_t statbuf;
|
|
203
|
+
int ret;
|
|
204
|
+
UTIL_TRACE_CALL("UTIL_isFdRegularFile(%d)", fd);
|
|
205
|
+
ret = fd >= 0 && UTIL_fstat(fd, "", &statbuf) && UTIL_isRegularFileStat(&statbuf);
|
|
206
|
+
UTIL_TRACE_RET(ret);
|
|
207
|
+
return ret;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
int UTIL_isRegularFile(const char* infilename)
|
|
211
|
+
{
|
|
212
|
+
stat_t statbuf;
|
|
213
|
+
int ret;
|
|
214
|
+
UTIL_TRACE_CALL("UTIL_isRegularFile(%s)", infilename);
|
|
215
|
+
ret = UTIL_stat(infilename, &statbuf) && UTIL_isRegularFileStat(&statbuf);
|
|
216
|
+
UTIL_TRACE_RET(ret);
|
|
217
|
+
return ret;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
int UTIL_isRegularFileStat(const stat_t* statbuf)
|
|
221
|
+
{
|
|
222
|
+
#if defined(_MSC_VER)
|
|
223
|
+
return (statbuf->st_mode & S_IFREG) != 0;
|
|
224
|
+
#else
|
|
225
|
+
return S_ISREG(statbuf->st_mode) != 0;
|
|
226
|
+
#endif
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* like chmod, but avoid changing permission of /dev/null */
|
|
230
|
+
int UTIL_chmod(char const* filename, const stat_t* statbuf, mode_t permissions)
|
|
231
|
+
{
|
|
232
|
+
return UTIL_fchmod(-1, filename, statbuf, permissions);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
int UTIL_fchmod(const int fd, char const* filename, const stat_t* statbuf, mode_t permissions)
|
|
236
|
+
{
|
|
237
|
+
stat_t localStatBuf;
|
|
238
|
+
UTIL_TRACE_CALL("UTIL_chmod(%s, %#4o)", filename, (unsigned)permissions);
|
|
239
|
+
if (statbuf == NULL) {
|
|
240
|
+
if (!UTIL_fstat(fd, filename, &localStatBuf)) {
|
|
241
|
+
UTIL_TRACE_RET(0);
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
statbuf = &localStatBuf;
|
|
245
|
+
}
|
|
246
|
+
if (!UTIL_isRegularFileStat(statbuf)) {
|
|
247
|
+
UTIL_TRACE_RET(0);
|
|
248
|
+
return 0; /* pretend success, but don't change anything */
|
|
249
|
+
}
|
|
250
|
+
#ifdef ZSTD_HAVE_FCHMOD
|
|
251
|
+
if (fd >= 0) {
|
|
252
|
+
int ret;
|
|
253
|
+
UTIL_TRACE_CALL("fchmod");
|
|
254
|
+
ret = fchmod(fd, permissions);
|
|
255
|
+
UTIL_TRACE_RET(ret);
|
|
256
|
+
UTIL_TRACE_RET(ret);
|
|
257
|
+
return ret;
|
|
258
|
+
} else
|
|
259
|
+
#endif
|
|
260
|
+
{
|
|
261
|
+
int ret;
|
|
262
|
+
UTIL_TRACE_CALL("chmod");
|
|
263
|
+
ret = chmod(filename, permissions);
|
|
264
|
+
UTIL_TRACE_RET(ret);
|
|
265
|
+
UTIL_TRACE_RET(ret);
|
|
266
|
+
return ret;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* set access and modification times */
|
|
271
|
+
int UTIL_utime(const char* filename, const stat_t *statbuf)
|
|
272
|
+
{
|
|
273
|
+
int ret;
|
|
274
|
+
UTIL_TRACE_CALL("UTIL_utime(%s)", filename);
|
|
275
|
+
/* We check that st_mtime is a macro here in order to give us confidence
|
|
276
|
+
* that struct stat has a struct timespec st_mtim member. We need this
|
|
277
|
+
* check because there are some platforms that claim to be POSIX 2008
|
|
278
|
+
* compliant but which do not have st_mtim... */
|
|
279
|
+
/* FreeBSD has implemented POSIX 2008 for a long time but still only
|
|
280
|
+
* advertises support for POSIX 2001. They have a version macro that
|
|
281
|
+
* lets us safely gate them in.
|
|
282
|
+
* See https://docs.freebsd.org/en/books/porters-handbook/versions/.
|
|
283
|
+
*/
|
|
284
|
+
#if ZSTD_USE_UTIMENSAT
|
|
285
|
+
{
|
|
286
|
+
/* (atime, mtime) */
|
|
287
|
+
struct timespec timebuf[2] = { {0, UTIME_NOW} };
|
|
288
|
+
timebuf[1] = statbuf->st_mtim;
|
|
289
|
+
ret = utimensat(AT_FDCWD, filename, timebuf, 0);
|
|
290
|
+
}
|
|
291
|
+
#else
|
|
292
|
+
{
|
|
293
|
+
struct utimbuf timebuf;
|
|
294
|
+
timebuf.actime = time(NULL);
|
|
295
|
+
timebuf.modtime = statbuf->st_mtime;
|
|
296
|
+
ret = utime(filename, &timebuf);
|
|
297
|
+
}
|
|
298
|
+
#endif
|
|
299
|
+
errno = 0;
|
|
300
|
+
UTIL_TRACE_RET(ret);
|
|
301
|
+
return ret;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
int UTIL_setFileStat(const char *filename, const stat_t *statbuf)
|
|
305
|
+
{
|
|
306
|
+
return UTIL_setFDStat(-1, filename, statbuf);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
int UTIL_setFDStat(const int fd, const char *filename, const stat_t *statbuf)
|
|
310
|
+
{
|
|
311
|
+
int res = 0;
|
|
312
|
+
stat_t curStatBuf;
|
|
313
|
+
UTIL_TRACE_CALL("UTIL_setFileStat(%d, %s)", fd, filename);
|
|
314
|
+
|
|
315
|
+
if (!UTIL_fstat(fd, filename, &curStatBuf) || !UTIL_isRegularFileStat(&curStatBuf)) {
|
|
316
|
+
UTIL_TRACE_RET(-1);
|
|
317
|
+
return -1;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/* Mimic gzip's behavior:
|
|
321
|
+
*
|
|
322
|
+
* "Change the group first, then the permissions, then the owner.
|
|
323
|
+
* That way, the permissions will be correct on systems that allow
|
|
324
|
+
* users to give away files, without introducing a security hole.
|
|
325
|
+
* Security depends on permissions not containing the setuid or
|
|
326
|
+
* setgid bits." */
|
|
327
|
+
|
|
328
|
+
#if !defined(_WIN32)
|
|
329
|
+
#ifdef ZSTD_HAVE_FCHOWN
|
|
330
|
+
if (fd >= 0) {
|
|
331
|
+
res += fchown(fd, -1, statbuf->st_gid); /* Apply group ownership */
|
|
332
|
+
} else
|
|
333
|
+
#endif
|
|
334
|
+
{
|
|
335
|
+
res += chown(filename, -1, statbuf->st_gid); /* Apply group ownership */
|
|
336
|
+
}
|
|
337
|
+
#endif
|
|
338
|
+
|
|
339
|
+
res += UTIL_fchmod(fd, filename, &curStatBuf, statbuf->st_mode & 0777); /* Copy file permissions */
|
|
340
|
+
|
|
341
|
+
#if !defined(_WIN32)
|
|
342
|
+
#ifdef ZSTD_HAVE_FCHOWN
|
|
343
|
+
if (fd >= 0) {
|
|
344
|
+
res += fchown(fd, statbuf->st_uid, -1); /* Apply user ownership */
|
|
345
|
+
} else
|
|
346
|
+
#endif
|
|
347
|
+
{
|
|
348
|
+
res += chown(filename, statbuf->st_uid, -1); /* Apply user ownership */
|
|
349
|
+
}
|
|
350
|
+
#endif
|
|
351
|
+
|
|
352
|
+
errno = 0;
|
|
353
|
+
UTIL_TRACE_RET(-res);
|
|
354
|
+
return -res; /* number of errors is returned */
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
int UTIL_isDirectory(const char* infilename)
|
|
358
|
+
{
|
|
359
|
+
stat_t statbuf;
|
|
360
|
+
int ret;
|
|
361
|
+
UTIL_TRACE_CALL("UTIL_isDirectory(%s)", infilename);
|
|
362
|
+
ret = UTIL_stat(infilename, &statbuf) && UTIL_isDirectoryStat(&statbuf);
|
|
363
|
+
UTIL_TRACE_RET(ret);
|
|
364
|
+
return ret;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
int UTIL_isDirectoryStat(const stat_t* statbuf)
|
|
368
|
+
{
|
|
369
|
+
int ret;
|
|
370
|
+
UTIL_TRACE_CALL("UTIL_isDirectoryStat()");
|
|
371
|
+
#if defined(_MSC_VER)
|
|
372
|
+
ret = (statbuf->st_mode & _S_IFDIR) != 0;
|
|
373
|
+
#else
|
|
374
|
+
ret = S_ISDIR(statbuf->st_mode) != 0;
|
|
375
|
+
#endif
|
|
376
|
+
UTIL_TRACE_RET(ret);
|
|
377
|
+
return ret;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
int UTIL_compareStr(const void *p1, const void *p2) {
|
|
381
|
+
return strcmp(* (char * const *) p1, * (char * const *) p2);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
int UTIL_isSameFile(const char* fName1, const char* fName2)
|
|
385
|
+
{
|
|
386
|
+
int ret;
|
|
387
|
+
assert(fName1 != NULL); assert(fName2 != NULL);
|
|
388
|
+
UTIL_TRACE_CALL("UTIL_isSameFile(%s, %s)", fName1, fName2);
|
|
389
|
+
#if defined(_MSC_VER) || defined(_WIN32)
|
|
390
|
+
/* note : Visual does not support file identification by inode.
|
|
391
|
+
* inode does not work on Windows, even with a posix layer, like msys2.
|
|
392
|
+
* The following work-around is limited to detecting exact name repetition only,
|
|
393
|
+
* aka `filename` is considered different from `subdir/../filename` */
|
|
394
|
+
ret = !strcmp(fName1, fName2);
|
|
395
|
+
#else
|
|
396
|
+
{ stat_t file1Stat;
|
|
397
|
+
stat_t file2Stat;
|
|
398
|
+
ret = UTIL_stat(fName1, &file1Stat)
|
|
399
|
+
&& UTIL_stat(fName2, &file2Stat)
|
|
400
|
+
&& UTIL_isSameFileStat(fName1, fName2, &file1Stat, &file2Stat);
|
|
401
|
+
}
|
|
402
|
+
#endif
|
|
403
|
+
UTIL_TRACE_RET(ret);
|
|
404
|
+
return ret;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
int UTIL_isSameFileStat(
|
|
408
|
+
const char* fName1, const char* fName2,
|
|
409
|
+
const stat_t* file1Stat, const stat_t* file2Stat)
|
|
410
|
+
{
|
|
411
|
+
int ret;
|
|
412
|
+
assert(fName1 != NULL); assert(fName2 != NULL);
|
|
413
|
+
UTIL_TRACE_CALL("UTIL_isSameFileStat(%s, %s)", fName1, fName2);
|
|
414
|
+
#if defined(_MSC_VER) || defined(_WIN32)
|
|
415
|
+
/* note : Visual does not support file identification by inode.
|
|
416
|
+
* inode does not work on Windows, even with a posix layer, like msys2.
|
|
417
|
+
* The following work-around is limited to detecting exact name repetition only,
|
|
418
|
+
* aka `filename` is considered different from `subdir/../filename` */
|
|
419
|
+
(void)file1Stat;
|
|
420
|
+
(void)file2Stat;
|
|
421
|
+
ret = !strcmp(fName1, fName2);
|
|
422
|
+
#else
|
|
423
|
+
{
|
|
424
|
+
ret = (file1Stat->st_dev == file2Stat->st_dev)
|
|
425
|
+
&& (file1Stat->st_ino == file2Stat->st_ino);
|
|
426
|
+
}
|
|
427
|
+
#endif
|
|
428
|
+
UTIL_TRACE_RET(ret);
|
|
429
|
+
return ret;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/* UTIL_isFIFO : distinguish named pipes */
|
|
433
|
+
int UTIL_isFIFO(const char* infilename)
|
|
434
|
+
{
|
|
435
|
+
UTIL_TRACE_CALL("UTIL_isFIFO(%s)", infilename);
|
|
436
|
+
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
|
|
437
|
+
#if PLATFORM_POSIX_VERSION >= 200112L
|
|
438
|
+
{
|
|
439
|
+
stat_t statbuf;
|
|
440
|
+
if (UTIL_stat(infilename, &statbuf) && UTIL_isFIFOStat(&statbuf)) {
|
|
441
|
+
UTIL_TRACE_RET(1);
|
|
442
|
+
return 1;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
#endif
|
|
446
|
+
(void)infilename;
|
|
447
|
+
UTIL_TRACE_RET(0);
|
|
448
|
+
return 0;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/* UTIL_isFIFO : distinguish named pipes */
|
|
452
|
+
int UTIL_isFIFOStat(const stat_t* statbuf)
|
|
453
|
+
{
|
|
454
|
+
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
|
|
455
|
+
#if PLATFORM_POSIX_VERSION >= 200112L
|
|
456
|
+
if (S_ISFIFO(statbuf->st_mode)) return 1;
|
|
457
|
+
#endif
|
|
458
|
+
(void)statbuf;
|
|
459
|
+
return 0;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/* process substitution */
|
|
463
|
+
int UTIL_isFileDescriptorPipe(const char* filename)
|
|
464
|
+
{
|
|
465
|
+
UTIL_TRACE_CALL("UTIL_isFileDescriptorPipe(%s)", filename);
|
|
466
|
+
/* Check if the filename is a /dev/fd/ path which indicates a file descriptor */
|
|
467
|
+
if (filename[0] == '/' && strncmp(filename, "/dev/fd/", 8) == 0) {
|
|
468
|
+
UTIL_TRACE_RET(1);
|
|
469
|
+
return 1;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/* Check for alternative process substitution formats on different systems */
|
|
473
|
+
if (filename[0] == '/' && strncmp(filename, "/proc/self/fd/", 14) == 0) {
|
|
474
|
+
UTIL_TRACE_RET(1);
|
|
475
|
+
return 1;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
UTIL_TRACE_RET(0);
|
|
479
|
+
return 0; /* Not recognized as a file descriptor pipe */
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/* UTIL_isBlockDevStat : distinguish named pipes */
|
|
483
|
+
int UTIL_isBlockDevStat(const stat_t* statbuf)
|
|
484
|
+
{
|
|
485
|
+
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
|
|
486
|
+
#if PLATFORM_POSIX_VERSION >= 200112L
|
|
487
|
+
if (S_ISBLK(statbuf->st_mode)) return 1;
|
|
488
|
+
#endif
|
|
489
|
+
(void)statbuf;
|
|
490
|
+
return 0;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
int UTIL_isLink(const char* infilename)
|
|
494
|
+
{
|
|
495
|
+
UTIL_TRACE_CALL("UTIL_isLink(%s)", infilename);
|
|
496
|
+
/* macro guards, as defined in : https://linux.die.net/man/2/lstat */
|
|
497
|
+
#if PLATFORM_POSIX_VERSION >= 200112L
|
|
498
|
+
{
|
|
499
|
+
stat_t statbuf;
|
|
500
|
+
int const r = lstat(infilename, &statbuf);
|
|
501
|
+
if (!r && S_ISLNK(statbuf.st_mode)) {
|
|
502
|
+
UTIL_TRACE_RET(1);
|
|
503
|
+
return 1;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
#endif
|
|
507
|
+
(void)infilename;
|
|
508
|
+
UTIL_TRACE_RET(0);
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
static int g_fakeStdinIsConsole = 0;
|
|
513
|
+
static int g_fakeStderrIsConsole = 0;
|
|
514
|
+
static int g_fakeStdoutIsConsole = 0;
|
|
515
|
+
|
|
516
|
+
int UTIL_isConsole(FILE* file)
|
|
517
|
+
{
|
|
518
|
+
int ret;
|
|
519
|
+
UTIL_TRACE_CALL("UTIL_isConsole(%d)", fileno(file));
|
|
520
|
+
if (file == stdin && g_fakeStdinIsConsole)
|
|
521
|
+
ret = 1;
|
|
522
|
+
else if (file == stderr && g_fakeStderrIsConsole)
|
|
523
|
+
ret = 1;
|
|
524
|
+
else if (file == stdout && g_fakeStdoutIsConsole)
|
|
525
|
+
ret = 1;
|
|
526
|
+
else
|
|
527
|
+
ret = IS_CONSOLE(file);
|
|
528
|
+
UTIL_TRACE_RET(ret);
|
|
529
|
+
return ret;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
void UTIL_fakeStdinIsConsole(void)
|
|
533
|
+
{
|
|
534
|
+
g_fakeStdinIsConsole = 1;
|
|
535
|
+
}
|
|
536
|
+
void UTIL_fakeStdoutIsConsole(void)
|
|
537
|
+
{
|
|
538
|
+
g_fakeStdoutIsConsole = 1;
|
|
539
|
+
}
|
|
540
|
+
void UTIL_fakeStderrIsConsole(void)
|
|
541
|
+
{
|
|
542
|
+
g_fakeStderrIsConsole = 1;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
U64 UTIL_getFileSize(const char* infilename)
|
|
546
|
+
{
|
|
547
|
+
stat_t statbuf;
|
|
548
|
+
UTIL_TRACE_CALL("UTIL_getFileSize(%s)", infilename);
|
|
549
|
+
if (!UTIL_stat(infilename, &statbuf)) {
|
|
550
|
+
UTIL_TRACE_RET(-1);
|
|
551
|
+
return UTIL_FILESIZE_UNKNOWN;
|
|
552
|
+
}
|
|
553
|
+
{
|
|
554
|
+
U64 const size = UTIL_getFileSizeStat(&statbuf);
|
|
555
|
+
UTIL_TRACE_RET((int)size);
|
|
556
|
+
return size;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
U64 UTIL_getFileSizeStat(const stat_t* statbuf)
|
|
561
|
+
{
|
|
562
|
+
if (!UTIL_isRegularFileStat(statbuf)) return UTIL_FILESIZE_UNKNOWN;
|
|
563
|
+
#if defined(_MSC_VER)
|
|
564
|
+
if (!(statbuf->st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
|
565
|
+
#elif defined(__MINGW32__) && defined (__MSVCRT__)
|
|
566
|
+
if (!(statbuf->st_mode & S_IFREG)) return UTIL_FILESIZE_UNKNOWN;
|
|
567
|
+
#else
|
|
568
|
+
if (!S_ISREG(statbuf->st_mode)) return UTIL_FILESIZE_UNKNOWN;
|
|
569
|
+
#endif
|
|
570
|
+
return (U64)statbuf->st_size;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size)
|
|
574
|
+
{
|
|
575
|
+
UTIL_HumanReadableSize_t hrs;
|
|
576
|
+
|
|
577
|
+
if (g_utilDisplayLevel > 3) {
|
|
578
|
+
/* In verbose mode, do not scale sizes down, except in the case of
|
|
579
|
+
* values that exceed the integral precision of a double. */
|
|
580
|
+
if (size >= (1ull << 53)) {
|
|
581
|
+
hrs.value = (double)size / (1ull << 20);
|
|
582
|
+
hrs.suffix = " MiB";
|
|
583
|
+
/* At worst, a double representation of a maximal size will be
|
|
584
|
+
* accurate to better than tens of kilobytes. */
|
|
585
|
+
hrs.precision = 2;
|
|
586
|
+
} else {
|
|
587
|
+
hrs.value = (double)size;
|
|
588
|
+
hrs.suffix = " B";
|
|
589
|
+
hrs.precision = 0;
|
|
590
|
+
}
|
|
591
|
+
} else {
|
|
592
|
+
/* In regular mode, scale sizes down and use suffixes. */
|
|
593
|
+
if (size >= (1ull << 60)) {
|
|
594
|
+
hrs.value = (double)size / (1ull << 60);
|
|
595
|
+
hrs.suffix = " EiB";
|
|
596
|
+
} else if (size >= (1ull << 50)) {
|
|
597
|
+
hrs.value = (double)size / (1ull << 50);
|
|
598
|
+
hrs.suffix = " PiB";
|
|
599
|
+
} else if (size >= (1ull << 40)) {
|
|
600
|
+
hrs.value = (double)size / (1ull << 40);
|
|
601
|
+
hrs.suffix = " TiB";
|
|
602
|
+
} else if (size >= (1ull << 30)) {
|
|
603
|
+
hrs.value = (double)size / (1ull << 30);
|
|
604
|
+
hrs.suffix = " GiB";
|
|
605
|
+
} else if (size >= (1ull << 20)) {
|
|
606
|
+
hrs.value = (double)size / (1ull << 20);
|
|
607
|
+
hrs.suffix = " MiB";
|
|
608
|
+
} else if (size >= (1ull << 10)) {
|
|
609
|
+
hrs.value = (double)size / (1ull << 10);
|
|
610
|
+
hrs.suffix = " KiB";
|
|
611
|
+
} else {
|
|
612
|
+
hrs.value = (double)size;
|
|
613
|
+
hrs.suffix = " B";
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if (hrs.value >= 100 || (U64)hrs.value == size) {
|
|
617
|
+
hrs.precision = 0;
|
|
618
|
+
} else if (hrs.value >= 10) {
|
|
619
|
+
hrs.precision = 1;
|
|
620
|
+
} else if (hrs.value > 1) {
|
|
621
|
+
hrs.precision = 2;
|
|
622
|
+
} else {
|
|
623
|
+
hrs.precision = 3;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return hrs;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
U64 UTIL_getTotalFileSize(const char* const * fileNamesTable, unsigned nbFiles)
|
|
631
|
+
{
|
|
632
|
+
U64 total = 0;
|
|
633
|
+
unsigned n;
|
|
634
|
+
UTIL_TRACE_CALL("UTIL_getTotalFileSize(%u)", nbFiles);
|
|
635
|
+
for (n=0; n<nbFiles; n++) {
|
|
636
|
+
U64 const size = UTIL_getFileSize(fileNamesTable[n]);
|
|
637
|
+
if (size == UTIL_FILESIZE_UNKNOWN) {
|
|
638
|
+
UTIL_TRACE_RET(-1);
|
|
639
|
+
return UTIL_FILESIZE_UNKNOWN;
|
|
640
|
+
}
|
|
641
|
+
total += size;
|
|
642
|
+
}
|
|
643
|
+
UTIL_TRACE_RET((int)total);
|
|
644
|
+
return total;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
/* Read the entire content of a file into a buffer with progressive resizing */
|
|
649
|
+
static char* UTIL_readFileContent(FILE* inFile, size_t* totalReadPtr)
|
|
650
|
+
{
|
|
651
|
+
size_t bufSize = 64 KB; /* Start with a reasonable buffer size */
|
|
652
|
+
size_t totalRead = 0;
|
|
653
|
+
size_t bytesRead = 0;
|
|
654
|
+
char* buf = (char*)malloc(bufSize);
|
|
655
|
+
if (buf == NULL) return NULL;
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
/* Read the file incrementally */
|
|
659
|
+
while ((bytesRead = fread(buf + totalRead, 1, bufSize - totalRead - 1, inFile)) > 0) {
|
|
660
|
+
totalRead += bytesRead;
|
|
661
|
+
|
|
662
|
+
/* If buffer is nearly full, expand it */
|
|
663
|
+
if (bufSize - totalRead < 1 KB) {
|
|
664
|
+
if (bufSize >= MAX_FILE_OF_FILE_NAMES_SIZE) {
|
|
665
|
+
/* Too large, abort */
|
|
666
|
+
free(buf);
|
|
667
|
+
return NULL;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
{ size_t newBufSize = bufSize * 2;
|
|
671
|
+
if (newBufSize > MAX_FILE_OF_FILE_NAMES_SIZE)
|
|
672
|
+
newBufSize = MAX_FILE_OF_FILE_NAMES_SIZE;
|
|
673
|
+
|
|
674
|
+
{ char* newBuf = (char*)realloc(buf, newBufSize);
|
|
675
|
+
if (newBuf == NULL) {
|
|
676
|
+
free(buf);
|
|
677
|
+
return NULL;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
buf = newBuf;
|
|
681
|
+
bufSize = newBufSize;
|
|
682
|
+
} } }
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/* Add null terminator to the end */
|
|
686
|
+
buf[totalRead] = '\0';
|
|
687
|
+
*totalReadPtr = totalRead;
|
|
688
|
+
|
|
689
|
+
return buf;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/* Process a buffer containing multiple lines and count the number of lines */
|
|
693
|
+
static size_t UTIL_processLines(char* buffer, size_t bufferSize)
|
|
694
|
+
{
|
|
695
|
+
size_t lineCount = 0;
|
|
696
|
+
size_t i = 0;
|
|
697
|
+
|
|
698
|
+
/* Convert newlines to null terminators and count lines */
|
|
699
|
+
while (i < bufferSize) {
|
|
700
|
+
if (buffer[i] == '\n') {
|
|
701
|
+
buffer[i] = '\0'; /* Replace newlines with null terminators */
|
|
702
|
+
lineCount++;
|
|
703
|
+
}
|
|
704
|
+
i++;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/* Count the last line if it doesn't end with a newline */
|
|
708
|
+
if (bufferSize > 0 && (i == 0 || buffer[i-1] != '\0')) {
|
|
709
|
+
lineCount++;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
return lineCount;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/* Create an array of pointers to the lines in a buffer */
|
|
716
|
+
static const char** UTIL_createLinePointers(char* buffer, size_t numLines, size_t bufferSize)
|
|
717
|
+
{
|
|
718
|
+
size_t lineIndex = 0;
|
|
719
|
+
size_t pos = 0;
|
|
720
|
+
void* const bufferPtrs = malloc(numLines * sizeof(const char**));
|
|
721
|
+
const char** const linePointers = (const char**)bufferPtrs;
|
|
722
|
+
if (bufferPtrs == NULL) return NULL;
|
|
723
|
+
|
|
724
|
+
while (lineIndex < numLines && pos < bufferSize) {
|
|
725
|
+
size_t len = 0;
|
|
726
|
+
linePointers[lineIndex++] = buffer+pos;
|
|
727
|
+
|
|
728
|
+
/* Find the next null terminator, being careful not to go past the buffer */
|
|
729
|
+
while ((pos + len < bufferSize) && buffer[pos + len] != '\0') {
|
|
730
|
+
len++;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/* Move past this string and its null terminator */
|
|
734
|
+
pos += len;
|
|
735
|
+
if (pos < bufferSize) pos++; /* Skip the null terminator if we're not at buffer end */
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/* Verify we processed the expected number of lines */
|
|
739
|
+
if (lineIndex != numLines) {
|
|
740
|
+
/* Something went wrong - we didn't find as many lines as expected */
|
|
741
|
+
free(bufferPtrs);
|
|
742
|
+
return NULL;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
return linePointers;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
FileNamesTable*
|
|
749
|
+
UTIL_createFileNamesTable_fromFileList(const char* fileList)
|
|
750
|
+
{
|
|
751
|
+
stat_t statbuf;
|
|
752
|
+
char* buffer = NULL;
|
|
753
|
+
size_t numLines = 0;
|
|
754
|
+
size_t bufferSize = 0;
|
|
755
|
+
|
|
756
|
+
/* Check if the input is a valid file */
|
|
757
|
+
if (!UTIL_stat(fileList, &statbuf)) {
|
|
758
|
+
return NULL;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/* Check if the input is a supported type */
|
|
762
|
+
if (!UTIL_isRegularFileStat(&statbuf) &&
|
|
763
|
+
!UTIL_isFIFOStat(&statbuf) &&
|
|
764
|
+
!UTIL_isFileDescriptorPipe(fileList)) {
|
|
765
|
+
return NULL;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/* Open the input file */
|
|
769
|
+
{ FILE* const inFile = fopen(fileList, "rb");
|
|
770
|
+
if (inFile == NULL) return NULL;
|
|
771
|
+
|
|
772
|
+
/* Read the file content */
|
|
773
|
+
buffer = UTIL_readFileContent(inFile, &bufferSize);
|
|
774
|
+
fclose(inFile);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (buffer == NULL) return NULL;
|
|
778
|
+
|
|
779
|
+
/* Process lines */
|
|
780
|
+
numLines = UTIL_processLines(buffer, bufferSize);
|
|
781
|
+
if (numLines == 0) {
|
|
782
|
+
free(buffer);
|
|
783
|
+
return NULL;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/* Create line pointers */
|
|
787
|
+
{ const char** linePointers = UTIL_createLinePointers(buffer, numLines, bufferSize);
|
|
788
|
+
if (linePointers == NULL) {
|
|
789
|
+
free(buffer);
|
|
790
|
+
return NULL;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/* Create the final table */
|
|
794
|
+
return UTIL_assembleFileNamesTable(linePointers, numLines, buffer);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
static FileNamesTable*
|
|
800
|
+
UTIL_assembleFileNamesTable2(const char** filenames, size_t tableSize, size_t tableCapacity, char* buf)
|
|
801
|
+
{
|
|
802
|
+
FileNamesTable* const table = (FileNamesTable*) malloc(sizeof(*table));
|
|
803
|
+
CONTROL(table != NULL);
|
|
804
|
+
table->fileNames = filenames;
|
|
805
|
+
table->buf = buf;
|
|
806
|
+
table->tableSize = tableSize;
|
|
807
|
+
table->tableCapacity = tableCapacity;
|
|
808
|
+
return table;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
FileNamesTable*
|
|
812
|
+
UTIL_assembleFileNamesTable(const char** filenames, size_t tableSize, char* buf)
|
|
813
|
+
{
|
|
814
|
+
return UTIL_assembleFileNamesTable2(filenames, tableSize, tableSize, buf);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
void UTIL_freeFileNamesTable(FileNamesTable* table)
|
|
818
|
+
{
|
|
819
|
+
if (table==NULL) return;
|
|
820
|
+
free((void*)table->fileNames);
|
|
821
|
+
free(table->buf);
|
|
822
|
+
free(table);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
FileNamesTable* UTIL_allocateFileNamesTable(size_t tableSize)
|
|
826
|
+
{
|
|
827
|
+
const char** const fnTable = (const char**)malloc(tableSize * sizeof(*fnTable));
|
|
828
|
+
FileNamesTable* fnt;
|
|
829
|
+
if (fnTable==NULL) return NULL;
|
|
830
|
+
fnt = UTIL_assembleFileNamesTable(fnTable, tableSize, NULL);
|
|
831
|
+
fnt->tableSize = 0; /* the table is empty */
|
|
832
|
+
return fnt;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
int UTIL_searchFileNamesTable(FileNamesTable* table, char const* name) {
|
|
836
|
+
size_t i;
|
|
837
|
+
for(i=0 ;i < table->tableSize; i++) {
|
|
838
|
+
if(!strcmp(table->fileNames[i], name)) {
|
|
839
|
+
return (int)i;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return -1;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
void UTIL_refFilename(FileNamesTable* fnt, const char* filename)
|
|
846
|
+
{
|
|
847
|
+
assert(fnt->tableSize < fnt->tableCapacity);
|
|
848
|
+
fnt->fileNames[fnt->tableSize] = filename;
|
|
849
|
+
fnt->tableSize++;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
static size_t getTotalTableSize(FileNamesTable* table)
|
|
853
|
+
{
|
|
854
|
+
size_t fnb, totalSize = 0;
|
|
855
|
+
for(fnb = 0 ; fnb < table->tableSize && table->fileNames[fnb] ; ++fnb) {
|
|
856
|
+
totalSize += strlen(table->fileNames[fnb]) + 1; /* +1 to add '\0' at the end of each fileName */
|
|
857
|
+
}
|
|
858
|
+
return totalSize;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
FileNamesTable*
|
|
862
|
+
UTIL_mergeFileNamesTable(FileNamesTable* table1, FileNamesTable* table2)
|
|
863
|
+
{
|
|
864
|
+
unsigned newTableIdx = 0;
|
|
865
|
+
size_t pos = 0;
|
|
866
|
+
size_t newTotalTableSize;
|
|
867
|
+
char* buf;
|
|
868
|
+
|
|
869
|
+
FileNamesTable* const newTable = UTIL_assembleFileNamesTable(NULL, 0, NULL);
|
|
870
|
+
CONTROL( newTable != NULL );
|
|
871
|
+
|
|
872
|
+
newTotalTableSize = getTotalTableSize(table1) + getTotalTableSize(table2);
|
|
873
|
+
|
|
874
|
+
buf = (char*) calloc(newTotalTableSize, sizeof(*buf));
|
|
875
|
+
CONTROL ( buf != NULL );
|
|
876
|
+
|
|
877
|
+
newTable->buf = buf;
|
|
878
|
+
newTable->tableSize = table1->tableSize + table2->tableSize;
|
|
879
|
+
newTable->fileNames = (const char **) calloc(newTable->tableSize, sizeof(*(newTable->fileNames)));
|
|
880
|
+
CONTROL ( newTable->fileNames != NULL );
|
|
881
|
+
|
|
882
|
+
{ unsigned idx1;
|
|
883
|
+
for( idx1=0 ; (idx1 < table1->tableSize) && table1->fileNames[idx1] && (pos < newTotalTableSize); ++idx1, ++newTableIdx) {
|
|
884
|
+
size_t const curLen = strlen(table1->fileNames[idx1]);
|
|
885
|
+
memcpy(buf+pos, table1->fileNames[idx1], curLen);
|
|
886
|
+
assert(newTableIdx <= newTable->tableSize);
|
|
887
|
+
newTable->fileNames[newTableIdx] = buf+pos;
|
|
888
|
+
pos += curLen+1;
|
|
889
|
+
} }
|
|
890
|
+
|
|
891
|
+
{ unsigned idx2;
|
|
892
|
+
for( idx2=0 ; (idx2 < table2->tableSize) && table2->fileNames[idx2] && (pos < newTotalTableSize) ; ++idx2, ++newTableIdx) {
|
|
893
|
+
size_t const curLen = strlen(table2->fileNames[idx2]);
|
|
894
|
+
memcpy(buf+pos, table2->fileNames[idx2], curLen);
|
|
895
|
+
assert(newTableIdx < newTable->tableSize);
|
|
896
|
+
newTable->fileNames[newTableIdx] = buf+pos;
|
|
897
|
+
pos += curLen+1;
|
|
898
|
+
} }
|
|
899
|
+
assert(pos <= newTotalTableSize);
|
|
900
|
+
newTable->tableSize = newTableIdx;
|
|
901
|
+
|
|
902
|
+
UTIL_freeFileNamesTable(table1);
|
|
903
|
+
UTIL_freeFileNamesTable(table2);
|
|
904
|
+
|
|
905
|
+
return newTable;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
#ifdef _WIN32
|
|
909
|
+
static int UTIL_prepareFileList(const char* dirName,
|
|
910
|
+
char** bufStart, size_t* pos,
|
|
911
|
+
char** bufEnd, int followLinks)
|
|
912
|
+
{
|
|
913
|
+
char* path;
|
|
914
|
+
size_t dirLength, pathLength;
|
|
915
|
+
int nbFiles = 0;
|
|
916
|
+
WIN32_FIND_DATAA cFile;
|
|
917
|
+
HANDLE hFile;
|
|
918
|
+
|
|
919
|
+
dirLength = strlen(dirName);
|
|
920
|
+
path = (char*) malloc(dirLength + 3);
|
|
921
|
+
if (!path) return 0;
|
|
922
|
+
|
|
923
|
+
memcpy(path, dirName, dirLength);
|
|
924
|
+
path[dirLength] = '\\';
|
|
925
|
+
path[dirLength+1] = '*';
|
|
926
|
+
path[dirLength+2] = 0;
|
|
927
|
+
|
|
928
|
+
hFile=FindFirstFileA(path, &cFile);
|
|
929
|
+
if (hFile == INVALID_HANDLE_VALUE) {
|
|
930
|
+
UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s'\n", dirName);
|
|
931
|
+
free(path);
|
|
932
|
+
return 0;
|
|
933
|
+
}
|
|
934
|
+
free(path);
|
|
935
|
+
|
|
936
|
+
do {
|
|
937
|
+
size_t const fnameLength = strlen(cFile.cFileName);
|
|
938
|
+
path = (char*) malloc(dirLength + fnameLength + 2);
|
|
939
|
+
if (!path) { FindClose(hFile); return 0; }
|
|
940
|
+
memcpy(path, dirName, dirLength);
|
|
941
|
+
path[dirLength] = '\\';
|
|
942
|
+
memcpy(path+dirLength+1, cFile.cFileName, fnameLength);
|
|
943
|
+
pathLength = dirLength+1+fnameLength;
|
|
944
|
+
path[pathLength] = 0;
|
|
945
|
+
if (cFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
946
|
+
if ( strcmp (cFile.cFileName, "..") == 0
|
|
947
|
+
|| strcmp (cFile.cFileName, ".") == 0 )
|
|
948
|
+
continue;
|
|
949
|
+
/* Recursively call "UTIL_prepareFileList" with the new path. */
|
|
950
|
+
nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks);
|
|
951
|
+
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
|
|
952
|
+
} else if ( (cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
|
|
953
|
+
|| (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
|
|
954
|
+
|| (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) ) {
|
|
955
|
+
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
|
956
|
+
ptrdiff_t const newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
|
957
|
+
*bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
|
|
958
|
+
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
|
|
959
|
+
*bufEnd = *bufStart + newListSize;
|
|
960
|
+
}
|
|
961
|
+
if (*bufStart + *pos + pathLength < *bufEnd) {
|
|
962
|
+
memcpy(*bufStart + *pos, path, pathLength+1 /* include final \0 */);
|
|
963
|
+
*pos += pathLength + 1;
|
|
964
|
+
nbFiles++;
|
|
965
|
+
} }
|
|
966
|
+
free(path);
|
|
967
|
+
} while (FindNextFileA(hFile, &cFile));
|
|
968
|
+
|
|
969
|
+
FindClose(hFile);
|
|
970
|
+
return nbFiles;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
#elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */
|
|
974
|
+
|
|
975
|
+
static int UTIL_prepareFileList(const char *dirName,
|
|
976
|
+
char** bufStart, size_t* pos,
|
|
977
|
+
char** bufEnd, int followLinks)
|
|
978
|
+
{
|
|
979
|
+
DIR* dir;
|
|
980
|
+
struct dirent * entry;
|
|
981
|
+
size_t dirLength;
|
|
982
|
+
int nbFiles = 0;
|
|
983
|
+
|
|
984
|
+
if (!(dir = opendir(dirName))) {
|
|
985
|
+
UTIL_DISPLAYLEVEL(1, "Cannot open directory '%s': %s\n", dirName, strerror(errno));
|
|
986
|
+
return 0;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
dirLength = strlen(dirName);
|
|
990
|
+
errno = 0;
|
|
991
|
+
while ((entry = readdir(dir)) != NULL) {
|
|
992
|
+
char* path;
|
|
993
|
+
size_t fnameLength, pathLength;
|
|
994
|
+
if (strcmp (entry->d_name, "..") == 0 ||
|
|
995
|
+
strcmp (entry->d_name, ".") == 0) continue;
|
|
996
|
+
fnameLength = strlen(entry->d_name);
|
|
997
|
+
path = (char*) malloc(dirLength + fnameLength + 2);
|
|
998
|
+
if (!path) { closedir(dir); return 0; }
|
|
999
|
+
memcpy(path, dirName, dirLength);
|
|
1000
|
+
|
|
1001
|
+
path[dirLength] = '/';
|
|
1002
|
+
memcpy(path+dirLength+1, entry->d_name, fnameLength);
|
|
1003
|
+
pathLength = dirLength+1+fnameLength;
|
|
1004
|
+
path[pathLength] = 0;
|
|
1005
|
+
|
|
1006
|
+
if (!followLinks && UTIL_isLink(path)) {
|
|
1007
|
+
UTIL_DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring\n", path);
|
|
1008
|
+
free(path);
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
if (UTIL_isDirectory(path)) {
|
|
1013
|
+
nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */
|
|
1014
|
+
if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
|
|
1015
|
+
} else {
|
|
1016
|
+
if (*bufStart + *pos + pathLength >= *bufEnd) {
|
|
1017
|
+
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
|
|
1018
|
+
assert(newListSize >= 0);
|
|
1019
|
+
*bufStart = (char*)UTIL_realloc(*bufStart, (size_t)newListSize);
|
|
1020
|
+
if (*bufStart != NULL) {
|
|
1021
|
+
*bufEnd = *bufStart + newListSize;
|
|
1022
|
+
} else {
|
|
1023
|
+
free(path); closedir(dir); return 0;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
if (*bufStart + *pos + pathLength < *bufEnd) {
|
|
1027
|
+
memcpy(*bufStart + *pos, path, pathLength + 1); /* with final \0 */
|
|
1028
|
+
*pos += pathLength + 1;
|
|
1029
|
+
nbFiles++;
|
|
1030
|
+
} }
|
|
1031
|
+
free(path);
|
|
1032
|
+
errno = 0; /* clear errno after UTIL_isDirectory, UTIL_prepareFileList */
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
if (errno != 0) {
|
|
1036
|
+
UTIL_DISPLAYLEVEL(1, "readdir(%s) error: %s \n", dirName, strerror(errno));
|
|
1037
|
+
free(*bufStart);
|
|
1038
|
+
*bufStart = NULL;
|
|
1039
|
+
}
|
|
1040
|
+
closedir(dir);
|
|
1041
|
+
return nbFiles;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
#else
|
|
1045
|
+
|
|
1046
|
+
static int UTIL_prepareFileList(const char *dirName,
|
|
1047
|
+
char** bufStart, size_t* pos,
|
|
1048
|
+
char** bufEnd, int followLinks)
|
|
1049
|
+
{
|
|
1050
|
+
(void)bufStart; (void)bufEnd; (void)pos; (void)followLinks;
|
|
1051
|
+
UTIL_DISPLAYLEVEL(1, "Directory %s ignored (compiled without _WIN32 or _POSIX_C_SOURCE) \n", dirName);
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
#endif /* #ifdef _WIN32 */
|
|
1056
|
+
|
|
1057
|
+
int UTIL_isCompressedFile(const char *inputName, const char *extensionList[])
|
|
1058
|
+
{
|
|
1059
|
+
const char* ext = UTIL_getFileExtension(inputName);
|
|
1060
|
+
while(*extensionList!=NULL)
|
|
1061
|
+
{
|
|
1062
|
+
const int isCompressedExtension = strcmp(ext,*extensionList);
|
|
1063
|
+
if(isCompressedExtension==0)
|
|
1064
|
+
return 1;
|
|
1065
|
+
++extensionList;
|
|
1066
|
+
}
|
|
1067
|
+
return 0;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
/*Utility function to get file extension from file */
|
|
1071
|
+
const char* UTIL_getFileExtension(const char* infilename)
|
|
1072
|
+
{
|
|
1073
|
+
const char* extension = strrchr(infilename, '.');
|
|
1074
|
+
if(!extension || extension==infilename) return "";
|
|
1075
|
+
return extension;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
static int pathnameHas2Dots(const char *pathname)
|
|
1079
|
+
{
|
|
1080
|
+
/* We need to figure out whether any ".." present in the path is a whole
|
|
1081
|
+
* path token, which is the case if it is bordered on both sides by either
|
|
1082
|
+
* the beginning/end of the path or by a directory separator.
|
|
1083
|
+
*/
|
|
1084
|
+
const char *needle = pathname;
|
|
1085
|
+
while (1) {
|
|
1086
|
+
needle = strstr(needle, "..");
|
|
1087
|
+
|
|
1088
|
+
if (needle == NULL) {
|
|
1089
|
+
return 0;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
if ((needle == pathname || needle[-1] == PATH_SEP)
|
|
1093
|
+
&& (needle[2] == '\0' || needle[2] == PATH_SEP)) {
|
|
1094
|
+
return 1;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/* increment so we search for the next match */
|
|
1098
|
+
needle++;
|
|
1099
|
+
};
|
|
1100
|
+
return 0;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
static int isFileNameValidForMirroredOutput(const char *filename)
|
|
1104
|
+
{
|
|
1105
|
+
return !pathnameHas2Dots(filename);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
#define DIR_DEFAULT_MODE 0755
|
|
1110
|
+
static mode_t getDirMode(const char *dirName)
|
|
1111
|
+
{
|
|
1112
|
+
stat_t st;
|
|
1113
|
+
if (!UTIL_stat(dirName, &st)) {
|
|
1114
|
+
UTIL_DISPLAY("zstd: failed to get DIR stats %s: %s\n", dirName, strerror(errno));
|
|
1115
|
+
return DIR_DEFAULT_MODE;
|
|
1116
|
+
}
|
|
1117
|
+
if (!UTIL_isDirectoryStat(&st)) {
|
|
1118
|
+
UTIL_DISPLAY("zstd: expected directory: %s\n", dirName);
|
|
1119
|
+
return DIR_DEFAULT_MODE;
|
|
1120
|
+
}
|
|
1121
|
+
return st.st_mode;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
static int makeDir(const char *dir, mode_t mode)
|
|
1125
|
+
{
|
|
1126
|
+
#if defined(_MSC_VER) || defined(__MINGW32__) || defined (__MSVCRT__)
|
|
1127
|
+
int ret = _mkdir(dir);
|
|
1128
|
+
(void) mode;
|
|
1129
|
+
#else
|
|
1130
|
+
int ret = mkdir(dir, mode);
|
|
1131
|
+
#endif
|
|
1132
|
+
if (ret != 0) {
|
|
1133
|
+
if (errno == EEXIST)
|
|
1134
|
+
return 0;
|
|
1135
|
+
UTIL_DISPLAY("zstd: failed to create DIR %s: %s\n", dir, strerror(errno));
|
|
1136
|
+
}
|
|
1137
|
+
return ret;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/* this function requires a mutable input string */
|
|
1141
|
+
static void convertPathnameToDirName(char *pathname)
|
|
1142
|
+
{
|
|
1143
|
+
size_t len = 0;
|
|
1144
|
+
char* pos = NULL;
|
|
1145
|
+
/* get dir name from pathname similar to 'dirname()' */
|
|
1146
|
+
assert(pathname != NULL);
|
|
1147
|
+
|
|
1148
|
+
/* remove trailing '/' chars */
|
|
1149
|
+
len = strlen(pathname);
|
|
1150
|
+
assert(len > 0);
|
|
1151
|
+
while (pathname[len] == PATH_SEP) {
|
|
1152
|
+
pathname[len] = '\0';
|
|
1153
|
+
len--;
|
|
1154
|
+
}
|
|
1155
|
+
if (len == 0) return;
|
|
1156
|
+
|
|
1157
|
+
/* if input is a single file, return '.' instead. i.e.
|
|
1158
|
+
* "xyz/abc/file.txt" => "xyz/abc"
|
|
1159
|
+
"./file.txt" => "."
|
|
1160
|
+
"file.txt" => "."
|
|
1161
|
+
*/
|
|
1162
|
+
pos = strrchr(pathname, PATH_SEP);
|
|
1163
|
+
if (pos == NULL) {
|
|
1164
|
+
pathname[0] = '.';
|
|
1165
|
+
pathname[1] = '\0';
|
|
1166
|
+
} else {
|
|
1167
|
+
*pos = '\0';
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/* pathname must be valid */
|
|
1172
|
+
static const char* trimLeadingRootChar(const char *pathname)
|
|
1173
|
+
{
|
|
1174
|
+
assert(pathname != NULL);
|
|
1175
|
+
if (pathname[0] == PATH_SEP)
|
|
1176
|
+
return pathname + 1;
|
|
1177
|
+
return pathname;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
/* pathname must be valid */
|
|
1181
|
+
static const char* trimLeadingCurrentDirConst(const char *pathname)
|
|
1182
|
+
{
|
|
1183
|
+
assert(pathname != NULL);
|
|
1184
|
+
if ((pathname[0] == '.') && (pathname[1] == PATH_SEP))
|
|
1185
|
+
return pathname + 2;
|
|
1186
|
+
return pathname;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
static char*
|
|
1190
|
+
trimLeadingCurrentDir(char *pathname)
|
|
1191
|
+
{
|
|
1192
|
+
/* 'union charunion' can do const-cast without compiler warning */
|
|
1193
|
+
union charunion {
|
|
1194
|
+
char *chr;
|
|
1195
|
+
const char* cchr;
|
|
1196
|
+
} ptr;
|
|
1197
|
+
ptr.cchr = trimLeadingCurrentDirConst(pathname);
|
|
1198
|
+
return ptr.chr;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/* remove leading './' or '/' chars here */
|
|
1202
|
+
static const char * trimPath(const char *pathname)
|
|
1203
|
+
{
|
|
1204
|
+
return trimLeadingRootChar(
|
|
1205
|
+
trimLeadingCurrentDirConst(pathname));
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
static char* mallocAndJoin2Dir(const char *dir1, const char *dir2)
|
|
1209
|
+
{
|
|
1210
|
+
assert(dir1 != NULL && dir2 != NULL);
|
|
1211
|
+
{ const size_t dir1Size = strlen(dir1);
|
|
1212
|
+
const size_t dir2Size = strlen(dir2);
|
|
1213
|
+
char *outDirBuffer, *buffer;
|
|
1214
|
+
|
|
1215
|
+
outDirBuffer = (char *) malloc(dir1Size + dir2Size + 2);
|
|
1216
|
+
CONTROL(outDirBuffer != NULL);
|
|
1217
|
+
|
|
1218
|
+
memcpy(outDirBuffer, dir1, dir1Size);
|
|
1219
|
+
outDirBuffer[dir1Size] = '\0';
|
|
1220
|
+
|
|
1221
|
+
buffer = outDirBuffer + dir1Size;
|
|
1222
|
+
if (dir1Size > 0 && *(buffer - 1) != PATH_SEP) {
|
|
1223
|
+
*buffer = PATH_SEP;
|
|
1224
|
+
buffer++;
|
|
1225
|
+
}
|
|
1226
|
+
memcpy(buffer, dir2, dir2Size);
|
|
1227
|
+
buffer[dir2Size] = '\0';
|
|
1228
|
+
|
|
1229
|
+
return outDirBuffer;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/* this function will return NULL if input srcFileName is not valid name for mirrored output path */
|
|
1234
|
+
char* UTIL_createMirroredDestDirName(const char* srcFileName, const char* outDirRootName)
|
|
1235
|
+
{
|
|
1236
|
+
char* pathname = NULL;
|
|
1237
|
+
if (!isFileNameValidForMirroredOutput(srcFileName))
|
|
1238
|
+
return NULL;
|
|
1239
|
+
|
|
1240
|
+
pathname = mallocAndJoin2Dir(outDirRootName, trimPath(srcFileName));
|
|
1241
|
+
|
|
1242
|
+
convertPathnameToDirName(pathname);
|
|
1243
|
+
return pathname;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
static int
|
|
1247
|
+
mirrorSrcDir(char* srcDirName, const char* outDirName)
|
|
1248
|
+
{
|
|
1249
|
+
mode_t srcMode;
|
|
1250
|
+
int status = 0;
|
|
1251
|
+
char* newDir = mallocAndJoin2Dir(outDirName, trimPath(srcDirName));
|
|
1252
|
+
if (!newDir)
|
|
1253
|
+
return -ENOMEM;
|
|
1254
|
+
|
|
1255
|
+
srcMode = getDirMode(srcDirName);
|
|
1256
|
+
status = makeDir(newDir, srcMode);
|
|
1257
|
+
free(newDir);
|
|
1258
|
+
return status;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
static int
|
|
1262
|
+
mirrorSrcDirRecursive(char* srcDirName, const char* outDirName)
|
|
1263
|
+
{
|
|
1264
|
+
int status = 0;
|
|
1265
|
+
char* pp = trimLeadingCurrentDir(srcDirName);
|
|
1266
|
+
char* sp = NULL;
|
|
1267
|
+
|
|
1268
|
+
while ((sp = strchr(pp, PATH_SEP)) != NULL) {
|
|
1269
|
+
if (sp != pp) {
|
|
1270
|
+
*sp = '\0';
|
|
1271
|
+
status = mirrorSrcDir(srcDirName, outDirName);
|
|
1272
|
+
if (status != 0)
|
|
1273
|
+
return status;
|
|
1274
|
+
*sp = PATH_SEP;
|
|
1275
|
+
}
|
|
1276
|
+
pp = sp + 1;
|
|
1277
|
+
}
|
|
1278
|
+
status = mirrorSrcDir(srcDirName, outDirName);
|
|
1279
|
+
return status;
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
static void
|
|
1283
|
+
makeMirroredDestDirsWithSameSrcDirMode(char** srcDirNames, unsigned nbFile, const char* outDirName)
|
|
1284
|
+
{
|
|
1285
|
+
unsigned int i = 0;
|
|
1286
|
+
for (i = 0; i < nbFile; i++)
|
|
1287
|
+
mirrorSrcDirRecursive(srcDirNames[i], outDirName);
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
static int
|
|
1291
|
+
firstIsParentOrSameDirOfSecond(const char* firstDir, const char* secondDir)
|
|
1292
|
+
{
|
|
1293
|
+
size_t firstDirLen = strlen(firstDir),
|
|
1294
|
+
secondDirLen = strlen(secondDir);
|
|
1295
|
+
return firstDirLen <= secondDirLen &&
|
|
1296
|
+
(secondDir[firstDirLen] == PATH_SEP || secondDir[firstDirLen] == '\0') &&
|
|
1297
|
+
0 == strncmp(firstDir, secondDir, firstDirLen);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
static int compareDir(const void* pathname1, const void* pathname2) {
|
|
1301
|
+
/* sort it after remove the leading '/' or './'*/
|
|
1302
|
+
const char* s1 = trimPath(*(char * const *) pathname1);
|
|
1303
|
+
const char* s2 = trimPath(*(char * const *) pathname2);
|
|
1304
|
+
return strcmp(s1, s2);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
static void
|
|
1308
|
+
makeUniqueMirroredDestDirs(char** srcDirNames, unsigned nbFile, const char* outDirName)
|
|
1309
|
+
{
|
|
1310
|
+
unsigned int i = 0, uniqueDirNr = 0;
|
|
1311
|
+
char** uniqueDirNames = NULL;
|
|
1312
|
+
|
|
1313
|
+
if (nbFile == 0)
|
|
1314
|
+
return;
|
|
1315
|
+
|
|
1316
|
+
uniqueDirNames = (char** ) malloc(nbFile * sizeof (char *));
|
|
1317
|
+
CONTROL(uniqueDirNames != NULL);
|
|
1318
|
+
|
|
1319
|
+
/* if dirs is "a/b/c" and "a/b/c/d", we only need call:
|
|
1320
|
+
* we just need "a/b/c/d" */
|
|
1321
|
+
qsort((void *)srcDirNames, nbFile, sizeof(char*), compareDir);
|
|
1322
|
+
|
|
1323
|
+
uniqueDirNr = 1;
|
|
1324
|
+
uniqueDirNames[uniqueDirNr - 1] = srcDirNames[0];
|
|
1325
|
+
for (i = 1; i < nbFile; i++) {
|
|
1326
|
+
char* prevDirName = srcDirNames[i - 1];
|
|
1327
|
+
char* currDirName = srcDirNames[i];
|
|
1328
|
+
|
|
1329
|
+
/* note: we always compare trimmed path, i.e.:
|
|
1330
|
+
* src dir of "./foo" and "/foo" will be both saved into:
|
|
1331
|
+
* "outDirName/foo/" */
|
|
1332
|
+
if (!firstIsParentOrSameDirOfSecond(trimPath(prevDirName),
|
|
1333
|
+
trimPath(currDirName)))
|
|
1334
|
+
uniqueDirNr++;
|
|
1335
|
+
|
|
1336
|
+
/* we need to maintain original src dir name instead of trimmed
|
|
1337
|
+
* dir, so we can retrieve the original src dir's mode_t */
|
|
1338
|
+
uniqueDirNames[uniqueDirNr - 1] = currDirName;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
makeMirroredDestDirsWithSameSrcDirMode(uniqueDirNames, uniqueDirNr, outDirName);
|
|
1342
|
+
|
|
1343
|
+
free(uniqueDirNames);
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
static void
|
|
1347
|
+
makeMirroredDestDirs(char** srcFileNames, unsigned nbFile, const char* outDirName)
|
|
1348
|
+
{
|
|
1349
|
+
unsigned int i = 0;
|
|
1350
|
+
for (i = 0; i < nbFile; ++i)
|
|
1351
|
+
convertPathnameToDirName(srcFileNames[i]);
|
|
1352
|
+
makeUniqueMirroredDestDirs(srcFileNames, nbFile, outDirName);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
void UTIL_mirrorSourceFilesDirectories(const char** inFileNames, unsigned int nbFile, const char* outDirName)
|
|
1356
|
+
{
|
|
1357
|
+
unsigned int i = 0, validFilenamesNr = 0;
|
|
1358
|
+
char** srcFileNames = (char **) malloc(nbFile * sizeof (char *));
|
|
1359
|
+
CONTROL(srcFileNames != NULL);
|
|
1360
|
+
|
|
1361
|
+
/* check input filenames is valid */
|
|
1362
|
+
for (i = 0; i < nbFile; ++i) {
|
|
1363
|
+
if (isFileNameValidForMirroredOutput(inFileNames[i])) {
|
|
1364
|
+
char* fname = STRDUP(inFileNames[i]);
|
|
1365
|
+
CONTROL(fname != NULL);
|
|
1366
|
+
srcFileNames[validFilenamesNr++] = fname;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
if (validFilenamesNr > 0) {
|
|
1371
|
+
makeDir(outDirName, DIR_DEFAULT_MODE);
|
|
1372
|
+
makeMirroredDestDirs(srcFileNames, validFilenamesNr, outDirName);
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
for (i = 0; i < validFilenamesNr; i++)
|
|
1376
|
+
free(srcFileNames[i]);
|
|
1377
|
+
free(srcFileNames);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
FileNamesTable*
|
|
1381
|
+
UTIL_createExpandedFNT(const char* const* inputNames, size_t nbIfns, int followLinks)
|
|
1382
|
+
{
|
|
1383
|
+
unsigned nbFiles;
|
|
1384
|
+
char* buf = (char*)malloc(LIST_SIZE_INCREASE);
|
|
1385
|
+
char* bufend = buf + LIST_SIZE_INCREASE;
|
|
1386
|
+
|
|
1387
|
+
if (!buf) return NULL;
|
|
1388
|
+
|
|
1389
|
+
{ size_t ifnNb, pos;
|
|
1390
|
+
for (ifnNb=0, pos=0, nbFiles=0; ifnNb<nbIfns; ifnNb++) {
|
|
1391
|
+
if (!UTIL_isDirectory(inputNames[ifnNb])) {
|
|
1392
|
+
size_t const len = strlen(inputNames[ifnNb]);
|
|
1393
|
+
if (buf + pos + len >= bufend) {
|
|
1394
|
+
ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
|
|
1395
|
+
assert(newListSize >= 0);
|
|
1396
|
+
buf = (char*)UTIL_realloc(buf, (size_t)newListSize);
|
|
1397
|
+
if (!buf) return NULL;
|
|
1398
|
+
bufend = buf + newListSize;
|
|
1399
|
+
}
|
|
1400
|
+
if (buf + pos + len < bufend) {
|
|
1401
|
+
memcpy(buf+pos, inputNames[ifnNb], len+1); /* including final \0 */
|
|
1402
|
+
pos += len + 1;
|
|
1403
|
+
nbFiles++;
|
|
1404
|
+
}
|
|
1405
|
+
} else {
|
|
1406
|
+
nbFiles += (unsigned)UTIL_prepareFileList(inputNames[ifnNb], &buf, &pos, &bufend, followLinks);
|
|
1407
|
+
if (buf == NULL) return NULL;
|
|
1408
|
+
} } }
|
|
1409
|
+
|
|
1410
|
+
/* note : even if nbFiles==0, function returns a valid, though empty, FileNamesTable* object */
|
|
1411
|
+
|
|
1412
|
+
{ size_t ifnNb, pos;
|
|
1413
|
+
size_t const fntCapacity = nbFiles + 1; /* minimum 1, allows adding one reference, typically stdin */
|
|
1414
|
+
const char** const fileNamesTable = (const char**)malloc(fntCapacity * sizeof(*fileNamesTable));
|
|
1415
|
+
if (!fileNamesTable) { free(buf); return NULL; }
|
|
1416
|
+
|
|
1417
|
+
for (ifnNb = 0, pos = 0; ifnNb < nbFiles; ifnNb++) {
|
|
1418
|
+
fileNamesTable[ifnNb] = buf + pos;
|
|
1419
|
+
if (buf + pos > bufend) { free(buf); free((void*)fileNamesTable); return NULL; }
|
|
1420
|
+
pos += strlen(fileNamesTable[ifnNb]) + 1;
|
|
1421
|
+
}
|
|
1422
|
+
return UTIL_assembleFileNamesTable2(fileNamesTable, nbFiles, fntCapacity, buf);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
|
|
1427
|
+
void UTIL_expandFNT(FileNamesTable** fnt, int followLinks)
|
|
1428
|
+
{
|
|
1429
|
+
FileNamesTable* const newFNT = UTIL_createExpandedFNT((*fnt)->fileNames, (*fnt)->tableSize, followLinks);
|
|
1430
|
+
CONTROL(newFNT != NULL);
|
|
1431
|
+
UTIL_freeFileNamesTable(*fnt);
|
|
1432
|
+
*fnt = newFNT;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
FileNamesTable* UTIL_createFNT_fromROTable(const char** filenames, size_t nbFilenames)
|
|
1436
|
+
{
|
|
1437
|
+
size_t const sizeof_FNTable = nbFilenames * sizeof(*filenames);
|
|
1438
|
+
const char** const newFNTable = (const char**)malloc(sizeof_FNTable);
|
|
1439
|
+
if (newFNTable==NULL) return NULL;
|
|
1440
|
+
memcpy((void*)newFNTable, filenames, sizeof_FNTable); /* void* : mitigate a Visual compiler bug or limitation */
|
|
1441
|
+
return UTIL_assembleFileNamesTable(newFNTable, nbFilenames, NULL);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
|
|
1445
|
+
/*-****************************************
|
|
1446
|
+
* count the number of cores
|
|
1447
|
+
******************************************/
|
|
1448
|
+
|
|
1449
|
+
#if defined(_WIN32) || defined(WIN32)
|
|
1450
|
+
|
|
1451
|
+
#include <windows.h>
|
|
1452
|
+
|
|
1453
|
+
typedef BOOL(WINAPI* LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
|
|
1454
|
+
|
|
1455
|
+
DWORD CountSetBits(ULONG_PTR bitMask)
|
|
1456
|
+
{
|
|
1457
|
+
DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1;
|
|
1458
|
+
DWORD bitSetCount = 0;
|
|
1459
|
+
ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT;
|
|
1460
|
+
DWORD i;
|
|
1461
|
+
|
|
1462
|
+
for (i = 0; i <= LSHIFT; ++i)
|
|
1463
|
+
{
|
|
1464
|
+
bitSetCount += ((bitMask & bitTest)?1:0);
|
|
1465
|
+
bitTest/=2;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
return bitSetCount;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
int UTIL_countCores(int logical)
|
|
1472
|
+
{
|
|
1473
|
+
static int numCores = 0;
|
|
1474
|
+
if (numCores != 0) return numCores;
|
|
1475
|
+
|
|
1476
|
+
{ LPFN_GLPI glpi;
|
|
1477
|
+
BOOL done = FALSE;
|
|
1478
|
+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
|
|
1479
|
+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL;
|
|
1480
|
+
DWORD returnLength = 0;
|
|
1481
|
+
size_t byteOffset = 0;
|
|
1482
|
+
|
|
1483
|
+
#if defined(_MSC_VER)
|
|
1484
|
+
/* Visual Studio does not like the following cast */
|
|
1485
|
+
# pragma warning( disable : 4054 ) /* conversion from function ptr to data ptr */
|
|
1486
|
+
# pragma warning( disable : 4055 ) /* conversion from data ptr to function ptr */
|
|
1487
|
+
#endif
|
|
1488
|
+
glpi = (LPFN_GLPI)(void*)GetProcAddress(GetModuleHandle(TEXT("kernel32")),
|
|
1489
|
+
"GetLogicalProcessorInformation");
|
|
1490
|
+
|
|
1491
|
+
if (glpi == NULL) {
|
|
1492
|
+
goto failed;
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
while(!done) {
|
|
1496
|
+
DWORD rc = glpi(buffer, &returnLength);
|
|
1497
|
+
if (FALSE == rc) {
|
|
1498
|
+
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
|
|
1499
|
+
if (buffer)
|
|
1500
|
+
free(buffer);
|
|
1501
|
+
buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength);
|
|
1502
|
+
|
|
1503
|
+
if (buffer == NULL) {
|
|
1504
|
+
perror("zstd");
|
|
1505
|
+
exit(1);
|
|
1506
|
+
}
|
|
1507
|
+
} else {
|
|
1508
|
+
/* some other error */
|
|
1509
|
+
goto failed;
|
|
1510
|
+
}
|
|
1511
|
+
} else {
|
|
1512
|
+
done = TRUE;
|
|
1513
|
+
} }
|
|
1514
|
+
|
|
1515
|
+
ptr = buffer;
|
|
1516
|
+
|
|
1517
|
+
while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) {
|
|
1518
|
+
|
|
1519
|
+
if (ptr->Relationship == RelationProcessorCore) {
|
|
1520
|
+
if (logical)
|
|
1521
|
+
numCores += CountSetBits(ptr->ProcessorMask);
|
|
1522
|
+
else
|
|
1523
|
+
numCores++;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
ptr++;
|
|
1527
|
+
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
free(buffer);
|
|
1531
|
+
|
|
1532
|
+
return numCores;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
failed:
|
|
1536
|
+
/* try to fall back on GetSystemInfo */
|
|
1537
|
+
{ SYSTEM_INFO sysinfo;
|
|
1538
|
+
GetSystemInfo(&sysinfo);
|
|
1539
|
+
numCores = sysinfo.dwNumberOfProcessors;
|
|
1540
|
+
if (numCores == 0) numCores = 1; /* just in case */
|
|
1541
|
+
}
|
|
1542
|
+
return numCores;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
#elif defined(__APPLE__)
|
|
1546
|
+
|
|
1547
|
+
#include <sys/sysctl.h>
|
|
1548
|
+
|
|
1549
|
+
/* Use apple-provided syscall
|
|
1550
|
+
* see: man 3 sysctl */
|
|
1551
|
+
int UTIL_countCores(int logical)
|
|
1552
|
+
{
|
|
1553
|
+
static S32 numCores = 0; /* apple specifies int32_t */
|
|
1554
|
+
if (numCores != 0) return numCores;
|
|
1555
|
+
|
|
1556
|
+
{ size_t size = sizeof(S32);
|
|
1557
|
+
int const ret = sysctlbyname(logical ? "hw.logicalcpu" : "hw.physicalcpu", &numCores, &size, NULL, 0);
|
|
1558
|
+
if (ret != 0) {
|
|
1559
|
+
if (errno == ENOENT) {
|
|
1560
|
+
/* entry not present, fall back on 1 */
|
|
1561
|
+
numCores = 1;
|
|
1562
|
+
} else {
|
|
1563
|
+
perror("zstd: can't get number of cpus");
|
|
1564
|
+
exit(1);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
return numCores;
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
#elif defined(__linux__)
|
|
1573
|
+
|
|
1574
|
+
/* parse /proc/cpuinfo
|
|
1575
|
+
* siblings / cpu cores should give hyperthreading ratio
|
|
1576
|
+
* otherwise fall back on sysconf */
|
|
1577
|
+
int UTIL_countCores(int logical)
|
|
1578
|
+
{
|
|
1579
|
+
static int numCores = 0;
|
|
1580
|
+
|
|
1581
|
+
if (numCores != 0) return numCores;
|
|
1582
|
+
|
|
1583
|
+
numCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
1584
|
+
if (numCores == -1) {
|
|
1585
|
+
/* value not queryable, fall back on 1 */
|
|
1586
|
+
return numCores = 1;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
/* try to determine if there's hyperthreading */
|
|
1590
|
+
{ FILE* const cpuinfo = fopen("/proc/cpuinfo", "r");
|
|
1591
|
+
#define BUF_SIZE 80
|
|
1592
|
+
char buff[BUF_SIZE];
|
|
1593
|
+
|
|
1594
|
+
int siblings = 0;
|
|
1595
|
+
int cpu_cores = 0;
|
|
1596
|
+
int ratio = 1;
|
|
1597
|
+
|
|
1598
|
+
if (cpuinfo == NULL) {
|
|
1599
|
+
/* fall back on the sysconf value */
|
|
1600
|
+
return numCores;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
/* assume the cpu cores/siblings values will be constant across all
|
|
1604
|
+
* present processors */
|
|
1605
|
+
while (!feof(cpuinfo)) {
|
|
1606
|
+
if (fgets(buff, BUF_SIZE, cpuinfo) != NULL) {
|
|
1607
|
+
if (strncmp(buff, "siblings", 8) == 0) {
|
|
1608
|
+
const char* const sep = strchr(buff, ':');
|
|
1609
|
+
if (sep == NULL || *sep == '\0') {
|
|
1610
|
+
/* formatting was broken? */
|
|
1611
|
+
goto failed;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
siblings = atoi(sep + 1);
|
|
1615
|
+
}
|
|
1616
|
+
if (strncmp(buff, "cpu cores", 9) == 0) {
|
|
1617
|
+
const char* const sep = strchr(buff, ':');
|
|
1618
|
+
if (sep == NULL || *sep == '\0') {
|
|
1619
|
+
/* formatting was broken? */
|
|
1620
|
+
goto failed;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
cpu_cores = atoi(sep + 1);
|
|
1624
|
+
}
|
|
1625
|
+
} else if (ferror(cpuinfo)) {
|
|
1626
|
+
/* fall back on the sysconf value */
|
|
1627
|
+
goto failed;
|
|
1628
|
+
} }
|
|
1629
|
+
if (siblings && cpu_cores && siblings > cpu_cores) {
|
|
1630
|
+
ratio = siblings / cpu_cores;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
if (ratio && numCores > ratio && !logical) {
|
|
1634
|
+
numCores = numCores / ratio;
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
failed:
|
|
1638
|
+
fclose(cpuinfo);
|
|
1639
|
+
return numCores;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
#elif defined(__FreeBSD__)
|
|
1644
|
+
|
|
1645
|
+
#include <sys/sysctl.h>
|
|
1646
|
+
|
|
1647
|
+
/* Use physical core sysctl when available
|
|
1648
|
+
* see: man 4 smp, man 3 sysctl */
|
|
1649
|
+
int UTIL_countCores(int logical)
|
|
1650
|
+
{
|
|
1651
|
+
static int numCores = 0; /* freebsd sysctl is native int sized */
|
|
1652
|
+
#if __FreeBSD_version >= 1300008
|
|
1653
|
+
static int perCore = 1;
|
|
1654
|
+
#endif
|
|
1655
|
+
if (numCores != 0) return numCores;
|
|
1656
|
+
|
|
1657
|
+
#if __FreeBSD_version >= 1300008
|
|
1658
|
+
{ size_t size = sizeof(numCores);
|
|
1659
|
+
int ret = sysctlbyname("kern.smp.cores", &numCores, &size, NULL, 0);
|
|
1660
|
+
if (ret == 0) {
|
|
1661
|
+
if (logical) {
|
|
1662
|
+
ret = sysctlbyname("kern.smp.threads_per_core", &perCore, &size, NULL, 0);
|
|
1663
|
+
/* default to physical cores if logical cannot be read */
|
|
1664
|
+
if (ret == 0)
|
|
1665
|
+
numCores *= perCore;
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
return numCores;
|
|
1669
|
+
}
|
|
1670
|
+
if (errno != ENOENT) {
|
|
1671
|
+
perror("zstd: can't get number of cpus");
|
|
1672
|
+
exit(1);
|
|
1673
|
+
}
|
|
1674
|
+
/* sysctl not present, fall through to older sysconf method */
|
|
1675
|
+
}
|
|
1676
|
+
#else
|
|
1677
|
+
/* suppress unused parameter warning */
|
|
1678
|
+
(void) logical;
|
|
1679
|
+
#endif
|
|
1680
|
+
|
|
1681
|
+
numCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
1682
|
+
if (numCores == -1) {
|
|
1683
|
+
/* value not queryable, fall back on 1 */
|
|
1684
|
+
numCores = 1;
|
|
1685
|
+
}
|
|
1686
|
+
return numCores;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__CYGWIN__)
|
|
1690
|
+
|
|
1691
|
+
/* Use POSIX sysconf
|
|
1692
|
+
* see: man 3 sysconf */
|
|
1693
|
+
int UTIL_countCores(int logical)
|
|
1694
|
+
{
|
|
1695
|
+
static int numCores = 0;
|
|
1696
|
+
|
|
1697
|
+
/* suppress unused parameter warning */
|
|
1698
|
+
(void)logical;
|
|
1699
|
+
|
|
1700
|
+
if (numCores != 0) return numCores;
|
|
1701
|
+
|
|
1702
|
+
numCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
1703
|
+
if (numCores == -1) {
|
|
1704
|
+
/* value not queryable, fall back on 1 */
|
|
1705
|
+
return numCores = 1;
|
|
1706
|
+
}
|
|
1707
|
+
return numCores;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
#else
|
|
1711
|
+
|
|
1712
|
+
int UTIL_countCores(int logical)
|
|
1713
|
+
{
|
|
1714
|
+
/* suppress unused parameter warning */
|
|
1715
|
+
(void)logical;
|
|
1716
|
+
|
|
1717
|
+
/* assume 1 */
|
|
1718
|
+
return 1;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
#endif
|
|
1722
|
+
|
|
1723
|
+
int UTIL_countPhysicalCores(void)
|
|
1724
|
+
{
|
|
1725
|
+
return UTIL_countCores(0);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
int UTIL_countLogicalCores(void)
|
|
1729
|
+
{
|
|
1730
|
+
return UTIL_countCores(1);
|
|
1731
|
+
}
|